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