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