bedbug_603e.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * Bedbug Functions specific to the MPC603e core
  3. */
  4. #include <common.h>
  5. #include <command.h>
  6. #include <linux/ctype.h>
  7. #include <bedbug/type.h>
  8. #include <bedbug/bedbug.h>
  9. #include <bedbug/regs.h>
  10. #include <bedbug/ppc.h>
  11. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG) && (defined(CONFIG_MPC824X) || defined(CONFIG_MPC8260))
  12. #define MAX_BREAK_POINTS 1
  13. extern CPU_DEBUG_CTX bug_ctx;
  14. void bedbug603e_init __P((void));
  15. void bedbug603e_do_break __P((cmd_tbl_t*,int,int,char*[]));
  16. void bedbug603e_break_isr __P((struct pt_regs*));
  17. int bedbug603e_find_empty __P((void));
  18. int bedbug603e_set __P((int,unsigned long));
  19. int bedbug603e_clear __P((int));
  20. /* ======================================================================
  21. * Initialize the global bug_ctx structure for the processor. Clear all
  22. * of the breakpoints.
  23. * ====================================================================== */
  24. void bedbug603e_init( void )
  25. {
  26. int i;
  27. /* -------------------------------------------------- */
  28. bug_ctx.hw_debug_enabled = 0;
  29. bug_ctx.stopped = 0;
  30. bug_ctx.current_bp = 0;
  31. bug_ctx.regs = NULL;
  32. bug_ctx.do_break = bedbug603e_do_break;
  33. bug_ctx.break_isr = bedbug603e_break_isr;
  34. bug_ctx.find_empty = bedbug603e_find_empty;
  35. bug_ctx.set = bedbug603e_set;
  36. bug_ctx.clear = bedbug603e_clear;
  37. for( i = 1; i <= MAX_BREAK_POINTS; ++i )
  38. (*bug_ctx.clear)( i );
  39. puts ("BEDBUG:ready\n");
  40. return;
  41. } /* bedbug_init_breakpoints */
  42. /* ======================================================================
  43. * Set/clear/show the hardware breakpoint for the 603e. The "off"
  44. * string will disable a specific breakpoint. The "show" string will
  45. * display the current breakpoints. Otherwise an address will set a
  46. * breakpoint at that address. Setting a breakpoint uses the CPU-specific
  47. * set routine which will assign a breakpoint number.
  48. * ====================================================================== */
  49. void bedbug603e_do_break (cmd_tbl_t *cmdtp, int flag, int argc,
  50. char *argv[])
  51. {
  52. long addr; /* Address to break at */
  53. int which_bp; /* Breakpoint number */
  54. /* -------------------------------------------------- */
  55. if (argc < 2)
  56. {
  57. printf ("Usage:\n%s\n", cmdtp->usage);
  58. return;
  59. }
  60. /* Turn off a breakpoint */
  61. if( strcmp( argv[ 1 ], "off" ) == 0 )
  62. {
  63. if( bug_ctx.hw_debug_enabled == 0 )
  64. {
  65. puts ( "No breakpoints enabled\n" );
  66. return;
  67. }
  68. which_bp = simple_strtoul( argv[ 2 ], NULL, 10 );
  69. if( bug_ctx.clear )
  70. (*bug_ctx.clear)( which_bp );
  71. printf( "Breakpoint %d removed\n", which_bp );
  72. return;
  73. }
  74. /* Show a list of breakpoints */
  75. if( strcmp( argv[ 1 ], "show" ) == 0 )
  76. {
  77. for( which_bp = 1; which_bp <= MAX_BREAK_POINTS; ++which_bp )
  78. {
  79. addr = GET_IABR();
  80. printf( "Breakpoint [%d]: ", which_bp );
  81. if( (addr & 0x00000002) == 0 )
  82. puts ( "NOT SET\n" );
  83. else
  84. disppc( (unsigned char *)(addr & 0xFFFFFFFC), 0, 1, bedbug_puts, F_RADHEX );
  85. }
  86. return;
  87. }
  88. /* Set a breakpoint at the address */
  89. if(!(( isdigit( argv[ 1 ][ 0 ] )) ||
  90. (( argv[ 1 ][ 0 ] >= 'a' ) && ( argv[ 1 ][ 0 ] <= 'f' )) ||
  91. (( argv[ 1 ][ 0 ] >= 'A' ) && ( argv[ 1 ][ 0 ] <= 'F' ))))
  92. {
  93. printf ("Usage:\n%s\n", cmdtp->usage);
  94. return;
  95. }
  96. addr = simple_strtoul( argv[ 1 ], NULL, 16 );
  97. if(( bug_ctx.set ) && ( which_bp = (*bug_ctx.set)( 0, addr )) > 0 )
  98. {
  99. printf( "Breakpoint [%d]: ", which_bp );
  100. disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
  101. }
  102. return;
  103. } /* bedbug603e_do_break */
  104. /* ======================================================================
  105. * Handle a breakpoint. Enter a mini main loop. Stay in the loop until
  106. * the stopped flag in the debug context is cleared.
  107. * ====================================================================== */
  108. void bedbug603e_break_isr( struct pt_regs *regs )
  109. {
  110. unsigned long addr; /* Address stopped at */
  111. /* -------------------------------------------------- */
  112. bug_ctx.current_bp = 1;
  113. addr = GET_IABR() & 0xFFFFFFFC;
  114. bedbug_main_loop( addr, regs );
  115. return;
  116. } /* bedbug603e_break_isr */
  117. /* ======================================================================
  118. * See if the hardware breakpoint is available.
  119. * ====================================================================== */
  120. int bedbug603e_find_empty( void )
  121. {
  122. /* -------------------------------------------------- */
  123. if( (GET_IABR() && 0x00000002) == 0 )
  124. return 1;
  125. return 0;
  126. } /* bedbug603e_find_empty */
  127. /* ======================================================================
  128. * Set a breakpoint. If 'which_bp' is zero then find an unused breakpoint
  129. * number, otherwise reassign the given breakpoint. If hardware debugging
  130. * is not enabled, then turn it on via the MSR and DBCR0. Set the break
  131. * address in the IABR register.
  132. * ====================================================================== */
  133. int bedbug603e_set( int which_bp, unsigned long addr )
  134. {
  135. /* -------------------------------------------------- */
  136. if(( addr & 0x00000003 ) != 0 )
  137. {
  138. puts ( "Breakpoints must be on a 32 bit boundary\n" );
  139. return 0;
  140. }
  141. /* Only look if which_bp == 0, else use which_bp */
  142. if(( bug_ctx.find_empty ) && ( !which_bp ) &&
  143. ( which_bp = (*bug_ctx.find_empty)()) == 0 )
  144. {
  145. puts ( "All breakpoints in use\n" );
  146. return 0;
  147. }
  148. if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
  149. {
  150. printf( "Invalid break point # %d\n", which_bp );
  151. return 0;
  152. }
  153. if( ! bug_ctx.hw_debug_enabled )
  154. {
  155. bug_ctx.hw_debug_enabled = 1;
  156. }
  157. SET_IABR( addr | 0x00000002 );
  158. return which_bp;
  159. } /* bedbug603e_set */
  160. /* ======================================================================
  161. * Disable a specific breakoint by setting the IABR register to zero.
  162. * ====================================================================== */
  163. int bedbug603e_clear( int which_bp )
  164. {
  165. /* -------------------------------------------------- */
  166. if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
  167. {
  168. printf( "Invalid break point # (%d)\n", which_bp );
  169. return -1;
  170. }
  171. SET_IABR( 0 );
  172. return 0;
  173. } /* bedbug603e_clear */
  174. /* ====================================================================== */
  175. #endif