]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_bedbug.c
7 #include <linux/ctype.h>
9 #include <bedbug/type.h>
10 #include <bedbug/bedbug.h>
11 #include <bedbug/regs.h>
12 #include <bedbug/ppc.h>
14 DECLARE_GLOBAL_DATA_PTR
;
16 extern void show_regs
__P ((struct pt_regs
*));
17 extern int run_command
__P ((const char *, int));
18 extern char console_buffer
[];
20 ulong dis_last_addr
= 0; /* Last address disassembled */
21 ulong dis_last_len
= 20; /* Default disassembler length */
22 CPU_DEBUG_CTX bug_ctx
; /* Bedbug context structure */
25 /* ======================================================================
26 * U-Boot's puts function does not append a newline, so the bedbug stuff
27 * will use this for the output of the dis/assembler.
28 * ====================================================================== */
30 int bedbug_puts (const char *str
)
32 /* -------------------------------------------------- */
34 printf ("%s\r\n", str
);
40 /* ======================================================================
41 * Initialize the bug_ctx structure used by the bedbug debugger. This is
42 * specific to the CPU since each has different debug registers and
44 * ====================================================================== */
46 void bedbug_init (void)
48 /* -------------------------------------------------- */
50 #if defined(CONFIG_4xx)
51 void bedbug405_init (void);
54 #elif defined(CONFIG_8xx)
55 void bedbug860_init (void);
60 #if defined(CONFIG_MPC824X) || defined(CONFIG_MPC8260)
61 /* Processors that are 603e core based */
62 void bedbug603e_init (void);
72 /* ======================================================================
73 * Entry point from the interpreter to the disassembler. Repeated calls
74 * will resume from the last disassembled address.
75 * ====================================================================== */
76 int do_bedbug_dis (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
78 ulong addr
; /* Address to start disassembly from */
79 ulong len
; /* # of instructions to disassemble */
81 /* -------------------------------------------------- */
83 /* Setup to go from the last address if none is given */
88 return cmd_usage(cmdtp
);
90 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
92 addr
= simple_strtoul (argv
[1], NULL
, 16);
94 /* If an extra param is given then it is the length */
96 len
= simple_strtoul (argv
[2], NULL
, 16);
99 /* Run the disassembler */
100 disppc ((unsigned char *) addr
, 0, len
, bedbug_puts
, F_RADHEX
);
102 dis_last_addr
= addr
+ (len
* 4);
105 } /* do_bedbug_dis */
107 U_BOOT_CMD (ds
, 3, 1, do_bedbug_dis
,
108 "disassemble memory",
109 "ds <address> [# instructions]");
111 /* ======================================================================
112 * Entry point from the interpreter to the assembler. Assembles
113 * instructions in consecutive memory locations until a '.' (period) is
114 * entered on a line by itself.
115 * ====================================================================== */
116 int do_bedbug_asm (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
118 long mem_addr
; /* Address to assemble into */
119 unsigned long instr
; /* Machine code for text */
120 char prompt
[15]; /* Prompt string for user input */
121 int asm_err
; /* Error code from the assembler */
123 /* -------------------------------------------------- */
127 return cmd_usage(cmdtp
);
129 printf ("\nEnter '.' when done\n");
130 mem_addr
= simple_strtoul (argv
[1], NULL
, 16);
134 disppc ((unsigned char *) mem_addr
, 0, 1, bedbug_puts
,
137 sprintf (prompt
, "%08lx: ", mem_addr
);
140 if (console_buffer
[0] && strcmp (console_buffer
, ".")) {
142 asmppc (mem_addr
, console_buffer
,
144 *(unsigned long *) mem_addr
= instr
;
147 printf ("*** Error: %s ***\n",
148 asm_error_str (asm_err
));
156 } /* do_bedbug_asm */
158 U_BOOT_CMD (as
, 2, 0, do_bedbug_asm
,
159 "assemble memory", "as <address>");
161 /* ======================================================================
162 * Used to set a break point from the interpreter. Simply calls into the
163 * CPU-specific break point set routine.
164 * ====================================================================== */
166 int do_bedbug_break (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
168 /* -------------------------------------------------- */
169 if (bug_ctx
.do_break
)
170 (*bug_ctx
.do_break
) (cmdtp
, flag
, argc
, argv
);
173 } /* do_bedbug_break */
175 U_BOOT_CMD (break, 3, 0, do_bedbug_break
,
176 "set or clear a breakpoint",
177 " - Set or clear a breakpoint\n"
178 "break <address> - Break at an address\n"
179 "break off <bp#> - Disable breakpoint.\n"
180 "break show - List breakpoints.");
182 /* ======================================================================
183 * Called from the debug interrupt routine. Simply calls the CPU-specific
184 * breakpoint handling routine.
185 * ====================================================================== */
187 void do_bedbug_breakpoint (struct pt_regs
*regs
)
189 /* -------------------------------------------------- */
191 if (bug_ctx
.break_isr
)
192 (*bug_ctx
.break_isr
) (regs
);
195 } /* do_bedbug_breakpoint */
199 /* ======================================================================
200 * Called from the CPU-specific breakpoint handling routine. Enter a
201 * mini main loop until the stopped flag is cleared from the breakpoint
204 * This handles the parts of the debugger that are common to all CPU's.
205 * ====================================================================== */
207 void bedbug_main_loop (unsigned long addr
, struct pt_regs
*regs
)
209 int len
; /* Length of command line */
210 int flag
; /* Command flags */
211 int rc
= 0; /* Result from run_command */
212 char prompt_str
[20]; /* Prompt string */
213 static char lastcommand
[CONFIG_SYS_CBSIZE
] = { 0 }; /* previous command */
214 /* -------------------------------------------------- */
217 (*bug_ctx
.clear
) (bug_ctx
.current_bp
);
219 printf ("Breakpoint %d: ", bug_ctx
.current_bp
);
220 disppc ((unsigned char *) addr
, 0, 1, bedbug_puts
, F_RADHEX
);
225 sprintf (prompt_str
, "BEDBUG.%d =>", bug_ctx
.current_bp
);
227 /* A miniature main loop */
228 while (bug_ctx
.stopped
) {
229 len
= readline (prompt_str
);
231 flag
= 0; /* assume no special flags for now */
234 strcpy (lastcommand
, console_buffer
);
236 flag
|= CMD_FLAG_REPEAT
;
239 printf ("<INTERRUPT>\n");
241 rc
= run_command (lastcommand
, flag
);
244 /* invalid command or not repeatable, forget it */
250 bug_ctx
.current_bp
= 0;
253 } /* bedbug_main_loop */
257 /* ======================================================================
258 * Interpreter command to continue from a breakpoint. Just clears the
259 * stopped flag in the context so that the breakpoint routine will
261 * ====================================================================== */
262 int do_bedbug_continue (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
264 /* -------------------------------------------------- */
266 if (!bug_ctx
.stopped
) {
267 printf ("Not at a breakpoint\n");
273 } /* do_bedbug_continue */
275 U_BOOT_CMD (continue, 1, 0, do_bedbug_continue
,
276 "continue from a breakpoint",
279 /* ======================================================================
280 * Interpreter command to continue to the next instruction, stepping into
281 * subroutines. Works by calling the find_next_addr() routine to compute
282 * the address passes control to the CPU-specific set breakpoint routine
283 * for the current breakpoint number.
284 * ====================================================================== */
285 int do_bedbug_step (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
287 unsigned long addr
; /* Address to stop at */
289 /* -------------------------------------------------- */
291 if (!bug_ctx
.stopped
) {
292 printf ("Not at a breakpoint\n");
296 if (!find_next_address ((unsigned char *) &addr
, FALSE
, bug_ctx
.regs
))
300 (*bug_ctx
.set
) (bug_ctx
.current_bp
, addr
);
304 } /* do_bedbug_step */
306 U_BOOT_CMD (step
, 1, 1, do_bedbug_step
,
307 "single step execution.",
310 /* ======================================================================
311 * Interpreter command to continue to the next instruction, stepping over
312 * subroutines. Works by calling the find_next_addr() routine to compute
313 * the address passes control to the CPU-specific set breakpoint routine
314 * for the current breakpoint number.
315 * ====================================================================== */
316 int do_bedbug_next (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
318 unsigned long addr
; /* Address to stop at */
320 /* -------------------------------------------------- */
322 if (!bug_ctx
.stopped
) {
323 printf ("Not at a breakpoint\n");
327 if (!find_next_address ((unsigned char *) &addr
, TRUE
, bug_ctx
.regs
))
331 (*bug_ctx
.set
) (bug_ctx
.current_bp
, addr
);
335 } /* do_bedbug_next */
337 U_BOOT_CMD (next
, 1, 1, do_bedbug_next
,
338 "single step execution, stepping over subroutines.",
341 /* ======================================================================
342 * Interpreter command to print the current stack. This assumes an EABI
343 * architecture, so it starts with GPR R1 and works back up the stack.
344 * ====================================================================== */
345 int do_bedbug_stack (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
347 unsigned long sp
; /* Stack pointer */
348 unsigned long func
; /* LR from stack */
349 int depth
; /* Stack iteration level */
350 int skip
= 1; /* Flag to skip the first entry */
351 unsigned long top
; /* Top of memory address */
353 /* -------------------------------------------------- */
355 if (!bug_ctx
.stopped
) {
356 printf ("Not at a breakpoint\n");
360 top
= gd
->bd
->bi_memstart
+ gd
->bd
->bi_memsize
;
363 printf ("Depth PC\n");
364 printf ("----- --------\n");
365 printf ("%5d %08lx\n", depth
++, bug_ctx
.regs
->nip
);
367 sp
= bug_ctx
.regs
->gpr
[1];
368 func
= *(unsigned long *) (sp
+ 4);
370 while ((func
< top
) && (sp
< top
)) {
372 printf ("%5d %08lx\n", depth
++, func
);
376 sp
= *(unsigned long *) sp
;
377 func
= *(unsigned long *) (sp
+ 4);
380 } /* do_bedbug_stack */
382 U_BOOT_CMD (where
, 1, 1, do_bedbug_stack
,
383 "Print the running stack.",
386 /* ======================================================================
387 * Interpreter command to dump the registers. Calls the CPU-specific
388 * show registers routine.
389 * ====================================================================== */
390 int do_bedbug_rdump (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
392 /* -------------------------------------------------- */
394 if (!bug_ctx
.stopped
) {
395 printf ("Not at a breakpoint\n");
399 show_regs (bug_ctx
.regs
);
401 } /* do_bedbug_rdump */
403 U_BOOT_CMD (rdump
, 1, 1, do_bedbug_rdump
,
404 "Show registers.", "");
405 /* ====================================================================== */
409 * Copyright (c) 2001 William L. Pitts
410 * All rights reserved.
412 * Redistribution and use in source and binary forms are freely
413 * permitted provided that the above copyright notice and this
414 * paragraph and the following disclaimer are duplicated in all
417 * This software is provided "AS IS" and without any express or
418 * implied warranties, including, without limitation, the implied
419 * warranties of merchantability and fitness for a particular