From 2e2176e1c51443dec7b99bbae8c0827823c69067 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 28 Feb 2019 23:03:45 -0500 Subject: [PATCH] tests/unicorn_emu: Add getters and setters for PC/SP Makes the interface consistent with the A64Unicorn class. --- tests/unicorn_emu/a32_unicorn.cpp | 26 ++++++++++++++++++++------ tests/unicorn_emu/a32_unicorn.h | 8 ++++++-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/tests/unicorn_emu/a32_unicorn.cpp b/tests/unicorn_emu/a32_unicorn.cpp index 58cd1bc8..ce07a331 100644 --- a/tests/unicorn_emu/a32_unicorn.cpp +++ b/tests/unicorn_emu/a32_unicorn.cpp @@ -43,6 +43,26 @@ void A32Unicorn::Run() { } } +u32 A32Unicorn::GetPC() const { + u32 pc; + CHECKED(uc_reg_read(uc, UC_ARM_REG_PC, &pc)); + return pc; +} + +void A32Unicorn::SetPC(u32 value) { + CHECKED(uc_reg_write(uc, UC_ARM_REG_PC, &value)); +} + +u32 A32Unicorn::GetSP() const { + u32 sp; + CHECKED(uc_reg_read(uc, UC_ARM_REG_SP, &sp)); + return sp; +} + +void A32Unicorn::SetSP(u32 value) { + CHECKED(uc_reg_write(uc, UC_ARM_REG_SP, &value)); +} + constexpr std::array gpr_ids{ UC_ARM_REG_R0, UC_ARM_REG_R1, UC_ARM_REG_R2, UC_ARM_REG_R3, UC_ARM_REG_R4, UC_ARM_REG_R5, UC_ARM_REG_R6, UC_ARM_REG_R7, UC_ARM_REG_R8, UC_ARM_REG_R9, UC_ARM_REG_R10, UC_ARM_REG_R11, UC_ARM_REG_R12, UC_ARM_REG_R13, UC_ARM_REG_R14, UC_ARM_REG_R15, @@ -99,12 +119,6 @@ void A32Unicorn::SetExtRegs(const ExtRegArray& value) { reinterpret_cast(const_cast(ptrs.data())), ptrs.size())); } -u32 A32Unicorn::GetPC() const { - u32 pc; - CHECKED(uc_reg_read(uc, UC_ARM_REG_R15, &pc)); - return pc; -} - u32 A32Unicorn::GetFpscr() const { u32 fpsr; CHECKED(uc_reg_read(uc, UC_ARM_REG_FPSCR, &fpsr)); diff --git a/tests/unicorn_emu/a32_unicorn.h b/tests/unicorn_emu/a32_unicorn.h index f8416fb2..378ca792 100644 --- a/tests/unicorn_emu/a32_unicorn.h +++ b/tests/unicorn_emu/a32_unicorn.h @@ -30,14 +30,18 @@ public: void Run(); + u32 GetSP() const; + void SetSP(u32 value); + + u32 GetPC() const; + void SetPC(u32 value); + RegisterArray GetRegisters() const; void SetRegisters(const RegisterArray& value); ExtRegArray GetExtRegs() const; void SetExtRegs(const ExtRegArray& value); - u32 GetPC() const; - u32 GetFpscr() const; void SetFpscr(u32 value);