]>
git.ipfire.org Git - people/ms/u-boot.git/blob - cmd/bedbug.c
32067575ed159c1f6ac71cae431f4eb5746bff85
9 #include <linux/ctype.h>
11 #include <bedbug/type.h>
12 #include <bedbug/bedbug.h>
13 #include <bedbug/regs.h>
14 #include <bedbug/ppc.h>
16 DECLARE_GLOBAL_DATA_PTR
;
18 extern void show_regs
__P ((struct pt_regs
*));
19 extern int run_command
__P ((const char *, int));
21 ulong dis_last_addr
= 0; /* Last address disassembled */
22 ulong dis_last_len
= 20; /* Default disassembler length */
23 CPU_DEBUG_CTX bug_ctx
; /* Bedbug context structure */
26 /* ======================================================================
27 * U-Boot's puts function does not append a newline, so the bedbug stuff
28 * will use this for the output of the dis/assembler.
29 * ====================================================================== */
31 int bedbug_puts (const char *str
)
33 /* -------------------------------------------------- */
35 printf ("%s\r\n", str
);
41 /* ======================================================================
42 * Initialize the bug_ctx structure used by the bedbug debugger. This is
43 * specific to the CPU since each has different debug registers and
45 * ====================================================================== */
47 void bedbug_init (void)
49 /* -------------------------------------------------- */
51 #if defined(CONFIG_4xx)
52 void bedbug405_init (void);
62 /* ======================================================================
63 * Entry point from the interpreter to the disassembler. Repeated calls
64 * will resume from the last disassembled address.
65 * ====================================================================== */
66 int do_bedbug_dis (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
68 ulong addr
; /* Address to start disassembly from */
69 ulong len
; /* # of instructions to disassemble */
71 /* -------------------------------------------------- */
73 /* Setup to go from the last address if none is given */
80 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
82 addr
= simple_strtoul (argv
[1], NULL
, 16);
84 /* If an extra param is given then it is the length */
86 len
= simple_strtoul (argv
[2], NULL
, 16);
89 /* Run the disassembler */
90 disppc ((unsigned char *) addr
, 0, len
, bedbug_puts
, F_RADHEX
);
92 dis_last_addr
= addr
+ (len
* 4);
97 U_BOOT_CMD (ds
, 3, 1, do_bedbug_dis
,
99 "ds <address> [# instructions]");
101 /* ======================================================================
102 * Entry point from the interpreter to the assembler. Assembles
103 * instructions in consecutive memory locations until a '.' (period) is
104 * entered on a line by itself.
105 * ====================================================================== */
106 int do_bedbug_asm (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
108 long mem_addr
; /* Address to assemble into */
109 unsigned long instr
; /* Machine code for text */
110 char prompt
[15]; /* Prompt string for user input */
111 int asm_err
; /* Error code from the assembler */
113 /* -------------------------------------------------- */
117 return CMD_RET_USAGE
;
119 printf ("\nEnter '.' when done\n");
120 mem_addr
= simple_strtoul (argv
[1], NULL
, 16);
124 disppc ((unsigned char *) mem_addr
, 0, 1, bedbug_puts
,
127 sprintf (prompt
, "%08lx: ", mem_addr
);
128 cli_readline(prompt
);
130 if (console_buffer
[0] && strcmp (console_buffer
, ".")) {
132 asmppc (mem_addr
, console_buffer
,
134 *(unsigned long *) mem_addr
= instr
;
137 printf ("*** Error: %s ***\n",
138 asm_error_str (asm_err
));
146 } /* do_bedbug_asm */
148 U_BOOT_CMD (as
, 2, 0, do_bedbug_asm
,
149 "assemble memory", "as <address>");
151 /* ======================================================================
152 * Used to set a break point from the interpreter. Simply calls into the
153 * CPU-specific break point set routine.
154 * ====================================================================== */
156 int do_bedbug_break (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
158 /* -------------------------------------------------- */
159 if (bug_ctx
.do_break
)
160 (*bug_ctx
.do_break
) (cmdtp
, flag
, argc
, argv
);
163 } /* do_bedbug_break */
165 U_BOOT_CMD (break, 3, 0, do_bedbug_break
,
166 "set or clear a breakpoint",
167 " - Set or clear a breakpoint\n"
168 "break <address> - Break at an address\n"
169 "break off <bp#> - Disable breakpoint.\n"
170 "break show - List breakpoints.");
172 /* ======================================================================
173 * Called from the debug interrupt routine. Simply calls the CPU-specific
174 * breakpoint handling routine.
175 * ====================================================================== */
177 void do_bedbug_breakpoint (struct pt_regs
*regs
)
179 /* -------------------------------------------------- */
181 if (bug_ctx
.break_isr
)
182 (*bug_ctx
.break_isr
) (regs
);
185 } /* do_bedbug_breakpoint */
189 /* ======================================================================
190 * Called from the CPU-specific breakpoint handling routine. Enter a
191 * mini main loop until the stopped flag is cleared from the breakpoint
194 * This handles the parts of the debugger that are common to all CPU's.
195 * ====================================================================== */
197 void bedbug_main_loop (unsigned long addr
, struct pt_regs
*regs
)
199 int len
; /* Length of command line */
200 int flag
; /* Command flags */
201 int rc
= 0; /* Result from run_command */
202 char prompt_str
[20]; /* Prompt string */
203 static char lastcommand
[CONFIG_SYS_CBSIZE
] = { 0 }; /* previous command */
204 /* -------------------------------------------------- */
207 (*bug_ctx
.clear
) (bug_ctx
.current_bp
);
209 printf ("Breakpoint %d: ", bug_ctx
.current_bp
);
210 disppc ((unsigned char *) addr
, 0, 1, bedbug_puts
, F_RADHEX
);
215 sprintf (prompt_str
, "BEDBUG.%d =>", bug_ctx
.current_bp
);
217 /* A miniature main loop */
218 while (bug_ctx
.stopped
) {
219 len
= cli_readline(prompt_str
);
221 flag
= 0; /* assume no special flags for now */
224 strcpy (lastcommand
, console_buffer
);
226 flag
|= CMD_FLAG_REPEAT
;
229 printf ("<INTERRUPT>\n");
231 rc
= run_command_repeatable(lastcommand
, flag
);
234 /* invalid command or not repeatable, forget it */
240 bug_ctx
.current_bp
= 0;
243 } /* bedbug_main_loop */
247 /* ======================================================================
248 * Interpreter command to continue from a breakpoint. Just clears the
249 * stopped flag in the context so that the breakpoint routine will
251 * ====================================================================== */
252 int do_bedbug_continue (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
254 /* -------------------------------------------------- */
256 if (!bug_ctx
.stopped
) {
257 printf ("Not at a breakpoint\n");
263 } /* do_bedbug_continue */
265 U_BOOT_CMD (continue, 1, 0, do_bedbug_continue
,
266 "continue from a breakpoint",
269 /* ======================================================================
270 * Interpreter command to continue to the next instruction, stepping into
271 * subroutines. Works by calling the find_next_addr() routine to compute
272 * the address passes control to the CPU-specific set breakpoint routine
273 * for the current breakpoint number.
274 * ====================================================================== */
275 int do_bedbug_step (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
277 unsigned long addr
; /* Address to stop at */
279 /* -------------------------------------------------- */
281 if (!bug_ctx
.stopped
) {
282 printf ("Not at a breakpoint\n");
286 if (!find_next_address((unsigned char *) &addr
, false, bug_ctx
.regs
))
290 (*bug_ctx
.set
) (bug_ctx
.current_bp
, addr
);
294 } /* do_bedbug_step */
296 U_BOOT_CMD (step
, 1, 1, do_bedbug_step
,
297 "single step execution.",
300 /* ======================================================================
301 * Interpreter command to continue to the next instruction, stepping over
302 * subroutines. Works by calling the find_next_addr() routine to compute
303 * the address passes control to the CPU-specific set breakpoint routine
304 * for the current breakpoint number.
305 * ====================================================================== */
306 int do_bedbug_next (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
308 unsigned long addr
; /* Address to stop at */
310 /* -------------------------------------------------- */
312 if (!bug_ctx
.stopped
) {
313 printf ("Not at a breakpoint\n");
317 if (!find_next_address((unsigned char *) &addr
, true, bug_ctx
.regs
))
321 (*bug_ctx
.set
) (bug_ctx
.current_bp
, addr
);
325 } /* do_bedbug_next */
327 U_BOOT_CMD (next
, 1, 1, do_bedbug_next
,
328 "single step execution, stepping over subroutines.",
331 /* ======================================================================
332 * Interpreter command to print the current stack. This assumes an EABI
333 * architecture, so it starts with GPR R1 and works back up the stack.
334 * ====================================================================== */
335 int do_bedbug_stack (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
337 unsigned long sp
; /* Stack pointer */
338 unsigned long func
; /* LR from stack */
339 int depth
; /* Stack iteration level */
340 int skip
= 1; /* Flag to skip the first entry */
341 unsigned long top
; /* Top of memory address */
343 /* -------------------------------------------------- */
345 if (!bug_ctx
.stopped
) {
346 printf ("Not at a breakpoint\n");
350 top
= gd
->bd
->bi_memstart
+ gd
->bd
->bi_memsize
;
353 printf ("Depth PC\n");
354 printf ("----- --------\n");
355 printf ("%5d %08lx\n", depth
++, bug_ctx
.regs
->nip
);
357 sp
= bug_ctx
.regs
->gpr
[1];
358 func
= *(unsigned long *) (sp
+ 4);
360 while ((func
< top
) && (sp
< top
)) {
362 printf ("%5d %08lx\n", depth
++, func
);
366 sp
= *(unsigned long *) sp
;
367 func
= *(unsigned long *) (sp
+ 4);
370 } /* do_bedbug_stack */
372 U_BOOT_CMD (where
, 1, 1, do_bedbug_stack
,
373 "Print the running stack.",
376 /* ======================================================================
377 * Interpreter command to dump the registers. Calls the CPU-specific
378 * show registers routine.
379 * ====================================================================== */
380 int do_bedbug_rdump (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
382 /* -------------------------------------------------- */
384 if (!bug_ctx
.stopped
) {
385 printf ("Not at a breakpoint\n");
389 show_regs (bug_ctx
.regs
);
391 } /* do_bedbug_rdump */
393 U_BOOT_CMD (rdump
, 1, 1, do_bedbug_rdump
,
394 "Show registers.", "");
395 /* ====================================================================== */
399 * Copyright (c) 2001 William L. Pitts
400 * All rights reserved.
402 * Redistribution and use in source and binary forms are freely
403 * permitted provided that the above copyright notice and this
404 * paragraph and the following disclaimer are duplicated in all
407 * This software is provided "AS IS" and without any express or
408 * implied warranties, including, without limitation, the implied
409 * warranties of merchantability and fitness for a particular