Rev 4132 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4132 | Rev 4137 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2005 Ondrej Palkovsky |
2 | * Copyright (c) 2005 Ondrej Palkovsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup mips32debug |
29 | /** @addtogroup mips32debug |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <arch/debugger.h> |
35 | #include <arch/debugger.h> |
36 | #include <arch/barrier.h> |
36 | #include <arch/barrier.h> |
37 | #include <memstr.h> |
37 | #include <memstr.h> |
38 | #include <console/kconsole.h> |
38 | #include <console/kconsole.h> |
39 | #include <console/cmd.h> |
39 | #include <console/cmd.h> |
40 | #include <print.h> |
40 | #include <print.h> |
41 | #include <panic.h> |
41 | #include <panic.h> |
42 | #include <arch.h> |
42 | #include <arch.h> |
43 | #include <arch/cp0.h> |
43 | #include <arch/cp0.h> |
44 | #include <func.h> |
44 | #include <func.h> |
45 | - | ||
46 | #ifdef CONFIG_SYMTAB |
- | |
47 | #include <symtab.h> |
45 | #include <symtab.h> |
48 | #endif |
- | |
49 | 46 | ||
50 | bpinfo_t breakpoints[BKPOINTS_MAX]; |
47 | bpinfo_t breakpoints[BKPOINTS_MAX]; |
51 | SPINLOCK_INITIALIZE(bkpoint_lock); |
48 | SPINLOCK_INITIALIZE(bkpoint_lock); |
52 | 49 | ||
53 | #ifdef CONFIG_KCONSOLE |
50 | #ifdef CONFIG_KCONSOLE |
54 | 51 | ||
55 | static int cmd_print_breakpoints(cmd_arg_t *argv); |
52 | static int cmd_print_breakpoints(cmd_arg_t *argv); |
56 | static cmd_info_t bkpts_info = { |
53 | static cmd_info_t bkpts_info = { |
57 | .name = "bkpts", |
54 | .name = "bkpts", |
58 | .description = "Print breakpoint table.", |
55 | .description = "Print breakpoint table.", |
59 | .func = cmd_print_breakpoints, |
56 | .func = cmd_print_breakpoints, |
60 | .argc = 0, |
57 | .argc = 0, |
61 | }; |
58 | }; |
62 | 59 | ||
63 | static int cmd_del_breakpoint(cmd_arg_t *argv); |
60 | static int cmd_del_breakpoint(cmd_arg_t *argv); |
64 | static cmd_arg_t del_argv = { |
61 | static cmd_arg_t del_argv = { |
65 | .type = ARG_TYPE_INT |
62 | .type = ARG_TYPE_INT |
66 | }; |
63 | }; |
67 | static cmd_info_t delbkpt_info = { |
64 | static cmd_info_t delbkpt_info = { |
68 | .name = "delbkpt", |
65 | .name = "delbkpt", |
69 | .description = "delbkpt <number> - Delete breakpoint.", |
66 | .description = "delbkpt <number> - Delete breakpoint.", |
70 | .func = cmd_del_breakpoint, |
67 | .func = cmd_del_breakpoint, |
71 | .argc = 1, |
68 | .argc = 1, |
72 | .argv = &del_argv |
69 | .argv = &del_argv |
73 | }; |
70 | }; |
74 | 71 | ||
75 | static int cmd_add_breakpoint(cmd_arg_t *argv); |
72 | static int cmd_add_breakpoint(cmd_arg_t *argv); |
76 | static cmd_arg_t add_argv = { |
73 | static cmd_arg_t add_argv = { |
77 | .type = ARG_TYPE_INT |
74 | .type = ARG_TYPE_INT |
78 | }; |
75 | }; |
79 | static cmd_info_t addbkpt_info = { |
76 | static cmd_info_t addbkpt_info = { |
80 | .name = "addbkpt", |
77 | .name = "addbkpt", |
81 | .description = "addbkpt <&symbol> - new bkpoint. Break on J/Branch " |
78 | .description = "addbkpt <&symbol> - new bkpoint. Break on J/Branch " |
82 | "insts unsupported.", |
79 | "insts unsupported.", |
83 | .func = cmd_add_breakpoint, |
80 | .func = cmd_add_breakpoint, |
84 | .argc = 1, |
81 | .argc = 1, |
85 | .argv = &add_argv |
82 | .argv = &add_argv |
86 | }; |
83 | }; |
87 | 84 | ||
88 | static cmd_arg_t adde_argv[] = { |
85 | static cmd_arg_t adde_argv[] = { |
89 | { .type = ARG_TYPE_INT }, |
86 | { .type = ARG_TYPE_INT }, |
90 | { .type = ARG_TYPE_INT } |
87 | { .type = ARG_TYPE_INT } |
91 | }; |
88 | }; |
92 | static cmd_info_t addbkpte_info = { |
89 | static cmd_info_t addbkpte_info = { |
93 | .name = "addbkpte", |
90 | .name = "addbkpte", |
94 | .description = "addebkpte <&symbol> <&func> - new bkpoint. Call " |
91 | .description = "addebkpte <&symbol> <&func> - new bkpoint. Call " |
95 | "func(or Nothing if 0).", |
92 | "func(or Nothing if 0).", |
96 | .func = cmd_add_breakpoint, |
93 | .func = cmd_add_breakpoint, |
97 | .argc = 2, |
94 | .argc = 2, |
98 | .argv = adde_argv |
95 | .argv = adde_argv |
99 | }; |
96 | }; |
100 | 97 | ||
101 | static struct { |
98 | static struct { |
102 | uint32_t andmask; |
99 | uint32_t andmask; |
103 | uint32_t value; |
100 | uint32_t value; |
104 | } jmpinstr[] = { |
101 | } jmpinstr[] = { |
105 | {0xf3ff0000, 0x41000000}, /* BCzF */ |
102 | {0xf3ff0000, 0x41000000}, /* BCzF */ |
106 | {0xf3ff0000, 0x41020000}, /* BCzFL */ |
103 | {0xf3ff0000, 0x41020000}, /* BCzFL */ |
107 | {0xf3ff0000, 0x41010000}, /* BCzT */ |
104 | {0xf3ff0000, 0x41010000}, /* BCzT */ |
108 | {0xf3ff0000, 0x41030000}, /* BCzTL */ |
105 | {0xf3ff0000, 0x41030000}, /* BCzTL */ |
109 | {0xfc000000, 0x10000000}, /* BEQ */ |
106 | {0xfc000000, 0x10000000}, /* BEQ */ |
110 | {0xfc000000, 0x50000000}, /* BEQL */ |
107 | {0xfc000000, 0x50000000}, /* BEQL */ |
111 | {0xfc1f0000, 0x04010000}, /* BEQL */ |
108 | {0xfc1f0000, 0x04010000}, /* BEQL */ |
112 | {0xfc1f0000, 0x04110000}, /* BGEZAL */ |
109 | {0xfc1f0000, 0x04110000}, /* BGEZAL */ |
113 | {0xfc1f0000, 0x04130000}, /* BGEZALL */ |
110 | {0xfc1f0000, 0x04130000}, /* BGEZALL */ |
114 | {0xfc1f0000, 0x04030000}, /* BGEZL */ |
111 | {0xfc1f0000, 0x04030000}, /* BGEZL */ |
115 | {0xfc1f0000, 0x1c000000}, /* BGTZ */ |
112 | {0xfc1f0000, 0x1c000000}, /* BGTZ */ |
116 | {0xfc1f0000, 0x5c000000}, /* BGTZL */ |
113 | {0xfc1f0000, 0x5c000000}, /* BGTZL */ |
117 | {0xfc1f0000, 0x18000000}, /* BLEZ */ |
114 | {0xfc1f0000, 0x18000000}, /* BLEZ */ |
118 | {0xfc1f0000, 0x58000000}, /* BLEZL */ |
115 | {0xfc1f0000, 0x58000000}, /* BLEZL */ |
119 | {0xfc1f0000, 0x04000000}, /* BLTZ */ |
116 | {0xfc1f0000, 0x04000000}, /* BLTZ */ |
120 | {0xfc1f0000, 0x04100000}, /* BLTZAL */ |
117 | {0xfc1f0000, 0x04100000}, /* BLTZAL */ |
121 | {0xfc1f0000, 0x04120000}, /* BLTZALL */ |
118 | {0xfc1f0000, 0x04120000}, /* BLTZALL */ |
122 | {0xfc1f0000, 0x04020000}, /* BLTZL */ |
119 | {0xfc1f0000, 0x04020000}, /* BLTZL */ |
123 | {0xfc000000, 0x14000000}, /* BNE */ |
120 | {0xfc000000, 0x14000000}, /* BNE */ |
124 | {0xfc000000, 0x54000000}, /* BNEL */ |
121 | {0xfc000000, 0x54000000}, /* BNEL */ |
125 | {0xfc000000, 0x08000000}, /* J */ |
122 | {0xfc000000, 0x08000000}, /* J */ |
126 | {0xfc000000, 0x0c000000}, /* JAL */ |
123 | {0xfc000000, 0x0c000000}, /* JAL */ |
127 | {0xfc1f07ff, 0x00000009}, /* JALR */ |
124 | {0xfc1f07ff, 0x00000009}, /* JALR */ |
128 | {0, 0} /* EndOfTable */ |
125 | {0, 0} /* EndOfTable */ |
129 | }; |
126 | }; |
130 | 127 | ||
131 | 128 | ||
132 | /** Test, if the given instruction is a jump or branch instruction |
129 | /** Test, if the given instruction is a jump or branch instruction |
133 | * |
130 | * |
134 | * @param instr Instruction code |
131 | * @param instr Instruction code |
135 | * @return true - it is jump instruction, false otherwise |
132 | * @return true - it is jump instruction, false otherwise |
136 | * |
133 | * |
137 | */ |
134 | */ |
138 | static bool is_jump(unative_t instr) |
135 | static bool is_jump(unative_t instr) |
139 | { |
136 | { |
140 | int i; |
137 | int i; |
141 | 138 | ||
142 | for (i = 0; jmpinstr[i].andmask; i++) { |
139 | for (i = 0; jmpinstr[i].andmask; i++) { |
143 | if ((instr & jmpinstr[i].andmask) == jmpinstr[i].value) |
140 | if ((instr & jmpinstr[i].andmask) == jmpinstr[i].value) |
144 | return true; |
141 | return true; |
145 | } |
142 | } |
146 | 143 | ||
147 | return false; |
144 | return false; |
148 | } |
145 | } |
149 | 146 | ||
150 | /** Add new breakpoint to table */ |
147 | /** Add new breakpoint to table */ |
151 | int cmd_add_breakpoint(cmd_arg_t *argv) |
148 | int cmd_add_breakpoint(cmd_arg_t *argv) |
152 | { |
149 | { |
153 | bpinfo_t *cur = NULL; |
150 | bpinfo_t *cur = NULL; |
154 | ipl_t ipl; |
151 | ipl_t ipl; |
155 | int i; |
152 | int i; |
156 | 153 | ||
157 | if (argv->intval & 0x3) { |
154 | if (argv->intval & 0x3) { |
158 | printf("Not aligned instruction, forgot to use &symbol?\n"); |
155 | printf("Not aligned instruction, forgot to use &symbol?\n"); |
159 | return 1; |
156 | return 1; |
160 | } |
157 | } |
161 | ipl = interrupts_disable(); |
158 | ipl = interrupts_disable(); |
162 | spinlock_lock(&bkpoint_lock); |
159 | spinlock_lock(&bkpoint_lock); |
163 | 160 | ||
164 | /* Check, that the breakpoints do not conflict */ |
161 | /* Check, that the breakpoints do not conflict */ |
165 | for (i = 0; i < BKPOINTS_MAX; i++) { |
162 | for (i = 0; i < BKPOINTS_MAX; i++) { |
166 | if (breakpoints[i].address == (uintptr_t)argv->intval) { |
163 | if (breakpoints[i].address == (uintptr_t)argv->intval) { |
167 | printf("Duplicate breakpoint %d.\n", i); |
164 | printf("Duplicate breakpoint %d.\n", i); |
168 | spinlock_unlock(&bkpoint_lock); |
165 | spinlock_unlock(&bkpoint_lock); |
169 | return 0; |
166 | return 0; |
170 | } else if (breakpoints[i].address == (uintptr_t)argv->intval + |
167 | } else if (breakpoints[i].address == (uintptr_t)argv->intval + |
171 | sizeof(unative_t) || breakpoints[i].address == |
168 | sizeof(unative_t) || breakpoints[i].address == |
172 | (uintptr_t)argv->intval - sizeof(unative_t)) { |
169 | (uintptr_t)argv->intval - sizeof(unative_t)) { |
173 | printf("Adjacent breakpoints not supported, conflict " |
170 | printf("Adjacent breakpoints not supported, conflict " |
174 | "with %d.\n", i); |
171 | "with %d.\n", i); |
175 | spinlock_unlock(&bkpoint_lock); |
172 | spinlock_unlock(&bkpoint_lock); |
176 | return 0; |
173 | return 0; |
177 | } |
174 | } |
178 | 175 | ||
179 | } |
176 | } |
180 | 177 | ||
181 | for (i = 0; i < BKPOINTS_MAX; i++) |
178 | for (i = 0; i < BKPOINTS_MAX; i++) |
182 | if (!breakpoints[i].address) { |
179 | if (!breakpoints[i].address) { |
183 | cur = &breakpoints[i]; |
180 | cur = &breakpoints[i]; |
184 | break; |
181 | break; |
185 | } |
182 | } |
186 | if (!cur) { |
183 | if (!cur) { |
187 | printf("Too many breakpoints.\n"); |
184 | printf("Too many breakpoints.\n"); |
188 | spinlock_unlock(&bkpoint_lock); |
185 | spinlock_unlock(&bkpoint_lock); |
189 | interrupts_restore(ipl); |
186 | interrupts_restore(ipl); |
190 | return 0; |
187 | return 0; |
191 | } |
188 | } |
192 | cur->address = (uintptr_t) argv->intval; |
189 | cur->address = (uintptr_t) argv->intval; |
193 | printf("Adding breakpoint on address: %p\n", argv->intval); |
190 | printf("Adding breakpoint on address: %p\n", argv->intval); |
194 | cur->instruction = ((unative_t *)cur->address)[0]; |
191 | cur->instruction = ((unative_t *)cur->address)[0]; |
195 | cur->nextinstruction = ((unative_t *)cur->address)[1]; |
192 | cur->nextinstruction = ((unative_t *)cur->address)[1]; |
196 | if (argv == &add_argv) { |
193 | if (argv == &add_argv) { |
197 | cur->flags = 0; |
194 | cur->flags = 0; |
198 | } else { /* We are add extended */ |
195 | } else { /* We are add extended */ |
199 | cur->flags = BKPOINT_FUNCCALL; |
196 | cur->flags = BKPOINT_FUNCCALL; |
200 | cur->bkfunc = (void (*)(void *, istate_t *)) argv[1].intval; |
197 | cur->bkfunc = (void (*)(void *, istate_t *)) argv[1].intval; |
201 | } |
198 | } |
202 | if (is_jump(cur->instruction)) |
199 | if (is_jump(cur->instruction)) |
203 | cur->flags |= BKPOINT_ONESHOT; |
200 | cur->flags |= BKPOINT_ONESHOT; |
204 | cur->counter = 0; |
201 | cur->counter = 0; |
205 | 202 | ||
206 | /* Set breakpoint */ |
203 | /* Set breakpoint */ |
207 | *((unative_t *)cur->address) = 0x0d; |
204 | *((unative_t *)cur->address) = 0x0d; |
208 | smc_coherence(cur->address); |
205 | smc_coherence(cur->address); |
209 | 206 | ||
210 | spinlock_unlock(&bkpoint_lock); |
207 | spinlock_unlock(&bkpoint_lock); |
211 | interrupts_restore(ipl); |
208 | interrupts_restore(ipl); |
212 | 209 | ||
213 | return 1; |
210 | return 1; |
214 | } |
211 | } |
215 | 212 | ||
216 | /** Remove breakpoint from table */ |
213 | /** Remove breakpoint from table */ |
217 | int cmd_del_breakpoint(cmd_arg_t *argv) |
214 | int cmd_del_breakpoint(cmd_arg_t *argv) |
218 | { |
215 | { |
219 | bpinfo_t *cur; |
216 | bpinfo_t *cur; |
220 | ipl_t ipl; |
217 | ipl_t ipl; |
221 | 218 | ||
222 | if (argv->intval > BKPOINTS_MAX) { |
219 | if (argv->intval > BKPOINTS_MAX) { |
223 | printf("Invalid breakpoint number.\n"); |
220 | printf("Invalid breakpoint number.\n"); |
224 | return 0; |
221 | return 0; |
225 | } |
222 | } |
226 | ipl = interrupts_disable(); |
223 | ipl = interrupts_disable(); |
227 | spinlock_lock(&bkpoint_lock); |
224 | spinlock_lock(&bkpoint_lock); |
228 | 225 | ||
229 | cur = &breakpoints[argv->intval]; |
226 | cur = &breakpoints[argv->intval]; |
230 | if (!cur->address) { |
227 | if (!cur->address) { |
231 | printf("Breakpoint does not exist.\n"); |
228 | printf("Breakpoint does not exist.\n"); |
232 | spinlock_unlock(&bkpoint_lock); |
229 | spinlock_unlock(&bkpoint_lock); |
233 | interrupts_restore(ipl); |
230 | interrupts_restore(ipl); |
234 | return 0; |
231 | return 0; |
235 | } |
232 | } |
236 | if ((cur->flags & BKPOINT_INPROG) && (cur->flags & BKPOINT_ONESHOT)) { |
233 | if ((cur->flags & BKPOINT_INPROG) && (cur->flags & BKPOINT_ONESHOT)) { |
237 | printf("Cannot remove one-shot breakpoint in-progress\n"); |
234 | printf("Cannot remove one-shot breakpoint in-progress\n"); |
238 | spinlock_unlock(&bkpoint_lock); |
235 | spinlock_unlock(&bkpoint_lock); |
239 | interrupts_restore(ipl); |
236 | interrupts_restore(ipl); |
240 | return 0; |
237 | return 0; |
241 | } |
238 | } |
242 | ((uint32_t *)cur->address)[0] = cur->instruction; |
239 | ((uint32_t *)cur->address)[0] = cur->instruction; |
243 | smc_coherence(((uint32_t *)cur->address)[0]); |
240 | smc_coherence(((uint32_t *)cur->address)[0]); |
244 | ((uint32_t *)cur->address)[1] = cur->nextinstruction; |
241 | ((uint32_t *)cur->address)[1] = cur->nextinstruction; |
245 | smc_coherence(((uint32_t *)cur->address)[1]); |
242 | smc_coherence(((uint32_t *)cur->address)[1]); |
246 | 243 | ||
247 | cur->address = NULL; |
244 | cur->address = NULL; |
248 | 245 | ||
249 | spinlock_unlock(&bkpoint_lock); |
246 | spinlock_unlock(&bkpoint_lock); |
250 | interrupts_restore(ipl); |
247 | interrupts_restore(ipl); |
251 | return 1; |
248 | return 1; |
252 | } |
249 | } |
253 | 250 | ||
254 | /** Print table of active breakpoints */ |
251 | /** Print table of active breakpoints */ |
255 | int cmd_print_breakpoints(cmd_arg_t *argv) |
252 | int cmd_print_breakpoints(cmd_arg_t *argv) |
256 | { |
253 | { |
257 | unsigned int i; |
254 | unsigned int i; |
258 | char *symbol; |
255 | char *symbol; |
259 | 256 | ||
260 | printf("# Count Address INPROG ONESHOT FUNCCALL In symbol\n"); |
257 | printf("# Count Address INPROG ONESHOT FUNCCALL In symbol\n"); |
261 | printf("-- ----- ---------- ------ ------- -------- ---------\n"); |
258 | printf("-- ----- ---------- ------ ------- -------- ---------\n"); |
262 | 259 | ||
263 | for (i = 0; i < BKPOINTS_MAX; i++) |
260 | for (i = 0; i < BKPOINTS_MAX; i++) |
264 | if (breakpoints[i].address) { |
261 | if (breakpoints[i].address) { |
265 | #ifdef CONFIG_SYMTAB |
- | |
266 | symbol = get_symtab_entry(breakpoints[i].address); |
262 | symbol = symtab_fmt_name_lookup( |
267 | #else |
- | |
268 | symbol = "n/a"; |
263 | breakpoints[i].address); |
269 | #endif |
- | |
270 | 264 | ||
271 | printf("%-2u %-5d %#10zx %-6s %-7s %-8s %s\n", i, |
265 | printf("%-2u %-5d %#10zx %-6s %-7s %-8s %s\n", i, |
272 | breakpoints[i].counter, breakpoints[i].address, |
266 | breakpoints[i].counter, breakpoints[i].address, |
273 | ((breakpoints[i].flags & BKPOINT_INPROG) ? "true" : |
267 | ((breakpoints[i].flags & BKPOINT_INPROG) ? "true" : |
274 | "false"), ((breakpoints[i].flags & BKPOINT_ONESHOT) |
268 | "false"), ((breakpoints[i].flags & BKPOINT_ONESHOT) |
275 | ? "true" : "false"), ((breakpoints[i].flags & |
269 | ? "true" : "false"), ((breakpoints[i].flags & |
276 | BKPOINT_FUNCCALL) ? "true" : "false"), symbol); |
270 | BKPOINT_FUNCCALL) ? "true" : "false"), symbol); |
277 | } |
271 | } |
278 | return 1; |
272 | return 1; |
279 | } |
273 | } |
280 | 274 | ||
281 | #endif |
275 | #endif |
282 | 276 | ||
283 | /** Initialize debugger */ |
277 | /** Initialize debugger */ |
284 | void debugger_init() |
278 | void debugger_init() |
285 | { |
279 | { |
286 | int i; |
280 | int i; |
287 | 281 | ||
288 | for (i = 0; i < BKPOINTS_MAX; i++) |
282 | for (i = 0; i < BKPOINTS_MAX; i++) |
289 | breakpoints[i].address = NULL; |
283 | breakpoints[i].address = NULL; |
290 | 284 | ||
291 | #ifdef CONFIG_KCONSOLE |
285 | #ifdef CONFIG_KCONSOLE |
292 | cmd_initialize(&bkpts_info); |
286 | cmd_initialize(&bkpts_info); |
293 | if (!cmd_register(&bkpts_info)) |
287 | if (!cmd_register(&bkpts_info)) |
294 | printf("Cannot register command %s\n", bkpts_info.name); |
288 | printf("Cannot register command %s\n", bkpts_info.name); |
295 | 289 | ||
296 | cmd_initialize(&delbkpt_info); |
290 | cmd_initialize(&delbkpt_info); |
297 | if (!cmd_register(&delbkpt_info)) |
291 | if (!cmd_register(&delbkpt_info)) |
298 | printf("Cannot register command %s\n", delbkpt_info.name); |
292 | printf("Cannot register command %s\n", delbkpt_info.name); |
299 | 293 | ||
300 | cmd_initialize(&addbkpt_info); |
294 | cmd_initialize(&addbkpt_info); |
301 | if (!cmd_register(&addbkpt_info)) |
295 | if (!cmd_register(&addbkpt_info)) |
302 | printf("Cannot register command %s\n", addbkpt_info.name); |
296 | printf("Cannot register command %s\n", addbkpt_info.name); |
303 | 297 | ||
304 | cmd_initialize(&addbkpte_info); |
298 | cmd_initialize(&addbkpte_info); |
305 | if (!cmd_register(&addbkpte_info)) |
299 | if (!cmd_register(&addbkpte_info)) |
306 | printf("Cannot register command %s\n", addbkpte_info.name); |
300 | printf("Cannot register command %s\n", addbkpte_info.name); |
307 | #endif |
301 | #endif |
308 | } |
302 | } |
309 | 303 | ||
310 | /** Handle breakpoint |
304 | /** Handle breakpoint |
311 | * |
305 | * |
312 | * Find breakpoint in breakpoint table. |
306 | * Find breakpoint in breakpoint table. |
313 | * If found, call kconsole, set break on next instruction and reexecute. |
307 | * If found, call kconsole, set break on next instruction and reexecute. |
314 | * If we are on "next instruction", set it back on the first and reexecute. |
308 | * If we are on "next instruction", set it back on the first and reexecute. |
315 | * If breakpoint not found in breakpoint table, call kconsole and start |
309 | * If breakpoint not found in breakpoint table, call kconsole and start |
316 | * next instruction. |
310 | * next instruction. |
317 | */ |
311 | */ |
318 | void debugger_bpoint(istate_t *istate) |
312 | void debugger_bpoint(istate_t *istate) |
319 | { |
313 | { |
320 | bpinfo_t *cur = NULL; |
314 | bpinfo_t *cur = NULL; |
321 | uintptr_t fireaddr = istate->epc; |
315 | uintptr_t fireaddr = istate->epc; |
322 | int i; |
316 | int i; |
323 | 317 | ||
324 | /* test branch delay slot */ |
318 | /* test branch delay slot */ |
325 | if (cp0_cause_read() & 0x80000000) |
319 | if (cp0_cause_read() & 0x80000000) |
326 | panic("Breakpoint in branch delay slot not supported."); |
320 | panic("Breakpoint in branch delay slot not supported."); |
327 | 321 | ||
328 | spinlock_lock(&bkpoint_lock); |
322 | spinlock_lock(&bkpoint_lock); |
329 | for (i = 0; i < BKPOINTS_MAX; i++) { |
323 | for (i = 0; i < BKPOINTS_MAX; i++) { |
330 | /* Normal breakpoint */ |
324 | /* Normal breakpoint */ |
331 | if (fireaddr == breakpoints[i].address && |
325 | if (fireaddr == breakpoints[i].address && |
332 | !(breakpoints[i].flags & BKPOINT_REINST)) { |
326 | !(breakpoints[i].flags & BKPOINT_REINST)) { |
333 | cur = &breakpoints[i]; |
327 | cur = &breakpoints[i]; |
334 | break; |
328 | break; |
335 | } |
329 | } |
336 | /* Reinst only breakpoint */ |
330 | /* Reinst only breakpoint */ |
337 | if ((breakpoints[i].flags & BKPOINT_REINST) && |
331 | if ((breakpoints[i].flags & BKPOINT_REINST) && |
338 | (fireaddr == breakpoints[i].address + sizeof(unative_t))) { |
332 | (fireaddr == breakpoints[i].address + sizeof(unative_t))) { |
339 | cur = &breakpoints[i]; |
333 | cur = &breakpoints[i]; |
340 | break; |
334 | break; |
341 | } |
335 | } |
342 | } |
336 | } |
343 | if (cur) { |
337 | if (cur) { |
344 | if (cur->flags & BKPOINT_REINST) { |
338 | if (cur->flags & BKPOINT_REINST) { |
345 | /* Set breakpoint on first instruction */ |
339 | /* Set breakpoint on first instruction */ |
346 | ((uint32_t *)cur->address)[0] = 0x0d; |
340 | ((uint32_t *)cur->address)[0] = 0x0d; |
347 | smc_coherence(((uint32_t *)cur->address)[0]); |
341 | smc_coherence(((uint32_t *)cur->address)[0]); |
348 | /* Return back the second */ |
342 | /* Return back the second */ |
349 | ((uint32_t *)cur->address)[1] = cur->nextinstruction; |
343 | ((uint32_t *)cur->address)[1] = cur->nextinstruction; |
350 | smc_coherence(((uint32_t *)cur->address)[1]); |
344 | smc_coherence(((uint32_t *)cur->address)[1]); |
351 | cur->flags &= ~BKPOINT_REINST; |
345 | cur->flags &= ~BKPOINT_REINST; |
352 | spinlock_unlock(&bkpoint_lock); |
346 | spinlock_unlock(&bkpoint_lock); |
353 | return; |
347 | return; |
354 | } |
348 | } |
355 | if (cur->flags & BKPOINT_INPROG) |
349 | if (cur->flags & BKPOINT_INPROG) |
356 | printf("Warning: breakpoint recursion\n"); |
350 | printf("Warning: breakpoint recursion\n"); |
357 | 351 | ||
358 | if (!(cur->flags & BKPOINT_FUNCCALL)) { |
352 | if (!(cur->flags & BKPOINT_FUNCCALL)) { |
359 | #ifdef CONFIG_SYMTAB |
- | |
360 | printf("***Breakpoint %d: %p in %s.\n", i, fireaddr, |
353 | printf("***Breakpoint %d: %p in %s.\n", i, fireaddr, |
361 | get_symtab_entry(istate->epc)); |
354 | symtab_fmt_name_lookup(istate->epc)); |
362 | #else |
- | |
363 | printf("***Breakpoint %d: %p.\n", i, fireaddr); |
- | |
364 | #endif |
- | |
365 | } |
355 | } |
366 | 356 | ||
367 | /* Return first instruction back */ |
357 | /* Return first instruction back */ |
368 | ((uint32_t *)cur->address)[0] = cur->instruction; |
358 | ((uint32_t *)cur->address)[0] = cur->instruction; |
369 | smc_coherence(cur->address); |
359 | smc_coherence(cur->address); |
370 | 360 | ||
371 | if (! (cur->flags & BKPOINT_ONESHOT)) { |
361 | if (! (cur->flags & BKPOINT_ONESHOT)) { |
372 | /* Set Breakpoint on next instruction */ |
362 | /* Set Breakpoint on next instruction */ |
373 | ((uint32_t *)cur->address)[1] = 0x0d; |
363 | ((uint32_t *)cur->address)[1] = 0x0d; |
374 | cur->flags |= BKPOINT_REINST; |
364 | cur->flags |= BKPOINT_REINST; |
375 | } |
365 | } |
376 | cur->flags |= BKPOINT_INPROG; |
366 | cur->flags |= BKPOINT_INPROG; |
377 | } else { |
367 | } else { |
378 | #ifdef CONFIG_SYMTAB |
- | |
379 | printf("***Breakpoint %p in %s.\n", fireaddr, |
368 | printf("***Breakpoint %d: %p in %s.\n", i, fireaddr, |
380 | get_symtab_entry(fireaddr)); |
369 | symtab_fmt_name_lookup(fireaddr)); |
381 | #else |
370 | |
382 | printf("***Breakpoint %p.\n", fireaddr); |
- | |
383 | #endif |
- | |
384 | /* Move on to next instruction */ |
371 | /* Move on to next instruction */ |
385 | istate->epc += 4; |
372 | istate->epc += 4; |
386 | } |
373 | } |
387 | if (cur) |
374 | if (cur) |
388 | cur->counter++; |
375 | cur->counter++; |
389 | if (cur && (cur->flags & BKPOINT_FUNCCALL)) { |
376 | if (cur && (cur->flags & BKPOINT_FUNCCALL)) { |
390 | /* Allow zero bkfunc, just for counting */ |
377 | /* Allow zero bkfunc, just for counting */ |
391 | if (cur->bkfunc) |
378 | if (cur->bkfunc) |
392 | cur->bkfunc(cur, istate); |
379 | cur->bkfunc(cur, istate); |
393 | } else { |
380 | } else { |
394 | #ifdef CONFIG_KCONSOLE |
381 | #ifdef CONFIG_KCONSOLE |
395 | /* This disables all other processors - we are not SMP, |
382 | /* This disables all other processors - we are not SMP, |
396 | * actually this gets us to cpu_halt, if scheduler() is run |
383 | * actually this gets us to cpu_halt, if scheduler() is run |
397 | * - we generally do not want scheduler to be run from debug, |
384 | * - we generally do not want scheduler to be run from debug, |
398 | * so this is a good idea |
385 | * so this is a good idea |
399 | */ |
386 | */ |
400 | atomic_set(&haltstate, 1); |
387 | atomic_set(&haltstate, 1); |
401 | spinlock_unlock(&bkpoint_lock); |
388 | spinlock_unlock(&bkpoint_lock); |
402 | 389 | ||
403 | kconsole("debug", "Debug console ready.\n", false); |
390 | kconsole("debug", "Debug console ready.\n", false); |
404 | 391 | ||
405 | spinlock_lock(&bkpoint_lock); |
392 | spinlock_lock(&bkpoint_lock); |
406 | atomic_set(&haltstate, 0); |
393 | atomic_set(&haltstate, 0); |
407 | #endif |
394 | #endif |
408 | } |
395 | } |
409 | if (cur && cur->address == fireaddr && (cur->flags & BKPOINT_INPROG)) { |
396 | if (cur && cur->address == fireaddr && (cur->flags & BKPOINT_INPROG)) { |
410 | /* Remove one-shot breakpoint */ |
397 | /* Remove one-shot breakpoint */ |
411 | if ((cur->flags & BKPOINT_ONESHOT)) |
398 | if ((cur->flags & BKPOINT_ONESHOT)) |
412 | cur->address = NULL; |
399 | cur->address = NULL; |
413 | /* Remove in-progress flag */ |
400 | /* Remove in-progress flag */ |
414 | cur->flags &= ~BKPOINT_INPROG; |
401 | cur->flags &= ~BKPOINT_INPROG; |
415 | } |
402 | } |
416 | spinlock_unlock(&bkpoint_lock); |
403 | spinlock_unlock(&bkpoint_lock); |
417 | } |
404 | } |
418 | 405 | ||
419 | /** @} |
406 | /** @} |
420 | */ |
407 | */ |
421 | 408 |