From 5d37073bd4af198960d12118fa281dd6b415176a Mon Sep 17 00:00:00 2001 From: Andrey Turkin Date: Fri, 14 Jun 2024 00:50:54 +0300 Subject: [PATCH] Complete RISC-V64 support --- src/arch/riscv64.rs | 70 +++++++++++++++++++++++++++++++++++++++++++-- src/sigabi.rs | 2 +- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/arch/riscv64.rs b/src/arch/riscv64.rs index 35c0c2c15e..4f6a0832d2 100644 --- a/src/arch/riscv64.rs +++ b/src/arch/riscv64.rs @@ -3,9 +3,13 @@ use core::{ ops::{Deref, DerefMut}, slice, }; - +use core::arch::asm; use super::error::{Error, Result}; + +pub const PAGE_SIZE: usize = 4096; + + #[cfg(feature = "userspace")] macro_rules! syscall { ($($name:ident($a:ident, $($b:ident, $($c:ident, $($d:ident, $($e:ident, $($f:ident, )?)?)?)?)?);)+) => { @@ -54,7 +58,38 @@ syscall! { #[derive(Copy, Clone, Debug, Default)] #[repr(C)] pub struct IntRegisters { - //TODO + pub pc: usize, + pub x31: usize, + pub x30: usize, + pub x29: usize, + pub x28: usize, + pub x27: usize, + pub x26: usize, + pub x25: usize, + pub x24: usize, + pub x23: usize, + pub x22: usize, + pub x21: usize, + pub x20: usize, + pub x19: usize, + pub x18: usize, + pub x17: usize, + pub x16: usize, + pub x15: usize, + pub x14: usize, + pub x13: usize, + pub x12: usize, + pub x11: usize, + pub x10: usize, + pub x9: usize, + pub x8: usize, + pub x7: usize, + pub x6: usize, + pub x5: usize, + // x4(tp) is in env + // x3(gp) is a platform scratch register + pub x2: usize, + pub x1: usize, } impl Deref for IntRegisters { @@ -83,7 +118,8 @@ impl DerefMut for IntRegisters { #[derive(Clone, Copy, Debug, Default)] #[repr(C, packed)] pub struct FloatRegisters { - //TODO + pub fregs: [u64; 32], + pub fcsr: u32, } impl Deref for FloatRegisters { @@ -108,3 +144,31 @@ impl DerefMut for FloatRegisters { } } } + +#[derive(Clone, Copy, Debug, Default)] +#[repr(packed)] +pub struct EnvRegisters { + pub tp: usize, +} +impl Deref for EnvRegisters { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts( + self as *const EnvRegisters as *const u8, + mem::size_of::(), + ) + } + } +} + +impl DerefMut for EnvRegisters { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut( + self as *mut EnvRegisters as *mut u8, + mem::size_of::(), + ) + } + } +} diff --git a/src/sigabi.rs b/src/sigabi.rs index 671a92393d..218dc27aee 100644 --- a/src/sigabi.rs +++ b/src/sigabi.rs @@ -40,7 +40,7 @@ pub struct Sigcontrol { pub control_flags: SigatomicUsize, pub saved_ip: NonatomicUsize, // rip/eip/pc - pub saved_archdep_reg: NonatomicUsize, // rflags/eflags/x0 + pub saved_archdep_reg: NonatomicUsize, // rflags(x64)/eflags(x86)/x0(aarch64)/t0(riscv64) } #[derive(Clone, Copy, Debug)] pub struct SenderInfo {