diff options
Diffstat (limited to '')
-rw-r--r-- | src/core/arm/unicorn/arm_unicorn.cpp | 2 | ||||
-rw-r--r-- | src/core/core.cpp | 5 | ||||
-rw-r--r-- | src/core/core.h | 11 | ||||
-rw-r--r-- | src/core/core_timing.cpp | 4 | ||||
-rw-r--r-- | src/core/core_timing.h | 3 | ||||
-rw-r--r-- | src/core/gdbstub/gdbstub.cpp | 10 | ||||
-rw-r--r-- | src/core/hle/kernel/event.h | 12 | ||||
-rw-r--r-- | src/core/perf_stats.cpp | 17 | ||||
-rw-r--r-- | src/core/perf_stats.h | 8 |
9 files changed, 50 insertions, 22 deletions
diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp index 4c11f35a4..6bc349460 100644 --- a/src/core/arm/unicorn/arm_unicorn.cpp +++ b/src/core/arm/unicorn/arm_unicorn.cpp @@ -203,7 +203,7 @@ void ARM_Unicorn::ExecuteInstructions(int num_instructions) { } Kernel::Thread* thread = Kernel::GetCurrentThread(); SaveContext(thread->context); - if (last_bkpt_hit || (num_instructions == 1)) { + if (last_bkpt_hit || GDBStub::GetCpuStepFlag()) { last_bkpt_hit = false; GDBStub::Break(); GDBStub::SendTrap(thread, 5); diff --git a/src/core/core.cpp b/src/core/core.cpp index e01c45cdd..085ba68d0 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -62,7 +62,6 @@ System::ResultStatus System::RunLoop(bool tight_loop) { // execute. Otherwise, get out of the loop function. if (GDBStub::GetCpuHaltFlag()) { if (GDBStub::GetCpuStepFlag()) { - GDBStub::SetCpuStepFlag(false); tight_loop = false; } else { return ResultStatus::Success; @@ -78,6 +77,10 @@ System::ResultStatus System::RunLoop(bool tight_loop) { } } + if (GDBStub::IsServerEnabled()) { + GDBStub::SetCpuStepFlag(false); + } + return status; } diff --git a/src/core/core.h b/src/core/core.h index a3be88aa8..c8ca4b247 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -82,6 +82,17 @@ public: */ ResultStatus SingleStep(); + /** + * Invalidate the CPU instruction caches + * This function should only be used by GDB Stub to support breakpoints, memory updates and + * step/continue commands. + */ + void InvalidateCpuInstructionCaches() { + for (auto& cpu : cpu_cores) { + cpu->ArmInterface().ClearInstructionCache(); + } + } + /// Shutdown the emulated system. void Shutdown(); diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index b2e3a495a..d3bb6f818 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -226,8 +226,8 @@ void Idle() { downcount = 0; } -u64 GetGlobalTimeUs() { - return GetTicks() * 1000000 / BASE_CLOCK_RATE; +std::chrono::microseconds GetGlobalTimeUs() { + return std::chrono::microseconds{GetTicks() * 1000000 / BASE_CLOCK_RATE}; } int GetDowncount() { diff --git a/src/core/core_timing.h b/src/core/core_timing.h index 5bbde47f4..dfa161c0d 100644 --- a/src/core/core_timing.h +++ b/src/core/core_timing.h @@ -17,6 +17,7 @@ * ScheduleEvent(periodInCycles - cyclesLate, callback, "whatever") */ +#include <chrono> #include <functional> #include <string> #include "common/common_types.h" @@ -86,7 +87,7 @@ void ClearPendingEvents(); void ForceExceptionCheck(s64 cycles); -u64 GetGlobalTimeUs(); +std::chrono::microseconds GetGlobalTimeUs(); int GetDowncount(); diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 884e64e99..332e5c3d0 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -173,6 +173,7 @@ struct Breakpoint { bool active; VAddr addr; u64 len; + std::array<u8, 4> inst; }; using BreakpointMap = std::map<VAddr, Breakpoint>; @@ -453,6 +454,8 @@ static void RemoveBreakpoint(BreakpointType type, VAddr addr) { LOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: {:016X} bytes at {:016X} of type {}", bp->second.len, bp->second.addr, static_cast<int>(type)); + Memory::WriteBlock(bp->second.addr, bp->second.inst.data(), bp->second.inst.size()); + Core::System::GetInstance().InvalidateCpuInstructionCaches(); p.erase(addr); } @@ -937,6 +940,7 @@ static void WriteMemory() { GdbHexToMem(data.data(), len_pos + 1, len); Memory::WriteBlock(addr, data.data(), len); + Core::System::GetInstance().InvalidateCpuInstructionCaches(); SendReply("OK"); } @@ -956,6 +960,7 @@ static void Step() { step_loop = true; halt_loop = true; send_trap = true; + Core::System::GetInstance().InvalidateCpuInstructionCaches(); } /// Tell the CPU if we hit a memory breakpoint. @@ -972,6 +977,7 @@ static void Continue() { memory_break = false; step_loop = false; halt_loop = false; + Core::System::GetInstance().InvalidateCpuInstructionCaches(); } /** @@ -988,6 +994,10 @@ static bool CommitBreakpoint(BreakpointType type, VAddr addr, u64 len) { breakpoint.active = true; breakpoint.addr = addr; breakpoint.len = len; + Memory::ReadBlock(addr, breakpoint.inst.data(), breakpoint.inst.size()); + static constexpr std::array<u8, 4> btrap{{0xd4, 0x20, 0x7d, 0x0}}; + Memory::WriteBlock(addr, btrap.data(), btrap.size()); + Core::System::GetInstance().InvalidateCpuInstructionCaches(); p.insert({addr, breakpoint}); LOG_DEBUG(Debug_GDBStub, "gdb: added {} breakpoint: {:016X} bytes at {:016X}", diff --git a/src/core/hle/kernel/event.h b/src/core/hle/kernel/event.h index 1c99911b2..3c20c05e8 100644 --- a/src/core/hle/kernel/event.h +++ b/src/core/hle/kernel/event.h @@ -31,10 +31,9 @@ public: return HANDLE_TYPE; } - ResetType reset_type; ///< Current ResetType - - bool signaled; ///< Whether the event has already been signaled - std::string name; ///< Name of event (optional) + ResetType GetResetType() const { + return reset_type; + } bool ShouldWait(Thread* thread) const override; void Acquire(Thread* thread) override; @@ -47,6 +46,11 @@ public: private: Event(); ~Event() override; + + ResetType reset_type; ///< Current ResetType + + bool signaled; ///< Whether the event has already been signaled + std::string name; ///< Name of event (optional) }; } // namespace Kernel diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index 5f53b16d3..8e09b9b63 100644 --- a/src/core/perf_stats.cpp +++ b/src/core/perf_stats.cpp @@ -40,22 +40,21 @@ void PerfStats::EndGameFrame() { game_frames += 1; } -PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) { +PerfStats::Results PerfStats::GetAndResetStats(microseconds current_system_time_us) { std::lock_guard<std::mutex> lock(object_mutex); - auto now = Clock::now(); + const auto now = Clock::now(); // Walltime elapsed since stats were reset - auto interval = duration_cast<DoubleSecs>(now - reset_point).count(); + const auto interval = duration_cast<DoubleSecs>(now - reset_point).count(); - auto system_us_per_second = - static_cast<double>(current_system_time_us - reset_point_system_us) / interval; + const auto system_us_per_second = (current_system_time_us - reset_point_system_us) / interval; Results results{}; results.system_fps = static_cast<double>(system_frames) / interval; results.game_fps = static_cast<double>(game_frames) / interval; results.frametime = duration_cast<DoubleSecs>(accumulated_frametime).count() / static_cast<double>(system_frames); - results.emulation_speed = system_us_per_second / 1'000'000.0; + results.emulation_speed = system_us_per_second.count() / 1'000'000.0; // Reset counters reset_point = now; @@ -74,10 +73,10 @@ double PerfStats::GetLastFrameTimeScale() { return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH; } -void FrameLimiter::DoFrameLimiting(u64 current_system_time_us) { +void FrameLimiter::DoFrameLimiting(microseconds current_system_time_us) { // Max lag caused by slow frames. Can be adjusted to compensate for too many slow frames. Higher // values increase the time needed to recover and limit framerate again after spikes. - constexpr microseconds MAX_LAG_TIME_US = 25ms; + constexpr microseconds MAX_LAG_TIME_US = 25us; if (!Settings::values.toggle_framelimit) { return; @@ -85,7 +84,7 @@ void FrameLimiter::DoFrameLimiting(u64 current_system_time_us) { auto now = Clock::now(); - frame_limiting_delta_err += microseconds(current_system_time_us - previous_system_time_us); + frame_limiting_delta_err += current_system_time_us - previous_system_time_us; frame_limiting_delta_err -= duration_cast<microseconds>(now - previous_walltime); frame_limiting_delta_err = std::clamp(frame_limiting_delta_err, -MAX_LAG_TIME_US, MAX_LAG_TIME_US); diff --git a/src/core/perf_stats.h b/src/core/perf_stats.h index 362b205c8..6e4619701 100644 --- a/src/core/perf_stats.h +++ b/src/core/perf_stats.h @@ -33,7 +33,7 @@ public: void EndSystemFrame(); void EndGameFrame(); - Results GetAndResetStats(u64 current_system_time_us); + Results GetAndResetStats(std::chrono::microseconds current_system_time_us); /** * Gets the ratio between walltime and the emulated time of the previous system frame. This is @@ -47,7 +47,7 @@ private: /// Point when the cumulative counters were reset Clock::time_point reset_point = Clock::now(); /// System time when the cumulative counters were reset - u64 reset_point_system_us = 0; + std::chrono::microseconds reset_point_system_us{0}; /// Cumulative duration (excluding v-sync/frame-limiting) of frames since last reset Clock::duration accumulated_frametime = Clock::duration::zero(); @@ -68,11 +68,11 @@ class FrameLimiter { public: using Clock = std::chrono::high_resolution_clock; - void DoFrameLimiting(u64 current_system_time_us); + void DoFrameLimiting(std::chrono::microseconds current_system_time_us); private: /// Emulated system time (in microseconds) at the last limiter invocation - u64 previous_system_time_us = 0; + std::chrono::microseconds previous_system_time_us{0}; /// Walltime at the last limiter invocation Clock::time_point previous_walltime = Clock::now(); |