Skip to content

Commit

Permalink
PowerPC: Raise alignment exceptions in more situations
Browse files Browse the repository at this point in the history
To avoid affecting the performance, the JITs will most of
the time not raise alignment exceptions unless you enable
the INI-only setting AlignmentExceptions.
  • Loading branch information
JosJuice committed Oct 13, 2021
1 parent 75e5a6b commit 62a4279
Show file tree
Hide file tree
Showing 16 changed files with 229 additions and 191 deletions.
9 changes: 7 additions & 2 deletions Source/Core/Common/Arm64Emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,16 @@ static constexpr u32 MaskImm26(s64 distance)
}

// FixupBranch branching
void ARM64XEmitter::SetJumpTarget(FixupBranch const& branch)
void ARM64XEmitter::SetJumpTarget(const FixupBranch& branch)
{
SetJumpTarget(branch, m_code);
}

void ARM64XEmitter::SetJumpTarget(const FixupBranch& branch, const u8* target)
{
bool Not = false;
u32 inst = 0;
s64 distance = (s64)(m_code - branch.ptr);
s64 distance = static_cast<s64>(target - branch.ptr);
distance >>= 2;

switch (branch.type)
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Common/Arm64Emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ class ARM64XEmitter
u8* GetWritableCodePtr();

// FixupBranch branching
void SetJumpTarget(FixupBranch const& branch);
void SetJumpTarget(const FixupBranch& branch);
void SetJumpTarget(const FixupBranch& branch, const u8* target);
FixupBranch CBZ(ARM64Reg Rt);
FixupBranch CBNZ(ARM64Reg Rt);
FixupBranch B(CCFlags cond);
Expand Down
11 changes: 9 additions & 2 deletions Source/Core/Core/PowerPC/Interpreter/ExceptionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
#include "Core/PowerPC/Gekko.h"
#include "Core/PowerPC/PowerPC.h"

inline void GenerateAlignmentException(u32 address)
inline void GenerateAlignmentException(u32 effective_address, UGeckoInstruction inst)
{
PowerPC::ppcState.Exceptions |= EXCEPTION_ALIGNMENT;
PowerPC::ppcState.spr[SPR_DAR] = address;
PowerPC::ppcState.spr[SPR_DAR] = effective_address;

// It has not been hardware tested what gets used instead of RD and RA in
// the cases documented as undefined. For now, simply use RD and RA
const bool x = inst.OPCD >= 32;
const u32 op = x ? inst.SUBOP10 : (inst.OPCD >> 1);
const u32 dsisr = ((op >> 8) << 15) | ((op & 0b11111) << 10) | (inst.RD << 5) | (inst.RA);
PowerPC::ppcState.spr[SPR_DSISR] = dsisr;
}

inline void GenerateDSIException(u32 address)
Expand Down
Loading

0 comments on commit 62a4279

Please sign in to comment.