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