1
2
3
4
5#include <common.h>
6#include <command.h>
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>
12
13#if defined(CONFIG_CMD_BEDBUG) && defined(CONFIG_8xx)
14
15#define MAX_BREAK_POINTS 2
16
17extern CPU_DEBUG_CTX bug_ctx;
18
19void bedbug860_init __P((void));
20void bedbug860_do_break __P((cmd_tbl_t*,int,int,char*const[]));
21void 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
29
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}
54
55
56
57
58
59
60
61
62
63
64
65void bedbug860_do_break (cmd_tbl_t *cmdtp, int flag, int argc,
66 char * const argv[])
67{
68 long addr = 0;
69 int which_bp;
70
71
72 if (argc < 2) {
73 cmd_usage(cmdtp);
74 return;
75 }
76
77
78
79 if( strcmp( argv[ 1 ], "off" ) == 0 )
80 {
81 if( bug_ctx.hw_debug_enabled == 0 )
82 {
83 printf( "No breakpoints enabled\n" );
84 return;
85 }
86
87 which_bp = simple_strtoul( argv[ 2 ], NULL, 10 );
88
89 if( bug_ctx.clear )
90 (*bug_ctx.clear)( which_bp );
91
92 printf( "Breakpoint %d removed\n", which_bp );
93 return;
94 }
95
96
97
98 if( strcmp( argv[ 1 ], "show" ) == 0 )
99 {
100 for( which_bp = 1; which_bp <= MAX_BREAK_POINTS; ++which_bp )
101 {
102
103 switch( which_bp )
104 {
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;
109 }
110
111 printf( "Breakpoint [%d]: ", which_bp );
112 if( addr == 0 )
113 printf( "NOT SET\n" );
114 else
115 disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
116 }
117 return;
118 }
119
120
121
122 if( !isdigit( argv[ 1 ][ 0 ])) {
123 cmd_usage(cmdtp);
124 return;
125 }
126
127 addr = simple_strtoul( argv[ 1 ], NULL, 16 ) & 0xfffffffc;
128
129 if(( bug_ctx.set ) && ( which_bp = (*bug_ctx.set)( 0, addr )) > 0 )
130 {
131 printf( "Breakpoint [%d]: ", which_bp );
132 disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
133 }
134
135 return;
136}
137
138
139
140
141
142
143
144
145
146
147void bedbug860_break_isr( struct pt_regs *regs )
148{
149 unsigned long addr;
150 unsigned long cause;
151
152
153 cause = GET_ICR();
154
155 if( !(cause & 0x00000004)) {
156 printf( "Not an instruction breakpoint (ICR 0x%08lx)\n", cause );
157 return;
158 }
159
160 addr = regs->nip;
161
162 if( addr == GET_CMPA() )
163 {
164 bug_ctx.current_bp = 1;
165 }
166 else if( addr == GET_CMPB() )
167 {
168 bug_ctx.current_bp = 2;
169 }
170 else if( addr == GET_CMPC() )
171 {
172 bug_ctx.current_bp = 3;
173 }
174 else if( addr == GET_CMPD() )
175 {
176 bug_ctx.current_bp = 4;
177 }
178
179 bedbug_main_loop( addr, regs );
180 return;
181}
182
183
184
185
186
187
188
189
190int bedbug860_find_empty( void )
191{
192
193
194 if( GET_CMPA() == 0 )
195 return 1;
196
197 if( GET_CMPB() == 0 )
198 return 2;
199
200 if( GET_CMPC() == 0 )
201 return 3;
202
203 if( GET_CMPD() == 0 )
204 return 4;
205
206 return 0;
207}
208
209
210
211
212
213
214
215
216
217
218
219int bedbug860_set( int which_bp, unsigned long addr )
220{
221
222
223
224 if(( bug_ctx.find_empty ) && ( !which_bp ) &&
225 ( which_bp = (*bug_ctx.find_empty)()) == 0 )
226 {
227 printf( "All breakpoints in use\n" );
228 return 0;
229 }
230
231 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
232 {
233 printf( "Invalid break point # %d\n", which_bp );
234 return 0;
235 }
236
237 if( ! bug_ctx.hw_debug_enabled )
238 {
239 bug_ctx.hw_debug_enabled = 1;
240 SET_DER( GET_DER() | 0x00000004 );
241 }
242
243 switch( which_bp )
244 {
245 case 1:
246 SET_CMPA( addr );
247 SET_ICTRL( GET_ICTRL() | 0x80080800 );
248 break;
249
250 case 2:
251 SET_CMPB( addr );
252 SET_ICTRL( GET_ICTRL() | 0x10020400 );
253 break;
254
255 case 3:
256 SET_CMPC( addr );
257 SET_ICTRL( GET_ICTRL() | 0x02008200 );
258 break;
259
260 case 4:
261 SET_CMPD( addr );
262 SET_ICTRL( GET_ICTRL() | 0x00404100 );
263 break;
264 }
265
266 return which_bp;
267}
268
269
270
271
272
273
274
275
276int bedbug860_clear( int which_bp )
277{
278
279
280 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
281 {
282 printf( "Invalid break point # (%d)\n", which_bp );
283 return -1;
284 }
285
286 switch( which_bp )
287 {
288 case 1:
289 SET_CMPA( 0 );
290 SET_ICTRL( GET_ICTRL() & ~0x80080800 );
291 break;
292
293 case 2:
294 SET_CMPB( 0 );
295 SET_ICTRL( GET_ICTRL() & ~0x10020400 );
296 break;
297
298 case 3:
299 SET_CMPC( 0 );
300 SET_ICTRL( GET_ICTRL() & ~0x02008200 );
301 break;
302
303 case 4:
304 SET_CMPD( 0 );
305 SET_ICTRL( GET_ICTRL() & ~0x00404100 );
306 break;
307 }
308
309 return 0;
310}
311
312
313
314#endif
315