Skip to content

Commit

Permalink
PowerPC: Pass current instruction to Read/Write functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JosJuice committed Jan 21, 2024
1 parent 04ecf4d commit b5e6806
Show file tree
Hide file tree
Showing 21 changed files with 517 additions and 402 deletions.
41 changes: 41 additions & 0 deletions Source/Core/Common/x64Emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,15 @@ class XEmitter
ABI_CallFunction(func);
}

template <typename FunctionPointer>
void ABI_CallFunctionPCC(FunctionPointer func, const void* param1, u32 param2, u32 param3)
{
MOV(64, R(ABI_PARAM1), Imm64(reinterpret_cast<u64>(param1)));
MOV(32, R(ABI_PARAM2), Imm32(param2));
MOV(32, R(ABI_PARAM3), Imm32(param3));
ABI_CallFunction(func);
}

template <typename FunctionPointer>
void ABI_CallFunctionPPC(FunctionPointer func, const void* param1, const void* param2, u32 param3)
{
Expand Down Expand Up @@ -1118,6 +1127,16 @@ class XEmitter
ABI_CallFunction(func);
}

template <typename FunctionPointer>
void ABI_CallFunctionPRC(FunctionPointer func, const void* ptr, X64Reg reg1, u32 param3)
{
if (reg1 != ABI_PARAM2)
MOV(64, R(ABI_PARAM2), R(reg1));
MOV(64, R(ABI_PARAM1), Imm64(reinterpret_cast<u64>(ptr)));
MOV(32, R(ABI_PARAM3), Imm32(param3));
ABI_CallFunction(func);
}

// Pass two registers as parameters.
template <typename FunctionPointer>
void ABI_CallFunctionRR(FunctionPointer func, X64Reg reg1, X64Reg reg2)
Expand All @@ -1135,6 +1154,16 @@ class XEmitter
ABI_CallFunction(func);
}

template <typename FunctionPointer>
void ABI_CallFunctionPRRC(FunctionPointer func, const void* ptr, X64Reg reg1, X64Reg reg2,
u32 param4)
{
MOVTwo(64, ABI_PARAM2, reg1, 0, ABI_PARAM3, reg2);
MOV(64, R(ABI_PARAM1), Imm64(reinterpret_cast<u64>(ptr)));
MOV(32, R(ABI_PARAM4), Imm32(param4));
ABI_CallFunction(func);
}

template <typename FunctionPointer>
void ABI_CallFunctionAC(int bits, FunctionPointer func, const Gen::OpArg& arg1, u32 param2)
{
Expand All @@ -1150,8 +1179,20 @@ class XEmitter
{
if (!arg2.IsSimpleReg(ABI_PARAM2))
MOV(bits, R(ABI_PARAM2), arg2);
MOV(64, R(ABI_PARAM1), Imm64(reinterpret_cast<u64>(ptr1)));
MOV(32, R(ABI_PARAM3), Imm32(param3));
ABI_CallFunction(func);
}

template <typename FunctionPointer>
void ABI_CallFunctionPACC(int bits, FunctionPointer func, const void* ptr1,
const Gen::OpArg& arg2, u32 param3, u32 param4)
{
if (!arg2.IsSimpleReg(ABI_PARAM2))
MOV(bits, R(ABI_PARAM2), arg2);
MOV(64, R(ABI_PARAM1), Imm64(reinterpret_cast<u64>(ptr1)));
MOV(32, R(ABI_PARAM3), Imm32(param3));
MOV(32, R(ABI_PARAM4), Imm32(param4));
ABI_CallFunction(func);
}

Expand Down
12 changes: 6 additions & 6 deletions Source/Core/Core/Boot/Boot_BS2Emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ bool CBoot::RunApploader(Core::System& system, const Core::CPUThreadGuard& guard
ppc_state.gpr[4] = iAppLoaderFuncAddr + 4;
ppc_state.gpr[5] = iAppLoaderFuncAddr + 8;
RunFunction(system, *entry);
const u32 iAppLoaderInit = mmu.Read_U32(iAppLoaderFuncAddr + 0);
const u32 iAppLoaderMain = mmu.Read_U32(iAppLoaderFuncAddr + 4);
const u32 iAppLoaderClose = mmu.Read_U32(iAppLoaderFuncAddr + 8);
const u32 iAppLoaderInit = mmu.Read_U32(iAppLoaderFuncAddr + 0, UGeckoInstruction{});
const u32 iAppLoaderMain = mmu.Read_U32(iAppLoaderFuncAddr + 4, UGeckoInstruction{});
const u32 iAppLoaderClose = mmu.Read_U32(iAppLoaderFuncAddr + 8, UGeckoInstruction{});

// iAppLoaderInit
DEBUG_LOG_FMT(BOOT, "Call iAppLoaderInit");
Expand All @@ -194,9 +194,9 @@ bool CBoot::RunApploader(Core::System& system, const Core::CPUThreadGuard& guard
// iAppLoaderMain returns 0 when there are no more sections to copy.
while (ppc_state.gpr[3] != 0x00)
{
const u32 ram_address = mmu.Read_U32(0x81300004);
const u32 length = mmu.Read_U32(0x81300008);
const u32 dvd_offset = mmu.Read_U32(0x8130000c) << (is_wii ? 2 : 0);
const u32 ram_address = mmu.Read_U32(0x81300004, UGeckoInstruction{});
const u32 length = mmu.Read_U32(0x81300008, UGeckoInstruction{});
const u32 dvd_offset = mmu.Read_U32(0x8130000c, UGeckoInstruction{}) << (is_wii ? 2 : 0);

INFO_LOG_FMT(BOOT, "DVDRead: offset: {:08x} memOffset: {:08x} length: {}", dvd_offset,
ram_address, length);
Expand Down
12 changes: 6 additions & 6 deletions Source/Core/Core/FifoPlayer/FifoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,12 @@ void FifoPlayer::LoadTextureMemory()

void FifoPlayer::WriteCP(u32 address, u16 value)
{
m_system.GetMMU().Write_U16(value, 0xCC000000 | address);
m_system.GetMMU().Write_U16(value, 0xCC000000 | address, UGeckoInstruction{});
}

void FifoPlayer::WritePI(u32 address, u32 value)
{
m_system.GetMMU().Write_U32(value, 0xCC003000 | address);
m_system.GetMMU().Write_U32(value, 0xCC003000 | address, UGeckoInstruction{});
}

void FifoPlayer::FlushWGP()
Expand Down Expand Up @@ -805,14 +805,14 @@ bool FifoPlayer::ShouldLoadXF(u8 reg)

bool FifoPlayer::IsIdleSet() const
{
CommandProcessor::UCPStatusReg status =
m_system.GetMMU().Read_U16(0xCC000000 | CommandProcessor::STATUS_REGISTER);
CommandProcessor::UCPStatusReg status = m_system.GetMMU().Read_U16(
0xCC000000 | CommandProcessor::STATUS_REGISTER, UGeckoInstruction{});
return status.CommandIdle;
}

bool FifoPlayer::IsHighWatermarkSet() const
{
CommandProcessor::UCPStatusReg status =
m_system.GetMMU().Read_U16(0xCC000000 | CommandProcessor::STATUS_REGISTER);
CommandProcessor::UCPStatusReg status = m_system.GetMMU().Read_U16(
0xCC000000 | CommandProcessor::STATUS_REGISTER, UGeckoInstruction{});
return status.OverflowHiWatermark;
}
2 changes: 1 addition & 1 deletion Source/Core/Core/HLE/HLE_OS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void HLE_write_console(const Core::CPUThreadGuard& guard)
std::string report_message = GetStringVA(system, guard, 4);
if (PowerPC::MMU::HostIsRAMAddress(guard, ppc_state.gpr[5]))
{
const u32 size = system.GetMMU().Read_U32(ppc_state.gpr[5]);
const u32 size = system.GetMMU().HostRead_U32(guard, ppc_state.gpr[5]);
if (size > report_message.size())
WARN_LOG_FMT(OSREPORT_HLE, "__write_console uses an invalid size of {:#010x}", size);
else if (size == 0)
Expand Down
Loading

0 comments on commit b5e6806

Please sign in to comment.