2 * Copyright (c) 2000-2004 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 #include <mach/machine/vm_param.h>
69 #include <mach/vm_types.h>
70 #endif /* ASSEMBLER */
73 * The machine independent pages are refered to as PAGES. A page
74 * is some number of hardware pages, depending on the target machine.
79 #define PAGE_SIZE_64 (unsigned long long)PAGE_SIZE /* pagesize in addr units */
80 #define PAGE_MASK_64 (unsigned long long)PAGE_MASK /* mask for off in page */
83 * Convert addresses to pages and vice versa. No rounding is used.
84 * The atop_32 and ptoa_32 macros should not be use on 64 bit types.
85 * The round_page_64 and trunc_page_64 macros should be used instead.
88 #define atop_32(x) ((uint32_t)(x) >> PAGE_SHIFT)
89 #define ptoa_32(x) ((uint32_t)(x) << PAGE_SHIFT)
90 #define atop_64(x) ((uint64_t)(x) >> PAGE_SHIFT)
91 #define ptoa_64(x) ((uint64_t)(x) << PAGE_SHIFT)
94 * While the following block is enabled, the legacy atop and ptoa
95 * macros will behave correctly. If not, they will generate
96 * invalid lvalue errors.
100 #define atop(x) ((uint32_t)(x) >> PAGE_SHIFT)
101 #define ptoa(x) ((uint32_t)(x) << PAGE_SHIFT)
103 #define atop(x) (0UL = 0)
104 #define ptoa(x) (0UL = 0)
108 * Page-size rounding macros for the Public fixed-width VM types.
110 #define mach_vm_round_page(x) (((mach_vm_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
111 #define mach_vm_trunc_page(x) ((mach_vm_offset_t)(x) & ~((signed)PAGE_MASK))
113 #define memory_object_round_page(x) (((memory_object_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
114 #define memory_object_trunc_page(x) ((memory_object_offset_t)(x) & ~((signed)PAGE_MASK))
117 * Rounding macros for the legacy (scalable with the current task's
118 * address space size) VM types.
121 #define round_page(x) (((vm_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
122 #define trunc_page(x) ((vm_offset_t)(x) & ~((signed)PAGE_MASK))
125 * Round off or truncate to the nearest page. These will work
126 * for either addresses or counts. (i.e. 1 byte rounds to 1 page
127 * bytes. The round_page_32 and trunc_page_32 macros should not be
128 * use on 64 bit types. The round_page_64 and trunc_page_64 macros
129 * should be used instead.
131 * These should only be used in the rare case the size of the address
132 * or length is hard-coded as 32 or 64 bit. Otherwise, the macros
133 * associated with the specific VM type should be used.
136 #define round_page_32(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
137 #define trunc_page_32(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
138 #define round_page_64(x) (((uint64_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
139 #define trunc_page_64(x) ((uint64_t)(x) & ~((signed)PAGE_MASK))
143 * Enable the following block to find uses of xxx_32 macros that should
144 * be xxx_64. These macros only work in C code, not C++. The resulting
145 * binaries are not functional. Look for invalid lvalue errors in
146 * the compiler output.
148 * Enabling the following block will also find use of the xxx_64 macros
149 * that have been passed pointers. The parameters should be case to an
150 * unsigned long type first. Look for invalid operands to binary + error
151 * in the compiler output.
167 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
172 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
176 #define round_page_32(x) \
177 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
181 #define trunc_page_32(x) \
182 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
187 #define atop_32(x) (0)
188 #define ptoa_32(x) (0)
189 #define round_page_32(x) (0)
190 #define trunc_page_32(x) (0)
192 #endif /* ! __cplusplus */
194 #define atop_64(x) ((uint64_t)((x) + (uint8_t *)0))
195 #define ptoa_64(x) ((uint64_t)((x) + (uint8_t *)0))
196 #define round_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
197 #define trunc_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
202 * Determine whether an address is page-aligned, or a count is
203 * an exact page multiple.
206 #define page_aligned(x) ((((vm_object_offset_t) (x)) & PAGE_MASK) == 0)
208 extern vm_size_t mem_size
; /* 32-bit size of memory - limited by maxmem - deprecated */
209 extern uint64_t max_mem
; /* 64-bit size of memory - limited by maxmem */
211 #ifdef XNU_KERNEL_PRIVATE
213 extern uint64_t mem_actual
; /* 64-bit size of memory - not limited by maxmem */
214 extern uint64_t sane_size
; /* Memory size to use for defaults calculations */
215 extern addr64_t vm_last_addr
; /* Highest kernel virtual address known to the VM system */
217 #endif /* XNU_KERNEL_PRIVATE */
219 extern vm_size_t page_size
;
220 extern vm_size_t page_mask
;
221 extern int page_shift
;
223 /* We need a way to get rid of compiler warnings when we cast from */
224 /* a 64 bit value to an address that is 32 bits. */
225 /* We know at this point the cast is harmless but sometime in */
226 /* the future it may not be. */
227 /* When size of an int is no longer equal to size of uintptr_t then */
228 /* the compile will fail and we know we need to fix our cast. */
230 #ifndef __CAST_DOWN_CHECK
231 #define __CAST_DOWN_CHECK
232 typedef char __NEED_TO_CHANGE_CAST_DOWN
[ sizeof(uintptr_t) == sizeof(int) ? 0 : -1 ];
233 #define CAST_DOWN( type, addr ) ( ((type)((uintptr_t) (addr))) )
234 #endif /* __CAST_DOWN_CHECK */
236 #endif /* ASSEMBLER */
240 #endif /* _MACH_VM_PARAM_H_ */