diff options
author | Hedges <hedges@resync.pl> | 2018-06-06 06:20:47 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2018-06-06 06:20:47 +0200 |
commit | 39fb3e362cf71d0542a5807c97039cd474ef3716 (patch) | |
tree | e54ad38fba3c7b2b32e5e408e9e7eb8cb6ffe6b0 /src/core/arm/unicorn | |
parent | Merge pull request #516 from Subv/f2i_r (diff) | |
download | yuzu-39fb3e362cf71d0542a5807c97039cd474ef3716.tar yuzu-39fb3e362cf71d0542a5807c97039cd474ef3716.tar.gz yuzu-39fb3e362cf71d0542a5807c97039cd474ef3716.tar.bz2 yuzu-39fb3e362cf71d0542a5807c97039cd474ef3716.tar.lz yuzu-39fb3e362cf71d0542a5807c97039cd474ef3716.tar.xz yuzu-39fb3e362cf71d0542a5807c97039cd474ef3716.tar.zst yuzu-39fb3e362cf71d0542a5807c97039cd474ef3716.zip |
Diffstat (limited to 'src/core/arm/unicorn')
-rw-r--r-- | src/core/arm/unicorn/arm_unicorn.cpp | 38 | ||||
-rw-r--r-- | src/core/arm/unicorn/arm_unicorn.h | 4 |
2 files changed, 41 insertions, 1 deletions
diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp index c0cc62f03..ce6c5616d 100644 --- a/src/core/arm/unicorn/arm_unicorn.cpp +++ b/src/core/arm/unicorn/arm_unicorn.cpp @@ -35,6 +35,17 @@ LoadDll LoadDll::g_load_dll; } \ } while (0) +static void CodeHook(uc_engine* uc, uint64_t address, uint32_t size, void* user_data) { + GDBStub::BreakpointAddress bkpt = + GDBStub::GetNextBreakpointFromAddress(address, GDBStub::BreakpointType::Execute); + if (GDBStub::IsMemoryBreak() || + (bkpt.type != GDBStub::BreakpointType::None && address == bkpt.address)) { + auto core = static_cast<ARM_Unicorn*>(user_data); + core->RecordBreak(bkpt); + uc_emu_stop(uc); + } +} + static void InterruptHook(uc_engine* uc, u32 intNo, void* user_data) { u32 esr{}; CHECKED(uc_reg_read(uc, UC_ARM64_REG_ESR, &esr)); @@ -67,6 +78,10 @@ ARM_Unicorn::ARM_Unicorn() { uc_hook hook{}; CHECKED(uc_hook_add(uc, &hook, UC_HOOK_INTR, (void*)InterruptHook, this, 0, -1)); CHECKED(uc_hook_add(uc, &hook, UC_HOOK_MEM_INVALID, (void*)UnmappedMemoryHook, this, 0, -1)); + if (GDBStub::IsServerEnabled()) { + CHECKED(uc_hook_add(uc, &hook, UC_HOOK_CODE, (void*)CodeHook, this, 0, -1)); + last_bkpt_hit = false; + } } ARM_Unicorn::~ARM_Unicorn() { @@ -155,7 +170,11 @@ void ARM_Unicorn::SetTlsAddress(VAddr base) { } void ARM_Unicorn::Run() { - ExecuteInstructions(std::max(CoreTiming::GetDowncount(), 0)); + if (GDBStub::IsServerEnabled()) { + ExecuteInstructions(std::max(4000000, 0)); + } else { + ExecuteInstructions(std::max(CoreTiming::GetDowncount(), 0)); + } } void ARM_Unicorn::Step() { @@ -168,6 +187,18 @@ void ARM_Unicorn::ExecuteInstructions(int num_instructions) { MICROPROFILE_SCOPE(ARM_Jit); CHECKED(uc_emu_start(uc, GetPC(), 1ULL << 63, 0, num_instructions)); CoreTiming::AddTicks(num_instructions); + if (GDBStub::IsServerEnabled()) { + if (last_bkpt_hit) { + uc_reg_write(uc, UC_ARM64_REG_PC, &last_bkpt.address); + } + Kernel::Thread* thread = Kernel::GetCurrentThread(); + SaveContext(thread->context); + if (last_bkpt_hit) { + last_bkpt_hit = false; + GDBStub::Break(); + } + GDBStub::SendTrap(thread, 5); + } } void ARM_Unicorn::SaveContext(ARM_Interface::ThreadContext& ctx) { @@ -233,3 +264,8 @@ void ARM_Unicorn::PrepareReschedule() { } void ARM_Unicorn::ClearInstructionCache() {} + +void ARM_Unicorn::RecordBreak(GDBStub::BreakpointAddress bkpt) { + last_bkpt = bkpt; + last_bkpt_hit = true; +} diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.h index b99b58e4c..a482a2aa3 100644 --- a/src/core/arm/unicorn/arm_unicorn.h +++ b/src/core/arm/unicorn/arm_unicorn.h @@ -7,6 +7,7 @@ #include <unicorn/unicorn.h> #include "common/common_types.h" #include "core/arm/arm_interface.h" +#include "core/gdbstub/gdbstub.h" class ARM_Unicorn final : public ARM_Interface { public: @@ -35,7 +36,10 @@ public: void Step() override; void ClearInstructionCache() override; void PageTableChanged() override{}; + void RecordBreak(GDBStub::BreakpointAddress bkpt); private: uc_engine* uc{}; + GDBStub::BreakpointAddress last_bkpt{}; + bool last_bkpt_hit; }; |