Home | History | Annotate | Line # | Download | only in ddb
db_access.c revision 1.15.2.2
      1  1.15.2.2   nathanw /*	$NetBSD: db_access.c,v 1.15.2.2 2002/02/28 04:13:04 nathanw Exp $	*/
      2       1.5       cgd 
      3  1.15.2.2   nathanw /*
      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.15.2.2   nathanw  *
      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.15.2.2   nathanw  *
     14      1.13        pk  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     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.15.2.2   nathanw  *
     18       1.1       cgd  * Carnegie Mellon requests users of this software to return to
     19  1.15.2.2   nathanw  *
     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.15.2.2   nathanw  *
     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.15.2.1   nathanw 
     32  1.15.2.1   nathanw #include <sys/cdefs.h>
     33  1.15.2.2   nathanw __KERNEL_RCSID(0, "$NetBSD: db_access.c,v 1.15.2.2 2002/02/28 04:13:04 nathanw Exp $");
     34       1.3   mycroft 
     35       1.3   mycroft #include <sys/param.h>
     36       1.3   mycroft #include <sys/proc.h>
     37       1.3   mycroft 
     38       1.1       cgd #include <machine/db_machdep.h>		/* type definitions */
     39       1.8   mycroft #include <machine/endian.h>
     40       1.1       cgd 
     41       1.7   mycroft #include <ddb/db_access.h>
     42       1.7   mycroft 
     43       1.1       cgd /*
     44       1.1       cgd  * Access unaligned data items on aligned (longword)
     45       1.1       cgd  * boundaries.
     46       1.1       cgd  */
     47       1.1       cgd 
     48      1.15  jdolecek const int db_extend[] = {	/* table for sign-extending */
     49       1.1       cgd 	0,
     50       1.1       cgd 	0xFFFFFF80,
     51       1.1       cgd 	0xFFFF8000,
     52       1.1       cgd 	0xFF800000
     53       1.1       cgd };
     54       1.1       cgd 
     55       1.1       cgd db_expr_t
     56  1.15.2.2   nathanw db_get_value(db_addr_t addr, size_t size, boolean_t is_signed)
     57       1.1       cgd {
     58       1.9   thorpej 	char data[sizeof(db_expr_t)];
     59      1.14  augustss 	db_expr_t value;
     60      1.14  augustss 	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.15.2.2   nathanw 
     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.15.2.2   nathanw db_put_value(db_addr_t addr, size_t size, db_expr_t value)
     79       1.1       cgd {
     80       1.9   thorpej 	char data[sizeof(db_expr_t)];
     81      1.14  augustss 	size_t i;
     82       1.1       cgd 
     83       1.8   mycroft #if BYTE_ORDER == LITTLE_ENDIAN
     84       1.8   mycroft 	for (i = 0; i < size; i++)
     85       1.8   mycroft #else /* BYTE_ORDER == BIG_ENDIAN */
     86      1.11        pk 	for (i = size; i-- > 0;)
     87       1.8   mycroft #endif /* BYTE_ORDER */
     88       1.1       cgd 	{
     89       1.8   mycroft 		data[i] = value & 0xFF;
     90       1.8   mycroft 		value >>= 8;
     91       1.1       cgd 	}
     92       1.1       cgd 
     93       1.1       cgd 	db_write_bytes(addr, size, data);
     94       1.1       cgd }
     95