blob: b90782ef290625ad0e6b9818bc3234bab6ab4f88 [file] [log] [blame]
wdenk1dda0b12002-08-27 10:52:29 +00001/*
2 * Bedbug Functions specific to the MPC860 chip
3 */
4
5#include <common.h>
6#include <command.h>
7#include <linux/ctype.h>
8
9#include <cmd_bedbug.h>
10#include <bedbug/bedbug.h>
11#include <bedbug/regs.h>
12#include <bedbug/ppc.h>
13
wdenk6bd14892003-04-10 11:18:18 +000014#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG) && defined(CONFIG_8xx)
wdenk1dda0b12002-08-27 10:52:29 +000015
16#define MAX_BREAK_POINTS 2
17
18extern CPU_DEBUG_CTX bug_ctx;
19
20void bedbug860_init __P((void));
21void bedbug860_do_break __P((cmd_tbl_t*,int,int,char*[]));
22void bedbug860_break_isr __P((struct pt_regs*));
23int bedbug860_find_empty __P((void));
24int bedbug860_set __P((int,unsigned long));
25int bedbug860_clear __P((int));
26
27
28/* ======================================================================
29 * Initialize the global bug_ctx structure for the MPC860. Clear all
30 * of the breakpoints.
31 * ====================================================================== */
32
33void bedbug860_init( void )
34{
35 int i;
36 /* -------------------------------------------------- */
37
38 bug_ctx.hw_debug_enabled = 0;
39 bug_ctx.stopped = 0;
40 bug_ctx.current_bp = 0;
41 bug_ctx.regs = NULL;
42
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;
48
49 for( i = 1; i <= MAX_BREAK_POINTS; ++i )
50 (*bug_ctx.clear)( i );
51
52 puts ("BEDBUG:ready\n");
53 return;
54} /* bedbug_init_breakpoints */
55
56
57
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 * ====================================================================== */
65
66void bedbug860_do_break (cmd_tbl_t *cmdtp, int flag, int argc,
67 char *argv[])
68{
69 long addr = 0; /* Address to break at */
70 int which_bp; /* Breakpoint number */
71 /* -------------------------------------------------- */
72
73 if (argc < 2)
74 {
75 printf ("Usage:\n%s\n", cmdtp->usage);
76 return;
77 }
78
79 /* Turn off a breakpoint */
80
81 if( strcmp( argv[ 1 ], "off" ) == 0 )
82 {
83 if( bug_ctx.hw_debug_enabled == 0 )
84 {
85 printf( "No breakpoints enabled\n" );
86 return;
87 }
88
89 which_bp = simple_strtoul( argv[ 2 ], NULL, 10 );
90
91 if( bug_ctx.clear )
92 (*bug_ctx.clear)( which_bp );
93
94 printf( "Breakpoint %d removed\n", which_bp );
95 return;
96 }
97
98 /* Show a list of breakpoints */
99
100 if( strcmp( argv[ 1 ], "show" ) == 0 )
101 {
102 for( which_bp = 1; which_bp <= MAX_BREAK_POINTS; ++which_bp )
103 {
104
105 switch( which_bp )
106 {
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;
111 }
112
113 printf( "Breakpoint [%d]: ", which_bp );
114 if( addr == 0 )
115 printf( "NOT SET\n" );
116 else
117 disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
118 }
119 return;
120 }
121
122 /* Set a breakpoint at the address */
123
124 if( !isdigit( argv[ 1 ][ 0 ]))
125 {
126 printf ("Usage:\n%s\n", cmdtp->usage);
127 return;
128 }
129
130 addr = simple_strtoul( argv[ 1 ], NULL, 16 ) & 0xfffffffc;
131
132 if(( bug_ctx.set ) && ( which_bp = (*bug_ctx.set)( 0, addr )) > 0 )
133 {
134 printf( "Breakpoint [%d]: ", which_bp );
135 disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
136 }
137
138 return;
139} /* bedbug860_do_break */
140
141
142
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 * ====================================================================== */
149
150void bedbug860_break_isr( struct pt_regs *regs )
151{
152 unsigned long addr; /* Address stopped at */
153 unsigned long cause; /* Address stopped at */
154 /* -------------------------------------------------- */
155
156 cause = GET_ICR();
157
158 if( !(cause & 0x00000004)) {
159 printf( "Not an instruction breakpoint (ICR 0x%08lx)\n", cause );
160 return;
161 }
162
163 addr = regs->nip;
164
165 if( addr == GET_CMPA() )
166 {
167 bug_ctx.current_bp = 1;
168 }
169 else if( addr == GET_CMPB() )
170 {
171 bug_ctx.current_bp = 2;
172 }
173 else if( addr == GET_CMPC() )
174 {
175 bug_ctx.current_bp = 3;
176 }
177 else if( addr == GET_CMPD() )
178 {
179 bug_ctx.current_bp = 4;
180 }
181
182 bedbug_main_loop( addr, regs );
183 return;
184} /* bedbug860_break_isr */
185
186
187
188/* ======================================================================
189 * Look through all of the hardware breakpoints available to see if one
190 * is unused.
191 * ====================================================================== */
192
193int bedbug860_find_empty( void )
194{
195 /* -------------------------------------------------- */
196
197 if( GET_CMPA() == 0 )
198 return 1;
199
200 if( GET_CMPB() == 0 )
201 return 2;
202
203 if( GET_CMPC() == 0 )
204 return 3;
205
206 if( GET_CMPD() == 0 )
207 return 4;
208
209 return 0;
210} /* bedbug860_find_empty */
211
212
213
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 * ====================================================================== */
221
222int bedbug860_set( int which_bp, unsigned long addr )
223{
224 /* -------------------------------------------------- */
225
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 )
229 {
230 printf( "All breakpoints in use\n" );
231 return 0;
232 }
233
234 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
235 {
236 printf( "Invalid break point # %d\n", which_bp );
237 return 0;
238 }
239
240 if( ! bug_ctx.hw_debug_enabled )
241 {
242 bug_ctx.hw_debug_enabled = 1;
243 SET_DER( GET_DER() | 0x00000004 );
244 }
245
246 switch( which_bp )
247 {
248 case 1:
249 SET_CMPA( addr );
250 SET_ICTRL( GET_ICTRL() | 0x80080800 ); /* CTA=Equal,IW0=Match A,SIW0EN */
251 break;
252
253 case 2:
254 SET_CMPB( addr );
255 SET_ICTRL( GET_ICTRL() | 0x10020400 ); /* CTB=Equal,IW1=Match B,SIW1EN */
256 break;
257
258 case 3:
259 SET_CMPC( addr );
260 SET_ICTRL( GET_ICTRL() | 0x02008200 ); /* CTC=Equal,IW2=Match C,SIW2EN */
261 break;
262
263 case 4:
264 SET_CMPD( addr );
265 SET_ICTRL( GET_ICTRL() | 0x00404100 ); /* CTD=Equal,IW3=Match D,SIW3EN */
266 break;
267 }
268
269 return which_bp;
270} /* bedbug860_set */
271
272
273
274/* ======================================================================
275 * Disable a specific breakoint by setting the appropriate IACx register
276 * to zero and claring the instruction address breakpoint in DBCR0.
277 * ====================================================================== */
278
279int bedbug860_clear( int which_bp )
280{
281 /* -------------------------------------------------- */
282
283 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
284 {
285 printf( "Invalid break point # (%d)\n", which_bp );
286 return -1;
287 }
288
289 switch( which_bp )
290 {
291 case 1:
292 SET_CMPA( 0 );
293 SET_ICTRL( GET_ICTRL() & ~0x80080800 ); /* CTA=Equal,IW0=Match A,SIW0EN */
294 break;
295
296 case 2:
297 SET_CMPB( 0 );
298 SET_ICTRL( GET_ICTRL() & ~0x10020400 ); /* CTB=Equal,IW1=Match B,SIW1EN */
299 break;
300
301 case 3:
302 SET_CMPC( 0 );
303 SET_ICTRL( GET_ICTRL() & ~0x02008200 ); /* CTC=Equal,IW2=Match C,SIW2EN */
304 break;
305
306 case 4:
307 SET_CMPD( 0 );
308 SET_ICTRL( GET_ICTRL() & ~0x00404100 ); /* CTD=Equal,IW3=Match D,SIW3EN */
309 break;
310 }
311
312 return 0;
313} /* bedbug860_clear */
314
315
316/* ====================================================================== */
317#endif
318