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