2 * Bedbug Functions specific to the MPC860 chip
7 #include <linux/ctype.h>
8 #include <bedbug/bedbug.h>
9 #include <bedbug/regs.h>
10 #include <bedbug/ppc.h>
11 #include <bedbug/type.h>
13 #if defined(CONFIG_CMD_BEDBUG) && defined(CONFIG_8xx)
15 #define MAX_BREAK_POINTS 2
17 extern CPU_DEBUG_CTX bug_ctx;
19 void bedbug860_init __P((void));
20 void bedbug860_do_break __P((cmd_tbl_t*,int,int,char*const[]));
21 void bedbug860_break_isr __P((struct pt_regs*));
22 int bedbug860_find_empty __P((void));
23 int bedbug860_set __P((int,unsigned long));
24 int bedbug860_clear __P((int));
27 /* ======================================================================
28 * Initialize the global bug_ctx structure for the MPC860. Clear all
30 * ====================================================================== */
32 void bedbug860_init( void )
35 /* -------------------------------------------------- */
37 bug_ctx.hw_debug_enabled = 0;
39 bug_ctx.current_bp = 0;
42 bug_ctx.do_break = bedbug860_do_break;
43 bug_ctx.break_isr = bedbug860_break_isr;
44 bug_ctx.find_empty = bedbug860_find_empty;
45 bug_ctx.set = bedbug860_set;
46 bug_ctx.clear = bedbug860_clear;
48 for( i = 1; i <= MAX_BREAK_POINTS; ++i )
49 (*bug_ctx.clear)( i );
51 puts ("BEDBUG:ready\n");
53 } /* bedbug_init_breakpoints */
57 /* ======================================================================
58 * Set/clear/show one of the hardware breakpoints for the 860. The "off"
59 * string will disable a specific breakpoint. The "show" string will
60 * display the current breakpoints. Otherwise an address will set a
61 * breakpoint at that address. Setting a breakpoint uses the CPU-specific
62 * set routine which will assign a breakpoint number.
63 * ====================================================================== */
65 void bedbug860_do_break (cmd_tbl_t *cmdtp, int flag, int argc,
68 long addr = 0; /* Address to break at */
69 int which_bp; /* Breakpoint number */
70 /* -------------------------------------------------- */
77 /* Turn off a breakpoint */
79 if( strcmp( argv[ 1 ], "off" ) == 0 )
81 if( bug_ctx.hw_debug_enabled == 0 )
83 printf( "No breakpoints enabled\n" );
87 which_bp = simple_strtoul( argv[ 2 ], NULL, 10 );
90 (*bug_ctx.clear)( which_bp );
92 printf( "Breakpoint %d removed\n", which_bp );
96 /* Show a list of breakpoints */
98 if( strcmp( argv[ 1 ], "show" ) == 0 )
100 for( which_bp = 1; which_bp <= MAX_BREAK_POINTS; ++which_bp )
105 case 1: addr = GET_CMPA(); break;
106 case 2: addr = GET_CMPB(); break;
107 case 3: addr = GET_CMPC(); break;
108 case 4: addr = GET_CMPD(); break;
111 printf( "Breakpoint [%d]: ", which_bp );
113 printf( "NOT SET\n" );
115 disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
120 /* Set a breakpoint at the address */
122 if( !isdigit( argv[ 1 ][ 0 ])) {
127 addr = simple_strtoul( argv[ 1 ], NULL, 16 ) & 0xfffffffc;
129 if(( bug_ctx.set ) && ( which_bp = (*bug_ctx.set)( 0, addr )) > 0 )
131 printf( "Breakpoint [%d]: ", which_bp );
132 disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
136 } /* bedbug860_do_break */
140 /* ======================================================================
141 * Handle a breakpoint. First determine which breakpoint was hit by
142 * looking at the DeBug Status Register (DBSR), clear the breakpoint
143 * and enter a mini main loop. Stay in the loop until the stopped flag
144 * in the debug context is cleared.
145 * ====================================================================== */
147 void bedbug860_break_isr( struct pt_regs *regs )
149 unsigned long addr; /* Address stopped at */
150 unsigned long cause; /* Address stopped at */
151 /* -------------------------------------------------- */
155 if( !(cause & 0x00000004)) {
156 printf( "Not an instruction breakpoint (ICR 0x%08lx)\n", cause );
162 if( addr == GET_CMPA() )
164 bug_ctx.current_bp = 1;
166 else if( addr == GET_CMPB() )
168 bug_ctx.current_bp = 2;
170 else if( addr == GET_CMPC() )
172 bug_ctx.current_bp = 3;
174 else if( addr == GET_CMPD() )
176 bug_ctx.current_bp = 4;
179 bedbug_main_loop( addr, regs );
181 } /* bedbug860_break_isr */
185 /* ======================================================================
186 * Look through all of the hardware breakpoints available to see if one
188 * ====================================================================== */
190 int bedbug860_find_empty( void )
192 /* -------------------------------------------------- */
194 if( GET_CMPA() == 0 )
197 if( GET_CMPB() == 0 )
200 if( GET_CMPC() == 0 )
203 if( GET_CMPD() == 0 )
207 } /* bedbug860_find_empty */
211 /* ======================================================================
212 * Set a breakpoint. If 'which_bp' is zero then find an unused breakpoint
213 * number, otherwise reassign the given breakpoint. If hardware debugging
214 * is not enabled, then turn it on via the MSR and DBCR0. Set the break
215 * address in the appropriate IACx register and enable proper address
216 * beakpoint in DBCR0.
217 * ====================================================================== */
219 int bedbug860_set( int which_bp, unsigned long addr )
221 /* -------------------------------------------------- */
223 /* Only look if which_bp == 0, else use which_bp */
224 if(( bug_ctx.find_empty ) && ( !which_bp ) &&
225 ( which_bp = (*bug_ctx.find_empty)()) == 0 )
227 printf( "All breakpoints in use\n" );
231 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
233 printf( "Invalid break point # %d\n", which_bp );
237 if( ! bug_ctx.hw_debug_enabled )
239 bug_ctx.hw_debug_enabled = 1;
240 SET_DER( GET_DER() | 0x00000004 );
247 SET_ICTRL( GET_ICTRL() | 0x80080800 ); /* CTA=Equal,IW0=Match A,SIW0EN */
252 SET_ICTRL( GET_ICTRL() | 0x10020400 ); /* CTB=Equal,IW1=Match B,SIW1EN */
257 SET_ICTRL( GET_ICTRL() | 0x02008200 ); /* CTC=Equal,IW2=Match C,SIW2EN */
262 SET_ICTRL( GET_ICTRL() | 0x00404100 ); /* CTD=Equal,IW3=Match D,SIW3EN */
267 } /* bedbug860_set */
271 /* ======================================================================
272 * Disable a specific breakoint by setting the appropriate IACx register
273 * to zero and claring the instruction address breakpoint in DBCR0.
274 * ====================================================================== */
276 int bedbug860_clear( int which_bp )
278 /* -------------------------------------------------- */
280 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
282 printf( "Invalid break point # (%d)\n", which_bp );
290 SET_ICTRL( GET_ICTRL() & ~0x80080800 ); /* CTA=Equal,IW0=Match A,SIW0EN */
295 SET_ICTRL( GET_ICTRL() & ~0x10020400 ); /* CTB=Equal,IW1=Match B,SIW1EN */
300 SET_ICTRL( GET_ICTRL() & ~0x02008200 ); /* CTC=Equal,IW2=Match C,SIW2EN */
305 SET_ICTRL( GET_ICTRL() & ~0x00404100 ); /* CTD=Equal,IW3=Match D,SIW3EN */
310 } /* bedbug860_clear */
313 /* ====================================================================== */