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