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