-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,736 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
// On riscv32, the following registers are used for args 1-6: | ||
// arg1: %a0 | ||
// arg2: %a1 | ||
// arg3: %a2 | ||
// arg4: %a3 | ||
// arg5: %a4 | ||
// arg6: %a5 | ||
// | ||
// %a7 is used for the syscall number. | ||
// | ||
// %a0 is reused for the syscall return value. | ||
// | ||
// No other registers are clobbered. | ||
use core::arch::asm; | ||
|
||
use crate::arch::riscv64::Sysno; | ||
|
||
/// Issues a raw system call with 0 arguments. | ||
/// | ||
/// # Safety | ||
/// | ||
/// Running a system call is inherently unsafe. It is the caller's | ||
/// responsibility to ensure safety. | ||
#[inline] | ||
pub unsafe fn syscall0(n: Sysno) -> usize { | ||
let mut ret: usize; | ||
asm!( | ||
"ecall", | ||
in("a7") n as usize, | ||
out("a0") ret, | ||
options(nostack, preserves_flags) | ||
); | ||
ret | ||
} | ||
|
||
/// Issues a raw system call with 1 argument. | ||
/// | ||
/// # Safety | ||
/// | ||
/// Running a system call is inherently unsafe. It is the caller's | ||
/// responsibility to ensure safety. | ||
#[inline] | ||
pub unsafe fn syscall1(n: Sysno, arg1: usize) -> usize { | ||
let mut ret: usize; | ||
asm!( | ||
"ecall", | ||
in("a7") n as usize, | ||
inlateout("a0") arg1 => ret, | ||
options(nostack, preserves_flags) | ||
); | ||
ret | ||
} | ||
|
||
/// Issues a raw system call with 2 arguments. | ||
/// | ||
/// # Safety | ||
/// | ||
/// Running a system call is inherently unsafe. It is the caller's | ||
/// responsibility to ensure safety. | ||
#[inline] | ||
pub unsafe fn syscall2(n: Sysno, arg1: usize, arg2: usize) -> usize { | ||
let mut ret: usize; | ||
asm!( | ||
"ecall", | ||
in("a7") n as usize, | ||
inlateout("a0") arg1 => ret, | ||
in("a1") arg2, | ||
options(nostack, preserves_flags) | ||
); | ||
ret | ||
} | ||
|
||
/// Issues a raw system call with 3 arguments. | ||
/// | ||
/// # Safety | ||
/// | ||
/// Running a system call is inherently unsafe. It is the caller's | ||
/// responsibility to ensure safety. | ||
#[inline] | ||
pub unsafe fn syscall3( | ||
n: Sysno, | ||
arg1: usize, | ||
arg2: usize, | ||
arg3: usize, | ||
) -> usize { | ||
let mut ret: usize; | ||
asm!( | ||
"ecall", | ||
in("a7") n as usize, | ||
inlateout("a0") arg1 => ret, | ||
in("a1") arg2, | ||
in("a2") arg3, | ||
options(nostack, preserves_flags) | ||
); | ||
ret | ||
} | ||
|
||
/// Issues a raw system call with 4 arguments. | ||
/// | ||
/// # Safety | ||
/// | ||
/// Running a system call is inherently unsafe. It is the caller's | ||
/// responsibility to ensure safety. | ||
#[inline] | ||
pub unsafe fn syscall4( | ||
n: Sysno, | ||
arg1: usize, | ||
arg2: usize, | ||
arg3: usize, | ||
arg4: usize, | ||
) -> usize { | ||
let mut ret: usize; | ||
asm!( | ||
"ecall", | ||
in("a7") n as usize, | ||
inlateout("a0") arg1 => ret, | ||
in("a1") arg2, | ||
in("a2") arg3, | ||
in("a3") arg4, | ||
options(nostack, preserves_flags) | ||
); | ||
ret | ||
} | ||
|
||
/// Issues a raw system call with 5 arguments. | ||
/// | ||
/// # Safety | ||
/// | ||
/// Running a system call is inherently unsafe. It is the caller's | ||
/// responsibility to ensure safety. | ||
#[inline] | ||
pub unsafe fn syscall5( | ||
n: Sysno, | ||
arg1: usize, | ||
arg2: usize, | ||
arg3: usize, | ||
arg4: usize, | ||
arg5: usize, | ||
) -> usize { | ||
let mut ret: usize; | ||
asm!( | ||
"ecall", | ||
in("a7") n as usize, | ||
inlateout("a0") arg1 => ret, | ||
in("a1") arg2, | ||
in("a2") arg3, | ||
in("a3") arg4, | ||
in("a4") arg5, | ||
options(nostack, preserves_flags) | ||
); | ||
ret | ||
} | ||
|
||
/// Issues a raw system call with 6 arguments. | ||
/// | ||
/// # Safety | ||
/// | ||
/// Running a system call is inherently unsafe. It is the caller's | ||
/// responsibility to ensure safety. | ||
#[inline] | ||
pub unsafe fn syscall6( | ||
n: Sysno, | ||
arg1: usize, | ||
arg2: usize, | ||
arg3: usize, | ||
arg4: usize, | ||
arg5: usize, | ||
arg6: usize, | ||
) -> usize { | ||
let mut ret: usize; | ||
asm!( | ||
"ecall", | ||
in("a7") n as usize, | ||
inlateout("a0") arg1 => ret, | ||
in("a1") arg2, | ||
in("a2") arg3, | ||
in("a3") arg4, | ||
in("a4") arg5, | ||
in("a5") arg6, | ||
options(nostack, preserves_flags) | ||
); | ||
ret | ||
} |
Oops, something went wrong.