db_machdep.c revision 1.17 1 1.17 skrll /* $NetBSD: db_machdep.c,v 1.17 2013/12/15 09:14:09 skrll 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.8 lukem #include <sys/cdefs.h>
32 1.17 skrll __KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.17 2013/12/15 09:14:09 skrll 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.15 matt { DDB_ADD_CMD("fault", db_show_fault_cmd, 0,
92 1.15 matt "Displays the fault registers",
93 1.15 matt NULL,NULL) },
94 1.13 christos #endif
95 1.13 christos #ifdef ARM32_DB_COMMANDS
96 1.13 christos ARM32_DB_COMMANDS,
97 1.13 christos #endif
98 1.13 christos { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL,NULL) }
99 1.13 christos };
100 1.13 christos
101 1.14 skrll #ifdef _KERNEL
102 1.13 christos int
103 1.13 christos db_access_und_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
104 1.13 christos {
105 1.13 christos
106 1.13 christos if (rw == DB_VAR_GET)
107 1.13 christos *valp = get_stackptr(PSR_UND32_MODE);
108 1.13 christos return(0);
109 1.13 christos }
110 1.13 christos
111 1.13 christos int
112 1.13 christos db_access_abt_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
113 1.13 christos {
114 1.13 christos
115 1.13 christos if (rw == DB_VAR_GET)
116 1.13 christos *valp = get_stackptr(PSR_ABT32_MODE);
117 1.13 christos return(0);
118 1.13 christos }
119 1.13 christos
120 1.13 christos int
121 1.13 christos db_access_irq_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
122 1.13 christos {
123 1.13 christos
124 1.13 christos if (rw == DB_VAR_GET)
125 1.13 christos *valp = get_stackptr(PSR_IRQ32_MODE);
126 1.13 christos return(0);
127 1.13 christos }
128 1.13 christos
129 1.1 matt void
130 1.15 matt db_show_fault_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
131 1.15 matt {
132 1.15 matt db_printf("DFAR=%#x DFSR=%#x IFAR=%#x IFSR=%#x TTBR=%#x\n",
133 1.15 matt armreg_dfar_read(), armreg_dfsr_read(),
134 1.15 matt armreg_ifar_read(), armreg_ifsr_read(),
135 1.15 matt armreg_ttbr_read());
136 1.15 matt }
137 1.13 christos #endif
138 1.1 matt
139 1.1 matt
140 1.1 matt void
141 1.12 dsl db_show_frame_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
142 1.1 matt {
143 1.1 matt struct trapframe *frame;
144 1.1 matt
145 1.1 matt if (!have_addr) {
146 1.1 matt db_printf("frame address must be specified\n");
147 1.1 matt return;
148 1.1 matt }
149 1.1 matt
150 1.1 matt frame = (struct trapframe *)addr;
151 1.1 matt
152 1.1 matt db_printf("frame address = %08x ", (u_int)frame);
153 1.1 matt db_printf("spsr=%08x\n", frame->tf_spsr);
154 1.1 matt db_printf("r0 =%08x r1 =%08x r2 =%08x r3 =%08x\n",
155 1.1 matt frame->tf_r0, frame->tf_r1, frame->tf_r2, frame->tf_r3);
156 1.1 matt db_printf("r4 =%08x r5 =%08x r6 =%08x r7 =%08x\n",
157 1.1 matt frame->tf_r4, frame->tf_r5, frame->tf_r6, frame->tf_r7);
158 1.1 matt db_printf("r8 =%08x r9 =%08x r10=%08x r11=%08x\n",
159 1.1 matt frame->tf_r8, frame->tf_r9, frame->tf_r10, frame->tf_r11);
160 1.1 matt db_printf("r12=%08x r13=%08x r14=%08x r15=%08x\n",
161 1.1 matt frame->tf_r12, frame->tf_usr_sp, frame->tf_usr_lr, frame->tf_pc);
162 1.1 matt db_printf("slr=%08x\n", frame->tf_svc_lr);
163 1.1 matt }
164