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