1 /* $NetBSD: db_machdep.c,v 1.29 2021/02/23 07:13:53 mrg Exp $ */
2
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Machine-dependent functions used by ddb
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.29 2021/02/23 07:13:53 mrg Exp $");
38
39 #include <sys/param.h>
40 #include <sys/proc.h>
41
42 #include <machine/db_machdep.h>
43 #include <machine/pte.h>
44
45 #include <sun3/sun3/machdep.h>
46 #ifdef _SUN3_
47 #include <sun3/sun3/control.h>
48 #endif /* SUN3 */
49
50 #include <ddb/db_command.h>
51 #include <ddb/db_output.h>
52 #include <ddb/db_interface.h>
53
54 static void db_mach_abort (db_expr_t, bool, db_expr_t, const char *);
55 static void db_mach_halt (db_expr_t, bool, db_expr_t, const char *);
56 static void db_mach_reboot (db_expr_t, bool, db_expr_t, const char *);
57 static void db_mach_pagemap(db_expr_t, bool, db_expr_t, const char *);
58
59 const struct db_command db_machine_command_table[] = {
60 { DDB_ADD_CMD("abort", db_mach_abort, 0,
61 "Calls prom_abort()", NULL, NULL) },
62 { DDB_ADD_CMD("halt", db_mach_halt, 0,
63 "Calls prom_halt()", NULL, NULL) },
64 { DDB_ADD_CMD("pgmap", db_mach_pagemap, CS_SET_DOT,
65 "Prints the PTE and segmap values", "virtual-address", NULL) },
66 { DDB_ADD_CMD("reboot", db_mach_reboot, 0,
67 "Calls prom_boot()", NULL, NULL) },
68 { DDB_END_CMD },
69 };
70
71 /*
72 * Machine-specific ddb commands for the sun3:
73 * abort: Drop into monitor via abort (allows continue)
74 * halt: Exit to monitor as in halt(8)
75 * reboot: Reboot the machine as in reboot(8)
76 * pgmap: Given addr, Print addr, segmap, pagemap, pte
77 */
78
79 static void
db_mach_abort(db_expr_t addr,bool have_addr,db_expr_t count,const char * modif)80 db_mach_abort(db_expr_t addr, bool have_addr, db_expr_t count,
81 const char *modif)
82 {
83
84 sunmon_abort();
85 }
86
87 static void
db_mach_halt(db_expr_t addr,bool have_addr,db_expr_t count,const char * modif)88 db_mach_halt(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
89 {
90
91 sunmon_halt();
92 }
93
94 static void
db_mach_reboot(db_expr_t addr,bool have_addr,db_expr_t count,const char * modif)95 db_mach_reboot(db_expr_t addr, bool have_addr, db_expr_t count,
96 const char *modif)
97 {
98
99 sunmon_reboot("");
100 }
101
102
103 static void pte_print(int);
104
105 static void
db_mach_pagemap(db_expr_t addr,bool have_addr,db_expr_t count,const char * modif)106 db_mach_pagemap(db_expr_t addr, bool have_addr, db_expr_t count,
107 const char *modif)
108 {
109 u_long va = m68k_trunc_page((u_long)addr);
110 int pte;
111 #ifdef _SUN3_
112 int sme;
113
114 sme = get_segmap(va);
115 if (sme == 0xFF) {
116 pte = 0;
117 } else {
118 pte = get_pte(va);
119 }
120 db_printf("0x%08lx [%02x] 0x%08x", va, sme, pte);
121 #endif /* SUN3 */
122 #ifdef _SUN3X_
123 pte = get_pte(va);
124 db_printf("0x%08lx 0x%08x", va, pte);
125 #endif /* SUN3X */
126
127 pte_print(pte);
128 db_next = va + PAGE_SIZE;
129 }
130
131 #ifdef _SUN3_
132 static void
pte_print(int pte)133 pte_print(int pte)
134 {
135 int t;
136 static const char *pgt_names[] = {
137 "MEM", "OBIO", "VMES", "VMEL",
138 };
139
140 if (pte & PG_VALID) {
141 db_printf(" V");
142 if (pte & PG_WRITE)
143 db_printf(" W");
144 if (pte & PG_SYSTEM)
145 db_printf(" S");
146 if (pte & PG_NC)
147 db_printf(" NC");
148 if (pte & PG_REF)
149 db_printf(" Ref");
150 if (pte & PG_MOD)
151 db_printf(" Mod");
152
153 t = (pte >> PG_TYPE_SHIFT) & 3;
154 db_printf(" %s", pgt_names[t]);
155 db_printf(" PA=0x%x\n", PG_PA(pte));
156 } else
157 db_printf(" INVALID\n");
158 }
159 #endif /* SUN3 */
160
161 #ifdef _SUN3X_
162 static void
pte_print(int pte)163 pte_print(int pte)
164 {
165
166 if (pte & MMU_SHORT_PTE_DT) {
167 if (pte & MMU_SHORT_PTE_CI)
168 db_printf(" CI");
169 if (pte & MMU_SHORT_PTE_M)
170 db_printf(" Mod");
171 if (pte & MMU_SHORT_PTE_USED)
172 db_printf(" Ref");
173 if (pte & MMU_SHORT_PTE_WP)
174 db_printf(" WP");
175 db_printf(" DT%d\n", pte & MMU_SHORT_PTE_DT);
176 } else
177 db_printf(" INVALID\n");
178 }
179 #endif /* SUN3X */
180