添加系统调用模块
parent
5ce82f274e
commit
fc02e9f961
@ -0,0 +1,30 @@
|
|||||||
|
use core::arch::asm;
|
||||||
|
|
||||||
|
const SYSCALL_WRITE: usize = 64;
|
||||||
|
const SYSCALL_EXIT: usize = 93;
|
||||||
|
|
||||||
|
|
||||||
|
fn syscall(id: usize, args: [usize; 3]) -> isize {
|
||||||
|
let mut ret: isize;
|
||||||
|
unsafe {
|
||||||
|
// a0寄存器同时作为输入参数和输出参数, {in_var} => {out_var}
|
||||||
|
asm!(
|
||||||
|
"ecall",
|
||||||
|
inlateout("x10") args[0] => ret,
|
||||||
|
in("x11") args[1],
|
||||||
|
in("x12") args[2],
|
||||||
|
in("x17") id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn sys_write(fd: usize, buffer: &[u8]) -> isize {
|
||||||
|
syscall(SYSCALL_WRITE, [fd, buffer.as_ptr() as usize, buffer.len()])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sys_exit(exit_code: i32) -> isize {
|
||||||
|
syscall(SYSCALL_EXIT, [exit_code as usize, 0, 0])
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue