*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#endif /* KERNEL_PRIVATE */
#include <mach/machine/vm_param.h>
-
-#ifndef ASSEMBLER
-#include <mach/vm_types.h>
-#endif /* ASSEMBLER */
+#include <mach/machine/vm_types.h>
/*
* The machine independent pages are refered to as PAGES. A page
* virtual memory system implementation.
*/
-#ifdef PAGE_SIZE_FIXED
-#define PAGE_SIZE 4096
-#define PAGE_SHIFT 12
-#define PAGE_MASK (PAGE_SIZE-1)
-#endif /* PAGE_SIZE_FIXED */
-
-#ifndef ASSEMBLER
-
+#ifndef PAGE_SIZE_FIXED
extern vm_size_t page_size;
extern vm_size_t page_mask;
extern int page_shift;
-#ifndef PAGE_SIZE_FIXED
#define PAGE_SIZE page_size /* pagesize in addr units */
#define PAGE_SHIFT page_shift /* number of bits to shift for pages */
#define PAGE_MASK page_mask /* mask for off in page */
#define PAGE_SIZE_64 (unsigned long long)page_size /* pagesize in addr units */
#define PAGE_MASK_64 (unsigned long long)page_mask /* mask for off in page */
#else /* PAGE_SIZE_FIXED */
-
+#define PAGE_SIZE 4096
+#define PAGE_SHIFT 12
+#define PAGE_MASK (PAGE_SIZE-1)
#define PAGE_SIZE_64 (unsigned long long)4096
#define PAGE_MASK_64 (PAGE_SIZE_64-1)
#endif /* PAGE_SIZE_FIXED */
+#ifndef ASSEMBLER
/*
- * Convert addresses to pages and vice versa. No rounding is used.
- * The atop_32 and ptoa_32 macros should not be use on 64 bit types.
- * The round_page_64 and trunc_page_64 macros should be used instead.
- */
-
-#define atop_32(x) ((uint32_t)(x) >> PAGE_SHIFT)
-#define ptoa_32(x) ((uint32_t)(x) << PAGE_SHIFT)
-#define atop_64(x) ((uint64_t)(x) >> PAGE_SHIFT)
-#define ptoa_64(x) ((uint64_t)(x) << PAGE_SHIFT)
-
-/*
- * While the following block is enabled, the legacy atop and ptoa
- * macros will behave correctly. If not, they will generate
- * invalid lvalue errors.
+ * Convert addresses to pages and vice versa.
+ * No rounding is used.
*/
-#if 1
-#define atop(x) ((uint32_t)(x) >> PAGE_SHIFT)
-#define ptoa(x) ((uint32_t)(x) << PAGE_SHIFT)
-#else
-#define atop(x) (0UL = 0)
-#define ptoa(x) (0UL = 0)
-#endif
-
+#define atop(x) (((natural_t)(x)) >> PAGE_SHIFT)
+#define ptoa(x) ((vm_offset_t)((x) << PAGE_SHIFT))
/*
* Round off or truncate to the nearest page. These will work
* for either addresses or counts. (i.e. 1 byte rounds to 1 page
- * bytes. The round_page_32 and trunc_page_32 macros should not be
- * use on 64 bit types. The round_page_64 and trunc_page_64 macros
- * should be used instead.
- */
-
-#define round_page_32(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
-#define trunc_page_32(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
-#define round_page_64(x) (((uint64_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
-#define trunc_page_64(x) ((uint64_t)(x) & ~((signed)PAGE_MASK))
-
-
-/*
- * While the following block is enabled, the legacy round_page
- * and trunc_page macros will behave correctly. If not, they will
- * generate invalid lvalue errors.
- */
-
-#if 1
-#define round_page(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
-#define trunc_page(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
-#else
-#define round_page(x) (0UL = 0)
-#define trunc_page(x) (0UL = 0)
-#endif
-
-/*
- * Enable the following block to find uses of xxx_32 macros that should
- * be xxx_64. These macros only work in C code, not C++. The resulting
- * binaries are not functional. Look for invalid lvalue errors in
- * the compiler output.
- *
- * Enabling the following block will also find use of the xxx_64 macros
- * that have been passed pointers. The parameters should be case to an
- * unsigned long type first. Look for invalid operands to binary + error
- * in the compiler output.
+ * bytes.
*/
-#if 0
-#undef atop_32
-#undef ptoa_32
-#undef round_page_32
-#undef trunc_page_32
-#undef atop_64
-#undef ptoa_64
-#undef round_page_64
-#undef trunc_page_64
-
-#ifndef __cplusplus
-
-#define atop_32(x) \
- (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
- (*(long *)0), \
- (0UL)) = 0)
-
-#define ptoa_32(x) \
- (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
- (*(long *)0), \
- (0UL)) = 0)
-
-#define round_page_32(x) \
- (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
- (*(long *)0), \
- (0UL)) = 0)
-
-#define trunc_page_32(x) \
- (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
- (*(long *)0), \
- (0UL)) = 0)
-#else
-
-#define atop_32(x) (0)
-#define ptoa_32(x) (0)
-#define round_page_32(x) (0)
-#define trunc_page_32(x) (0)
-
-#endif /* ! __cplusplus */
-
-#define atop_64(x) ((uint64_t)((x) + (uint8_t *)0))
-#define ptoa_64(x) ((uint64_t)((x) + (uint8_t *)0))
-#define round_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
-#define trunc_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
+#define round_page(x) ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) & ~PAGE_MASK))
+#define trunc_page(x) ((vm_offset_t)(((vm_offset_t)(x)) & ~PAGE_MASK))
-#endif
+#define round_page_64(x) ((unsigned long long)((((unsigned long long)(x)) + PAGE_MASK_64) & ~PAGE_MASK_64))
+#define trunc_page_64(x) ((unsigned long long)(((unsigned long long)(x)) & ~PAGE_MASK_64))
/*
* Determine whether an address is page-aligned, or a count is
#define page_aligned(x) ((((vm_object_offset_t) (x)) & PAGE_MASK) == 0)
-extern vm_size_t mem_size; /* 32-bit size of memory - limited by maxmem - deprecated */
-extern uint64_t max_mem; /* 64-bit size of memory - limited by maxmem */
-extern uint64_t mem_actual; /* 64-bit size of memory - not limited by maxmem */
-extern uint64_t sane_size; /* Memory size to use for defaults calculations */
-extern addr64_t vm_last_addr; /* Highest kernel virtual address known to the VM system */
+extern vm_size_t mem_size; /* size of physical memory (bytes) */
#endif /* ASSEMBLER */
#endif /* _MACH_VM_PARAM_H_ */