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