mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-05 06:26:49 +00:00
Rework aarch64 signal handling
This commit is contained in:
parent
d6acdc77e0
commit
4bb79b6c31
4 changed files with 142 additions and 2 deletions
|
|
@ -393,6 +393,7 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
|||
target_sources(rpcs3_emu PRIVATE
|
||||
CPU/Backends/AArch64/AArch64ASM.cpp
|
||||
CPU/Backends/AArch64/AArch64JIT.cpp
|
||||
CPU/Backends/AArch64/AArch64Signal.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
|
|||
83
rpcs3/Emu/CPU/Backends/AArch64/AArch64Signal.cpp
Normal file
83
rpcs3/Emu/CPU/Backends/AArch64/AArch64Signal.cpp
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#include <stdafx.h>
|
||||
#include "AArch64Signal.h"
|
||||
|
||||
namespace aarch64
|
||||
{
|
||||
constexpr u32 ESR_CTX_MAGIC = 0x45535201;
|
||||
|
||||
// Some of the EC codes we care about
|
||||
enum class EL1_exception_class
|
||||
{
|
||||
undefined = 0,
|
||||
|
||||
instr_abort_0 = 32, // PAGE_FAULT - Execute, change in EL
|
||||
instr_abort_1 = 33, // PAGE_FAULT - Execute, same EL
|
||||
data_abort_0 = 36, // PAGE_FAULT - Generic, causing change in EL (e.g kernel sig handler back to EL0)
|
||||
data_abort_1 = 37, // PAGE_FAULT - Generic, no change in EL, e.g EL1 driver fault
|
||||
|
||||
illegal_execution = 14, // BUS_ERROR
|
||||
unaligned_pc = 34, // BUS_ERROR
|
||||
unaligned_sp = 38, // BUS_ERROR
|
||||
|
||||
breakpoint = 60, // BRK
|
||||
};
|
||||
|
||||
const aarch64_esr_ctx* find_EL1_esr_context(const ucontext_t* ctx)
|
||||
{
|
||||
u32 offset = 0;
|
||||
const auto& mctx = ctx->uc_mcontext;
|
||||
|
||||
while ((offset + 4) < sizeof(mctx.__reserved))
|
||||
{
|
||||
auto head = reinterpret_cast<const aarch64_cpu_ctx_block*>(&mctx.__reserved[offset]);
|
||||
if (!head->magic)
|
||||
{
|
||||
// End of linked list
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (head->magic == ESR_CTX_MAGIC)
|
||||
{
|
||||
return reinterpret_cast<const aarch64_esr_ctx*>(head);
|
||||
}
|
||||
|
||||
offset += head->size;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
fault_reason decode_fault_reason(const ucontext_t* uctx)
|
||||
{
|
||||
auto esr_ctx = find_EL1_esr_context(uctx);
|
||||
if (!esr_ctx) {
|
||||
return fault_reason::undefined;
|
||||
}
|
||||
|
||||
// We don't really care about most of the register fields, but we can check for a few things.
|
||||
const auto exception_class = (esr_ctx->esr >> 26) & 0b111111;
|
||||
switch (static_cast<EL1_exception_class>(exception_class))
|
||||
{
|
||||
case EL1_exception_class::breakpoint:
|
||||
// Debug break
|
||||
return fault_reason::breakpoint;
|
||||
case EL1_exception_class::illegal_execution:
|
||||
case EL1_exception_class::unaligned_pc:
|
||||
case EL1_exception_class::unaligned_sp:
|
||||
return fault_reason::illegal_instruction;
|
||||
case EL1_exception_class::instr_abort_0:
|
||||
case EL1_exception_class::instr_abort_1:
|
||||
return fault_reason::instruction_execute;
|
||||
case EL1_exception_class::data_abort_0:
|
||||
case EL1_exception_class::data_abort_1:
|
||||
// Page fault
|
||||
break;
|
||||
default:
|
||||
return fault_reason::undefined;
|
||||
}
|
||||
|
||||
// Check direction bit
|
||||
const auto direction = (esr_ctx->esr >> 6u) & 1u;
|
||||
return direction ? fault_reason::data_write : fault_reason::data_read;
|
||||
}
|
||||
}
|
||||
37
rpcs3/Emu/CPU/Backends/AArch64/AArch64Signal.h
Normal file
37
rpcs3/Emu/CPU/Backends/AArch64/AArch64Signal.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include <util/types.hpp>
|
||||
#include <sys/ucontext.h>
|
||||
|
||||
namespace aarch64
|
||||
{
|
||||
// Some renamed kernel definitions, we don't need to include kernel headers directly
|
||||
#pragma pack(push, 1)
|
||||
|
||||
struct aarch64_cpu_ctx_block
|
||||
{
|
||||
u32 magic;
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct aarch64_esr_ctx
|
||||
{
|
||||
aarch64_cpu_ctx_block head;
|
||||
u64 esr; // Exception syndrome register
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
// Fault reason
|
||||
enum class fault_reason
|
||||
{
|
||||
undefined = 0,
|
||||
data_read,
|
||||
data_write,
|
||||
instruction_execute,
|
||||
illegal_instruction,
|
||||
breakpoint
|
||||
};
|
||||
|
||||
fault_reason decode_fault_reason(const ucontext_t* uctx);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue