From ec96d066abf6b1e6b5484b8a9cfa18cf0cd8612c Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 30 Aug 2025 20:22:24 +0000 Subject: [PATCH] [nce] more arm macos fixes Signed-off-by: lizzie --- src/core/arm/nce/arm_nce.cpp | 22 ++++++---------------- src/dynarmic/src/dynarmic/common/context.h | 12 ++++++------ 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/core/arm/nce/arm_nce.cpp b/src/core/arm/nce/arm_nce.cpp index dacc6c5583..198cbf1477 100644 --- a/src/core/arm/nce/arm_nce.cpp +++ b/src/core/arm/nce/arm_nce.cpp @@ -40,11 +40,7 @@ constexpr u32 StackSize = 128_KiB; } // namespace void* ArmNce::RestoreGuestContext(void* raw_context) { - // Retrieve the host context. - auto& host_ctx = static_cast(raw_context)->uc_mcontext; - // Retrieve the host floating point state. - auto* fpctx = GetFloatingPointState(host_ctx); - + CTX_DECLARE(raw_context); // Restore all guest state except tpidr_el0. // Thread-local parameters will be located in x9. auto* tpidr = reinterpret_cast(CTX_X(9)); @@ -66,12 +62,7 @@ void* ArmNce::RestoreGuestContext(void* raw_context) { } void ArmNce::SaveGuestContext(GuestContext* guest_ctx, void* raw_context) { - // Retrieve the host context. - auto& host_ctx = static_cast(raw_context)->uc_mcontext; - - // Retrieve the host floating point state. - auto* fpctx = GetFloatingPointState(host_ctx); - + CTX_DECLARE(raw_context); // Save all guest registers except tpidr_el0. std::memcpy(guest_ctx->cpu_registers.data(), &CTX_X(0), sizeof(guest_ctx->cpu_registers)); std::memcpy(guest_ctx->vector_registers.data(), &CTX_Q(0), sizeof(guest_ctx->vector_registers)); @@ -95,16 +86,15 @@ void ArmNce::SaveGuestContext(GuestContext* guest_ctx, void* raw_context) { } bool ArmNce::HandleFailedGuestFault(GuestContext* guest_ctx, void* raw_info, void* raw_context) { - auto& host_ctx = static_cast(raw_context)->uc_mcontext; + CTX_DECLARE(raw_context); auto* info = static_cast(raw_info); // We can't handle the access, so determine why we crashed. - const bool is_prefetch_abort = host_ctx.pc == reinterpret_cast(info->si_addr); - + auto const is_prefetch_abort = CTX_PC == reinterpret_cast(info->si_addr); // For data aborts, skip the instruction and return to guest code. // This will allow games to continue in many scenarios where they would otherwise crash. if (!is_prefetch_abort) { - host_ctx.pc += 4; + CTX_PC += 4; return true; } @@ -129,7 +119,7 @@ bool ArmNce::HandleGuestAlignmentFault(GuestContext* guest_ctx, void* raw_info, auto& memory = guest_ctx->system->ApplicationMemory(); // Match and execute an instruction. if (auto next_pc = MatchAndExecuteOneInstruction(memory, raw_context); next_pc) { - host_ctx.pc = *next_pc; + CTX_PC = *next_pc; return true; } // We couldn't handle the access. diff --git a/src/dynarmic/src/dynarmic/common/context.h b/src/dynarmic/src/dynarmic/common/context.h index 6f68d61e23..73f58b7329 100644 --- a/src/dynarmic/src/dynarmic/common/context.h +++ b/src/dynarmic/src/dynarmic/common/context.h @@ -17,13 +17,13 @@ #endif #ifndef MCL_ARCHITECTURE_RISCV -# ifndef __OpenBSD__ +# ifdef __OpenBSD__ +# define CTX_DECLARE(raw_context) ucontext_t* ucontext = reinterpret_cast(raw_context); +# else # define CTX_DECLARE(raw_context) \ ucontext_t* ucontext = reinterpret_cast(raw_context); \ - auto& mctx = reinterpret_cast(raw_context)->uc_mcontext; \ + [[maybe_unused]] auto& mctx = reinterpret_cast(raw_context)->uc_mcontext; \ [[maybe_unused]] const auto fpctx = GetFloatingPointState(mctx); -# else -# define CTX_DECLARE(raw_context) ucontext_t* ucontext = reinterpret_cast(raw_context); # endif #endif @@ -54,7 +54,7 @@ # define CTX_PC (mctx->__ss.__pc) # define CTX_SP (mctx->__ss.__sp) # define CTX_LR (mctx->__ss.__lr) -# define CTX_LR (mctx->__ss.__pstate) +# define CTX_PSTATE (mctx->__ss.__pstate) # define CTX_X(i) (mctx->__ss.__x[i]) # define CTX_Q(i) (mctx->__ns.__v[i]) # define CTX_FPSR(i) (mctx->__ns.__fpsr) @@ -63,7 +63,7 @@ # define CTX_PC (mctx.pc) # define CTX_SP (mctx.sp) # define CTX_LR (mctx.regs[30]) -# define CTX_SP (mctx.pstate) +# define CTX_PSTATE (mctx.pstate) # define CTX_X(i) (mctx.regs[i]) # define CTX_Q(i) (fpctx->vregs[i]) # elif defined(__FreeBSD__)