db_machdep.c revision 1.15 1 1.15 matt /* $NetBSD: db_machdep.c,v 1.15 2012/09/21 22:12:35 matt 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.15 matt __KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.15 2012/09/21 22:12:35 matt 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.13 christos #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.13 christos #include <ddb/db_variables.h>
46 1.13 christos #include <ddb/db_command.h>
47 1.1 matt
48 1.14 skrll #ifdef _KERNEL
49 1.13 christos static long nil;
50 1.1 matt
51 1.13 christos int db_access_und_sp(const struct db_variable *, db_expr_t *, int);
52 1.13 christos int db_access_abt_sp(const struct db_variable *, db_expr_t *, int);
53 1.13 christos int db_access_irq_sp(const struct db_variable *, db_expr_t *, int);
54 1.14 skrll #endif
55 1.13 christos
56 1.13 christos const struct db_variable db_regs[] = {
57 1.13 christos { "spsr", (long *)&DDB_REGS->tf_spsr, FCN_NULL, NULL },
58 1.13 christos { "r0", (long *)&DDB_REGS->tf_r0, FCN_NULL, NULL },
59 1.13 christos { "r1", (long *)&DDB_REGS->tf_r1, FCN_NULL, NULL },
60 1.13 christos { "r2", (long *)&DDB_REGS->tf_r2, FCN_NULL, NULL },
61 1.13 christos { "r3", (long *)&DDB_REGS->tf_r3, FCN_NULL, NULL },
62 1.13 christos { "r4", (long *)&DDB_REGS->tf_r4, FCN_NULL, NULL },
63 1.13 christos { "r5", (long *)&DDB_REGS->tf_r5, FCN_NULL, NULL },
64 1.13 christos { "r6", (long *)&DDB_REGS->tf_r6, FCN_NULL, NULL },
65 1.13 christos { "r7", (long *)&DDB_REGS->tf_r7, FCN_NULL, NULL },
66 1.13 christos { "r8", (long *)&DDB_REGS->tf_r8, FCN_NULL, NULL },
67 1.13 christos { "r9", (long *)&DDB_REGS->tf_r9, FCN_NULL, NULL },
68 1.13 christos { "r10", (long *)&DDB_REGS->tf_r10, FCN_NULL, NULL },
69 1.13 christos { "r11", (long *)&DDB_REGS->tf_r11, FCN_NULL, NULL },
70 1.13 christos { "r12", (long *)&DDB_REGS->tf_r12, FCN_NULL, NULL },
71 1.13 christos { "usr_sp", (long *)&DDB_REGS->tf_usr_sp, FCN_NULL, NULL },
72 1.13 christos { "usr_lr", (long *)&DDB_REGS->tf_usr_lr, FCN_NULL, NULL },
73 1.13 christos { "svc_sp", (long *)&DDB_REGS->tf_svc_sp, FCN_NULL, NULL },
74 1.13 christos { "svc_lr", (long *)&DDB_REGS->tf_svc_lr, FCN_NULL, NULL },
75 1.13 christos { "pc", (long *)&DDB_REGS->tf_pc, FCN_NULL, NULL },
76 1.14 skrll #ifdef _KERNEL
77 1.13 christos { "und_sp", &nil, db_access_und_sp, NULL },
78 1.13 christos { "abt_sp", &nil, db_access_abt_sp, NULL },
79 1.13 christos { "irq_sp", &nil, db_access_irq_sp, NULL },
80 1.14 skrll #endif
81 1.13 christos };
82 1.13 christos
83 1.13 christos const struct db_variable * const db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
84 1.13 christos
85 1.13 christos const struct db_command db_machine_command_table[] = {
86 1.13 christos { DDB_ADD_CMD("frame", db_show_frame_cmd, 0,
87 1.13 christos "Displays the contents of a trapframe",
88 1.13 christos "[address]",
89 1.13 christos " address:\taddress of trapfame to display")},
90 1.13 christos #ifdef _KERNEL
91 1.13 christos { DDB_ADD_CMD("panic", db_show_panic_cmd, 0,
92 1.13 christos "Displays the last panic string",
93 1.13 christos NULL,NULL) },
94 1.15 matt { DDB_ADD_CMD("fault", db_show_fault_cmd, 0,
95 1.15 matt "Displays the fault registers",
96 1.15 matt NULL,NULL) },
97 1.13 christos #endif
98 1.13 christos #ifdef ARM32_DB_COMMANDS
99 1.13 christos ARM32_DB_COMMANDS,
100 1.13 christos #endif
101 1.13 christos { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL,NULL) }
102 1.13 christos };
103 1.13 christos
104 1.14 skrll #ifdef _KERNEL
105 1.13 christos int
106 1.13 christos db_access_und_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
107 1.13 christos {
108 1.13 christos
109 1.13 christos if (rw == DB_VAR_GET)
110 1.13 christos *valp = get_stackptr(PSR_UND32_MODE);
111 1.13 christos return(0);
112 1.13 christos }
113 1.13 christos
114 1.13 christos int
115 1.13 christos db_access_abt_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
116 1.13 christos {
117 1.13 christos
118 1.13 christos if (rw == DB_VAR_GET)
119 1.13 christos *valp = get_stackptr(PSR_ABT32_MODE);
120 1.13 christos return(0);
121 1.13 christos }
122 1.13 christos
123 1.13 christos int
124 1.13 christos db_access_irq_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
125 1.13 christos {
126 1.13 christos
127 1.13 christos if (rw == DB_VAR_GET)
128 1.13 christos *valp = get_stackptr(PSR_IRQ32_MODE);
129 1.13 christos return(0);
130 1.13 christos }
131 1.13 christos
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.15 matt
142 1.15 matt void
143 1.15 matt db_show_fault_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
144 1.15 matt {
145 1.15 matt db_printf("DFAR=%#x DFSR=%#x IFAR=%#x IFSR=%#x TTBR=%#x\n",
146 1.15 matt armreg_dfar_read(), armreg_dfsr_read(),
147 1.15 matt armreg_ifar_read(), armreg_ifsr_read(),
148 1.15 matt armreg_ttbr_read());
149 1.15 matt }
150 1.13 christos #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