]> git.proxmox.com Git - mirror_edk2.git/blame - DuetPkg/DxeIpl/Ia32/Paging.c
Update the copyright notice format
[mirror_edk2.git] / DuetPkg / DxeIpl / Ia32 / Paging.c
CommitLineData
18b84857 1/** @file\r
ca162103 2\r
b1f700a8
HT
3Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials \r
ca162103 5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13 Paging.c\r
14\r
15Abstract:\r
16\r
17Revision History:\r
18\r
18b84857 19**/\r
ca162103 20\r
21#include "DxeIpl.h"\r
22#include "HobGeneration.h"\r
23#include "VirtualMemory.h"\r
24#include "Debug.h"\r
25\r
26#define EFI_PAGE_SIZE_4K 0x1000\r
27#define EFI_PAGE_SIZE_4M 0x400000\r
28\r
29//\r
30// Create 4G 4M-page table\r
31// PDE (31:22) : 1024 entries\r
32//\r
33#define EFI_MAX_ENTRY_NUM 1024\r
34\r
35#define EFI_PDE_ENTRY_NUM EFI_MAX_ENTRY_NUM\r
36\r
37#define EFI_PDE_PAGE_NUM 1\r
38\r
39#define EFI_PAGE_NUMBER_4M (EFI_PDE_PAGE_NUM)\r
40\r
41//\r
42// Create 4M 4K-page table\r
43// PTE (21:12) : 1024 entries\r
44//\r
45#define EFI_PTE_ENTRY_NUM EFI_MAX_ENTRY_NUM\r
46#define EFI_PTE_PAGE_NUM 1\r
47\r
48#define EFI_PAGE_NUMBER_4K (EFI_PTE_PAGE_NUM)\r
49\r
50#define EFI_PAGE_NUMBER (EFI_PAGE_NUMBER_4M + EFI_PAGE_NUMBER_4K)\r
51\r
52VOID\r
53EnableNullPointerProtection (\r
54 UINT8 *PageTable\r
55 )\r
56{\r
57 IA32_PAGE_TABLE_ENTRY_4K *PageTableEntry4KB;\r
58\r
59 PageTableEntry4KB = (IA32_PAGE_TABLE_ENTRY_4K *)((UINTN)PageTable + EFI_PAGE_NUMBER_4M * EFI_PAGE_SIZE_4K);\r
60\r
61 //\r
62 // Fill in the Page Table entries\r
63 // Mark 0~4K as not present\r
64 //\r
65 PageTableEntry4KB->Bits.Present = 0;\r
66\r
67 return ;\r
68}\r
69\r
70VOID\r
71Ia32Create4KPageTables (\r
72 UINT8 *PageTable\r
73 )\r
74{\r
75 UINT64 PageAddress;\r
76 UINTN PTEIndex;\r
77 IA32_PAGE_DIRECTORY_ENTRY_4K *PageDirectoryEntry4KB;\r
78 IA32_PAGE_TABLE_ENTRY_4K *PageTableEntry4KB;\r
79\r
80 PageAddress = 0;\r
81\r
82 //\r
83 // Page Table structure 2 level 4K.\r
84 //\r
85 // Page Table 4K : PageDirectoryEntry4K : bits 31-22\r
86 // PageTableEntry : bits 21-12\r
87 //\r
88\r
89 PageTableEntry4KB = (IA32_PAGE_TABLE_ENTRY_4K *)((UINTN)PageTable + EFI_PAGE_NUMBER_4M * EFI_PAGE_SIZE_4K);\r
90 PageDirectoryEntry4KB = (IA32_PAGE_DIRECTORY_ENTRY_4K *)((UINTN)PageTable);\r
91\r
92 PageDirectoryEntry4KB->Uint32 = (UINT32)(UINTN)PageTableEntry4KB;\r
93 PageDirectoryEntry4KB->Bits.ReadWrite = 0;\r
94 PageDirectoryEntry4KB->Bits.Present = 1;\r
95 PageDirectoryEntry4KB->Bits.MustBeZero = 1;\r
96\r
97 for (PTEIndex = 0; PTEIndex < EFI_PTE_ENTRY_NUM; PTEIndex++, PageTableEntry4KB++) {\r
98 //\r
99 // Fill in the Page Table entries\r
100 //\r
101 PageTableEntry4KB->Uint32 = (UINT32)PageAddress;\r
102 PageTableEntry4KB->Bits.ReadWrite = 1;\r
103 PageTableEntry4KB->Bits.Present = 1;\r
104\r
105 PageAddress += EFI_PAGE_SIZE_4K;\r
106 }\r
107\r
108 return ;\r
109}\r
110\r
111VOID\r
112Ia32Create4MPageTables (\r
113 UINT8 *PageTable\r
114 )\r
115{\r
116 UINT32 PageAddress;\r
117 UINT8 *TempPageTable;\r
118 UINTN PDEIndex;\r
119 IA32_PAGE_TABLE_ENTRY_4M *PageDirectoryEntry4MB;\r
120\r
121 TempPageTable = PageTable;\r
122\r
123 PageAddress = 0;\r
124\r
125 //\r
126 // Page Table structure 1 level 4MB.\r
127 //\r
128 // Page Table 4MB : PageDirectoryEntry4M : bits 31-22\r
129 //\r
130\r
131 PageDirectoryEntry4MB = (IA32_PAGE_TABLE_ENTRY_4M *)TempPageTable;\r
132\r
133 for (PDEIndex = 0; PDEIndex < EFI_PDE_ENTRY_NUM; PDEIndex++, PageDirectoryEntry4MB++) {\r
134 //\r
135 // Fill in the Page Directory entries\r
136 //\r
137 PageDirectoryEntry4MB->Uint32 = (UINT32)PageAddress;\r
138 PageDirectoryEntry4MB->Bits.ReadWrite = 1;\r
139 PageDirectoryEntry4MB->Bits.Present = 1;\r
140 PageDirectoryEntry4MB->Bits.MustBe1 = 1;\r
141\r
142 PageAddress += EFI_PAGE_SIZE_4M;\r
143 }\r
144\r
145 return ;\r
146}\r
147\r
148VOID *\r
149PreparePageTable (\r
150 VOID *PageNumberTop,\r
151 UINT8 SizeOfMemorySpace \r
152 )\r
153/*++\r
154Description:\r
155 Generate pagetable below PageNumberTop, \r
156 and return the bottom address of pagetable for putting other things later.\r
157--*/\r
158{\r
159 VOID *PageNumberBase;\r
160\r
161 PageNumberBase = (VOID *)((UINTN)PageNumberTop - EFI_PAGE_NUMBER * EFI_PAGE_SIZE_4K);\r
162 ZeroMem (PageNumberBase, EFI_PAGE_NUMBER * EFI_PAGE_SIZE_4K);\r
163\r
164 Ia32Create4MPageTables (PageNumberBase);\r
165 Ia32Create4KPageTables (PageNumberBase);\r
166 //\r
167 // Not enable NULL Pointer Protection if using INTX call\r
168 //\r
169// EnableNullPointerProtection (PageNumberBase);\r
170\r
171 return PageNumberBase;\r
172}\r