1
2
3
4
5#include <common.h>
6#include <command.h>
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>
12
13#if defined(CONFIG_CMD_BEDBUG) \
14 && (defined(CONFIG_MPC824X) || defined(CONFIG_MPC8260))
15
16#define MAX_BREAK_POINTS 1
17
18extern CPU_DEBUG_CTX bug_ctx;
19
20void bedbug603e_init __P((void));
21void bedbug603e_do_break __P((cmd_tbl_t*,int,int,char*const[]));
22void bedbug603e_break_isr __P((struct pt_regs*));
23int bedbug603e_find_empty __P((void));
24int bedbug603e_set __P((int,unsigned long));
25int bedbug603e_clear __P((int));
26
27
28
29
30
31
32
33void bedbug603e_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 = 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;
48
49 for( i = 1; i <= MAX_BREAK_POINTS; ++i )
50 (*bug_ctx.clear)( i );
51
52 puts ("BEDBUG:ready\n");
53 return;
54}
55
56
57
58
59
60
61
62
63
64
65
66void bedbug603e_do_break (cmd_tbl_t *cmdtp, int flag, int argc,
67 char * const argv[])
68{
69 long addr;
70 int which_bp;
71
72
73 if (argc < 2) {
74 cmd_usage(cmdtp);
75 return;
76 }
77
78
79
80 if( strcmp( argv[ 1 ], "off" ) == 0 )
81 {
82 if( bug_ctx.hw_debug_enabled == 0 )
83 {
84 puts ( "No breakpoints enabled\n" );
85 return;
86 }
87
88 which_bp = simple_strtoul( argv[ 2 ], NULL, 10 );
89
90 if( bug_ctx.clear )
91 (*bug_ctx.clear)( which_bp );
92
93 printf( "Breakpoint %d removed\n", which_bp );
94 return;
95 }
96
97
98
99 if( strcmp( argv[ 1 ], "show" ) == 0 )
100 {
101 for( which_bp = 1; which_bp <= MAX_BREAK_POINTS; ++which_bp )
102 {
103
104 addr = GET_IABR();
105
106 printf( "Breakpoint [%d]: ", which_bp );
107 if( (addr & 0x00000002) == 0 )
108 puts ( "NOT SET\n" );
109 else
110 disppc( (unsigned char *)(addr & 0xFFFFFFFC), 0, 1, bedbug_puts, F_RADHEX );
111 }
112 return;
113 }
114
115
116
117 if(!(( isdigit( argv[ 1 ][ 0 ] )) ||
118 (( argv[ 1 ][ 0 ] >= 'a' ) && ( argv[ 1 ][ 0 ] <= 'f' )) ||
119 (( argv[ 1 ][ 0 ] >= 'A' ) && ( argv[ 1 ][ 0 ] <= 'F' )))) {
120 cmd_usage(cmdtp);
121 return;
122 }
123
124 addr = simple_strtoul( argv[ 1 ], NULL, 16 );
125
126 if(( bug_ctx.set ) && ( which_bp = (*bug_ctx.set)( 0, addr )) > 0 )
127 {
128 printf( "Breakpoint [%d]: ", which_bp );
129 disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX );
130 }
131
132 return;
133}
134
135
136
137
138
139
140
141
142void bedbug603e_break_isr( struct pt_regs *regs )
143{
144 unsigned long addr;
145
146
147 bug_ctx.current_bp = 1;
148 addr = GET_IABR() & 0xFFFFFFFC;
149
150 bedbug_main_loop( addr, regs );
151 return;
152}
153
154
155
156
157
158
159
160int bedbug603e_find_empty( void )
161{
162
163
164 if( (GET_IABR() && 0x00000002) == 0 )
165 return 1;
166
167 return 0;
168}
169
170
171
172
173
174
175
176
177
178
179int bedbug603e_set( int which_bp, unsigned long addr )
180{
181
182
183 if(( addr & 0x00000003 ) != 0 )
184 {
185 puts ( "Breakpoints must be on a 32 bit boundary\n" );
186 return 0;
187 }
188
189
190 if(( bug_ctx.find_empty ) && ( !which_bp ) &&
191 ( which_bp = (*bug_ctx.find_empty)()) == 0 )
192 {
193 puts ( "All breakpoints in use\n" );
194 return 0;
195 }
196
197 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
198 {
199 printf( "Invalid break point # %d\n", which_bp );
200 return 0;
201 }
202
203 if( ! bug_ctx.hw_debug_enabled )
204 {
205 bug_ctx.hw_debug_enabled = 1;
206 }
207
208 SET_IABR( addr | 0x00000002 );
209
210 return which_bp;
211}
212
213
214
215
216
217
218
219int bedbug603e_clear( int which_bp )
220{
221
222
223 if( which_bp < 1 || which_bp > MAX_BREAK_POINTS )
224 {
225 printf( "Invalid break point # (%d)\n", which_bp );
226 return -1;
227 }
228
229 SET_IABR( 0 );
230
231 return 0;
232}
233
234
235
236#endif
237