Skip to content

Commit 9d733ab

Browse files
authored
Merge pull request #265 from hawkw/eliza/flush-all
Only perform a single TLB flush after identity mapping
2 parents 167eb99 + 3bb5b8e commit 9d733ab

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/bin/bios.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,28 @@ fn bootloader_main(
117117
PhysFrame::containing_address(PhysAddr::new(GIGABYTE));
118118
let end_frame = PhysFrame::containing_address(PhysAddr::new(max_phys_addr - 1));
119119
for frame in PhysFrame::range_inclusive(start_frame, end_frame) {
120-
unsafe {
120+
let flusher = unsafe {
121121
bootloader_page_table
122122
.identity_map(
123123
frame,
124124
PageTableFlags::PRESENT | PageTableFlags::WRITABLE,
125125
&mut frame_allocator,
126126
)
127127
.unwrap()
128-
.flush()
129128
};
129+
// skip flushing the entry from the TLB for now, as we will
130+
// flush the entire TLB at the end of the loop.
131+
flusher.ignore();
130132
}
131133
}
132134

135+
// once all the physical memory is mapped, flush the TLB by reloading the
136+
// CR3 register.
137+
//
138+
// we perform a single flush here rather than flushing each individual entry as
139+
// it's mapped using `invlpg`, for efficiency.
140+
x86_64::instructions::tlb::flush_all();
141+
133142
let framebuffer_addr = PhysAddr::new(unsafe { VBEModeInfo_physbaseptr }.into());
134143
let mut error = None;
135144
let framebuffer_info = unsafe {

0 commit comments

Comments
 (0)