1 /* $OpenBSD: db_access.c,v 1.7 1997/07/19 22:31:14 niklas Exp $ */ 2 /* $NetBSD: db_access.c,v 1.8 1994/10/09 08:37:35 mycroft Exp $ */ 3 4 /* 5 * Mach Operating System 6 * Copyright (c) 1991,1990 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 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 the 27 * the rights to redistribute these changes. 28 * 29 * Author: David B. Golub, Carnegie Mellon University 30 * Date: 7/90 31 */ 32 33 #include <sys/param.h> 34 #include <sys/proc.h> 35 36 #include <vm/vm.h> 37 38 #include <machine/db_machdep.h> /* type definitions */ 39 #include <machine/endian.h> 40 41 #include <ddb/db_access.h> 42 43 /* 44 * Access unaligned data items on aligned (longword) 45 * boundaries. 46 */ 47 db_expr_t 48 db_get_value(addr, size, is_signed) 49 db_addr_t addr; 50 size_t size; 51 boolean_t is_signed; 52 { 53 char data[sizeof(db_expr_t)]; 54 db_expr_t value, extend; 55 int i; 56 57 db_read_bytes(addr, size, data); 58 59 value = 0; 60 extend = (~(db_expr_t)0) << (size * 8 - 1); 61 #if BYTE_ORDER == LITTLE_ENDIAN 62 for (i = size - 1; i >= 0; i--) 63 #else /* BYTE_ORDER == BIG_ENDIAN */ 64 for (i = 0; i < size; i++) 65 #endif /* BYTE_ORDER */ 66 value = (value << 8) + (data[i] & 0xFF); 67 68 if (size < sizeof(db_expr_t) && is_signed && (value & extend)) 69 value |= extend; 70 return (value); 71 } 72 73 void 74 db_put_value(addr, size, value) 75 db_addr_t addr; 76 size_t size; 77 db_expr_t value; 78 { 79 char data[sizeof(db_expr_t)]; 80 int i; 81 82 #if BYTE_ORDER == LITTLE_ENDIAN 83 for (i = 0; i < size; i++) 84 #else /* BYTE_ORDER == BIG_ENDIAN */ 85 for (i = size - 1; i >= 0; i--) 86 #endif /* BYTE_ORDER */ 87 { 88 data[i] = value & 0xff; 89 value >>= 8; 90 } 91 92 db_write_bytes(addr, size, data); 93 } 94