bedbug_603e.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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*[]));
  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 *argv[])
  52. {
  53. long addr; /* Address to break at */
  54. int which_bp; /* Breakpoint number */
  55. /* -------------------------------------------------- */
  56. if (argc < 2)
  57. {
  58. cmd_usage(cmdtp);
  59. return;
  60. }
  61. /* Turn off a breakpoint */
  62. if( strcmp( argv[ 1 ], "off" ) == 0 )
  63. {
  64. if( bug_ctx.hw_debug_enabled == 0 )
  65. {
  66. puts ( "No breakpoints enabled\n" );
  67. return;
  68. }
  69. which_bp = simple_strtoul( argv[ 2 ], NULL, 10 );
  70. if( bug_ctx.clear )
  71. (*bug_ctx.clear)( which_bp );
  72. printf( "Breakpoint %d removed\n", which_bp );
  73. return;
  74. }
  75. /* Show a list of breakpoints */
  76. if( strcmp( argv[ 1 ], "show" ) == 0 )
  77. {
  78. for( which_bp = 1; which_bp <= MAX_BREAK_POINTS; ++which_bp )
  79. {
  80. addr = GET_IABR();
  81. printf( "Breakpoint [%d]: ", which_bp );
  82. if( (addr & 0x00000002) == 0 )
  83. puts ( "NOT SET\n" );
  84. else
  85. disppc( (unsigned char *)(addr & 0xFFFFFFFC), 0, 1, bedbug_puts, F_RADHEX );
  86. }
  87. return;
  88. }
  89. /* Set a breakpoint at the address */
  90. if(!(( isdigit( argv[ 1 ][ 0 ] )) ||
  91. (( argv[ 1 ][ 0 ] >= 'a' ) && ( argv[ 1 ][ 0 ] <= 'f' )) ||
  92. (( argv[ 1 ][ 0 ] >= 'A' ) && ( argv[ 1 ][ 0 ] <= 'F' ))))
  93. {
  94. cmd_usage(cmdtp);
  95. return;
  96. }
  97. addr = simple_strtoul( argv[ 1 ], NULL, 16 );
  98. if(( bug_ctx.set ) && ( which_bp = (*bug_ctx.set)( 0, addr )) > 0 )
  99. {
  100. printf( "Breakpoint [%d]: ", which_bp );
  101. disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
  102. }
  103. return;
  104. } /* bedbug603e_do_break */
  105. /* ======================================================================
  106. * Handle a breakpoint. Enter a mini main loop. Stay in the loop until
  107. * the stopped flag in the debug context is cleared.
  108. * ====================================================================== */
  109. void bedbug603e_break_isr( struct pt_regs *regs )
  110. {
  111. unsigned long addr; /* Address stopped at */
  112. /* -------------------------------------------------- */
  113. bug_ctx.current_bp = 1;
  114. addr = GET_IABR() & 0xFFFFFFFC;
  115. bedbug_main_loop( addr, regs );
  116. return;
  117. } /* bedbug603e_break_isr */
  118. /* ======================================================================
  119. * See if the hardware breakpoint is available.
  120. * ====================================================================== */
  121. int bedbug603e_find_empty( void )
  122. {
  123. /* -------------------------------------------------- */
  124. if( (GET_IABR() && 0x00000002) == 0 )
  125. return 1;
  126. return 0;
  127. } /* bedbug603e_find_empty */
  128. /* ======================================================================
  129. * Set a breakpoint. If 'which_bp' is zero then find an unused breakpoint
  130. * number, otherwise reassign the given breakpoint. If hardware debugging
  131. * is not enabled, then turn it on via the MSR and DBCR0. Set the break
  132. * address in the IABR register.
  133. * ====================================================================== */
  134. int bedbug603e_set( int which_bp, unsigned long addr )
  135. {
  136. /* -------------------------------------------------- */
  137. if(( addr & 0x00000003 ) != 0 )
  138. {
  139. puts ( "Breakpoints must be on a 32 bit boundary\n" );
  140. return 0;
  141. }
  142. /* Only look if which_bp == 0, else use which_bp */
  143. if(( bug_ctx.find_empty ) && ( !which_bp ) &&
  144. ( which_bp = (*bug_ctx.find_empty)()) == 0 )
  145. {
  146. puts ( "All breakpoints in use\n" );
  147. return 0;
  148. }
  149. if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
  150. {
  151. printf( "Invalid break point # %d\n", which_bp );
  152. return 0;
  153. }
  154. if( ! bug_ctx.hw_debug_enabled )
  155. {
  156. bug_ctx.hw_debug_enabled = 1;
  157. }
  158. SET_IABR( addr | 0x00000002 );
  159. return which_bp;
  160. } /* bedbug603e_set */
  161. /* ======================================================================
  162. * Disable a specific breakoint by setting the IABR register to zero.
  163. * ====================================================================== */
  164. int bedbug603e_clear( int which_bp )
  165. {
  166. /* -------------------------------------------------- */
  167. if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
  168. {
  169. printf( "Invalid break point # (%d)\n", which_bp );
  170. return -1;
  171. }
  172. SET_IABR( 0 );
  173. return 0;
  174. } /* bedbug603e_clear */
  175. /* ====================================================================== */
  176. #endif