summaryrefslogtreecommitdiff
path: root/vendor/redox_syscall/src/arch/riscv64.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/redox_syscall/src/arch/riscv64.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/redox_syscall/src/arch/riscv64.rs')
-rw-r--r--vendor/redox_syscall/src/arch/riscv64.rs93
1 files changed, 93 insertions, 0 deletions
diff --git a/vendor/redox_syscall/src/arch/riscv64.rs b/vendor/redox_syscall/src/arch/riscv64.rs
new file mode 100644
index 0000000..2a90260
--- /dev/null
+++ b/vendor/redox_syscall/src/arch/riscv64.rs
@@ -0,0 +1,93 @@
+use core::{mem, slice};
+use core::ops::{Deref, DerefMut};
+
+use super::error::{Error, Result};
+
+macro_rules! syscall {
+ ($($name:ident($a:ident, $($b:ident, $($c:ident, $($d:ident, $($e:ident, $($f:ident, )?)?)?)?)?);)+) => {
+ $(
+ pub unsafe fn $name($a: usize, $($b: usize, $($c: usize, $($d: usize, $($e: usize, $($f: usize)?)?)?)?)?) -> Result<usize> {
+ let ret: usize;
+
+ asm!(
+ "ecall",
+ in("a7") $a,
+ $(
+ in("a0") $b,
+ $(
+ in("a1") $c,
+ $(
+ in("a2") $d,
+ $(
+ in("a3") $e,
+ $(
+ in("a4") $f,
+ )?
+ )?
+ )?
+ )?
+ )?
+ lateout("a0") ret,
+ options(nostack),
+ );
+
+ Error::demux(ret)
+ }
+ )+
+ };
+}
+
+syscall! {
+ syscall0(a,);
+ syscall1(a, b,);
+ syscall2(a, b, c,);
+ syscall3(a, b, c, d,);
+ syscall4(a, b, c, d, e,);
+ syscall5(a, b, c, d, e, f,);
+}
+
+#[derive(Copy, Clone, Debug, Default)]
+#[repr(C)]
+pub struct IntRegisters {
+ //TODO
+}
+
+impl Deref for IntRegisters {
+ type Target = [u8];
+ fn deref(&self) -> &[u8] {
+ unsafe {
+ slice::from_raw_parts(self as *const IntRegisters as *const u8, mem::size_of::<IntRegisters>())
+ }
+ }
+}
+
+impl DerefMut for IntRegisters {
+ fn deref_mut(&mut self) -> &mut [u8] {
+ unsafe {
+ slice::from_raw_parts_mut(self as *mut IntRegisters as *mut u8, mem::size_of::<IntRegisters>())
+ }
+ }
+}
+
+#[derive(Clone, Copy, Debug, Default)]
+#[repr(packed)]
+pub struct FloatRegisters {
+ //TODO
+}
+
+impl Deref for FloatRegisters {
+ type Target = [u8];
+ fn deref(&self) -> &[u8] {
+ unsafe {
+ slice::from_raw_parts(self as *const FloatRegisters as *const u8, mem::size_of::<FloatRegisters>())
+ }
+ }
+}
+
+impl DerefMut for FloatRegisters {
+ fn deref_mut(&mut self) -> &mut [u8] {
+ unsafe {
+ slice::from_raw_parts_mut(self as *mut FloatRegisters as *mut u8, mem::size_of::<FloatRegisters>())
+ }
+ }
+}