Skip to content

Commit

Permalink
Merge pull request #304 from athenavm/limit-vm-registers
Browse files Browse the repository at this point in the history
limit the number of VM regs to 16 (RV32e)
  • Loading branch information
poszu authored Jan 8, 2025
2 parents 660249b + 0fc071b commit 290842d
Show file tree
Hide file tree
Showing 7 changed files with 519 additions and 520 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Athena

Athena is a prototype deterministic smart contract engine that serves as the [Spacemesh network VM][2], and Athena is being designed and built by the [Spacemesh][8] team. However, Athena is designed to be modular and largely protocol-agnostic so [it will run on other chains][9]. Contributions and integrations are welcome.
Athena is a prototype deterministic smart contract engine that serves as the [Spacemesh network VM][2], and Athena is being designed and built by the [Spacemesh][8] team. However, Athena is designed to be modular and largely protocol-agnostic so [it will run on other chains][9]. Contributions and integrations are welcome.

Athena includes a virtual machine (VM) based on the RISC-V ISA, including support for [RV32IM][10] and [RV32EM][1], an interpreter/compiler for running smart contract code, and related tooling. The VM is modular and features a mature FFI that can be integrated into any language that supports CFFI. For more information on the Athena project and its goals see [Introducing Athena][2] and the [Athena project updates][3].
Athena includes a virtual machine (VM) based on the RISC-V ISA, including support for [RV32EM][1], an interpreter/compiler for running smart contract code, and related tooling. The VM features a C FFI that can be integrated into any language that supports interop with C. For more information on the Athena project and its goals see [Introducing Athena][2] and the [Athena project updates][3].

## Project Goals
- **Developer Experience**: Provide a robust environment with extensive tooling support.
Expand Down
9 changes: 5 additions & 4 deletions core/src/runtime/gdbstub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl SingleThreadBase for Runtime<'_> {
) -> gdbstub::target::TargetResult<(), Self> {
tracing::trace!("writing registers: {regs:?}");
for (reg, value) in regs.x.iter().enumerate() {
self.rw(Register::from_u32(reg as u32), *value)
self.rw(Register::try_from(reg as u32).unwrap(), *value)
}

Ok(())
Expand Down Expand Up @@ -182,7 +182,7 @@ impl SingleRegisterAccess<()> for Runtime<'_> {
) -> gdbstub::target::TargetResult<usize, Self> {
match reg_id {
RiscvRegId::Gpr(id) => {
let value = self.registers()[id as usize];
let value = self.state.regs.read(Register::try_from(id as u32).unwrap());
buf.copy_from_slice(&value.to_le_bytes());
Ok(4)
}
Expand All @@ -202,7 +202,7 @@ impl SingleRegisterAccess<()> for Runtime<'_> {
match reg_id {
RiscvRegId::Gpr(id) => {
let value = u32::from_le_bytes(val.try_into().unwrap());
self.rw(Register::from_u32(id as u32), value);
self.rw(Register::try_from(id as u32).unwrap(), value);
}
RiscvRegId::Pc => {
let value = u32::from_le_bytes(val.try_into().unwrap());
Expand Down Expand Up @@ -295,7 +295,7 @@ impl<'h> run_blocking::BlockingEventLoop for GdbBlockingEventLoop<'h> {
ExecutionError::HaltWithNonZeroExitCode(code) => {
SingleThreadStopReason::Exited(code as u8)
}
ExecutionError::InvalidMemoryAccess(_, _) => {
ExecutionError::InvalidMemoryAccess(_, _, _) => {
SingleThreadStopReason::Terminated(Signal::EXC_BAD_ACCESS)
}
ExecutionError::UnsupportedSyscall(_) => {
Expand Down Expand Up @@ -355,6 +355,7 @@ pub fn gdb_event_loop_thread<'h>(
return Err(ExecutionError::InvalidMemoryAccess(
crate::runtime::Opcode::UNIMP,
0,
crate::runtime::MemoryErr::Unaligned,
))
}
Signal::SIGSYS => return Err(ExecutionError::UnsupportedSyscall(0)),
Expand Down
Loading

0 comments on commit 290842d

Please sign in to comment.