wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * BedBug Functions |
| 3 | */ |
| 4 | |
| 5 | #include <common.h> |
Simon Glass | dec3c01 | 2014-04-10 20:01:25 -0600 | [diff] [blame] | 6 | #include <cli.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 7 | #include <command.h> |
| 8 | #include <linux/ctype.h> |
| 9 | #include <net.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 10 | #include <bedbug/type.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 11 | #include <bedbug/bedbug.h> |
| 12 | #include <bedbug/regs.h> |
| 13 | #include <bedbug/ppc.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 14 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 17 | extern void show_regs __P ((struct pt_regs *)); |
| 18 | extern int run_command __P ((const char *, int)); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 19 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 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 */ |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 23 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 24 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 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 | * ====================================================================== */ |
| 29 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 30 | int bedbug_puts (const char *str) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 31 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 32 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 33 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 34 | printf ("%s\r\n", str); |
| 35 | return 0; |
| 36 | } /* bedbug_puts */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 37 | |
| 38 | |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 39 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 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 |
| 43 | * settings. |
| 44 | * ====================================================================== */ |
| 45 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 46 | void bedbug_init (void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 47 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 48 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 49 | |
| 50 | #if defined(CONFIG_4xx) |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 51 | void bedbug405_init (void); |
| 52 | |
| 53 | bedbug405_init (); |
wdenk | 6bd1489 | 2003-04-10 11:18:18 +0000 | [diff] [blame] | 54 | #elif defined(CONFIG_8xx) |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 55 | void bedbug860_init (void); |
| 56 | |
| 57 | bedbug860_init (); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
| 60 | #if defined(CONFIG_MPC824X) || defined(CONFIG_MPC8260) |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 61 | /* Processors that are 603e core based */ |
| 62 | void bedbug603e_init (void); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 63 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 64 | bedbug603e_init (); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 65 | #endif |
| 66 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 67 | return; |
| 68 | } /* bedbug_init */ |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 69 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 70 | |
| 71 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 72 | /* ====================================================================== |
| 73 | * Entry point from the interpreter to the disassembler. Repeated calls |
| 74 | * will resume from the last disassembled address. |
| 75 | * ====================================================================== */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 76 | int do_bedbug_dis (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 77 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 78 | ulong addr; /* Address to start disassembly from */ |
| 79 | ulong len; /* # of instructions to disassemble */ |
| 80 | |
| 81 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 82 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 83 | /* Setup to go from the last address if none is given */ |
| 84 | addr = dis_last_addr; |
| 85 | len = dis_last_len; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 86 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 87 | if (argc < 2) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 88 | return CMD_RET_USAGE; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 89 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 90 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 91 | /* New command */ |
| 92 | addr = simple_strtoul (argv[1], NULL, 16); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 93 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 94 | /* If an extra param is given then it is the length */ |
| 95 | if (argc > 2) |
| 96 | len = simple_strtoul (argv[2], NULL, 16); |
| 97 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 98 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 99 | /* Run the disassembler */ |
| 100 | disppc ((unsigned char *) addr, 0, len, bedbug_puts, F_RADHEX); |
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 | dis_last_addr = addr + (len * 4); |
| 103 | dis_last_len = len; |
| 104 | return 0; |
| 105 | } /* do_bedbug_dis */ |
| 106 | |
| 107 | U_BOOT_CMD (ds, 3, 1, do_bedbug_dis, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 108 | "disassemble memory", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 109 | "ds <address> [# instructions]"); |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 110 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 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 | * ====================================================================== */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 116 | int do_bedbug_asm (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 117 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 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 */ |
| 122 | |
| 123 | /* -------------------------------------------------- */ |
| 124 | int rcode = 0; |
| 125 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 126 | if (argc < 2) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 127 | return CMD_RET_USAGE; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 128 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 129 | printf ("\nEnter '.' when done\n"); |
| 130 | mem_addr = simple_strtoul (argv[1], NULL, 16); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 131 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 132 | while (1) { |
| 133 | putc ('\n'); |
| 134 | disppc ((unsigned char *) mem_addr, 0, 1, bedbug_puts, |
| 135 | F_RADHEX); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 136 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 137 | sprintf (prompt, "%08lx: ", mem_addr); |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 138 | cli_readline(prompt); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 139 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 140 | if (console_buffer[0] && strcmp (console_buffer, ".")) { |
| 141 | if ((instr = |
| 142 | asmppc (mem_addr, console_buffer, |
| 143 | &asm_err)) != 0) { |
| 144 | *(unsigned long *) mem_addr = instr; |
| 145 | mem_addr += 4; |
| 146 | } else { |
| 147 | printf ("*** Error: %s ***\n", |
| 148 | asm_error_str (asm_err)); |
| 149 | rcode = 1; |
| 150 | } |
| 151 | } else { |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | return rcode; |
| 156 | } /* do_bedbug_asm */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 157 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 158 | U_BOOT_CMD (as, 2, 0, do_bedbug_asm, |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 159 | "assemble memory", "as <address>"); |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 160 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 161 | /* ====================================================================== |
| 162 | * Used to set a break point from the interpreter. Simply calls into the |
| 163 | * CPU-specific break point set routine. |
| 164 | * ====================================================================== */ |
| 165 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 166 | int do_bedbug_break (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
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 | /* -------------------------------------------------- */ |
| 169 | if (bug_ctx.do_break) |
| 170 | (*bug_ctx.do_break) (cmdtp, flag, argc, argv); |
| 171 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 172 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 173 | } /* do_bedbug_break */ |
| 174 | |
| 175 | U_BOOT_CMD (break, 3, 0, do_bedbug_break, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 176 | "set or clear a breakpoint", |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 177 | " - Set or clear a breakpoint\n" |
| 178 | "break <address> - Break at an address\n" |
| 179 | "break off <bp#> - Disable breakpoint.\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 180 | "break show - List breakpoints."); |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 181 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 182 | /* ====================================================================== |
| 183 | * Called from the debug interrupt routine. Simply calls the CPU-specific |
| 184 | * breakpoint handling routine. |
| 185 | * ====================================================================== */ |
| 186 | |
| 187 | void do_bedbug_breakpoint (struct pt_regs *regs) |
| 188 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 189 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 190 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 191 | if (bug_ctx.break_isr) |
| 192 | (*bug_ctx.break_isr) (regs); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 193 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 194 | return; |
| 195 | } /* do_bedbug_breakpoint */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 196 | |
| 197 | |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 198 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 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 |
| 202 | * context. |
| 203 | * |
| 204 | * This handles the parts of the debugger that are common to all CPU's. |
| 205 | * ====================================================================== */ |
| 206 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 207 | void bedbug_main_loop (unsigned long addr, struct pt_regs *regs) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 208 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 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 */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 213 | static char lastcommand[CONFIG_SYS_CBSIZE] = { 0 }; /* previous command */ |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 214 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 215 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 216 | if (bug_ctx.clear) |
| 217 | (*bug_ctx.clear) (bug_ctx.current_bp); |
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 | printf ("Breakpoint %d: ", bug_ctx.current_bp); |
| 220 | disppc ((unsigned char *) addr, 0, 1, bedbug_puts, F_RADHEX); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 221 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 222 | bug_ctx.stopped = 1; |
| 223 | bug_ctx.regs = regs; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 224 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 225 | sprintf (prompt_str, "BEDBUG.%d =>", bug_ctx.current_bp); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 226 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 227 | /* A miniature main loop */ |
| 228 | while (bug_ctx.stopped) { |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 229 | len = cli_readline(prompt_str); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 230 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 231 | flag = 0; /* assume no special flags for now */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 232 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 233 | if (len > 0) |
| 234 | strcpy (lastcommand, console_buffer); |
| 235 | else if (len == 0) |
| 236 | flag |= CMD_FLAG_REPEAT; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 237 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 238 | if (len == -1) |
| 239 | printf ("<INTERRUPT>\n"); |
| 240 | else |
Thomas Betker | 0271756 | 2014-06-05 20:07:58 +0200 | [diff] [blame] | 241 | rc = run_command_repeatable(lastcommand, flag); |
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 (rc <= 0) { |
| 244 | /* invalid command or not repeatable, forget it */ |
| 245 | lastcommand[0] = 0; |
| 246 | } |
| 247 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 248 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 249 | bug_ctx.regs = NULL; |
| 250 | bug_ctx.current_bp = 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 251 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 252 | return; |
| 253 | } /* bedbug_main_loop */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 254 | |
| 255 | |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 256 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 257 | /* ====================================================================== |
| 258 | * Interpreter command to continue from a breakpoint. Just clears the |
| 259 | * stopped flag in the context so that the breakpoint routine will |
| 260 | * return. |
| 261 | * ====================================================================== */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 262 | int do_bedbug_continue (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 263 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 264 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 265 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 266 | if (!bug_ctx.stopped) { |
| 267 | printf ("Not at a breakpoint\n"); |
| 268 | return 1; |
| 269 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 270 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 271 | bug_ctx.stopped = 0; |
| 272 | return 0; |
| 273 | } /* do_bedbug_continue */ |
| 274 | |
| 275 | U_BOOT_CMD (continue, 1, 0, do_bedbug_continue, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 276 | "continue from a breakpoint", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 277 | ""); |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 278 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 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 | * ====================================================================== */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 285 | int do_bedbug_step (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 286 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 287 | unsigned long addr; /* Address to stop at */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 288 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 289 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 290 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 291 | if (!bug_ctx.stopped) { |
| 292 | printf ("Not at a breakpoint\n"); |
| 293 | return 1; |
| 294 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 295 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 296 | if (!find_next_address((unsigned char *) &addr, false, bug_ctx.regs)) |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 297 | return 1; |
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 | if (bug_ctx.set) |
| 300 | (*bug_ctx.set) (bug_ctx.current_bp, addr); |
| 301 | |
| 302 | bug_ctx.stopped = 0; |
| 303 | return 0; |
| 304 | } /* do_bedbug_step */ |
| 305 | |
| 306 | U_BOOT_CMD (step, 1, 1, do_bedbug_step, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 307 | "single step execution.", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 308 | ""); |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 309 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 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 | * ====================================================================== */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 316 | int do_bedbug_next (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 317 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 318 | unsigned long addr; /* Address to stop at */ |
| 319 | |
| 320 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 321 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 322 | if (!bug_ctx.stopped) { |
| 323 | printf ("Not at a breakpoint\n"); |
| 324 | return 1; |
| 325 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 326 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 327 | if (!find_next_address((unsigned char *) &addr, true, bug_ctx.regs)) |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 328 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 329 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 330 | if (bug_ctx.set) |
| 331 | (*bug_ctx.set) (bug_ctx.current_bp, addr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 332 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 333 | bug_ctx.stopped = 0; |
| 334 | return 0; |
| 335 | } /* do_bedbug_next */ |
| 336 | |
| 337 | U_BOOT_CMD (next, 1, 1, do_bedbug_next, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 338 | "single step execution, stepping over subroutines.", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 339 | ""); |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 340 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 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 | * ====================================================================== */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 345 | int do_bedbug_stack (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 346 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 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 */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 352 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 353 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 354 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 355 | if (!bug_ctx.stopped) { |
| 356 | printf ("Not at a breakpoint\n"); |
| 357 | return 1; |
| 358 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 359 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 360 | top = gd->bd->bi_memstart + gd->bd->bi_memsize; |
| 361 | depth = 0; |
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 | printf ("Depth PC\n"); |
| 364 | printf ("----- --------\n"); |
| 365 | printf ("%5d %08lx\n", depth++, bug_ctx.regs->nip); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 366 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 367 | sp = bug_ctx.regs->gpr[1]; |
| 368 | func = *(unsigned long *) (sp + 4); |
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 | while ((func < top) && (sp < top)) { |
| 371 | if (!skip) |
| 372 | printf ("%5d %08lx\n", depth++, func); |
| 373 | else |
| 374 | --skip; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 375 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 376 | sp = *(unsigned long *) sp; |
| 377 | func = *(unsigned long *) (sp + 4); |
| 378 | } |
| 379 | return 0; |
| 380 | } /* do_bedbug_stack */ |
| 381 | |
| 382 | U_BOOT_CMD (where, 1, 1, do_bedbug_stack, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 383 | "Print the running stack.", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 384 | ""); |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 385 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 386 | /* ====================================================================== |
| 387 | * Interpreter command to dump the registers. Calls the CPU-specific |
| 388 | * show registers routine. |
| 389 | * ====================================================================== */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 390 | int do_bedbug_rdump (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 391 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 392 | /* -------------------------------------------------- */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 393 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 394 | if (!bug_ctx.stopped) { |
| 395 | printf ("Not at a breakpoint\n"); |
| 396 | return 1; |
| 397 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 398 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 399 | show_regs (bug_ctx.regs); |
| 400 | return 0; |
| 401 | } /* do_bedbug_rdump */ |
| 402 | |
| 403 | U_BOOT_CMD (rdump, 1, 1, do_bedbug_rdump, |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 404 | "Show registers.", ""); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 405 | /* ====================================================================== */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 406 | |
| 407 | |
| 408 | /* |
| 409 | * Copyright (c) 2001 William L. Pitts |
| 410 | * All rights reserved. |
| 411 | * |
| 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 |
| 415 | * such forms. |
| 416 | * |
| 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 |
| 420 | * purpose. |
| 421 | */ |