1 /* 2 * Mach Operating System 3 * Copyright (c) 1991,1990 Carnegie Mellon University 4 * All Rights Reserved. 5 * 6 * Permission to use, copy, modify and distribute this software and its 7 * documentation is hereby granted, provided that both the copyright 8 * notice and this permission notice appear in all copies of the 9 * software, derivative works or modified versions, and any portions 10 * thereof, and that both notices appear in supporting documentation. 11 * 12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 15 * 16 * Carnegie Mellon requests users of this software to return to 17 * 18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 19 * School of Computer Science 20 * Carnegie Mellon University 21 * Pittsburgh PA 15213-3890 22 * 23 * any improvements or extensions that they make and grant Carnegie the 24 * rights to redistribute these changes. 25 * 26 * $Id: db_access.c,v 1.3 1993/11/25 01:30:01 wollman Exp $ 27 */ 28 29 /* 30 * Author: David B. Golub, Carnegie Mellon University 31 * Date: 7/90 32 */ 33 #include "param.h" 34 #include "systm.h" 35 #include "proc.h" 36 #include "ddb/ddb.h" 37 38 /* 39 * Access unaligned data items on aligned (longword) 40 * boundaries. 41 */ 42 43 extern void db_read_bytes(); /* machine-dependent */ 44 extern void db_write_bytes(); /* machine-dependent */ 45 46 unsigned db_extend[] = { /* table for sign-extending */ 47 0, 48 0xFFFFFF80U, 49 0xFFFF8000U, 50 0xFF800000U 51 }; 52 53 db_expr_t 54 db_get_value(addr, size, is_signed) 55 db_addr_t addr; 56 register int size; 57 boolean_t is_signed; 58 { 59 char data[sizeof(int)]; 60 register db_expr_t value; 61 register int i; 62 63 db_read_bytes(addr, size, data); 64 65 value = 0; 66 #if BYTE_MSF 67 for (i = 0; i < size; i++) 68 #else /* BYTE_LSF */ 69 for (i = size - 1; i >= 0; i--) 70 #endif 71 { 72 value = (value << 8) + (data[i] & 0xFF); 73 } 74 75 if (size < 4) { 76 if (is_signed && (value & db_extend[size]) != 0) 77 value |= db_extend[size]; 78 } 79 return (value); 80 } 81 82 void 83 db_put_value(addr, size, value) 84 db_addr_t addr; 85 register int size; 86 register db_expr_t value; 87 { 88 char data[sizeof(int)]; 89 register int i; 90 91 #if BYTE_MSF 92 for (i = size - 1; i >= 0; i--) 93 #else /* BYTE_LSF */ 94 for (i = 0; i < size; i++) 95 #endif 96 { 97 data[i] = value & 0xFF; 98 value >>= 8; 99 } 100 101 db_write_bytes(addr, size, data); 102 } 103 104