diff --git a/.cargo/config.toml b/.cargo/config.toml index 57c500f7..62e08301 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -5,10 +5,11 @@ build-std-features = ["compiler-builtins-mem"] [build] target = "x86_64-eduos.json" -[target.aarch64-eduos] +[target.i686-eduos] rustflags = [ - "-C", "link-arg=-Tlink_aarch64.ld" + "-C", "link-arg=-Tsrc/arch/x86/link_i686.ld", "-C", "relocation-model=static" ] +runner = "qemu-system-x86_64 -display none -serial stdio -smp 1 -m 256M -device isa-debug-exit,iobase=0xf4,iosize=0x04 -kernel" [target.x86_64-eduos] runner = "bootimage runner" diff --git a/Cargo.lock b/Cargo.lock index 4cb0775a..171cb03e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,9 +22,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bootloader" -version = "0.9.23" +version = "0.9.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6e02311b16c9819e7c72866d379cdd3026c3b7b25c1edf161f548f8e887e7ff" +checksum = "365861702868e2a37b4247aaecc7bd8f4389baec8d025497ad8ba7ff37ee9440" [[package]] name = "eduos-rs" diff --git a/Cargo.toml b/Cargo.toml index 8ae1eceb..d47c6088 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,16 +10,19 @@ build-command = ["build"] # The command invoked with the created bootimage (the "{}" will be replaced # with the path to the bootable disk image) # Applies to `bootimage run` and `bootimage runner` -run-command = ["qemu-system-x86_64", "-display", "none", "-smp", "1", "-m", "128M", "-serial", "stdio", "-cpu", "qemu64,apic,fsgsbase,rdtscp,xsave,xsaveopt,fxsr", "-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-drive", "format=raw,file={}"] +run-command = ["qemu-system-x86_64", "-display", "none", "-smp", "1", "-m", "256M", "-serial", "stdio", "-cpu", "qemu64,apic,fsgsbase,rdtscp,xsave,xsaveopt,fxsr", "-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-drive", "format=raw,file={}"] # Additional arguments passed to the run command for non-test executables # Applies to `bootimage run` and `bootimage runner` run-args = [] +[features] +default = ["qemu-exit"] + [dependencies] spin = "0.9" simple-chunk-allocator = "0.1.5" -qemu-exit = "3.0" # Spinlocks. -bootloader = "0.9.23" +qemu-exit = { version = "3.0", optional = true } +bootloader = "0.9.29" [target.'cfg(target_arch = "x86_64")'.dependencies.x86] version = "0.52" 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/mod.rs b/src/arch/mod.rs index 9b0d3a29..725d1012 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -13,3 +13,7 @@ pub use self::x86::kernel::switch::switch; // Export our platform-specific modules. #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] pub use self::x86::mm; + +pub fn init() { + processor::cpu_init(); +} diff --git a/src/arch/x86/kernel/processor.rs b/src/arch/x86/kernel/processor.rs index 08b01f85..b203c612 100644 --- a/src/arch/x86/kernel/processor.rs +++ b/src/arch/x86/kernel/processor.rs @@ -4,20 +4,33 @@ use core::arch::asm; use qemu_exit::QEMUExit; use x86::controlregs::*; -pub fn halt() { +pub(crate) fn halt() { unsafe { asm!("hlt", options(nomem, nostack)); } } +#[allow(unused_variables)] #[no_mangle] -pub extern "C" fn shutdown() -> ! { - // shutdown, works like Qemu's shutdown command - let qemu_exit_handle = qemu_exit::X86::new(0xf4, 5); - qemu_exit_handle.exit_success(); +pub extern "C" fn shutdown(error_code: i32) -> ! { + #[cfg(feature = "qemu-exit")] + { + let code = if error_code == 0 { 3 >> 1 } else { 1 }; + + // shutdown, works like Qemu's shutdown command + let qemu_exit_handle = qemu_exit::X86::new(0xf4, code); + qemu_exit_handle.exit_success(); + } + + #[cfg(not(feature = "qemu-exit"))] + loop { + unsafe { + x86::halt(); + } + } } -pub fn cpu_init() { +pub(crate) fn cpu_init() { let mut cr0 = unsafe { cr0() }; // be sure that AM, NE and MP is enabled diff --git a/src/arch/x86/kernel/start.rs b/src/arch/x86/kernel/start.rs index 3077e6e9..a272e80c 100755 --- a/src/arch/x86/kernel/start.rs +++ b/src/arch/x86/kernel/start.rs @@ -1,5 +1,7 @@ +use crate::arch::x86::kernel::processor::shutdown; + extern "C" { - pub fn main(); + pub fn main() -> i32; } #[cfg(not(test))] @@ -7,7 +9,7 @@ extern "C" { pub unsafe extern "C" fn _start(boot_info: &'static bootloader::BootInfo) -> ! { crate::arch::x86::kernel::BOOT_INFO = Some(boot_info); - main(); + let ret = main(); - loop {} + shutdown(ret) } diff --git a/src/lib.rs b/src/lib.rs index b9bfbdfc..d7cc940a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,4 @@ -#![feature(lang_items)] -#![feature(asm_const)] #![feature(const_mut_refs)] -#![feature(panic_info_message)] #![feature(linked_list_cursors)] #![feature(alloc_error_handler)] #![feature(naked_functions)] @@ -43,7 +40,7 @@ static mut HEAP_BITMAP: PageAligned<[u8; CHUNK_AMOUNT / 8]> = heap_bitmap!(chunk static ALLOCATOR: GlobalChunkAllocator = unsafe { GlobalChunkAllocator::new(HEAP.deref_mut_const(), HEAP_BITMAP.deref_mut_const()) }; -/// This function is called on panic. +//// This function is called on panic. #[cfg(not(test))] #[panic_handler] pub fn panic(info: &PanicInfo) -> ! { @@ -53,13 +50,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"); - loop { - halt(); - } + shutdown(1); } diff --git a/src/main.rs b/src/main.rs index 1514dd93..27b0afee 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,7 +6,7 @@ #[macro_use] extern crate eduos_rs; -use eduos_rs::arch::processor::shutdown; +use eduos_rs::arch; use eduos_rs::scheduler; extern "C" fn foo() { @@ -21,7 +20,8 @@ extern "C" fn foo() { /// named `_start` by default. #[cfg(not(test))] #[no_mangle] // don't mangle the name of this function -pub extern "C" fn main() -> ! { +pub extern "C" fn main() -> i32 { + arch::init(); scheduler::init(); println!("Hello from eduOS-rs!"); @@ -34,6 +34,5 @@ pub extern "C" fn main() -> ! { println!("Shutdown system!"); - // shutdown system - shutdown(); + 0 } 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",