db_memrw.c revision 1.5 1 /* $NetBSD: db_memrw.c,v 1.5 1994/12/02 18:18:44 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 virtual memory read/write.
32 * To write in the text segment, we have to first make
33 * the page writable, do the write, then restore the PTE.
34 * For writes outside the text segment, and all reads,
35 * just do the access -- if it causes a fault, the debugger
36 * will recover with a longjmp to an appropriate place.
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 bytes from kernel address space for debugger.
49 * This used to check for valid PTEs, but now that
50 * traps in DDB work correctly, "Just Do It!"
51 */
52 void
53 db_read_bytes(addr, size, data)
54 vm_offset_t addr;
55 register int size;
56 register char *data;
57 {
58 register char *src;
59
60 src = (char *)addr;
61 while (--size >= 0)
62 *data++ = *src++;
63 }
64
65 /*
66 * Write one byte somewhere in kernel text.
67 * It does not matter if this is slow. -gwr
68 */
69 static void
70 db_write_text(dst, ch)
71 char *dst;
72 int ch;
73 {
74 int oldpte, tmppte;
75 vm_offset_t pgva;
76
77 pgva = sun3_trunc_page((long)dst);
78 oldpte = get_pte(pgva);
79
80 if ((oldpte & PG_VALID) == 0) {
81 db_printf(" address 0x%x not a valid page\n", dst);
82 return;
83 }
84
85 tmppte = oldpte | PG_WRITE;
86 set_pte(pgva, tmppte);
87
88 *dst = (char) ch;
89
90 set_pte(pgva, oldpte);
91 }
92
93 /*
94 * Write bytes to kernel address space for debugger.
95 */
96 void
97 db_write_bytes(addr, size, data)
98 vm_offset_t addr;
99 int size;
100 char *data;
101 {
102 extern char start[], etext[] ;
103 char *dst;
104
105 dst = (char *)addr;
106 while (--size >= 0) {
107 if ((dst >= start) && (dst < etext))
108 db_write_text(dst, *data);
109 else
110 *dst = *data;
111 dst++; data++;
112 }
113 }
114