1 /* $NetBSD: db_memrw.c,v 1.4 2001/05/18 20:38:27 matt Exp $ */ 2 /* $OpenBSD: db_memrw.c,v 1.5 2003/10/15 01:06:13 drahn 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 #include <sys/systm.h> 44 45 #include <uvm/uvm_extern.h> 46 47 #include <machine/db_machdep.h> 48 #include <machine/pcb.h> 49 50 #include <ddb/db_access.h> 51 52 /* 53 * Read bytes from kernel address space for debugger. 54 */ 55 void 56 db_read_bytes(addr, size, data) 57 vaddr_t addr; 58 size_t size; 59 char *data; 60 { 61 char *src = (char *)addr; 62 faultbuf env; 63 faultbuf *old_onfault = curpcb->pcb_onfault; 64 if (setfault(&env)) { 65 curpcb->pcb_onfault = old_onfault; 66 return; 67 } 68 69 if (size == 4) { 70 *((int *)data) = *((int *)src); 71 } else if (size == 2) { 72 *((short *)data) = *((short *)src); 73 } else { 74 while (size > 0) { 75 --size; 76 *data++ = *src++; 77 } 78 } 79 curpcb->pcb_onfault = old_onfault; 80 } 81 82 /* 83 * Write bytes to kernel address space for debugger. 84 */ 85 void 86 db_write_bytes(addr, size, data) 87 vaddr_t addr; 88 size_t size; 89 char *data; 90 { 91 char *dst = (char *)addr; 92 faultbuf env; 93 faultbuf *old_onfault = curpcb->pcb_onfault; 94 95 if (setfault(&env)) { 96 curpcb->pcb_onfault = old_onfault; 97 return; 98 } 99 100 if (size == 4) { 101 *((int *)dst) = *((int *)data); 102 } else if (size == 2) { 103 *((short *)dst) = *((short *)data); 104 } else { 105 while (size > 0) { 106 --size; 107 *dst++ = *data++; 108 } 109 } 110 syncicache((void *)addr, size); 111 curpcb->pcb_onfault = old_onfault; 112 } 113 114