db_machdep.c revision 1.13 1 1.13 christos /* $NetBSD: db_machdep.c,v 1.13 2012/02/16 02:33:37 christos 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.13 christos __KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.13 2012/02/16 02:33:37 christos 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.13 christos static long nil;
49 1.1 matt
50 1.13 christos int db_access_und_sp(const struct db_variable *, db_expr_t *, int);
51 1.13 christos int db_access_abt_sp(const struct db_variable *, db_expr_t *, int);
52 1.13 christos int db_access_irq_sp(const struct db_variable *, db_expr_t *, int);
53 1.13 christos
54 1.13 christos const struct db_variable db_regs[] = {
55 1.13 christos { "spsr", (long *)&DDB_REGS->tf_spsr, FCN_NULL, NULL },
56 1.13 christos { "r0", (long *)&DDB_REGS->tf_r0, FCN_NULL, NULL },
57 1.13 christos { "r1", (long *)&DDB_REGS->tf_r1, FCN_NULL, NULL },
58 1.13 christos { "r2", (long *)&DDB_REGS->tf_r2, FCN_NULL, NULL },
59 1.13 christos { "r3", (long *)&DDB_REGS->tf_r3, FCN_NULL, NULL },
60 1.13 christos { "r4", (long *)&DDB_REGS->tf_r4, FCN_NULL, NULL },
61 1.13 christos { "r5", (long *)&DDB_REGS->tf_r5, FCN_NULL, NULL },
62 1.13 christos { "r6", (long *)&DDB_REGS->tf_r6, FCN_NULL, NULL },
63 1.13 christos { "r7", (long *)&DDB_REGS->tf_r7, FCN_NULL, NULL },
64 1.13 christos { "r8", (long *)&DDB_REGS->tf_r8, FCN_NULL, NULL },
65 1.13 christos { "r9", (long *)&DDB_REGS->tf_r9, FCN_NULL, NULL },
66 1.13 christos { "r10", (long *)&DDB_REGS->tf_r10, FCN_NULL, NULL },
67 1.13 christos { "r11", (long *)&DDB_REGS->tf_r11, FCN_NULL, NULL },
68 1.13 christos { "r12", (long *)&DDB_REGS->tf_r12, FCN_NULL, NULL },
69 1.13 christos { "usr_sp", (long *)&DDB_REGS->tf_usr_sp, FCN_NULL, NULL },
70 1.13 christos { "usr_lr", (long *)&DDB_REGS->tf_usr_lr, FCN_NULL, NULL },
71 1.13 christos { "svc_sp", (long *)&DDB_REGS->tf_svc_sp, FCN_NULL, NULL },
72 1.13 christos { "svc_lr", (long *)&DDB_REGS->tf_svc_lr, FCN_NULL, NULL },
73 1.13 christos { "pc", (long *)&DDB_REGS->tf_pc, FCN_NULL, NULL },
74 1.13 christos { "und_sp", &nil, db_access_und_sp, NULL },
75 1.13 christos { "abt_sp", &nil, db_access_abt_sp, NULL },
76 1.13 christos { "irq_sp", &nil, db_access_irq_sp, NULL },
77 1.13 christos };
78 1.13 christos
79 1.13 christos const struct db_variable * const db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
80 1.13 christos
81 1.13 christos const struct db_command db_machine_command_table[] = {
82 1.13 christos { DDB_ADD_CMD("frame", db_show_frame_cmd, 0,
83 1.13 christos "Displays the contents of a trapframe",
84 1.13 christos "[address]",
85 1.13 christos " address:\taddress of trapfame to display")},
86 1.13 christos #ifdef _KERNEL
87 1.13 christos { DDB_ADD_CMD("panic", db_show_panic_cmd, 0,
88 1.13 christos "Displays the last panic string",
89 1.13 christos NULL,NULL) },
90 1.13 christos #endif
91 1.13 christos #ifdef ARM32_DB_COMMANDS
92 1.13 christos ARM32_DB_COMMANDS,
93 1.13 christos #endif
94 1.13 christos { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL,NULL) }
95 1.13 christos };
96 1.13 christos
97 1.13 christos int
98 1.13 christos db_access_und_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
99 1.13 christos {
100 1.13 christos
101 1.13 christos if (rw == DB_VAR_GET)
102 1.13 christos *valp = get_stackptr(PSR_UND32_MODE);
103 1.13 christos return(0);
104 1.13 christos }
105 1.13 christos
106 1.13 christos int
107 1.13 christos db_access_abt_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
108 1.13 christos {
109 1.13 christos
110 1.13 christos if (rw == DB_VAR_GET)
111 1.13 christos *valp = get_stackptr(PSR_ABT32_MODE);
112 1.13 christos return(0);
113 1.13 christos }
114 1.13 christos
115 1.13 christos int
116 1.13 christos db_access_irq_sp(const struct db_variable *vp, db_expr_t *valp, int rw)
117 1.13 christos {
118 1.13 christos
119 1.13 christos if (rw == DB_VAR_GET)
120 1.13 christos *valp = get_stackptr(PSR_IRQ32_MODE);
121 1.13 christos return(0);
122 1.13 christos }
123 1.13 christos
124 1.13 christos #ifdef _KERNEL
125 1.1 matt void
126 1.12 dsl db_show_panic_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
127 1.1 matt {
128 1.1 matt int s;
129 1.1 matt s = splhigh();
130 1.1 matt
131 1.1 matt db_printf("Panic string: %s\n", panicstr);
132 1.1 matt (void)splx(s);
133 1.1 matt }
134 1.13 christos #endif
135 1.1 matt
136 1.1 matt
137 1.1 matt void
138 1.12 dsl db_show_frame_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
139 1.1 matt {
140 1.1 matt struct trapframe *frame;
141 1.1 matt
142 1.1 matt if (!have_addr) {
143 1.1 matt db_printf("frame address must be specified\n");
144 1.1 matt return;
145 1.1 matt }
146 1.1 matt
147 1.1 matt frame = (struct trapframe *)addr;
148 1.1 matt
149 1.1 matt db_printf("frame address = %08x ", (u_int)frame);
150 1.1 matt db_printf("spsr=%08x\n", frame->tf_spsr);
151 1.1 matt db_printf("r0 =%08x r1 =%08x r2 =%08x r3 =%08x\n",
152 1.1 matt frame->tf_r0, frame->tf_r1, frame->tf_r2, frame->tf_r3);
153 1.1 matt db_printf("r4 =%08x r5 =%08x r6 =%08x r7 =%08x\n",
154 1.1 matt frame->tf_r4, frame->tf_r5, frame->tf_r6, frame->tf_r7);
155 1.1 matt db_printf("r8 =%08x r9 =%08x r10=%08x r11=%08x\n",
156 1.1 matt frame->tf_r8, frame->tf_r9, frame->tf_r10, frame->tf_r11);
157 1.1 matt db_printf("r12=%08x r13=%08x r14=%08x r15=%08x\n",
158 1.1 matt frame->tf_r12, frame->tf_usr_sp, frame->tf_usr_lr, frame->tf_pc);
159 1.1 matt db_printf("slr=%08x\n", frame->tf_svc_lr);
160 1.1 matt }
161