bedbug_603e.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 defined(CONFIG_CMD_BEDBUG) \
  12. && (defined(CONFIG_MPC824X) || defined(CONFIG_MPC8260))
  13. #define MAX_BREAK_POINTS 1
  14. extern CPU_DEBUG_CTX bug_ctx;
  15. void bedbug603e_init __P((void));
  16. void bedbug603e_do_break __P((cmd_tbl_t*,int,int,char*const[]));
  17. void bedbug603e_break_isr __P((struct pt_regs*));
  18. int bedbug603e_find_empty __P((void));
  19. int bedbug603e_set __P((int,unsigned long));
  20. int bedbug603e_clear __P((int));
  21. /* ======================================================================
  22. * Initialize the global bug_ctx structure for the processor. Clear all
  23. * of the breakpoints.
  24. * ====================================================================== */
  25. void bedbug603e_init( void )
  26. {
  27. int i;
  28. /* -------------------------------------------------- */
  29. bug_ctx.hw_debug_enabled = 0;
  30. bug_ctx.stopped = 0;
  31. bug_ctx.current_bp = 0;
  32. bug_ctx.regs = NULL;
  33. bug_ctx.do_break = bedbug603e_do_break;
  34. bug_ctx.break_isr = bedbug603e_break_isr;
  35. bug_ctx.find_empty = bedbug603e_find_empty;
  36. bug_ctx.set = bedbug603e_set;
  37. bug_ctx.clear = bedbug603e_clear;
  38. for( i = 1; i <= MAX_BREAK_POINTS; ++i )
  39. (*bug_ctx.clear)( i );
  40. puts ("BEDBUG:ready\n");
  41. return;
  42. } /* bedbug_init_breakpoints */
  43. /* ======================================================================
  44. * Set/clear/show the hardware breakpoint for the 603e. The "off"
  45. * string will disable a specific breakpoint. The "show" string will
  46. * display the current breakpoints. Otherwise an address will set a
  47. * breakpoint at that address. Setting a breakpoint uses the CPU-specific
  48. * set routine which will assign a breakpoint number.
  49. * ====================================================================== */
  50. void bedbug603e_do_break (cmd_tbl_t *cmdtp, int flag, int argc,
  51. char * const argv[])
  52. {
  53. long addr; /* Address to break at */
  54. int which_bp; /* Breakpoint number */
  55. /* -------------------------------------------------- */
  56. if (argc < 2) {
  57. cmd_usage(cmdtp);
  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. cmd_usage(cmdtp);
  93. return;
  94. }
  95. addr = simple_strtoul( argv[ 1 ], NULL, 16 );
  96. if(( bug_ctx.set ) && ( which_bp = (*bug_ctx.set)( 0, addr )) > 0 )
  97. {
  98. printf( "Breakpoint [%d]: ", which_bp );
  99. disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
  100. }
  101. return;
  102. } /* bedbug603e_do_break */
  103. /* ======================================================================
  104. * Handle a breakpoint. Enter a mini main loop. Stay in the loop until
  105. * the stopped flag in the debug context is cleared.
  106. * ====================================================================== */
  107. void bedbug603e_break_isr( struct pt_regs *regs )
  108. {
  109. unsigned long addr; /* Address stopped at */
  110. /* -------------------------------------------------- */
  111. bug_ctx.current_bp = 1;
  112. addr = GET_IABR() & 0xFFFFFFFC;
  113. bedbug_main_loop( addr, regs );
  114. return;
  115. } /* bedbug603e_break_isr */
  116. /* ======================================================================
  117. * See if the hardware breakpoint is available.
  118. * ====================================================================== */
  119. int bedbug603e_find_empty( void )
  120. {
  121. /* -------------------------------------------------- */
  122. if( (GET_IABR() && 0x00000002) == 0 )
  123. return 1;
  124. return 0;
  125. } /* bedbug603e_find_empty */
  126. /* ======================================================================
  127. * Set a breakpoint. If 'which_bp' is zero then find an unused breakpoint
  128. * number, otherwise reassign the given breakpoint. If hardware debugging
  129. * is not enabled, then turn it on via the MSR and DBCR0. Set the break
  130. * address in the IABR register.
  131. * ====================================================================== */
  132. int bedbug603e_set( int which_bp, unsigned long addr )
  133. {
  134. /* -------------------------------------------------- */
  135. if(( addr & 0x00000003 ) != 0 )
  136. {
  137. puts ( "Breakpoints must be on a 32 bit boundary\n" );
  138. return 0;
  139. }
  140. /* Only look if which_bp == 0, else use which_bp */
  141. if(( bug_ctx.find_empty ) && ( !which_bp ) &&
  142. ( which_bp = (*bug_ctx.find_empty)()) == 0 )
  143. {
  144. puts ( "All breakpoints in use\n" );
  145. return 0;
  146. }
  147. if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
  148. {
  149. printf( "Invalid break point # %d\n", which_bp );
  150. return 0;
  151. }
  152. if( ! bug_ctx.hw_debug_enabled )
  153. {
  154. bug_ctx.hw_debug_enabled = 1;
  155. }
  156. SET_IABR( addr | 0x00000002 );
  157. return which_bp;
  158. } /* bedbug603e_set */
  159. /* ======================================================================
  160. * Disable a specific breakoint by setting the IABR register to zero.
  161. * ====================================================================== */
  162. int bedbug603e_clear( int which_bp )
  163. {
  164. /* -------------------------------------------------- */
  165. if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
  166. {
  167. printf( "Invalid break point # (%d)\n", which_bp );
  168. return -1;
  169. }
  170. SET_IABR( 0 );
  171. return 0;
  172. } /* bedbug603e_clear */
  173. /* ====================================================================== */
  174. #endif