xref: /netbsd-src/sys/arch/arm/arm32/db_machdep.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*	$NetBSD: db_machdep.c,v 1.17 2013/12/15 09:14:09 skrll Exp $	*/
2 
3 /*
4  * Copyright (c) 1996 Mark Brinicombe
5  *
6  * Mach Operating System
7  * Copyright (c) 1991,1990 Carnegie Mellon University
8  * All Rights Reserved.
9  *
10  * Permission to use, copy, modify and distribute this software and its
11  * documentation is hereby granted, provided that both the copyright
12  * notice and this permission notice appear in all copies of the
13  * software, derivative works or modified versions, and any portions
14  * thereof, and that both notices appear in supporting documentation.
15  *
16  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19  *
20  * Carnegie Mellon requests users of this software to return to
21  *
22  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
23  *  School of Computer Science
24  *  Carnegie Mellon University
25  *  Pittsburgh PA 15213-3890
26  *
27  * any improvements or extensions that they make and grant Carnegie the
28  * rights to redistribute these changes.
29  */
30 
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.17 2013/12/15 09:14:09 skrll Exp $");
33 
34 #include <sys/param.h>
35 #include <sys/proc.h>
36 #include <sys/vnode.h>
37 #include <sys/systm.h>
38 
39 #include <arm/arm32/db_machdep.h>
40 #include <arm/cpufunc.h>
41 
42 #include <ddb/db_access.h>
43 #include <ddb/db_sym.h>
44 #include <ddb/db_output.h>
45 #include <ddb/db_variables.h>
46 #include <ddb/db_command.h>
47 
48 #ifdef _KERNEL
49 static long nil;
50 
51 int db_access_und_sp(const struct db_variable *, db_expr_t *, int);
52 int db_access_abt_sp(const struct db_variable *, db_expr_t *, int);
53 int db_access_irq_sp(const struct db_variable *, db_expr_t *, int);
54 #endif
55 
56 const struct db_variable db_regs[] = {
57 	{ "spsr", (long *)&DDB_REGS->tf_spsr, FCN_NULL, NULL },
58 	{ "r0", (long *)&DDB_REGS->tf_r0, FCN_NULL, NULL },
59 	{ "r1", (long *)&DDB_REGS->tf_r1, FCN_NULL, NULL },
60 	{ "r2", (long *)&DDB_REGS->tf_r2, FCN_NULL, NULL },
61 	{ "r3", (long *)&DDB_REGS->tf_r3, FCN_NULL, NULL },
62 	{ "r4", (long *)&DDB_REGS->tf_r4, FCN_NULL, NULL },
63 	{ "r5", (long *)&DDB_REGS->tf_r5, FCN_NULL, NULL },
64 	{ "r6", (long *)&DDB_REGS->tf_r6, FCN_NULL, NULL },
65 	{ "r7", (long *)&DDB_REGS->tf_r7, FCN_NULL, NULL },
66 	{ "r8", (long *)&DDB_REGS->tf_r8, FCN_NULL, NULL },
67 	{ "r9", (long *)&DDB_REGS->tf_r9, FCN_NULL, NULL },
68 	{ "r10", (long *)&DDB_REGS->tf_r10, FCN_NULL, NULL },
69 	{ "r11", (long *)&DDB_REGS->tf_r11, FCN_NULL, NULL },
70 	{ "r12", (long *)&DDB_REGS->tf_r12, FCN_NULL, NULL },
71 	{ "usr_sp", (long *)&DDB_REGS->tf_usr_sp, FCN_NULL, NULL },
72 	{ "usr_lr", (long *)&DDB_REGS->tf_usr_lr, FCN_NULL, NULL },
73 	{ "svc_sp", (long *)&DDB_REGS->tf_svc_sp, FCN_NULL, NULL },
74 	{ "svc_lr", (long *)&DDB_REGS->tf_svc_lr, FCN_NULL, NULL },
75 	{ "pc", (long *)&DDB_REGS->tf_pc, FCN_NULL, NULL },
76 #ifdef _KERNEL
77 	{ "und_sp", &nil, db_access_und_sp, NULL },
78 	{ "abt_sp", &nil, db_access_abt_sp, NULL },
79 	{ "irq_sp", &nil, db_access_irq_sp, NULL },
80 #endif
81 };
82 
83 const struct db_variable * const db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
84 
85 const struct db_command db_machine_command_table[] = {
86 	{ DDB_ADD_CMD("frame",	db_show_frame_cmd,	0,
87 			"Displays the contents of a trapframe",
88 			"[address]",
89 			"   address:\taddress of trapfame to display")},
90 #ifdef _KERNEL
91 	{ DDB_ADD_CMD("fault",	db_show_fault_cmd,	0,
92 			"Displays the fault registers",
93 		     	NULL,NULL) },
94 #endif
95 #ifdef ARM32_DB_COMMANDS
96 	ARM32_DB_COMMANDS,
97 #endif
98 	{ DDB_ADD_CMD(NULL,     NULL,           0,NULL,NULL,NULL) }
99 };
100 
101 #ifdef _KERNEL
102 int
103 db_access_und_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
104 {
105 
106 	if (rw == DB_VAR_GET)
107 		*valp = get_stackptr(PSR_UND32_MODE);
108 	return(0);
109 }
110 
111 int
112 db_access_abt_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
113 {
114 
115 	if (rw == DB_VAR_GET)
116 		*valp = get_stackptr(PSR_ABT32_MODE);
117 	return(0);
118 }
119 
120 int
121 db_access_irq_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
122 {
123 
124 	if (rw == DB_VAR_GET)
125 		*valp = get_stackptr(PSR_IRQ32_MODE);
126 	return(0);
127 }
128 
129 void
130 db_show_fault_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
131 {
132 	db_printf("DFAR=%#x DFSR=%#x IFAR=%#x IFSR=%#x TTBR=%#x\n",
133 	    armreg_dfar_read(), armreg_dfsr_read(),
134 	    armreg_ifar_read(), armreg_ifsr_read(),
135 	    armreg_ttbr_read());
136 }
137 #endif
138 
139 
140 void
141 db_show_frame_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
142 {
143 	struct trapframe *frame;
144 
145 	if (!have_addr) {
146 		db_printf("frame address must be specified\n");
147 		return;
148 	}
149 
150 	frame = (struct trapframe *)addr;
151 
152 	db_printf("frame address = %08x  ", (u_int)frame);
153 	db_printf("spsr=%08x\n", frame->tf_spsr);
154 	db_printf("r0 =%08x r1 =%08x r2 =%08x r3 =%08x\n",
155 	    frame->tf_r0, frame->tf_r1, frame->tf_r2, frame->tf_r3);
156 	db_printf("r4 =%08x r5 =%08x r6 =%08x r7 =%08x\n",
157 	    frame->tf_r4, frame->tf_r5, frame->tf_r6, frame->tf_r7);
158 	db_printf("r8 =%08x r9 =%08x r10=%08x r11=%08x\n",
159 	    frame->tf_r8, frame->tf_r9, frame->tf_r10, frame->tf_r11);
160 	db_printf("r12=%08x r13=%08x r14=%08x r15=%08x\n",
161 	    frame->tf_r12, frame->tf_usr_sp, frame->tf_usr_lr, frame->tf_pc);
162 	db_printf("slr=%08x\n", frame->tf_svc_lr);
163 }
164