bedbug_860.c 7.8 KB

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