mirror of
https://github.com/LearningOS/rust-based-os-comp2022.git
synced 2026-05-05 12:24:30 +08:00
41 lines
798 B
Rust
41 lines
798 B
Rust
// os/src/main.rs
|
|
#![no_std]
|
|
#![no_main]
|
|
#![feature(panic_info_message)]
|
|
|
|
mod lang_item;
|
|
#[macro_use]
|
|
mod console;
|
|
|
|
const SYSCALL_EXIT: usize = 93;
|
|
const SYSCALL_WRITE: usize = 64;
|
|
|
|
fn syscall(id: usize, args: [usize; 3]) -> isize {
|
|
let mut ret;
|
|
unsafe {
|
|
core::arch::asm!(
|
|
"ecall",
|
|
inlateout("x10") args[0] => ret,
|
|
in("x11") args[1],
|
|
in("x12") args[2],
|
|
in("x17") id,
|
|
);
|
|
}
|
|
ret
|
|
}
|
|
|
|
pub fn sys_exit(xstate: i32) -> isize {
|
|
syscall(SYSCALL_EXIT, [xstate as usize, 0, 0])
|
|
}
|
|
|
|
pub fn sys_write(fd: usize, buffer: &[u8]) -> isize {
|
|
syscall(SYSCALL_WRITE, [fd, buffer.as_ptr() as usize, buffer.len()])
|
|
}
|
|
|
|
#[no_mangle]
|
|
extern "C" fn _start() {
|
|
print!("Hello ");
|
|
println!("world!");
|
|
sys_exit(9);
|
|
}
|