Home | History | Annotate | Line # | Download | only in arm32
      1  1.39       mrg /*	$NetBSD: db_machdep.c,v 1.39 2021/02/23 07:13:51 mrg Exp $	*/
      2   1.1      matt 
      3  1.17     skrll /*
      4   1.1      matt  * Copyright (c) 1996 Mark Brinicombe
      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.17     skrll  *
     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.17     skrll  *
     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.17     skrll  *
     20   1.1      matt  * Carnegie Mellon requests users of this software to return to
     21  1.17     skrll  *
     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.17     skrll  *
     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.8     lukem 
     31  1.20     skrll #ifdef _KERNEL_OPT
     32  1.25     skrll #include "opt_cputypes.h"
     33  1.19      matt #include "opt_multiprocessor.h"
     34  1.20     skrll #endif
     35  1.19      matt 
     36   1.8     lukem #include <sys/cdefs.h>
     37  1.39       mrg __KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.39 2021/02/23 07:13:51 mrg Exp $");
     38   1.1      matt 
     39   1.1      matt #include <sys/param.h>
     40  1.31     skrll 
     41  1.19      matt #include <sys/cpu.h>
     42   1.1      matt #include <sys/proc.h>
     43   1.1      matt #include <sys/vnode.h>
     44   1.1      matt #include <sys/systm.h>
     45   1.1      matt 
     46   1.7     chris #include <arm/arm32/db_machdep.h>
     47  1.32  jmcneill #include <arm/arm32/machdep.h>
     48  1.13  christos #include <arm/cpufunc.h>
     49   1.1      matt 
     50   1.1      matt #include <ddb/db_access.h>
     51   1.1      matt #include <ddb/db_sym.h>
     52   1.1      matt #include <ddb/db_output.h>
     53  1.13  christos #include <ddb/db_variables.h>
     54  1.13  christos #include <ddb/db_command.h>
     55  1.19      matt #include <ddb/db_run.h>
     56   1.1      matt 
     57  1.20     skrll #ifndef _KERNEL
     58  1.20     skrll #include <stddef.h>
     59  1.20     skrll #endif
     60  1.20     skrll 
     61  1.14     skrll #ifdef _KERNEL
     62  1.13  christos static long nil;
     63   1.1      matt 
     64  1.30     skrll void db_md_cpuinfo_cmd(db_expr_t, bool, db_expr_t, const char *);
     65  1.30     skrll 
     66  1.13  christos int db_access_und_sp(const struct db_variable *, db_expr_t *, int);
     67  1.13  christos int db_access_abt_sp(const struct db_variable *, db_expr_t *, int);
     68  1.13  christos int db_access_irq_sp(const struct db_variable *, db_expr_t *, int);
     69  1.14     skrll #endif
     70  1.13  christos 
     71  1.19      matt static int
     72  1.19      matt ddb_reg_var(const struct db_variable *v, db_expr_t *ep, int op)
     73  1.19      matt {
     74  1.21     skrll 	register_t * const rp = (register_t *)DDB_REGS;
     75  1.19      matt 	if (op == DB_VAR_SET) {
     76  1.19      matt 		rp[(uintptr_t)v->valuep] = *ep;
     77  1.19      matt 	} else {
     78  1.19      matt 		*ep = rp[(uintptr_t)v->valuep];
     79  1.19      matt 	}
     80  1.19      matt 	return 0;
     81  1.19      matt }
     82  1.19      matt 
     83  1.19      matt 
     84  1.19      matt #define XO(f) ((long *)(offsetof(db_regs_t, f) / sizeof(register_t)))
     85  1.13  christos const struct db_variable db_regs[] = {
     86  1.19      matt 	{ "spsr", XO(tf_spsr), ddb_reg_var, NULL },
     87  1.19      matt 	{ "r0", XO(tf_r0), ddb_reg_var, NULL },
     88  1.19      matt 	{ "r1", XO(tf_r1), ddb_reg_var, NULL },
     89  1.19      matt 	{ "r2", XO(tf_r2), ddb_reg_var, NULL },
     90  1.19      matt 	{ "r3", XO(tf_r3), ddb_reg_var, NULL },
     91  1.19      matt 	{ "r4", XO(tf_r4), ddb_reg_var, NULL },
     92  1.19      matt 	{ "r5", XO(tf_r5), ddb_reg_var, NULL },
     93  1.19      matt 	{ "r6", XO(tf_r6), ddb_reg_var, NULL },
     94  1.19      matt 	{ "r7", XO(tf_r7), ddb_reg_var, NULL },
     95  1.19      matt 	{ "r8", XO(tf_r8), ddb_reg_var, NULL },
     96  1.19      matt 	{ "r9", XO(tf_r9), ddb_reg_var, NULL },
     97  1.19      matt 	{ "r10", XO(tf_r10), ddb_reg_var, NULL },
     98  1.19      matt 	{ "r11", XO(tf_r11), ddb_reg_var, NULL },
     99  1.19      matt 	{ "r12", XO(tf_r12), ddb_reg_var, NULL },
    100  1.19      matt 	{ "usr_sp", XO(tf_usr_sp), ddb_reg_var, NULL },
    101  1.19      matt 	{ "usr_lr", XO(tf_usr_lr), ddb_reg_var, NULL },
    102  1.19      matt 	{ "svc_sp", XO(tf_svc_sp), ddb_reg_var, NULL },
    103  1.19      matt 	{ "svc_lr", XO(tf_svc_lr), ddb_reg_var, NULL },
    104  1.19      matt 	{ "pc", XO(tf_pc), ddb_reg_var, NULL },
    105  1.14     skrll #ifdef _KERNEL
    106  1.13  christos 	{ "und_sp", &nil, db_access_und_sp, NULL },
    107  1.13  christos 	{ "abt_sp", &nil, db_access_abt_sp, NULL },
    108  1.13  christos 	{ "irq_sp", &nil, db_access_irq_sp, NULL },
    109  1.14     skrll #endif
    110  1.13  christos };
    111  1.19      matt #undef XO
    112  1.13  christos 
    113  1.13  christos const struct db_variable * const db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
    114  1.13  christos 
    115  1.13  christos const struct db_command db_machine_command_table[] = {
    116  1.28     skrll #ifdef _KERNEL
    117  1.28     skrll #if defined(MULTIPROCESSOR)
    118  1.28     skrll 	{ DDB_ADD_CMD("cpu",	db_switch_cpu_cmd,	0,
    119  1.28     skrll 			"switch to a different cpu",
    120  1.28     skrll 		     	NULL,NULL) },
    121  1.28     skrll #endif /* MULTIPROCESSOR */
    122  1.30     skrll 	{ DDB_ADD_CMD("cpuinfo", db_md_cpuinfo_cmd,	0,
    123  1.30     skrll 			"Displays the cpuinfo",
    124  1.30     skrll 		    NULL, NULL)
    125  1.30     skrll 	},
    126  1.28     skrll 	{ DDB_ADD_CMD("fault",	db_show_fault_cmd,	0,
    127  1.28     skrll 			"Displays the fault registers",
    128  1.28     skrll 		     	NULL,NULL) },
    129  1.28     skrll #endif
    130  1.13  christos 	{ DDB_ADD_CMD("frame",	db_show_frame_cmd,	0,
    131  1.13  christos 			"Displays the contents of a trapframe",
    132  1.13  christos 			"[address]",
    133  1.13  christos 			"   address:\taddress of trapfame to display")},
    134  1.13  christos #ifdef _KERNEL
    135  1.32  jmcneill 	{ DDB_ADD_CMD("reset",	db_reset_cmd,		0,
    136  1.32  jmcneill 			"Reset the system",
    137  1.32  jmcneill 			NULL,NULL) },
    138  1.37     skrll #ifdef _ARM_ARCH_7
    139  1.18      matt 	{ DDB_ADD_CMD("tlb",	db_show_tlb_cmd,	0,
    140  1.18      matt 			"Displays the TLB",
    141  1.18      matt 		     	NULL,NULL) },
    142  1.37     skrll #endif
    143  1.27     skrll #endif /* _KERNEL */
    144  1.19      matt 
    145  1.39       mrg 	{ DDB_END_CMD },
    146  1.13  christos };
    147  1.13  christos 
    148  1.27     skrll void
    149  1.27     skrll db_show_frame_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
    150  1.27     skrll {
    151  1.27     skrll 	struct trapframe *frame;
    152  1.27     skrll 
    153  1.27     skrll 	if (!have_addr) {
    154  1.27     skrll 		db_printf("frame address must be specified\n");
    155  1.27     skrll 		return;
    156  1.27     skrll 	}
    157  1.27     skrll 
    158  1.27     skrll 	frame = (struct trapframe *)addr;
    159  1.27     skrll 
    160  1.27     skrll 	db_printf("frame address = %08x  ", (u_int)frame);
    161  1.27     skrll 	db_printf("spsr=%08x\n", frame->tf_spsr);
    162  1.27     skrll 	db_printf("r0 =%08x r1 =%08x r2 =%08x r3 =%08x\n",
    163  1.27     skrll 	    frame->tf_r0, frame->tf_r1, frame->tf_r2, frame->tf_r3);
    164  1.27     skrll 	db_printf("r4 =%08x r5 =%08x r6 =%08x r7 =%08x\n",
    165  1.27     skrll 	    frame->tf_r4, frame->tf_r5, frame->tf_r6, frame->tf_r7);
    166  1.27     skrll 	db_printf("r8 =%08x r9 =%08x r10=%08x r11=%08x\n",
    167  1.27     skrll 	    frame->tf_r8, frame->tf_r9, frame->tf_r10, frame->tf_r11);
    168  1.27     skrll 	db_printf("r12=%08x r13=%08x r14=%08x r15=%08x\n",
    169  1.27     skrll 	    frame->tf_r12, frame->tf_usr_sp, frame->tf_usr_lr, frame->tf_pc);
    170  1.27     skrll 	db_printf("slr=%08x ssp=%08x\n", frame->tf_svc_lr, frame->tf_svc_sp);
    171  1.27     skrll }
    172  1.27     skrll 
    173  1.14     skrll #ifdef _KERNEL
    174  1.13  christos int
    175  1.13  christos db_access_und_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
    176  1.13  christos {
    177  1.13  christos 
    178  1.13  christos 	if (rw == DB_VAR_GET)
    179  1.13  christos 		*valp = get_stackptr(PSR_UND32_MODE);
    180  1.13  christos 	return(0);
    181  1.13  christos }
    182  1.13  christos 
    183  1.13  christos int
    184  1.13  christos db_access_abt_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
    185  1.13  christos {
    186  1.13  christos 
    187  1.13  christos 	if (rw == DB_VAR_GET)
    188  1.13  christos 		*valp = get_stackptr(PSR_ABT32_MODE);
    189  1.13  christos 	return(0);
    190  1.13  christos }
    191  1.13  christos 
    192  1.13  christos int
    193  1.13  christos db_access_irq_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
    194  1.13  christos {
    195  1.13  christos 
    196  1.13  christos 	if (rw == DB_VAR_GET)
    197  1.13  christos 		*valp = get_stackptr(PSR_IRQ32_MODE);
    198  1.13  christos 	return(0);
    199  1.13  christos }
    200  1.13  christos 
    201   1.1      matt void
    202  1.15      matt db_show_fault_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
    203  1.15      matt {
    204  1.18      matt 	db_printf("DFAR=%#x DFSR=%#x IFAR=%#x IFSR=%#x\n",
    205  1.15      matt 	    armreg_dfar_read(), armreg_dfsr_read(),
    206  1.18      matt 	    armreg_ifar_read(), armreg_ifsr_read());
    207  1.18      matt 	db_printf("CONTEXTIDR=%#x TTBCR=%#x TTBR=%#x\n",
    208  1.18      matt 	    armreg_contextidr_read(), armreg_ttbcr_read(),
    209  1.15      matt 	    armreg_ttbr_read());
    210  1.15      matt }
    211  1.18      matt 
    212  1.32  jmcneill void
    213  1.32  jmcneill db_reset_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
    214  1.32  jmcneill {
    215  1.32  jmcneill 	if (cpu_reset_address == NULL) {
    216  1.32  jmcneill 		db_printf("cpu_reset_address is not set\n");
    217  1.32  jmcneill 		return;
    218  1.32  jmcneill 	}
    219  1.32  jmcneill 
    220  1.32  jmcneill 	cpu_reset_address();
    221  1.32  jmcneill }
    222  1.32  jmcneill 
    223  1.38       rin #ifdef _ARM_ARCH_7
    224  1.18      matt static void
    225  1.18      matt tlb_print_common_header(const char *str)
    226  1.18      matt {
    227  1.18      matt 	db_printf("-W/I-- ----VA---- ----PA---- --SIZE-- D AP XN ASD %s\n", str);
    228  1.18      matt }
    229  1.18      matt 
    230  1.18      matt static void
    231  1.18      matt tlb_print_addr(size_t way, size_t va_index, vaddr_t vpn, paddr_t pfn)
    232  1.18      matt {
    233  1.18      matt 	db_printf("[%1zu:%02zx] 0x%05lx000 0x%05lx000", way, va_index, vpn, pfn);
    234  1.18      matt }
    235  1.18      matt 
    236  1.18      matt static void
    237  1.18      matt tlb_print_size_domain_prot(const char *sizestr, u_int domain, u_int ap,
    238  1.18      matt     bool xn_p)
    239  1.18      matt {
    240  1.18      matt 	db_printf(" %8s %1x %2d %s", sizestr, domain, ap, (xn_p ? "XN" : "--"));
    241  1.18      matt }
    242  1.18      matt 
    243  1.18      matt static void
    244  1.18      matt tlb_print_asid(bool ng_p, tlb_asid_t asid)
    245  1.18      matt {
    246  1.18      matt 	if (ng_p) {
    247  1.18      matt 		db_printf(" %3d", asid);
    248  1.18      matt 	} else {
    249  1.18      matt 		db_printf(" ---");
    250  1.18      matt 	}
    251  1.18      matt }
    252  1.18      matt 
    253  1.18      matt struct db_tlbinfo {
    254  1.18      matt 	vaddr_t (*dti_decode_vpn)(size_t, uint32_t, uint32_t);
    255  1.18      matt 	void (*dti_print_header)(void);
    256  1.18      matt 	void (*dti_print_entry)(size_t, size_t, uint32_t, uint32_t);
    257  1.26     skrll 	u_int dti_index;
    258  1.18      matt };
    259  1.18      matt 
    260  1.18      matt static void
    261  1.18      matt tlb_print_cortex_a5_header(void)
    262  1.18      matt {
    263  1.18      matt 	tlb_print_common_header(" S TEX C B");
    264  1.18      matt }
    265  1.18      matt 
    266  1.18      matt static vaddr_t
    267  1.18      matt tlb_decode_cortex_a5_vpn(size_t va_index, uint32_t d0, uint32_t d1)
    268  1.18      matt {
    269  1.18      matt 	const uint64_t d = ((uint64_t)d1 << 32) | d0;
    270  1.18      matt 
    271  1.18      matt 	const u_int size = __SHIFTOUT(d, ARM_A5_TLBDATA_SIZE);
    272  1.18      matt 	return __SHIFTOUT(d, ARM_A5_TLBDATA_VA) * (ARM_A5_TLBDATAOP_INDEX + 1)
    273  1.18      matt 	    + (va_index << (4*size));
    274  1.18      matt }
    275  1.18      matt 
    276  1.18      matt static void
    277  1.18      matt tlb_print_cortex_a5_entry(size_t way, size_t va_index, uint32_t d0, uint32_t d1)
    278  1.18      matt {
    279  1.18      matt 	static const char size_strings[4][8] = {
    280  1.18      matt 	    "  4KB  ", " 64KB  ", "  1MB  ", " 16MB  ",
    281  1.18      matt 	};
    282  1.18      matt 
    283  1.18      matt 	const uint64_t d = ((uint64_t)d1 << 32) | d0;
    284  1.18      matt 
    285  1.18      matt 	const paddr_t pfn = __SHIFTOUT(d, ARM_A5_TLBDATA_PA);
    286  1.18      matt 	const vaddr_t vpn = tlb_decode_cortex_a5_vpn(va_index, d0, d1);
    287  1.18      matt 
    288  1.18      matt 	tlb_print_addr(way, va_index, vpn, pfn);
    289  1.18      matt 
    290  1.18      matt 	const u_int size = __SHIFTOUT(d, ARM_A5_TLBDATA_SIZE);
    291  1.18      matt 	const u_int domain = __SHIFTOUT(d, ARM_A5_TLBDATA_DOM);
    292  1.18      matt 	const u_int ap = __SHIFTOUT(d, ARM_A5_TLBDATA_AP);
    293  1.18      matt 	const bool xn_p = (d & ARM_A5_TLBDATA_XN) != 0;
    294  1.18      matt 
    295  1.18      matt 	tlb_print_size_domain_prot(size_strings[size], domain, ap, xn_p);
    296  1.18      matt 
    297  1.18      matt 	const bool ng_p = (d & ARM_A5_TLBDATA_nG) != 0;
    298  1.18      matt 	const tlb_asid_t asid = __SHIFTOUT(d, ARM_A5_TLBDATA_ASID);
    299  1.18      matt 
    300  1.18      matt 	tlb_print_asid(ng_p, asid);
    301  1.18      matt 
    302  1.18      matt 	const u_int tex = __SHIFTOUT(d, ARM_A5_TLBDATA_TEX);
    303  1.18      matt 	const bool c_p = (d & ARM_A5_TLBDATA_C) != 0;
    304  1.18      matt 	const bool b_p = (d & ARM_A5_TLBDATA_B) != 0;
    305  1.18      matt 	const bool s_p = (d & ARM_A5_TLBDATA_S) != 0;
    306  1.18      matt 
    307  1.18      matt 	db_printf(" %c  %d  %c %c\n", (s_p ? 'S' : '-'), tex,
    308  1.18      matt 	    (c_p ? 'C' : '-'), (b_p ? 'B' : '-'));
    309  1.18      matt }
    310  1.18      matt 
    311  1.18      matt static const struct db_tlbinfo tlb_cortex_a5_info = {
    312  1.18      matt 	.dti_decode_vpn = tlb_decode_cortex_a5_vpn,
    313  1.18      matt 	.dti_print_header = tlb_print_cortex_a5_header,
    314  1.18      matt 	.dti_print_entry = tlb_print_cortex_a5_entry,
    315  1.18      matt 	.dti_index = ARM_A5_TLBDATAOP_INDEX,
    316  1.18      matt };
    317  1.18      matt 
    318  1.18      matt static const char tlb_cortex_a7_esizes[8][8] = {
    319  1.18      matt     " 4KB(S)", " 4KB(L)", "64KB(S)", "64KB(L)",
    320  1.18      matt     " 1MB(S)", " 2MB(L)", "16MB(S)", " 1GB(L)",
    321  1.18      matt };
    322  1.18      matt 
    323  1.18      matt static void
    324  1.18      matt tlb_print_cortex_a7_header(void)
    325  1.18      matt {
    326  1.18      matt 	tlb_print_common_header("IS --OS- SH");
    327  1.18      matt }
    328  1.18      matt 
    329  1.18      matt static inline vaddr_t
    330  1.18      matt tlb_decode_cortex_a7_vpn(size_t va_index, uint32_t d0, uint32_t d1)
    331  1.18      matt {
    332  1.18      matt 	const u_int size = __SHIFTOUT(d0, ARM_A7_TLBDATA0_SIZE);
    333  1.18      matt 	const u_int shift = (size & 1)
    334  1.18      matt 	    ? ((0x12090400 >> (8*size)) & 0x1f)
    335  1.18      matt 	    : (2 * size);
    336  1.18      matt 
    337  1.18      matt 	return __SHIFTOUT(d0, ARM_A7_TLBDATA0_VA) * (ARM_A7_TLBDATAOP_INDEX + 1)
    338  1.18      matt 	    + (va_index << shift);
    339  1.18      matt }
    340  1.18      matt 
    341  1.18      matt static void
    342  1.18      matt tlb_print_cortex_a7_entry(size_t way, size_t va_index, uint32_t d0, uint32_t d1)
    343  1.18      matt {
    344  1.18      matt 	const uint32_t d2 = armreg_tlbdata2_read();
    345  1.18      matt 	const uint64_t d01 = ((uint64_t)d1 << 32) | d0;
    346  1.18      matt 	const uint64_t d12 = ((uint64_t)d2 << 32) | d1;
    347  1.18      matt 
    348  1.18      matt 	const paddr_t pfn = __SHIFTOUT(d12, ARM_A7_TLBDATA12_PA);
    349  1.18      matt 	const vaddr_t vpn = tlb_decode_cortex_a7_vpn(va_index, d0, d1);
    350  1.18      matt 
    351  1.18      matt 	tlb_print_addr(way, va_index, vpn, pfn);
    352  1.18      matt 
    353  1.18      matt 	const u_int size = __SHIFTOUT(d0, ARM_A7_TLBDATA0_SIZE);
    354  1.18      matt 	const u_int domain = __SHIFTOUT(d2, ARM_A7_TLBDATA2_DOM);
    355  1.18      matt 	const u_int ap = __SHIFTOUT(d1, ARM_A7_TLBDATA1_AP);
    356  1.18      matt 	const bool xn_p = (d2 & ARM_A7_TLBDATA2_XN1) != 0;
    357  1.18      matt 
    358  1.18      matt 	tlb_print_size_domain_prot(tlb_cortex_a7_esizes[size], domain, ap, xn_p);
    359  1.18      matt 
    360  1.18      matt 	const bool ng_p = (d1 & ARM_A7_TLBDATA1_nG) != 0;
    361  1.18      matt 	const tlb_asid_t asid = __SHIFTOUT(d01, ARM_A7_TLBDATA01_ASID);
    362  1.18      matt 
    363  1.18      matt 	tlb_print_asid(ng_p, asid);
    364  1.18      matt 
    365  1.18      matt 	const u_int is = __SHIFTOUT(d2, ARM_A7_TLBDATA2_IS);
    366  1.18      matt 	if (is == ARM_A7_TLBDATA2_IS_DSO) {
    367  1.18      matt 		u_int mt = __SHIFTOUT(d2, ARM_A7_TLBDATA2_SDO_MT);
    368  1.18      matt 		switch (mt) {
    369  1.18      matt 		case ARM_A7_TLBDATA2_SDO_MT_D:
    370  1.18      matt 			db_printf(" DV\n");
    371  1.18      matt 			return;
    372  1.18      matt 		case ARM_A7_TLBDATA2_SDO_MT_SO:
    373  1.18      matt 			db_printf(" SO\n");
    374  1.18      matt 			return;
    375  1.18      matt 		default:
    376  1.18      matt 			db_printf(" %02u\n", mt);
    377  1.18      matt 			return;
    378  1.18      matt 		}
    379  1.18      matt 	}
    380  1.18      matt 	const u_int os = __SHIFTOUT(d2, ARM_A7_TLBDATA2_OS);
    381  1.18      matt 	const u_int sh = __SHIFTOUT(d2, ARM_A7_TLBDATA2_SH);
    382  1.18      matt 	static const char is_types[3][3] = { "NC", "WB", "WT" };
    383  1.18      matt 	static const char os_types[4][6] = { "NC", "WB+WA", "WT", "WB" };
    384  1.22     skrll 	static const char sh_types[4][3] = { "NS", "na", "OS", "IS" };
    385  1.18      matt 	db_printf(" %2s %5s %2s\n", is_types[is], os_types[os], sh_types[sh]);
    386  1.18      matt }
    387  1.18      matt 
    388  1.18      matt static const struct db_tlbinfo tlb_cortex_a7_info = {
    389  1.18      matt 	.dti_decode_vpn = tlb_decode_cortex_a7_vpn,
    390  1.18      matt 	.dti_print_header = tlb_print_cortex_a7_header,
    391  1.18      matt 	.dti_print_entry = tlb_print_cortex_a7_entry,
    392  1.18      matt 	.dti_index = ARM_A7_TLBDATAOP_INDEX,
    393  1.18      matt };
    394  1.18      matt 
    395  1.18      matt static inline const struct db_tlbinfo *
    396  1.18      matt tlb_lookup_tlbinfo(void)
    397  1.18      matt {
    398  1.18      matt 	const bool cortex_a5_p = CPU_ID_CORTEX_A5_P(curcpu()->ci_arm_cpuid);
    399  1.18      matt 	const bool cortex_a7_p = CPU_ID_CORTEX_A7_P(curcpu()->ci_arm_cpuid);
    400  1.18      matt 	if (cortex_a5_p) {
    401  1.18      matt 		return &tlb_cortex_a5_info;
    402  1.18      matt 	}
    403  1.18      matt 	if (cortex_a7_p) {
    404  1.18      matt 		return &tlb_cortex_a7_info;
    405  1.18      matt 	}
    406  1.18      matt 	return NULL;
    407  1.18      matt }
    408  1.18      matt 
    409  1.18      matt void
    410  1.18      matt db_show_tlb_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
    411  1.18      matt {
    412  1.18      matt 	const struct db_tlbinfo * const dti = tlb_lookup_tlbinfo();
    413  1.18      matt 
    414  1.36  jmcneill 	if (dti == NULL) {
    415  1.36  jmcneill 		db_printf("not supported on this CPU\n");
    416  1.36  jmcneill 		return;
    417  1.36  jmcneill 	}
    418  1.36  jmcneill 
    419  1.18      matt 	if (have_addr) {
    420  1.18      matt 		const vaddr_t vpn = (vaddr_t)addr >> L2_S_SHIFT;
    421  1.18      matt 		const u_int va_index = vpn & dti->dti_index;
    422  1.18      matt 		for (size_t way = 0; way < 2; way++) {
    423  1.18      matt 			armreg_tlbdataop_write(
    424  1.18      matt 			    __SHIFTIN(va_index, dti->dti_index)
    425  1.18      matt 			    | __SHIFTIN(way, ARM_TLBDATAOP_WAY));
    426  1.37     skrll 			isb();
    427  1.18      matt 			const uint32_t d0 = armreg_tlbdata0_read();
    428  1.18      matt 			const uint32_t d1 = armreg_tlbdata1_read();
    429  1.18      matt 			if ((d0 & ARM_TLBDATA_VALID)
    430  1.18      matt 			    && vpn == (*dti->dti_decode_vpn)(va_index, d0, d1)) {
    431  1.18      matt 				(*dti->dti_print_header)();
    432  1.18      matt 				(*dti->dti_print_entry)(way, va_index, d0, d1);
    433  1.18      matt 				return;
    434  1.18      matt 			}
    435  1.18      matt 		}
    436  1.18      matt 		db_printf("VA %#"DDB_EXPR_FMT"x not found in TLB\n", addr);
    437  1.18      matt 		return;
    438  1.18      matt 	}
    439  1.18      matt 
    440  1.18      matt 	bool first = true;
    441  1.18      matt 	size_t n = 0;
    442  1.18      matt 	for (size_t va_index = 0; va_index <= dti->dti_index; va_index++) {
    443  1.18      matt 		for (size_t way = 0; way < 2; way++) {
    444  1.18      matt 			armreg_tlbdataop_write(
    445  1.18      matt 			    __SHIFTIN(way, ARM_TLBDATAOP_WAY)
    446  1.18      matt 			    | __SHIFTIN(va_index, dti->dti_index));
    447  1.37     skrll 			isb();
    448  1.18      matt 			const uint32_t d0 = armreg_tlbdata0_read();
    449  1.18      matt 			const uint32_t d1 = armreg_tlbdata1_read();
    450  1.18      matt 			if (d0 & ARM_TLBDATA_VALID) {
    451  1.18      matt 				if (first) {
    452  1.18      matt 					(*dti->dti_print_header)();
    453  1.18      matt 					first = false;
    454  1.18      matt 				}
    455  1.18      matt 				(*dti->dti_print_entry)(way, va_index, d0, d1);
    456  1.18      matt 				n++;
    457  1.18      matt 			}
    458  1.18      matt 		}
    459  1.18      matt 	}
    460  1.18      matt 	db_printf("%zu TLB valid entries found\n", n);
    461  1.18      matt }
    462  1.37     skrll #endif
    463   1.1      matt 
    464  1.27     skrll #if defined(MULTIPROCESSOR)
    465  1.19      matt void
    466  1.19      matt db_switch_cpu_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
    467  1.19      matt {
    468  1.19      matt 	if (addr >= maxcpus) {
    469  1.19      matt 		db_printf("cpu %"DDB_EXPR_FMT"d out of range", addr);
    470  1.19      matt 		return;
    471  1.19      matt 	}
    472  1.19      matt 	struct cpu_info *new_ci = cpu_lookup(addr);
    473  1.19      matt 	if (new_ci == NULL) {
    474  1.19      matt 		db_printf("cpu %"DDB_EXPR_FMT"d does not exist", addr);
    475  1.19      matt 		return;
    476  1.19      matt 	}
    477  1.19      matt 	if (DDB_REGS->tf_spsr & PSR_T_bit) {
    478  1.19      matt 		DDB_REGS->tf_pc -= 2; /* XXX */
    479  1.19      matt 	} else {
    480  1.19      matt 		DDB_REGS->tf_pc -= 4;
    481  1.19      matt 	}
    482  1.19      matt 	db_newcpu = new_ci;
    483  1.19      matt 	db_continue_cmd(0, false, 0, "");
    484  1.19      matt }
    485  1.19      matt #endif
    486  1.30     skrll 
    487  1.30     skrll static void
    488  1.30     skrll show_cpuinfo(struct cpu_info *kci)
    489  1.30     skrll {
    490  1.30     skrll 	struct cpu_info cpuinfobuf;
    491  1.30     skrll 	cpuid_t cpuid;
    492  1.30     skrll 	int i;
    493  1.30     skrll 
    494  1.30     skrll 	db_read_bytes((db_addr_t)kci, sizeof(cpuinfobuf), (char *)&cpuinfobuf);
    495  1.30     skrll 
    496  1.30     skrll 	struct cpu_info *ci = &cpuinfobuf;
    497  1.30     skrll 	cpuid = ci->ci_cpuid;
    498  1.30     skrll 	db_printf("cpu_info=%p, cpu_name=%s\n", kci, ci->ci_cpuname);
    499  1.30     skrll 	db_printf("%p cpu[%lu].ci_cpuid        = %lu\n",
    500  1.30     skrll 	    &ci->ci_cpuid, cpuid, ci->ci_cpuid);
    501  1.30     skrll 	db_printf("%p cpu[%lu].ci_curlwp       = %p\n",
    502  1.30     skrll 	    &ci->ci_curlwp, cpuid, ci->ci_curlwp);
    503  1.30     skrll 	for (i = 0; i < SOFTINT_COUNT; i++) {
    504  1.30     skrll 		db_printf("%p cpu[%lu].ci_softlwps[%d]  = %p\n",
    505  1.30     skrll 		    &ci->ci_softlwps[i], cpuid, i, ci->ci_softlwps[i]);
    506  1.30     skrll 	}
    507  1.30     skrll 	db_printf("%p cpu[%lu].ci_lastintr     = %" PRIu64 "\n",
    508  1.30     skrll 	    &ci->ci_lastintr, cpuid, ci->ci_lastintr);
    509  1.30     skrll 	db_printf("%p cpu[%lu].ci_want_resched = %d\n",
    510  1.30     skrll 	    &ci->ci_want_resched, cpuid, ci->ci_want_resched);
    511  1.30     skrll 	db_printf("%p cpu[%lu].ci_cpl          = %d\n",
    512  1.30     skrll 	    &ci->ci_cpl, cpuid, ci->ci_cpl);
    513  1.30     skrll 	db_printf("%p cpu[%lu].ci_softints     = 0x%08x\n",
    514  1.30     skrll 	    &ci->ci_softints, cpuid, ci->ci_softints);
    515  1.30     skrll 	db_printf("%p cpu[%lu].ci_intr_depth   = %u\n",
    516  1.30     skrll 	    &ci->ci_intr_depth, cpuid, ci->ci_intr_depth);
    517  1.30     skrll 
    518  1.30     skrll }
    519  1.30     skrll 
    520  1.30     skrll void
    521  1.30     skrll db_md_cpuinfo_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
    522  1.30     skrll     const char *modif)
    523  1.30     skrll {
    524  1.30     skrll #ifdef MULTIPROCESSOR
    525  1.30     skrll 	CPU_INFO_ITERATOR cii;
    526  1.30     skrll 	struct cpu_info *ci;
    527  1.30     skrll 	bool showall = false;
    528  1.30     skrll 
    529  1.30     skrll 	if (modif != NULL) {
    530  1.30     skrll 		for (; *modif != '\0'; modif++) {
    531  1.30     skrll 			switch (*modif) {
    532  1.30     skrll 			case 'a':
    533  1.30     skrll 				showall = true;
    534  1.30     skrll 				break;
    535  1.30     skrll 			}
    536  1.30     skrll 		}
    537  1.30     skrll 	}
    538  1.30     skrll 
    539  1.30     skrll 	if (showall) {
    540  1.30     skrll 		for (CPU_INFO_FOREACH(cii, ci)) {
    541  1.30     skrll 			show_cpuinfo(ci);
    542  1.30     skrll 		}
    543  1.30     skrll 	} else
    544  1.30     skrll #endif /* MULTIPROCESSOR */
    545  1.30     skrll 		show_cpuinfo(curcpu());
    546  1.30     skrll }
    547  1.30     skrll 
    548  1.27     skrll #endif /* _KERNEL */
    549