Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit BIOS bootloader's max_phys_addr to 4 GiB #260

Merged
merged 2 commits into from
Sep 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/bin/bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fn bootloader_main(
use bootloader::binary::{
bios::memory_descriptor::E820MemoryRegion, legacy_memory_region::LegacyFrameAllocator,
};
const GIGABYTE: u64 = 4096 * 512 * 512;

let e820_memory_map = {
let ptr = usize_from(memory_map_addr.as_u64()) as *const E820MemoryRegion;
Expand All @@ -86,6 +87,10 @@ fn bootloader_main(
let max_phys_addr = e820_memory_map
.iter()
.map(|r| r.start_addr + r.len)
// Don't consider addresses > 4GiB when determining the maximum
// physical address for the bootloader, as we are in protected mode and
// cannot address more than 4 GiB of memory anyway.
.filter(|&addr| addr < GIGABYTE * 4)
hawkw marked this conversation as resolved.
Show resolved Hide resolved
.max()
.expect("no physical memory regions found");

Expand All @@ -106,7 +111,7 @@ fn bootloader_main(
// identity-map remaining physical memory (first gigabyte is already identity-mapped)
{
let start_frame: PhysFrame<Size2MiB> =
PhysFrame::containing_address(PhysAddr::new(4096 * 512 * 512));
PhysFrame::containing_address(PhysAddr::new(GIGABYTE));
let end_frame = PhysFrame::containing_address(PhysAddr::new(max_phys_addr - 1));
for frame in PhysFrame::range_inclusive(start_frame, end_frame) {
unsafe {
Expand Down