db_machdep.c revision 1.12.12.2 1 1.12.12.2 yamt /* $NetBSD: db_machdep.c,v 1.12.12.2 2012/10/30 17:18:56 yamt Exp $ */
2 1.1 matt
3 1.1 matt /*
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.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.8 lukem
31 1.8 lukem #include <sys/cdefs.h>
32 1.12.12.2 yamt __KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.12.12.2 2012/10/30 17:18:56 yamt Exp $");
33 1.1 matt
34 1.1 matt #include <sys/param.h>
35 1.1 matt #include <sys/proc.h>
36 1.1 matt #include <sys/vnode.h>
37 1.1 matt #include <sys/systm.h>
38 1.1 matt
39 1.7 chris #include <arm/arm32/db_machdep.h>
40 1.12.12.1 yamt #include <arm/cpufunc.h>
41 1.1 matt
42 1.1 matt #include <ddb/db_access.h>
43 1.1 matt #include <ddb/db_sym.h>
44 1.1 matt #include <ddb/db_output.h>
45 1.12.12.1 yamt #include <ddb/db_variables.h>
46 1.12.12.1 yamt #include <ddb/db_command.h>
47 1.1 matt
48 1.12.12.2 yamt #ifdef _KERNEL
49 1.12.12.1 yamt static long nil;
50 1.1 matt
51 1.12.12.1 yamt int db_access_und_sp(const struct db_variable *, db_expr_t *, int);
52 1.12.12.1 yamt int db_access_abt_sp(const struct db_variable *, db_expr_t *, int);
53 1.12.12.1 yamt int db_access_irq_sp(const struct db_variable *, db_expr_t *, int);
54 1.12.12.2 yamt #endif
55 1.12.12.1 yamt
56 1.12.12.1 yamt const struct db_variable db_regs[] = {
57 1.12.12.1 yamt { "spsr", (long *)&DDB_REGS->tf_spsr, FCN_NULL, NULL },
58 1.12.12.1 yamt { "r0", (long *)&DDB_REGS->tf_r0, FCN_NULL, NULL },
59 1.12.12.1 yamt { "r1", (long *)&DDB_REGS->tf_r1, FCN_NULL, NULL },
60 1.12.12.1 yamt { "r2", (long *)&DDB_REGS->tf_r2, FCN_NULL, NULL },
61 1.12.12.1 yamt { "r3", (long *)&DDB_REGS->tf_r3, FCN_NULL, NULL },
62 1.12.12.1 yamt { "r4", (long *)&DDB_REGS->tf_r4, FCN_NULL, NULL },
63 1.12.12.1 yamt { "r5", (long *)&DDB_REGS->tf_r5, FCN_NULL, NULL },
64 1.12.12.1 yamt { "r6", (long *)&DDB_REGS->tf_r6, FCN_NULL, NULL },
65 1.12.12.1 yamt { "r7", (long *)&DDB_REGS->tf_r7, FCN_NULL, NULL },
66 1.12.12.1 yamt { "r8", (long *)&DDB_REGS->tf_r8, FCN_NULL, NULL },
67 1.12.12.1 yamt { "r9", (long *)&DDB_REGS->tf_r9, FCN_NULL, NULL },
68 1.12.12.1 yamt { "r10", (long *)&DDB_REGS->tf_r10, FCN_NULL, NULL },
69 1.12.12.1 yamt { "r11", (long *)&DDB_REGS->tf_r11, FCN_NULL, NULL },
70 1.12.12.1 yamt { "r12", (long *)&DDB_REGS->tf_r12, FCN_NULL, NULL },
71 1.12.12.1 yamt { "usr_sp", (long *)&DDB_REGS->tf_usr_sp, FCN_NULL, NULL },
72 1.12.12.1 yamt { "usr_lr", (long *)&DDB_REGS->tf_usr_lr, FCN_NULL, NULL },
73 1.12.12.1 yamt { "svc_sp", (long *)&DDB_REGS->tf_svc_sp, FCN_NULL, NULL },
74 1.12.12.1 yamt { "svc_lr", (long *)&DDB_REGS->tf_svc_lr, FCN_NULL, NULL },
75 1.12.12.1 yamt { "pc", (long *)&DDB_REGS->tf_pc, FCN_NULL, NULL },
76 1.12.12.2 yamt #ifdef _KERNEL
77 1.12.12.1 yamt { "und_sp", &nil, db_access_und_sp, NULL },
78 1.12.12.1 yamt { "abt_sp", &nil, db_access_abt_sp, NULL },
79 1.12.12.1 yamt { "irq_sp", &nil, db_access_irq_sp, NULL },
80 1.12.12.2 yamt #endif
81 1.12.12.1 yamt };
82 1.12.12.1 yamt
83 1.12.12.1 yamt const struct db_variable * const db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
84 1.12.12.1 yamt
85 1.12.12.1 yamt const struct db_command db_machine_command_table[] = {
86 1.12.12.1 yamt { DDB_ADD_CMD("frame", db_show_frame_cmd, 0,
87 1.12.12.1 yamt "Displays the contents of a trapframe",
88 1.12.12.1 yamt "[address]",
89 1.12.12.1 yamt " address:\taddress of trapfame to display")},
90 1.12.12.1 yamt #ifdef _KERNEL
91 1.12.12.1 yamt { DDB_ADD_CMD("panic", db_show_panic_cmd, 0,
92 1.12.12.1 yamt "Displays the last panic string",
93 1.12.12.1 yamt NULL,NULL) },
94 1.12.12.2 yamt { DDB_ADD_CMD("fault", db_show_fault_cmd, 0,
95 1.12.12.2 yamt "Displays the fault registers",
96 1.12.12.2 yamt NULL,NULL) },
97 1.12.12.1 yamt #endif
98 1.12.12.1 yamt #ifdef ARM32_DB_COMMANDS
99 1.12.12.1 yamt ARM32_DB_COMMANDS,
100 1.12.12.1 yamt #endif
101 1.12.12.1 yamt { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL,NULL) }
102 1.12.12.1 yamt };
103 1.12.12.1 yamt
104 1.12.12.2 yamt #ifdef _KERNEL
105 1.12.12.1 yamt int
106 1.12.12.1 yamt db_access_und_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
107 1.12.12.1 yamt {
108 1.12.12.1 yamt
109 1.12.12.1 yamt if (rw == DB_VAR_GET)
110 1.12.12.1 yamt *valp = get_stackptr(PSR_UND32_MODE);
111 1.12.12.1 yamt return(0);
112 1.12.12.1 yamt }
113 1.12.12.1 yamt
114 1.12.12.1 yamt int
115 1.12.12.1 yamt db_access_abt_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
116 1.12.12.1 yamt {
117 1.12.12.1 yamt
118 1.12.12.1 yamt if (rw == DB_VAR_GET)
119 1.12.12.1 yamt *valp = get_stackptr(PSR_ABT32_MODE);
120 1.12.12.1 yamt return(0);
121 1.12.12.1 yamt }
122 1.12.12.1 yamt
123 1.12.12.1 yamt int
124 1.12.12.1 yamt db_access_irq_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
125 1.12.12.1 yamt {
126 1.12.12.1 yamt
127 1.12.12.1 yamt if (rw == DB_VAR_GET)
128 1.12.12.1 yamt *valp = get_stackptr(PSR_IRQ32_MODE);
129 1.12.12.1 yamt return(0);
130 1.12.12.1 yamt }
131 1.12.12.1 yamt
132 1.1 matt void
133 1.12 dsl db_show_panic_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
134 1.1 matt {
135 1.1 matt int s;
136 1.1 matt s = splhigh();
137 1.1 matt
138 1.1 matt db_printf("Panic string: %s\n", panicstr);
139 1.1 matt (void)splx(s);
140 1.1 matt }
141 1.12.12.2 yamt
142 1.12.12.2 yamt void
143 1.12.12.2 yamt db_show_fault_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
144 1.12.12.2 yamt {
145 1.12.12.2 yamt db_printf("DFAR=%#x DFSR=%#x IFAR=%#x IFSR=%#x TTBR=%#x\n",
146 1.12.12.2 yamt armreg_dfar_read(), armreg_dfsr_read(),
147 1.12.12.2 yamt armreg_ifar_read(), armreg_ifsr_read(),
148 1.12.12.2 yamt armreg_ttbr_read());
149 1.12.12.2 yamt }
150 1.12.12.1 yamt #endif
151 1.1 matt
152 1.1 matt
153 1.1 matt void
154 1.12 dsl db_show_frame_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
155 1.1 matt {
156 1.1 matt struct trapframe *frame;
157 1.1 matt
158 1.1 matt if (!have_addr) {
159 1.1 matt db_printf("frame address must be specified\n");
160 1.1 matt return;
161 1.1 matt }
162 1.1 matt
163 1.1 matt frame = (struct trapframe *)addr;
164 1.1 matt
165 1.1 matt db_printf("frame address = %08x ", (u_int)frame);
166 1.1 matt db_printf("spsr=%08x\n", frame->tf_spsr);
167 1.1 matt db_printf("r0 =%08x r1 =%08x r2 =%08x r3 =%08x\n",
168 1.1 matt frame->tf_r0, frame->tf_r1, frame->tf_r2, frame->tf_r3);
169 1.1 matt db_printf("r4 =%08x r5 =%08x r6 =%08x r7 =%08x\n",
170 1.1 matt frame->tf_r4, frame->tf_r5, frame->tf_r6, frame->tf_r7);
171 1.1 matt db_printf("r8 =%08x r9 =%08x r10=%08x r11=%08x\n",
172 1.1 matt frame->tf_r8, frame->tf_r9, frame->tf_r10, frame->tf_r11);
173 1.1 matt db_printf("r12=%08x r13=%08x r14=%08x r15=%08x\n",
174 1.1 matt frame->tf_r12, frame->tf_usr_sp, frame->tf_usr_lr, frame->tf_pc);
175 1.1 matt db_printf("slr=%08x\n", frame->tf_svc_lr);
176 1.1 matt }
177