1*433d6423SLionel Sambuc /*
2*433d6423SLionel Sambuc * Mach Operating System
3*433d6423SLionel Sambuc * Copyright (c) 1991,1990 Carnegie Mellon University
4*433d6423SLionel Sambuc * All Rights Reserved.
5*433d6423SLionel Sambuc *
6*433d6423SLionel Sambuc * Permission to use, copy, modify and distribute this software and its
7*433d6423SLionel Sambuc * documentation is hereby granted, provided that both the copyright
8*433d6423SLionel Sambuc * notice and this permission notice appear in all copies of the
9*433d6423SLionel Sambuc * software, derivative works or modified versions, and any portions
10*433d6423SLionel Sambuc * thereof, and that both notices appear in supporting documentation.
11*433d6423SLionel Sambuc *
12*433d6423SLionel Sambuc * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13*433d6423SLionel Sambuc * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14*433d6423SLionel Sambuc * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15*433d6423SLionel Sambuc *
16*433d6423SLionel Sambuc * Carnegie Mellon requests users of this software to return to
17*433d6423SLionel Sambuc *
18*433d6423SLionel Sambuc * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19*433d6423SLionel Sambuc * School of Computer Science
20*433d6423SLionel Sambuc * Carnegie Mellon University
21*433d6423SLionel Sambuc * Pittsburgh PA 15213-3890
22*433d6423SLionel Sambuc *
23*433d6423SLionel Sambuc * any improvements or extensions that they make and grant Carnegie the
24*433d6423SLionel Sambuc * rights to redistribute these changes.
25*433d6423SLionel Sambuc */
26*433d6423SLionel Sambuc
27*433d6423SLionel Sambuc /*
28*433d6423SLionel Sambuc * Author: David B. Golub, Carnegie Mellon University
29*433d6423SLionel Sambuc * Date: 7/90
30*433d6423SLionel Sambuc */
31*433d6423SLionel Sambuc #include "ddb.h"
32*433d6423SLionel Sambuc #include "db_access.h"
33*433d6423SLionel Sambuc
34*433d6423SLionel Sambuc #include "extra.h"
35*433d6423SLionel Sambuc
36*433d6423SLionel Sambuc /*
37*433d6423SLionel Sambuc * Access unaligned data items on aligned (longword)
38*433d6423SLionel Sambuc * boundaries.
39*433d6423SLionel Sambuc */
40*433d6423SLionel Sambuc
41*433d6423SLionel Sambuc static unsigned db_extend[] = { /* table for sign-extending */
42*433d6423SLionel Sambuc 0,
43*433d6423SLionel Sambuc 0xFFFFFF80U,
44*433d6423SLionel Sambuc 0xFFFF8000U,
45*433d6423SLionel Sambuc 0xFF800000U
46*433d6423SLionel Sambuc };
47*433d6423SLionel Sambuc
48*433d6423SLionel Sambuc void
db_read_bytes(addr,size,data)49*433d6423SLionel Sambuc db_read_bytes(addr, size, data)
50*433d6423SLionel Sambuc vm_offset_t addr;
51*433d6423SLionel Sambuc register int size;
52*433d6423SLionel Sambuc register char *data;
53*433d6423SLionel Sambuc {
54*433d6423SLionel Sambuc register char *src;
55*433d6423SLionel Sambuc
56*433d6423SLionel Sambuc src = (char *)addr;
57*433d6423SLionel Sambuc while (--size >= 0)
58*433d6423SLionel Sambuc *data++ = text_read_ub(src++);
59*433d6423SLionel Sambuc
60*433d6423SLionel Sambuc }
61*433d6423SLionel Sambuc
62*433d6423SLionel Sambuc db_expr_t
db_get_value(addr,size,is_signed)63*433d6423SLionel Sambuc db_get_value(addr, size, is_signed)
64*433d6423SLionel Sambuc db_addr_t addr;
65*433d6423SLionel Sambuc register int size;
66*433d6423SLionel Sambuc boolean_t is_signed;
67*433d6423SLionel Sambuc {
68*433d6423SLionel Sambuc char data[sizeof(int)];
69*433d6423SLionel Sambuc register db_expr_t value;
70*433d6423SLionel Sambuc register int i;
71*433d6423SLionel Sambuc
72*433d6423SLionel Sambuc db_read_bytes(addr, size, data);
73*433d6423SLionel Sambuc
74*433d6423SLionel Sambuc value = 0;
75*433d6423SLionel Sambuc #if BYTE_MSF
76*433d6423SLionel Sambuc for (i = 0; i < size; i++)
77*433d6423SLionel Sambuc #else /* BYTE_LSF */
78*433d6423SLionel Sambuc for (i = size - 1; i >= 0; i--)
79*433d6423SLionel Sambuc #endif
80*433d6423SLionel Sambuc {
81*433d6423SLionel Sambuc value = (value << 8) + (data[i] & 0xFF);
82*433d6423SLionel Sambuc }
83*433d6423SLionel Sambuc
84*433d6423SLionel Sambuc if (size < 4) {
85*433d6423SLionel Sambuc if (is_signed && (value & db_extend[size]) != 0)
86*433d6423SLionel Sambuc value |= db_extend[size];
87*433d6423SLionel Sambuc }
88*433d6423SLionel Sambuc return (value);
89*433d6423SLionel Sambuc }
90*433d6423SLionel Sambuc
91