db_memrw.c revision 1.3 1 /* $NetBSD: db_memrw.c,v 1.3 1994/11/28 19:17:07 gwr Exp $ */
2
3 /*
4 * Copyright (c) 1994 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 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 /*
31 * Interface to the debugger for writing in the kernel.
32 * To write in the text segment, we have to first make
33 * the page writable, do the write, then restore the PTE.
34 *
35 * XXX - Should do db_read_bytes() here too so it can
36 * make sure the address is valid (mapped) first...
37 */
38
39 #include <sys/param.h>
40 #include <sys/proc.h>
41
42 #include <vm/vm.h>
43
44 #include <machine/db_machdep.h>
45 #include <machine/pte.h>
46
47 /*
48 * Read one byte somewhere in the kernel.
49 * It does not matter if this is slow. -gwr
50 */
51 static char
52 db_read_data(src)
53 char *src;
54 {
55 int oldpte;
56 vm_offset_t pgva;
57 int ch;
58
59 pgva = sun3_trunc_page((long)src);
60 oldpte = get_pte(pgva);
61
62 if ((oldpte & PG_VALID) == 0) {
63 db_printf(" address 0x%x not a valid page\n", src);
64 return 0;
65 }
66 return (*src);
67 }
68
69 /*
70 * Read bytes from kernel address space for debugger.
71 * It does not matter if this is slow. -gwr
72 */
73 void
74 db_read_bytes(addr, size, data)
75 vm_offset_t addr;
76 register int size;
77 register char *data;
78 {
79 char *src, *limit;
80
81 src = (char *)addr;
82 limit = src + size;
83
84 while (src < limit) {
85 *data = db_read_data(src);
86 data++;
87 src++;
88 }
89 }
90
91 /*
92 * Write one byte somewhere in kernel text.
93 * It does not matter if this is slow. -gwr
94 */
95 static void
96 db_write_text(dst, ch)
97 char *dst;
98 int ch;
99 {
100 int oldpte, tmppte;
101 vm_offset_t pgva;
102
103 pgva = sun3_trunc_page((long)dst);
104 oldpte = get_pte(pgva);
105
106 if ((oldpte & PG_VALID) == 0) {
107 db_printf(" address 0x%x not a valid page\n", dst);
108 return;
109 }
110
111 tmppte = oldpte | PG_WRITE;
112 set_pte(pgva, tmppte);
113
114 *dst = (char) ch;
115
116 set_pte(pgva, oldpte);
117 }
118
119 /*
120 * Write one byte somewhere outside kernel text.
121 * It does not matter if this is slow. -gwr
122 */
123 static void
124 db_write_data(dst, ch)
125 char *dst;
126 int ch;
127 {
128 int oldpte;
129 vm_offset_t pgva;
130
131 pgva = sun3_trunc_page((long)dst);
132 oldpte = get_pte(pgva);
133
134 if ((oldpte & (PG_VALID | PG_WRITE)) == 0) {
135 db_printf(" address 0x%x not a valid page\n", dst);
136 return;
137 }
138 *dst = (char) ch;
139 }
140
141 /*
142 * Write bytes to kernel address space for debugger.
143 */
144 void
145 db_write_bytes(addr, size, data)
146 vm_offset_t addr;
147 int size;
148 char *data;
149 {
150 extern char start[], etext[] ;
151 char *dst, *limit;
152
153 dst = (char *)addr;
154 limit = dst + size;
155
156 while (dst < limit) {
157 if ((dst >= start) && (dst < etext))
158 db_write_text(dst, *data);
159 else
160 db_write_data(dst, *data);
161 dst++;
162 data++;
163 }
164 }
165