1 /* $NetBSD: db_machdep.c,v 1.3 2021/02/23 07:13:53 mrg Exp $ */
2
3 /*
4 * Copyright (c) 1996-2002 Eduardo Horvath. All rights reserved.
5 * Mach Operating System
6 * Copyright (c) 1991,1990 Carnegie Mellon University
7 * All Rights Reserved.
8 *
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 *
29 * From: db_interface.c,v 2.4 1991/02/05 17:11:13 mrt (CMU)
30 */
31
32 /*
33 * Interface to new debugger.
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.3 2021/02/23 07:13:53 mrg Exp $");
38
39 #ifdef _KERNEL_OPT
40 #include "opt_ddb.h"
41 #endif
42
43 #include <sys/param.h>
44 #include <sys/cpu.h>
45 #include <ddb/ddb.h>
46
47 #ifdef _KERNEL
48 static int
db_sparc_charop(const struct db_variable * vp,db_expr_t * val,int opcode)49 db_sparc_charop(const struct db_variable *vp, db_expr_t *val, int opcode)
50 {
51 char *regaddr =
52 (char *)(((uint8_t *)DDB_REGS) + (size_t)vp->valuep);
53
54 switch (opcode) {
55 case DB_VAR_GET:
56 *val = *regaddr;
57 break;
58 case DB_VAR_SET:
59 *regaddr = *val;
60 break;
61 #ifdef DIAGNOSTIC
62 default:
63 printf("db_sparc_charop: opcode %d\n", opcode);
64 break;
65 #endif
66 }
67
68 return 0;
69 }
70
71 #ifdef not_used
72 static int
db_sparc_shortop(const struct db_variable * vp,db_expr_t * val,int opcode)73 db_sparc_shortop(const struct db_variable *vp, db_expr_t *val, int opcode)
74 {
75 short *regaddr =
76 (short *)(((uint8_t *)DDB_REGS) + (size_t)vp->valuep);
77
78 switch (opcode) {
79 case DB_VAR_GET:
80 *val = *regaddr;
81 break;
82 case DB_VAR_SET:
83 *regaddr = *val;
84 break;
85 #ifdef DIAGNOSTIC
86 default:
87 printf("sparc_shortop: opcode %d\n", opcode);
88 break;
89 #endif
90 }
91
92 return 0;
93 }
94 #endif
95
96 static int
db_sparc_intop(const struct db_variable * vp,db_expr_t * val,int opcode)97 db_sparc_intop(const struct db_variable *vp, db_expr_t *val, int opcode)
98 {
99 int *regaddr =
100 (int *)(((uint8_t *)DDB_REGS) + (size_t)vp->valuep);
101
102 switch (opcode) {
103 case DB_VAR_GET:
104 *val = *regaddr;
105 break;
106 case DB_VAR_SET:
107 *regaddr = *val;
108 break;
109 #ifdef DIAGNOSTIC
110 default:
111 printf("db_sparc_intop: opcode %d\n", opcode);
112 break;
113 #endif
114 }
115
116 return 0;
117 }
118
119 static int
db_sparc_regop(const struct db_variable * vp,db_expr_t * val,int opcode)120 db_sparc_regop(const struct db_variable *vp, db_expr_t *val, int opcode)
121 {
122 db_expr_t *regaddr =
123 (db_expr_t *)(((uint8_t *)DDB_REGS) + (size_t)vp->valuep);
124
125 switch (opcode) {
126 case DB_VAR_GET:
127 *val = *regaddr;
128 break;
129 case DB_VAR_SET:
130 *regaddr = *val;
131 break;
132 #ifdef DIAGNOSTIC
133 default:
134 printf("db_sparc_regop: unknown op %d\n", opcode);
135 break;
136 #endif
137 }
138 return 0;
139 }
140
141 /*
142 * Machine register set.
143 */
144 #define dbreg(xx) (long *)offsetof(db_regs_t, db_tf.tf_ ## xx)
145 #define dbregfr(xx) (long *)offsetof(db_regs_t, db_fr.fr_ ## xx)
146 #define dbregfp(xx) (long *)offsetof(db_regs_t, db_fpstate.fs_ ## xx)
147
148 static uint64_t nil;
149
150 const struct db_variable db_regs[] = {
151 { "tstate", dbreg(tstate), db_sparc_regop, 0 },
152 { "pc", dbreg(pc), db_sparc_regop, 0 },
153 { "npc", dbreg(npc), db_sparc_regop, 0 },
154 { "ipl", dbreg(oldpil), db_sparc_charop, 0 },
155 { "y", dbreg(y), db_sparc_intop, 0 },
156 { "g0", (void *)&nil, FCN_NULL, 0 },
157 { "g1", dbreg(global[1]), db_sparc_regop, 0 },
158 { "g2", dbreg(global[2]), db_sparc_regop, 0 },
159 { "g3", dbreg(global[3]), db_sparc_regop, 0 },
160 { "g4", dbreg(global[4]), db_sparc_regop, 0 },
161 { "g5", dbreg(global[5]), db_sparc_regop, 0 },
162 { "g6", dbreg(global[6]), db_sparc_regop, 0 },
163 { "g7", dbreg(global[7]), db_sparc_regop, 0 },
164 { "o0", dbreg(out[0]), db_sparc_regop, 0 },
165 { "o1", dbreg(out[1]), db_sparc_regop, 0 },
166 { "o2", dbreg(out[2]), db_sparc_regop, 0 },
167 { "o3", dbreg(out[3]), db_sparc_regop, 0 },
168 { "o4", dbreg(out[4]), db_sparc_regop, 0 },
169 { "o5", dbreg(out[5]), db_sparc_regop, 0 },
170 { "o6", dbreg(out[6]), db_sparc_regop, 0 },
171 { "o7", dbreg(out[7]), db_sparc_regop, 0 },
172 { "l0", dbregfr(local[0]), db_sparc_regop, 0 },
173 { "l1", dbregfr(local[1]), db_sparc_regop, 0 },
174 { "l2", dbregfr(local[2]), db_sparc_regop, 0 },
175 { "l3", dbregfr(local[3]), db_sparc_regop, 0 },
176 { "l4", dbregfr(local[4]), db_sparc_regop, 0 },
177 { "l5", dbregfr(local[5]), db_sparc_regop, 0 },
178 { "l6", dbregfr(local[6]), db_sparc_regop, 0 },
179 { "l7", dbregfr(local[7]), db_sparc_regop, 0 },
180 { "i0", dbregfr(arg[0]), db_sparc_regop, 0 },
181 { "i1", dbregfr(arg[1]), db_sparc_regop, 0 },
182 { "i2", dbregfr(arg[2]), db_sparc_regop, 0 },
183 { "i3", dbregfr(arg[3]), db_sparc_regop, 0 },
184 { "i4", dbregfr(arg[4]), db_sparc_regop, 0 },
185 { "i5", dbregfr(arg[5]), db_sparc_regop, 0 },
186 { "i6", dbregfr(fp), db_sparc_regop, 0 },
187 { "i7", dbregfr(pc), db_sparc_regop, 0 },
188 { "f0", dbregfp(regs[0]), db_sparc_regop, 0 },
189 { "f2", dbregfp(regs[2]), db_sparc_regop, 0 },
190 { "f4", dbregfp(regs[4]), db_sparc_regop, 0 },
191 { "f6", dbregfp(regs[6]), db_sparc_regop, 0 },
192 { "f8", dbregfp(regs[8]), db_sparc_regop, 0 },
193 { "f10", dbregfp(regs[10]), db_sparc_regop, 0 },
194 { "f12", dbregfp(regs[12]), db_sparc_regop, 0 },
195 { "f14", dbregfp(regs[14]), db_sparc_regop, 0 },
196 { "f16", dbregfp(regs[16]), db_sparc_regop, 0 },
197 { "f18", dbregfp(regs[18]), db_sparc_regop, 0 },
198 { "f20", dbregfp(regs[20]), db_sparc_regop, 0 },
199 { "f22", dbregfp(regs[22]), db_sparc_regop, 0 },
200 { "f24", dbregfp(regs[24]), db_sparc_regop, 0 },
201 { "f26", dbregfp(regs[26]), db_sparc_regop, 0 },
202 { "f28", dbregfp(regs[28]), db_sparc_regop, 0 },
203 { "f30", dbregfp(regs[30]), db_sparc_regop, 0 },
204 { "f32", dbregfp(regs[32]), db_sparc_regop, 0 },
205 { "f34", dbregfp(regs[34]), db_sparc_regop, 0 },
206 { "f36", dbregfp(regs[36]), db_sparc_regop, 0 },
207 { "f38", dbregfp(regs[38]), db_sparc_regop, 0 },
208 { "f40", dbregfp(regs[40]), db_sparc_regop, 0 },
209 { "f42", dbregfp(regs[42]), db_sparc_regop, 0 },
210 { "f44", dbregfp(regs[44]), db_sparc_regop, 0 },
211 { "f46", dbregfp(regs[46]), db_sparc_regop, 0 },
212 { "f48", dbregfp(regs[48]), db_sparc_regop, 0 },
213 { "f50", dbregfp(regs[50]), db_sparc_regop, 0 },
214 { "f52", dbregfp(regs[52]), db_sparc_regop, 0 },
215 { "f54", dbregfp(regs[54]), db_sparc_regop, 0 },
216 { "f56", dbregfp(regs[56]), db_sparc_regop, 0 },
217 { "f58", dbregfp(regs[58]), db_sparc_regop, 0 },
218 { "f60", dbregfp(regs[60]), db_sparc_regop, 0 },
219 { "f62", dbregfp(regs[62]), db_sparc_regop, 0 },
220 { "fsr", dbregfp(fsr), db_sparc_regop, 0 },
221 { "gsr", dbregfp(gsr), db_sparc_intop, 0 },
222 };
223 const struct db_variable * const db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
224 #endif
225
226 #ifndef DDB
227 const struct db_command db_machine_command_table[] = {
228 { DDB_END_CMD },
229 };
230 #endif /* DDB */
231