HyperPlatform Programmer's Reference
util_page_constants.h
Go to the documentation of this file.
1 // Copyright (c) 2015-2017, Satoshi Tanda. All rights reserved.
2 // Use of this source code is governed by a MIT-style license that can be
3 // found in the LICENSE file.
4 
11 
12 #ifndef HYPERPLATFORM_UTIL_CONSTANT_H_
13 #define HYPERPLATFORM_UTIL_CONSTANT_H_
14 
15 // Virtual Address Interpretation For Handling PTEs
16 //
17 // -- On x64
18 // Sign extension 16 bits
19 // Page map level 4 selector 9 bits
20 // Page directory pointer selector 9 bits
21 // Page directory selector 9 bits
22 // Page table selector 9 bits
23 // Byte within page 12 bits
24 // 11111111 11111111 11111000 10000000 00000011 01010011 00001010 00011000
25 // ^^^^^^^^ ^^^^^^^^ ~~~~~~~~ ~^^^^^^^ ^^~~~~~~ ~~~^^^^^ ^^^^~~~~ ~~~~~~~~
26 // Sign extension PML4 PDPT PD PT Offset
27 //
28 // -- On x86(PAE)
29 // Page directory pointer selector 2 bits
30 // Page directory selector 9 bits
31 // Page table selector 9 bits
32 // Byte within page 12 bits
33 // 10 000011011 000001101 001001110101
34 // ^^ ~~~~~~~~~ ^^^^^^^^^ ~~~~~~~~~~~~
35 // PDPT PD PT Offset
36 //
37 // -- On x86 and ARM
38 // Page directory selector 10 bits
39 // Page table selector 10 bits
40 // Byte within page 12 bits
41 // 1000001101 1000001101 001001110101
42 // ~~~~~~~~~~ ^^^^^^^^^^ ~~~~~~~~~~~~
43 // PD PT Offset
44 //
45 //
46 // x64 x86(PAE) x86 ARM
47 // Page map level 4 selector 9 - - -
48 // Page directory pointer selector 9 2 - -
49 // Page directory selector 9 9 10 10
50 // Page table selector 9 9 10 10
51 // Byte within page 12 12 12 12
52 //
53 // 6666555555555544444444443333333333222222222211111111110000000000
54 // 3210987654321098765432109876543210987654321098765432109876543210
55 // ----------------------------------------------------------------
56 // aaaaaaaaaaaaaaaabbbbbbbbbcccccccccdddddddddeeeeeeeeeffffffffffff x64
57 // ................................ccdddddddddeeeeeeeeeffffffffffff x86(PAE)
58 // ................................ddddddddddeeeeeeeeeeffffffffffff x86
59 // ................................ddddddddddeeeeeeeeeeffffffffffff ARM
60 //
61 // a = Sign extension, b = PML4, c = PDPT, d = PD, e = PT, f = Offset
62 
63 #if defined(_AMD64_)
64 
65 // Base addresses of page structures. Use !pte to obtain them.
66 static auto kUtilpPxeBase = 0xfffff6fb7dbed000ull;
67 static auto kUtilpPpeBase = 0xfffff6fb7da00000ull;
68 static auto kUtilpPdeBase = 0xfffff6fb40000000ull;
69 static auto kUtilpPteBase = 0xfffff68000000000ull;
70 
71 // Get the highest 25 bits
72 static const auto kUtilpPxiShift = 39ull;
73 
74 // Get the highest 34 bits
75 static const auto kUtilpPpiShift = 30ull;
76 
77 // Get the highest 43 bits
78 static const auto kUtilpPdiShift = 21ull;
79 
80 // Get the highest 52 bits
81 static const auto kUtilpPtiShift = 12ull;
82 
83 // Use 9 bits; 0b0000_0000_0000_0000_0000_0000_0001_1111_1111
84 static const auto kUtilpPxiMask = 0x1ffull;
85 
86 // Use 18 bits; 0b0000_0000_0000_0000_0011_1111_1111_1111_1111
87 static const auto kUtilpPpiMask = 0x3ffffull;
88 
89 // Use 27 bits; 0b0000_0000_0111_1111_1111_1111_1111_1111_1111
90 static const auto kUtilpPdiMask = 0x7ffffffull;
91 
92 // Use 36 bits; 0b1111_1111_1111_1111_1111_1111_1111_1111_1111
93 static const auto kUtilpPtiMask = 0xfffffffffull;
94 
95 #elif defined(_X86_)
96 
97 // Base addresses of page structures. Use !pte to obtain them.
98 static auto kUtilpPdeBase = 0xc0300000;
99 static auto kUtilpPteBase = 0xc0000000;
100 
101 // Get the highest 10 bits
102 static const auto kUtilpPdiShift = 22;
103 
104 // Get the highest 20 bits
105 static const auto kUtilpPtiShift = 12;
106 
107 // Use 10 bits; 0b0000_0000_0000_0000_0000_0000_0011_1111_1111
108 static const auto kUtilpPdiMask = 0x3ff;
109 
110 // Use 20 bits; 0b0000_0000_0000_0000_1111_1111_1111_1111_1111
111 static const auto kUtilpPtiMask = 0xfffff;
112 
113 // unused but defined to compile without ifdef
114 
115 static auto kUtilpPxeBase = 0;
116 static auto kUtilpPpeBase = 0;
117 static const auto kUtilpPxiShift = 0;
118 static const auto kUtilpPpiShift = 0;
119 static const auto kUtilpPxiMask = 0;
120 static const auto kUtilpPpiMask = 0;
121 
122 #endif
123 
124 // Base addresses of page structures. Use !pte to obtain them.
125 static const auto kUtilpPdeBasePae = 0xc0600000;
126 static const auto kUtilpPteBasePae = 0xc0000000;
127 
128 // Get the highest 11 bits
129 static const auto kUtilpPdiShiftPae = 21;
130 
131 // Get the highest 20 bits
132 static const auto kUtilpPtiShiftPae = 12;
133 
134 // Use 11 bits; 0b0000_0000_0000_0000_0000_0000_0111_1111_1111
135 static const auto kUtilpPdiMaskPae = 0x7ff;
136 
137 // Use 20 bits; 0b0000_0000_0000_0000_1111_1111_1111_1111_1111
138 static const auto kUtilpPtiMaskPae = 0xfffff;
139 
140 #endif // HYPERPLATFORM_UTIL_H_
static const auto kUtilpPtiMaskPae
static const auto kUtilpPdiShiftPae
static const auto kUtilpPdiMaskPae
static const auto kUtilpPteBasePae
static const auto kUtilpPtiShiftPae
static const auto kUtilpPdeBasePae