From ebb0bd2b41fae0404762e4dfc8c97cb24423a905 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 27 Jul 2021 15:09:36 -0700 Subject: [PATCH] kern: improve single-step around user-exception entry --- .../arch/arm64/kern_exception_handlers.cpp | 17 +++++++++++------ .../arch/arm64/kern_exception_handlers_asm.s | 5 ----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libraries/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp b/libraries/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp index 714ce88f4..b54815e23 100644 --- a/libraries/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp +++ b/libraries/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp @@ -109,13 +109,9 @@ namespace ams::kern::arch::arm64 { break; } - /* If we should, clear the thread's state as single-step. */ + /* In the event that we return from this exception, we want SPSR.SS set so that we advance an instruction if single-stepping. */ #if defined(MESOSPHERE_ENABLE_HARDWARE_SINGLE_STEP) - if (AMS_UNLIKELY(GetCurrentThread().IsSingleStep())) { - GetCurrentThread().ClearSingleStep(); - cpu::MonitorDebugSystemControlRegisterAccessor().SetSoftwareStep(false).Store(); - cpu::EnsureInstructionConsistency(); - } + context->psr |= (1ul << 21); #endif /* If we should process the user exception (and it's not a breakpoint), try to enter. */ @@ -224,6 +220,15 @@ namespace ams::kern::arch::arm64 { } } + /* If we should, clear the thread's state as single-step. */ + #if defined(MESOSPHERE_ENABLE_HARDWARE_SINGLE_STEP) + if (AMS_UNLIKELY(GetCurrentThread().IsSingleStep())) { + GetCurrentThread().ClearSingleStep(); + cpu::MonitorDebugSystemControlRegisterAccessor().SetSoftwareStep(false).Store(); + cpu::EnsureInstructionConsistency(); + } + #endif + { /* Collect additional information based on the ec. */ ams::svc::DebugException exception; diff --git a/mesosphere/kernel/source/arch/arm64/kern_exception_handlers_asm.s b/mesosphere/kernel/source/arch/arm64/kern_exception_handlers_asm.s index 0f0c6a7a7..d376de636 100644 --- a/mesosphere/kernel/source/arch/arm64/kern_exception_handlers_asm.s +++ b/mesosphere/kernel/source/arch/arm64/kern_exception_handlers_asm.s @@ -217,11 +217,6 @@ _ZN3ams4kern4arch5arm6430EL0SynchronousExceptionHandlerEv: ldp x21, x22, [sp, #(EXCEPTION_CONTEXT_PC_PSR)] ldr x23, [sp, #(EXCEPTION_CONTEXT_TPIDR)] - #if defined(MESOSPHERE_ENABLE_HARDWARE_SINGLE_STEP) - /* Since we're returning from an exception, set SPSR.SS so that we advance an instruction if single-stepping. */ - orr x22, x22, #(1 << 21) - #endif - msr sp_el0, x20 msr elr_el1, x21 msr spsr_el1, x22