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