xref: /netbsd/sys/arch/powerpc/powerpc/db_memrw.c (revision 6550d01e)
1 /*	$NetBSD: db_memrw.c,v 1.9 2005/12/11 12:18:46 christos 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/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.9 2005/12/11 12:18:46 christos Exp $");
43 
44 #include <sys/param.h>
45 #include <sys/proc.h>
46 
47 #include <uvm/uvm_extern.h>
48 
49 #include <machine/db_machdep.h>
50 
51 #include <ddb/db_access.h>
52 
53 /*
54  * Read bytes from kernel address space for debugger.
55  */
56 void
57 db_read_bytes(vaddr_t addr, size_t size, char *data)
58 {
59 	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(vaddr_t addr, size_t size, const char *data)
82 {
83 	char *dst = (char *)addr;
84 
85 	if (size == 4) {
86 
87 		*((int*)dst) = *((const int*)data);
88 
89 	} else 	if (size == 2) {
90 
91 		*((short*)dst) = *((const short*)data);
92 
93 	} else {
94 
95 		while (size > 0) {
96 			--size;
97 			*dst++ = *data++;
98 		}
99 
100 	}
101 
102 	__syncicache((void *)addr, size);
103 }
104