Skip to content

Commit

Permalink
sh4: pass context to interpreter funcs. get rid of sh4 regs #define
Browse files Browse the repository at this point in the history
  • Loading branch information
flyinghead committed Nov 8, 2024
1 parent 9cb7d9e commit db846ca
Show file tree
Hide file tree
Showing 24 changed files with 770 additions and 799 deletions.
16 changes: 8 additions & 8 deletions core/hw/sh4/dyna/blockmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ DynarecCodeEntryPtr DYNACALL bm_GetCodeByVAddr(u32 addr)
#ifdef USE_WINCE_HACK
case 0xfffffde7: // GetTickCount
// This should make this syscall faster
r[0] = sh4_sched_now64() * 1000 / SH4_MAIN_CLOCK;
next_pc = pr;
Sh4cntx.r[0] = sh4_sched_now64() * 1000 / SH4_MAIN_CLOCK;
Sh4cntx.pc = Sh4cntx.pr;
Sh4cntx.cycle_counter -= 100;
break;

Expand All @@ -75,11 +75,11 @@ DynarecCodeEntryPtr DYNACALL bm_GetCodeByVAddr(u32 addr)
bool isRam;
u64 *ptr;
u32 paddr;
if (rdv_writeMemImmediate(r[4], sizeof(u64), (void*&)ptr, isRam, paddr) && isRam)
if (rdv_writeMemImmediate(Sh4cntx.r[4], sizeof(u64), (void*&)ptr, isRam, paddr) && isRam)
{
*ptr = sh4_sched_now64() >> 4;
r[0] = 1;
next_pc = pr;
Sh4cntx.r[0] = 1;
Sh4cntx.pc = Sh4cntx.pr;
Sh4cntx.cycle_counter -= 100;
}
else
Expand All @@ -94,15 +94,15 @@ DynarecCodeEntryPtr DYNACALL bm_GetCodeByVAddr(u32 addr)
Do_Exception(addr, Sh4Ex_AddressErrorRead);
break;
}
addr = next_pc;
addr = Sh4cntx.pc;
}

u32 paddr;
MmuError rv = mmu_instruction_translation(addr, paddr);
if (rv != MmuError::NONE)
{
DoMMUException(addr, rv, MMU_TT_IREAD);
mmu_instruction_translation(next_pc, paddr);
mmu_instruction_translation(Sh4cntx.pc, paddr);
}

return bm_GetCode(paddr);
Expand Down Expand Up @@ -472,7 +472,7 @@ void bm_RamWriteAccess(u32 addr)
std::vector<RuntimeBlockInfo*> list_copy;
list_copy.insert(list_copy.begin(), block_list.begin(), block_list.end());
if (!list_copy.empty())
DEBUG_LOG(DYNAREC, "bm_RamWriteAccess write access to %08x pc %08x", addr, next_pc);
DEBUG_LOG(DYNAREC, "bm_RamWriteAccess write access to %08x pc %08x", addr, Sh4cntx.pc);
for (auto& block : list_copy)
bm_DiscardBlock(block);
verify(block_list.empty());
Expand Down
4 changes: 2 additions & 2 deletions core/hw/sh4/dyna/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,11 +984,11 @@ bool dec_DecodeBlock(RuntimeBlockInfo* rbi,u32 max_cycles)

if (!blk->has_fpu_op && OpDesc[op]->IsFloatingPoint())
{
if (sr.FD == 1)
if (Sh4cntx.sr.FD == 1)
{
// We need to know FPSCR to compile the block, so let the exception handler run first
// as it may change the fp registers
Do_Exception(next_pc, Sh4Ex_FpuDisabled);
Do_Exception(Sh4cntx.pc, Sh4Ex_FpuDisabled);
return false;
}
blk->has_fpu_op = true;
Expand Down
36 changes: 18 additions & 18 deletions core/hw/sh4/dyna/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void Sh4Recompiler::clear_temp_cache(bool full)

void Sh4Recompiler::ResetCache()
{
INFO_LOG(DYNAREC, "recSh4:Dynarec Cache clear at %08X free space %d", next_pc, codeBuffer.getFreeSpace());
INFO_LOG(DYNAREC, "recSh4:Dynarec Cache clear at %08X free space %d", Sh4cntx.pc, codeBuffer.getFreeSpace());
codeBuffer.reset(false);
bm_ResetCache();
smc_hotspots.clear();
Expand Down Expand Up @@ -168,14 +168,14 @@ bool RuntimeBlockInfo::Setup(u32 rpc,fpscr_t rfpu_cfg)

DynarecCodeEntryPtr rdv_CompilePC(u32 blockcheck_failures)
{
const u32 pc = next_pc;
const u32 pc = Sh4cntx.pc;

if (codeBuffer.getFreeSpace() < 32_KB || pc == 0x8c0000e0 || pc == 0xac010000 || pc == 0xac008300)
Sh4Recompiler::Instance->ResetCache();

RuntimeBlockInfo* rbi = sh4Dynarec->allocateBlock();

if (!rbi->Setup(pc, fpscr))
if (!rbi->Setup(pc, Sh4cntx.fpscr))
{
delete rbi;
return nullptr;
Expand Down Expand Up @@ -204,16 +204,16 @@ DynarecCodeEntryPtr rdv_CompilePC(u32 blockcheck_failures)

DynarecCodeEntryPtr DYNACALL rdv_FailedToFindBlock_pc()
{
return rdv_FailedToFindBlock(next_pc);
return rdv_FailedToFindBlock(Sh4cntx.pc);
}

DynarecCodeEntryPtr DYNACALL rdv_FailedToFindBlock(u32 pc)
{
//DEBUG_LOG(DYNAREC, "rdv_FailedToFindBlock %08x", pc);
next_pc=pc;
Sh4cntx.pc=pc;
DynarecCodeEntryPtr code = rdv_CompilePC(0);
if (code == NULL)
code = bm_GetCodeByVAddr(next_pc);
code = bm_GetCodeByVAddr(Sh4cntx.pc);
else
code = (DynarecCodeEntryPtr)CC_RW2RX(code);
return code;
Expand Down Expand Up @@ -247,15 +247,15 @@ DynarecCodeEntryPtr DYNACALL rdv_BlockCheckFail(u32 addr)
}
else
{
next_pc = addr;
Sh4cntx.pc = addr;
Sh4Recompiler::Instance->ResetCache();
}
return (DynarecCodeEntryPtr)CC_RW2RX(rdv_CompilePC(blockcheck_failures));
}

DynarecCodeEntryPtr rdv_FindOrCompile()
{
DynarecCodeEntryPtr rv = bm_GetCodeByVAddr(next_pc); // Returns exec addr
DynarecCodeEntryPtr rv = bm_GetCodeByVAddr(Sh4cntx.pc); // Returns exec addr
if (rv == ngen_FailedToFindBlock)
rv = (DynarecCodeEntryPtr)CC_RW2RX(rdv_CompilePC(0)); // Returns rw addr

Expand All @@ -281,20 +281,20 @@ void* DYNACALL rdv_LinkBlock(u8* code,u32 dpc)
if (bcls == BET_CLS_Static)
{
if (rbi->BlockType == BET_StaticIntr)
next_pc = rbi->NextBlock;
Sh4cntx.pc = rbi->NextBlock;
else
next_pc = rbi->BranchBlock;
Sh4cntx.pc = rbi->BranchBlock;
}
else if (bcls == BET_CLS_Dynamic)
{
next_pc = dpc;
Sh4cntx.pc = dpc;
}
else if (bcls == BET_CLS_COND)
{
if (dpc)
next_pc = rbi->BranchBlock;
Sh4cntx.pc = rbi->BranchBlock;
else
next_pc = rbi->NextBlock;
Sh4cntx.pc = rbi->NextBlock;
}

DynarecCodeEntryPtr rv = rdv_FindOrCompile(); // Returns rx ptr
Expand All @@ -313,17 +313,17 @@ void* DYNACALL rdv_LinkBlock(u8* code,u32 dpc)
}
else if (rbi->relink_data == 0)
{
rbi->pBranchBlock = bm_GetBlock(next_pc).get();
rbi->pBranchBlock = bm_GetBlock(Sh4cntx.pc).get();
rbi->pBranchBlock->AddRef(rbi);
}
}
else
{
RuntimeBlockInfo* nxt = bm_GetBlock(next_pc).get();
RuntimeBlockInfo* nxt = bm_GetBlock(Sh4cntx.pc).get();

if (rbi->BranchBlock == next_pc)
if (rbi->BranchBlock == Sh4cntx.pc)
rbi->pBranchBlock = nxt;
if (rbi->NextBlock == next_pc)
if (rbi->NextBlock == Sh4cntx.pc)
rbi->pNextBlock = nxt;

nxt->AddRef(rbi);
Expand All @@ -334,7 +334,7 @@ void* DYNACALL rdv_LinkBlock(u8* code,u32 dpc)
}
else
{
INFO_LOG(DYNAREC, "null RBI: from %08X to %08X -- unlinked stale block -- code %p next %p", rbi->vaddr, next_pc, code, rv);
INFO_LOG(DYNAREC, "null RBI: from %08X to %08X -- unlinked stale block -- code %p next %p", rbi->vaddr, Sh4cntx.pc, code, rv);
}

return (void*)rv;
Expand Down
1 change: 1 addition & 0 deletions core/hw/sh4/dyna/shil_canonical.h
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ shil_opc(div1)
shil_canonical
(
u64,f1,(u32 a, s32 b, u32 T),
sr_t& sr = Sh4cntx.sr;
bool qxm = sr.Q ^ sr.M;
sr.Q = (int)a < 0;
a = (a << 1) | T;
Expand Down
Loading

0 comments on commit db846ca

Please sign in to comment.