Skip to content

Commit 30b3c7c

Browse files
authored
Merge pull request #14 from icicle-emu/write-reg-sp
Fix bug where `reg_write("rip", ...)` would not work after stepping
2 parents 2f06c21 + a228304 commit 30b3c7c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

python/icicle/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ def exception_value(self) -> int: ...
100100

101101
icount_limit: int
102102

103+
pc: int
104+
105+
sp: int
106+
103107
# TODO: API to get memory information?
104108

105109
def mem_map(self, address: int, size: int, protection: MemoryProtection): ...

src/lib.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,26 @@ impl Icicle {
276276
self.architecture.to_string()
277277
}
278278

279+
#[getter]
280+
pub fn get_pc(&self) -> u64 {
281+
self.vm.cpu.read_pc()
282+
}
283+
284+
#[setter]
285+
pub fn set_pc(&mut self, address: u64) {
286+
self.vm.cpu.write_pc(address)
287+
}
288+
289+
#[getter]
290+
pub fn get_sp(&mut self) -> u64 {
291+
self.vm.cpu.read_reg(self.vm.cpu.arch.reg_sp)
292+
}
293+
294+
#[setter]
295+
pub fn set_sp(&mut self, address: u64) {
296+
self.vm.cpu.write_reg(self.vm.cpu.arch.reg_sp, address)
297+
}
298+
279299
#[new]
280300
#[pyo3(signature = (
281301
architecture,
@@ -455,7 +475,13 @@ impl Icicle {
455475
}
456476

457477
pub fn reg_write(&mut self, name: &str, value: u64) -> PyResult<()> {
458-
Ok(self.vm.cpu.write_reg(reg_find(self, name)?.var, value))
478+
let var = reg_find(self, name)?.var;
479+
if var == self.vm.cpu.arch.reg_pc {
480+
self.vm.cpu.write_pc(value);
481+
} else {
482+
self.vm.cpu.write_reg(var, value);
483+
}
484+
Ok(())
459485
}
460486

461487
pub fn reset(&mut self) {

0 commit comments

Comments
 (0)