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