db_memrw.c revision 1.2 1 /* $NetBSD: db_memrw.c,v 1.2 1994/11/21 21:38:25 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 * Write one byte somewhere in kernel text.
49 * It does not matter if this is slow. -gwr
50 */
51 static void
52 db_write_text(dst, ch)
53 char *dst;
54 int ch;
55 {
56 int oldpte, tmppte;
57 vm_offset_t pgva;
58
59 pgva = sun3_trunc_page((long)dst);
60 oldpte = get_pte(pgva);
61
62 if ((oldpte & PG_VALID) == 0) {
63 db_printf(" address 0x%x not a valid page\n", dst);
64 return;
65 }
66
67 tmppte = oldpte | PG_WRITE;
68 set_pte(pgva, tmppte);
69
70 *dst = (char) ch;
71
72 set_pte(pgva, oldpte);
73 }
74
75 /*
76 * Write bytes to kernel address space for debugger.
77 */
78 void
79 db_write_bytes(addr, size, data)
80 vm_offset_t addr;
81 int size;
82 char *data;
83 {
84 char *dst, *limit;
85 extern char start[], etext[] ;
86
87 dst = (char *)addr;
88 limit = dst + size;
89
90 while (dst < limit) {
91 if ((dst >= start) && (dst < etext))
92 db_write_text(dst, *data);
93 else
94 *dst = *data;
95 dst++;
96 data++;
97 }
98 }
99