Skip to content

Commit 1775317

Browse files
committed
don't switch to new page tables in bootloader
We don't need to do this anymore because we no longer modify the bootloader's page tables. This also finally makes it possible to access all memory mapped in by UEFI and not just the memory accessible through the first PML4 entry. Some UEFI implementations map the frame buffer into ranges not accessible through the first PML4 entry.
1 parent 94a549d commit 1775317

File tree

3 files changed

+0
-46
lines changed

3 files changed

+0
-46
lines changed

bios/stage-4/src/main.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,6 @@ fn create_page_tables(frame_allocator: &mut impl FrameAllocator<Size4KiB>) -> Pa
221221
// We identity-mapped all memory, so the offset between physical and virtual addresses is 0
222222
let phys_offset = VirtAddr::new(0);
223223

224-
// copy the currently active level 4 page table, because it might be read-only
225-
let bootloader_page_table = {
226-
let frame = x86_64::registers::control::Cr3::read().0;
227-
let table: *mut PageTable = (phys_offset + frame.start_address().as_u64()).as_mut_ptr();
228-
unsafe { OffsetPageTable::new(&mut *table, phys_offset) }
229-
};
230-
231224
// create a new page table hierarchy for the kernel
232225
let (kernel_page_table, kernel_level_4_frame) = {
233226
// get an unused frame for new level 4 page table
@@ -246,7 +239,6 @@ fn create_page_tables(frame_allocator: &mut impl FrameAllocator<Size4KiB>) -> Pa
246239
};
247240

248241
PageTables {
249-
bootloader: bootloader_page_table,
250242
kernel: kernel_page_table,
251243
kernel_level_4_frame,
252244
}

common/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,6 @@ pub fn switch_to_kernel(page_tables: PageTables, mappings: Mappings, boot_info:
605605

606606
/// Provides access to the page tables of the bootloader and kernel address space.
607607
pub struct PageTables {
608-
/// Provides access to the page tables of the bootloader address space.
609-
pub bootloader: OffsetPageTable<'static>,
610608
/// Provides access to the page tables of the kernel address space (not active).
611609
pub kernel: OffsetPageTable<'static>,
612610
/// The physical frame where the level 4 page table of the kernel address space is stored.

uefi/src/main.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -389,41 +389,6 @@ fn create_page_tables(
389389
// UEFI identity-maps all memory, so the offset between physical and virtual addresses is 0
390390
let phys_offset = VirtAddr::new(0);
391391

392-
// copy the currently active level 4 page table, because it might be read-only
393-
log::trace!("switching to new level 4 table");
394-
let bootloader_page_table = {
395-
let old_table = {
396-
let frame = x86_64::registers::control::Cr3::read().0;
397-
let ptr: *const PageTable = (phys_offset + frame.start_address().as_u64()).as_ptr();
398-
unsafe { &*ptr }
399-
};
400-
let new_frame = frame_allocator
401-
.allocate_frame()
402-
.expect("Failed to allocate frame for new level 4 table");
403-
let new_table: &mut PageTable = {
404-
let ptr: *mut PageTable =
405-
(phys_offset + new_frame.start_address().as_u64()).as_mut_ptr();
406-
// create a new, empty page table
407-
unsafe {
408-
ptr.write(PageTable::new());
409-
&mut *ptr
410-
}
411-
};
412-
413-
// copy the first entry (we don't need to access more than 512 GiB; also, some UEFI
414-
// implementations seem to create an level 4 table entry 0 in all slots)
415-
new_table[0] = old_table[0].clone();
416-
417-
// the first level 4 table entry is now identical, so we can just load the new one
418-
unsafe {
419-
x86_64::registers::control::Cr3::write(
420-
new_frame,
421-
x86_64::registers::control::Cr3Flags::empty(),
422-
);
423-
OffsetPageTable::new(&mut *new_table, phys_offset)
424-
}
425-
};
426-
427392
// create a new page table hierarchy for the kernel
428393
let (kernel_page_table, kernel_level_4_frame) = {
429394
// get an unused frame for new level 4 page table
@@ -442,7 +407,6 @@ fn create_page_tables(
442407
};
443408

444409
bootloader_x86_64_common::PageTables {
445-
bootloader: bootloader_page_table,
446410
kernel: kernel_page_table,
447411
kernel_level_4_frame,
448412
}

0 commit comments

Comments
 (0)