2 * Bedbug Functions specific to the MPC860 chip
7 #include <linux/ctype.h>
9 #include <cmd_bedbug.h>
10 #include <bedbug/bedbug.h>
11 #include <bedbug/regs.h>
12 #include <bedbug/ppc.h>
14 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG) && defined(CONFIG_MPC860)
16 #define MAX_BREAK_POINTS 2
18 extern CPU_DEBUG_CTX bug_ctx;
20 void bedbug860_init __P((void));
21 void bedbug860_do_break __P((cmd_tbl_t*,int,int,char*[]));
22 void bedbug860_break_isr __P((struct pt_regs*));
23 int bedbug860_find_empty __P((void));
24 int bedbug860_set __P((int,unsigned long));
25 int bedbug860_clear __P((int));
28 /* ======================================================================
29 * Initialize the global bug_ctx structure for the MPC860. Clear all
31 * ====================================================================== */
33 void bedbug860_init( void )
36 /* -------------------------------------------------- */
38 bug_ctx.hw_debug_enabled = 0;
40 bug_ctx.current_bp = 0;
43 bug_ctx.do_break = bedbug860_do_break;
44 bug_ctx.break_isr = bedbug860_break_isr;
45 bug_ctx.find_empty = bedbug860_find_empty;
46 bug_ctx.set = bedbug860_set;
47 bug_ctx.clear = bedbug860_clear;
49 for( i = 1; i <= MAX_BREAK_POINTS; ++i )
50 (*bug_ctx.clear)( i );
52 puts ("BEDBUG:ready\n");
54 } /* bedbug_init_breakpoints */
58 /* ======================================================================
59 * Set/clear/show one of the hardware breakpoints for the 860. The "off"
60 * string will disable a specific breakpoint. The "show" string will
61 * display the current breakpoints. Otherwise an address will set a
62 * breakpoint at that address. Setting a breakpoint uses the CPU-specific
63 * set routine which will assign a breakpoint number.
64 * ====================================================================== */
66 void bedbug860_do_break (cmd_tbl_t *cmdtp, int flag, int argc,
69 long addr = 0; /* Address to break at */
70 int which_bp; /* Breakpoint number */
71 /* -------------------------------------------------- */
75 printf ("Usage:\n%s\n", cmdtp->usage);
79 /* Turn off a breakpoint */
81 if( strcmp( argv[ 1 ], "off" ) == 0 )
83 if( bug_ctx.hw_debug_enabled == 0 )
85 printf( "No breakpoints enabled\n" );
89 which_bp = simple_strtoul( argv[ 2 ], NULL, 10 );
92 (*bug_ctx.clear)( which_bp );
94 printf( "Breakpoint %d removed\n", which_bp );
98 /* Show a list of breakpoints */
100 if( strcmp( argv[ 1 ], "show" ) == 0 )
102 for( which_bp = 1; which_bp <= MAX_BREAK_POINTS; ++which_bp )
107 case 1: addr = GET_CMPA(); break;
108 case 2: addr = GET_CMPB(); break;
109 case 3: addr = GET_CMPC(); break;
110 case 4: addr = GET_CMPD(); break;
113 printf( "Breakpoint [%d]: ", which_bp );
115 printf( "NOT SET\n" );
117 disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
122 /* Set a breakpoint at the address */
124 if( !isdigit( argv[ 1 ][ 0 ]))
126 printf ("Usage:\n%s\n", cmdtp->usage);
130 addr = simple_strtoul( argv[ 1 ], NULL, 16 ) & 0xfffffffc;
132 if(( bug_ctx.set ) && ( which_bp = (*bug_ctx.set)( 0, addr )) > 0 )
134 printf( "Breakpoint [%d]: ", which_bp );
135 disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
139 } /* bedbug860_do_break */
143 /* ======================================================================
144 * Handle a breakpoint. First determine which breakpoint was hit by
145 * looking at the DeBug Status Register (DBSR), clear the breakpoint
146 * and enter a mini main loop. Stay in the loop until the stopped flag
147 * in the debug context is cleared.
148 * ====================================================================== */
150 void bedbug860_break_isr( struct pt_regs *regs )
152 unsigned long addr; /* Address stopped at */
153 unsigned long cause; /* Address stopped at */
154 /* -------------------------------------------------- */
158 if( !(cause & 0x00000004)) {
159 printf( "Not an instruction breakpoint (ICR 0x%08lx)\n", cause );
165 if( addr == GET_CMPA() )
167 bug_ctx.current_bp = 1;
169 else if( addr == GET_CMPB() )
171 bug_ctx.current_bp = 2;
173 else if( addr == GET_CMPC() )
175 bug_ctx.current_bp = 3;
177 else if( addr == GET_CMPD() )
179 bug_ctx.current_bp = 4;
182 bedbug_main_loop( addr, regs );
184 } /* bedbug860_break_isr */
188 /* ======================================================================
189 * Look through all of the hardware breakpoints available to see if one
191 * ====================================================================== */
193 int bedbug860_find_empty( void )
195 /* -------------------------------------------------- */
197 if( GET_CMPA() == 0 )
200 if( GET_CMPB() == 0 )
203 if( GET_CMPC() == 0 )
206 if( GET_CMPD() == 0 )
210 } /* bedbug860_find_empty */
214 /* ======================================================================
215 * Set a breakpoint. If 'which_bp' is zero then find an unused breakpoint
216 * number, otherwise reassign the given breakpoint. If hardware debugging
217 * is not enabled, then turn it on via the MSR and DBCR0. Set the break
218 * address in the appropriate IACx register and enable proper address
219 * beakpoint in DBCR0.
220 * ====================================================================== */
222 int bedbug860_set( int which_bp, unsigned long addr )
224 /* -------------------------------------------------- */
226 /* Only look if which_bp == 0, else use which_bp */
227 if(( bug_ctx.find_empty ) && ( !which_bp ) &&
228 ( which_bp = (*bug_ctx.find_empty)()) == 0 )
230 printf( "All breakpoints in use\n" );
234 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
236 printf( "Invalid break point # %d\n", which_bp );
240 if( ! bug_ctx.hw_debug_enabled )
242 bug_ctx.hw_debug_enabled = 1;
243 SET_DER( GET_DER() | 0x00000004 );
250 SET_ICTRL( GET_ICTRL() | 0x80080800 ); /* CTA=Equal,IW0=Match A,SIW0EN */
255 SET_ICTRL( GET_ICTRL() | 0x10020400 ); /* CTB=Equal,IW1=Match B,SIW1EN */
260 SET_ICTRL( GET_ICTRL() | 0x02008200 ); /* CTC=Equal,IW2=Match C,SIW2EN */
265 SET_ICTRL( GET_ICTRL() | 0x00404100 ); /* CTD=Equal,IW3=Match D,SIW3EN */
270 } /* bedbug860_set */
274 /* ======================================================================
275 * Disable a specific breakoint by setting the appropriate IACx register
276 * to zero and claring the instruction address breakpoint in DBCR0.
277 * ====================================================================== */
279 int bedbug860_clear( int which_bp )
281 /* -------------------------------------------------- */
283 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
285 printf( "Invalid break point # (%d)\n", which_bp );
293 SET_ICTRL( GET_ICTRL() & ~0x80080800 ); /* CTA=Equal,IW0=Match A,SIW0EN */
298 SET_ICTRL( GET_ICTRL() & ~0x10020400 ); /* CTB=Equal,IW1=Match B,SIW1EN */
303 SET_ICTRL( GET_ICTRL() & ~0x02008200 ); /* CTC=Equal,IW2=Match C,SIW2EN */
308 SET_ICTRL( GET_ICTRL() & ~0x00404100 ); /* CTD=Equal,IW3=Match D,SIW3EN */
313 } /* bedbug860_clear */
316 /* ====================================================================== */