]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ddb/db_access.c
xnu-517.3.15.tar.gz
[apple/xnu.git] / osfmk / ddb / db_access.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 /*
29 * Mach Operating System
30 * Copyright (c) 1991,1990 Carnegie Mellon University
31 * All Rights Reserved.
32 *
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
38 *
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53 /*
54 */
55 /*
56 * Author: David B. Golub, Carnegie Mellon University
57 * Date: 7/90
58 */
59 #include <mach/boolean.h>
60 #include <machine/db_machdep.h> /* type definitions */
61 #include <machine/setjmp.h>
62 #include <machine/endian.h>
63 #include <kern/task.h>
64 #include <ddb/db_access.h>
65
66
67
68 /*
69 * Access unaligned data items on aligned (longword)
70 * boundaries.
71 */
72
73 int db_access_level = DB_ACCESS_LEVEL;
74
75 db_expr_t
76 db_get_task_value(
77 db_addr_t addr,
78 register int size,
79 boolean_t is_signed,
80 task_t task)
81 {
82 char data[sizeof(db_expr_t)];
83 register db_expr_t value;
84 register int i;
85 uint64_t signx;
86
87 if(size == 0) return 0;
88
89 db_read_bytes((vm_offset_t)addr, size, data, task);
90
91 value = 0;
92 #if BYTE_MSF
93 for (i = 0; i < size; i++)
94 #else /* BYTE_LSF */
95 for (i = size - 1; i >= 0; i--)
96 #endif
97 {
98 value = (value << 8) + (data[i] & 0xFF);
99 }
100
101 if(!is_signed) return value;
102
103 signx = 0xFFFFFFFFFFFFFFFFULL << ((size << 3) - 1);
104
105 if(value & signx) value |= signx; /* Add 1s to front if sign bit is on */
106
107 return (value);
108 }
109
110 void
111 db_put_task_value(
112 db_addr_t addr,
113 register int size,
114 register db_expr_t value,
115 task_t task)
116 {
117 char data[sizeof(db_expr_t)];
118 register int i;
119
120 #if BYTE_MSF
121 for (i = size - 1; i >= 0; i--)
122 #else /* BYTE_LSF */
123 for (i = 0; i < size; i++)
124 #endif
125 {
126 data[i] = value & 0xFF;
127 value >>= 8;
128 }
129
130 db_write_bytes((vm_offset_t)addr, size, data, task);
131 }
132
133 db_expr_t
134 db_get_value(
135 db_addr_t addr,
136 int size,
137 boolean_t is_signed)
138 {
139 return(db_get_task_value(addr, size, is_signed, TASK_NULL));
140 }
141
142 void
143 db_put_value(
144 db_addr_t addr,
145 int size,
146 db_expr_t value)
147 {
148 db_put_task_value(addr, size, value, TASK_NULL);
149 }