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>
87 #include <mach/vm_types.h>
88 #endif /* ASSEMBLER */
91 * The machine independent pages are refered to as PAGES. A page
92 * is some number of hardware pages, depending on the target machine.
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.
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.
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 */
115 extern vm_size_t page_size
;
116 extern vm_size_t page_mask
;
117 extern int page_shift
;
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 */
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 */
128 #define PAGE_SIZE_64 (unsigned long long)4096
129 #define PAGE_MASK_64 (PAGE_SIZE_64-1)
130 #endif /* PAGE_SIZE_FIXED */
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.
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)
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.
150 #define atop(x) ((uint32_t)(x) >> PAGE_SHIFT)
151 #define ptoa(x) ((uint32_t)(x) << PAGE_SHIFT)
153 #define atop(x) (0UL = 0)
154 #define ptoa(x) (0UL = 0)
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.
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))
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.
179 #define round_page(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
180 #define trunc_page(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
182 #define round_page(x) (0UL = 0)
183 #define trunc_page(x) (0UL = 0)
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.
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.
211 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
216 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
220 #define round_page_32(x) \
221 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
225 #define trunc_page_32(x) \
226 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
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)
236 #endif /* ! __cplusplus */
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))
246 * Determine whether an address is page-aligned, or a count is
247 * an exact page multiple.
250 #define page_aligned(x) ((((vm_object_offset_t) (x)) & PAGE_MASK) == 0)
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 */
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. */
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 */
271 #endif /* ASSEMBLER */
272 #endif /* _MACH_VM_PARAM_H_ */