From 9c78f70071daa8d4d65ffe335c21af0e4b523841 Mon Sep 17 00:00:00 2001 From: Oxore Date: Sun, 25 Sep 2022 16:37:03 +0300 Subject: Impl read and write watchpoints --- emulator.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'emulator.cpp') diff --git a/emulator.cpp b/emulator.cpp index 7a1dffa..ea2c051 100644 --- a/emulator.cpp +++ b/emulator.cpp @@ -287,6 +287,45 @@ int m68k_instr_callback(int pc) return 0; } +static inline bool ranges_overlap( + const uint32_t a_start, + const uint32_t a_len, + const uint32_t b_start, + const uint32_t b_len) +{ + return (a_start < b_start + b_len && b_start < a_start + a_len); +} + +// XXX Maybe better move it to bus.cpp? +void m68k_read_callback(const uint32_t address, const uint32_t size) +{ + const auto it = std::find_if( + read_bkpts.begin(), + read_bkpts.end(), + [&](const Breakpoint& b) { return ranges_overlap(address, size, b.offset, b.length); }); + if (it != read_bkpts.end()) { + g_m68k_debug.SetRunning(false); + g_m68k_debug.RaiseBreakpoint(); + m68k_end_timeslice(); + printf("Read watchpoint @ 0x%08x\n", address); + } +} + +// XXX Maybe better move it to bus.cpp? +void m68k_write_callback(const uint32_t address, const uint32_t size) +{ + const auto it = std::find_if( + write_bkpts.begin(), + write_bkpts.end(), + [&](const Breakpoint& b) { return ranges_overlap(address, size, b.offset, b.length); }); + if (it != write_bkpts.end()) { + g_m68k_debug.SetRunning(false); + g_m68k_debug.RaiseBreakpoint(); + m68k_end_timeslice(); + printf("Write watchpoint @ 0x%08x\n", address); + } +} + void ParseAndReact( int conn_fd, GDBRemote::ExchangeContext& exchange_ctx, -- cgit v1.2.3