From 032910cc5655e85c37c1124092bd4e952040da7b Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 10 Sep 2024 22:40:45 +0200 Subject: [PATCH] switch to the latest rust tool chain - remove the usage of the crate x86_64 --- Cargo.lock | 213 ++++++++++++++++++---------------- Cargo.toml | 7 +- aarch64-eduos.json | 16 --- rust-toolchain.toml | 2 +- src/arch/aarch64/mod.rs | 3 - src/arch/aarch64/processor.rs | 4 - src/arch/aarch64/serial.rs | 34 ------ src/arch/aarch64/start.rs | 20 ---- src/arch/mod.rs | 36 ++---- src/arch/x86_64/processor.rs | 4 +- src/arch/x86_64/serial.rs | 4 +- src/arch/x86_64/start.rs | 10 +- src/lib.rs | 1 - src/main.rs | 9 +- x86_64-eduos.json | 4 +- 15 files changed, 138 insertions(+), 229 deletions(-) delete mode 100644 aarch64-eduos.json delete mode 100644 src/arch/aarch64/mod.rs delete mode 100644 src/arch/aarch64/processor.rs delete mode 100644 src/arch/aarch64/serial.rs delete mode 100644 src/arch/aarch64/start.rs diff --git a/Cargo.lock b/Cargo.lock index 87b40813..8cc5342a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bit_field" @@ -20,12 +20,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - [[package]] name = "bootloader" version = "0.9.29" @@ -33,183 +27,196 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "365861702868e2a37b4247aaecc7bd8f4389baec8d025497ad8ba7ff37ee9440" [[package]] -name = "cfg-if" -version = "1.0.0" +name = "bumpalo" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] -name = "cfg_aliases" -version = "0.1.1" +name = "cfg-if" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "eduos-rs" version = "0.1.0" dependencies = [ "bootloader", - "hermit-sync", - "qemu-exit", "semihosting", + "spinning_top", + "wasm-bindgen", + "web-sys", "x86", - "x86_64", ] [[package]] -name = "exclusive_cell" -version = "0.1.0" +name = "js-sys" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5b9e9908e50b47ebbc3d6fd66ed295b997c270e8d2312a035bcc62722a160ef" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] [[package]] -name = "generic_once_cell" -version = "0.1.1" +name = "lock_api" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c27ddeab45f9c2238a860db235b3e80ce23651fa8293b6f7f53fb72cbb5ce539" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "lock_api", + "autocfg", + "scopeguard", ] [[package]] -name = "hermit-sync" -version = "0.1.6" +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "once_cell" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3111d3f7c7088383182bb9807ecbcd2ed2be4a3c967d740b287b520d8cb8be75" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "proc-macro2" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ - "exclusive_cell", - "generic_once_cell", - "interrupt-mutex", - "interrupts", - "lock_api", - "one-shot-mutex", - "spinning_top", + "unicode-ident", ] [[package]] -name = "interrupt-mutex" -version = "0.1.0" +name = "quote" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3257a88802f4c0857934e5c0bedd80f755a5a08afb1294c5188ca97e4a7f76c0" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "interrupts", - "lock_api", + "proc-macro2", ] [[package]] -name = "interrupts" -version = "0.1.5" +name = "raw-cpuid" +version = "10.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ccb0bdc9cefc5772ebc23d9bd94aabf408ab6753735f1936ac6ed7e714c8c6" +checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332" dependencies = [ - "cfg-if", - "nix", + "bitflags", ] [[package]] -name = "libc" -version = "0.2.154" +name = "scopeguard" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] -name = "lock_api" -version = "0.4.10" +name = "semihosting" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" -dependencies = [ - "autocfg", - "scopeguard", -] +checksum = "a5260e8474680a4617e36cee7f4602655c89146bde012a5b6ba7cc080ec49dcd" [[package]] -name = "nix" -version = "0.28.0" +name = "spinning_top" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" +checksum = "d96d2d1d716fb500937168cc09353ffdc7a012be8475ac7308e1bdf0e3923300" dependencies = [ - "bitflags 2.5.0", - "cfg-if", - "cfg_aliases", - "libc", + "lock_api", ] [[package]] -name = "one-shot-mutex" -version = "0.1.1" +name = "syn" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c32f39cf70e43cb1488b67fd6adbc9c0ccaac00fe751ee0d02f82fcfe6267e2" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ - "lock_api", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "qemu-exit" -version = "3.0.2" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bb0fd6580eeed0103c054e3fba2c2618ff476943762f28a645b63b8692b21c9" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] -name = "raw-cpuid" -version = "10.7.0" +name = "wasm-bindgen" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ - "bitflags 1.3.2", + "cfg-if", + "wasm-bindgen-macro", ] [[package]] -name = "rustversion" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" - -[[package]] -name = "scopeguard" -version = "1.2.0" +name = "wasm-bindgen-backend" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] [[package]] -name = "semihosting" -version = "0.1.9" +name = "wasm-bindgen-macro" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5260e8474680a4617e36cee7f4602655c89146bde012a5b6ba7cc080ec49dcd" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] [[package]] -name = "spinning_top" -version = "0.3.0" +name = "wasm-bindgen-macro-support" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96d2d1d716fb500937168cc09353ffdc7a012be8475ac7308e1bdf0e3923300" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ - "lock_api", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", ] [[package]] -name = "volatile" -version = "0.4.6" +name = "wasm-bindgen-shared" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] -name = "x86" -version = "0.52.0" +name = "web-sys" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2781db97787217ad2a2845c396a5efe286f87467a5810836db6d74926e94a385" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ - "bit_field", - "bitflags 1.3.2", - "raw-cpuid", + "js-sys", + "wasm-bindgen", ] [[package]] -name = "x86_64" -version = "0.15.1" +name = "x86" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bc79523af8abf92fb1a970c3e086c5a343f6bcc1a0eb890f575cbb3b45743df" +checksum = "2781db97787217ad2a2845c396a5efe286f87467a5810836db6d74926e94a385" dependencies = [ "bit_field", - "bitflags 2.5.0", - "rustversion", - "volatile", + "bitflags", + "raw-cpuid", ] diff --git a/Cargo.toml b/Cargo.toml index f9e6d29e..7f7849a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,7 @@ run-command = ["qemu-system-x86_64", "-display", "none", "-smp", "1", "-m", "256 run-args = [] [dependencies] -hermit-sync = "0.1.6" -qemu-exit = "3.0" # Spinlocks. +spinning_top = "0.3.0" [target.'cfg(target_arch = "aarch64")'.dependencies] semihosting = "0.1.9" @@ -25,5 +24,7 @@ semihosting = "0.1.9" [target.'cfg(target_arch = "x86_64")'.dependencies] bootloader = "0.9.29" x86 = { version = "0.52", default-features = false } -x86_64 = "0.15" +[target.'cfg(target_arch = "wasm32")'.dependencies] +wasm-bindgen = { version = "0.2.92" } +web-sys = { version = "0.3.4", features = ['Document','Element','HtmlElement','Node','Window',] } \ No newline at end of file diff --git a/aarch64-eduos.json b/aarch64-eduos.json deleted file mode 100644 index bae91ff1..00000000 --- a/aarch64-eduos.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "llvm-target": "aarch64-unknown-none", - "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", - "arch": "aarch64", - "target-endian": "little", - "target-pointer-width": "64", - "target-c-int-width": "32", - "os": "none", - "executables": true, - "linker-flavor": "ld.lld", - "linker": "rust-lld", - "panic-strategy": "abort", - "disable-redzone": true, - "features": "+a53,+strict-align,-fp-armv8", - "link-arg": "-T link.ld" -} diff --git a/rust-toolchain.toml b/rust-toolchain.toml index d8e245c0..701aaceb 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2023-03-10" +channel = "nightly-2024-09-01" components = [ "clippy", "rustfmt", diff --git a/src/arch/aarch64/mod.rs b/src/arch/aarch64/mod.rs deleted file mode 100644 index 96f6460c..00000000 --- a/src/arch/aarch64/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod processor; -pub mod serial; -pub mod start; diff --git a/src/arch/aarch64/processor.rs b/src/arch/aarch64/processor.rs deleted file mode 100644 index 98f50379..00000000 --- a/src/arch/aarch64/processor.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[no_mangle] -pub extern "C" fn shutdown(error_code: i32) -> ! { - semihosting::process::exit(error_code) -} diff --git a/src/arch/aarch64/serial.rs b/src/arch/aarch64/serial.rs deleted file mode 100644 index b7fa1fa0..00000000 --- a/src/arch/aarch64/serial.rs +++ /dev/null @@ -1,34 +0,0 @@ -use core::fmt; -use core::ptr::write_bytes; -use hermit_sync::SpinMutex; - -/// A COM serial port. -pub struct ComPort { - /// base address of I/O registers. - base_addr: u32, -} - -impl ComPort { - /// Create a new COM port with the specified base address. - const fn new(base_addr: u32) -> Self { - Self { base_addr } - } -} - -impl fmt::Write for ComPort { - /// Output a string to our COM port. This allows using nice, - /// high-level tools like Rust's `write!` macro. - fn write_str(&mut self, s: &str) -> fmt::Result { - unsafe { - // Output each byte of our string. - for &b in s.as_bytes() { - // Write our byte. - write_bytes(self.base_addr as *mut u8, b, 1); - } - } - Ok(()) - } -} - -/// Our primary serial port. -pub static COM1: SpinMutex = SpinMutex::new(ComPort::new(0x09000000)); diff --git a/src/arch/aarch64/start.rs b/src/arch/aarch64/start.rs deleted file mode 100644 index 25808a51..00000000 --- a/src/arch/aarch64/start.rs +++ /dev/null @@ -1,20 +0,0 @@ -use core::arch::asm; - -extern "C" { - fn main() -> !; -} - -#[cfg(not(test))] -#[no_mangle] -#[naked] -pub unsafe extern "C" fn _start() -> ! { - // init 1G stack stack in RAM area (>0x40000000 for qemu virt device) - asm!( - "movz x1, 0x5000, lsl 16", - "mov sp, x1", - // Jump to Rust code - "b {main}", - main = sym main, - options(noreturn), - ); -} diff --git a/src/arch/mod.rs b/src/arch/mod.rs index 48fa101a..3ba9a0e9 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -1,37 +1,15 @@ -// Copyright (c) 2017 Stefan Lankes, RWTH Aachen University -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - // Export our platform-specific modules. #[cfg(target_arch = "x86_64")] pub use self::x86_64::{processor, serial}; -#[cfg(target_arch = "aarch64")] -pub use self::aarch64::{processor, serial}; - // Implementations for x86_64. #[cfg(target_arch = "x86_64")] pub mod x86_64; -// Implementations for aarch64. -#[cfg(target_arch = "aarch64")] -pub mod aarch64; +// Export our platform-specific modules. +#[cfg(target_arch = "x86")] +pub use self::x86_64::{processor, serial}; + +// Implementations for x86_64. +#[cfg(target_arch = "x86")] +pub mod x86_64; diff --git a/src/arch/x86_64/processor.rs b/src/arch/x86_64/processor.rs index 5223f7c7..d4223f2f 100644 --- a/src/arch/x86_64/processor.rs +++ b/src/arch/x86_64/processor.rs @@ -1,5 +1,5 @@ use x86::controlregs::*; -use x86_64::instructions::port::Port; +use x86::io; pub fn halt() { unsafe { @@ -10,7 +10,7 @@ pub fn halt() { fn qemu_exit(success: bool) { let code = if success { 3 >> 1 } else { 0 }; unsafe { - Port::::new(0xf4).write(code); + io::outl(0xf4, code); } } diff --git a/src/arch/x86_64/serial.rs b/src/arch/x86_64/serial.rs index 26c385f2..48401601 100644 --- a/src/arch/x86_64/serial.rs +++ b/src/arch/x86_64/serial.rs @@ -1,5 +1,5 @@ use core::fmt; -use hermit_sync::SpinMutex; +use spinning_top::Spinlock; use x86::io::*; /// A COM serial port. @@ -32,4 +32,4 @@ impl fmt::Write for ComPort { } /// Our primary serial port. -pub static COM1: SpinMutex = SpinMutex::new(ComPort::new(0x3F8)); +pub static COM1: Spinlock = Spinlock::new(ComPort::new(0x3F8)); diff --git a/src/arch/x86_64/start.rs b/src/arch/x86_64/start.rs index 7dd75b5e..1612629a 100644 --- a/src/arch/x86_64/start.rs +++ b/src/arch/x86_64/start.rs @@ -1,11 +1,13 @@ +use crate::arch::x86_64::processor::shutdown; + extern "C" { - fn main(); + fn main() -> i32; } #[cfg(not(test))] #[no_mangle] pub unsafe extern "C" fn _start() -> ! { - main(); - - loop {} + let ret = main(); + // shutdown system + shutdown(ret); } diff --git a/src/lib.rs b/src/lib.rs index 6d41bd4a..f2638425 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(asm_const)] #![feature(allocator_api)] #![feature(naked_functions)] #![no_std] diff --git a/src/main.rs b/src/main.rs index badf975f..d12d7970 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -#![feature(panic_info_message)] #![feature(abi_x86_interrupt)] #![no_std] // don't link the Rust standard library #![cfg_attr(not(test), no_main)] // disable all Rust-level entry points @@ -7,8 +6,8 @@ #[macro_use] extern crate eduos_rs; +#[cfg(all(not(test), not(target_arch = "wasm32")))] use core::panic::PanicInfo; -use eduos_rs::arch::processor::shutdown; /// This function is the entry point of the kernel #[cfg(not(test))] @@ -17,7 +16,7 @@ pub extern "C" fn main() -> ! { println!("Hello world!"); // shutdown system - shutdown(0); + eduos_rs::shutdown(0); } /// This function is called on panic. @@ -30,11 +29,11 @@ pub fn panic(info: &PanicInfo) -> ! { print!("{}:{}: ", location.file(), location.line()); } - if let Some(message) = info.message() { + if let Some(message) = info.message().as_str() { print!("{}", message); } print!("\n"); - shutdown(1); + eduos_rs::shutdown(1); } diff --git a/x86_64-eduos.json b/x86_64-eduos.json index 468cb5e3..4f898021 100644 --- a/x86_64-eduos.json +++ b/x86_64-eduos.json @@ -5,8 +5,8 @@ "target-c-int-width": "32", "os": "none", "arch": "x86_64", - "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", - "features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", + "features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2,+soft-float", "disable-redzone": true, "executables": true, "linker-flavor": "ld.lld",