]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/vm_param.h
e4511b2a96f09484a9060003a976d1132c9e009c
[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 #include <mach/vm_types.h>
87
88 /*
89 * The machine independent pages are refered to as PAGES. A page
90 * is some number of hardware pages, depending on the target machine.
91 */
92
93 /*
94 * All references to the size of a page should be done with PAGE_SIZE
95 * or PAGE_SHIFT. The fact they are variables is hidden here so that
96 * we can easily make them constant if we so desire.
97 */
98
99 /*
100 * Regardless whether it is implemented with a constant or a variable,
101 * the PAGE_SIZE is assumed to be a power of two throughout the
102 * virtual memory system implementation.
103 */
104
105 #ifndef PAGE_SIZE_FIXED
106 extern vm_size_t page_size;
107 extern vm_size_t page_mask;
108 extern int page_shift;
109
110 #define PAGE_SIZE page_size /* pagesize in addr units */
111 #define PAGE_SHIFT page_shift /* number of bits to shift for pages */
112 #define PAGE_MASK page_mask /* mask for off in page */
113
114 #define PAGE_SIZE_64 (unsigned long long)page_size /* pagesize in addr units */
115 #define PAGE_MASK_64 (unsigned long long)page_mask /* mask for off in page */
116 #else /* PAGE_SIZE_FIXED */
117 #define PAGE_SIZE 4096
118 #define PAGE_SHIFT 12
119 #define PAGE_MASK (PAGE_SIZE-1)
120 #define PAGE_SIZE_64 (unsigned long long)4096
121 #define PAGE_MASK_64 (PAGE_SIZE_64-1)
122 #endif /* PAGE_SIZE_FIXED */
123
124 #ifndef ASSEMBLER
125
126 /*
127 * Convert addresses to pages and vice versa. No rounding is used.
128 * The atop_32 and ptoa_32 macros should not be use on 64 bit types.
129 * The round_page_64 and trunc_page_64 macros should be used instead.
130 */
131
132 #define atop_32(x) ((uint32_t)(x) >> PAGE_SHIFT)
133 #define ptoa_32(x) ((uint32_t)(x) << PAGE_SHIFT)
134 #define atop_64(x) ((uint64_t)(x) >> PAGE_SHIFT)
135 #define ptoa_64(x) ((uint64_t)(x) << PAGE_SHIFT)
136
137 /*
138 * While the following block is enabled, the legacy atop and ptoa
139 * macros will behave correctly. If not, they will generate
140 * invalid lvalue errors.
141 */
142
143 #if 1
144 #define atop(x) ((uint32_t)(x) >> PAGE_SHIFT)
145 #define ptoa(x) ((uint32_t)(x) << PAGE_SHIFT)
146 #else
147 #define atop(x) (0UL = 0)
148 #define ptoa(x) (0UL = 0)
149 #endif
150
151
152 /*
153 * Round off or truncate to the nearest page. These will work
154 * for either addresses or counts. (i.e. 1 byte rounds to 1 page
155 * bytes. The round_page_32 and trunc_page_32 macros should not be
156 * use on 64 bit types. The round_page_64 and trunc_page_64 macros
157 * should be used instead.
158 */
159
160 #define round_page_32(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
161 #define trunc_page_32(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
162 #define round_page_64(x) (((uint64_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
163 #define trunc_page_64(x) ((uint64_t)(x) & ~((signed)PAGE_MASK))
164
165
166 /*
167 * While the following block is enabled, the legacy round_page
168 * and trunc_page macros will behave correctly. If not, they will
169 * generate invalid lvalue errors.
170 */
171
172 #if 1
173 #define round_page(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
174 #define trunc_page(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
175 #else
176 #define round_page(x) (0UL = 0)
177 #define trunc_page(x) (0UL = 0)
178 #endif
179
180 /*
181 * Enable the following block to find uses of xxx_32 macros that should
182 * be xxx_64. These macros only work in C code, not C++. The resulting
183 * binaries are not functional. Look for invalid lvalue errors in
184 * the compiler output.
185 *
186 * Enabling the following block will also find use of the xxx_64 macros
187 * that have been passed pointers. The parameters should be case to an
188 * unsigned long type first. Look for invalid operands to binary + error
189 * in the compiler output.
190 */
191
192 #if 0
193 #undef atop_32
194 #undef ptoa_32
195 #undef round_page_32
196 #undef trunc_page_32
197 #undef atop_64
198 #undef ptoa_64
199 #undef round_page_64
200 #undef trunc_page_64
201
202 #ifndef __cplusplus
203
204 #define atop_32(x) \
205 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
206 (*(long *)0), \
207 (0UL)) = 0)
208
209 #define ptoa_32(x) \
210 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
211 (*(long *)0), \
212 (0UL)) = 0)
213
214 #define round_page_32(x) \
215 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
216 (*(long *)0), \
217 (0UL)) = 0)
218
219 #define trunc_page_32(x) \
220 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
221 (*(long *)0), \
222 (0UL)) = 0)
223 #else
224
225 #define atop_32(x) (0)
226 #define ptoa_32(x) (0)
227 #define round_page_32(x) (0)
228 #define trunc_page_32(x) (0)
229
230 #endif /* ! __cplusplus */
231
232 #define atop_64(x) ((uint64_t)((x) + (uint8_t *)0))
233 #define ptoa_64(x) ((uint64_t)((x) + (uint8_t *)0))
234 #define round_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
235 #define trunc_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
236
237 #endif
238
239 /*
240 * Determine whether an address is page-aligned, or a count is
241 * an exact page multiple.
242 */
243
244 #define page_aligned(x) ((((vm_object_offset_t) (x)) & PAGE_MASK) == 0)
245
246 extern vm_size_t mem_size; /* size of physical memory (bytes) */
247 extern uint64_t max_mem; /* 64-bit size of memory - limited by maxmem */
248
249 #endif /* ASSEMBLER */
250 #endif /* _MACH_VM_PARAM_H_ */