Skip to content

Commit

Permalink
Merge pull request #14 from icicle-emu/write-reg-sp
Browse files Browse the repository at this point in the history
Fix bug where `reg_write("rip", ...)` would not work after stepping
  • Loading branch information
mrexodia authored Dec 24, 2024
2 parents 2f06c21 + a228304 commit 30b3c7c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions python/icicle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def exception_value(self) -> int: ...

icount_limit: int

pc: int

sp: int

# TODO: API to get memory information?

def mem_map(self, address: int, size: int, protection: MemoryProtection): ...
Expand Down
28 changes: 27 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,26 @@ impl Icicle {
self.architecture.to_string()
}

#[getter]
pub fn get_pc(&self) -> u64 {
self.vm.cpu.read_pc()
}

#[setter]
pub fn set_pc(&mut self, address: u64) {
self.vm.cpu.write_pc(address)
}

#[getter]
pub fn get_sp(&mut self) -> u64 {
self.vm.cpu.read_reg(self.vm.cpu.arch.reg_sp)
}

#[setter]
pub fn set_sp(&mut self, address: u64) {
self.vm.cpu.write_reg(self.vm.cpu.arch.reg_sp, address)
}

#[new]
#[pyo3(signature = (
architecture,
Expand Down Expand Up @@ -455,7 +475,13 @@ impl Icicle {
}

pub fn reg_write(&mut self, name: &str, value: u64) -> PyResult<()> {
Ok(self.vm.cpu.write_reg(reg_find(self, name)?.var, value))
let var = reg_find(self, name)?.var;
if var == self.vm.cpu.arch.reg_pc {
self.vm.cpu.write_pc(value);
} else {
self.vm.cpu.write_reg(var, value);
}
Ok(())
}

pub fn reset(&mut self) {
Expand Down

0 comments on commit 30b3c7c

Please sign in to comment.