Skip to content

Update x86_64 to 0.15.2 #490

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

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
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
38 changes: 25 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bios/stage-4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bootloader-x86_64-common = { workspace = true }
bootloader-x86_64-bios-common = { workspace = true }
bootloader-boot-config = { workspace = true }
log = "0.4.14"
x86_64 = "0.14.8"
x86_64 = "0.15.2"
rsdp = "2.0.0"
usize_conversions = "0.2.0"
serde-json-core = "0.5.0"
Expand Down
2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bootloader-boot-config = { workspace = true }
conquer-once = { version = "0.3.2", default-features = false }
spinning_top = "0.2.4"
usize_conversions = "0.2.0"
x86_64 = { version = "0.14.8" }
x86_64 = { version = "0.15.2" }
xmas-elf = "0.8.0"
raw-cpuid = "10.2.0"
rand = { version = "0.8.4", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions common/src/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub fn create_and_load(frame: PhysFrame) {
let ptr: *mut GlobalDescriptorTable = virt_addr.as_mut_ptr();

let mut gdt = GlobalDescriptorTable::new();
let code_selector = gdt.add_entry(Descriptor::kernel_code_segment());
let data_selector = gdt.add_entry(Descriptor::kernel_data_segment());
let code_selector = gdt.append(Descriptor::kernel_code_segment());
let data_selector = gdt.append(Descriptor::kernel_data_segment());
let gdt = unsafe {
ptr.write(gdt);
&*ptr
Expand Down
20 changes: 9 additions & 11 deletions common/src/level_4_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ impl UsedLevel4Entries {

// The bootload needs to access the frame buffer.
if let Some(frame_buffer) = framebuffer {
used.mark_range_as_used(frame_buffer.addr.as_u64(), frame_buffer.info.byte_len);
used.mark_range_as_used(
frame_buffer.addr.as_u64(),
frame_buffer.info.byte_len as u64,
);
}

// Mark the statically configured ranges from the config as used.

if let Some(config::Mapping::FixedAddress(physical_memory_offset)) =
config.mappings.physical_memory
{
used.mark_range_as_used(physical_memory_offset, max_phys_addr.as_u64().into_usize());
used.mark_range_as_used(physical_memory_offset, max_phys_addr.as_u64());
}

if let Some(config::Mapping::FixedAddress(recursive_address)) =
Expand All @@ -76,12 +79,12 @@ impl UsedLevel4Entries {
let memory_regions_layout = Layout::array::<MemoryRegion>(regions).unwrap();
let (combined, _) = boot_info_layout.extend(memory_regions_layout).unwrap();

used.mark_range_as_used(boot_info_address, combined.size());
used.mark_range_as_used(boot_info_address, combined.size() as u64);
}

if let config::Mapping::FixedAddress(framebuffer_address) = config.mappings.framebuffer {
if let Some(framebuffer) = framebuffer {
used.mark_range_as_used(framebuffer_address, framebuffer.info.byte_len);
used.mark_range_as_used(framebuffer_address, framebuffer.info.byte_len as u64);
}
}

Expand Down Expand Up @@ -111,14 +114,9 @@ impl UsedLevel4Entries {
}

/// Marks all p4 entries in the range `[address..address+size)` as used.
///
/// `size` can be a `u64` or `usize`.
fn mark_range_as_used<S>(&mut self, address: u64, size: S)
where
VirtAddr: core::ops::Add<S, Output = VirtAddr>,
{
fn mark_range_as_used(&mut self, address: u64, size: u64) {
let start = VirtAddr::new(address);
let end_inclusive = (start + size) - 1usize;
let end_inclusive = (start + size) - 1;
let start_page = Page::<Size4KiB>::containing_address(start);
let end_page_inclusive = Page::<Size4KiB>::containing_address(end_inclusive);

Expand Down
11 changes: 6 additions & 5 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,9 @@ where
log::info!("Map framebuffer");

let framebuffer_start_frame: PhysFrame = PhysFrame::containing_address(framebuffer.addr);
let framebuffer_end_frame =
PhysFrame::containing_address(framebuffer.addr + framebuffer.info.byte_len - 1u64);
let framebuffer_end_frame = PhysFrame::containing_address(
framebuffer.addr + framebuffer.info.byte_len as u64 - 1u64,
);
let start_page = mapping_addr_page_aligned(
config.mappings.framebuffer,
u64::from_usize(framebuffer.info.byte_len),
Expand Down Expand Up @@ -394,7 +395,7 @@ where
}
};

let entry = &mut kernel_page_table.level_4_table()[index];
let entry = &mut kernel_page_table.level_4_table_mut()[index];
if !entry.is_unused() {
panic!(
"Could not set up recursive mapping: index {} already in use",
Expand Down Expand Up @@ -496,8 +497,8 @@ where
)
.expect("boot info addr is not properly aligned");

let memory_map_regions_addr = boot_info_addr + memory_regions_offset;
let memory_map_regions_end = boot_info_addr + combined.size();
let memory_map_regions_addr = boot_info_addr + memory_regions_offset as u64;
let memory_map_regions_end = boot_info_addr + combined.size() as u64;

let start_page = Page::containing_address(boot_info_addr);
let end_page = Page::containing_address(memory_map_regions_end - 1u64);
Expand Down
4 changes: 2 additions & 2 deletions common/src/load_kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ where
let copy_len = end_inclusive_offset_in_frame - start_offset_in_frame + 1;

// Calculate the physical addresses.
let start_phys_addr = phys_addr.start_address() + start_offset_in_frame;
let start_phys_addr = phys_addr.start_address() + start_offset_in_frame as u64;

// These are the offsets from the start address. These correspond
// to the destination indices in `buf`.
Expand Down Expand Up @@ -416,7 +416,7 @@ where
let copy_len = end_inclusive_offset_in_frame - start_offset_in_frame + 1;

// Calculate the physical addresses.
let start_phys_addr = phys_addr.start_address() + start_offset_in_frame;
let start_phys_addr = phys_addr.start_address() + start_offset_in_frame as u64;

// These are the offsets from the start address. These correspond
// to the destination indices in `buf`.
Expand Down
32 changes: 22 additions & 10 deletions tests/test_kernels/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tests/test_kernels/config_file/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ edition = "2021"

[dependencies]
bootloader_api = { path = "../../../api" }
x86_64 = { version = "0.14.7", default-features = false, features = [
x86_64 = { version = "0.15.2", default-features = false, features = [
"instructions",
"inline_asm",
] }
uart_16550 = "0.2.10"
3 changes: 1 addition & 2 deletions tests/test_kernels/default_settings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ edition = "2021"

[dependencies]
bootloader_api = { path = "../../../api" }
x86_64 = { version = "0.14.7", default-features = false, features = [
x86_64 = { version = "0.15.2", default-features = false, features = [
"instructions",
"inline_asm",
] }
uart_16550 = "0.2.10"
Loading
Loading