bedbug_603e.c 6.1 KB

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