Skip to content

Commit

Permalink
switch to the latest rust toolchain
Browse files Browse the repository at this point in the history
- use qemu_exit to return error code
  • Loading branch information
stlankes committed Sep 15, 2024
1 parent 0dc9bb0 commit ffac139
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 32 deletions.
5 changes: 3 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "nightly-2023-03-10"
channel = "nightly-2024-09-01"
components = [
"clippy",
"rustfmt",
Expand Down
4 changes: 4 additions & 0 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
25 changes: 19 additions & 6 deletions src/arch/x86/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/arch/x86/kernel/start.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use crate::arch::x86::kernel::processor::shutdown;

extern "C" {
pub fn main();
pub fn main() -> i32;
}

#[cfg(not(test))]
#[no_mangle]
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)
}
11 changes: 3 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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) -> ! {
Expand All @@ -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);
}
9 changes: 4 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand All @@ -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!");
Expand All @@ -34,6 +34,5 @@ pub extern "C" fn main() -> ! {

println!("Shutdown system!");

// shutdown system
shutdown();
0
}
4 changes: 2 additions & 2 deletions x86_64-eduos.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ffac139

Please sign in to comment.