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