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