Skip to content

Commit

Permalink
dynarec: use sh4 ctx to get register pointers. prefer offset
Browse files Browse the repository at this point in the history
Move restoreHostRoundingMode() into Sh4Context
  • Loading branch information
flyinghead committed Nov 9, 2024
1 parent 7c1c581 commit 129673a
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 140 deletions.
14 changes: 7 additions & 7 deletions core/debug/debug_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ class DebugAgent
for (u32 i = 0; i < Sh4RegList.size(); i++)
{
if (Sh4RegList[i] == reg_sr_status)
allregs[i] = p_sh4rcb->cntx.sr.getFull();
allregs[i] = Sh4cntx.sr.getFull();
else if (Sh4RegList[i] != NoReg)
allregs[i] = *GetRegPtr(Sh4RegList[i]);
allregs[i] = *GetRegPtr(Sh4cntx, Sh4RegList[i]);
}
*regs = &allregs[0];
return allregs.size();
Expand All @@ -134,7 +134,7 @@ class DebugAgent
{
for (u32 i = 0; i < Sh4RegList.size(); i++)
if (Sh4RegList[i] != NoReg)
*GetRegPtr(Sh4RegList[i]) = regs[i];
*GetRegPtr(Sh4cntx, Sh4RegList[i]) = regs[i];
}

u32 readReg(u32 regNum)
Expand All @@ -143,9 +143,9 @@ class DebugAgent
return 0;
Sh4RegType reg = Sh4RegList[regNum];
if (reg == reg_sr_status)
return p_sh4rcb->cntx.sr.getFull();
return Sh4cntx.sr.getFull();
if (reg != NoReg)
return *GetRegPtr(reg);
return *GetRegPtr(Sh4cntx, reg);
return 0;
}
void writeReg(u32 regNum, u32 value)
Expand All @@ -154,9 +154,9 @@ class DebugAgent
return;
Sh4RegType reg = Sh4RegList[regNum];
if (reg == reg_sr_status)
p_sh4rcb->cntx.sr.setFull(value);
Sh4cntx.sr.setFull(value);
else if (reg != NoReg)
*GetRegPtr(reg) = value;
*GetRegPtr(Sh4cntx, reg) = value;
}

const u8 *readMem(u32 addr, u32 len)
Expand Down
6 changes: 2 additions & 4 deletions core/hw/pvr/Renderer_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "serialize.h"
#include "hw/holly/holly_intc.h"
#include "hw/sh4/sh4_if.h"
#include "hw/sh4/sh4_core.h"
#include "profiler/fc_profiler.h"
#include "network/ggpo.h"

Expand Down Expand Up @@ -90,15 +91,12 @@ class PvrMessageQueue
}
else
{
void setDefaultRoundingMode();
void RestoreHostRoundingMode();

setDefaultRoundingMode();
// drain the queue after switching to !threaded rendering
while (!queue.empty())
waitAndExecute();
execute(msg);
RestoreHostRoundingMode();
Sh4cntx.restoreHostRoundingMode();
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/hw/sh4/dyna/blockmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static bm_Map blkmap;
u32 protected_blocks;
u32 unprotected_blocks;

#define FPCA(x) ((DynarecCodeEntryPtr&)sh4rcb.fpcb[(x>>1)&FPCB_MASK])
#define FPCA(x) ((DynarecCodeEntryPtr&)p_sh4rcb->fpcb[(x>>1)&FPCB_MASK])

// addr must be a physical address
// This returns an executable address
Expand Down
6 changes: 3 additions & 3 deletions core/hw/sh4/dyna/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ void Sh4Recompiler::ResetCache()

void Sh4Recompiler::Run()
{
RestoreHostRoundingMode();
getContext()->restoreHostRoundingMode();

u8 *sh4_dyna_rcb = (u8 *)getContext() + sizeof(Sh4cntx);
INFO_LOG(DYNAREC, "cntx // fpcb offset: %td // pc offset: %td // pc %08X", (u8*)&sh4rcb.fpcb - sh4_dyna_rcb,
u8 *sh4_dyna_rcb = (u8 *)getContext() + sizeof(Sh4Context);
INFO_LOG(DYNAREC, "cntx // fpcb offset: %td // pc offset: %td // pc %08X", (u8*)p_sh4rcb->fpcb - sh4_dyna_rcb,
(u8*)&getContext()->pc - sh4_dyna_rcb, getContext()->pc);

sh4Dynarec->mainloop(sh4_dyna_rcb);
Expand Down
4 changes: 2 additions & 2 deletions core/hw/sh4/dyna/shil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ u32 getRegOffset(Sh4RegType reg)
}
}

u32* GetRegPtr(u32 reg)
u32* GetRegPtr(Sh4Context& ctx, u32 reg)
{
return (u32 *)((u8 *)&p_sh4rcb->cntx + getRegOffset((Sh4RegType)reg));
return (u32 *)((u8 *)&ctx + getRegOffset((Sh4RegType)reg));
}

std::string name_reg(Sh4RegType reg)
Expand Down
5 changes: 3 additions & 2 deletions core/hw/sh4/dyna/shil.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ enum Sh4RegType
};

u32 getRegOffset(Sh4RegType reg);
u32* GetRegPtr(u32 reg);
u32* GetRegPtr(Sh4Context& ctx, u32 reg);

enum shil_param_type
{
Expand Down Expand Up @@ -231,7 +231,8 @@ struct shil_param

bool is_imm_s8() const { return is_imm() && (int8_t)_imm == (int32_t)_imm; }

u32* reg_ptr() const { verify(is_reg()); return GetRegPtr(_reg); }
u32* reg_ptr(Sh4Context& ctx) const { verify(is_reg()); return GetRegPtr(ctx, _reg); }
u32 reg_offset() const { verify(is_reg()); return getRegOffset(_reg); }
s32 reg_nofs() const { verify(is_reg()); return (int)getRegOffset(_reg) - sizeof(Sh4Context); }
u32 reg_aofs() const { return -reg_nofs(); }

Expand Down
4 changes: 2 additions & 2 deletions core/hw/sh4/interpr/sh4_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ u16 Sh4Interpreter::ReadNexOp()
void Sh4Interpreter::Run()
{
Instance = this;
RestoreHostRoundingMode();
ctx->restoreHostRoundingMode();

try {
do
Expand Down Expand Up @@ -83,7 +83,7 @@ void Sh4Interpreter::Step()
verify(!ctx->CpuRunning);
Instance = this;

RestoreHostRoundingMode();
ctx->restoreHostRoundingMode();
try {
u32 op = ReadNexOp();
ExecuteOpcode(op);
Expand Down
1 change: 0 additions & 1 deletion core/hw/sh4/sh4_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

int UpdateSystem_INTC();
bool UpdateSR();
void RestoreHostRoundingMode();
void setDefaultRoundingMode();

struct SH4ThrownException
Expand Down
4 changes: 2 additions & 2 deletions core/hw/sh4/sh4_core_regs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ void DYNACALL Sh4Context::UpdateFPSCR(Sh4Context *ctx)
setHostRoundingMode(ctx->fpscr.RM, ctx->fpscr.DN);
}

void RestoreHostRoundingMode()
void Sh4Context::restoreHostRoundingMode()
{
old_rm = 0xFF;
old_dn = 0xFF;
setHostRoundingMode(p_sh4rcb->cntx.fpscr.RM, p_sh4rcb->cntx.fpscr.DN);
setHostRoundingMode(fpscr.RM, fpscr.DN);
}

void setDefaultRoundingMode()
Expand Down
4 changes: 2 additions & 2 deletions core/hw/sh4/sh4_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ struct alignas(64) Sh4Context
}

static void DYNACALL UpdateFPSCR(Sh4Context *ctx);
void restoreHostRoundingMode();

private:
union DoubleReg
Expand Down Expand Up @@ -240,8 +241,7 @@ struct alignas(PAGE_SIZE) Sh4RCB
static_assert((sizeof(Sh4RCB) % PAGE_SIZE) == 0, "sizeof(Sh4RCB) not multiple of PAGE_SIZE");

extern Sh4RCB* p_sh4rcb;
#define sh4rcb (*p_sh4rcb)
#define Sh4cntx (sh4rcb.cntx)
#define Sh4cntx (p_sh4rcb->cntx)

//Get an interface to sh4 interpreter
Sh4Executor *Get_Sh4Interpreter();
Expand Down
2 changes: 1 addition & 1 deletion core/rec-ARM/rec_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ void Arm32Assembler::canonCall(const shil_opcode *op, void *function)
CC_PS& param = CC_pars[i];
if (param.type == CPT_ptr)
{
Mov(rd, (u32)param.par->reg_ptr());
Mov(rd, (u32)param.par->reg_ptr(sh4ctx));
}
else if (param.type == CPT_sh4ctx)
{
Expand Down
Loading

0 comments on commit 129673a

Please sign in to comment.