db_interface.c revision 1.3.2.2 1 1.3.2.2 bouyer /* $NetBSD: db_interface.c,v 1.3.2.2 2001/03/12 13:27:19 bouyer Exp $ */
2 1.3.2.2 bouyer
3 1.3.2.2 bouyer /*
4 1.3.2.2 bouyer * Copyright (c) 1996 Scott K. Stevens
5 1.3.2.2 bouyer *
6 1.3.2.2 bouyer * Mach Operating System
7 1.3.2.2 bouyer * Copyright (c) 1991,1990 Carnegie Mellon University
8 1.3.2.2 bouyer * All Rights Reserved.
9 1.3.2.2 bouyer *
10 1.3.2.2 bouyer * Permission to use, copy, modify and distribute this software and its
11 1.3.2.2 bouyer * documentation is hereby granted, provided that both the copyright
12 1.3.2.2 bouyer * notice and this permission notice appear in all copies of the
13 1.3.2.2 bouyer * software, derivative works or modified versions, and any portions
14 1.3.2.2 bouyer * thereof, and that both notices appear in supporting documentation.
15 1.3.2.2 bouyer *
16 1.3.2.2 bouyer * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 1.3.2.2 bouyer * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18 1.3.2.2 bouyer * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 1.3.2.2 bouyer *
20 1.3.2.2 bouyer * Carnegie Mellon requests users of this software to return to
21 1.3.2.2 bouyer *
22 1.3.2.2 bouyer * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
23 1.3.2.2 bouyer * School of Computer Science
24 1.3.2.2 bouyer * Carnegie Mellon University
25 1.3.2.2 bouyer * Pittsburgh PA 15213-3890
26 1.3.2.2 bouyer *
27 1.3.2.2 bouyer * any improvements or extensions that they make and grant Carnegie the
28 1.3.2.2 bouyer * rights to redistribute these changes.
29 1.3.2.2 bouyer *
30 1.3.2.2 bouyer * From: db_interface.c,v 2.4 1991/02/05 17:11:13 mrt (CMU)
31 1.3.2.2 bouyer */
32 1.3.2.2 bouyer
33 1.3.2.2 bouyer /*
34 1.3.2.2 bouyer * Interface to new debugger.
35 1.3.2.2 bouyer */
36 1.3.2.2 bouyer #include "opt_ddb.h"
37 1.3.2.2 bouyer
38 1.3.2.2 bouyer #include <sys/param.h>
39 1.3.2.2 bouyer #include <sys/proc.h>
40 1.3.2.2 bouyer #include <sys/reboot.h>
41 1.3.2.2 bouyer #include <sys/systm.h> /* just for boothowto */
42 1.3.2.2 bouyer #include <sys/exec.h>
43 1.3.2.2 bouyer
44 1.3.2.2 bouyer #include <uvm/uvm_extern.h>
45 1.3.2.2 bouyer
46 1.3.2.2 bouyer #include <machine/db_machdep.h>
47 1.3.2.2 bouyer #include <machine/katelib.h>
48 1.3.2.2 bouyer #include <machine/pte.h>
49 1.3.2.2 bouyer #include <machine/undefined.h>
50 1.3.2.2 bouyer #include <ddb/db_command.h>
51 1.3.2.2 bouyer #include <ddb/db_output.h>
52 1.3.2.2 bouyer #include <ddb/db_variables.h>
53 1.3.2.2 bouyer #include <ddb/db_sym.h>
54 1.3.2.2 bouyer #include <ddb/db_extern.h>
55 1.3.2.2 bouyer #include <ddb/db_interface.h>
56 1.3.2.2 bouyer #include <dev/cons.h>
57 1.3.2.2 bouyer
58 1.3.2.2 bouyer static int nil;
59 1.3.2.2 bouyer
60 1.3.2.2 bouyer int db_access_und_sp __P((const struct db_variable *, db_expr_t *, int));
61 1.3.2.2 bouyer int db_access_abt_sp __P((const struct db_variable *, db_expr_t *, int));
62 1.3.2.2 bouyer int db_access_irq_sp __P((const struct db_variable *, db_expr_t *, int));
63 1.3.2.2 bouyer u_int db_fetch_reg __P((int, db_regs_t *));
64 1.3.2.2 bouyer
65 1.3.2.2 bouyer const struct db_variable db_regs[] = {
66 1.3.2.2 bouyer { "spsr", (long *)&DDB_REGS->tf_spsr, FCN_NULL, },
67 1.3.2.2 bouyer { "r0", (long *)&DDB_REGS->tf_r0, FCN_NULL, },
68 1.3.2.2 bouyer { "r1", (long *)&DDB_REGS->tf_r1, FCN_NULL, },
69 1.3.2.2 bouyer { "r2", (long *)&DDB_REGS->tf_r2, FCN_NULL, },
70 1.3.2.2 bouyer { "r3", (long *)&DDB_REGS->tf_r3, FCN_NULL, },
71 1.3.2.2 bouyer { "r4", (long *)&DDB_REGS->tf_r4, FCN_NULL, },
72 1.3.2.2 bouyer { "r5", (long *)&DDB_REGS->tf_r5, FCN_NULL, },
73 1.3.2.2 bouyer { "r6", (long *)&DDB_REGS->tf_r6, FCN_NULL, },
74 1.3.2.2 bouyer { "r7", (long *)&DDB_REGS->tf_r7, FCN_NULL, },
75 1.3.2.2 bouyer { "r8", (long *)&DDB_REGS->tf_r8, FCN_NULL, },
76 1.3.2.2 bouyer { "r9", (long *)&DDB_REGS->tf_r9, FCN_NULL, },
77 1.3.2.2 bouyer { "r10", (long *)&DDB_REGS->tf_r10, FCN_NULL, },
78 1.3.2.2 bouyer { "r11", (long *)&DDB_REGS->tf_r11, FCN_NULL, },
79 1.3.2.2 bouyer { "r12", (long *)&DDB_REGS->tf_r12, FCN_NULL, },
80 1.3.2.2 bouyer { "usr_sp", (long *)&DDB_REGS->tf_usr_sp, FCN_NULL, },
81 1.3.2.2 bouyer { "usr_lr", (long *)&DDB_REGS->tf_usr_lr, FCN_NULL, },
82 1.3.2.2 bouyer { "svc_sp", (long *)&DDB_REGS->tf_svc_sp, FCN_NULL, },
83 1.3.2.2 bouyer { "svc_lr", (long *)&DDB_REGS->tf_svc_lr, FCN_NULL, },
84 1.3.2.2 bouyer { "pc", (long *)&DDB_REGS->tf_pc, FCN_NULL, },
85 1.3.2.2 bouyer { "und_sp", (long *)&nil, db_access_und_sp, },
86 1.3.2.2 bouyer { "abt_sp", (long *)&nil, db_access_abt_sp, },
87 1.3.2.2 bouyer { "irq_sp", (long *)&nil, db_access_irq_sp, },
88 1.3.2.2 bouyer };
89 1.3.2.2 bouyer
90 1.3.2.2 bouyer const struct db_variable * const db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
91 1.3.2.2 bouyer
92 1.3.2.2 bouyer extern label_t *db_recover;
93 1.3.2.2 bouyer
94 1.3.2.2 bouyer int db_active = 0;
95 1.3.2.2 bouyer
96 1.3.2.2 bouyer int db_access_und_sp(vp, valp, rw)
97 1.3.2.2 bouyer const struct db_variable *vp;
98 1.3.2.2 bouyer db_expr_t *valp;
99 1.3.2.2 bouyer int rw;
100 1.3.2.2 bouyer {
101 1.3.2.2 bouyer if (rw == DB_VAR_GET)
102 1.3.2.2 bouyer *valp = get_stackptr(PSR_UND32_MODE);
103 1.3.2.2 bouyer return(0);
104 1.3.2.2 bouyer }
105 1.3.2.2 bouyer
106 1.3.2.2 bouyer int db_access_abt_sp(vp, valp, rw)
107 1.3.2.2 bouyer const struct db_variable *vp;
108 1.3.2.2 bouyer db_expr_t *valp;
109 1.3.2.2 bouyer int rw;
110 1.3.2.2 bouyer {
111 1.3.2.2 bouyer if (rw == DB_VAR_GET)
112 1.3.2.2 bouyer *valp = get_stackptr(PSR_ABT32_MODE);
113 1.3.2.2 bouyer return(0);
114 1.3.2.2 bouyer }
115 1.3.2.2 bouyer
116 1.3.2.2 bouyer int db_access_irq_sp(vp, valp, rw)
117 1.3.2.2 bouyer const struct db_variable *vp;
118 1.3.2.2 bouyer db_expr_t *valp;
119 1.3.2.2 bouyer int rw;
120 1.3.2.2 bouyer {
121 1.3.2.2 bouyer if (rw == DB_VAR_GET)
122 1.3.2.2 bouyer *valp = get_stackptr(PSR_IRQ32_MODE);
123 1.3.2.2 bouyer return(0);
124 1.3.2.2 bouyer }
125 1.3.2.2 bouyer
126 1.3.2.2 bouyer /*
127 1.3.2.2 bouyer * kdb_trap - field a TRACE or BPT trap
128 1.3.2.2 bouyer */
129 1.3.2.2 bouyer int
130 1.3.2.2 bouyer kdb_trap(type, regs)
131 1.3.2.2 bouyer int type;
132 1.3.2.2 bouyer db_regs_t *regs;
133 1.3.2.2 bouyer {
134 1.3.2.2 bouyer int s;
135 1.3.2.2 bouyer
136 1.3.2.2 bouyer switch (type) {
137 1.3.2.2 bouyer case T_BREAKPOINT: /* breakpoint */
138 1.3.2.2 bouyer case -1: /* keyboard interrupt */
139 1.3.2.2 bouyer break;
140 1.3.2.2 bouyer default:
141 1.3.2.2 bouyer db_printf("kernel: trap");
142 1.3.2.2 bouyer if (db_recover != 0) {
143 1.3.2.2 bouyer db_error("Faulted in DDB; continuing...\n");
144 1.3.2.2 bouyer /*NOTREACHED*/
145 1.3.2.2 bouyer }
146 1.3.2.2 bouyer }
147 1.3.2.2 bouyer
148 1.3.2.2 bouyer /* Should switch to kdb`s own stack here. */
149 1.3.2.2 bouyer
150 1.3.2.2 bouyer ddb_regs = *regs;
151 1.3.2.2 bouyer
152 1.3.2.2 bouyer s = splhigh();
153 1.3.2.2 bouyer db_active++;
154 1.3.2.2 bouyer cnpollc(TRUE);
155 1.3.2.2 bouyer db_trap(type, 0/*code*/);
156 1.3.2.2 bouyer cnpollc(FALSE);
157 1.3.2.2 bouyer db_active--;
158 1.3.2.2 bouyer splx(s);
159 1.3.2.2 bouyer
160 1.3.2.2 bouyer *regs = ddb_regs;
161 1.3.2.2 bouyer
162 1.3.2.2 bouyer return (1);
163 1.3.2.2 bouyer }
164 1.3.2.2 bouyer
165 1.3.2.2 bouyer
166 1.3.2.2 bouyer /*
167 1.3.2.2 bouyer * Received keyboard interrupt sequence.
168 1.3.2.2 bouyer */
169 1.3.2.2 bouyer void
170 1.3.2.2 bouyer kdb_kbd_trap(regs)
171 1.3.2.2 bouyer db_regs_t *regs;
172 1.3.2.2 bouyer {
173 1.3.2.2 bouyer if (db_active == 0 && (boothowto & RB_KDB)) {
174 1.3.2.2 bouyer printf("\n\nkernel: keyboard interrupt\n");
175 1.3.2.2 bouyer kdb_trap(-1, regs);
176 1.3.2.2 bouyer }
177 1.3.2.2 bouyer }
178 1.3.2.2 bouyer
179 1.3.2.2 bouyer
180 1.3.2.2 bouyer static int
181 1.3.2.2 bouyer db_validate_address(addr)
182 1.3.2.2 bouyer vm_offset_t addr;
183 1.3.2.2 bouyer {
184 1.3.2.2 bouyer pt_entry_t *ptep;
185 1.3.2.2 bouyer pd_entry_t *pdep;
186 1.3.2.2 bouyer struct proc *p = curproc;
187 1.3.2.2 bouyer
188 1.3.2.2 bouyer /*
189 1.3.2.2 bouyer * If we have a valid pmap for curproc, use it's page directory
190 1.3.2.2 bouyer * otherwise use the kernel pmap's page directory.
191 1.3.2.2 bouyer */
192 1.3.2.2 bouyer if (!p || !p->p_vmspace || !p->p_vmspace->vm_map.pmap)
193 1.3.2.2 bouyer pdep = kernel_pmap->pm_pdir;
194 1.3.2.2 bouyer else
195 1.3.2.2 bouyer pdep = p->p_vmspace->vm_map.pmap->pm_pdir;
196 1.3.2.2 bouyer
197 1.3.2.2 bouyer /* Make sure the address we are reading is valid */
198 1.3.2.2 bouyer switch ((pdep[(addr >> 20) + 0] & L1_MASK)) {
199 1.3.2.2 bouyer case L1_SECTION:
200 1.3.2.2 bouyer break;
201 1.3.2.2 bouyer case L1_PAGE:
202 1.3.2.2 bouyer /* Check the L2 page table for validity */
203 1.3.2.2 bouyer ptep = vtopte(addr);
204 1.3.2.2 bouyer if ((*ptep & L2_MASK) != L2_INVAL)
205 1.3.2.2 bouyer break;
206 1.3.2.2 bouyer /* FALLTHROUGH */
207 1.3.2.2 bouyer default:
208 1.3.2.2 bouyer return 1;
209 1.3.2.2 bouyer }
210 1.3.2.2 bouyer
211 1.3.2.2 bouyer return 0;
212 1.3.2.2 bouyer }
213 1.3.2.2 bouyer
214 1.3.2.2 bouyer /*
215 1.3.2.2 bouyer * Read bytes from kernel address space for debugger.
216 1.3.2.2 bouyer */
217 1.3.2.2 bouyer void
218 1.3.2.2 bouyer db_read_bytes(addr, size, data)
219 1.3.2.2 bouyer vm_offset_t addr;
220 1.3.2.2 bouyer int size;
221 1.3.2.2 bouyer char *data;
222 1.3.2.2 bouyer {
223 1.3.2.2 bouyer char *src;
224 1.3.2.2 bouyer
225 1.3.2.2 bouyer src = (char *)addr;
226 1.3.2.2 bouyer while (--size >= 0) {
227 1.3.2.2 bouyer if (db_validate_address((u_int)src)) {
228 1.3.2.2 bouyer db_printf("address %p is invalid\n", src);
229 1.3.2.2 bouyer return;
230 1.3.2.2 bouyer }
231 1.3.2.2 bouyer *data++ = *src++;
232 1.3.2.2 bouyer }
233 1.3.2.2 bouyer }
234 1.3.2.2 bouyer
235 1.3.2.2 bouyer static void
236 1.3.2.2 bouyer db_write_text(dst, ch)
237 1.3.2.2 bouyer unsigned char *dst;
238 1.3.2.2 bouyer int ch;
239 1.3.2.2 bouyer {
240 1.3.2.2 bouyer pt_entry_t *ptep, pteo;
241 1.3.2.2 bouyer vm_offset_t va;
242 1.3.2.2 bouyer
243 1.3.2.2 bouyer va = (unsigned long)dst & (~PGOFSET);
244 1.3.2.2 bouyer ptep = vtopte(va);
245 1.3.2.2 bouyer
246 1.3.2.2 bouyer if (db_validate_address((u_int)dst)) {
247 1.3.2.2 bouyer db_printf(" address %p not a valid page\n", dst);
248 1.3.2.2 bouyer return;
249 1.3.2.2 bouyer }
250 1.3.2.2 bouyer
251 1.3.2.2 bouyer pteo = *ptep;
252 1.3.2.2 bouyer *ptep = pteo | PT_AP(AP_KRW);
253 1.3.2.2 bouyer cpu_tlb_flushD_SE(va);
254 1.3.2.2 bouyer
255 1.3.2.2 bouyer *dst = (unsigned char)ch;
256 1.3.2.2 bouyer
257 1.3.2.2 bouyer /* make sure the caches and memory are in sync */
258 1.3.2.2 bouyer cpu_cache_syncI_rng((u_int)dst, 4);
259 1.3.2.2 bouyer
260 1.3.2.2 bouyer *ptep = pteo;
261 1.3.2.2 bouyer cpu_tlb_flushD_SE(va);
262 1.3.2.2 bouyer }
263 1.3.2.2 bouyer
264 1.3.2.2 bouyer /*
265 1.3.2.2 bouyer * Write bytes to kernel address space for debugger.
266 1.3.2.2 bouyer */
267 1.3.2.2 bouyer void
268 1.3.2.2 bouyer db_write_bytes(addr, size, data)
269 1.3.2.2 bouyer vm_offset_t addr;
270 1.3.2.2 bouyer int size;
271 1.3.2.2 bouyer char *data;
272 1.3.2.2 bouyer {
273 1.3.2.2 bouyer extern char etext[];
274 1.3.2.2 bouyer char *dst;
275 1.3.2.2 bouyer int loop;
276 1.3.2.2 bouyer
277 1.3.2.2 bouyer dst = (char *)addr;
278 1.3.2.2 bouyer loop = size;
279 1.3.2.2 bouyer while (--loop >= 0) {
280 1.3.2.2 bouyer if ((dst >= (char *)KERNEL_TEXT_BASE) && (dst < etext))
281 1.3.2.2 bouyer db_write_text(dst, *data);
282 1.3.2.2 bouyer else {
283 1.3.2.2 bouyer if (db_validate_address((u_int)dst)) {
284 1.3.2.2 bouyer db_printf("address %p is invalid\n", dst);
285 1.3.2.2 bouyer return;
286 1.3.2.2 bouyer }
287 1.3.2.2 bouyer *dst = *data;
288 1.3.2.2 bouyer }
289 1.3.2.2 bouyer dst++, data++;
290 1.3.2.2 bouyer }
291 1.3.2.2 bouyer /* make sure the caches and memory are in sync */
292 1.3.2.2 bouyer cpu_cache_syncI_rng(addr, size);
293 1.3.2.2 bouyer
294 1.3.2.2 bouyer /* In case the current page tables have been modified ... */
295 1.3.2.2 bouyer cpu_tlb_flushID();
296 1.3.2.2 bouyer }
297 1.3.2.2 bouyer
298 1.3.2.2 bouyer void
299 1.3.2.2 bouyer cpu_Debugger()
300 1.3.2.2 bouyer {
301 1.3.2.2 bouyer asm(".word 0xe7ffffff");
302 1.3.2.2 bouyer }
303 1.3.2.2 bouyer
304 1.3.2.2 bouyer void db_show_vmstat_cmd __P((db_expr_t addr, int have_addr, db_expr_t count, char *modif));
305 1.3.2.2 bouyer void db_show_intrchain_cmd __P((db_expr_t addr, int have_addr, db_expr_t count, char *modif));
306 1.3.2.2 bouyer void db_show_panic_cmd __P((db_expr_t addr, int have_addr, db_expr_t count, char *modif));
307 1.3.2.2 bouyer void db_show_frame_cmd __P((db_expr_t addr, int have_addr, db_expr_t count, char *modif));
308 1.3.2.2 bouyer
309 1.3.2.2 bouyer const struct db_command db_machine_command_table[] = {
310 1.3.2.2 bouyer { "frame", db_show_frame_cmd, 0, NULL },
311 1.3.2.2 bouyer { "intrchain", db_show_intrchain_cmd, 0, NULL },
312 1.3.2.2 bouyer { "panic", db_show_panic_cmd, 0, NULL },
313 1.3.2.2 bouyer { "vmstat", db_show_vmstat_cmd, 0, NULL },
314 1.3.2.2 bouyer #ifdef ARM32_DB_COMMANDS
315 1.3.2.2 bouyer ARM32_DB_COMMANDS,
316 1.3.2.2 bouyer #endif
317 1.3.2.2 bouyer { NULL, NULL, 0, NULL }
318 1.3.2.2 bouyer };
319 1.3.2.2 bouyer
320 1.3.2.2 bouyer int
321 1.3.2.2 bouyer db_trapper(addr, inst, frame, fault_code)
322 1.3.2.2 bouyer u_int addr;
323 1.3.2.2 bouyer u_int inst;
324 1.3.2.2 bouyer trapframe_t *frame;
325 1.3.2.2 bouyer int fault_code;
326 1.3.2.2 bouyer {
327 1.3.2.2 bouyer if (fault_code == 0) {
328 1.3.2.2 bouyer frame->tf_pc -= INSN_SIZE;
329 1.3.2.2 bouyer if ((inst & ~INSN_COND_MASK) == (BKPT_INST & ~INSN_COND_MASK))
330 1.3.2.2 bouyer kdb_trap(T_BREAKPOINT, frame);
331 1.3.2.2 bouyer else
332 1.3.2.2 bouyer kdb_trap(-1, frame);
333 1.3.2.2 bouyer } else
334 1.3.2.2 bouyer return (1);
335 1.3.2.2 bouyer return (0);
336 1.3.2.2 bouyer }
337 1.3.2.2 bouyer
338 1.3.2.2 bouyer extern u_int esym;
339 1.3.2.2 bouyer extern u_int end;
340 1.3.2.2 bouyer
341 1.3.2.2 bouyer static struct undefined_handler db_uh;
342 1.3.2.2 bouyer
343 1.3.2.2 bouyer void
344 1.3.2.2 bouyer db_machine_init()
345 1.3.2.2 bouyer {
346 1.3.2.2 bouyer struct exec *kernexec = (struct exec *)KERNEL_TEXT_BASE;
347 1.3.2.2 bouyer int len;
348 1.3.2.2 bouyer
349 1.3.2.2 bouyer /*
350 1.3.2.2 bouyer * The boot loader currently loads the kernel with the a.out
351 1.3.2.2 bouyer * header still attached.
352 1.3.2.2 bouyer */
353 1.3.2.2 bouyer
354 1.3.2.2 bouyer if (kernexec->a_syms == 0) {
355 1.3.2.2 bouyer printf("[No symbol table]\n");
356 1.3.2.2 bouyer } else {
357 1.3.2.2 bouyer /* cover the symbols themselves (what is the int for?? XXX) */
358 1.3.2.2 bouyer esym = (int)&end + kernexec->a_syms + sizeof(int);
359 1.3.2.2 bouyer
360 1.3.2.2 bouyer /*
361 1.3.2.2 bouyer * and the string table. (int containing size of string
362 1.3.2.2 bouyer * table is included in string table size).
363 1.3.2.2 bouyer */
364 1.3.2.2 bouyer len = *((u_int *)esym);
365 1.3.2.2 bouyer esym += (len + (sizeof(u_int) - 1)) & ~(sizeof(u_int) - 1);
366 1.3.2.2 bouyer }
367 1.3.2.2 bouyer
368 1.3.2.2 bouyer /*
369 1.3.2.2 bouyer * We get called before malloc() is available, so supply a static
370 1.3.2.2 bouyer * struct undefined_handler.
371 1.3.2.2 bouyer */
372 1.3.2.2 bouyer db_uh.uh_handler = db_trapper;
373 1.3.2.2 bouyer install_coproc_handler_static(0, &db_uh);
374 1.3.2.2 bouyer }
375 1.3.2.2 bouyer
376 1.3.2.2 bouyer u_int
377 1.3.2.2 bouyer db_fetch_reg(reg, db_regs)
378 1.3.2.2 bouyer int reg;
379 1.3.2.2 bouyer db_regs_t *db_regs;
380 1.3.2.2 bouyer {
381 1.3.2.2 bouyer
382 1.3.2.2 bouyer switch (reg) {
383 1.3.2.2 bouyer case 0:
384 1.3.2.2 bouyer return (db_regs->tf_r0);
385 1.3.2.2 bouyer case 1:
386 1.3.2.2 bouyer return (db_regs->tf_r1);
387 1.3.2.2 bouyer case 2:
388 1.3.2.2 bouyer return (db_regs->tf_r2);
389 1.3.2.2 bouyer case 3:
390 1.3.2.2 bouyer return (db_regs->tf_r3);
391 1.3.2.2 bouyer case 4:
392 1.3.2.2 bouyer return (db_regs->tf_r4);
393 1.3.2.2 bouyer case 5:
394 1.3.2.2 bouyer return (db_regs->tf_r5);
395 1.3.2.2 bouyer case 6:
396 1.3.2.2 bouyer return (db_regs->tf_r6);
397 1.3.2.2 bouyer case 7:
398 1.3.2.2 bouyer return (db_regs->tf_r7);
399 1.3.2.2 bouyer case 8:
400 1.3.2.2 bouyer return (db_regs->tf_r8);
401 1.3.2.2 bouyer case 9:
402 1.3.2.2 bouyer return (db_regs->tf_r9);
403 1.3.2.2 bouyer case 10:
404 1.3.2.2 bouyer return (db_regs->tf_r10);
405 1.3.2.2 bouyer case 11:
406 1.3.2.2 bouyer return (db_regs->tf_r11);
407 1.3.2.2 bouyer case 12:
408 1.3.2.2 bouyer return (db_regs->tf_r12);
409 1.3.2.2 bouyer case 13:
410 1.3.2.2 bouyer return (db_regs->tf_svc_sp);
411 1.3.2.2 bouyer case 14:
412 1.3.2.2 bouyer return (db_regs->tf_svc_lr);
413 1.3.2.2 bouyer case 15:
414 1.3.2.2 bouyer return (db_regs->tf_pc);
415 1.3.2.2 bouyer default:
416 1.3.2.2 bouyer panic("db_fetch_reg: botch");
417 1.3.2.2 bouyer }
418 1.3.2.2 bouyer }
419 1.3.2.2 bouyer
420 1.3.2.2 bouyer u_int
421 1.3.2.2 bouyer branch_taken(insn, pc, db_regs)
422 1.3.2.2 bouyer u_int insn;
423 1.3.2.2 bouyer u_int pc;
424 1.3.2.2 bouyer db_regs_t *db_regs;
425 1.3.2.2 bouyer {
426 1.3.2.2 bouyer u_int addr, nregs;
427 1.3.2.2 bouyer
428 1.3.2.2 bouyer switch ((insn >> 24) & 0xf) {
429 1.3.2.2 bouyer case 0xa: /* b ... */
430 1.3.2.2 bouyer case 0xb: /* bl ... */
431 1.3.2.2 bouyer addr = ((insn << 2) & 0x03ffffff);
432 1.3.2.2 bouyer if (addr & 0x02000000)
433 1.3.2.2 bouyer addr |= 0xfc000000;
434 1.3.2.2 bouyer return (pc + 8 + addr);
435 1.3.2.2 bouyer case 0x7: /* ldr pc, [pc, reg, lsl #2] */
436 1.3.2.2 bouyer addr = db_fetch_reg(insn & 0xf, db_regs);
437 1.3.2.2 bouyer addr = pc + 8 + (addr << 2);
438 1.3.2.2 bouyer db_read_bytes(addr, 4, (char *)&addr);
439 1.3.2.2 bouyer return (addr);
440 1.3.2.2 bouyer case 0x1: /* mov pc, reg */
441 1.3.2.2 bouyer addr = db_fetch_reg(insn & 0xf, db_regs);
442 1.3.2.2 bouyer return (addr);
443 1.3.2.2 bouyer case 0x8: /* ldmxx reg, {..., pc} */
444 1.3.2.2 bouyer case 0x9:
445 1.3.2.2 bouyer addr = db_fetch_reg((insn >> 16) & 0xf, db_regs);
446 1.3.2.2 bouyer nregs = (insn & 0x5555) + ((insn >> 1) & 0x5555);
447 1.3.2.2 bouyer nregs = (nregs & 0x3333) + ((nregs >> 2) & 0x3333);
448 1.3.2.2 bouyer nregs = (nregs + (nregs >> 4)) & 0x0f0f;
449 1.3.2.2 bouyer nregs = (nregs + (nregs >> 8)) & 0x001f;
450 1.3.2.2 bouyer switch ((insn >> 23) & 0x3) {
451 1.3.2.2 bouyer case 0x0: /* ldmda */
452 1.3.2.2 bouyer addr = addr - 0;
453 1.3.2.2 bouyer break;
454 1.3.2.2 bouyer case 0x1: /* ldmia */
455 1.3.2.2 bouyer addr = addr + 0 + ((nregs - 1) << 2);
456 1.3.2.2 bouyer break;
457 1.3.2.2 bouyer case 0x2: /* ldmdb */
458 1.3.2.2 bouyer addr = addr - 4;
459 1.3.2.2 bouyer break;
460 1.3.2.2 bouyer case 0x3: /* ldmib */
461 1.3.2.2 bouyer addr = addr + 4 + ((nregs - 1) << 2);
462 1.3.2.2 bouyer break;
463 1.3.2.2 bouyer }
464 1.3.2.2 bouyer db_read_bytes(addr, 4, (char *)&addr);
465 1.3.2.2 bouyer return (addr);
466 1.3.2.2 bouyer default:
467 1.3.2.2 bouyer panic("branch_taken: botch");
468 1.3.2.2 bouyer }
469 1.3.2.2 bouyer }
470