Skip to content

Commit

Permalink
Merge pull request #44 from hack3ric/riscv64-support
Browse files Browse the repository at this point in the history
Add riscv64 support
  • Loading branch information
JakWai01 authored Jul 20, 2024
2 parents 44fbd1c + 23d1385 commit 3b7f5cc
Show file tree
Hide file tree
Showing 4 changed files with 795 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ default = []
all = [
# "aarch64", "arm", "mips", "mips64", "powerpc", "powerpc64", "s390x",
# "sparc", "sparc64", "x86",
"x86_64"
"x86_64", "riscv64"
]

# Enable syscall tables for individual architectures.
Expand All @@ -32,6 +32,7 @@ all = [
#sparc64 = []
#x86 = []
x86_64 = []
riscv64 = []

[dependencies]
anyhow = "1"
Expand Down
7 changes: 7 additions & 0 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use syscalls::Sysno;
// pub mod powerpc;
// #[cfg(any(target_arch = "powerpc64", feature = "powerpc64"))]
// pub mod powerpc64;
#[cfg(any(target_arch = "riscv64", feature = "riscv64"))]
pub mod riscv64;
// #[cfg(any(target_arch = "s390x", feature = "s390x"))]
// pub mod s390x;
// #[cfg(any(target_arch = "sparc", feature = "sparc"))]
Expand All @@ -42,6 +44,8 @@ pub mod x86_64;
// pub use powerpc::*;
// #[cfg(target_arch = "powerpc64")]
// pub use powerpc64::*;
#[cfg(target_arch = "riscv64")]
pub use riscv64::*;
// #[cfg(target_arch = "s390x")]
// pub use s390x::*;
// #[cfg(target_arch = "sparc")]
Expand Down Expand Up @@ -139,7 +143,10 @@ fn map_arg(pid: Pid, registers: user_regs_struct, idx: usize, arg: SyscallArgTyp
let value = get_arg_value(registers, idx);
// The return value of a system call for functions like read or write represents the number of bytes that were successfully processed.
// which will stores in rax
#[cfg(target_arch = "x86_64")]
let length = registers.rax as usize;
#[cfg(target_arch = "riscv64")]
let length = registers.a7 as usize;
match arg {
SyscallArgType::Int => SyscallArg::Int(value as i64),
SyscallArgType::Bytes => SyscallArg::Bytes(read_bytes(pid, value, length)),
Expand Down
Loading

0 comments on commit 3b7f5cc

Please sign in to comment.