bedbug_860.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * Bedbug Functions specific to the MPC860 chip
  3. */
  4. #include <common.h>
  5. #include <command.h>
  6. #include <linux/ctype.h>
  7. #include <bedbug/bedbug.h>
  8. #include <bedbug/regs.h>
  9. #include <bedbug/ppc.h>
  10. #include <bedbug/type.h>
  11. #if defined(CONFIG_CMD_BEDBUG) && defined(CONFIG_8xx)
  12. #define MAX_BREAK_POINTS 2
  13. extern CPU_DEBUG_CTX bug_ctx;
  14. void bedbug860_init __P((void));
  15. void bedbug860_do_break __P((cmd_tbl_t*,int,int,char*const[]));
  16. void bedbug860_break_isr __P((struct pt_regs*));
  17. int bedbug860_find_empty __P((void));
  18. int bedbug860_set __P((int,unsigned long));
  19. int bedbug860_clear __P((int));
  20. /* ======================================================================
  21. * Initialize the global bug_ctx structure for the MPC860. Clear all
  22. * of the breakpoints.
  23. * ====================================================================== */
  24. void bedbug860_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 = bedbug860_do_break;
  33. bug_ctx.break_isr = bedbug860_break_isr;
  34. bug_ctx.find_empty = bedbug860_find_empty;
  35. bug_ctx.set = bedbug860_set;
  36. bug_ctx.clear = bedbug860_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 one of the hardware breakpoints for the 860. 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 bedbug860_do_break (cmd_tbl_t *cmdtp, int flag, int argc,
  50. char * const argv[])
  51. {
  52. long addr = 0; /* Address to break at */
  53. int which_bp; /* Breakpoint number */
  54. /* -------------------------------------------------- */
  55. if (argc < 2)
  56. return cmd_usage(cmdtp);
  57. /* Turn off a breakpoint */
  58. if( strcmp( argv[ 1 ], "off" ) == 0 )
  59. {
  60. if( bug_ctx.hw_debug_enabled == 0 )
  61. {
  62. printf( "No breakpoints enabled\n" );
  63. return;
  64. }
  65. which_bp = simple_strtoul( argv[ 2 ], NULL, 10 );
  66. if( bug_ctx.clear )
  67. (*bug_ctx.clear)( which_bp );
  68. printf( "Breakpoint %d removed\n", which_bp );
  69. return;
  70. }
  71. /* Show a list of breakpoints */
  72. if( strcmp( argv[ 1 ], "show" ) == 0 )
  73. {
  74. for( which_bp = 1; which_bp <= MAX_BREAK_POINTS; ++which_bp )
  75. {
  76. switch( which_bp )
  77. {
  78. case 1: addr = GET_CMPA(); break;
  79. case 2: addr = GET_CMPB(); break;
  80. case 3: addr = GET_CMPC(); break;
  81. case 4: addr = GET_CMPD(); break;
  82. }
  83. printf( "Breakpoint [%d]: ", which_bp );
  84. if( addr == 0 )
  85. printf( "NOT SET\n" );
  86. else
  87. disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
  88. }
  89. return;
  90. }
  91. /* Set a breakpoint at the address */
  92. if( !isdigit( argv[ 1 ][ 0 ]))
  93. return cmd_usage(cmdtp);
  94. addr = simple_strtoul( argv[ 1 ], NULL, 16 ) & 0xfffffffc;
  95. if(( bug_ctx.set ) && ( which_bp = (*bug_ctx.set)( 0, addr )) > 0 )
  96. {
  97. printf( "Breakpoint [%d]: ", which_bp );
  98. disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
  99. }
  100. return;
  101. } /* bedbug860_do_break */
  102. /* ======================================================================
  103. * Handle a breakpoint. First determine which breakpoint was hit by
  104. * looking at the DeBug Status Register (DBSR), clear the breakpoint
  105. * and enter a mini main loop. Stay in the loop until the stopped flag
  106. * in the debug context is cleared.
  107. * ====================================================================== */
  108. void bedbug860_break_isr( struct pt_regs *regs )
  109. {
  110. unsigned long addr; /* Address stopped at */
  111. unsigned long cause; /* Address stopped at */
  112. /* -------------------------------------------------- */
  113. cause = GET_ICR();
  114. if( !(cause & 0x00000004)) {
  115. printf( "Not an instruction breakpoint (ICR 0x%08lx)\n", cause );
  116. return;
  117. }
  118. addr = regs->nip;
  119. if( addr == GET_CMPA() )
  120. {
  121. bug_ctx.current_bp = 1;
  122. }
  123. else if( addr == GET_CMPB() )
  124. {
  125. bug_ctx.current_bp = 2;
  126. }
  127. else if( addr == GET_CMPC() )
  128. {
  129. bug_ctx.current_bp = 3;
  130. }
  131. else if( addr == GET_CMPD() )
  132. {
  133. bug_ctx.current_bp = 4;
  134. }
  135. bedbug_main_loop( addr, regs );
  136. return;
  137. } /* bedbug860_break_isr */
  138. /* ======================================================================
  139. * Look through all of the hardware breakpoints available to see if one
  140. * is unused.
  141. * ====================================================================== */
  142. int bedbug860_find_empty( void )
  143. {
  144. /* -------------------------------------------------- */
  145. if( GET_CMPA() == 0 )
  146. return 1;
  147. if( GET_CMPB() == 0 )
  148. return 2;
  149. if( GET_CMPC() == 0 )
  150. return 3;
  151. if( GET_CMPD() == 0 )
  152. return 4;
  153. return 0;
  154. } /* bedbug860_find_empty */
  155. /* ======================================================================
  156. * Set a breakpoint. If 'which_bp' is zero then find an unused breakpoint
  157. * number, otherwise reassign the given breakpoint. If hardware debugging
  158. * is not enabled, then turn it on via the MSR and DBCR0. Set the break
  159. * address in the appropriate IACx register and enable proper address
  160. * beakpoint in DBCR0.
  161. * ====================================================================== */
  162. int bedbug860_set( int which_bp, unsigned long addr )
  163. {
  164. /* -------------------------------------------------- */
  165. /* Only look if which_bp == 0, else use which_bp */
  166. if(( bug_ctx.find_empty ) && ( !which_bp ) &&
  167. ( which_bp = (*bug_ctx.find_empty)()) == 0 )
  168. {
  169. printf( "All breakpoints in use\n" );
  170. return 0;
  171. }
  172. if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
  173. {
  174. printf( "Invalid break point # %d\n", which_bp );
  175. return 0;
  176. }
  177. if( ! bug_ctx.hw_debug_enabled )
  178. {
  179. bug_ctx.hw_debug_enabled = 1;
  180. SET_DER( GET_DER() | 0x00000004 );
  181. }
  182. switch( which_bp )
  183. {
  184. case 1:
  185. SET_CMPA( addr );
  186. SET_ICTRL( GET_ICTRL() | 0x80080800 ); /* CTA=Equal,IW0=Match A,SIW0EN */
  187. break;
  188. case 2:
  189. SET_CMPB( addr );
  190. SET_ICTRL( GET_ICTRL() | 0x10020400 ); /* CTB=Equal,IW1=Match B,SIW1EN */
  191. break;
  192. case 3:
  193. SET_CMPC( addr );
  194. SET_ICTRL( GET_ICTRL() | 0x02008200 ); /* CTC=Equal,IW2=Match C,SIW2EN */
  195. break;
  196. case 4:
  197. SET_CMPD( addr );
  198. SET_ICTRL( GET_ICTRL() | 0x00404100 ); /* CTD=Equal,IW3=Match D,SIW3EN */
  199. break;
  200. }
  201. return which_bp;
  202. } /* bedbug860_set */
  203. /* ======================================================================
  204. * Disable a specific breakoint by setting the appropriate IACx register
  205. * to zero and claring the instruction address breakpoint in DBCR0.
  206. * ====================================================================== */
  207. int bedbug860_clear( int which_bp )
  208. {
  209. /* -------------------------------------------------- */
  210. if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
  211. {
  212. printf( "Invalid break point # (%d)\n", which_bp );
  213. return -1;
  214. }
  215. switch( which_bp )
  216. {
  217. case 1:
  218. SET_CMPA( 0 );
  219. SET_ICTRL( GET_ICTRL() & ~0x80080800 ); /* CTA=Equal,IW0=Match A,SIW0EN */
  220. break;
  221. case 2:
  222. SET_CMPB( 0 );
  223. SET_ICTRL( GET_ICTRL() & ~0x10020400 ); /* CTB=Equal,IW1=Match B,SIW1EN */
  224. break;
  225. case 3:
  226. SET_CMPC( 0 );
  227. SET_ICTRL( GET_ICTRL() & ~0x02008200 ); /* CTC=Equal,IW2=Match C,SIW2EN */
  228. break;
  229. case 4:
  230. SET_CMPD( 0 );
  231. SET_ICTRL( GET_ICTRL() & ~0x00404100 ); /* CTD=Equal,IW3=Match D,SIW3EN */
  232. break;
  233. }
  234. return 0;
  235. } /* bedbug860_clear */
  236. /* ====================================================================== */
  237. #endif