]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
1c79356b | 5 | * |
8ad349bb A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the | |
10 | * License may not be used to create, or enable the creation or | |
11 | * redistribution of, unlawful or unlicensed copies of an Apple operating | |
12 | * system, or to circumvent, violate, or enable the circumvention or | |
13 | * violation of, any terms of an Apple operating system software license | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
20 | * The Original Code and all software distributed under the License are | |
21 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
22 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
23 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
24 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
25 | * Please see the License for the specific language governing rights and | |
26 | * limitations under the License. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
1c79356b A |
29 | */ |
30 | /* | |
31 | * @OSF_COPYRIGHT@ | |
32 | */ | |
33 | /* | |
34 | * Mach Operating System | |
35 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University | |
36 | * All Rights Reserved. | |
37 | * | |
38 | * Permission to use, copy, modify and distribute this software and its | |
39 | * documentation is hereby granted, provided that both the copyright | |
40 | * notice and this permission notice appear in all copies of the | |
41 | * software, derivative works or modified versions, and any portions | |
42 | * thereof, and that both notices appear in supporting documentation. | |
43 | * | |
44 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
45 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
46 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
47 | * | |
48 | * Carnegie Mellon requests users of this software to return to | |
49 | * | |
50 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
51 | * School of Computer Science | |
52 | * Carnegie Mellon University | |
53 | * Pittsburgh PA 15213-3890 | |
54 | * | |
55 | * any improvements or extensions that they make and grant Carnegie Mellon | |
56 | * the rights to redistribute these changes. | |
57 | */ | |
58 | /* | |
59 | */ | |
60 | /* | |
61 | * File: mach/vm_param.h | |
62 | * Author: Avadis Tevanian, Jr., Michael Wayne Young | |
63 | * Date: 1985 | |
64 | * | |
65 | * Machine independent virtual memory parameters. | |
66 | * | |
67 | */ | |
68 | ||
69 | #ifndef _MACH_VM_PARAM_H_ | |
70 | #define _MACH_VM_PARAM_H_ | |
71 | ||
1c79356b | 72 | #include <mach/machine/vm_param.h> |
90556fb8 | 73 | |
91447636 A |
74 | #ifdef KERNEL |
75 | ||
55e303ae | 76 | #ifndef ASSEMBLER |
90556fb8 | 77 | #include <mach/vm_types.h> |
55e303ae | 78 | #endif /* ASSEMBLER */ |
1c79356b A |
79 | |
80 | /* | |
81 | * The machine independent pages are refered to as PAGES. A page | |
82 | * is some number of hardware pages, depending on the target machine. | |
83 | */ | |
84 | ||
55e303ae A |
85 | #ifndef ASSEMBLER |
86 | ||
91447636 A |
87 | #define PAGE_SIZE_64 (unsigned long long)PAGE_SIZE /* pagesize in addr units */ |
88 | #define PAGE_MASK_64 (unsigned long long)PAGE_MASK /* mask for off in page */ | |
1c79356b | 89 | |
90556fb8 A |
90 | /* |
91 | * Convert addresses to pages and vice versa. No rounding is used. | |
92 | * The atop_32 and ptoa_32 macros should not be use on 64 bit types. | |
93 | * The round_page_64 and trunc_page_64 macros should be used instead. | |
94 | */ | |
95 | ||
96 | #define atop_32(x) ((uint32_t)(x) >> PAGE_SHIFT) | |
97 | #define ptoa_32(x) ((uint32_t)(x) << PAGE_SHIFT) | |
98 | #define atop_64(x) ((uint64_t)(x) >> PAGE_SHIFT) | |
99 | #define ptoa_64(x) ((uint64_t)(x) << PAGE_SHIFT) | |
100 | ||
1c79356b | 101 | /* |
90556fb8 A |
102 | * While the following block is enabled, the legacy atop and ptoa |
103 | * macros will behave correctly. If not, they will generate | |
104 | * invalid lvalue errors. | |
d7e50217 A |
105 | */ |
106 | ||
90556fb8 A |
107 | #if 1 |
108 | #define atop(x) ((uint32_t)(x) >> PAGE_SHIFT) | |
109 | #define ptoa(x) ((uint32_t)(x) << PAGE_SHIFT) | |
110 | #else | |
111 | #define atop(x) (0UL = 0) | |
112 | #define ptoa(x) (0UL = 0) | |
113 | #endif | |
114 | ||
91447636 A |
115 | /* |
116 | * Page-size rounding macros for the Public fixed-width VM types. | |
117 | */ | |
118 | #define mach_vm_round_page(x) (((mach_vm_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK)) | |
119 | #define mach_vm_trunc_page(x) ((mach_vm_offset_t)(x) & ~((signed)PAGE_MASK)) | |
120 | ||
121 | #define memory_object_round_page(x) (((memory_object_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK)) | |
122 | #define memory_object_trunc_page(x) ((memory_object_offset_t)(x) & ~((signed)PAGE_MASK)) | |
123 | ||
124 | /* | |
125 | * Rounding macros for the legacy (scalable with the current task's | |
126 | * address space size) VM types. | |
127 | */ | |
128 | ||
129 | #define round_page(x) (((vm_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK)) | |
130 | #define trunc_page(x) ((vm_offset_t)(x) & ~((signed)PAGE_MASK)) | |
1c79356b A |
131 | |
132 | /* | |
133 | * Round off or truncate to the nearest page. These will work | |
134 | * for either addresses or counts. (i.e. 1 byte rounds to 1 page | |
90556fb8 A |
135 | * bytes. The round_page_32 and trunc_page_32 macros should not be |
136 | * use on 64 bit types. The round_page_64 and trunc_page_64 macros | |
137 | * should be used instead. | |
91447636 A |
138 | * |
139 | * These should only be used in the rare case the size of the address | |
140 | * or length is hard-coded as 32 or 64 bit. Otherwise, the macros | |
141 | * associated with the specific VM type should be used. | |
90556fb8 A |
142 | */ |
143 | ||
144 | #define round_page_32(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK)) | |
145 | #define trunc_page_32(x) ((uint32_t)(x) & ~((signed)PAGE_MASK)) | |
146 | #define round_page_64(x) (((uint64_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK)) | |
147 | #define trunc_page_64(x) ((uint64_t)(x) & ~((signed)PAGE_MASK)) | |
148 | ||
149 | ||
90556fb8 A |
150 | /* |
151 | * Enable the following block to find uses of xxx_32 macros that should | |
152 | * be xxx_64. These macros only work in C code, not C++. The resulting | |
153 | * binaries are not functional. Look for invalid lvalue errors in | |
154 | * the compiler output. | |
155 | * | |
156 | * Enabling the following block will also find use of the xxx_64 macros | |
157 | * that have been passed pointers. The parameters should be case to an | |
158 | * unsigned long type first. Look for invalid operands to binary + error | |
159 | * in the compiler output. | |
160 | */ | |
1c79356b | 161 | |
90556fb8 A |
162 | #if 0 |
163 | #undef atop_32 | |
164 | #undef ptoa_32 | |
165 | #undef round_page_32 | |
166 | #undef trunc_page_32 | |
167 | #undef atop_64 | |
168 | #undef ptoa_64 | |
169 | #undef round_page_64 | |
170 | #undef trunc_page_64 | |
171 | ||
172 | #ifndef __cplusplus | |
173 | ||
174 | #define atop_32(x) \ | |
175 | (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \ | |
176 | (*(long *)0), \ | |
177 | (0UL)) = 0) | |
178 | ||
179 | #define ptoa_32(x) \ | |
180 | (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \ | |
181 | (*(long *)0), \ | |
182 | (0UL)) = 0) | |
183 | ||
184 | #define round_page_32(x) \ | |
185 | (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \ | |
186 | (*(long *)0), \ | |
187 | (0UL)) = 0) | |
188 | ||
189 | #define trunc_page_32(x) \ | |
190 | (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \ | |
191 | (*(long *)0), \ | |
192 | (0UL)) = 0) | |
193 | #else | |
194 | ||
195 | #define atop_32(x) (0) | |
196 | #define ptoa_32(x) (0) | |
197 | #define round_page_32(x) (0) | |
198 | #define trunc_page_32(x) (0) | |
199 | ||
200 | #endif /* ! __cplusplus */ | |
201 | ||
202 | #define atop_64(x) ((uint64_t)((x) + (uint8_t *)0)) | |
203 | #define ptoa_64(x) ((uint64_t)((x) + (uint8_t *)0)) | |
204 | #define round_page_64(x) ((uint64_t)((x) + (uint8_t *)0)) | |
205 | #define trunc_page_64(x) ((uint64_t)((x) + (uint8_t *)0)) | |
206 | ||
207 | #endif | |
1c79356b A |
208 | |
209 | /* | |
210 | * Determine whether an address is page-aligned, or a count is | |
211 | * an exact page multiple. | |
212 | */ | |
213 | ||
214 | #define page_aligned(x) ((((vm_object_offset_t) (x)) & PAGE_MASK) == 0) | |
215 | ||
55e303ae | 216 | extern vm_size_t mem_size; /* 32-bit size of memory - limited by maxmem - deprecated */ |
91447636 A |
217 | extern uint64_t max_mem; /* 64-bit size of memory - limited by maxmem */ |
218 | ||
219 | #ifdef XNU_KERNEL_PRIVATE | |
220 | ||
221 | extern uint64_t mem_actual; /* 64-bit size of memory - not limited by maxmem */ | |
222 | extern uint64_t sane_size; /* Memory size to use for defaults calculations */ | |
55e303ae A |
223 | extern addr64_t vm_last_addr; /* Highest kernel virtual address known to the VM system */ |
224 | ||
5d5c5d0d A |
225 | extern const vm_offset_t vm_min_kernel_address; |
226 | extern const vm_offset_t vm_max_kernel_address; | |
227 | ||
91447636 A |
228 | #endif /* XNU_KERNEL_PRIVATE */ |
229 | ||
230 | extern vm_size_t page_size; | |
231 | extern vm_size_t page_mask; | |
232 | extern int page_shift; | |
233 | ||
55e303ae A |
234 | /* We need a way to get rid of compiler warnings when we cast from */ |
235 | /* a 64 bit value to an address that is 32 bits. */ | |
236 | /* We know at this point the cast is harmless but sometime in */ | |
237 | /* the future it may not be. */ | |
238 | /* When size of an int is no longer equal to size of uintptr_t then */ | |
239 | /* the compile will fail and we know we need to fix our cast. */ | |
240 | #include <stdint.h> | |
241 | #ifndef __CAST_DOWN_CHECK | |
242 | #define __CAST_DOWN_CHECK | |
243 | typedef char __NEED_TO_CHANGE_CAST_DOWN[ sizeof(uintptr_t) == sizeof(int) ? 0 : -1 ]; | |
244 | #define CAST_DOWN( type, addr ) ( ((type)((uintptr_t) (addr))) ) | |
245 | #endif /* __CAST_DOWN_CHECK */ | |
1c79356b A |
246 | |
247 | #endif /* ASSEMBLER */ | |
91447636 A |
248 | |
249 | #endif /* KERNEL */ | |
250 | ||
1c79356b | 251 | #endif /* _MACH_VM_PARAM_H_ */ |