db_access.c revision 798
14Srgrimes/* 24Srgrimes * Mach Operating System 34Srgrimes * Copyright (c) 1991,1990 Carnegie Mellon University 44Srgrimes * All Rights Reserved. 54Srgrimes * 64Srgrimes * Permission to use, copy, modify and distribute this software and its 74Srgrimes * documentation is hereby granted, provided that both the copyright 84Srgrimes * notice and this permission notice appear in all copies of the 94Srgrimes * software, derivative works or modified versions, and any portions 104Srgrimes * thereof, and that both notices appear in supporting documentation. 114Srgrimes * 124Srgrimes * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 134Srgrimes * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 144Srgrimes * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 154Srgrimes * 164Srgrimes * Carnegie Mellon requests users of this software to return to 174Srgrimes * 184Srgrimes * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 194Srgrimes * School of Computer Science 204Srgrimes * Carnegie Mellon University 214Srgrimes * Pittsburgh PA 15213-3890 224Srgrimes * 234Srgrimes * any improvements or extensions that they make and grant Carnegie the 244Srgrimes * rights to redistribute these changes. 254Srgrimes * 26798Swollman * $Id: db_access.c,v 1.2 1993/10/16 16:47:04 rgrimes Exp $ 274Srgrimes */ 28623Srgrimes 294Srgrimes/* 304Srgrimes * Author: David B. Golub, Carnegie Mellon University 314Srgrimes * Date: 7/90 324Srgrimes */ 334Srgrimes#include "param.h" 344Srgrimes#include "proc.h" 354Srgrimes#include <machine/db_machdep.h> /* type definitions */ 364Srgrimes 374Srgrimes/* 384Srgrimes * Access unaligned data items on aligned (longword) 394Srgrimes * boundaries. 404Srgrimes */ 414Srgrimes 424Srgrimesextern void db_read_bytes(); /* machine-dependent */ 434Srgrimesextern void db_write_bytes(); /* machine-dependent */ 444Srgrimes 45798Swollmanunsigned db_extend[] = { /* table for sign-extending */ 464Srgrimes 0, 47798Swollman 0xFFFFFF80U, 48798Swollman 0xFFFF8000U, 49798Swollman 0xFF800000U 504Srgrimes}; 514Srgrimes 524Srgrimesdb_expr_t 534Srgrimesdb_get_value(addr, size, is_signed) 544Srgrimes db_addr_t addr; 554Srgrimes register int size; 564Srgrimes boolean_t is_signed; 574Srgrimes{ 584Srgrimes char data[sizeof(int)]; 594Srgrimes register db_expr_t value; 604Srgrimes register int i; 614Srgrimes 624Srgrimes db_read_bytes(addr, size, data); 634Srgrimes 644Srgrimes value = 0; 654Srgrimes#if BYTE_MSF 664Srgrimes for (i = 0; i < size; i++) 674Srgrimes#else /* BYTE_LSF */ 684Srgrimes for (i = size - 1; i >= 0; i--) 694Srgrimes#endif 704Srgrimes { 714Srgrimes value = (value << 8) + (data[i] & 0xFF); 724Srgrimes } 734Srgrimes 744Srgrimes if (size < 4) { 754Srgrimes if (is_signed && (value & db_extend[size]) != 0) 764Srgrimes value |= db_extend[size]; 774Srgrimes } 784Srgrimes return (value); 794Srgrimes} 804Srgrimes 814Srgrimesvoid 824Srgrimesdb_put_value(addr, size, value) 834Srgrimes db_addr_t addr; 844Srgrimes register int size; 854Srgrimes register db_expr_t value; 864Srgrimes{ 874Srgrimes char data[sizeof(int)]; 884Srgrimes register int i; 894Srgrimes 904Srgrimes#if BYTE_MSF 914Srgrimes for (i = size - 1; i >= 0; i--) 924Srgrimes#else /* BYTE_LSF */ 934Srgrimes for (i = 0; i < size; i++) 944Srgrimes#endif 954Srgrimes { 964Srgrimes data[i] = value & 0xFF; 974Srgrimes value >>= 8; 984Srgrimes } 994Srgrimes 1004Srgrimes db_write_bytes(addr, size, data); 1014Srgrimes} 1024Srgrimes 103