1 /* $NetBSD: db_machdep.c,v 1.2 2021/02/23 07:13:52 mrg Exp $ */
2
3 /*
4 * Mach Operating System
5 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * All Rights Reserved.
7 *
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *
18 * Carnegie Mellon requests users of this software to return to
19 *
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
24 *
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
27 *
28 * From: db_interface.c,v 2.4 1991/02/05 17:11:13 mrt (CMU)
29 */
30
31 /*
32 * Interface to new debugger.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.2 2021/02/23 07:13:52 mrg Exp $");
37
38 #ifdef _KERNEL_OPT
39 #include "opt_ddb.h"
40 #endif
41
42 #include <sys/param.h>
43 #include <machine/db_machdep.h>
44 #include <ddb/db_user.h>
45 #include <ddb/db_command.h>
46 #include <ddb/db_variables.h>
47
48 /*
49 * Machine register set.
50 */
51 #define dbreg(xx) (long *)offsetof(db_regs_t, db_tf.tf_ ## xx)
52 #define dbregfr(xx) (long *)offsetof(db_regs_t, db_fr.fr_ ## xx)
53
54 static int db_sparc_regop(const struct db_variable *, db_expr_t *, int);
55
56 db_regs_t *ddb_regp;
57 static long nil;
58
59 const struct db_variable db_regs[] = {
60 { "psr", dbreg(psr), db_sparc_regop, NULL, },
61 { "pc", dbreg(pc), db_sparc_regop, NULL, },
62 { "npc", dbreg(npc), db_sparc_regop, NULL, },
63 { "y", dbreg(y), db_sparc_regop, NULL, },
64 { "wim", dbreg(global[0]), db_sparc_regop, NULL, }, /* see reg.h */
65 { "g0", &nil, FCN_NULL, NULL, },
66 { "g1", dbreg(global[1]), db_sparc_regop, NULL, },
67 { "g2", dbreg(global[2]), db_sparc_regop, NULL, },
68 { "g3", dbreg(global[3]), db_sparc_regop, NULL, },
69 { "g4", dbreg(global[4]), db_sparc_regop, NULL, },
70 { "g5", dbreg(global[5]), db_sparc_regop, NULL, },
71 { "g6", dbreg(global[6]), db_sparc_regop, NULL, },
72 { "g7", dbreg(global[7]), db_sparc_regop, NULL, },
73 { "o0", dbreg(out[0]), db_sparc_regop, NULL, },
74 { "o1", dbreg(out[1]), db_sparc_regop, NULL, },
75 { "o2", dbreg(out[2]), db_sparc_regop, NULL, },
76 { "o3", dbreg(out[3]), db_sparc_regop, NULL, },
77 { "o4", dbreg(out[4]), db_sparc_regop, NULL, },
78 { "o5", dbreg(out[5]), db_sparc_regop, NULL, },
79 { "o6", dbreg(out[6]), db_sparc_regop, NULL, },
80 { "o7", dbreg(out[7]), db_sparc_regop, NULL, },
81 { "l0", dbregfr(local[0]), db_sparc_regop, NULL, },
82 { "l1", dbregfr(local[1]), db_sparc_regop, NULL, },
83 { "l2", dbregfr(local[2]), db_sparc_regop, NULL, },
84 { "l3", dbregfr(local[3]), db_sparc_regop, NULL, },
85 { "l4", dbregfr(local[4]), db_sparc_regop, NULL, },
86 { "l5", dbregfr(local[5]), db_sparc_regop, NULL, },
87 { "l6", dbregfr(local[6]), db_sparc_regop, NULL, },
88 { "l7", dbregfr(local[7]), db_sparc_regop, NULL, },
89 { "i0", dbregfr(arg[0]), db_sparc_regop, NULL, },
90 { "i1", dbregfr(arg[1]), db_sparc_regop, NULL, },
91 { "i2", dbregfr(arg[2]), db_sparc_regop, NULL, },
92 { "i3", dbregfr(arg[3]), db_sparc_regop, NULL, },
93 { "i4", dbregfr(arg[4]), db_sparc_regop, NULL, },
94 { "i5", dbregfr(arg[5]), db_sparc_regop, NULL, },
95 { "i6", dbregfr(fp), db_sparc_regop, NULL, },
96 { "i7", dbregfr(pc), db_sparc_regop, NULL, },
97 };
98 const struct db_variable * const db_eregs =
99 db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
100
101 static int
db_sparc_regop(const struct db_variable * vp,db_expr_t * val,int opcode)102 db_sparc_regop(const struct db_variable *vp, db_expr_t *val, int opcode)
103 {
104 db_expr_t *regaddr =
105 (db_expr_t *)(((uint8_t *)DDB_REGS) + ((size_t)vp->valuep));
106
107 switch (opcode) {
108 case DB_VAR_GET:
109 *val = *regaddr;
110 break;
111 case DB_VAR_SET:
112 *regaddr = *val;
113 break;
114 default:
115 #ifdef _KERNEL
116 panic("db_sparc_regop: unknown op %d", opcode);
117 #else
118 printf("db_sparc_regop: unknown op %d\n", opcode);
119 #endif
120 }
121 return 0;
122 }
123
124 #ifndef DDB
125 const struct db_command db_machine_command_table[] = {
126 { DDB_END_CMD },
127 };
128 #endif /* DDB */
129