]>
Commit | Line | Data |
---|---|---|
c90e37b5 JJ |
1 | ;------------------------------------------------------------------------------\r |
2 | ; @file\r | |
3 | ; Sets the CR3 register for 64-bit paging\r | |
4 | ;\r | |
5 | ; Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.<BR>\r | |
6 | ; This program and the accompanying materials\r | |
7 | ; are licensed and made available under the terms and conditions of the BSD License\r | |
8 | ; which accompanies this distribution. The full text of the license may be found at\r | |
9 | ; http://opensource.org/licenses/bsd-license.php\r | |
10 | ;\r | |
11 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | ;\r | |
14 | ;------------------------------------------------------------------------------\r | |
15 | \r | |
16 | BITS 32\r | |
17 | \r | |
18 | %define PAGE_PRESENT 0x01\r | |
19 | %define PAGE_READ_WRITE 0x02\r | |
20 | %define PAGE_USER_SUPERVISOR 0x04\r | |
21 | %define PAGE_WRITE_THROUGH 0x08\r | |
22 | %define PAGE_CACHE_DISABLE 0x010\r | |
23 | %define PAGE_ACCESSED 0x020\r | |
24 | %define PAGE_DIRTY 0x040\r | |
25 | %define PAGE_PAT 0x080\r | |
26 | %define PAGE_GLOBAL 0x0100\r | |
27 | %define PAGE_2M_MBO 0x080\r | |
28 | %define PAGE_2M_PAT 0x01000\r | |
29 | \r | |
30 | %define PAGE_2M_PDE_ATTR (PAGE_2M_MBO + \\r | |
c90e37b5 JJ |
31 | PAGE_ACCESSED + \\r |
32 | PAGE_DIRTY + \\r | |
33 | PAGE_READ_WRITE + \\r | |
34 | PAGE_PRESENT)\r | |
35 | \r | |
98f378a7 | 36 | %define PAGE_PDP_ATTR (PAGE_ACCESSED + \\r |
c90e37b5 JJ |
37 | PAGE_READ_WRITE + \\r |
38 | PAGE_PRESENT)\r | |
39 | \r | |
40 | \r | |
41 | ;\r | |
42 | ; Modified: EAX, ECX\r | |
43 | ;\r | |
44 | SetCr3ForPageTables64:\r | |
45 | \r | |
46 | ;\r | |
b382ede3 JJ |
47 | ; For OVMF, build some initial page tables at 0x800000-0x806000.\r |
48 | ;\r | |
49 | ; This range should match with PcdOvmfSecPageTablesBase and\r | |
50 | ; PcdOvmfSecPageTablesSize which are declared in the FDF files.\r | |
c90e37b5 JJ |
51 | ;\r |
52 | ; At the end of PEI, the pages tables will be rebuilt into a\r | |
53 | ; more permanent location by DxeIpl.\r | |
54 | ;\r | |
55 | \r | |
56 | mov ecx, 6 * 0x1000 / 4\r | |
57 | xor eax, eax\r | |
58 | clearPageTablesMemoryLoop:\r | |
b382ede3 | 59 | mov dword[ecx * 4 + 0x800000 - 4], eax\r |
c90e37b5 JJ |
60 | loop clearPageTablesMemoryLoop\r |
61 | \r | |
62 | ;\r | |
63 | ; Top level Page Directory Pointers (1 * 512GB entry)\r | |
64 | ;\r | |
b382ede3 | 65 | mov dword[0x800000], 0x801000 + PAGE_PDP_ATTR\r |
c90e37b5 JJ |
66 | \r |
67 | ;\r | |
68 | ; Next level Page Directory Pointers (4 * 1GB entries => 4GB)\r | |
69 | ;\r | |
b382ede3 JJ |
70 | mov dword[0x801000], 0x802000 + PAGE_PDP_ATTR\r |
71 | mov dword[0x801008], 0x803000 + PAGE_PDP_ATTR\r | |
72 | mov dword[0x801010], 0x804000 + PAGE_PDP_ATTR\r | |
73 | mov dword[0x801018], 0x805000 + PAGE_PDP_ATTR\r | |
c90e37b5 JJ |
74 | \r |
75 | ;\r | |
76 | ; Page Table Entries (2048 * 2MB entries => 4GB)\r | |
77 | ;\r | |
78 | mov ecx, 0x800\r | |
79 | pageTableEntriesLoop:\r | |
80 | mov eax, ecx\r | |
81 | dec eax\r | |
82 | shl eax, 21\r | |
83 | add eax, PAGE_2M_PDE_ATTR\r | |
b382ede3 | 84 | mov [ecx * 8 + 0x802000 - 8], eax\r |
c90e37b5 JJ |
85 | loop pageTableEntriesLoop\r |
86 | \r | |
87 | ;\r | |
88 | ; Set CR3 now that the paging structures are available\r | |
89 | ;\r | |
b382ede3 | 90 | mov eax, 0x800000\r |
c90e37b5 JJ |
91 | mov cr3, eax\r |
92 | \r | |
93 | OneTimeCallRet SetCr3ForPageTables64\r |