@@ -28,6 +28,9 @@ RefPtr<PageDirectory> PageDirectory::find_by_cr3(u32 cr3)
28
28
return cr3_map ().get (cr3).value_or ({});
29
29
}
30
30
31
+ #if ARCH(X86_64)
32
+ extern " C" PageDirectoryEntry boot_pml4t[1024 ];
33
+ #endif
31
34
extern " C" PageDirectoryEntry* boot_pdpt[4 ];
32
35
extern " C" PageDirectoryEntry boot_pd0[1024 ];
33
36
extern " C" PageDirectoryEntry boot_pd3[1024 ];
@@ -38,6 +41,11 @@ UNMAP_AFTER_INIT PageDirectory::PageDirectory()
38
41
m_identity_range_allocator.initialize_with_range (VirtualAddress (FlatPtr (0x00000000 )), 0x00200000 );
39
42
40
43
// Adopt the page tables already set up by boot.S
44
+ #if ARCH(X86_64)
45
+ PhysicalAddress boot_pml4t_paddr (virtual_to_low_physical ((FlatPtr)boot_pml4t));
46
+ dmesgln (" MM: boot_pml4t @ {}" , boot_pml4t_paddr);
47
+ m_pml4t = PhysicalPage::create (boot_pml4t_paddr, true , false );
48
+ #endif
41
49
PhysicalAddress boot_pdpt_paddr (virtual_to_low_physical ((FlatPtr)boot_pdpt));
42
50
PhysicalAddress boot_pd0_paddr (virtual_to_low_physical ((FlatPtr)boot_pd0));
43
51
PhysicalAddress boot_pd3_paddr (virtual_to_low_physical ((FlatPtr)boot_pd3));
@@ -64,6 +72,11 @@ PageDirectory::PageDirectory(const RangeAllocator* parent_range_allocator)
64
72
}
65
73
66
74
// Set up a userspace page directory
75
+ #if ARCH(X86_64)
76
+ m_pml4t = MM.allocate_user_physical_page ();
77
+ if (!m_pml4t)
78
+ return ;
79
+ #endif
67
80
m_directory_table = MM.allocate_user_physical_page ();
68
81
if (!m_directory_table)
69
82
return ;
@@ -79,12 +92,27 @@ PageDirectory::PageDirectory(const RangeAllocator* parent_range_allocator)
79
92
// Share the top 1 GiB of kernel-only mappings (>=3GiB or >=0xc0000000)
80
93
m_directory_pages[3 ] = MM.kernel_page_directory ().m_directory_pages [3 ];
81
94
95
+ #if ARCH(X86_64)
96
+ {
97
+ auto & table = *(PageDirectoryPointerTable*)MM.quickmap_page (*m_pml4t);
98
+ table.raw [0 ] = (FlatPtr)m_directory_table->paddr ().as_ptr () | 3 ;
99
+ MM.unquickmap_page ();
100
+ }
101
+ #endif
102
+
82
103
{
83
104
auto & table = *(PageDirectoryPointerTable*)MM.quickmap_page (*m_directory_table);
105
+ #if ARCH(I386)
84
106
table.raw [0 ] = (FlatPtr)m_directory_pages[0 ]->paddr ().as_ptr () | 1 ;
85
107
table.raw [1 ] = (FlatPtr)m_directory_pages[1 ]->paddr ().as_ptr () | 1 ;
86
108
table.raw [2 ] = (FlatPtr)m_directory_pages[2 ]->paddr ().as_ptr () | 1 ;
87
109
table.raw [3 ] = (FlatPtr)m_directory_pages[3 ]->paddr ().as_ptr () | 1 ;
110
+ #else
111
+ table.raw [0 ] = (FlatPtr)m_directory_pages[0 ]->paddr ().as_ptr () | 3 ;
112
+ table.raw [1 ] = (FlatPtr)m_directory_pages[1 ]->paddr ().as_ptr () | 3 ;
113
+ table.raw [2 ] = (FlatPtr)m_directory_pages[2 ]->paddr ().as_ptr () | 3 ;
114
+ table.raw [3 ] = (FlatPtr)m_directory_pages[3 ]->paddr ().as_ptr () | 3 ;
115
+ #endif
88
116
89
117
// 2 ** MAXPHYADDR - 1
90
118
// Where MAXPHYADDR = physical_address_bit_width
0 commit comments