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

Update x86_64 to 0.15.2 #490

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 8 additions & 8 deletions common/src/load_kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ where
let end_inclusive_copy_address = cmp::min(end_inclusive_addr, page_end_inclusive);

// These are the offsets into the frame we want to copy from.
let start_offset_in_frame = (start_copy_address - page_start) as usize;
let end_inclusive_offset_in_frame = (end_inclusive_copy_address - page_start) as usize;
let start_offset_in_frame = start_copy_address - page_start;
let end_inclusive_offset_in_frame = end_inclusive_copy_address - page_start;

// Calculate how many bytes we want to copy from this frame.
let copy_len = end_inclusive_offset_in_frame - start_offset_in_frame + 1;
Expand All @@ -362,11 +362,11 @@ where
// SAFETY: We know that this memory is valid because we got it
// as a result from a translation. There are not other
// references to it.
&*core::ptr::slice_from_raw_parts(src_ptr, copy_len)
&*core::ptr::slice_from_raw_parts(src_ptr, copy_len as usize)
};

// Calculate the destination pointer.
let dest = &mut buf[start_offset_in_buf..][..copy_len];
let dest = &mut buf[start_offset_in_buf..][..copy_len as usize];

// Do the actual copy.
dest.copy_from_slice(src);
Expand Down Expand Up @@ -409,8 +409,8 @@ where
let end_inclusive_copy_address = cmp::min(end_inclusive_addr, page_end_inclusive);

// These are the offsets into the frame we want to copy from.
let start_offset_in_frame = (start_copy_address - page_start) as usize;
let end_inclusive_offset_in_frame = (end_inclusive_copy_address - page_start) as usize;
let start_offset_in_frame = start_copy_address - page_start;
let end_inclusive_offset_in_frame = end_inclusive_copy_address - page_start;

// Calculate how many bytes we want to copy from this frame.
let copy_len = end_inclusive_offset_in_frame - start_offset_in_frame + 1;
Expand All @@ -429,11 +429,11 @@ where
// SAFETY: We know that this memory is valid because we got it
// as a result from a translation. There are not other
// references to it.
&mut *core::ptr::slice_from_raw_parts_mut(dest_ptr, copy_len)
&mut *core::ptr::slice_from_raw_parts_mut(dest_ptr, copy_len as usize)
};

// Calculate the destination pointer.
let src = &buf[start_offset_in_buf..][..copy_len];
let src = &buf[start_offset_in_buf..][..copy_len as usize];

// Do the actual copy.
dest.copy_from_slice(src);
Expand Down
Loading
Loading