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