wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * BedBug Functions |
| 3 | */ |
| 4 | |
| 5 | #include <common.h> |
| 6 | #include <command.h> |
| 7 | #include <linux/ctype.h> |
| 8 | #include <net.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 9 | #include <bedbug/type.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 10 | #include <bedbug/bedbug.h> |
| 11 | #include <bedbug/regs.h> |
| 12 | #include <bedbug/ppc.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 13 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 16 | #if defined(CONFIG_CMD_BEDBUG) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 17 | |
| 18 | #ifndef MAX |
| 19 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
| 20 | #endif |
| 21 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 22 | extern void show_regs __P ((struct pt_regs *)); |
| 23 | extern int run_command __P ((const char *, int)); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 24 | extern char console_buffer[]; |
| 25 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 26 | ulong dis_last_addr = 0; /* Last address disassembled */ |
| 27 | ulong dis_last_len = 20; /* Default disassembler length */ |
| 28 | CPU_DEBUG_CTX bug_ctx; /* Bedbug context structure */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 29 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 30 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 31 | /* ====================================================================== |
| 32 | * U-Boot's puts function does not append a newline, so the bedbug stuff |
| 33 | * will use this for the output of the dis/assembler. |
| 34 | * ====================================================================== */ |
| 35 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 36 | int bedbug_puts (const char *str) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 37 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 38 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 39 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 40 | printf ("%s\r\n", str); |
| 41 | return 0; |
| 42 | } /* bedbug_puts */ |
| 43 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 44 | |
| 45 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 46 | /* ====================================================================== |
| 47 | * Initialize the bug_ctx structure used by the bedbug debugger. This is |
| 48 | * specific to the CPU since each has different debug registers and |
| 49 | * settings. |
| 50 | * ====================================================================== */ |
| 51 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 52 | void bedbug_init (void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 53 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 54 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 55 | |
| 56 | #if defined(CONFIG_4xx) |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 57 | void bedbug405_init (void); |
| 58 | |
| 59 | bedbug405_init (); |
wdenk | 6bd1489 | 2003-04-10 11:18:18 +0000 | [diff] [blame] | 60 | #elif defined(CONFIG_8xx) |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 61 | void bedbug860_init (void); |
| 62 | |
| 63 | bedbug860_init (); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 64 | #endif |
| 65 | |
| 66 | #if defined(CONFIG_MPC824X) || defined(CONFIG_MPC8260) |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 67 | /* Processors that are 603e core based */ |
| 68 | void bedbug603e_init (void); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 69 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 70 | bedbug603e_init (); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 71 | #endif |
| 72 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 73 | return; |
| 74 | } /* bedbug_init */ |
| 75 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 76 | |
| 77 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 78 | /* ====================================================================== |
| 79 | * Entry point from the interpreter to the disassembler. Repeated calls |
| 80 | * will resume from the last disassembled address. |
| 81 | * ====================================================================== */ |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 82 | int do_bedbug_dis (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 83 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 84 | ulong addr; /* Address to start disassembly from */ |
| 85 | ulong len; /* # of instructions to disassemble */ |
| 86 | |
| 87 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 88 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 89 | /* Setup to go from the last address if none is given */ |
| 90 | addr = dis_last_addr; |
| 91 | len = dis_last_len; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 92 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 93 | if (argc < 2) { |
| 94 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 95 | return 1; |
| 96 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 97 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 98 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 99 | /* New command */ |
| 100 | addr = simple_strtoul (argv[1], NULL, 16); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 101 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 102 | /* If an extra param is given then it is the length */ |
| 103 | if (argc > 2) |
| 104 | len = simple_strtoul (argv[2], NULL, 16); |
| 105 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 106 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 107 | /* Run the disassembler */ |
| 108 | disppc ((unsigned char *) addr, 0, len, bedbug_puts, F_RADHEX); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 109 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 110 | dis_last_addr = addr + (len * 4); |
| 111 | dis_last_len = len; |
| 112 | return 0; |
| 113 | } /* do_bedbug_dis */ |
| 114 | |
| 115 | U_BOOT_CMD (ds, 3, 1, do_bedbug_dis, |
| 116 | "ds - disassemble memory\n", |
| 117 | "ds <address> [# instructions]\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 118 | |
| 119 | /* ====================================================================== |
| 120 | * Entry point from the interpreter to the assembler. Assembles |
| 121 | * instructions in consecutive memory locations until a '.' (period) is |
| 122 | * entered on a line by itself. |
| 123 | * ====================================================================== */ |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 124 | int do_bedbug_asm (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 125 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 126 | long mem_addr; /* Address to assemble into */ |
| 127 | unsigned long instr; /* Machine code for text */ |
| 128 | char prompt[15]; /* Prompt string for user input */ |
| 129 | int asm_err; /* Error code from the assembler */ |
| 130 | |
| 131 | /* -------------------------------------------------- */ |
| 132 | int rcode = 0; |
| 133 | |
| 134 | if (argc < 2) { |
| 135 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 136 | return 1; |
| 137 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 138 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 139 | printf ("\nEnter '.' when done\n"); |
| 140 | mem_addr = simple_strtoul (argv[1], NULL, 16); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 141 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 142 | while (1) { |
| 143 | putc ('\n'); |
| 144 | disppc ((unsigned char *) mem_addr, 0, 1, bedbug_puts, |
| 145 | F_RADHEX); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 146 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 147 | sprintf (prompt, "%08lx: ", mem_addr); |
| 148 | readline (prompt); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 149 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 150 | if (console_buffer[0] && strcmp (console_buffer, ".")) { |
| 151 | if ((instr = |
| 152 | asmppc (mem_addr, console_buffer, |
| 153 | &asm_err)) != 0) { |
| 154 | *(unsigned long *) mem_addr = instr; |
| 155 | mem_addr += 4; |
| 156 | } else { |
| 157 | printf ("*** Error: %s ***\n", |
| 158 | asm_error_str (asm_err)); |
| 159 | rcode = 1; |
| 160 | } |
| 161 | } else { |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | return rcode; |
| 166 | } /* do_bedbug_asm */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 167 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 168 | U_BOOT_CMD (as, 2, 0, do_bedbug_asm, |
| 169 | "as - assemble memory\n", "as <address>\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 170 | |
| 171 | /* ====================================================================== |
| 172 | * Used to set a break point from the interpreter. Simply calls into the |
| 173 | * CPU-specific break point set routine. |
| 174 | * ====================================================================== */ |
| 175 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 176 | int do_bedbug_break (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 177 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 178 | /* -------------------------------------------------- */ |
| 179 | if (bug_ctx.do_break) |
| 180 | (*bug_ctx.do_break) (cmdtp, flag, argc, argv); |
| 181 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 182 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 183 | } /* do_bedbug_break */ |
| 184 | |
| 185 | U_BOOT_CMD (break, 3, 0, do_bedbug_break, |
| 186 | "break - set or clear a breakpoint\n", |
| 187 | " - Set or clear a breakpoint\n" |
| 188 | "break <address> - Break at an address\n" |
| 189 | "break off <bp#> - Disable breakpoint.\n" |
| 190 | "break show - List breakpoints.\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 191 | |
| 192 | /* ====================================================================== |
| 193 | * Called from the debug interrupt routine. Simply calls the CPU-specific |
| 194 | * breakpoint handling routine. |
| 195 | * ====================================================================== */ |
| 196 | |
| 197 | void do_bedbug_breakpoint (struct pt_regs *regs) |
| 198 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 199 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 200 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 201 | if (bug_ctx.break_isr) |
| 202 | (*bug_ctx.break_isr) (regs); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 203 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 204 | return; |
| 205 | } /* do_bedbug_breakpoint */ |
| 206 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 207 | |
| 208 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 209 | /* ====================================================================== |
| 210 | * Called from the CPU-specific breakpoint handling routine. Enter a |
| 211 | * mini main loop until the stopped flag is cleared from the breakpoint |
| 212 | * context. |
| 213 | * |
| 214 | * This handles the parts of the debugger that are common to all CPU's. |
| 215 | * ====================================================================== */ |
| 216 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 217 | void bedbug_main_loop (unsigned long addr, struct pt_regs *regs) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 218 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 219 | int len; /* Length of command line */ |
| 220 | int flag; /* Command flags */ |
| 221 | int rc = 0; /* Result from run_command */ |
| 222 | char prompt_str[20]; /* Prompt string */ |
| 223 | static char lastcommand[CFG_CBSIZE] = { 0 }; /* previous command */ |
| 224 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 225 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 226 | if (bug_ctx.clear) |
| 227 | (*bug_ctx.clear) (bug_ctx.current_bp); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 228 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 229 | printf ("Breakpoint %d: ", bug_ctx.current_bp); |
| 230 | disppc ((unsigned char *) addr, 0, 1, bedbug_puts, F_RADHEX); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 231 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 232 | bug_ctx.stopped = 1; |
| 233 | bug_ctx.regs = regs; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 234 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 235 | sprintf (prompt_str, "BEDBUG.%d =>", bug_ctx.current_bp); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 236 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 237 | /* A miniature main loop */ |
| 238 | while (bug_ctx.stopped) { |
| 239 | len = readline (prompt_str); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 240 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 241 | flag = 0; /* assume no special flags for now */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 242 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 243 | if (len > 0) |
| 244 | strcpy (lastcommand, console_buffer); |
| 245 | else if (len == 0) |
| 246 | flag |= CMD_FLAG_REPEAT; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 247 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 248 | if (len == -1) |
| 249 | printf ("<INTERRUPT>\n"); |
| 250 | else |
| 251 | rc = run_command (lastcommand, flag); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 252 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 253 | if (rc <= 0) { |
| 254 | /* invalid command or not repeatable, forget it */ |
| 255 | lastcommand[0] = 0; |
| 256 | } |
| 257 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 258 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 259 | bug_ctx.regs = NULL; |
| 260 | bug_ctx.current_bp = 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 261 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 262 | return; |
| 263 | } /* bedbug_main_loop */ |
| 264 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 265 | |
| 266 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 267 | /* ====================================================================== |
| 268 | * Interpreter command to continue from a breakpoint. Just clears the |
| 269 | * stopped flag in the context so that the breakpoint routine will |
| 270 | * return. |
| 271 | * ====================================================================== */ |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 272 | int do_bedbug_continue (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 273 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 274 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 275 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 276 | if (!bug_ctx.stopped) { |
| 277 | printf ("Not at a breakpoint\n"); |
| 278 | return 1; |
| 279 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 280 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 281 | bug_ctx.stopped = 0; |
| 282 | return 0; |
| 283 | } /* do_bedbug_continue */ |
| 284 | |
| 285 | U_BOOT_CMD (continue, 1, 0, do_bedbug_continue, |
| 286 | "continue- continue from a breakpoint\n", |
| 287 | " - continue from a breakpoint.\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 288 | |
| 289 | /* ====================================================================== |
| 290 | * Interpreter command to continue to the next instruction, stepping into |
| 291 | * subroutines. Works by calling the find_next_addr() routine to compute |
| 292 | * the address passes control to the CPU-specific set breakpoint routine |
| 293 | * for the current breakpoint number. |
| 294 | * ====================================================================== */ |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 295 | int do_bedbug_step (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 296 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 297 | unsigned long addr; /* Address to stop at */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 298 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 299 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 300 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 301 | if (!bug_ctx.stopped) { |
| 302 | printf ("Not at a breakpoint\n"); |
| 303 | return 1; |
| 304 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 305 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 306 | if (!find_next_address ((unsigned char *) &addr, FALSE, bug_ctx.regs)) |
| 307 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 308 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 309 | if (bug_ctx.set) |
| 310 | (*bug_ctx.set) (bug_ctx.current_bp, addr); |
| 311 | |
| 312 | bug_ctx.stopped = 0; |
| 313 | return 0; |
| 314 | } /* do_bedbug_step */ |
| 315 | |
| 316 | U_BOOT_CMD (step, 1, 1, do_bedbug_step, |
| 317 | "step - single step execution.\n", |
| 318 | " - single step execution.\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 319 | |
| 320 | /* ====================================================================== |
| 321 | * Interpreter command to continue to the next instruction, stepping over |
| 322 | * subroutines. Works by calling the find_next_addr() routine to compute |
| 323 | * the address passes control to the CPU-specific set breakpoint routine |
| 324 | * for the current breakpoint number. |
| 325 | * ====================================================================== */ |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 326 | int do_bedbug_next (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 327 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 328 | unsigned long addr; /* Address to stop at */ |
| 329 | |
| 330 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 331 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 332 | if (!bug_ctx.stopped) { |
| 333 | printf ("Not at a breakpoint\n"); |
| 334 | return 1; |
| 335 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 336 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 337 | if (!find_next_address ((unsigned char *) &addr, TRUE, bug_ctx.regs)) |
| 338 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 339 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 340 | if (bug_ctx.set) |
| 341 | (*bug_ctx.set) (bug_ctx.current_bp, addr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 342 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 343 | bug_ctx.stopped = 0; |
| 344 | return 0; |
| 345 | } /* do_bedbug_next */ |
| 346 | |
| 347 | U_BOOT_CMD (next, 1, 1, do_bedbug_next, |
| 348 | "next - single step execution, stepping over subroutines.\n", |
| 349 | " - single step execution, stepping over subroutines.\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 350 | |
| 351 | /* ====================================================================== |
| 352 | * Interpreter command to print the current stack. This assumes an EABI |
| 353 | * architecture, so it starts with GPR R1 and works back up the stack. |
| 354 | * ====================================================================== */ |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 355 | int do_bedbug_stack (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 356 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 357 | unsigned long sp; /* Stack pointer */ |
| 358 | unsigned long func; /* LR from stack */ |
| 359 | int depth; /* Stack iteration level */ |
| 360 | int skip = 1; /* Flag to skip the first entry */ |
| 361 | unsigned long top; /* Top of memory address */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 362 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 363 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 364 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 365 | if (!bug_ctx.stopped) { |
| 366 | printf ("Not at a breakpoint\n"); |
| 367 | return 1; |
| 368 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 369 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 370 | top = gd->bd->bi_memstart + gd->bd->bi_memsize; |
| 371 | depth = 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 372 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 373 | printf ("Depth PC\n"); |
| 374 | printf ("----- --------\n"); |
| 375 | printf ("%5d %08lx\n", depth++, bug_ctx.regs->nip); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 376 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 377 | sp = bug_ctx.regs->gpr[1]; |
| 378 | func = *(unsigned long *) (sp + 4); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 379 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 380 | while ((func < top) && (sp < top)) { |
| 381 | if (!skip) |
| 382 | printf ("%5d %08lx\n", depth++, func); |
| 383 | else |
| 384 | --skip; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 385 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 386 | sp = *(unsigned long *) sp; |
| 387 | func = *(unsigned long *) (sp + 4); |
| 388 | } |
| 389 | return 0; |
| 390 | } /* do_bedbug_stack */ |
| 391 | |
| 392 | U_BOOT_CMD (where, 1, 1, do_bedbug_stack, |
| 393 | "where - Print the running stack.\n", |
| 394 | " - Print the running stack.\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 395 | |
| 396 | /* ====================================================================== |
| 397 | * Interpreter command to dump the registers. Calls the CPU-specific |
| 398 | * show registers routine. |
| 399 | * ====================================================================== */ |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 400 | int do_bedbug_rdump (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 401 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 402 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 403 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 404 | if (!bug_ctx.stopped) { |
| 405 | printf ("Not at a breakpoint\n"); |
| 406 | return 1; |
| 407 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 408 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 409 | show_regs (bug_ctx.regs); |
| 410 | return 0; |
| 411 | } /* do_bedbug_rdump */ |
| 412 | |
| 413 | U_BOOT_CMD (rdump, 1, 1, do_bedbug_rdump, |
| 414 | "rdump - Show registers.\n", " - Show registers.\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 415 | /* ====================================================================== */ |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 416 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 417 | |
| 418 | |
| 419 | /* |
| 420 | * Copyright (c) 2001 William L. Pitts |
| 421 | * All rights reserved. |
| 422 | * |
| 423 | * Redistribution and use in source and binary forms are freely |
| 424 | * permitted provided that the above copyright notice and this |
| 425 | * paragraph and the following disclaimer are duplicated in all |
| 426 | * such forms. |
| 427 | * |
| 428 | * This software is provided "AS IS" and without any express or |
| 429 | * implied warranties, including, without limitation, the implied |
| 430 | * warranties of merchantability and fitness for a particular |
| 431 | * purpose. |
| 432 | */ |