]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/vm_param.h
e4511b2a96f09484a9060003a976d1132c9e009c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
31 * All Rights Reserved.
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.
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.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
56 * File: mach/vm_param.h
57 * Author: Avadis Tevanian, Jr., Michael Wayne Young
60 * Machine independent virtual memory parameters.
64 #ifndef _MACH_VM_PARAM_H_
65 #define _MACH_VM_PARAM_H_
67 #ifndef KERNEL_PRIVATE
69 #error YOU HAVE MADE A MISTAKE BY INCLUDING THIS FILE;
71 #error THIS FILE SHOULD NOT BE VISIBLE TO USER PROGRAMS.
73 #error USE <mach/machine/vm_param.h> TO GET MACHINE-DEPENDENT ADDRESS
74 #error SPACE AND PAGE SIZE ITEMS.
76 #error USE <mach/machine/vm_types.h> TO GET TYPE DECLARATIONS USED IN
77 #error THE MACH KERNEL INTERFACE.
79 #error IN ALL PROBABILITY, YOU SHOULD GET ALL OF THE TYPES USED IN THE
80 #error INTERFACE FROM <mach/mach_types.h>
82 #endif /* KERNEL_PRIVATE */
84 #include <mach/machine/vm_param.h>
86 #include <mach/vm_types.h>
89 * The machine independent pages are refered to as PAGES. A page
90 * is some number of hardware pages, depending on the target machine.
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.
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.
105 #ifndef PAGE_SIZE_FIXED
106 extern vm_size_t page_size
;
107 extern vm_size_t page_mask
;
108 extern int page_shift
;
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 */
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 */
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.
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)
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.
144 #define atop(x) ((uint32_t)(x) >> PAGE_SHIFT)
145 #define ptoa(x) ((uint32_t)(x) << PAGE_SHIFT)
147 #define atop(x) (0UL = 0)
148 #define ptoa(x) (0UL = 0)
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.
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))
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.
173 #define round_page(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
174 #define trunc_page(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
176 #define round_page(x) (0UL = 0)
177 #define trunc_page(x) (0UL = 0)
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.
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.
205 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
210 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
214 #define round_page_32(x) \
215 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
219 #define trunc_page_32(x) \
220 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
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)
230 #endif /* ! __cplusplus */
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))
240 * Determine whether an address is page-aligned, or a count is
241 * an exact page multiple.
244 #define page_aligned(x) ((((vm_object_offset_t) (x)) & PAGE_MASK) == 0)
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 */
249 #endif /* ASSEMBLER */
250 #endif /* _MACH_VM_PARAM_H_ */