lizzie 6 days ago
parent
commit
7ec24e3b1a
  1. 7
      src/dynarmic/src/dynarmic/backend/x64/a64_emit_x64.cpp
  2. 7
      src/dynarmic/src/dynarmic/backend/x64/abi.cpp
  3. 14
      src/dynarmic/src/dynarmic/backend/x64/exception_handler_windows.cpp

7
src/dynarmic/src/dynarmic/backend/x64/a64_emit_x64.cpp

@ -90,6 +90,10 @@ A64EmitX64::BlockDescriptor A64EmitX64::Emit(IR::Block& block) noexcept {
code.align();
const auto* const entrypoint = code.getCurr();
code.push(rbp);
code.mov(rbp, rsp);
code.and_(rsp, -16);
DEBUG_ASSERT(block.GetCondition() == IR::Cond::AL);
typedef void (EmitX64::*EmitHandlerFn)(EmitContext& context, IR::Inst* inst);
constexpr EmitHandlerFn opcode_handlers[] = {
@ -248,6 +252,9 @@ void A64EmitX64::GenTerminalHandlers() {
}
code.and_(code.ABI_PARAM1.cvt32(), fast_dispatch_table_mask);
code.lea(code.ABI_RETURN, code.ptr[code.ABI_PARAM2 + code.ABI_PARAM1]);
code.mov(rsp, rbp);
code.pop(rbp);
code.ret();
PerfMapRegister(fast_dispatch_table_lookup, code.getCurr(), "a64_fast_dispatch_table_lookup");
}

7
src/dynarmic/src/dynarmic/backend/x64/abi.cpp

@ -43,12 +43,10 @@ static FrameInfo CalculateFrameInfo(const size_t num_gprs, const size_t num_xmms
void ABI_PushRegistersAndAdjustStack(BlockOfCode& code, const size_t frame_size, std::bitset<32> const& regs) {
using namespace Xbyak::util;
const size_t num_gprs = (ABI_ALL_GPRS & regs).count() + 1;
const size_t num_gprs = (ABI_ALL_GPRS & regs).count();
const size_t num_xmms = (ABI_ALL_XMMS & regs).count();
const FrameInfo frame_info = CalculateFrameInfo(num_gprs, num_xmms, frame_size);
code.push(rbp);
code.mov(rbp, rsp);
for (size_t i = 0; i < regs.size(); ++i)
if (regs[i] && HostLocIsGPR(HostLoc(i)))
code.push(HostLocToReg64(HostLoc(i)));
@ -70,7 +68,7 @@ void ABI_PushRegistersAndAdjustStack(BlockOfCode& code, const size_t frame_size,
void ABI_PopRegistersAndAdjustStack(BlockOfCode& code, const size_t frame_size, std::bitset<32> const& regs) {
using namespace Xbyak::util;
const size_t num_gprs = (ABI_ALL_GPRS & regs).count() + 1;
const size_t num_gprs = (ABI_ALL_GPRS & regs).count();
const size_t num_xmms = (ABI_ALL_XMMS & regs).count();
const FrameInfo frame_info = CalculateFrameInfo(num_gprs, num_xmms, frame_size);
@ -89,7 +87,6 @@ void ABI_PopRegistersAndAdjustStack(BlockOfCode& code, const size_t frame_size,
for (int32_t i = regs.size() - 1; i >= 0; --i)
if (regs[i] && HostLocIsGPR(HostLoc(i)))
code.pop(HostLocToReg64(HostLoc(i)));
code.pop(rbp);
}
void ABI_PushCalleeSaveRegistersAndAdjustStack(BlockOfCode& code, const std::size_t frame_size) {

14
src/dynarmic/src/dynarmic/backend/x64/exception_handler_windows.cpp

@ -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.
@ -176,7 +176,7 @@ struct ExceptionHandler::Impl final {
code.align(16);
const u8* exception_handler_without_cb = code.getCurr<u8*>();
code.mov(code.eax, static_cast<u32>(ExceptionContinueSearch));
code.mov(code.eax, u32(ExceptionContinueSearch));
code.ret();
code.align(16);
@ -192,20 +192,18 @@ struct ExceptionHandler::Impl final {
code.lea(code.rsp, code.ptr[code.rsp - 8]);
code.mov(code.ABI_PARAM1, std::bit_cast<u64>(&cb));
code.mov(code.ABI_PARAM2, code.ABI_PARAM3);
code.CallLambda(
[](const std::function<FakeCall(u64)>& cb_, PCONTEXT ctx) {
code.CallLambda([](const std::function<FakeCall(u64)>& cb_, PCONTEXT ctx) {
FakeCall fc = cb_(ctx->Rip);
ctx->Rsp -= sizeof(u64);
*std::bit_cast<u64*>(ctx->Rsp) = fc.ret_rip;
ctx->Rip = fc.call_rip;
});
code.add(code.rsp, 8);
code.mov(code.eax, static_cast<u32>(ExceptionContinueExecution));
code.mov(code.eax, u32(ExceptionContinueExecution));
code.ret();
exception_handler_without_cb_offset = static_cast<ULONG>(exception_handler_without_cb - code.getCode<u8*>());
exception_handler_with_cb_offset = static_cast<ULONG>(exception_handler_with_cb - code.getCode<u8*>());
exception_handler_without_cb_offset = ULONG(exception_handler_without_cb - code.getCode<u8*>());
exception_handler_with_cb_offset = ULONG(exception_handler_with_cb - code.getCode<u8*>());
code.align(16);
UNWIND_INFO* unwind_info = static_cast<UNWIND_INFO*>(code.AllocateFromCodeSpace(sizeof(UNWIND_INFO)));

Loading…
Cancel
Save