1*1b9a8bbaSmrg /* $NetBSD: db_machdep.c,v 1.12 2010/06/06 03:34:14 mrg Exp $ */
2ec984a04Sfredette
3ec984a04Sfredette /*-
4ec984a04Sfredette * Copyright (c) 1996 The NetBSD Foundation, Inc.
5ec984a04Sfredette * All rights reserved.
6ec984a04Sfredette *
7ec984a04Sfredette * This code is derived from software contributed to The NetBSD Foundation
8ec984a04Sfredette * by Gordon W. Ross.
9ec984a04Sfredette *
10ec984a04Sfredette * Redistribution and use in source and binary forms, with or without
11ec984a04Sfredette * modification, are permitted provided that the following conditions
12ec984a04Sfredette * are met:
13ec984a04Sfredette * 1. Redistributions of source code must retain the above copyright
14ec984a04Sfredette * notice, this list of conditions and the following disclaimer.
15ec984a04Sfredette * 2. Redistributions in binary form must reproduce the above copyright
16ec984a04Sfredette * notice, this list of conditions and the following disclaimer in the
17ec984a04Sfredette * documentation and/or other materials provided with the distribution.
18ec984a04Sfredette *
19ec984a04Sfredette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20ec984a04Sfredette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21ec984a04Sfredette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22ec984a04Sfredette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23ec984a04Sfredette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24ec984a04Sfredette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25ec984a04Sfredette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26ec984a04Sfredette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ec984a04Sfredette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28ec984a04Sfredette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29ec984a04Sfredette * POSSIBILITY OF SUCH DAMAGE.
30ec984a04Sfredette */
31ec984a04Sfredette
32ec984a04Sfredette /*
33ec984a04Sfredette * Machine-dependent functions used by ddb
34ec984a04Sfredette */
35ec984a04Sfredette
36ed517291Slukem #include <sys/cdefs.h>
37*1b9a8bbaSmrg __KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.12 2010/06/06 03:34:14 mrg Exp $");
38ed517291Slukem
39ec984a04Sfredette #include <sys/param.h>
40ec984a04Sfredette #include <sys/proc.h>
41ec984a04Sfredette
4243e759e5Sthorpej #include <uvm/uvm_extern.h>
4343e759e5Sthorpej
44ec984a04Sfredette #include <machine/db_machdep.h>
45ec984a04Sfredette #include <machine/promlib.h>
46ec984a04Sfredette #include <machine/pte.h>
47ec984a04Sfredette
48ec984a04Sfredette #include <sun2/sun2/machdep.h>
49ec984a04Sfredette #include <sun2/sun2/control.h>
50ec984a04Sfredette
51ec984a04Sfredette #include <ddb/db_command.h>
52ec984a04Sfredette #include <ddb/db_output.h>
53ec984a04Sfredette #include <ddb/db_interface.h>
54ec984a04Sfredette
556d6dd329She static void db_mach_abort (db_expr_t, bool, db_expr_t, const char *);
566d6dd329She static void db_mach_halt (db_expr_t, bool, db_expr_t, const char *);
576d6dd329She static void db_mach_reboot (db_expr_t, bool, db_expr_t, const char *);
586d6dd329She static void db_mach_pagemap(db_expr_t, bool, db_expr_t, const char *);
59ec984a04Sfredette
60ec984a04Sfredette const struct db_command db_machine_command_table[] = {
61*1b9a8bbaSmrg { DDB_ADD_CMD("abort", db_mach_abort, 0,
62*1b9a8bbaSmrg "Calls prom_abort()", NULL, NULL) },
63*1b9a8bbaSmrg { DDB_ADD_CMD("halt", db_mach_halt, 0,
64*1b9a8bbaSmrg "Calls prom_halt()", NULL, NULL) },
65*1b9a8bbaSmrg { DDB_ADD_CMD("pgmap", db_mach_pagemap, CS_SET_DOT,
66*1b9a8bbaSmrg "Prints the PTE and segmap values", "virtual-address", NULL) },
67*1b9a8bbaSmrg { DDB_ADD_CMD("reboot", db_mach_reboot, 0,
68*1b9a8bbaSmrg "Calls prom_boot()", NULL, NULL) },
69d9a407bbSmartin { DDB_ADD_CMD( NULL,NULL,0,NULL,NULL,NULL) }
70ec984a04Sfredette };
71ec984a04Sfredette
72ec984a04Sfredette /*
73ec984a04Sfredette * Machine-specific ddb commands for the sun2:
74ec984a04Sfredette * abort: Drop into monitor via abort (allows continue)
75ec984a04Sfredette * halt: Exit to monitor as in halt(8)
76ec984a04Sfredette * reboot: Reboot the machine as in reboot(8)
77ec984a04Sfredette * pgmap: Given addr, Print addr, segmap, pagemap, pte
78ec984a04Sfredette */
79ec984a04Sfredette
80ec984a04Sfredette static void
db_mach_abort(db_expr_t addr,bool have_addr,db_expr_t count,const char * modif)816d6dd329She db_mach_abort(db_expr_t addr, bool have_addr, db_expr_t count,
826d6dd329She const char *modif)
83ec984a04Sfredette {
84ec984a04Sfredette prom_abort();
85ec984a04Sfredette }
86ec984a04Sfredette
87ec984a04Sfredette static void
db_mach_halt(db_expr_t addr,bool have_addr,db_expr_t count,const char * modif)886d6dd329She db_mach_halt(db_expr_t addr, bool have_addr, db_expr_t count,
896d6dd329She const char *modif)
90ec984a04Sfredette {
91ec984a04Sfredette prom_halt();
92ec984a04Sfredette }
93ec984a04Sfredette
94ec984a04Sfredette static void
db_mach_reboot(db_expr_t addr,bool have_addr,db_expr_t count,const char * modif)956d6dd329She db_mach_reboot(db_expr_t addr, bool have_addr, db_expr_t count,
969eb856b0Stsutsui const char *modif)
97ec984a04Sfredette {
98ec984a04Sfredette prom_boot("");
99ec984a04Sfredette }
100ec984a04Sfredette
101ec984a04Sfredette
10210b1a7beSchs static void pte_print(int);
103ec984a04Sfredette
104ec984a04Sfredette static void
db_mach_pagemap(db_expr_t addr,bool have_addr,db_expr_t count,const char * modif)1056d6dd329She db_mach_pagemap(db_expr_t addr, bool have_addr, db_expr_t count,
1069eb856b0Stsutsui const char *modif)
107ec984a04Sfredette {
108ec984a04Sfredette u_long va = m68k_trunc_page((u_long)addr);
109ec984a04Sfredette int pte;
110ec984a04Sfredette int sme;
111ec984a04Sfredette
112ec984a04Sfredette sme = get_segmap(va);
113ec984a04Sfredette if (sme == 0xFF) pte = 0;
114ec984a04Sfredette else pte = get_pte(va);
115ec984a04Sfredette db_printf("0x%08lx [%02x] 0x%08x", va, sme, pte);
116ec984a04Sfredette
117ec984a04Sfredette pte_print(pte);
11843e759e5Sthorpej db_next = va + PAGE_SIZE;
119ec984a04Sfredette }
120ec984a04Sfredette
121ec984a04Sfredette static void
pte_print(int pte)12210b1a7beSchs pte_print(int pte)
123ec984a04Sfredette {
124ec984a04Sfredette int t;
1259eb856b0Stsutsui static const char *pgt_names[] = {
1268d1b187aSfredette "MEM", "OBIO", "VME0", "VME8",
127ec984a04Sfredette };
128ec984a04Sfredette
129ec984a04Sfredette if (pte & PG_VALID) {
130ec984a04Sfredette db_printf(" V");
131ec984a04Sfredette if (pte & PG_WRITE)
132ec984a04Sfredette db_printf(" W");
133ec984a04Sfredette if (pte & PG_SYSTEM)
134ec984a04Sfredette db_printf(" S");
135ec984a04Sfredette if (pte & PG_NC)
136ec984a04Sfredette db_printf(" NC");
137ec984a04Sfredette if (pte & PG_REF)
138ec984a04Sfredette db_printf(" Ref");
139ec984a04Sfredette if (pte & PG_MOD)
140ec984a04Sfredette db_printf(" Mod");
141ec984a04Sfredette
142ec984a04Sfredette t = (pte >> PG_TYPE_SHIFT) & 3;
143ec984a04Sfredette db_printf(" %s", pgt_names[t]);
144ec984a04Sfredette db_printf(" PA=0x%x\n", PG_PA(pte));
145ec984a04Sfredette }
146ec984a04Sfredette else db_printf(" INVALID\n");
147ec984a04Sfredette }
148