From cf53896b897429ceb3d0c42f8051cdbf856e3c8f Mon Sep 17 00:00:00 2001 From: AJR Date: Sun, 13 Mar 2022 11:58:29 -0400 Subject: [PATCH] arm7: Add debugger privilege callback for 26/32, A/T and user mode changes --- src/devices/cpu/arm7/arm7.cpp | 8 ++++++++ src/devices/cpu/arm7/arm7ops.cpp | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/devices/cpu/arm7/arm7.cpp b/src/devices/cpu/arm7/arm7.cpp index 813cf22c619..7a67c2f5a30 100644 --- a/src/devices/cpu/arm7/arm7.cpp +++ b/src/devices/cpu/arm7/arm7.cpp @@ -300,6 +300,7 @@ void arm7_cpu_device::update_reg_ptr() void arm7_cpu_device::set_cpsr(uint32_t val) { uint8_t old_mode = GET_CPSR & MODE_FLAG; + bool call_hook = false; if (m_archFlags & ARCHFLAG_MODE26) { if ((val & 0x10) != (m_r[eCPSR] & 0x10)) @@ -315,6 +316,7 @@ void arm7_cpu_device::set_cpsr(uint32_t val) // 32 -> 26 m_r[eR15] = (m_r[eR15] & 0x03FFFFFC) /* PC */ | (val & 0xF0000000) /* N Z C V */ | ((val & 0x000000C0) << (26 - 6)) /* I F */ | (val & 0x00000003) /* M1 M0 */; } + call_hook = true; } else { @@ -329,11 +331,17 @@ void arm7_cpu_device::set_cpsr(uint32_t val) { val |= 0x10; // force valid mode } + if ((val & T_MASK) != (m_r[eCPSR] & T_MASK)) + call_hook = true; m_r[eCPSR] = val; if ((GET_CPSR & MODE_FLAG) != old_mode) { + if ((GET_CPSR & MODE_FLAG) == eARM7_MODE_USER || old_mode == eARM7_MODE_USER) + call_hook = true; update_reg_ptr(); } + if (call_hook) + debugger_privilege_hook(); } diff --git a/src/devices/cpu/arm7/arm7ops.cpp b/src/devices/cpu/arm7/arm7ops.cpp index f5a8f435762..9737ce8bede 100644 --- a/src/devices/cpu/arm7/arm7ops.cpp +++ b/src/devices/cpu/arm7/arm7ops.cpp @@ -1676,8 +1676,8 @@ void arm7_cpu_device::arm7ops_0123(uint32_t insn) R15 = GetRegister(insn & 0x0f); // If new PC address has A0 set, switch to Thumb mode if (R15 & 1) { - set_cpsr(GET_CPSR|T_MASK); R15--; + set_cpsr(GET_CPSR|T_MASK); } } else if ((insn & 0x0ff000f0) == 0x01200030) // BLX Rn - v5 @@ -1688,8 +1688,8 @@ void arm7_cpu_device::arm7ops_0123(uint32_t insn) R15 = GetRegister(insn & 0x0f); // If new PC address has A0 set, switch to Thumb mode if (R15 & 1) { - set_cpsr(GET_CPSR|T_MASK); R15--; + set_cpsr(GET_CPSR|T_MASK); } } else if ((insn & 0x0ff000f0) == 0x01600010) // CLZ - v5