mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2024-12-28 02:26:07 +00:00
generate IR trampolines for HLE functions
This commit is contained in:
parent
4dd2e4cf1f
commit
5e28b5342b
2
externals/hex-emu
vendored
2
externals/hex-emu
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 0e5a75a7f428d4cb58c44c3ec4c007b60de04dc7
|
Subproject commit 710744fe5a9ede5452ecf7ca9a3e468da33703fd
|
|
@ -19,6 +19,7 @@
|
||||||
#include "core/tls.h"
|
#include "core/tls.h"
|
||||||
#include "core/virtual_memory.h"
|
#include "core/virtual_memory.h"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include "Config/Config.h"
|
#include "Config/Config.h"
|
||||||
|
@ -90,6 +91,13 @@ void AssertHandler(char const *Message) {
|
||||||
fsync(OutputFD);
|
fsync(OutputFD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unordered_set<u64> trampoline_entries;
|
||||||
|
|
||||||
|
void GenerateTrampoline(u64 hle_handler) {
|
||||||
|
LOG_INFO(Core_Linker, "Adding trampoline {:#010x}", hle_handler);
|
||||||
|
trampoline_entries.insert(hle_handler);
|
||||||
|
}
|
||||||
|
|
||||||
static void RunMainEntry(VAddr addr, EntryParams* params, ExitFunc exit_func) {
|
static void RunMainEntry(VAddr addr, EntryParams* params, ExitFunc exit_func) {
|
||||||
#ifdef ARCH_X86_64
|
#ifdef ARCH_X86_64
|
||||||
// reinterpret_cast<entry_func_t>(addr)(params, exit_func); // can't be used, stack has to have
|
// reinterpret_cast<entry_func_t>(addr)(params, exit_func); // can't be used, stack has to have
|
||||||
|
@ -118,9 +126,10 @@ static void RunMainEntry(VAddr addr, EntryParams* params, ExitFunc exit_func) {
|
||||||
FEXCore::Config::Initialize();
|
FEXCore::Config::Initialize();
|
||||||
FEXCore::Config::ReloadMetaLayer();
|
FEXCore::Config::ReloadMetaLayer();
|
||||||
FEXCore::Config::Set(FEXCore::Config::CONFIG_IS64BIT_MODE, "1");
|
FEXCore::Config::Set(FEXCore::Config::CONFIG_IS64BIT_MODE, "1");
|
||||||
|
FEXCore::Config::Set(FEXCore::Config::CONFIG_ENABLEAVX, "1");
|
||||||
InitializeStaticTables(FEXCore::Context::MODE_64BIT);
|
InitializeStaticTables(FEXCore::Context::MODE_64BIT);
|
||||||
|
|
||||||
auto CTX = new FEXCore::Context::Context();
|
FEXCore::Context::Context* CTX = new FEXCore::Context::Context();
|
||||||
CTX->CPUID.Init(CTX);
|
CTX->CPUID.Init(CTX);
|
||||||
|
|
||||||
// SyscallHandler->SetCodeLoader(&Loader);
|
// SyscallHandler->SetCodeLoader(&Loader);
|
||||||
|
@ -156,6 +165,25 @@ FEXCore::Config::ReloadMetaLayer();
|
||||||
rdi = (u64)exit_func;
|
rdi = (u64)exit_func;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto& entry : trampoline_entries) {
|
||||||
|
CTX->AddCustomIREntrypoint(entry, [entry](uintptr_t Entrypoint, FEXCore::IR::IREmitter* emit) {
|
||||||
|
using namespace FEXCore;
|
||||||
|
auto IRHeader = emit->_IRHeader(emit->Invalid(), 0);
|
||||||
|
auto Block = emit->CreateCodeNode();
|
||||||
|
IRHeader.first->Blocks = emit->WrapNode(Block);
|
||||||
|
emit->SetCurrentCodeBlock(Block);
|
||||||
|
|
||||||
|
const uint8_t GPRSize = 8;
|
||||||
|
|
||||||
|
emit-> _Break(emit->_Constant(entry), FEXCore::IR::BreakDefinition {
|
||||||
|
.ErrorRegister = 0,
|
||||||
|
.Signal = 254,
|
||||||
|
.TrapNumber = 0,
|
||||||
|
.si_code = 0,
|
||||||
|
});
|
||||||
|
}, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
CTX->RunUntilExit();
|
CTX->RunUntilExit();
|
||||||
|
|
||||||
UNIMPLEMENTED_MSG("Missing RunMainEntry() implementation for target CPU architecture.");
|
UNIMPLEMENTED_MSG("Missing RunMainEntry() implementation for target CPU architecture.");
|
||||||
|
@ -392,6 +420,7 @@ bool Linker::Resolve(const std::string& name, Loader::SymbolType sym_type, Modul
|
||||||
}
|
}
|
||||||
if (record) {
|
if (record) {
|
||||||
*return_info = *record;
|
*return_info = *record;
|
||||||
|
GenerateTrampoline(return_info->virtual_address);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,6 +434,7 @@ bool Linker::Resolve(const std::string& name, Loader::SymbolType sym_type, Modul
|
||||||
}
|
}
|
||||||
LOG_ERROR(Core_Linker, "Linker: Stub resolved {} as {} (lib: {}, mod: {})", sr.name,
|
LOG_ERROR(Core_Linker, "Linker: Stub resolved {} as {} (lib: {}, mod: {})", sr.name,
|
||||||
return_info->name, library->name, module->name);
|
return_info->name, library->name, module->name);
|
||||||
|
GenerateTrampoline(return_info->virtual_address);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue