/***************************************************************************/ /** **/ /** HPE CONFIDENTIAL. This software is confidential proprietary software **/ /** licensed by Hewlett-Packard Enterprise Development, LP, and is not **/ /** authorized to be used, duplicated OR disclosed to anyone without the **/ /** prior written permission of HPE. **/ /** © 2023 Copyright Hewlett-Packard Enterprise Development, LP **/ /** **/ /** VMS SOFTWARE, INC. CONFIDENTIAL. This software is confidential **/ /** proprietary software licensed by VMS Software, Inc., and is not **/ /** authorized to be used, duplicated or disclosed to anyone without **/ /** the prior written permission of VMS Software, Inc. **/ /** © 2023 Copyright VMS Software, Inc. **/ /** **/ /***************************************************************************/ /********************************************************************************************************************************/ /* Created: 9-Nov-2023 12:07:58 by OpenVMS SDL V3.7 */ /* Source: 02-NOV-2022 16:47:19 $1$DGA8345:[LIB_H.SRC]MMG_CONSTANTS.SDL;1 */ /********************************************************************************************************************************/ /*** MODULE MMG_CONSTANTS IDENT X-20 ***/ #ifndef __MMG_CONSTANTS_LOADED #define __MMG_CONSTANTS_LOADED 1 #pragma __nostandard /* This file uses non-ANSI-Standard features */ #pragma __member_alignment __save #pragma __nomember_alignment #ifdef __INITIAL_POINTER_SIZE /* Defined whenever ptr size pragmas supported */ #pragma __required_pointer_size __save /* Save the previously-defined required ptr size */ #pragma __required_pointer_size __short /* And set ptr size default to 32-bit pointers */ #endif #ifdef __cplusplus extern "C" { #define __unknown_params ... #define __optional_params ... #else #define __unknown_params #define __optional_params ... #endif #ifndef __struct #if !defined(__VAXC) #define __struct struct #else #define __struct variant_struct #endif #endif #ifndef __union #if !defined(__VAXC) #define __union union #else #define __union variant_union #endif #endif /* There are three fundamental variables about the paging data structures: */ /* - size of a page in bytes */ /* - number of bytes in a PTE */ /* - number of levels of page table in a full translation */ /* Given these numbers, we can calculate many of the other values needed */ /* by memory management. */ /* */ /* These constants may be of general interest to VMS code. */ #define MMG$C_BITS_PER_BYTE 8 #define MMG$C_BITS_PER_BYTE_SHIFT 3 #define MMG$C_BYTES_PER_PAGELET 512 #define MMG$C_BYTES_PER_PAGELET_SHIFT 9 #define MMG$C_BITS_PER_QUADWORD 64 #define MMG$C_BITS_PER_QUADWORD_SHIFT 6 #define MMG$C_BYTES_PER_QUADWORD 8 #define MMG$C_BYTES_PER_QUADWORD_SHIFT 3 /* This next set of constants are specific to memory management. */ #define MMG$$C_BYTES_PER_PTE 8 #define MMG$$C_BYTES_PER_PTE_SHIFT 3 #define MMG$$C_OFFSET_TO_PFN_SHIFT 3 #define MMG$$C_PFN_TO_OFFSET_SHIFT 3 /* Calculation conversion from Mbytes to 8K Pages */ #define MMG$$C_BYTES_PER_1MB 1048576 #define MMG$$C_BYTES_PER_1MB_SHIFT 20 #define MMG$$C_PAGE8K_PER_MB 128 #define MMG$$C_PAGE8K_PER_MB_SHIFT 7 #define MMG$$C_BYTES_PER_2MB 2097152 #define MMG$$C_BYTES_PER_2MB_SHIFT 21 /* On x86, the number of levels of page tables is not an architectural */ /* constant: it can be either 4 or 5. So, some of the numbers we want */ /* must continue to be run-time "constants" calculated at boot time. */ /* This last set of constants are specific to x86 memory management. */ #define MMG$$C_BOFF_MASK_4K 0xFFFull /* mask for just the byte-offset bits on a 4-kB PFN */ #define MMG$$C_BOFF_MASK 0x1FFFull /* mask for just the byte-offset bits on an 8-kB page */ #define MMG$$C_BOFF_MASK_8K 0x1FFFull /* mask for just the byte-offset bits on an 8-kB page */ #define MMG$$C_BOFF_MASK_2M 0x1FFFFFull /* mask for just the byte-offset bits on a 2-MB PFN */ #define MMG$$C_BOFF_MASK_4M 0x3FFFFFull /* mask for just the byte-offset bits on a 4-MB page */ #define MMG$$C_BOFF_MASK_1G 0x3FFFFFFFull /* mask for just the byte-offset bits on a 1-GB PFN */ #define MMG$$C_BOFF_MASK_2G 0x7FFFFFFFull /* mask for just the byte-offset bits on a 2-GB page */ #define MMG$$C_NON_BOFF_MASK_4K 0xFFFFFFFFFFFFF000ull /* mask for everything except byte offset on a 4-kB PFN */ #define MMG$$C_NON_BOFF_MASK 0xFFFFFFFFFFFFE000ull /* mask for everything except byte offset on an 8-kB page */ #define MMG$$C_NON_BOFF_MASK_8K 0xFFFFFFFFFFFFE000ull /* mask for everything except byte offset on an 8-kB page */ #define MMG$$C_NON_BOFF_MASK_2M 0xFFFFFFFFFFE00000ull /* mask for everything except byte offset on a 2-MB PFN */ #define MMG$$C_NON_BOFF_MASK_4M 0xFFFFFFFFFFC00000ull /* mask for everything except byte offset on a 4-MB page */ #define MMG$$C_NON_BOFF_MASK_1G 0xFFFFFFFFC0000000ull /* mask for everything except byte offset on a 1-GB PFN */ #define MMG$$C_NON_BOFF_MASK_2G 0xFFFFFFFF80000000ull /* mask for everything except byte offset on a 2-GB page */ #define MMG$$C_BYTES_PER_HW_PAGE 4096ull /* HW PFN Size */ /* These are commonly used symbols. Note, the PA/PFN shift is NOT EQUAL */ /* to the VA/VPN shift. */ #define MMG$$C_BOFF_SIZE 13 #define MMG$$C_BWP_WIDTH 13 #define MMG$$C_BYTES_PER_PAGE 8192 #define MMG$$C_PTE_SEGMENT_SIZE 9 #define MMG$$C_PA_TO_PFN_SHIFT 12 #define MMG$$C_PAGE_SIZE 8192 #define MMG$$C_PAGELETS_PER_PAGE 16 #define MMG$$C_PFN_TO_PA_SHIFT 12 #define MMG$$C_PTES_PER_PAGE 512 /* page table pages are always 4K */ #define MMG$$C_VA_TO_VPN_SHIFT 13 #define MMG$$C_VPN_TO_VA_SHIFT 13 /* This set is for the x86 architectural PFN size of 4 kB. */ #define MMG$$C_BYTES_PER_HW_PAGE_SHIFT 12 #define MMG$$C_HW_BOFF_SIZE 12 #define MMG$$C_HW_BWP_WIDTH 12 #define MMG$$C_HW_PAGE_SIZE 4096 #define MMG$$C_PAGELETS_PER_HW_PAGE 8 #define MMG$$C_VA_TO_HW_VPN_SHIFT 12 #define MMG$$C_HW_VPN_TO_VA_SHIFT 12 /* This set is for the page allocation size of 8 kB. */ #define MMG$$C_PA_TO_ALLOC_PFN_SHIFT 13 #define MMG$$C_ALLOC_PFN_TO_PA_SHIFT 13 /* This set is for a PFN size of 2 MB. */ #define MMG$$C_BYTES_PER_2MB_PAGE 2097152 #define MMG$$C_BYTES_PER_2MB_PAGE_SHIFT 21 #define MMG$$C_PAGE_SIZE_2MB 2097152 #define MMG$$C_PAGELETS_PER_2MB_PAGE 4096 #define MMG$$C_BWP_WIDTH_2MB 21 #define MMG$$C_PA_TO_2MB_PFN_SHIFT 21 #define MMG$$C_PFN_2MB_TO_PA_SHIFT 21 #define MMG$$C_VA_TO_2MB_VPN_SHIFT 21 #define MMG$$C_VPN_2MB_TO_VA_SHIFT 21 /* This set is for a page size of 4 MB. */ #define MMG$$C_BYTES_PER_4MB_PAGE 4194304 #define MMG$$C_BYTES_PER_4MB_PAGE_SHIFT 22 #define MMG$$C_PAGE_SIZE_4MB 4194304 #define MMG$$C_PAGELETS_PER_4MB_PAGE 8192 #define MMG$$C_BWP_WIDTH_4MB 22 #define MMG$$C_PA_TO_4MB_PFN_SHIFT 22 #define MMG$$C_PFN_4MB_TO_PA_SHIFT 22 #define MMG$$C_VA_TO_4MB_VPN_SHIFT 22 #define MMG$$C_VPN_4MB_TO_VA_SHIFT 22 /* This set is for a PFN size of 1 GB. */ #define MMG$$C_BYTES_PER_1GB_PAGE 1073741824 #define MMG$$C_BYTES_PER_1GB_PAGE_SHIFT 30 #define MMG$$C_PAGE_SIZE_1GB 1073741824 #define MMG$$C_PAGELETS_PER_1GB_PAGE 2097152 #define MMG$$C_BWP_WIDTH_1GB 30 #define MMG$$C_PA_TO_1GB_PFN_SHIFT 30 #define MMG$$C_PFN_1GB_TO_PA_SHIFT 30 #define MMG$$C_VA_TO_1GB_VPN_SHIFT 30 #define MMG$$C_VPN_1GB_TO_VA_SHIFT 30 /* This set is for a page size of 2 GB. */ #define MMG$$C_BYTES_PER_2GB_PAGE 2147483648 #define MMG$$C_BYTES_PER_2GB_PAGE_SHIFT 31 #define MMG$$C_PAGE_SIZE_2GB 2147483648 #define MMG$$C_PAGELETS_PER_2GB_PAGE 4194304 #define MMG$$C_BWP_WIDTH_2GB 31 #define MMG$$C_PA_TO_2GB_PFN_SHIFT 31 #define MMG$$C_PFN_2GB_TO_PA_SHIFT 31 #define MMG$$C_VA_TO_2GB_VPN_SHIFT 31 #define MMG$$C_VPN_2GB_TO_VA_SHIFT 31 /* The PFN_TO_PFNDBIDX constants are the number of bit positions a PFN needs */ /* to be shifted to produce an index into the PFNDB. The PFNDB */ /* operates on 8K increments. Note that for a 4 kB x86 PFN, the shift is right */ /* and for a 2 MB and 1 GB PFN, the shift is a left shift. */ #define MMG$$C_PFN_TO_PFNDBIDX_4K 1 /* Right Shift */ #define MMG$$C_PFN_TO_PFNDBIDX_2M 8 /* Left Shift */ #define MMG$$C_PFN_TO_PFNDBIDX_2MB 8 /* Left Shift, to be retired */ #define MMG$$C_PFN_TO_PFNDBIDX_1G 17 /* Left Shift */ /* Starting (low-order) bit number of PT segments */ /* Equivalently, the number of bits to shift RIGHT to place the indicated */ /* PT INDEX so that it starts at bit 0. This number can be used as */ /* an index into a page table typed as PTE_PQ. */ #define MMG$$C_BPT_BITPOS 12 #define MMG$$C_PD_BITPOS 21 #define MMG$$C_PDPT_BITPOS 30 #define MMG$$C_PML4_BITPOS 39 #define MMG$$C_PML5_BITPOS 48 /* The number of bits to shift RIGHT to place the indicated PT OFFSET */ /* so that it starts at bit 3, thus making it an offset into a page */ /* table typed as INT64, PTE_PQ, or equivalent. Caller must make sure */ /* the low 3 bits are zero. */ #define MMG$$C_BPT_OFFPOS 9 #define MMG$$C_PD_OFFPOS 18 #define MMG$$C_PDPT_OFFPOS 27 #define MMG$$C_PML4_OFFPOS 36 #define MMG$$C_PML5_OFFPOS 45 /* Masks to extract the indicated PT segment from an address. */ /* Typical usage is to apply the mask to get the segment value */ /* then shift it as needed. */ /* In order to get the masks to appear to generate as hex values vs. decimal values, */ /* the masks have been placed into a structure as bitfield masks. */ #define MMG$$C_SEGMENT_MASK 0x1FFull #define MMG$$C_BPT_MASK (MMG$$C_SEGMENT_MASK << MMG$$C_BPT_BITPOS) #define MMG$$C_PD_MASK (MMG$$C_SEGMENT_MASK << MMG$$C_PD_BITPOS) #define MMG$$C_PDPT_MASK (MMG$$C_SEGMENT_MASK << MMG$$C_PDPT_BITPOS) #define MMG$$C_PML4_MASK (MMG$$C_SEGMENT_MASK << MMG$$C_PML4_BITPOS) #define MMG$$C_PML5_MASK (MMG$$C_SEGMENT_MASK << MMG$$C_PML5_BITPOS) /* Masks to extract combined fields for indexing into a page table from */ /* its base address cannot be defined as compile-time constants since */ /* their values depend on whether 4- or 5-level paging is enabled. */ /* This is only known at boot time. */ /* Create constants with the number of entries and the size of 4 and 5 level page tables. */ /* These values are not available in in bliss32. */ /*+ */ /* Define constants to assist walking the per mode X86 page tables. */ /*- */ /* 4 levels of 512 segments */ /* 5 levels of 512 segments */ #define MMG$$C_LEVEL4_PT_ENTRIES 68719476736 #define MMG$$C_LEVEL5_PT_ENTRIES 35184372088832 #define MMG$$C_LEVEL4_PT_SIZE 549755813888 #define MMG$$C_LEVEL5_PT_SIZE 281474976710656 /*+ */ /* Add an X86 constant for the end of S0S1 space. The S0S1 region ends 64KB short of */ /* the end of the region so that it matches Alpha/IA64. */ /*- */ #define MMG$$C_MAX_S0S1 0xFFFFFFFFFFFF0000ull /* mask for everything except byte offset on a 2-GB page */ /*+ */ /* The x86 constant for the number of 8KB global pages when GBLPAGES (the */ /* number of 512B pagelets) is the maximum of -1. The value is 0x10000000. */ /*- */ #define MMG$$C_MAX_GLOBAL_PAGES 268435456 #pragma __member_alignment __restore #ifdef __INITIAL_POINTER_SIZE /* Defined whenever ptr size pragmas supported */ #pragma __required_pointer_size __restore /* Restore the previously-defined required ptr size */ #endif #ifdef __cplusplus } #endif #pragma __standard #endif /* __MMG_CONSTANTS_LOADED */