]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/vm_param.h
xnu-517.tar.gz
[apple/xnu.git] / osfmk / mach / vm_param.h
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,1989,1988,1987 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 * File: mach/vm_param.h
57 * Author: Avadis Tevanian, Jr., Michael Wayne Young
58 * Date: 1985
59 *
60 * Machine independent virtual memory parameters.
61 *
62 */
63
64 #ifndef _MACH_VM_PARAM_H_
65 #define _MACH_VM_PARAM_H_
66
67 #ifndef KERNEL_PRIVATE
68
69 #error YOU HAVE MADE A MISTAKE BY INCLUDING THIS FILE;
70 #error
71 #error THIS FILE SHOULD NOT BE VISIBLE TO USER PROGRAMS.
72 #error
73 #error USE <mach/machine/vm_param.h> TO GET MACHINE-DEPENDENT ADDRESS
74 #error SPACE AND PAGE SIZE ITEMS.
75 #error
76 #error USE <mach/machine/vm_types.h> TO GET TYPE DECLARATIONS USED IN
77 #error THE MACH KERNEL INTERFACE.
78 #error
79 #error IN ALL PROBABILITY, YOU SHOULD GET ALL OF THE TYPES USED IN THE
80 #error INTERFACE FROM <mach/mach_types.h>
81
82 #endif /* KERNEL_PRIVATE */
83
84 #include <mach/machine/vm_param.h>
85
86 #ifndef ASSEMBLER
87 #include <mach/vm_types.h>
88 #endif /* ASSEMBLER */
89
90 /*
91 * The machine independent pages are refered to as PAGES. A page
92 * is some number of hardware pages, depending on the target machine.
93 */
94
95 /*
96 * All references to the size of a page should be done with PAGE_SIZE
97 * or PAGE_SHIFT. The fact they are variables is hidden here so that
98 * we can easily make them constant if we so desire.
99 */
100
101 /*
102 * Regardless whether it is implemented with a constant or a variable,
103 * the PAGE_SIZE is assumed to be a power of two throughout the
104 * virtual memory system implementation.
105 */
106
107 #ifdef PAGE_SIZE_FIXED
108 #define PAGE_SIZE 4096
109 #define PAGE_SHIFT 12
110 #define PAGE_MASK (PAGE_SIZE-1)
111 #endif /* PAGE_SIZE_FIXED */
112
113 #ifndef ASSEMBLER
114
115 extern vm_size_t page_size;
116 extern vm_size_t page_mask;
117 extern int page_shift;
118
119 #ifndef PAGE_SIZE_FIXED
120 #define PAGE_SIZE page_size /* pagesize in addr units */
121 #define PAGE_SHIFT page_shift /* number of bits to shift for pages */
122 #define PAGE_MASK page_mask /* mask for off in page */
123
124 #define PAGE_SIZE_64 (unsigned long long)page_size /* pagesize in addr units */
125 #define PAGE_MASK_64 (unsigned long long)page_mask /* mask for off in page */
126 #else /* PAGE_SIZE_FIXED */
127
128 #define PAGE_SIZE_64 (unsigned long long)4096
129 #define PAGE_MASK_64 (PAGE_SIZE_64-1)
130 #endif /* PAGE_SIZE_FIXED */
131
132 /*
133 * Convert addresses to pages and vice versa. No rounding is used.
134 * The atop_32 and ptoa_32 macros should not be use on 64 bit types.
135 * The round_page_64 and trunc_page_64 macros should be used instead.
136 */
137
138 #define atop_32(x) ((uint32_t)(x) >> PAGE_SHIFT)
139 #define ptoa_32(x) ((uint32_t)(x) << PAGE_SHIFT)
140 #define atop_64(x) ((uint64_t)(x) >> PAGE_SHIFT)
141 #define ptoa_64(x) ((uint64_t)(x) << PAGE_SHIFT)
142
143 /*
144 * While the following block is enabled, the legacy atop and ptoa
145 * macros will behave correctly. If not, they will generate
146 * invalid lvalue errors.
147 */
148
149 #if 1
150 #define atop(x) ((uint32_t)(x) >> PAGE_SHIFT)
151 #define ptoa(x) ((uint32_t)(x) << PAGE_SHIFT)
152 #else
153 #define atop(x) (0UL = 0)
154 #define ptoa(x) (0UL = 0)
155 #endif
156
157
158 /*
159 * Round off or truncate to the nearest page. These will work
160 * for either addresses or counts. (i.e. 1 byte rounds to 1 page
161 * bytes. The round_page_32 and trunc_page_32 macros should not be
162 * use on 64 bit types. The round_page_64 and trunc_page_64 macros
163 * should be used instead.
164 */
165
166 #define round_page_32(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
167 #define trunc_page_32(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
168 #define round_page_64(x) (((uint64_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
169 #define trunc_page_64(x) ((uint64_t)(x) & ~((signed)PAGE_MASK))
170
171
172 /*
173 * While the following block is enabled, the legacy round_page
174 * and trunc_page macros will behave correctly. If not, they will
175 * generate invalid lvalue errors.
176 */
177
178 #if 1
179 #define round_page(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
180 #define trunc_page(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
181 #else
182 #define round_page(x) (0UL = 0)
183 #define trunc_page(x) (0UL = 0)
184 #endif
185
186 /*
187 * Enable the following block to find uses of xxx_32 macros that should
188 * be xxx_64. These macros only work in C code, not C++. The resulting
189 * binaries are not functional. Look for invalid lvalue errors in
190 * the compiler output.
191 *
192 * Enabling the following block will also find use of the xxx_64 macros
193 * that have been passed pointers. The parameters should be case to an
194 * unsigned long type first. Look for invalid operands to binary + error
195 * in the compiler output.
196 */
197
198 #if 0
199 #undef atop_32
200 #undef ptoa_32
201 #undef round_page_32
202 #undef trunc_page_32
203 #undef atop_64
204 #undef ptoa_64
205 #undef round_page_64
206 #undef trunc_page_64
207
208 #ifndef __cplusplus
209
210 #define atop_32(x) \
211 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
212 (*(long *)0), \
213 (0UL)) = 0)
214
215 #define ptoa_32(x) \
216 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
217 (*(long *)0), \
218 (0UL)) = 0)
219
220 #define round_page_32(x) \
221 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
222 (*(long *)0), \
223 (0UL)) = 0)
224
225 #define trunc_page_32(x) \
226 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
227 (*(long *)0), \
228 (0UL)) = 0)
229 #else
230
231 #define atop_32(x) (0)
232 #define ptoa_32(x) (0)
233 #define round_page_32(x) (0)
234 #define trunc_page_32(x) (0)
235
236 #endif /* ! __cplusplus */
237
238 #define atop_64(x) ((uint64_t)((x) + (uint8_t *)0))
239 #define ptoa_64(x) ((uint64_t)((x) + (uint8_t *)0))
240 #define round_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
241 #define trunc_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
242
243 #endif
244
245 /*
246 * Determine whether an address is page-aligned, or a count is
247 * an exact page multiple.
248 */
249
250 #define page_aligned(x) ((((vm_object_offset_t) (x)) & PAGE_MASK) == 0)
251
252 extern vm_size_t mem_size; /* 32-bit size of memory - limited by maxmem - deprecated */
253 extern uint64_t max_mem; /* 64-bit size of memory - limited by maxmem */
254 extern uint64_t mem_actual; /* 64-bit size of memory - not limited by maxmem */
255 extern uint64_t sane_size; /* Memory size to use for defaults calculations */
256 extern addr64_t vm_last_addr; /* Highest kernel virtual address known to the VM system */
257
258 /* We need a way to get rid of compiler warnings when we cast from */
259 /* a 64 bit value to an address that is 32 bits. */
260 /* We know at this point the cast is harmless but sometime in */
261 /* the future it may not be. */
262 /* When size of an int is no longer equal to size of uintptr_t then */
263 /* the compile will fail and we know we need to fix our cast. */
264 #include <stdint.h>
265 #ifndef __CAST_DOWN_CHECK
266 #define __CAST_DOWN_CHECK
267 typedef char __NEED_TO_CHANGE_CAST_DOWN[ sizeof(uintptr_t) == sizeof(int) ? 0 : -1 ];
268 #define CAST_DOWN( type, addr ) ( ((type)((uintptr_t) (addr))) )
269 #endif /* __CAST_DOWN_CHECK */
270
271 #endif /* ASSEMBLER */
272 #endif /* _MACH_VM_PARAM_H_ */