2 * Bedbug Functions specific to the PPC405 chip
7 #include <linux/ctype.h>
9 #include <cmd_bedbug.h>
10 #include <bedbug/bedbug.h>
11 #include <bedbug/regs.h>
12 #include <bedbug/ppc.h>
14 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG) && defined(CONFIG_4xx)
16 #define MAX_BREAK_POINTS 4
18 extern CPU_DEBUG_CTX bug_ctx;
20 void bedbug405_init __P ((void));
21 void bedbug405_do_break __P ((cmd_tbl_t *, int, int, char *[]));
22 void bedbug405_break_isr __P ((struct pt_regs *));
23 int bedbug405_find_empty __P ((void));
24 int bedbug405_set __P ((int, unsigned long));
25 int bedbug405_clear __P ((int));
28 /* ======================================================================
29 * Initialize the global bug_ctx structure for the IBM PPC405. Clear all
31 * ====================================================================== */
33 void bedbug405_init (void)
37 /* -------------------------------------------------- */
39 bug_ctx.hw_debug_enabled = 0;
41 bug_ctx.current_bp = 0;
44 bug_ctx.do_break = bedbug405_do_break;
45 bug_ctx.break_isr = bedbug405_break_isr;
46 bug_ctx.find_empty = bedbug405_find_empty;
47 bug_ctx.set = bedbug405_set;
48 bug_ctx.clear = bedbug405_clear;
50 for (i = 1; i <= MAX_BREAK_POINTS; ++i)
53 puts ("BEDBUG:ready\n");
55 } /* bedbug_init_breakpoints */
59 /* ======================================================================
60 * Set/clear/show one of the hardware breakpoints for the 405. The "off"
61 * string will disable a specific breakpoint. The "show" string will
62 * display the current breakpoints. Otherwise an address will set a
63 * breakpoint at that address. Setting a breakpoint uses the CPU-specific
64 * set routine which will assign a breakpoint number.
65 * ====================================================================== */
67 void bedbug405_do_break (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
69 long addr = 0; /* Address to break at */
70 int which_bp; /* Breakpoint number */
72 /* -------------------------------------------------- */
75 printf ("Usage:\n%s\n", cmdtp->usage);
79 /* Turn off a breakpoint */
81 if (strcmp (argv[1], "off") == 0) {
82 if (bug_ctx.hw_debug_enabled == 0) {
83 printf ("No breakpoints enabled\n");
87 which_bp = simple_strtoul (argv[2], NULL, 10);
90 (*bug_ctx.clear) (which_bp);
92 printf ("Breakpoint %d removed\n", which_bp);
96 /* Show a list of breakpoints */
98 if (strcmp (argv[1], "show") == 0) {
99 for (which_bp = 1; which_bp <= MAX_BREAK_POINTS; ++which_bp) {
116 printf ("Breakpoint [%d]: ", which_bp);
118 printf ("NOT SET\n");
120 disppc ((unsigned char *) addr, 0, 1, bedbug_puts,
126 /* Set a breakpoint at the address */
128 if (!isdigit (argv[1][0])) {
129 printf ("Usage:\n%s\n", cmdtp->usage);
133 addr = simple_strtoul (argv[1], NULL, 16) & 0xfffffffc;
135 if ((bug_ctx.set) && (which_bp = (*bug_ctx.set) (0, addr)) > 0) {
136 printf ("Breakpoint [%d]: ", which_bp);
137 disppc ((unsigned char *) addr, 0, 1, bedbug_puts, F_RADHEX);
141 } /* bedbug405_do_break */
145 /* ======================================================================
146 * Handle a breakpoint. First determine which breakpoint was hit by
147 * looking at the DeBug Status Register (DBSR), clear the breakpoint
148 * and enter a mini main loop. Stay in the loop until the stopped flag
149 * in the debug context is cleared.
150 * ====================================================================== */
152 void bedbug405_break_isr (struct pt_regs *regs)
154 unsigned long dbsr_val; /* Value of the DBSR */
155 unsigned long addr = 0; /* Address stopped at */
157 /* -------------------------------------------------- */
159 dbsr_val = GET_DBSR ();
161 if (dbsr_val & DBSR_IA1) {
162 bug_ctx.current_bp = 1;
164 SET_DBSR (DBSR_IA1); /* Write a 1 to clear */
165 } else if (dbsr_val & DBSR_IA2) {
166 bug_ctx.current_bp = 2;
168 SET_DBSR (DBSR_IA2); /* Write a 1 to clear */
169 } else if (dbsr_val & DBSR_IA3) {
170 bug_ctx.current_bp = 3;
172 SET_DBSR (DBSR_IA3); /* Write a 1 to clear */
173 } else if (dbsr_val & DBSR_IA4) {
174 bug_ctx.current_bp = 4;
176 SET_DBSR (DBSR_IA4); /* Write a 1 to clear */
179 bedbug_main_loop (addr, regs);
181 } /* bedbug405_break_isr */
185 /* ======================================================================
186 * Look through all of the hardware breakpoints available to see if one
188 * ====================================================================== */
190 int bedbug405_find_empty (void)
192 /* -------------------------------------------------- */
194 if (GET_IAC1 () == 0)
197 if (GET_IAC2 () == 0)
200 if (GET_IAC3 () == 0)
203 if (GET_IAC4 () == 0)
207 } /* bedbug405_find_empty */
211 /* ======================================================================
212 * Set a breakpoint. If 'which_bp' is zero then find an unused breakpoint
213 * number, otherwise reassign the given breakpoint. If hardware debugging
214 * is not enabled, then turn it on via the MSR and DBCR0. Set the break
215 * address in the appropriate IACx register and enable proper address
216 * beakpoint in DBCR0.
217 * ====================================================================== */
219 int bedbug405_set (int which_bp, unsigned long addr)
221 /* -------------------------------------------------- */
223 /* Only look if which_bp == 0, else use which_bp */
224 if ((bug_ctx.find_empty) && (!which_bp) &&
225 (which_bp = (*bug_ctx.find_empty) ()) == 0) {
226 printf ("All breakpoints in use\n");
230 if (which_bp < 1 || which_bp > MAX_BREAK_POINTS) {
231 printf ("Invalid break point # %d\n", which_bp);
235 if (!bug_ctx.hw_debug_enabled) {
236 SET_MSR (GET_MSR () | 0x200); /* set MSR[ DE ] */
237 SET_DBCR0 (GET_DBCR0 () | DBCR0_IDM);
238 bug_ctx.hw_debug_enabled = 1;
244 SET_DBCR0 (GET_DBCR0 () | DBCR0_IA1);
249 SET_DBCR0 (GET_DBCR0 () | DBCR0_IA2);
254 SET_DBCR0 (GET_DBCR0 () | DBCR0_IA3);
259 SET_DBCR0 (GET_DBCR0 () | DBCR0_IA4);
264 } /* bedbug405_set */
268 /* ======================================================================
269 * Disable a specific breakoint by setting the appropriate IACx register
270 * to zero and claring the instruction address breakpoint in DBCR0.
271 * ====================================================================== */
273 int bedbug405_clear (int which_bp)
275 /* -------------------------------------------------- */
277 if (which_bp < 1 || which_bp > MAX_BREAK_POINTS) {
278 printf ("Invalid break point # (%d)\n", which_bp);
285 SET_DBCR0 (GET_DBCR0 () & ~DBCR0_IA1);
290 SET_DBCR0 (GET_DBCR0 () & ~DBCR0_IA2);
295 SET_DBCR0 (GET_DBCR0 () & ~DBCR0_IA3);
300 SET_DBCR0 (GET_DBCR0 () & ~DBCR0_IA4);
305 } /* bedbug405_clear */
308 /* ====================================================================== */