From 797964df837bba0f964f5bc348d3db60233b8a44 Mon Sep 17 00:00:00 2001 From: Dan Cross Date: Tue, 30 Jan 2024 19:37:14 +0000 Subject: [PATCH] Update rust, deps, fix exposed issues Update Rust and dependencies, and fix a number of exposed issues that popped up as a result. This code is now clippy-clean. Signed-off-by: Dan Cross --- Cargo.lock | 159 ++++++++++++++---------------- aarch64/src/kalloc.rs | 4 +- aarch64/src/kmem.rs | 10 +- aarch64/src/mailbox.rs | 8 +- aarch64/src/main.rs | 8 +- aarch64/src/runtime.rs | 2 +- aarch64/src/trap.rs | 4 +- aarch64/src/vm.rs | 32 +++--- lib/riscv64-unknown-none-elf.json | 4 +- lib/x86_64-unknown-none-elf.json | 4 +- port/src/dat.rs | 16 +-- port/src/devcons.rs | 8 +- port/src/fdt.rs | 18 ++-- port/src/lib.rs | 2 +- riscv64/src/main.rs | 2 +- rust-toolchain.toml | 2 +- x86_64/src/dat.rs | 2 +- x86_64/src/devcons.rs | 5 +- x86_64/src/main.rs | 5 +- xtask/src/main.rs | 7 +- 20 files changed, 151 insertions(+), 151 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b0afa4..ada5b56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.5.0" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" dependencies = [ "anstyle", "anstyle-parse", @@ -27,33 +27,33 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.2" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c4c2c83f81532e5845a733998b6971faca23490340a418e9b72a3ec9de12ea" +checksum = "2faccea4cc4ab4a667ce676a30e8ec13922a692c99bb8f5b11f1502c72e04220" [[package]] name = "anstyle-parse" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" dependencies = [ "windows-sys", ] [[package]] name = "anstyle-wincon" -version = "2.1.0" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" dependencies = [ "anstyle", "windows-sys", @@ -73,9 +73,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "bitstruct" @@ -99,20 +99,19 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.0" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d5f1946157a96594eb2d2c10eb7ad9a2b27518cb3000209dec700c35df9197d" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" dependencies = [ "clap_builder", "clap_derive", - "once_cell", ] [[package]] name = "clap_builder" -version = "4.4.0" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78116e32a042dd73c2901f0dc30790d20ff3447f3e3472fad359e8c3d282bcd6" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" dependencies = [ "anstream", "anstyle", @@ -122,21 +121,21 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.0" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9fd1a5729c4548118d7d70ff234a44868d00489a4b6597b0b020918a0e91a1a" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.48", ] [[package]] name = "clap_lex" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "colorchoice" @@ -152,9 +151,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" [[package]] name = "heck" @@ -164,9 +163,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "indexmap" -version = "2.0.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "433de089bd45971eecf4668ee0ee8f4cec17db4f8bd8f7bc3197a6ce37aa7d9b" dependencies = [ "equivalent", "hashbrown", @@ -174,57 +173,51 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "num_enum" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70bf6736f74634d299d00086f02986875b3c2d924781a6a2cb6c201e73da0ceb" +checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" dependencies = [ "num_enum_derive", ] [[package]] name = "num_enum_derive" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56ea360eafe1022f7cc56cd7b869ed57330fb2453d0c7831d99b74c65d2f5597" +checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.48", ] -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - [[package]] name = "port" version = "0.1.0" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.2", ] [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -247,29 +240,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.186" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f5db24220c009de9bd45e69fb2938f4b6d2df856aa9304ce377b3180f83b7c1" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.186" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad697f7e0b65af4983a4ce8f56ed5b357e8d3c36651bf6a7e13639c17b8e670" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.48", ] [[package]] name = "serde_spanned" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ "serde", ] @@ -293,9 +286,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.29" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -304,15 +297,15 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.12" +version = "0.12.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" +checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae" [[package]] name = "toml" -version = "0.8.0" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c226a7bba6d859b63c92c4b4fe69c5b6b72d0cb897dbc8e6012298e6154cb56e" +checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" dependencies = [ "serde", "serde_spanned", @@ -322,18 +315,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.20.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ff63e60a958cefbb518ae1fd6566af80d9d4be430a33f3723dfc47d1d411d95" +checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" dependencies = [ "indexmap", "serde", @@ -344,9 +337,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "utf8parse" @@ -356,18 +349,18 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "windows-sys" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.48.5" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -380,51 +373,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.5" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" [[package]] name = "windows_aarch64_msvc" -version = "0.48.5" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" [[package]] name = "windows_i686_gnu" -version = "0.48.5" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" [[package]] name = "windows_i686_msvc" -version = "0.48.5" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" [[package]] name = "windows_x86_64_gnu" -version = "0.48.5" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.5" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" [[package]] name = "windows_x86_64_msvc" -version = "0.48.5" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.15" +version = "0.5.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +checksum = "1931d78a9c73861da0134f453bb1f790ce49b2e30eba8410b4b79bac72b46a2d" dependencies = [ "memchr", ] diff --git a/aarch64/src/kalloc.rs b/aarch64/src/kalloc.rs index ff50101..7bdb886 100644 --- a/aarch64/src/kalloc.rs +++ b/aarch64/src/kalloc.rs @@ -39,7 +39,7 @@ impl FreeList { pub unsafe fn free_pages(pages: &mut [Page4K]) { static mut NODE: LockNode = LockNode::new(); - let mut lock = FREE_LIST.lock(unsafe { &NODE }); + let mut lock = FREE_LIST.lock(unsafe { &*ptr::addr_of!(NODE) }); let fl = &mut *lock; for page in pages.iter_mut() { fl.put(page); @@ -48,7 +48,7 @@ pub unsafe fn free_pages(pages: &mut [Page4K]) { pub fn alloc() -> Result<&'static mut Page4K, Error> { static mut NODE: LockNode = LockNode::new(); - let mut lock = FREE_LIST.lock(unsafe { &NODE }); + let mut lock = FREE_LIST.lock(unsafe { &*ptr::addr_of!(NODE) }); let fl = &mut *lock; fl.get() } diff --git a/aarch64/src/kmem.rs b/aarch64/src/kmem.rs index a5c8f26..582b8fa 100644 --- a/aarch64/src/kmem.rs +++ b/aarch64/src/kmem.rs @@ -55,7 +55,7 @@ impl PhysAddr { self.0 } - pub const fn to_virt(&self) -> usize { + pub const fn as_virt(&self) -> usize { (self.0 as usize).wrapping_add(KZERO) } @@ -67,8 +67,8 @@ impl PhysAddr { Self::from_virt(a.addr()) } - pub const fn to_ptr_mut(&self) -> *mut T { - self.to_virt() as *mut T + pub const fn as_ptr_mut(&self) -> *mut T { + self.as_virt() as *mut T } pub const fn round_up(&self, step: u64) -> PhysAddr { @@ -102,11 +102,11 @@ impl Step for PhysAddr { } fn forward_checked(startpa: Self, count: usize) -> Option { - startpa.0.checked_add(count as u64).map(|x| PhysAddr(x)) + startpa.0.checked_add(count as u64).map(PhysAddr) } fn backward_checked(startpa: Self, count: usize) -> Option { - startpa.0.checked_sub(count as u64).map(|x| PhysAddr(x)) + startpa.0.checked_sub(count as u64).map(PhysAddr) } } diff --git a/aarch64/src/mailbox.rs b/aarch64/src/mailbox.rs index 1e95e3c..587c2df 100644 --- a/aarch64/src/mailbox.rs +++ b/aarch64/src/mailbox.rs @@ -19,8 +19,8 @@ static MAILBOX: Lock> = Lock::new("mailbox", None); /// can be made at a time. We have no heap at this point, so creating a mailbox /// that can be initialised based off the devicetree is rather convoluted. pub fn init(dt: &DeviceTree) { - static mut NODE: LockNode = LockNode::new(); - let mut mailbox = MAILBOX.lock(unsafe { &NODE }); + let node = LockNode::new(); + let mut mailbox = MAILBOX.lock(&node); *mailbox = Some({ static mut MAYBE_MAILBOX: MaybeUninit = MaybeUninit::uninit(); unsafe { @@ -124,8 +124,8 @@ where let size = mem::size_of::>() as u32; let req = Request::> { size, code, tags: *tags }; let mut msg = MessageWithTags { request: req }; - static mut NODE: LockNode = LockNode::new(); - let mut mailbox = MAILBOX.lock(unsafe { &NODE }); + let node = LockNode::new(); + let mut mailbox = MAILBOX.lock(&node); mailbox.as_deref_mut().unwrap().request(&mut msg); let res = unsafe { msg.response }; res.tags.body diff --git a/aarch64/src/main.rs b/aarch64/src/main.rs index 590a39b..a62c7e0 100644 --- a/aarch64/src/main.rs +++ b/aarch64/src/main.rs @@ -1,5 +1,6 @@ #![allow(clippy::upper_case_acronyms)] -#![cfg_attr(not(any(test, feature = "cargo-clippy")), no_std)] +#![allow(internal_features)] +#![cfg_attr(not(any(test)), no_std)] #![cfg_attr(not(test), no_main)] #![feature(alloc_error_handler)] #![feature(asm_const)] @@ -24,6 +25,7 @@ mod vm; use crate::kmem::{PhysAddr, PhysRange}; use crate::vm::kernel_root; use core::ffi::c_void; +use core::ptr; use port::fdt::DeviceTree; use port::println; use vm::PageTable; @@ -122,8 +124,8 @@ pub extern "C" fn main9(dtb_va: usize) { kalloc::free_pages(kmem::early_pages()); let dtb_range = PhysRange::with_len(PhysAddr::from_virt(dtb_va).addr(), dt.size()); - vm::init(&dt, &mut KPGTBL, dtb_range); - vm::switch(&KPGTBL); + vm::init(&dt, &mut *ptr::addr_of_mut!(KPGTBL), dtb_range); + vm::switch(&*ptr::addr_of!(KPGTBL)); } print_binary_sections(); diff --git a/aarch64/src/runtime.rs b/aarch64/src/runtime.rs index 8109bbf..abf04a3 100644 --- a/aarch64/src/runtime.rs +++ b/aarch64/src/runtime.rs @@ -16,7 +16,7 @@ use port::mem::VirtRange; // - Add support for raspi4 #[panic_handler] pub fn panic(info: &PanicInfo) -> ! { - let mmio = rpi_mmio().expect("mmio base detect failed").start().to_virt(); + let mmio = rpi_mmio().expect("mmio base detect failed").start().as_virt(); let gpio_range = VirtRange::with_len(mmio + 0x200000, 0xb4); let aux_range = VirtRange::with_len(mmio + 0x215000, 0x8); diff --git a/aarch64/src/trap.rs b/aarch64/src/trap.rs index e557a4f..eadcec7 100644 --- a/aarch64/src/trap.rs +++ b/aarch64/src/trap.rs @@ -67,5 +67,7 @@ fn trap(frame: &mut TrapFrame) { // Just print out the frame and loop for now // TODO Make it a little prettier and more space efficient println!("{:#x?}", frame); - loop {} + loop { + core::hint::spin_loop(); + } } diff --git a/aarch64/src/vm.rs b/aarch64/src/vm.rs index 03be69b..ec9a853 100644 --- a/aarch64/src/vm.rs +++ b/aarch64/src/vm.rs @@ -14,9 +14,9 @@ use port::fdt::DeviceTree; #[cfg(not(test))] use port::println; -pub const PAGE_SIZE_4K: usize = 4 * 1024; -pub const PAGE_SIZE_2M: usize = 2 * 1024 * 1024; -pub const PAGE_SIZE_1G: usize = 1 * 1024 * 1024 * 1024; +pub const PAGE_SIZE_4K: usize = 4 << 10; +pub const PAGE_SIZE_2M: usize = 2 << 20; +pub const PAGE_SIZE_1G: usize = 1 << 30; #[allow(dead_code)] #[derive(Debug, Clone, Copy, PartialEq)] @@ -76,10 +76,10 @@ pub enum AccessPermission { #[repr(u8)] pub enum Shareable { #[num_enum(default)] - NonShareable = 0, // Non-shareable (single core) - Unpredictable = 1, // Unpredicatable! - OuterShareable = 2, // Outer shareable (shared across CPUs, GPU) - InnerShareable = 3, // Inner shareable (shared across CPUs) + Non = 0, // Non-shareable (single core) + Unpredictable = 1, // Unpredicatable! + Outer = 2, // Outer shareable (shared across CPUs, GPU) + Inner = 3, // Inner shareable (shared across CPUs) } bitstruct! { @@ -111,7 +111,7 @@ impl Entry { fn rw_kernel_data() -> Self { Entry(0) - .with_shareable(Shareable::InnerShareable) + .with_shareable(Shareable::Inner) .with_accessed(true) .with_uxn(true) .with_pxn(true) @@ -122,7 +122,7 @@ impl Entry { fn ro_kernel_data() -> Self { Entry(0) .with_access_permission(AccessPermission::PrivRo) - .with_shareable(Shareable::InnerShareable) + .with_shareable(Shareable::Inner) .with_accessed(true) .with_uxn(true) .with_pxn(true) @@ -133,7 +133,7 @@ impl Entry { fn ro_kernel_text() -> Self { Entry(0) .with_access_permission(AccessPermission::PrivRw) - .with_shareable(Shareable::InnerShareable) + .with_shareable(Shareable::Inner) .with_accessed(true) .with_uxn(true) .with_pxn(false) @@ -144,7 +144,7 @@ impl Entry { fn ro_kernel_device() -> Self { Entry(0) .with_access_permission(AccessPermission::PrivRw) - .with_shareable(Shareable::InnerShareable) + .with_shareable(Shareable::Inner) .with_accessed(true) .with_uxn(true) .with_pxn(true) @@ -162,7 +162,7 @@ impl Entry { } fn virt_page_addr(self) -> usize { - self.phys_page_addr().to_virt() + self.phys_page_addr().as_virt() } fn table(self, level: Level) -> bool { @@ -394,7 +394,7 @@ impl PageTable { invalidate_all_tlb_entries(); } - return Ok(()); + Ok(()) } /// Map the physical range using the requested page size. @@ -413,7 +413,7 @@ impl PageTable { let mut startva = None; let mut endva = 0; for pa in range.step_by_rounded(page_size.size()) { - let va = pa.to_virt(); + let va = pa.as_virt(); self.map_to(entry.with_phys_addr(pa), va, page_size)?; startva.get_or_insert(va); endva = va + page_size.size(); @@ -469,7 +469,7 @@ fn print_pte(indent: usize, i: usize, level: Level, pte: Entry) { } } -pub unsafe fn init(dt: &DeviceTree, kpage_table: &mut PageTable, dtb_range: PhysRange) { +pub unsafe fn init(_dt: &DeviceTree, kpage_table: &mut PageTable, dtb_range: PhysRange) { // We use recursive page tables, but we have to be careful in the init call, // since the kpage_table is not currently pointed to by ttbr1_el1. Any // recursive addressing of (511, 511, 511, 511) always points to the @@ -577,7 +577,7 @@ pub unsafe fn invalidate_all_tlb_entries() { /// Return the root kernel page table pub fn kernel_root() -> &'static mut PageTable { - unsafe { &mut *PhysAddr::new(ttbr1_el1()).to_ptr_mut::() } + unsafe { &mut *PhysAddr::new(ttbr1_el1()).as_ptr_mut::() } } #[cfg(test)] diff --git a/lib/riscv64-unknown-none-elf.json b/lib/riscv64-unknown-none-elf.json index 38d12f4..33ba992 100644 --- a/lib/riscv64-unknown-none-elf.json +++ b/lib/riscv64-unknown-none-elf.json @@ -2,7 +2,7 @@ "arch": "riscv64", "code-model": "medium", "cpu": "generic-rv64", - "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n64-S128", + "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128", "eh-frame-header": false, "emit-debug-gdb-scripts": false, "features": "+m,+a,+f,+d,+c", @@ -20,4 +20,4 @@ "-nostdlib" ] } -} \ No newline at end of file +} diff --git a/lib/x86_64-unknown-none-elf.json b/lib/x86_64-unknown-none-elf.json index a703a4b..b312674 100644 --- a/lib/x86_64-unknown-none-elf.json +++ b/lib/x86_64-unknown-none-elf.json @@ -1,6 +1,6 @@ { "llvm-target": "x86_64-unknown-none-elf", - "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", "linker-flavor": "ld.lld", "linker": "rust-lld", "target-endian": "little", @@ -20,4 +20,4 @@ "-nostdlib" ] } -} \ No newline at end of file +} diff --git a/port/src/dat.rs b/port/src/dat.rs index e8b4584..22f6070 100644 --- a/port/src/dat.rs +++ b/port/src/dat.rs @@ -5,6 +5,8 @@ use bitflags::bitflags; use core::ptr::NonNull; use core::result::Result; +pub struct Error {} + pub struct Chan { _offset: u64, _devoffset: u64, @@ -59,18 +61,18 @@ pub trait Dev { fn shutdown(); fn attach(spec: &[u8]) -> Chan; fn walk(&self, c: &Chan, nc: &mut Chan, name: &[&[u8]]) -> Walkqid; - fn stat(&self, c: &Chan, sb: &mut [u8]) -> Result<(), ()>; + fn stat(&self, c: &Chan, sb: &mut [u8]) -> Result<(), Error>; fn open(&mut self, c: &Chan, mode: u32) -> Chan; fn create(&mut self, c: &mut Chan, name: &[u8], mode: Mode, perms: u32); fn close(&mut self, c: Chan); - fn read(&mut self, c: &mut Chan, buf: &mut [u8], offset: u64) -> Result; - fn bread(&mut self, c: &mut Chan, bnum: u64, offset: u64) -> Result; - fn write(&mut self, c: &mut Chan, buf: &[u8], offset: u64) -> Result; - fn bwrite(&mut self, c: &mut Chan, block: &Block, offset: u64) -> Result; + fn read(&mut self, c: &mut Chan, buf: &mut [u8], offset: u64) -> Result; + fn bread(&mut self, c: &mut Chan, bnum: u64, offset: u64) -> Result; + fn write(&mut self, c: &mut Chan, buf: &[u8], offset: u64) -> Result; + fn bwrite(&mut self, c: &mut Chan, block: &Block, offset: u64) -> Result; fn remove(&mut self, c: &mut Chan); - fn wstat(&mut self, c: &mut Chan, sb: &[u8]) -> Result<(), ()>; + fn wstat(&mut self, c: &mut Chan, sb: &[u8]) -> Result<(), Error>; fn power(&mut self, on: bool); - fn config(&mut self /* other args */) -> Result<(), ()>; + fn config(&mut self /* other args */) -> Result<(), Error>; } pub struct Block { diff --git a/port/src/devcons.rs b/port/src/devcons.rs index 7b85013..e6cb53b 100644 --- a/port/src/devcons.rs +++ b/port/src/devcons.rs @@ -32,8 +32,8 @@ impl Console { where F: FnOnce() -> &'static mut dyn Uart, { - static mut NODE: LockNode = LockNode::new(); - let mut cons = CONS.lock(unsafe { &NODE }); + let node = LockNode::new(); + let mut cons = CONS.lock(&node); *cons = Some(uart_fn()); Self } @@ -41,8 +41,8 @@ impl Console { pub fn putstr(&mut self, s: &str) { // XXX: Just for testing. - static mut NODE: LockNode = LockNode::new(); - let mut uart_guard = CONS.lock(unsafe { &NODE }); + let node = LockNode::new(); + let mut uart_guard = CONS.lock(&node); let uart = uart_guard.as_deref_mut().unwrap(); for b in s.bytes() { putb(uart, b); diff --git a/port/src/fdt.rs b/port/src/fdt.rs index ed3d2bb..4fa1fc6 100644 --- a/port/src/fdt.rs +++ b/port/src/fdt.rs @@ -68,6 +68,9 @@ impl<'a> DeviceTree<'a> { } /// Given a pointer to the dtb as a usize, return a DeviceTree struct. + /// + /// # Safety + /// The caller must ensure that `ptr` is a valid virtual address. pub unsafe fn from_usize(ptr: usize) -> Result { let u8ptr = ptr as *const mem::MaybeUninit; @@ -79,8 +82,7 @@ impl<'a> DeviceTree<'a> { let len = dtb_for_header.header.totalsize as usize; // Extract the buffer for real - let dtb_buf: &[mem::MaybeUninit] = - unsafe { core::slice::from_raw_parts(u8ptr as *const MaybeUninit, len) }; + let dtb_buf: &[mem::MaybeUninit] = unsafe { core::slice::from_raw_parts(u8ptr, len) }; FdtHeader::new(dtb_buf, false).map(|header| Self { data: dtb_buf, header }) } @@ -158,7 +160,7 @@ impl<'a> DeviceTree<'a> { pub fn property_value_as_u32(&self, prop: &Property) -> Option { let value_end = prop.value_start + prop.value_len; - self.structs().get(prop.value_start..value_end).and_then(|bs| bytes_to_u32(bs)) + self.structs().get(prop.value_start..value_end).and_then(bytes_to_u32) } pub fn property_value_as_u32_iter(&self, prop: &Property) -> impl Iterator + '_ { @@ -170,7 +172,7 @@ impl<'a> DeviceTree<'a> { } let (start, end) = (value_i, value_i + 4); value_i = end; - return self.structs().get(start..end).and_then(|bs| bytes_to_u32(bs)); + return self.structs().get(start..end).and_then(bytes_to_u32); }) } @@ -191,7 +193,7 @@ impl<'a> DeviceTree<'a> { let bytes_fn = if num_cells == 1 { bytes_to_u32_as_u64 } else { bytes_to_u64 }; let start = value_i; let end = value_i + (num_cells * 4); - self.structs().get(start..end).and_then(|bs| bytes_fn(bs)) + self.structs().get(start..end).and_then(bytes_fn) } /// Return the reg values as u64 whether the size is 1 or 2 cells. @@ -542,7 +544,7 @@ impl<'a> DeviceTree<'a> { } fn parse_token(structs: &[mem::MaybeUninit], i: usize) -> Option { - let token = structs.get(i..).and_then(|bs| bytes_to_u32(bs)); + let token = structs.get(i..).and_then(bytes_to_u32); match token { Some(0x1) => { @@ -562,8 +564,8 @@ impl<'a> DeviceTree<'a> { } Some(0x2) => Some(FdtToken::EndNode(FdtTokenContext { start: i, total_len: 4 })), Some(0x3) => { - let len = structs.get((i + 4)..).and_then(|bs| bytes_to_u32(bs)).unwrap_or(0); - let nameoff = structs.get((i + 8)..).and_then(|bs| bytes_to_u32(bs)).unwrap_or(0); + let len = structs.get((i + 4)..).and_then(bytes_to_u32).unwrap_or(0); + let nameoff = structs.get((i + 8)..).and_then(bytes_to_u32).unwrap_or(0); Some(FdtToken::Prop(FdtPropContext { start: i, name_start: nameoff as usize, diff --git a/port/src/lib.rs b/port/src/lib.rs index f0e77ef..e152358 100644 --- a/port/src/lib.rs +++ b/port/src/lib.rs @@ -1,5 +1,5 @@ #![allow(clippy::upper_case_acronyms)] -#![cfg_attr(not(any(test, feature = "cargo-clippy")), no_std)] +#![cfg_attr(not(any(test)), no_std)] #![feature(maybe_uninit_slice)] #![forbid(unsafe_op_in_unsafe_fn)] diff --git a/riscv64/src/main.rs b/riscv64/src/main.rs index 03fbc24..19f1621 100644 --- a/riscv64/src/main.rs +++ b/riscv64/src/main.rs @@ -1,7 +1,7 @@ #![feature(alloc_error_handler)] #![feature(asm_const)] #![feature(panic_info_message)] -#![cfg_attr(not(any(test, feature = "cargo-clippy")), no_std)] +#![cfg_attr(not(any(test)), no_std)] #![cfg_attr(not(test), no_main)] #![allow(clippy::upper_case_acronyms)] #![forbid(unsafe_op_in_unsafe_fn)] diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 3ee535f..9cd1ac4 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2023-06-05" +channel = "nightly-2024-01-30" components = [ "rustfmt", "rust-src", "clippy", "llvm-tools" ] targets = [ "aarch64-unknown-none", diff --git a/x86_64/src/dat.rs b/x86_64/src/dat.rs index ab0c014..8337712 100644 --- a/x86_64/src/dat.rs +++ b/x86_64/src/dat.rs @@ -1 +1 @@ -// \ No newline at end of file +// diff --git a/x86_64/src/devcons.rs b/x86_64/src/devcons.rs index e266f9a..b4c2781 100644 --- a/x86_64/src/devcons.rs +++ b/x86_64/src/devcons.rs @@ -1,5 +1,6 @@ // Racy to start. +use core::cell::SyncUnsafeCell; use port::devcons::{Console, Uart}; struct Uart16550 { @@ -14,7 +15,7 @@ impl Uart for Uart16550 { pub fn init() { Console::new(|| { - static mut UART: Uart16550 = Uart16550 { port: 0x3f8 }; - unsafe { &mut UART } + static UART: SyncUnsafeCell = SyncUnsafeCell::new(Uart16550 { port: 0x3f8 }); + unsafe { &mut *UART.get() } }); } diff --git a/x86_64/src/main.rs b/x86_64/src/main.rs index f0a312a..cd85932 100644 --- a/x86_64/src/main.rs +++ b/x86_64/src/main.rs @@ -1,7 +1,8 @@ #![feature(alloc_error_handler)] #![feature(asm_const)] #![feature(naked_functions)] -#![cfg_attr(not(any(test, feature = "cargo-clippy")), no_std)] +#![feature(sync_unsafe_cell)] +#![cfg_attr(not(any(test)), no_std)] #![cfg_attr(not(test), no_main)] #![allow(clippy::upper_case_acronyms)] #![forbid(unsafe_op_in_unsafe_fn)] @@ -40,7 +41,7 @@ pub extern "C" fn main9() { println!("looping now"); let mut ctx = Label::new(); let mut thr = Label::new(); - thr.pc = jumpback as u64; + thr.pc = jumpback as usize as u64; unsafe { thr.sp = &mut THRSTACK[1023] as *mut _ as u64; CTX = &mut ctx as *mut _ as u64; diff --git a/xtask/src/main.rs b/xtask/src/main.rs index ae55200..88ca412 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -98,10 +98,7 @@ impl RustupState { return Err(String::from_utf8(output.stdout.clone())?.into()); } - Ok(String::from_utf8(output.stdout.clone())? - .lines() - .flat_map(|line| Triple::from_str(line)) - .collect()) + Ok(String::from_utf8(output.stdout.clone())?.lines().flat_map(Triple::from_str).collect()) } /// For the given arch, return a compatible toolchain triple that is @@ -506,7 +503,7 @@ impl QemuStep { //cmd.arg("-curses"); // cmd.arg("-bios").arg("none"); let dump_dtb = &self.dump_dtb; - if dump_dtb != "" { + if !dump_dtb.is_empty() { cmd.arg("-machine").arg(format!("virt,dumpdtb={dump_dtb}")); } else { cmd.arg("-machine").arg("virt");