Common:X64ABI: Make proper stack frames

This commit is contained in:
TellowKrinkle 2022-06-24 23:08:18 -05:00
parent b5da4e9d48
commit f2a074f4f8
2 changed files with 14 additions and 2 deletions

View File

@ -43,11 +43,18 @@ void XEmitter::ABI_CalculateFrameSize(BitSet32 mask, size_t rsp_alignment, size_
size_t XEmitter::ABI_PushRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignment,
size_t needed_frame_size)
{
mask[RSP] = false; // Stack pointer is never pushed
size_t shadow, subtraction, xmm_offset;
ABI_CalculateFrameSize(mask, rsp_alignment, needed_frame_size, &shadow, &subtraction,
&xmm_offset);
for (int r : mask& ABI_ALL_GPRS)
if (mask[RBP])
{
// Make a nice stack frame for any debuggers or profilers that might be looking at this
PUSH(RBP);
MOV(64, R(RBP), R(RSP));
}
for (int r : mask& ABI_ALL_GPRS & ~BitSet32{RBP})
PUSH((X64Reg)r);
if (subtraction)
@ -65,6 +72,7 @@ size_t XEmitter::ABI_PushRegistersAndAdjustStack(BitSet32 mask, size_t rsp_align
void XEmitter::ABI_PopRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignment,
size_t needed_frame_size)
{
mask[RSP] = false; // Stack pointer is never pushed
size_t shadow, subtraction, xmm_offset;
ABI_CalculateFrameSize(mask, rsp_alignment, needed_frame_size, &shadow, &subtraction,
&xmm_offset);
@ -80,9 +88,12 @@ void XEmitter::ABI_PopRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignmen
for (int r = 15; r >= 0; r--)
{
if (mask[r])
if (r != RBP && mask[r])
POP((X64Reg)r);
}
// RSP is pushed first and popped last to make debuggers/profilers happy
if (mask[RBP])
POP(RBP);
}
void XEmitter::MOVTwo(int bits, Gen::X64Reg dst1, Gen::X64Reg src1, s32 offset1, Gen::X64Reg dst2,

View File

@ -404,6 +404,7 @@ void VertexLoaderX64::GenerateVertexLoader()
BitSet32 regs = {src_reg, dst_reg, scratch1, scratch2,
scratch3, remaining_reg, skipped_reg, base_reg};
regs &= ABI_ALL_CALLEE_SAVED;
regs[RBP] = true; // Give us a stack frame
ABI_PushRegistersAndAdjustStack(regs, 0);
// Backup count since we're going to count it down.