2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
53 * File: mach/vm_param.h
54 * Author: Avadis Tevanian, Jr., Michael Wayne Young
57 * Machine independent virtual memory parameters.
61 #ifndef _MACH_VM_PARAM_H_
62 #define _MACH_VM_PARAM_H_
64 #ifndef KERNEL_PRIVATE
66 #error YOU HAVE MADE A MISTAKE BY INCLUDING THIS FILE;
68 #error THIS FILE SHOULD NOT BE VISIBLE TO USER PROGRAMS.
70 #error USE <mach/machine/vm_param.h> TO GET MACHINE-DEPENDENT ADDRESS
71 #error SPACE AND PAGE SIZE ITEMS.
73 #error USE <mach/machine/vm_types.h> TO GET TYPE DECLARATIONS USED IN
74 #error THE MACH KERNEL INTERFACE.
76 #error IN ALL PROBABILITY, YOU SHOULD GET ALL OF THE TYPES USED IN THE
77 #error INTERFACE FROM <mach/mach_types.h>
79 #endif /* KERNEL_PRIVATE */
81 #include <mach/machine/vm_param.h>
84 #include <mach/vm_types.h>
85 #endif /* ASSEMBLER */
88 * The machine independent pages are refered to as PAGES. A page
89 * is some number of hardware pages, depending on the target machine.
93 * All references to the size of a page should be done with PAGE_SIZE
94 * or PAGE_SHIFT. The fact they are variables is hidden here so that
95 * we can easily make them constant if we so desire.
99 * Regardless whether it is implemented with a constant or a variable,
100 * the PAGE_SIZE is assumed to be a power of two throughout the
101 * virtual memory system implementation.
104 #ifdef PAGE_SIZE_FIXED
105 #define PAGE_SIZE 4096
106 #define PAGE_SHIFT 12
107 #define PAGE_MASK (PAGE_SIZE-1)
108 #endif /* PAGE_SIZE_FIXED */
112 extern vm_size_t page_size
;
113 extern vm_size_t page_mask
;
114 extern int page_shift
;
116 #ifndef PAGE_SIZE_FIXED
117 #define PAGE_SIZE page_size /* pagesize in addr units */
118 #define PAGE_SHIFT page_shift /* number of bits to shift for pages */
119 #define PAGE_MASK page_mask /* mask for off in page */
121 #define PAGE_SIZE_64 (unsigned long long)page_size /* pagesize in addr units */
122 #define PAGE_MASK_64 (unsigned long long)page_mask /* mask for off in page */
123 #else /* PAGE_SIZE_FIXED */
125 #define PAGE_SIZE_64 (unsigned long long)4096
126 #define PAGE_MASK_64 (PAGE_SIZE_64-1)
127 #endif /* PAGE_SIZE_FIXED */
130 * Convert addresses to pages and vice versa. No rounding is used.
131 * The atop_32 and ptoa_32 macros should not be use on 64 bit types.
132 * The round_page_64 and trunc_page_64 macros should be used instead.
135 #define atop_32(x) ((uint32_t)(x) >> PAGE_SHIFT)
136 #define ptoa_32(x) ((uint32_t)(x) << PAGE_SHIFT)
137 #define atop_64(x) ((uint64_t)(x) >> PAGE_SHIFT)
138 #define ptoa_64(x) ((uint64_t)(x) << PAGE_SHIFT)
141 * While the following block is enabled, the legacy atop and ptoa
142 * macros will behave correctly. If not, they will generate
143 * invalid lvalue errors.
147 #define atop(x) ((uint32_t)(x) >> PAGE_SHIFT)
148 #define ptoa(x) ((uint32_t)(x) << PAGE_SHIFT)
150 #define atop(x) (0UL = 0)
151 #define ptoa(x) (0UL = 0)
156 * Round off or truncate to the nearest page. These will work
157 * for either addresses or counts. (i.e. 1 byte rounds to 1 page
158 * bytes. The round_page_32 and trunc_page_32 macros should not be
159 * use on 64 bit types. The round_page_64 and trunc_page_64 macros
160 * should be used instead.
163 #define round_page_32(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
164 #define trunc_page_32(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
165 #define round_page_64(x) (((uint64_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
166 #define trunc_page_64(x) ((uint64_t)(x) & ~((signed)PAGE_MASK))
170 * While the following block is enabled, the legacy round_page
171 * and trunc_page macros will behave correctly. If not, they will
172 * generate invalid lvalue errors.
176 #define round_page(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
177 #define trunc_page(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
179 #define round_page(x) (0UL = 0)
180 #define trunc_page(x) (0UL = 0)
184 * Enable the following block to find uses of xxx_32 macros that should
185 * be xxx_64. These macros only work in C code, not C++. The resulting
186 * binaries are not functional. Look for invalid lvalue errors in
187 * the compiler output.
189 * Enabling the following block will also find use of the xxx_64 macros
190 * that have been passed pointers. The parameters should be case to an
191 * unsigned long type first. Look for invalid operands to binary + error
192 * in the compiler output.
208 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
213 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
217 #define round_page_32(x) \
218 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
222 #define trunc_page_32(x) \
223 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
228 #define atop_32(x) (0)
229 #define ptoa_32(x) (0)
230 #define round_page_32(x) (0)
231 #define trunc_page_32(x) (0)
233 #endif /* ! __cplusplus */
235 #define atop_64(x) ((uint64_t)((x) + (uint8_t *)0))
236 #define ptoa_64(x) ((uint64_t)((x) + (uint8_t *)0))
237 #define round_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
238 #define trunc_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
243 * Determine whether an address is page-aligned, or a count is
244 * an exact page multiple.
247 #define page_aligned(x) ((((vm_object_offset_t) (x)) & PAGE_MASK) == 0)
249 extern vm_size_t mem_size
; /* 32-bit size of memory - limited by maxmem - deprecated */
250 extern uint64_t max_mem
; /* 64-bit size of memory - limited by maxmem */
251 extern uint64_t mem_actual
; /* 64-bit size of memory - not limited by maxmem */
252 extern uint64_t sane_size
; /* Memory size to use for defaults calculations */
253 extern addr64_t vm_last_addr
; /* Highest kernel virtual address known to the VM system */
255 /* We need a way to get rid of compiler warnings when we cast from */
256 /* a 64 bit value to an address that is 32 bits. */
257 /* We know at this point the cast is harmless but sometime in */
258 /* the future it may not be. */
259 /* When size of an int is no longer equal to size of uintptr_t then */
260 /* the compile will fail and we know we need to fix our cast. */
262 #ifndef __CAST_DOWN_CHECK
263 #define __CAST_DOWN_CHECK
264 typedef char __NEED_TO_CHANGE_CAST_DOWN
[ sizeof(uintptr_t) == sizeof(int) ? 0 : -1 ];
265 #define CAST_DOWN( type, addr ) ( ((type)((uintptr_t) (addr))) )
266 #endif /* __CAST_DOWN_CHECK */
268 #endif /* ASSEMBLER */
269 #endif /* _MACH_VM_PARAM_H_ */