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