Skip to content

Commit

Permalink
limit the number of VM regs to 16 (RV32e)
Browse files Browse the repository at this point in the history
  • Loading branch information
poszu committed Jan 7, 2025
1 parent 660249b commit 4533ff4
Show file tree
Hide file tree
Showing 6 changed files with 517 additions and 518 deletions.
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 4533ff4

Please sign in to comment.