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