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