diff --git a/Cargo.lock b/Cargo.lock index 7cda21bb..9beea6ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,10 +26,20 @@ dependencies = [ "font8x8 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "llvm-tools 0.1.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.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "x86_64 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "xmas-elf 0.6.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 = "cc" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "fixedvec" version = "0.2.3" @@ -71,11 +81,6 @@ name = "nodrop" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "os_bootinfo" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "pulldown-cmark" version = "0.0.3" @@ -109,6 +114,16 @@ name = "rand_core" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "raw-cpuid" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rdrand" version = "0.4.0" @@ -125,6 +140,27 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "skeptic" version = "0.5.0" @@ -179,14 +215,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "x86_64" -version = "0.3.6" +version = "0.7.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.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ux 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -207,6 +243,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum array-init 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "23589ecb866b460d3a0f1278834750268c607e8e28a1b982c907219f3178cd72" "checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" +"checksum cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "39f75544d7bbaf57560d2168f28fd649ff9c76153874db88bdbdfd839b1a7e7d" "checksum fixedvec 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7c6c16d316ccdac21a4dd648e314e76facbbaf316e83ca137d0857a9c07419d0" "checksum font8x8 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b81d84c3c978af7d05d31a2198af4b9ba956d819d15d8f6d58fc150e33f8dc1f" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" @@ -214,13 +252,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047" "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 os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "66481dbeb5e773e7bd85b63cd6042c30786f834338288c5ec4f3742673db360a" "checksum pulldown-cmark 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8361e81576d2e02643b04950e487ec172b687180da65c731c03cf336784e6c07" "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" "checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" +"checksum raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "30a9d219c32c9132f7be513c18be77c9881c7107d2ab5569d205a6a0f0e6dc7d" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" +"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum skeptic 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "061203a849117b0f7090baf8157aa91dac30545208fbb85166ac58b4ca33d89c" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" @@ -229,6 +270,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum x86_64 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f9258d7e2dd25008d69e8c9e9ee37865887a5e1e3d06a62f1cb3f6c209e6f177" +"checksum x86_64 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5cc744d2d87b185a40e08363136c68ff639cf78119b9189d80064f4c611eb50" "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 79a7045b..95135ce6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ build = "build.rs" [dependencies] xmas-elf = "0.6.2" -x86_64 = "0.3.5" +x86_64 = "0.7.2" usize_conversions = "0.2.0" fixedvec = "0.2.3" diff --git a/README.md b/README.md index 14b65e9b..a9b345ff 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # bootloader -[![Build Status](https://travis-ci.org/rust-osdev/bootloader.svg?branch=master)](https://travis-ci.org/rust-osdev/bootloader) [![Join the chat at https://gitter.im/rust-osdev/bootloader](https://badges.gitter.im/rust-osdev/bootloader.svg)](https://gitter.im/rust-osdev/bootloader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://dev.azure.com/rust-osdev/bootloader/_apis/build/status/rust-osdev.bootloader?branchName=master)](https://dev.azure.com/rust-osdev/bootloader/_build/latest?definitionId=1&branchName=master) [![Join the chat at https://gitter.im/rust-osdev/bootloader](https://badges.gitter.im/rust-osdev/bootloader.svg)](https://gitter.im/rust-osdev/bootloader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) An experimental x86 bootloader written in Rust and inline assembly. diff --git a/src/frame_allocator.rs b/src/frame_allocator.rs index b754a6ac..5b77cdb2 100644 --- a/src/frame_allocator.rs +++ b/src/frame_allocator.rs @@ -1,6 +1,6 @@ use super::{frame_range, phys_frame_range}; use bootloader::bootinfo::{MemoryMap, MemoryRegion, MemoryRegionType}; -use x86_64::structures::paging::{PhysFrame, PhysFrameRange}; +use x86_64::structures::paging::{frame::PhysFrameRange, PhysFrame}; pub(crate) struct FrameAllocator<'a> { pub memory_map: &'a mut MemoryMap, diff --git a/src/main.rs b/src/main.rs index f9f0c078..7649a231 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,9 +15,9 @@ use core::panic::PanicInfo; use core::{mem, slice}; use fixedvec::alloc_stack; use usize_conversions::usize_from; -use x86_64::structures::paging::{Mapper, RecursivePageTable}; use x86_64::structures::paging::{ - Page, PageTableFlags, PhysFrame, PhysFrameRange, Size2MiB, Size4KiB, + frame::PhysFrameRange, Mapper, Page, PageTableFlags, PhysFrame, RecursivePageTable, Size2MiB, + Size4KiB, }; use x86_64::ux::u9; use x86_64::{PhysAddr, VirtAddr}; @@ -227,13 +227,15 @@ fn load_elf( .allocate_frame(MemoryRegionType::BootInfo) .expect("frame allocation failed"); let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE; - page_table::map_page( - page, - frame, - flags, - &mut rec_page_table, - &mut frame_allocator, - ) + unsafe { + page_table::map_page( + page, + frame, + flags, + &mut rec_page_table, + &mut frame_allocator, + ) + } .expect("Mapping of bootinfo page failed") .flush(); page @@ -249,13 +251,15 @@ fn load_elf( for frame in PhysFrame::range_inclusive(start_frame, end_frame) { let page = Page::containing_address(virt_for_phys(frame.start_address())); let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE; - page_table::map_page( - page, - frame, - flags, - &mut rec_page_table, - &mut frame_allocator, - ) + unsafe { + page_table::map_page( + page, + frame, + flags, + &mut rec_page_table, + &mut frame_allocator, + ) + } .expect("Mapping of bootinfo page failed") .flush(); } diff --git a/src/page_table.rs b/src/page_table.rs index 0e5ffda9..c06440b1 100644 --- a/src/page_table.rs +++ b/src/page_table.rs @@ -1,9 +1,9 @@ use crate::frame_allocator::FrameAllocator; use bootloader::bootinfo::MemoryRegionType; use fixedvec::FixedVec; -use x86_64::structures::paging::{self, MapToError, RecursivePageTable, UnmapError}; +use x86_64::structures::paging::mapper::{MapToError, MapperFlush, UnmapError}; use x86_64::structures::paging::{ - Mapper, MapperFlush, Page, PageSize, PageTableFlags, PhysFrame, Size4KiB, + self, Mapper, Page, PageSize, PageTableFlags, PhysFrame, RecursivePageTable, Size4KiB, }; use x86_64::{align_up, PhysAddr, VirtAddr}; use xmas_elf::program::{self, ProgramHeader64}; @@ -31,7 +31,7 @@ pub(crate) fn map_kernel( let frame = frame_allocator .allocate_frame(region_type) .ok_or(MapToError::FrameAllocationFailed)?; - map_page(page, frame, flags, page_table, frame_allocator)?.flush(); + unsafe { map_page(page, frame, flags, page_table, frame_allocator)? }.flush(); } Ok(stack_end.start_address()) @@ -68,7 +68,8 @@ 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; - map_page(page, frame, page_table_flags, page_table, frame_allocator)?.flush(); + unsafe { map_page(page, frame, page_table_flags, page_table, frame_allocator)? } + .flush(); } if mem_size > file_size { @@ -85,13 +86,15 @@ pub(crate) fn map_segment( let new_frame = frame_allocator .allocate_frame(MemoryRegionType::Kernel) .ok_or(MapToError::FrameAllocationFailed)?; - map_page( - temp_page.clone(), - new_frame.clone(), - page_table_flags, - page_table, - frame_allocator, - )? + unsafe { + map_page( + temp_page.clone(), + new_frame.clone(), + page_table_flags, + page_table, + frame_allocator, + )? + } .flush(); type PageArray = [u64; Size4KiB::SIZE as usize / 8]; @@ -114,13 +117,15 @@ pub(crate) fn map_segment( }); } - map_page( - last_page, - new_frame, - page_table_flags, - page_table, - frame_allocator, - )? + unsafe { + map_page( + last_page, + new_frame, + page_table_flags, + page_table, + frame_allocator, + )? + } .flush(); } @@ -134,7 +139,10 @@ pub(crate) fn map_segment( let frame = frame_allocator .allocate_frame(MemoryRegionType::Kernel) .ok_or(MapToError::FrameAllocationFailed)?; - map_page(page, frame, page_table_flags, page_table, frame_allocator)?.flush(); + unsafe { + map_page(page, frame, page_table_flags, page_table, frame_allocator)? + } + .flush(); } // zero @@ -149,7 +157,7 @@ pub(crate) fn map_segment( Ok(()) } -pub(crate) fn map_page<'a, S>( +pub(crate) unsafe fn map_page<'a, S>( page: Page, phys_frame: PhysFrame, flags: PageTableFlags, @@ -162,8 +170,8 @@ where { struct PageTableAllocator<'a, 'b: 'a>(&'a mut FrameAllocator<'b>); - impl<'a, 'b> paging::FrameAllocator for PageTableAllocator<'a, 'b> { - fn alloc(&mut self) -> Option> { + unsafe impl<'a, 'b> paging::FrameAllocator for PageTableAllocator<'a, 'b> { + fn allocate_frame(&mut self) -> Option> { self.0.allocate_frame(MemoryRegionType::PageTable) } }