bedbug_860.c 7.8 KB

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