xref: /netbsd/sys/arch/powerpc/powerpc/db_memrw.c (revision bf9ec67e)
1 /*	$NetBSD: db_memrw.c,v 1.5 2001/12/27 10:25:41 dbj Exp $	*/
2 /*	$OpenBSD: db_memrw.c,v 1.2 1996/12/28 06:21:52 rahnds Exp $	*/
3 
4 /*
5  * Mach Operating System
6  * Copyright (c) 1992 Carnegie Mellon University
7  * All Rights Reserved.
8  *
9  * Permission to use, copy, modify and distribute this software and its
10  * documentation is hereby granted, provided that both the copyright
11  * notice and this permission notice appear in all copies of the
12  * software, derivative works or modified versions, and any portions
13  * thereof, and that both notices appear in supporting documentation.
14  *
15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18  *
19  * Carnegie Mellon requests users of this software to return to
20  *
21  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22  *  School of Computer Science
23  *  Carnegie Mellon University
24  *  Pittsburgh PA 15213-3890
25  *
26  * any improvements or extensions that they make and grant Carnegie Mellon
27  * the rights to redistribute these changes.
28  */
29 
30 /*
31  * Interface to the debugger for virtual memory read/write.
32  * This is a simple version for kernels with writable text.
33  * For an example of read-only kernel text, see the file:
34  * sys/arch/sun3/sun3/db_memrw.c
35  *
36  * ALERT!  If you want to access device registers with a
37  * specific size, then the read/write functions have to
38  * make sure to do the correct sized pointer access.
39  */
40 
41 #include <sys/param.h>
42 #include <sys/proc.h>
43 
44 #include <uvm/uvm_extern.h>
45 
46 #include <machine/db_machdep.h>
47 
48 #include <ddb/db_access.h>
49 
50 /*
51  * Read bytes from kernel address space for debugger.
52  */
53 void
54 db_read_bytes(addr, size, data)
55 	vaddr_t		addr;
56 	register size_t	size;
57 	register char	*data;
58 {
59 	register char	*src = (char*)addr;
60 
61 	if (size == 4) {
62 		*((int*)data) = *((int*)src);
63 		return;
64 	}
65 
66 	if (size == 2) {
67 		*((short*)data) = *((short*)src);
68 		return;
69 	}
70 
71 	while (size > 0) {
72 		--size;
73 		*data++ = *src++;
74 	}
75 }
76 
77 /*
78  * Write bytes to kernel address space for debugger.
79  */
80 void
81 db_write_bytes(addr, size, data)
82 	vaddr_t		addr;
83 	register size_t	size;
84 	register char	*data;
85 {
86 	register char	*dst = (char *)addr;
87 
88 	if (size == 4) {
89 
90 		*((int*)dst) = *((int*)data);
91 
92 	} else 	if (size == 2) {
93 
94 		*((short*)dst) = *((short*)data);
95 
96 	} else {
97 
98 		while (size > 0) {
99 			--size;
100 			*dst++ = *data++;
101 		}
102 
103 	}
104 
105 	__syncicache((void *)addr, size);
106 }
107 
108