FreeBSD/Linux Kernel Cross Reference
sys/ddb/db_access.c
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 "AS IS"
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 Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: db_access.c,v $
29 * Revision 2.9 93/03/09 10:53:11 danner
30 * Here we go again. Pls leave db_extend[] alone, ok ?
31 * [93/03/05 af]
32 *
33 * Revision 2.8 93/01/14 17:24:15 danner
34 * Fixed last entry of db_extend.
35 * [93/01/14 danner]
36 *
37 * 64bit cleanup. db_extend[] was rightly signed.
38 * [92/11/30 af]
39 *
40 * Revision 2.7 92/08/03 17:30:22 jfriedl
41 * removed silly prototypes
42 * [92/08/02 jfriedl]
43 *
44 * Revision 2.6 92/05/21 17:06:10 jfriedl
45 * Made db_extend unsigned and made constants unsigned as well.
46 * This make it the same in STDC and traditional. Also shuts up lint.
47 * [92/05/16 jfriedl]
48 *
49 * Revision 2.5 91/10/09 15:56:44 af
50 * Added db_{get,put}_task_value, and changed db_{get,put}_value
51 * to call them. db_{get,put}_value are left for compatibility
52 * reason.
53 * Added "task" parameter to specifiy target task space.
54 * Added db_access_level to indicate implementation dependent
55 * access capability.
56 * [91/08/29 tak]
57 *
58 * Revision 2.4 91/05/14 15:31:33 mrt
59 * Correcting copyright
60 *
61 * Revision 2.3 91/02/05 17:05:44 mrt
62 * Changed to new Mach copyright
63 * [91/01/31 16:16:22 mrt]
64 *
65 * Revision 2.2 90/08/27 21:48:20 dbg
66 * Fix type declarations.
67 * [90/08/07 dbg]
68 * Created.
69 * [90/07/25 dbg]
70 *
71 */
72 /*
73 * Author: David B. Golub, Carnegie Mellon University
74 * Date: 7/90
75 */
76 #include <mach/boolean.h>
77 #include <machine/db_machdep.h> /* type definitions */
78 #include <machine/setjmp.h>
79 #include <kern/task.h>
80 #include <ddb/db_access.h>
81
82
83
84 /*
85 * Access unaligned data items on aligned (longword)
86 * boundaries.
87 */
88
89 extern void db_read_bytes(); /* machine-dependent */
90 extern void db_write_bytes(); /* machine-dependent */
91
92 int db_access_level = DB_ACCESS_LEVEL;
93
94 /*
95 * This table is for sign-extending things.
96 * Therefore its entries are signed, and yes
97 * they are infact negative numbers.
98 * So don't you put no more Us in it. Or Ls either.
99 * Otherwise there is no point having it, n'est pas ?
100 */
101 static int db_extend[sizeof(int)+1] = { /* table for sign-extending */
102 0,
103 0xFFFFFF80,
104 0xFFFF8000,
105 0xFF800000,
106 0x80000000
107 };
108
109 db_expr_t
110 db_get_task_value(addr, size, is_signed, task)
111 db_addr_t addr;
112 register int size;
113 boolean_t is_signed;
114 task_t task;
115 {
116 char data[sizeof(db_expr_t)];
117 register db_expr_t value;
118 register int i;
119
120 db_read_bytes((void*)addr, size, data, task);
121
122 value = 0;
123 #if BYTE_MSF
124 for (i = 0; i < size; i++)
125 #else /* BYTE_LSF */
126 for (i = size - 1; i >= 0; i--)
127 #endif
128 {
129 value = (value << 8) + (data[i] & 0xFF);
130 }
131
132 if (size <= sizeof(int)) {
133 if (is_signed && (value & db_extend[size]) != 0)
134 value |= db_extend[size];
135 }
136 return (value);
137 }
138
139 void
140 db_put_task_value(addr, size, value, task)
141 db_addr_t addr;
142 register int size;
143 register db_expr_t value;
144 task_t task;
145 {
146 char data[sizeof(db_expr_t)];
147 register int i;
148
149 #if BYTE_MSF
150 for (i = size - 1; i >= 0; i--)
151 #else /* BYTE_LSF */
152 for (i = 0; i < size; i++)
153 #endif
154 {
155 data[i] = value & 0xFF;
156 value >>= 8;
157 }
158
159 db_write_bytes((void*)addr, size, data, task);
160 }
161
162 db_expr_t
163 db_get_value(addr, size, is_signed)
164 db_addr_t addr;
165 int size;
166 boolean_t is_signed;
167 {
168 return(db_get_task_value(addr, size, is_signed, TASK_NULL));
169 }
170
171 void
172 db_put_value(addr, size, value)
173 db_addr_t addr;
174 int size;
175 db_expr_t value;
176 {
177 db_put_task_value(addr, size, value, TASK_NULL);
178 }
Cache object: 9223f484bc9b16b4a819a29f797aa26a
|