Wrap syscalls in user_lib && change xstate to exit_code
This commit is contained in:
parent
923abbbc96
commit
15ea8d934a
5 changed files with 19 additions and 14 deletions
|
@ -4,8 +4,8 @@ use crate::task::{
|
||||||
};
|
};
|
||||||
use crate::timer::get_time_ms;
|
use crate::timer::get_time_ms;
|
||||||
|
|
||||||
pub fn sys_exit(xstate: i32) -> ! {
|
pub fn sys_exit(exit_code: i32) -> ! {
|
||||||
println!("[kernel] Application exited with code {}", xstate);
|
println!("[kernel] Application exited with code {}", exit_code);
|
||||||
exit_current_and_run_next();
|
exit_current_and_run_next();
|
||||||
panic!("Unreachable in sys_exit!");
|
panic!("Unreachable in sys_exit!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,14 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate user_lib;
|
extern crate user_lib;
|
||||||
|
|
||||||
use user_lib::{sys_get_time, sys_yield};
|
use user_lib::{get_time, yield_};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn main() -> i32 {
|
fn main() -> i32 {
|
||||||
let current_timer = sys_get_time();
|
let current_timer = get_time();
|
||||||
let wait_for = current_timer + 3000;
|
let wait_for = current_timer + 3000;
|
||||||
while sys_get_time() < wait_for {
|
while get_time() < wait_for {
|
||||||
sys_yield();
|
yield_();
|
||||||
}
|
}
|
||||||
println!("Test sleep OK!");
|
println!("Test sleep OK!");
|
||||||
0
|
0
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
use core::fmt::{self, Write};
|
use core::fmt::{self, Write};
|
||||||
use crate::syscall::{STDOUT, sys_write};
|
use super::write;
|
||||||
|
|
||||||
struct Stdout;
|
struct Stdout;
|
||||||
|
|
||||||
|
const STDOUT: usize = 1;
|
||||||
|
|
||||||
impl Write for Stdout {
|
impl Write for Stdout {
|
||||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||||
sys_write(STDOUT, s.as_bytes());
|
write(STDOUT, s.as_bytes());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ mod lang_items;
|
||||||
#[link_section = ".text.entry"]
|
#[link_section = ".text.entry"]
|
||||||
pub extern "C" fn _start() -> ! {
|
pub extern "C" fn _start() -> ! {
|
||||||
clear_bss();
|
clear_bss();
|
||||||
syscall::sys_exit(main());
|
exit(main());
|
||||||
panic!("unreachable after sys_exit!");
|
panic!("unreachable after sys_exit!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,4 +32,9 @@ fn clear_bss() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use syscall::*;
|
use syscall::*;
|
||||||
|
|
||||||
|
pub fn write(fd: usize, buf: &[u8]) -> isize { sys_write(fd, buf) }
|
||||||
|
pub fn exit(exit_code: i32) -> isize { sys_exit(exit_code) }
|
||||||
|
pub fn yield_() -> isize { sys_yield() }
|
||||||
|
pub fn get_time() -> isize { sys_get_time() }
|
|
@ -1,5 +1,3 @@
|
||||||
pub const STDOUT: usize = 1;
|
|
||||||
|
|
||||||
const SYSCALL_WRITE: usize = 64;
|
const SYSCALL_WRITE: usize = 64;
|
||||||
const SYSCALL_EXIT: usize = 93;
|
const SYSCALL_EXIT: usize = 93;
|
||||||
const SYSCALL_YIELD: usize = 124;
|
const SYSCALL_YIELD: usize = 124;
|
||||||
|
@ -22,8 +20,8 @@ pub fn sys_write(fd: usize, buffer: &[u8]) -> isize {
|
||||||
syscall(SYSCALL_WRITE, [fd, buffer.as_ptr() as usize, buffer.len()])
|
syscall(SYSCALL_WRITE, [fd, buffer.as_ptr() as usize, buffer.len()])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sys_exit(xstate: i32) -> isize {
|
pub fn sys_exit(exit_code: i32) -> isize {
|
||||||
syscall(SYSCALL_EXIT, [xstate as usize, 0, 0])
|
syscall(SYSCALL_EXIT, [exit_code as usize, 0, 0])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sys_yield() -> isize {
|
pub fn sys_yield() -> isize {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue