diff --git a/Cargo.lock b/Cargo.lock index 19149842..b821f22b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,13 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "array-init" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "bit_field" version = "0.9.0" @@ -33,7 +25,7 @@ dependencies = [ "llvm-tools 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "x86_64 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "x86_64 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "xmas-elf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -57,11 +49,6 @@ name = "llvm-tools" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "nodrop" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "serde" version = "1.0.98" @@ -80,21 +67,14 @@ name = "usize_conversions" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "ux" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "x86_64" -version = "0.7.4" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "array-init 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ux 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -111,7 +91,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum array-init 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "23589ecb866b460d3a0f1278834750268c607e8e28a1b982c907219f3178cd72" "checksum bit_field 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a165d606cf084741d4ac3a28fb6e9b1eb0bd31f6cd999098cfddb0b2ab381dc0" "checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56" "checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" @@ -119,11 +98,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fixedvec 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b395ef2adf62bdeefcd1b59ad0dd2225c6c333ec79656ea79ac5285c46d051ea" "checksum font8x8 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "44226c40489fb1d602344a1d8f1b544570c3435e396dda1eda7b5ef010d8f1be" "checksum llvm-tools 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "955be5d0ca0465caf127165acb47964f911e2bc26073e865deb8be7189302faf" -"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5626ac617da2f2d9c48af5515a21d5a480dbd151e01bb1c355e26a3e68113" "checksum toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b8c96d7873fa7ef8bdeb3a9cda3ac48389b4154f32b9803b4bc26220b677b039" "checksum usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f70329e2cbe45d6c97a5112daad40c34cd9a4e18edb5a2a18fefeb584d8d25e5" -"checksum ux 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "88dfeb711b61ce620c0cb6fd9f8e3e678622f0c971da2a63c4b3e25e88ed012f" -"checksum x86_64 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1ad37c1665071808d64e65f7cdae32afcdc90fd7ae7fa402bbda36b824f1add6" +"checksum x86_64 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5d9e3e26fcb51976eafa310e8f2b7a5a83ae8c185443efe50cbc6534a4fffa0d" "checksum xmas-elf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "22678df5df766e8d1e5d609da69f0c3132d794edf6ab5e75e7abcd2270d4cf58" "checksum zero 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5f1bc8a6b2005884962297587045002d8cfb8dcec9db332f4ca216ddc5de82c5" diff --git a/Cargo.toml b/Cargo.toml index a38b5c91..357f2a92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ required-features = ["binary"] [dependencies] xmas-elf = { version = "0.6.2", optional = true } -x86_64 = { version = "0.7.2", optional = true } +x86_64 = { version = "0.8.3", optional = true } usize_conversions = { version = "0.2.0", optional = true } fixedvec = { version = "0.2.4", optional = true } bit_field = { version = "0.10.0", optional = true } diff --git a/src/bootinfo/memory_map.rs b/src/bootinfo/memory_map.rs index c719bd90..bd9eb7fb 100644 --- a/src/bootinfo/memory_map.rs +++ b/src/bootinfo/memory_map.rs @@ -15,6 +15,7 @@ pub struct MemoryMap { } #[doc(hidden)] +#[allow(clippy::new_without_default)] impl MemoryMap { pub fn new() -> Self { MemoryMap { diff --git a/src/frame_allocator.rs b/src/frame_allocator.rs index 5b77cdb2..5630702f 100644 --- a/src/frame_allocator.rs +++ b/src/frame_allocator.rs @@ -1,13 +1,16 @@ use super::{frame_range, phys_frame_range}; use bootloader::bootinfo::{MemoryMap, MemoryRegion, MemoryRegionType}; -use x86_64::structures::paging::{frame::PhysFrameRange, PhysFrame}; +use x86_64::structures::paging::{frame::PhysFrameRange, PhysFrame, UnusedPhysFrame}; pub(crate) struct FrameAllocator<'a> { pub memory_map: &'a mut MemoryMap, } impl<'a> FrameAllocator<'a> { - pub(crate) fn allocate_frame(&mut self, region_type: MemoryRegionType) -> Option { + pub(crate) fn allocate_frame( + &mut self, + region_type: MemoryRegionType, + ) -> Option { // try to find an existing region of same type that can be enlarged let mut iter = self.memory_map.iter_mut().peekable(); while let Some(region) = iter.next() { @@ -17,7 +20,8 @@ impl<'a> FrameAllocator<'a> { && next.region_type == MemoryRegionType::Usable && !next.range.is_empty() { - let frame = phys_frame_range(region.range).end; + let frame = + unsafe { UnusedPhysFrame::new(phys_frame_range(region.range).end) }; region.range.end_frame_number += 1; iter.next().unwrap().range.start_frame_number += 1; return Some(frame); @@ -26,7 +30,7 @@ impl<'a> FrameAllocator<'a> { } } - fn split_usable_region<'a, I>(iter: &mut I) -> Option<(PhysFrame, PhysFrameRange)> + fn split_usable_region<'a, I>(iter: &mut I) -> Option<(UnusedPhysFrame, PhysFrameRange)> where I: Iterator, { @@ -38,9 +42,10 @@ impl<'a> FrameAllocator<'a> { continue; } - let frame = phys_frame_range(region.range).start; + let physframe = phys_frame_range(region.range).start; + let unused_frame = unsafe { UnusedPhysFrame::new(physframe) }; region.range.start_frame_number += 1; - return Some((frame, PhysFrame::range(frame, frame + 1))); + return Some((unused_frame, PhysFrame::range(physframe, physframe + 1))); } None } diff --git a/src/level4_entries.rs b/src/level4_entries.rs index ce877a32..60ace846 100644 --- a/src/level4_entries.rs +++ b/src/level4_entries.rs @@ -1,7 +1,9 @@ use core::convert::TryInto; use fixedvec::FixedVec; -use x86_64::ux; -use x86_64::{structures::paging::Page, VirtAddr}; +use x86_64::{ + structures::paging::{Page, PageTableIndex}, + VirtAddr, +}; use xmas_elf::program::ProgramHeader64; pub struct UsedLevel4Entries { @@ -29,7 +31,7 @@ impl UsedLevel4Entries { used } - pub fn get_free_entry(&mut self) -> ux::u9 { + pub fn get_free_entry(&mut self) -> PageTableIndex { let (idx, entry) = self .entry_state .iter_mut() @@ -38,6 +40,6 @@ impl UsedLevel4Entries { .expect("no usable level 4 entries found"); *entry = true; - ux::u9::new(idx.try_into().unwrap()) + PageTableIndex::new(idx.try_into().unwrap()) } } diff --git a/src/main.rs b/src/main.rs index 66b13fbe..a9e206d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,9 +19,8 @@ use usize_conversions::usize_from; use x86_64::instructions::tlb; use x86_64::structures::paging::{ frame::PhysFrameRange, page_table::PageTableEntry, Mapper, Page, PageTable, PageTableFlags, - PhysFrame, RecursivePageTable, Size2MiB, Size4KiB, + PageTableIndex, PhysFrame, RecursivePageTable, Size2MiB, Size4KiB, UnusedPhysFrame, }; -use x86_64::ux::u9; use x86_64::{PhysAddr, VirtAddr}; // The bootloader_config.rs file contains some configuration constants set by the build script: @@ -170,7 +169,7 @@ fn bootloader_main( enable_nxe_bit(); // Create a recursive page table entry - let recursive_index = u9::new(level4_entries.get_free_entry().try_into().unwrap()); + let recursive_index = PageTableIndex::new(level4_entries.get_free_entry().try_into().unwrap()); let mut entry = PageTableEntry::new(); entry.set_addr( p4_physical, @@ -243,9 +242,9 @@ fn bootloader_main( let boot_info_page = { let page: Page = Page::from_page_table_indices( level4_entries.get_free_entry(), - u9::new(0), - u9::new(0), - u9::new(0), + PageTableIndex::new(0), + PageTableIndex::new(0), + PageTableIndex::new(0), ); let frame = frame_allocator .allocate_frame(MemoryRegionType::BootInfo) @@ -287,9 +286,12 @@ fn bootloader_main( // If offset not manually provided, find a free p4 entry and map memory here. // One level 4 entry spans 2^48/512 bytes (over 500gib) so this should suffice. assert!(max_phys_addr < (1 << 48) / 512); - Page::from_page_table_indices_1gib(level4_entries.get_free_entry(), u9::new(0)) - .start_address() - .as_u64() + Page::from_page_table_indices_1gib( + level4_entries.get_free_entry(), + PageTableIndex::new(0), + ) + .start_address() + .as_u64() }); let virt_for_phys = @@ -304,7 +306,7 @@ fn bootloader_main( unsafe { page_table::map_page( page, - frame, + UnusedPhysFrame::new(frame), flags, &mut rec_page_table, &mut frame_allocator, diff --git a/src/page_table.rs b/src/page_table.rs index 6d7ef5a7..7aa1180c 100644 --- a/src/page_table.rs +++ b/src/page_table.rs @@ -4,6 +4,7 @@ use fixedvec::FixedVec; use x86_64::structures::paging::mapper::{MapToError, MapperFlush, UnmapError}; use x86_64::structures::paging::{ self, Mapper, Page, PageSize, PageTableFlags, PhysFrame, RecursivePageTable, Size4KiB, + UnusedPhysFrame, }; use x86_64::{align_up, PhysAddr, VirtAddr}; use xmas_elf::program::{self, ProgramHeader64}; @@ -68,8 +69,16 @@ pub(crate) fn map_segment( for frame in PhysFrame::range_inclusive(start_frame, end_frame) { let offset = frame - start_frame; let page = start_page + offset; - unsafe { map_page(page, frame, page_table_flags, page_table, frame_allocator)? } - .flush(); + unsafe { + map_page( + page, + UnusedPhysFrame::new(frame), + page_table_flags, + page_table, + frame_allocator, + )? + } + .flush(); } if mem_size > file_size { @@ -89,7 +98,7 @@ pub(crate) fn map_segment( unsafe { map_page( temp_page.clone(), - new_frame.clone(), + UnusedPhysFrame::new(new_frame.clone()), page_table_flags, page_table, frame_allocator, @@ -159,7 +168,7 @@ pub(crate) fn map_segment( pub(crate) unsafe fn map_page<'a, S>( page: Page, - phys_frame: PhysFrame, + phys_frame: UnusedPhysFrame, flags: PageTableFlags, page_table: &mut RecursivePageTable<'a>, frame_allocator: &mut FrameAllocator, @@ -171,7 +180,7 @@ where struct PageTableAllocator<'a, 'b: 'a>(&'a mut FrameAllocator<'b>); unsafe impl<'a, 'b> paging::FrameAllocator for PageTableAllocator<'a, 'b> { - fn allocate_frame(&mut self) -> Option> { + fn allocate_frame(&mut self) -> Option> { self.0.allocate_frame(MemoryRegionType::PageTable) } }