xref: /netbsd/sys/arch/sun2/sun2/db_machdep.c (revision 6550d01e)
1 /*	$NetBSD: db_machdep.c,v 1.12 2010/06/06 03:34:14 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.12 2010/06/06 03:34:14 mrg Exp $");
38 
39 #include <sys/param.h>
40 #include <sys/proc.h>
41 
42 #include <uvm/uvm_extern.h>
43 
44 #include <machine/db_machdep.h>
45 #include <machine/promlib.h>
46 #include <machine/pte.h>
47 
48 #include <sun2/sun2/machdep.h>
49 #include <sun2/sun2/control.h>
50 
51 #include <ddb/db_command.h>
52 #include <ddb/db_output.h>
53 #include <ddb/db_interface.h>
54 
55 static void db_mach_abort  (db_expr_t, bool, db_expr_t, const char *);
56 static void db_mach_halt   (db_expr_t, bool, db_expr_t, const char *);
57 static void db_mach_reboot (db_expr_t, bool, db_expr_t, const char *);
58 static void db_mach_pagemap(db_expr_t, bool, db_expr_t, const char *);
59 
60 const struct db_command db_machine_command_table[] = {
61 	{ DDB_ADD_CMD("abort",	db_mach_abort,	0,
62 	  "Calls prom_abort()", NULL, NULL) },
63 	{ DDB_ADD_CMD("halt",	db_mach_halt,	0,
64 	  "Calls prom_halt()", NULL, NULL) },
65 	{ DDB_ADD_CMD("pgmap",	db_mach_pagemap, CS_SET_DOT,
66 	  "Prints the PTE and segmap values", "virtual-address", NULL) },
67 	{ DDB_ADD_CMD("reboot",	db_mach_reboot,	0,
68 	  "Calls prom_boot()", NULL, NULL) },
69 	{ DDB_ADD_CMD( NULL,NULL,0,NULL,NULL,NULL) }
70 };
71 
72 /*
73  * Machine-specific ddb commands for the sun2:
74  *    abort:	Drop into monitor via abort (allows continue)
75  *    halt: 	Exit to monitor as in halt(8)
76  *    reboot:	Reboot the machine as in reboot(8)
77  *    pgmap:	Given addr, Print addr, segmap, pagemap, pte
78  */
79 
80 static void
81 db_mach_abort(db_expr_t addr, bool have_addr, db_expr_t count,
82     const char *modif)
83 {
84 	prom_abort();
85 }
86 
87 static void
88 db_mach_halt(db_expr_t addr, bool have_addr, db_expr_t count,
89     const char *modif)
90 {
91 	prom_halt();
92 }
93 
94 static void
95 db_mach_reboot(db_expr_t addr, bool have_addr, db_expr_t count,
96     const char *modif)
97 {
98 	prom_boot("");
99 }
100 
101 
102 static void pte_print(int);
103 
104 static void
105 db_mach_pagemap(db_expr_t addr, bool have_addr, db_expr_t count,
106     const char *modif)
107 {
108 	u_long va = m68k_trunc_page((u_long)addr);
109 	int pte;
110 	int sme;
111 
112 	sme = get_segmap(va);
113 	if (sme == 0xFF) pte = 0;
114 	else pte = get_pte(va);
115 	db_printf("0x%08lx [%02x] 0x%08x", va, sme, pte);
116 
117 	pte_print(pte);
118 	db_next = va + PAGE_SIZE;
119 }
120 
121 static void
122 pte_print(int pte)
123 {
124 	int t;
125 	static const char *pgt_names[] = {
126 		"MEM", "OBIO", "VME0", "VME8",
127 	};
128 
129 	if (pte & PG_VALID) {
130 		db_printf(" V");
131 		if (pte & PG_WRITE)
132 			db_printf(" W");
133 		if (pte & PG_SYSTEM)
134 			db_printf(" S");
135 		if (pte & PG_NC)
136 			db_printf(" NC");
137 		if (pte & PG_REF)
138 			db_printf(" Ref");
139 		if (pte & PG_MOD)
140 			db_printf(" Mod");
141 
142 		t = (pte >> PG_TYPE_SHIFT) & 3;
143 		db_printf(" %s", pgt_names[t]);
144 		db_printf(" PA=0x%x\n", PG_PA(pte));
145 	}
146 	else db_printf(" INVALID\n");
147 }
148