diff --git a/Cargo.lock b/Cargo.lock index 47dd969..0bf9b20 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" @@ -20,12 +12,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bitflags" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bootloader" -version = "0.8.2" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bit_field 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -37,26 +29,21 @@ version = "0.1.0" dependencies = [ "polling_serial 0.1.0", "vga_buffer 0.1.0", - "x86_64 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", + "x86_64 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "cast" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "dendrobates_tinctoreus_azureus" version = "0.1.0" dependencies = [ - "bootloader 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bootloader 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)", "cache_utils 0.1.0", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "linked_list_allocator 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "linked_list_allocator 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "polling_serial 0.1.0", "vga_buffer 0.1.0", "volatile 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "x86_64 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", + "x86_64 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -69,24 +56,19 @@ dependencies = [ [[package]] name = "linked_list_allocator" -version = "0.6.4" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "spin 0.5.2 (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 = "polling_serial" version = "0.1.0" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "x86_64 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", + "x86_64 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -94,11 +76,6 @@ name = "spin" version = "0.5.2" 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 = "vga_buffer" version = "0.1.0" @@ -115,27 +92,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "x86_64" -version = "0.7.5" +version = "0.9.2" 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.2.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)", + "bitflags 1.2.1 (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.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8a606a02debe2813760609f57a64a2ffd27d9fdf5b2f133eaca0b248dd92cdd2" -"checksum bootloader 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abfbe6cdea6367860818facc8e4a184f003cb83d7d004acaaf57baebf1949da0" -"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" +"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +"checksum bootloader 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "37b4577f46430d7dd1f16fa13a3aab5e3b57fe9ce7ff4378aa6b184e268eb60e" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum linked_list_allocator 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "47314ec1d29aa869ee7cb5a5be57be9b1055c56567d59c3fb6689926743e0bea" -"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" +"checksum linked_list_allocator 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "47de1a43fad0250ee197e9e124e5b5deab3d7b39d4428ae8a6d741ceb340c362" "checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" -"checksum ux 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "88dfeb711b61ce620c0cb6fd9f8e3e678622f0c971da2a63c4b3e25e88ed012f" "checksum volatile 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6af0edf5b4faacc31fc51159244d78d65ec580f021afcef7bd53c04aeabc7f29" -"checksum x86_64 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "997837f3913aac8f67164683258756d712376849906c8d609f844084bc03ef84" +"checksum x86_64 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7467ff985c75f098f9897ea693141dbb25c8a5ceaf91e4a28ab705765932efb6" diff --git a/Cargo.toml b/Cargo.toml index 3be773e..8217ce4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ test-success-exit-code = 33 # (0x10 << 1) | 1 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -x86_64 = "0.7.5" +x86_64 = "0.9.2" vga_buffer = { path = "vga_buffer" } polling_serial = { path = "polling_serial" } volatile = "0.2.6" diff --git a/cache_utils/Cargo.toml b/cache_utils/Cargo.toml index d76badb..b725187 100644 --- a/cache_utils/Cargo.toml +++ b/cache_utils/Cargo.toml @@ -9,4 +9,4 @@ edition = "2018" [dependencies] polling_serial = { path = "../polling_serial" } vga_buffer = { path = "../vga_buffer" } -x86_64 = "0.7.5" +x86_64 = "0.9.2" diff --git a/polling_serial/Cargo.toml b/polling_serial/Cargo.toml index f3f0884..a5c416d 100644 --- a/polling_serial/Cargo.toml +++ b/polling_serial/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -x86_64 = "0.7.5" +x86_64 = "0.9.2" spin = "0.5.2" [dependencies.lazy_static] diff --git a/src/allocator.rs b/src/allocator.rs index 0f26aac..ba46e25 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -1,5 +1,3 @@ -use alloc::alloc::{GlobalAlloc, Layout}; -use core::ptr::null_mut; use polling_serial::serial_println; use x86_64::{ structures::paging::{ @@ -11,22 +9,10 @@ use x86_64::{ pub const HEAP_START: usize = 0x4444_4444_0000; pub const HEAP_SIZE: usize = 0x1 << 20; // 1MB Heap -pub struct Dummy; - -unsafe impl GlobalAlloc for Dummy { - unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { - null_mut() - } - - unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) { - panic!("dealloc should never be called"); - } -} - pub fn init_heap( mapper: &mut impl Mapper, frame_allocator: &mut impl FrameAllocator, -) -> Result<(), MapToError> { +) -> Result<(), MapToError> { let page_range = { let heap_start = VirtAddr::new(HEAP_START as u64); let heap_end = heap_start + HEAP_SIZE as u64 - 1u64; @@ -40,10 +26,7 @@ pub fn init_heap( .allocate_frame() .ok_or(MapToError::FrameAllocationFailed)?; let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE; - unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() }; - if i == 0 { - serial_println!("Mapped {:?} at {:?}", page, frame); - } + mapper.map_to(page, frame, flags, frame_allocator)?.flush(); } unsafe { diff --git a/src/interrupts.rs b/src/interrupts.rs index 3fdd3ee..6cdaf4b 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -32,7 +32,7 @@ extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStackFra x86_64::instructions::bochs_breakpoint(); } -extern "x86-interrupt" fn double_fault_handler(sf: &mut InterruptStackFrame, e: u64) { +extern "x86-interrupt" fn double_fault_handler(sf: &mut InterruptStackFrame, e: u64) -> ! { // LLVM bug causing misaligned stacks when error codes are present. // This code realigns the stack and then grabs the correct values by doing some pointer arithmetic let stack_frame: &mut InterruptStackFrame; diff --git a/src/memory.rs b/src/memory.rs index ea92994..24022c9 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -1,6 +1,7 @@ use x86_64::{ structures::paging::{ FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB, + UnusedPhysFrame, }, PhysAddr, VirtAddr, }; @@ -45,9 +46,11 @@ pub fn create_example_mapping( use x86_64::structures::paging::PageTableFlags as Flags; let frame = PhysFrame::containing_address(PhysAddr::new(0xb8000)); + let not_really_unused_frame = unsafe { UnusedPhysFrame::new(frame) }; let flags = Flags::PRESENT | Flags::WRITABLE; - let map_to_result = unsafe { mapper.map_to(page, frame, flags, frame_allocator) }; + let map_to_result = + unsafe { mapper.map_to(page, not_really_unused_frame, flags, frame_allocator) }; map_to_result.expect("map_to failed").flush(); } @@ -79,13 +82,14 @@ impl BootInfoFrameAllocator { // transform to an iterator of frame start addresses let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096)); // create `PhysFrame` types from the start addresses - frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr))) + let frames = frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr))); + frames } } unsafe impl FrameAllocator for BootInfoFrameAllocator { - fn allocate_frame(&mut self) -> Option { + fn allocate_frame(&mut self) -> Option { let frame = self.usable_frames().nth(self.next); self.next += 1; - frame + frame.map(|f| unsafe { UnusedPhysFrame::new(f) }) } }