diff options
Diffstat (limited to 'src/core/arm')
-rw-r--r-- | src/core/arm/arm_interface.cpp | 48 | ||||
-rw-r--r-- | src/core/arm/arm_interface.h | 17 | ||||
-rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic_32.cpp | 34 | ||||
-rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic_32.h | 7 | ||||
-rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic_64.cpp | 33 | ||||
-rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic_64.h | 7 | ||||
-rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic_cp15.cpp | 2 | ||||
-rw-r--r-- | src/core/arm/symbols.cpp | 85 |
8 files changed, 118 insertions, 115 deletions
diff --git a/src/core/arm/arm_interface.cpp b/src/core/arm/arm_interface.cpp index c347e7ea7..9a285dfc6 100644 --- a/src/core/arm/arm_interface.cpp +++ b/src/core/arm/arm_interface.cpp @@ -9,7 +9,9 @@ #include "core/arm/arm_interface.h" #include "core/arm/symbols.h" #include "core/core.h" +#include "core/debugger/debugger.h" #include "core/hle/kernel/k_process.h" +#include "core/hle/kernel/svc.h" #include "core/loader/loader.h" #include "core/memory.h" @@ -88,4 +90,50 @@ void ARM_Interface::LogBacktrace() const { } } +void ARM_Interface::Run() { + using Kernel::StepState; + using Kernel::SuspendType; + + while (true) { + Kernel::KThread* current_thread{system.Kernel().CurrentScheduler()->GetCurrentThread()}; + Dynarmic::HaltReason hr{}; + + // Notify the debugger and go to sleep if a step was performed + // and this thread has been scheduled again. + if (current_thread->GetStepState() == StepState::StepPerformed) { + system.GetDebugger().NotifyThreadStopped(current_thread); + current_thread->RequestSuspend(SuspendType::Debug); + break; + } + + // Otherwise, run the thread. + system.EnterDynarmicProfile(); + if (current_thread->GetStepState() == StepState::StepPending) { + hr = StepJit(); + + if (Has(hr, step_thread)) { + current_thread->SetStepState(StepState::StepPerformed); + } + } else { + hr = RunJit(); + } + system.ExitDynarmicProfile(); + + // Notify the debugger and go to sleep if a breakpoint was hit. + if (Has(hr, breakpoint)) { + system.GetDebugger().NotifyThreadStopped(current_thread); + current_thread->RequestSuspend(Kernel::SuspendType::Debug); + break; + } + + // Handle syscalls and scheduling (this may change the current thread) + if (Has(hr, svc_call)) { + Kernel::Svc::Call(system, GetSvcNumber()); + } + if (Has(hr, break_loop) || !uses_wall_clock) { + break; + } + } +} + } // namespace Core diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index 8ce973a77..66f6107e9 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -6,6 +6,9 @@ #include <array> #include <vector> + +#include <dynarmic/interface/halt_reason.h> + #include "common/common_funcs.h" #include "common/common_types.h" #include "core/hardware_properties.h" @@ -64,10 +67,7 @@ public: static_assert(sizeof(ThreadContext64) == 0x320); /// Runs the CPU until an event happens - virtual void Run() = 0; - - /// Step CPU by one instruction - virtual void Step() = 0; + void Run(); /// Clear all instruction cache virtual void ClearInstructionCache() = 0; @@ -194,6 +194,11 @@ public: void LogBacktrace() const; + static constexpr Dynarmic::HaltReason step_thread = Dynarmic::HaltReason::Step; + static constexpr Dynarmic::HaltReason break_loop = Dynarmic::HaltReason::UserDefined2; + static constexpr Dynarmic::HaltReason svc_call = Dynarmic::HaltReason::UserDefined3; + static constexpr Dynarmic::HaltReason breakpoint = Dynarmic::HaltReason::UserDefined4; + protected: /// System context that this ARM interface is running under. System& system; @@ -201,6 +206,10 @@ protected: bool uses_wall_clock; static void SymbolicateBacktrace(Core::System& system, std::vector<BacktraceEntry>& out); + + virtual Dynarmic::HaltReason RunJit() = 0; + virtual Dynarmic::HaltReason StepJit() = 0; + virtual u32 GetSvcNumber() const = 0; }; } // namespace Core diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.cpp b/src/core/arm/dynarmic/arm_dynarmic_32.cpp index 781a77f6f..7c82d0b96 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_32.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_32.cpp @@ -17,6 +17,8 @@ #include "core/arm/dynarmic/arm_exclusive_monitor.h" #include "core/core.h" #include "core/core_timing.h" +#include "core/debugger/debugger.h" +#include "core/hle/kernel/k_process.h" #include "core/hle/kernel/svc.h" #include "core/memory.h" @@ -24,9 +26,6 @@ namespace Core { using namespace Common::Literals; -constexpr Dynarmic::HaltReason break_loop = Dynarmic::HaltReason::UserDefined2; -constexpr Dynarmic::HaltReason svc_call = Dynarmic::HaltReason::UserDefined3; - class DynarmicCallbacks32 : public Dynarmic::A32::UserCallbacks { public: explicit DynarmicCallbacks32(ARM_Dynarmic_32& parent_) @@ -78,16 +77,21 @@ public: } void ExceptionRaised(u32 pc, Dynarmic::A32::Exception exception) override { + if (parent.system.DebuggerEnabled()) { + parent.jit.load()->Regs()[15] = pc; + parent.jit.load()->HaltExecution(ARM_Interface::breakpoint); + return; + } + parent.LogBacktrace(); LOG_CRITICAL(Core_ARM, "ExceptionRaised(exception = {}, pc = {:08X}, code = {:08X}, thumb = {})", exception, pc, MemoryReadCode(pc), parent.IsInThumbMode()); - UNIMPLEMENTED(); } void CallSVC(u32 swi) override { parent.svc_swi = swi; - parent.jit.load()->HaltExecution(svc_call); + parent.jit.load()->HaltExecution(ARM_Interface::svc_call); } void AddTicks(u64 ticks) override { @@ -232,20 +236,16 @@ std::shared_ptr<Dynarmic::A32::Jit> ARM_Dynarmic_32::MakeJit(Common::PageTable* return std::make_unique<Dynarmic::A32::Jit>(config); } -void ARM_Dynarmic_32::Run() { - while (true) { - const auto hr = jit.load()->Run(); - if (Has(hr, svc_call)) { - Kernel::Svc::Call(system, svc_swi); - } - if (Has(hr, break_loop) || !uses_wall_clock) { - break; - } - } +Dynarmic::HaltReason ARM_Dynarmic_32::RunJit() { + return jit.load()->Run(); +} + +Dynarmic::HaltReason ARM_Dynarmic_32::StepJit() { + return jit.load()->Step(); } -void ARM_Dynarmic_32::Step() { - jit.load()->Step(); +u32 ARM_Dynarmic_32::GetSvcNumber() const { + return svc_swi; } ARM_Dynarmic_32::ARM_Dynarmic_32(System& system_, CPUInterrupts& interrupt_handlers_, diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.h b/src/core/arm/dynarmic/arm_dynarmic_32.h index abfe76644..5b1d60005 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_32.h +++ b/src/core/arm/dynarmic/arm_dynarmic_32.h @@ -41,8 +41,6 @@ public: void SetVectorReg(int index, u128 value) override; u32 GetPSTATE() const override; void SetPSTATE(u32 pstate) override; - void Run() override; - void Step() override; VAddr GetTlsAddress() const override; void SetTlsAddress(VAddr address) override; void SetTPIDR_EL0(u64 value) override; @@ -70,6 +68,11 @@ public: std::vector<BacktraceEntry> GetBacktrace() const override; +protected: + Dynarmic::HaltReason RunJit() override; + Dynarmic::HaltReason StepJit() override; + u32 GetSvcNumber() const override; + private: std::shared_ptr<Dynarmic::A32::Jit> MakeJit(Common::PageTable* page_table) const; diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.cpp b/src/core/arm/dynarmic/arm_dynarmic_64.cpp index 1b1334598..d4c67eafd 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_64.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_64.cpp @@ -15,6 +15,7 @@ #include "core/arm/dynarmic/arm_exclusive_monitor.h" #include "core/core.h" #include "core/core_timing.h" +#include "core/debugger/debugger.h" #include "core/hardware_properties.h" #include "core/hle/kernel/k_process.h" #include "core/hle/kernel/svc.h" @@ -25,9 +26,6 @@ namespace Core { using Vector = Dynarmic::A64::Vector; using namespace Common::Literals; -constexpr Dynarmic::HaltReason break_loop = Dynarmic::HaltReason::UserDefined2; -constexpr Dynarmic::HaltReason svc_call = Dynarmic::HaltReason::UserDefined3; - class DynarmicCallbacks64 : public Dynarmic::A64::UserCallbacks { public: explicit DynarmicCallbacks64(ARM_Dynarmic_64& parent_) @@ -119,8 +117,13 @@ public: case Dynarmic::A64::Exception::SendEventLocal: case Dynarmic::A64::Exception::Yield: return; - case Dynarmic::A64::Exception::Breakpoint: default: + if (parent.system.DebuggerEnabled()) { + parent.jit.load()->SetPC(pc); + parent.jit.load()->HaltExecution(ARM_Interface::breakpoint); + return; + } + parent.LogBacktrace(); ASSERT_MSG(false, "ExceptionRaised(exception = {}, pc = {:08X}, code = {:08X})", static_cast<std::size_t>(exception), pc, MemoryReadCode(pc)); @@ -129,7 +132,7 @@ public: void CallSVC(u32 swi) override { parent.svc_swi = swi; - parent.jit.load()->HaltExecution(svc_call); + parent.jit.load()->HaltExecution(ARM_Interface::svc_call); } void AddTicks(u64 ticks) override { @@ -293,20 +296,16 @@ std::shared_ptr<Dynarmic::A64::Jit> ARM_Dynarmic_64::MakeJit(Common::PageTable* return std::make_shared<Dynarmic::A64::Jit>(config); } -void ARM_Dynarmic_64::Run() { - while (true) { - const auto hr = jit.load()->Run(); - if (Has(hr, svc_call)) { - Kernel::Svc::Call(system, svc_swi); - } - if (Has(hr, break_loop) || !uses_wall_clock) { - break; - } - } +Dynarmic::HaltReason ARM_Dynarmic_64::RunJit() { + return jit.load()->Run(); +} + +Dynarmic::HaltReason ARM_Dynarmic_64::StepJit() { + return jit.load()->Step(); } -void ARM_Dynarmic_64::Step() { - jit.load()->Step(); +u32 ARM_Dynarmic_64::GetSvcNumber() const { + return svc_swi; } ARM_Dynarmic_64::ARM_Dynarmic_64(System& system_, CPUInterrupts& interrupt_handlers_, diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.h b/src/core/arm/dynarmic/arm_dynarmic_64.h index 01a7e4dad..abfbc3c3f 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_64.h +++ b/src/core/arm/dynarmic/arm_dynarmic_64.h @@ -39,8 +39,6 @@ public: void SetVectorReg(int index, u128 value) override; u32 GetPSTATE() const override; void SetPSTATE(u32 pstate) override; - void Run() override; - void Step() override; VAddr GetTlsAddress() const override; void SetTlsAddress(VAddr address) override; void SetTPIDR_EL0(u64 value) override; @@ -64,6 +62,11 @@ public: std::vector<BacktraceEntry> GetBacktrace() const override; +protected: + Dynarmic::HaltReason RunJit() override; + Dynarmic::HaltReason StepJit() override; + u32 GetSvcNumber() const override; + private: std::shared_ptr<Dynarmic::A64::Jit> MakeJit(Common::PageTable* page_table, std::size_t address_space_bits) const; diff --git a/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp b/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp index a043e6735..6aae79c48 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp @@ -20,7 +20,7 @@ struct fmt::formatter<Dynarmic::A32::CoprocReg> { } template <typename FormatContext> auto format(const Dynarmic::A32::CoprocReg& reg, FormatContext& ctx) { - return format_to(ctx.out(), "cp{}", static_cast<size_t>(reg)); + return fmt::format_to(ctx.out(), "cp{}", static_cast<size_t>(reg)); } }; diff --git a/src/core/arm/symbols.cpp b/src/core/arm/symbols.cpp index 4aa1a1ee1..0259c7ea2 100644 --- a/src/core/arm/symbols.cpp +++ b/src/core/arm/symbols.cpp @@ -3,73 +3,14 @@ #include "common/bit_field.h" #include "common/common_funcs.h" +#include "common/elf.h" #include "core/arm/symbols.h" #include "core/core.h" #include "core/memory.h" -namespace Core { -namespace { - -constexpr u64 ELF_DYNAMIC_TAG_NULL = 0; -constexpr u64 ELF_DYNAMIC_TAG_STRTAB = 5; -constexpr u64 ELF_DYNAMIC_TAG_SYMTAB = 6; -constexpr u64 ELF_DYNAMIC_TAG_SYMENT = 11; - -enum class ELFSymbolType : u8 { - None = 0, - Object = 1, - Function = 2, - Section = 3, - File = 4, - Common = 5, - TLS = 6, -}; - -enum class ELFSymbolBinding : u8 { - Local = 0, - Global = 1, - Weak = 2, -}; - -enum class ELFSymbolVisibility : u8 { - Default = 0, - Internal = 1, - Hidden = 2, - Protected = 3, -}; - -struct ELF64Symbol { - u32 name_index; - union { - u8 info; - - BitField<0, 4, ELFSymbolType> type; - BitField<4, 4, ELFSymbolBinding> binding; - }; - ELFSymbolVisibility visibility; - u16 sh_index; - u64 value; - u64 size; -}; -static_assert(sizeof(ELF64Symbol) == 0x18, "ELF64Symbol has incorrect size."); - -struct ELF32Symbol { - u32 name_index; - u32 value; - u32 size; - union { - u8 info; - - BitField<0, 4, ELFSymbolType> type; - BitField<4, 4, ELFSymbolBinding> binding; - }; - ELFSymbolVisibility visibility; - u16 sh_index; -}; -static_assert(sizeof(ELF32Symbol) == 0x10, "ELF32Symbol has incorrect size."); - -} // Anonymous namespace +using namespace Common::ELF; +namespace Core { namespace Symbols { template <typename Word, typename ELFSymbol, typename ByteReader> @@ -110,15 +51,15 @@ static Symbols GetSymbols(ByteReader ReadBytes) { const Word value = ReadWord(dynamic_index + sizeof(Word)); dynamic_index += 2 * sizeof(Word); - if (tag == ELF_DYNAMIC_TAG_NULL) { + if (tag == ElfDtNull) { break; } - if (tag == ELF_DYNAMIC_TAG_STRTAB) { + if (tag == ElfDtStrtab) { string_table_offset = value; - } else if (tag == ELF_DYNAMIC_TAG_SYMTAB) { + } else if (tag == ElfDtSymtab) { symbol_table_offset = value; - } else if (tag == ELF_DYNAMIC_TAG_SYMENT) { + } else if (tag == ElfDtSyment) { symbol_entry_size = value; } } @@ -134,14 +75,14 @@ static Symbols GetSymbols(ByteReader ReadBytes) { ELFSymbol symbol{}; ReadBytes(&symbol, symbol_index, sizeof(ELFSymbol)); - VAddr string_offset = string_table_offset + symbol.name_index; + VAddr string_offset = string_table_offset + symbol.st_name; std::string name; for (u8 c = Read8(string_offset); c != 0; c = Read8(++string_offset)) { name += static_cast<char>(c); } symbol_index += symbol_entry_size; - out[name] = std::make_pair(symbol.value, symbol.size); + out[name] = std::make_pair(symbol.st_value, symbol.st_size); } return out; @@ -152,9 +93,9 @@ Symbols GetSymbols(VAddr base, Core::Memory::Memory& memory, bool is_64) { [&](void* ptr, size_t offset, size_t size) { memory.ReadBlock(base + offset, ptr, size); }}; if (is_64) { - return GetSymbols<u64, ELF64Symbol>(ReadBytes); + return GetSymbols<u64, Elf64_Sym>(ReadBytes); } else { - return GetSymbols<u32, ELF32Symbol>(ReadBytes); + return GetSymbols<u32, Elf32_Sym>(ReadBytes); } } @@ -164,9 +105,9 @@ Symbols GetSymbols(std::span<const u8> data, bool is_64) { }}; if (is_64) { - return GetSymbols<u64, ELF64Symbol>(ReadBytes); + return GetSymbols<u64, Elf64_Sym>(ReadBytes); } else { - return GetSymbols<u32, ELF32Symbol>(ReadBytes); + return GetSymbols<u32, Elf32_Sym>(ReadBytes); } } |