1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Improved be_t

Fixed NV4097_SET_TWO_SIDE_LIGHT_EN
Added LIS, ORI, NOP & BLR to PPU Jit
This commit is contained in:
DHrpcs3 2014-10-01 12:45:43 +03:00
parent 64158b1b10
commit eada1fe12c
13 changed files with 93 additions and 119 deletions

View File

@ -624,5 +624,9 @@ namespace PPU_instr
bind_instr(g3f_0_list, MFFS, FRD, RC);
bind_instr(g3f_0_list, MTFSF, FM, FRB, RC);
static auto LIS = std::bind(ADDIS, std::placeholders::_1, 0, std::placeholders::_2);
static auto NOP = std::bind(ORI, 0, 0, 0);
static auto BLR = std::bind(BCLR, 0x10 | 0x04, 0, 0, 0);
#undef bind_instr
};

View File

@ -59,12 +59,13 @@ public:
}
};
struct ID
class ID
{
std::string m_name;
IDData* m_data;
IDType m_type;
public:
template<typename T>
ID(const std::string& name, T* data, const IDType type)
: m_name(name)
@ -96,6 +97,21 @@ struct ID
{
delete m_data;
}
const std::string& GetName() const
{
return m_name;
}
IDData* GetData() const
{
return m_data;
}
IDType GetType() const
{
return m_type;
}
};
class IdManager
@ -172,7 +188,7 @@ public:
return false;
}
result = f->second.m_data->get<T>();
result = f->second.GetData()->get<T>();
return true;
}
@ -198,8 +214,8 @@ public:
if (item == m_id_map.end()) {
return false;
}
if (item->second.m_type < TYPE_OTHER) {
m_types[item->second.m_type].erase(id);
if (item->second.GetType() < TYPE_OTHER) {
m_types[item->second.GetType()].erase(id);
}
item->second.Kill();

View File

@ -108,9 +108,9 @@ void MemoryBase::Init(MemoryType type)
memset(RawSPUMem, 0, sizeof(RawSPUMem));
#ifdef _WIN32
if (!m_base_addr)
if (!g_base_addr)
#else
if ((s64)m_base_addr == (s64)-1)
if ((s64)g_base_addr == (s64)-1)
#endif
{
LOG_ERROR(MEMORY, "Initializing memory failed");
@ -119,7 +119,7 @@ void MemoryBase::Init(MemoryType type)
}
else
{
LOG_NOTICE(MEMORY, "Initializing memory: m_base_addr = 0x%llx", (u64)m_base_addr);
LOG_NOTICE(MEMORY, "Initializing memory: m_base_addr = 0x%llx", (u64)g_base_addr);
}
switch (type)
@ -205,7 +205,7 @@ bool MemoryBase::Map(const u64 addr, const u32 size)
{
LV2_LOCK(0);
if ((u32)addr != addr || (u64)addr + (u64)size > 0x100000000ull)
if ((addr | (addr + size)) & ~0xFFFFFFFFull)
{
return false;
}

View File

@ -7,7 +7,7 @@ using std::nullptr_t;
#define safe_delete(x) do {delete (x);(x)=nullptr;} while(0)
#define safe_free(x) do {free(x);(x)=nullptr;} while(0)
extern void* const m_base_addr;
extern void* const g_base_addr;
enum MemoryType
{
@ -70,7 +70,7 @@ public:
static void* const GetBaseAddr()
{
return m_base_addr;
return g_base_addr;
}
__noinline void InvalidAddress(const char* func, const u64 addr);

View File

@ -4,7 +4,7 @@
#ifdef _WIN32
#include <Windows.h>
void* const m_base_addr = VirtualAlloc(nullptr, 0x100000000, MEM_RESERVE, PAGE_NOACCESS);
void* const g_base_addr = VirtualAlloc(nullptr, 0x100000000, MEM_RESERVE, PAGE_NOACCESS);
#else
#include <sys/mman.h>
@ -13,7 +13,7 @@ void* const m_base_addr = VirtualAlloc(nullptr, 0x100000000, MEM_RESERVE, PAGE_N
#define MAP_ANONYMOUS MAP_ANON
#endif
void* const m_base_addr = ::mmap(nullptr, 0x100000000, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
void* const g_base_addr = ::mmap(nullptr, 0x100000000, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
#endif
namespace vm

View File

@ -10,7 +10,7 @@ namespace vm
template<typename T>
T* const get_ptr(u32 addr)
{
return (T*)((u8*)m_base_addr + addr);
return (T*)((u8*)g_base_addr + addr);
}
template<typename T>
@ -35,49 +35,29 @@ namespace vm
{
static u8 read8(u32 addr)
{
return *((u8*)m_base_addr + addr);
}
static u8 read8(u64 addr)
{
return read8((u32)addr);
return *((u8*)g_base_addr + addr);
}
static void write8(u32 addr, u8 value)
{
*((u8*)m_base_addr + addr) = value;
}
static void write8(u64 addr, u8 value)
{
write8((u32)addr, value);
*((u8*)g_base_addr + addr) = value;
}
static u16 read16(u32 addr)
{
return re16(*(u16*)((u8*)m_base_addr + addr));
}
static u16 read16(u64 addr)
{
return read16((u32)addr);
return re16(*(u16*)((u8*)g_base_addr + addr));
}
static void write16(u32 addr, u16 value)
{
*(u16*)((u8*)m_base_addr + addr) = re16(value);
}
static void write16(u64 addr, u16 value)
{
write16((u32)addr, value);
*(u16*)((u8*)g_base_addr + addr) = re16(value);
}
static u32 read32(u32 addr)
{
if (addr < RAW_SPU_BASE_ADDR || (addr % RAW_SPU_OFFSET) < RAW_SPU_PROB_OFFSET)
{
return re32(*(u32*)((u8*)m_base_addr + addr));
return re32(*(u32*)((u8*)g_base_addr + addr));
}
else
{
@ -85,16 +65,11 @@ namespace vm
}
}
static u32 read32(u64 addr)
{
return read32((u32)addr);
}
static void write32(u32 addr, u32 value)
{
if (addr < RAW_SPU_BASE_ADDR || (addr % RAW_SPU_OFFSET) < RAW_SPU_PROB_OFFSET)
{
*(u32*)((u8*)m_base_addr + addr) = re32(value);
*(u32*)((u8*)g_base_addr + addr) = re32(value);
}
else
{
@ -102,49 +77,24 @@ namespace vm
}
}
static void write32(u64 addr, u32 value)
{
write32((u32)addr, value);
}
static u64 read64(u32 addr)
{
return re64(*(u64*)((u8*)m_base_addr + addr));
}
static u64 read64(u64 addr)
{
return read64((u32)addr);
return re64(*(u64*)((u8*)g_base_addr + addr));
}
static void write64(u32 addr, u64 value)
{
*(u64*)((u8*)m_base_addr + addr) = re64(value);
}
static void write64(u64 addr, u64 value)
{
write64((u32)addr, value);
*(u64*)((u8*)g_base_addr + addr) = re64(value);
}
static u128 read128(u32 addr)
{
return re128(*(u128*)((u8*)m_base_addr + addr));
}
static u128 read128(u64 addr)
{
return read128((u32)addr);
return re128(*(u128*)((u8*)g_base_addr + addr));
}
static void write128(u32 addr, u128 value)
{
*(u128*)((u8*)m_base_addr + addr) = re128(value);
}
static void write128(u64 addr, u128 value)
{
write128((u32)addr, value);
*(u128*)((u8*)g_base_addr + addr) = re128(value);
}
}
@ -152,52 +102,52 @@ namespace vm
{
static u8 read8(u32 addr)
{
return *((u8*)m_base_addr + addr);
return *((u8*)g_base_addr + addr);
}
static void write8(u32 addr, u8 value)
{
*((u8*)m_base_addr + addr) = value;
*((u8*)g_base_addr + addr) = value;
}
static u16 read16(u32 addr)
{
return *(u16*)((u8*)m_base_addr + addr);
return *(u16*)((u8*)g_base_addr + addr);
}
static void write16(u32 addr, u16 value)
{
*(u16*)((u8*)m_base_addr + addr) = value;
*(u16*)((u8*)g_base_addr + addr) = value;
}
static u32 read32(u32 addr)
{
return *(u32*)((u8*)m_base_addr + addr);
return *(u32*)((u8*)g_base_addr + addr);
}
static void write32(u32 addr, u32 value)
{
*(u32*)((u8*)m_base_addr + addr) = value;
*(u32*)((u8*)g_base_addr + addr) = value;
}
static u64 read64(u32 addr)
{
return *(u64*)((u8*)m_base_addr + addr);
return *(u64*)((u8*)g_base_addr + addr);
}
static void write64(u32 addr, u64 value)
{
*(u64*)((u8*)m_base_addr + addr) = value;
*(u64*)((u8*)g_base_addr + addr) = value;
}
static u128 read128(u32 addr)
{
return *(u128*)((u8*)m_base_addr + addr);
return *(u128*)((u8*)g_base_addr + addr);
}
static void write128(u32 addr, u128 value)
{
*(u128*)((u8*)m_base_addr + addr) = value;
*(u128*)((u8*)g_base_addr + addr) = value;
}
}
}

View File

@ -60,14 +60,14 @@ namespace vm
return make(m_addr - count * sizeof(AT));
}
__forceinline _ptr_base<T, lvl - 1, AT>& operator *() const
__forceinline _ptr_base<T, lvl - 1, std::conditional<is_be_t<T>::value, typename to_be_t<AT>::type, AT>>& operator *() const
{
return vm::get_ref<_ptr_base<T, lvl - 1, AT>>(m_addr);
return vm::get_ref<_ptr_base<T, lvl - 1, std::conditional<is_be_t<T>::value, typename to_be_t<AT>::type, AT>>>(m_addr);
}
__forceinline _ptr_base<T, lvl - 1, AT>& operator [](int index) const
__forceinline _ptr_base<T, lvl - 1, std::conditional<is_be_t<T>::value, typename to_be_t<AT>::type, AT>>& operator [](int index) const
{
return vm::get_ref<_ptr_base<T, lvl - 1, AT>>(m_addr + sizeof(AT) * index);
return vm::get_ref<_ptr_base<T, lvl - 1, std::conditional<is_be_t<T>::value, typename to_be_t<AT>::type, AT>>>(m_addr + sizeof(AT)* index);
}
operator bool() const

View File

@ -1804,12 +1804,9 @@ void GLGSRender::ExecCMD()
}
}
if (m_set_two_side_light_enable)
{
// TODO: Use other glLightModel functions?
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
checkForGlError("glLightModeli");
}
// TODO: Use other glLightModel functions?
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, m_set_two_side_light_enable ? GL_TRUE : GL_FALSE);
checkForGlError("glLightModeli");
if(m_set_shade_mode)
{

View File

@ -5,6 +5,7 @@
#include "Emu/SysCalls/Static.h"
#include "Crypto/sha1.h"
#include "ModuleManager.h"
#include "Emu/Cell/PPUInstrTable.h"
u32 getFunctionId(const char* name)
{
@ -149,12 +150,12 @@ void Module::SetName(const std::string& name)
bool Module::CheckID(u32 id) const
{
return Emu.GetIdManager().CheckID(id) && Emu.GetIdManager().GetID(id).m_name == GetName();
return Emu.GetIdManager().CheckID(id) && Emu.GetIdManager().GetID(id).GetName() == GetName();
}
bool Module::CheckID(u32 id, ID*& _id) const
{
return Emu.GetIdManager().CheckID(id) && (_id = &Emu.GetIdManager().GetID(id))->m_name == GetName();
return Emu.GetIdManager().CheckID(id) && (_id = &Emu.GetIdManager().GetID(id))->GetName() == GetName();
}
bool Module::RemoveId(u32 id)
@ -174,12 +175,15 @@ void Module::PushNewFuncSub(SFunc* func)
void fix_import(Module* module, u32 func, u32 addr)
{
vm::write32(addr + 0x0, 0x3d600000 | (func >> 16)); /* lis r11, (func_id >> 16) */
vm::write32(addr + 0x4, 0x616b0000 | (func & 0xffff)); /* ori r11, (func_id & 0xffff) */
vm::write32(addr + 0x8, 0x60000000); /* nop */
// leave rtoc saving at 0xC
vm::write64(addr + 0x10, 0x440000024e800020ull); /* sc + blr */
vm::write64(addr + 0x18, 0x6000000060000000ull); /* nop + nop */
using namespace PPU_instr;
vm::write32(addr + 0x0, LIS(11, func >> 16)); /* lis r11, (func_id >> 16) */
vm::write32(addr + 0x4, ORI(11, 11, func & 0xffff)); /* ori r11, (func_id & 0xffff) */
vm::write32(addr + 0x8, NOP());
vm::write32(addr + 0x10, BLR());
vm::write32(addr + 0x14, SC(2));
vm::write32(addr + 0x18, NOP());
vm::write32(addr + 0x20, NOP());
module->Load(func);
}

View File

@ -89,7 +89,7 @@ public:
if(!CheckID(id, id_data)) return false;
data = id_data->m_data->get<T>();
data = id_data->GetData()->get<T>();
return true;
}
@ -100,8 +100,8 @@ public:
if(!CheckID(id, id_data)) return false;
data = id_data->m_data->get<T>();
type = id_data->m_type;
data = id_data->GetData()->get<T>();
type = id_data->GetType();
return true;
}

View File

@ -31,7 +31,7 @@
namespace detail{
template<> bool CheckId(u32 id, ID*& _id,const std::string &name)
{
return Emu.GetIdManager().CheckID(id) && (_id = &Emu.GetIdManager().GetID(id))->m_name == name;
return Emu.GetIdManager().CheckID(id) && (_id = &Emu.GetIdManager().GetID(id))->GetName() == name;
}
}

View File

@ -12,7 +12,7 @@ namespace detail{
{
ID* id_data;
if(!CheckId(id, id_data,name)) return false;
data = id_data->m_data->get<T>();
data = id_data->GetData()->get<T>();
return true;
}
@ -40,7 +40,7 @@ public:
bool CheckId(u32 id) const
{
return GetIdManager().CheckID(id) && GetIdManager().GetID(id).m_name == GetName();
return GetIdManager().CheckID(id) && GetIdManager().GetID(id).GetName() == GetName();
}
template<typename T>

View File

@ -370,7 +370,7 @@ bool ELF64Loader::LoadPhdrData(u64 offset)
if(!phdr.p_filesz)
break;
auto& proc_param = vm::get_ref<sys_process_param>(offset + phdr.p_vaddr);
const sys_process_param& proc_param = vm::get_ref<sys_process_param>(offset + phdr.p_vaddr);
if (proc_param.size < sizeof(sys_process_param))
{
@ -400,7 +400,7 @@ bool ELF64Loader::LoadPhdrData(u64 offset)
if(!phdr.p_filesz)
break;
sys_proc_prx_param proc_prx_param = vm::get_ref<sys_proc_prx_param>(offset + phdr.p_vaddr);
const sys_proc_prx_param& proc_prx_param = vm::get_ref<sys_proc_prx_param>(offset + phdr.p_vaddr);
#ifdef LOADER_DEBUG
@ -414,21 +414,24 @@ bool ELF64Loader::LoadPhdrData(u64 offset)
LOG_NOTICE(LOADER, "*** ver: 0x%x", proc_prx_param.ver.ToLE());
#endif
if (proc_prx_param.magic != 0x1b434cec) {
if (proc_prx_param.magic != 0x1b434cec)
{
LOG_ERROR(LOADER, "Bad magic! (0x%x)", proc_prx_param.magic.ToLE());
break;
}
for(u32 s=proc_prx_param.libstubstart; s<proc_prx_param.libstubend; s+=sizeof(Elf64_StubHeader))
for (u32 s = proc_prx_param.libstubstart; s < proc_prx_param.libstubend; s += sizeof(Elf64_StubHeader))
{
Elf64_StubHeader stub = vm::get_ref<Elf64_StubHeader>(offset + s);
const Elf64_StubHeader& stub = vm::get_ref<Elf64_StubHeader>(offset + s);
const std::string module_name = vm::get_ptr<const char>(stub.s_modulename);
Module* module = Emu.GetModuleManager().GetModuleByName(module_name);
if (module) {
if (module)
{
//module->SetLoaded();
}
else {
else
{
LOG_WARNING(LOADER, "Unknown module '%s'", module_name.c_str());
}
@ -447,10 +450,10 @@ bool ELF64Loader::LoadPhdrData(u64 offset)
u64 tbl = Memory.MainMem.AllocAlign(stub.s_imports * 4 * 2);
u64 dst = Memory.MainMem.AllocAlign(stub.s_imports * section);
for(u32 i=0; i<stub.s_imports; ++i)
for (u32 i = 0; i < stub.s_imports; ++i)
{
const u32 nid = vm::read32(stub.s_nid + i*4);
const u32 text = vm::read32(stub.s_text + i*4);
const u32 nid = vm::read32(stub.s_nid + i * 4);
const u32 text = vm::read32(stub.s_text + i * 4);
if (module && !module->Load(nid))
{
@ -471,10 +474,10 @@ bool ELF64Loader::LoadPhdrData(u64 offset)
out_tbl[0] = (u32)dst + i*section;
out_tbl[1] = Emu.GetModuleManager().GetFuncNumById(nid);
auto out_dst = vm::ptr<be_t<u32>>::make((u32)dst + i*section);
auto out_dst = vm::ptr<be_t<u32>>::make((u32)dst + i * section);
out_dst[0] = OR(11, 2, 2, 0);
out_dst[1] = SC(2);
out_dst[2] = BCLR(0x10 | 0x04, 0, 0, 0);
out_dst[2] = BLR();
}
}
#ifdef LOADER_DEBUG