db_memrw.c revision 1.7 1 /* $NetBSD: db_memrw.c,v 1.7 1995/02/07 04:37:48 gwr Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995 Gordon W. Ross
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 * 4. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Gordon Ross
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * Machine-dependent functions used by ddb
35 */
36
37 #include <sys/param.h>
38 #include <sys/proc.h>
39
40 #include <vm/vm.h>
41
42 #include <machine/db_machdep.h>
43 #include <ddb/db_command.h>
44
45 #include <machine/pte.h>
46
47 /*
48 * Interface to the debugger for virtual memory read/write.
49 *
50 * To write in the text segment, we have to first make
51 * the page writable, do the write, then restore the PTE.
52 * For writes outside the text segment, and all reads,
53 * just do the access -- if it causes a fault, the debugger
54 * will recover with a longjmp to an appropriate place.
55 */
56
57 /*
58 * Read bytes from kernel address space for debugger.
59 * This used to check for valid PTEs, but now that
60 * traps in DDB work correctly, "Just Do It!"
61 */
62 void
63 db_read_bytes(addr, size, data)
64 vm_offset_t addr;
65 register int size;
66 register char *data;
67 {
68 register char *src;
69
70 src = (char *)addr;
71 while (--size >= 0)
72 *data++ = *src++;
73 }
74
75 /*
76 * Write one byte somewhere in kernel text.
77 * It does not matter if this is slow. -gwr
78 */
79 static void
80 db_write_text(dst, ch)
81 char *dst;
82 int ch;
83 {
84 int oldpte, tmppte;
85 vm_offset_t pgva;
86
87 pgva = sun3_trunc_page((long)dst);
88 oldpte = get_pte(pgva);
89
90 if ((oldpte & PG_VALID) == 0) {
91 db_printf(" address 0x%x not a valid page\n", dst);
92 return;
93 }
94
95 tmppte = oldpte | PG_WRITE;
96 set_pte(pgva, tmppte);
97
98 *dst = (char) ch;
99
100 set_pte(pgva, oldpte);
101 }
102
103 /*
104 * Write bytes to kernel address space for debugger.
105 */
106 void
107 db_write_bytes(addr, size, data)
108 vm_offset_t addr;
109 int size;
110 char *data;
111 {
112 extern char start[], etext[] ;
113 char *dst;
114
115 dst = (char *)addr;
116 while (--size >= 0) {
117 if ((dst >= start) && (dst < etext))
118 db_write_text(dst, *data);
119 else
120 *dst = *data;
121 dst++; data++;
122 }
123 }
124
125
126 /*
127 * Machine-specific ddb commands for the sun3:
128 * abort: Drop into monitor via abort (allows continue)
129 * halt: Exit to monitor as in halt(8)
130 * reboot: Reboot the machine as in reboot(8)
131 */
132
133 extern void sun3_mon_abort();
134 extern void sun3_mon_halt();
135
136 void
137 db_mon_reboot()
138 {
139 sun3_mon_reboot("");
140 }
141
142 struct db_command db_machine_cmds[] = {
143 { "abort", sun3_mon_abort, 0, 0 },
144 { "halt", sun3_mon_halt, 0, 0 },
145 { "reboot", db_mon_reboot, 0, 0 },
146 { (char *)0, }
147 };
148
149 /*
150 * This is called before ddb_init() to install the
151 * machine-specific command table. (see machdep.c)
152 */
153 void
154 db_machine_init()
155 {
156 db_machine_commands_install(db_machine_cmds);
157 }
158