2 * Bedbug Functions specific to the MPC603e core
7 #include <linux/ctype.h>
8 #include <bedbug/type.h>
9 #include <bedbug/bedbug.h>
10 #include <bedbug/regs.h>
11 #include <bedbug/ppc.h>
13 #if defined(CONFIG_CMD_BEDBUG) \
14 && (defined(CONFIG_MPC824X) || defined(CONFIG_MPC8260))
16 #define MAX_BREAK_POINTS 1
18 extern CPU_DEBUG_CTX bug_ctx;
20 void bedbug603e_init __P((void));
21 void bedbug603e_do_break __P((cmd_tbl_t*,int,int,char*const[]));
22 void bedbug603e_break_isr __P((struct pt_regs*));
23 int bedbug603e_find_empty __P((void));
24 int bedbug603e_set __P((int,unsigned long));
25 int bedbug603e_clear __P((int));
28 /* ======================================================================
29 * Initialize the global bug_ctx structure for the processor. Clear all
31 * ====================================================================== */
33 void bedbug603e_init( void )
36 /* -------------------------------------------------- */
38 bug_ctx.hw_debug_enabled = 0;
40 bug_ctx.current_bp = 0;
43 bug_ctx.do_break = bedbug603e_do_break;
44 bug_ctx.break_isr = bedbug603e_break_isr;
45 bug_ctx.find_empty = bedbug603e_find_empty;
46 bug_ctx.set = bedbug603e_set;
47 bug_ctx.clear = bedbug603e_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 the hardware breakpoint for the 603e. 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 bedbug603e_do_break (cmd_tbl_t *cmdtp, int flag, int argc,
69 long addr; /* Address to break at */
70 int which_bp; /* Breakpoint number */
71 /* -------------------------------------------------- */
78 /* Turn off a breakpoint */
80 if( strcmp( argv[ 1 ], "off" ) == 0 )
82 if( bug_ctx.hw_debug_enabled == 0 )
84 puts ( "No breakpoints enabled\n" );
88 which_bp = simple_strtoul( argv[ 2 ], NULL, 10 );
91 (*bug_ctx.clear)( which_bp );
93 printf( "Breakpoint %d removed\n", which_bp );
97 /* Show a list of breakpoints */
99 if( strcmp( argv[ 1 ], "show" ) == 0 )
101 for( which_bp = 1; which_bp <= MAX_BREAK_POINTS; ++which_bp )
106 printf( "Breakpoint [%d]: ", which_bp );
107 if( (addr & 0x00000002) == 0 )
108 puts ( "NOT SET\n" );
110 disppc( (unsigned char *)(addr & 0xFFFFFFFC), 0, 1, bedbug_puts, F_RADHEX );
115 /* Set a breakpoint at the address */
117 if(!(( isdigit( argv[ 1 ][ 0 ] )) ||
118 (( argv[ 1 ][ 0 ] >= 'a' ) && ( argv[ 1 ][ 0 ] <= 'f' )) ||
119 (( argv[ 1 ][ 0 ] >= 'A' ) && ( argv[ 1 ][ 0 ] <= 'F' )))) {
124 addr = simple_strtoul( argv[ 1 ], NULL, 16 );
126 if(( bug_ctx.set ) && ( which_bp = (*bug_ctx.set)( 0, addr )) > 0 )
128 printf( "Breakpoint [%d]: ", which_bp );
129 disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
133 } /* bedbug603e_do_break */
137 /* ======================================================================
138 * Handle a breakpoint. Enter a mini main loop. Stay in the loop until
139 * the stopped flag in the debug context is cleared.
140 * ====================================================================== */
142 void bedbug603e_break_isr( struct pt_regs *regs )
144 unsigned long addr; /* Address stopped at */
145 /* -------------------------------------------------- */
147 bug_ctx.current_bp = 1;
148 addr = GET_IABR() & 0xFFFFFFFC;
150 bedbug_main_loop( addr, regs );
152 } /* bedbug603e_break_isr */
156 /* ======================================================================
157 * See if the hardware breakpoint is available.
158 * ====================================================================== */
160 int bedbug603e_find_empty( void )
162 /* -------------------------------------------------- */
164 if( (GET_IABR() && 0x00000002) == 0 )
168 } /* bedbug603e_find_empty */
172 /* ======================================================================
173 * Set a breakpoint. If 'which_bp' is zero then find an unused breakpoint
174 * number, otherwise reassign the given breakpoint. If hardware debugging
175 * is not enabled, then turn it on via the MSR and DBCR0. Set the break
176 * address in the IABR register.
177 * ====================================================================== */
179 int bedbug603e_set( int which_bp, unsigned long addr )
181 /* -------------------------------------------------- */
183 if(( addr & 0x00000003 ) != 0 )
185 puts ( "Breakpoints must be on a 32 bit boundary\n" );
189 /* Only look if which_bp == 0, else use which_bp */
190 if(( bug_ctx.find_empty ) && ( !which_bp ) &&
191 ( which_bp = (*bug_ctx.find_empty)()) == 0 )
193 puts ( "All breakpoints in use\n" );
197 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
199 printf( "Invalid break point # %d\n", which_bp );
203 if( ! bug_ctx.hw_debug_enabled )
205 bug_ctx.hw_debug_enabled = 1;
208 SET_IABR( addr | 0x00000002 );
211 } /* bedbug603e_set */
215 /* ======================================================================
216 * Disable a specific breakoint by setting the IABR register to zero.
217 * ====================================================================== */
219 int bedbug603e_clear( int which_bp )
221 /* -------------------------------------------------- */
223 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
225 printf( "Invalid break point # (%d)\n", which_bp );
232 } /* bedbug603e_clear */
235 /* ====================================================================== */