blob: 83db035ab5105a66dc2476de40be3da4f60de5ed [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>
wdenk1dda0b12002-08-27 10:52:29 +00008#include <bedbug/bedbug.h>
9#include <bedbug/regs.h>
10#include <bedbug/ppc.h>
wdenk57b2d802003-06-27 21:31:46 +000011#include <bedbug/type.h>
wdenk1dda0b12002-08-27 10:52:29 +000012
Jon Loeliger526e5ce2007-07-09 19:06:00 -050013#if defined(CONFIG_CMD_BEDBUG) && defined(CONFIG_8xx)
wdenk1dda0b12002-08-27 10:52:29 +000014
15#define MAX_BREAK_POINTS 2
16
17extern CPU_DEBUG_CTX bug_ctx;
18
19void bedbug860_init __P((void));
Wolfgang Denk6262d0212010-06-28 22:00:46 +020020void bedbug860_do_break __P((cmd_tbl_t*,int,int,char*const[]));
wdenk1dda0b12002-08-27 10:52:29 +000021void bedbug860_break_isr __P((struct pt_regs*));
22int bedbug860_find_empty __P((void));
23int bedbug860_set __P((int,unsigned long));
24int bedbug860_clear __P((int));
25
26
27/* ======================================================================
28 * Initialize the global bug_ctx structure for the MPC860. Clear all
29 * of the breakpoints.
30 * ====================================================================== */
31
32void bedbug860_init( void )
33{
34 int i;
35 /* -------------------------------------------------- */
36
37 bug_ctx.hw_debug_enabled = 0;
38 bug_ctx.stopped = 0;
39 bug_ctx.current_bp = 0;
40 bug_ctx.regs = NULL;
41
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;
47
48 for( i = 1; i <= MAX_BREAK_POINTS; ++i )
49 (*bug_ctx.clear)( i );
50
51 puts ("BEDBUG:ready\n");
52 return;
53} /* bedbug_init_breakpoints */
54
55
56
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 * ====================================================================== */
64
65void bedbug860_do_break (cmd_tbl_t *cmdtp, int flag, int argc,
Wolfgang Denk6262d0212010-06-28 22:00:46 +020066 char * const argv[])
wdenk1dda0b12002-08-27 10:52:29 +000067{
68 long addr = 0; /* Address to break at */
69 int which_bp; /* Breakpoint number */
70 /* -------------------------------------------------- */
71
72 if (argc < 2)
Wolfgang Denk3b683112010-07-17 01:06:04 +020073 return cmd_usage(cmdtp);
wdenk1dda0b12002-08-27 10:52:29 +000074
75 /* Turn off a breakpoint */
76
77 if( strcmp( argv[ 1 ], "off" ) == 0 )
78 {
79 if( bug_ctx.hw_debug_enabled == 0 )
80 {
81 printf( "No breakpoints enabled\n" );
82 return;
83 }
84
85 which_bp = simple_strtoul( argv[ 2 ], NULL, 10 );
86
87 if( bug_ctx.clear )
88 (*bug_ctx.clear)( which_bp );
89
90 printf( "Breakpoint %d removed\n", which_bp );
91 return;
92 }
93
94 /* Show a list of breakpoints */
95
96 if( strcmp( argv[ 1 ], "show" ) == 0 )
97 {
98 for( which_bp = 1; which_bp <= MAX_BREAK_POINTS; ++which_bp )
99 {
100
101 switch( which_bp )
102 {
103 case 1: addr = GET_CMPA(); break;
104 case 2: addr = GET_CMPB(); break;
105 case 3: addr = GET_CMPC(); break;
106 case 4: addr = GET_CMPD(); break;
107 }
108
109 printf( "Breakpoint [%d]: ", which_bp );
110 if( addr == 0 )
111 printf( "NOT SET\n" );
112 else
113 disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
114 }
115 return;
116 }
117
118 /* Set a breakpoint at the address */
119
120 if( !isdigit( argv[ 1 ][ 0 ]))
Wolfgang Denk3b683112010-07-17 01:06:04 +0200121 return cmd_usage(cmdtp);
wdenk1dda0b12002-08-27 10:52:29 +0000122
123 addr = simple_strtoul( argv[ 1 ], NULL, 16 ) & 0xfffffffc;
124
125 if(( bug_ctx.set ) && ( which_bp = (*bug_ctx.set)( 0, addr )) > 0 )
126 {
127 printf( "Breakpoint [%d]: ", which_bp );
128 disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
129 }
130
131 return;
132} /* bedbug860_do_break */
133
134
135
136/* ======================================================================
137 * Handle a breakpoint. First determine which breakpoint was hit by
138 * looking at the DeBug Status Register (DBSR), clear the breakpoint
139 * and enter a mini main loop. Stay in the loop until the stopped flag
140 * in the debug context is cleared.
141 * ====================================================================== */
142
143void bedbug860_break_isr( struct pt_regs *regs )
144{
145 unsigned long addr; /* Address stopped at */
146 unsigned long cause; /* Address stopped at */
147 /* -------------------------------------------------- */
148
149 cause = GET_ICR();
150
151 if( !(cause & 0x00000004)) {
152 printf( "Not an instruction breakpoint (ICR 0x%08lx)\n", cause );
153 return;
154 }
155
156 addr = regs->nip;
157
158 if( addr == GET_CMPA() )
159 {
160 bug_ctx.current_bp = 1;
161 }
162 else if( addr == GET_CMPB() )
163 {
164 bug_ctx.current_bp = 2;
165 }
166 else if( addr == GET_CMPC() )
167 {
168 bug_ctx.current_bp = 3;
169 }
170 else if( addr == GET_CMPD() )
171 {
172 bug_ctx.current_bp = 4;
173 }
174
175 bedbug_main_loop( addr, regs );
176 return;
177} /* bedbug860_break_isr */
178
179
180
181/* ======================================================================
182 * Look through all of the hardware breakpoints available to see if one
183 * is unused.
184 * ====================================================================== */
185
186int bedbug860_find_empty( void )
187{
188 /* -------------------------------------------------- */
189
190 if( GET_CMPA() == 0 )
191 return 1;
192
193 if( GET_CMPB() == 0 )
194 return 2;
195
196 if( GET_CMPC() == 0 )
197 return 3;
198
199 if( GET_CMPD() == 0 )
200 return 4;
201
202 return 0;
203} /* bedbug860_find_empty */
204
205
206
207/* ======================================================================
208 * Set a breakpoint. If 'which_bp' is zero then find an unused breakpoint
209 * number, otherwise reassign the given breakpoint. If hardware debugging
210 * is not enabled, then turn it on via the MSR and DBCR0. Set the break
211 * address in the appropriate IACx register and enable proper address
212 * beakpoint in DBCR0.
213 * ====================================================================== */
214
215int bedbug860_set( int which_bp, unsigned long addr )
216{
217 /* -------------------------------------------------- */
218
219 /* Only look if which_bp == 0, else use which_bp */
220 if(( bug_ctx.find_empty ) && ( !which_bp ) &&
221 ( which_bp = (*bug_ctx.find_empty)()) == 0 )
222 {
223 printf( "All breakpoints in use\n" );
224 return 0;
225 }
226
227 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
228 {
229 printf( "Invalid break point # %d\n", which_bp );
230 return 0;
231 }
232
233 if( ! bug_ctx.hw_debug_enabled )
234 {
235 bug_ctx.hw_debug_enabled = 1;
236 SET_DER( GET_DER() | 0x00000004 );
237 }
238
239 switch( which_bp )
240 {
241 case 1:
242 SET_CMPA( addr );
243 SET_ICTRL( GET_ICTRL() | 0x80080800 ); /* CTA=Equal,IW0=Match A,SIW0EN */
244 break;
245
246 case 2:
247 SET_CMPB( addr );
248 SET_ICTRL( GET_ICTRL() | 0x10020400 ); /* CTB=Equal,IW1=Match B,SIW1EN */
249 break;
250
251 case 3:
252 SET_CMPC( addr );
253 SET_ICTRL( GET_ICTRL() | 0x02008200 ); /* CTC=Equal,IW2=Match C,SIW2EN */
254 break;
255
256 case 4:
257 SET_CMPD( addr );
258 SET_ICTRL( GET_ICTRL() | 0x00404100 ); /* CTD=Equal,IW3=Match D,SIW3EN */
259 break;
260 }
261
262 return which_bp;
263} /* bedbug860_set */
264
265
266
267/* ======================================================================
268 * Disable a specific breakoint by setting the appropriate IACx register
269 * to zero and claring the instruction address breakpoint in DBCR0.
270 * ====================================================================== */
271
272int bedbug860_clear( int which_bp )
273{
274 /* -------------------------------------------------- */
275
276 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
277 {
278 printf( "Invalid break point # (%d)\n", which_bp );
279 return -1;
280 }
281
282 switch( which_bp )
283 {
284 case 1:
285 SET_CMPA( 0 );
286 SET_ICTRL( GET_ICTRL() & ~0x80080800 ); /* CTA=Equal,IW0=Match A,SIW0EN */
287 break;
288
289 case 2:
290 SET_CMPB( 0 );
291 SET_ICTRL( GET_ICTRL() & ~0x10020400 ); /* CTB=Equal,IW1=Match B,SIW1EN */
292 break;
293
294 case 3:
295 SET_CMPC( 0 );
296 SET_ICTRL( GET_ICTRL() & ~0x02008200 ); /* CTC=Equal,IW2=Match C,SIW2EN */
297 break;
298
299 case 4:
300 SET_CMPD( 0 );
301 SET_ICTRL( GET_ICTRL() & ~0x00404100 ); /* CTD=Equal,IW3=Match D,SIW3EN */
302 break;
303 }
304
305 return 0;
306} /* bedbug860_clear */
307
308
309/* ====================================================================== */
310#endif