This commit is contained in:
lizzie 2026-03-29 17:19:31 +00:00
parent 214517094a
commit e6a73ca06e
2 changed files with 31 additions and 13 deletions

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
/* This file is part of the dynarmic project.

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
@ -34,23 +34,21 @@
# endif
#endif
#ifdef ARCHITECTURE_x86_64
#ifdef ARCHITECTURE_arm64
# ifdef __OpenBSD__
# define CTX_DECLARE(raw_context) ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(raw_context);
# else
# define CTX_DECLARE(raw_context) \
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(raw_context); \
[[maybe_unused]] auto& mctx = ucontext->uc_mcontext;
# endif
#elif defined(ARCHITECTURE_arm64)
# ifdef __OpenBSD__
# define CTX_DECLARE(raw_context) ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(raw_context);
# else
# define CTX_DECLARE(raw_context) \
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(raw_context); \
# define CTX_DECLARE(raw_context) ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(raw_context); \
[[maybe_unused]] auto& mctx = ucontext->uc_mcontext; \
[[maybe_unused]] const auto fpctx = GetFloatingPointState(mctx);
# endif
#else
# ifdef __OpenBSD__
# define CTX_DECLARE(raw_context) ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(raw_context);
# else
# define CTX_DECLARE(raw_context) ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(raw_context); \
[[maybe_unused]] auto& mctx = ucontext->uc_mcontext;
# endif
#endif
#if defined(ARCHITECTURE_x86_64)
@ -67,6 +65,7 @@
# define CTX_RIP (mctx.__gregs[_REG_RIP])
# define CTX_RSP (mctx.__gregs[_REG_RSP])
# elif defined(__OpenBSD__)
// https://github.com/openbsd/src/blob/master/sys/arch/x86_64/include/signal.h
# define CTX_RIP (ucontext->sc_rip)
# define CTX_RSP (ucontext->sc_rsp)
# elif defined(__sun__)
@ -110,6 +109,7 @@
# define CTX_X(i) (mctx.mc_gpregs.gp_x[i])
# define CTX_Q(i) (mctx.mc_fpregs.fp_q[i])
# elif defined(__OpenBSD__)
// https://github.com/openbsd/src/blob/master/sys/arch/arm64/include/signal.h
# define CTX_PC (ucontext->sc_elr)
# define CTX_SP (ucontext->sc_sp)
# define CTX_LR (ucontext->sc_lr)
@ -126,12 +126,30 @@
# define CTX_SEPC (mctx.__gregs[REG_PC])
# define CTX_SP (mctx.__gregs[REG_SP])
# elif defined(__NetBSD__)
// https://github.com/NetBSD/src/blob/trunk/sys/arch/riscv/include/mcontext.h
# define CTX_SEPC (mctx.__gregs[_REG_PC])
# define CTX_SP (mctx.__gregs[_REG_SP])
# elif defined(__OpenBSD__)
// https://github.com/openbsd/src/blob/master/sys/arch/riscv64/include/signal.h
# define CTX_SEPC (ucontext->sc_sepc)
# define CTX_SP (ucontext->sc_sp)
# endif
#elif defined(ARCHITECTURE_powerpc64)
# if defined(__FreeBSD__)
# define CTX_PC (mctx.mc_srr0)
# define CTX_SP (mctx.mc_gpr[1])
# elif defined(__linux__)
// https://github.com/lattera/glibc/blob/master/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
# define CTX_PC (mctx.uc_regs[REG_PC])
# define CTX_SP (mctx.uc_regs[REG_SP])
# elif defined(__NetBSD__)
# define CTX_PC (mctx.__gregs[_REG_PC])
# define CTX_SP (mctx.__gregs[_REG_R1])
# elif defined(__OpenBSD__)
// https://github.com/openbsd/src/blob/master/sys/arch/powerpc64/include/signal.h
# define CTX_PC (ucontext->sc_pc)
# define CTX_SP (ucontext->sc_reg[1])
# endif
#else
# error "unimplemented"
#endif