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