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