xref: /netbsd-src/sys/ddb/db_access.c (revision cda4f8f6ee55684e8d311b86c99ea59191e6b74f)
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 /*
27  * $Id: db_access.c,v 1.2 1993/05/20 03:39:04 cgd Exp $
28  *
29  * HISTORY
30  * $Log: db_access.c,v $
31  * Revision 1.2  1993/05/20 03:39:04  cgd
32  * add explicit rcs id
33  *
34  * Revision 1.1  1993/03/21  09:46:24  cgd
35  * Initial revision
36  *
37  * Revision 1.1  1992/03/25  21:44:50  pace
38  * Initial revision
39  *
40  * Revision 2.3  91/02/05  17:05:44  mrt
41  * 	Changed to new Mach copyright
42  * 	[91/01/31  16:16:22  mrt]
43  *
44  * Revision 2.2  90/08/27  21:48:20  dbg
45  * 	Fix type declarations.
46  * 	[90/08/07            dbg]
47  * 	Created.
48  * 	[90/07/25            dbg]
49  *
50  */
51 /*
52  *	Author: David B. Golub, Carnegie Mellon University
53  *	Date:	7/90
54  */
55 #include "param.h"
56 #include "proc.h"
57 #include <machine/db_machdep.h>		/* type definitions */
58 
59 /*
60  * Access unaligned data items on aligned (longword)
61  * boundaries.
62  */
63 
64 extern void	db_read_bytes();	/* machine-dependent */
65 extern void	db_write_bytes();	/* machine-dependent */
66 
67 int db_extend[] = {	/* table for sign-extending */
68 	0,
69 	0xFFFFFF80,
70 	0xFFFF8000,
71 	0xFF800000
72 };
73 
74 db_expr_t
75 db_get_value(addr, size, is_signed)
76 	db_addr_t	addr;
77 	register int	size;
78 	boolean_t	is_signed;
79 {
80 	char		data[sizeof(int)];
81 	register db_expr_t value;
82 	register int	i;
83 
84 	db_read_bytes(addr, size, data);
85 
86 	value = 0;
87 #if	BYTE_MSF
88 	for (i = 0; i < size; i++)
89 #else	/* BYTE_LSF */
90 	for (i = size - 1; i >= 0; i--)
91 #endif
92 	{
93 	    value = (value << 8) + (data[i] & 0xFF);
94 	}
95 
96 	if (size < 4) {
97 	    if (is_signed && (value & db_extend[size]) != 0)
98 		value |= db_extend[size];
99 	}
100 	return (value);
101 }
102 
103 void
104 db_put_value(addr, size, value)
105 	db_addr_t	addr;
106 	register int	size;
107 	register db_expr_t value;
108 {
109 	char		data[sizeof(int)];
110 	register int	i;
111 
112 #if	BYTE_MSF
113 	for (i = size - 1; i >= 0; i--)
114 #else	/* BYTE_LSF */
115 	for (i = 0; i < size; i++)
116 #endif
117 	{
118 	    data[i] = value & 0xFF;
119 	    value >>= 8;
120 	}
121 
122 	db_write_bytes(addr, size, data);
123 }
124 
125