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