Allow new-style export registration.
This commit is contained in:
parent
08770a4ec0
commit
ce3359389b
|
@ -417,9 +417,8 @@ uint64_t UndefinedCallExtern(void* raw_context, uint64_t symbol_info_ptr) {
|
|||
}
|
||||
void X64Emitter::CallExtern(const hir::Instr* instr,
|
||||
const FunctionInfo* symbol_info) {
|
||||
if (!symbol_info->extern_handler()) {
|
||||
CallNative(UndefinedCallExtern, reinterpret_cast<uint64_t>(symbol_info));
|
||||
} else if (symbol_info->behavior() == FunctionBehavior::kBuiltin) {
|
||||
if (symbol_info->behavior() == FunctionBehavior::kBuiltin &&
|
||||
symbol_info->builtin_handler()) {
|
||||
// rcx = context
|
||||
// rdx = target host function
|
||||
// r8 = arg0
|
||||
|
@ -433,7 +432,8 @@ void X64Emitter::CallExtern(const hir::Instr* instr,
|
|||
ReloadECX();
|
||||
ReloadEDX();
|
||||
// rax = host return
|
||||
} else if (symbol_info->behavior() == FunctionBehavior::kExtern) {
|
||||
} else if (symbol_info->behavior() == FunctionBehavior::kExtern &&
|
||||
symbol_info->extern_handler()) {
|
||||
// rcx = context
|
||||
// rdx = target host function
|
||||
mov(rdx, reinterpret_cast<uint64_t>(symbol_info->extern_handler()));
|
||||
|
@ -444,6 +444,8 @@ void X64Emitter::CallExtern(const hir::Instr* instr,
|
|||
ReloadECX();
|
||||
ReloadEDX();
|
||||
// rax = host return
|
||||
} else {
|
||||
CallNative(UndefinedCallExtern, reinterpret_cast<uint64_t>(symbol_info));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,22 +19,20 @@ ExportResolver::ExportResolver() {}
|
|||
|
||||
ExportResolver::~ExportResolver() {}
|
||||
|
||||
void ExportResolver::RegisterTable(const std::string& library_name,
|
||||
Export* exports, const size_t count) {
|
||||
tables_.emplace_back(library_name, exports, count);
|
||||
void ExportResolver::RegisterTable(
|
||||
const std::string& library_name,
|
||||
const std::vector<xe::cpu::Export*>* exports) {
|
||||
tables_.emplace_back(library_name, exports);
|
||||
}
|
||||
|
||||
Export* ExportResolver::GetExportByOrdinal(const std::string& library_name,
|
||||
uint16_t ordinal) {
|
||||
for (const auto& table : tables_) {
|
||||
if (table.name == library_name || table.simple_name == library_name) {
|
||||
// TODO(benvanik): binary search?
|
||||
for (size_t n = 0; n < table.count; n++) {
|
||||
if (table.exports[n].ordinal == ordinal) {
|
||||
return &table.exports[n];
|
||||
}
|
||||
if (ordinal > table.exports->size()) {
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
return table.exports->at(ordinal);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -89,8 +89,8 @@ class ExportResolver {
|
|||
ExportResolver();
|
||||
~ExportResolver();
|
||||
|
||||
void RegisterTable(const std::string& library_name, Export* exports,
|
||||
const size_t count);
|
||||
void RegisterTable(const std::string& library_name,
|
||||
const std::vector<Export*>* exports);
|
||||
|
||||
Export* GetExportByOrdinal(const std::string& library_name, uint16_t ordinal);
|
||||
|
||||
|
@ -105,10 +105,9 @@ class ExportResolver {
|
|||
struct ExportTable {
|
||||
std::string name;
|
||||
std::string simple_name; // without extension
|
||||
Export* exports;
|
||||
size_t count;
|
||||
ExportTable(const std::string& name, Export* exports, size_t count)
|
||||
: name(name), exports(exports), count(count) {
|
||||
const std::vector<Export*>* exports;
|
||||
ExportTable(const std::string& name, const std::vector<Export*>* exports)
|
||||
: name(name), exports(exports) {
|
||||
auto dot_pos = name.find_last_of('.');
|
||||
if (dot_pos != std::string::npos) {
|
||||
simple_name = name.substr(0, dot_pos);
|
||||
|
|
|
@ -234,8 +234,13 @@ bool XexModule::SetupLibraryImports(const xe_xex2_import_library_t* library) {
|
|||
|
||||
FunctionInfo::ExternHandler handler = 0;
|
||||
if (kernel_export) {
|
||||
handler =
|
||||
(FunctionInfo::ExternHandler)kernel_export->function_data.shim;
|
||||
if (kernel_export->function_data.trampoline) {
|
||||
handler = (FunctionInfo::ExternHandler)
|
||||
kernel_export->function_data.trampoline;
|
||||
} else {
|
||||
handler =
|
||||
(FunctionInfo::ExternHandler)kernel_export->function_data.shim;
|
||||
}
|
||||
} else {
|
||||
handler = UndefinedImport;
|
||||
}
|
||||
|
|
|
@ -33,21 +33,35 @@ XamModule::XamModule(Emulator* emulator, KernelState* kernel_state)
|
|||
xam::RegisterVoiceExports(export_resolver_, kernel_state_);
|
||||
}
|
||||
|
||||
std::vector<xe::cpu::Export*> xam_exports;
|
||||
|
||||
xe::cpu::Export* RegisterExport_xam(xe::cpu::Export* export) {
|
||||
if (xam_exports.size() <= export->ordinal) {
|
||||
xam_exports.resize(xe::round_up(export->ordinal, 256));
|
||||
}
|
||||
xam_exports[export->ordinal] = export;
|
||||
return export;
|
||||
}
|
||||
|
||||
void XamModule::RegisterExportTable(xe::cpu::ExportResolver* export_resolver) {
|
||||
assert_not_null(export_resolver);
|
||||
|
||||
if (!export_resolver) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build the export table used for resolution.
|
||||
#include "xenia/kernel/util/export_table_pre.inc"
|
||||
static xe::cpu::Export xam_export_table[] = {
|
||||
#include "xenia/kernel/xam_table.inc"
|
||||
};
|
||||
#include "xenia/kernel/util/export_table_post.inc"
|
||||
export_resolver->RegisterTable("xam.xex", xam_export_table,
|
||||
xe::countof(xam_export_table));
|
||||
for (size_t i = 0; i < xe::countof(xam_export_table); ++i) {
|
||||
auto& export = xam_export_table[i];
|
||||
if (xam_exports.size() <= export.ordinal) {
|
||||
xam_exports.resize(xe::round_up(export.ordinal, 256));
|
||||
}
|
||||
if (!xam_exports[export.ordinal]) {
|
||||
xam_exports[export.ordinal] = &export;
|
||||
}
|
||||
}
|
||||
export_resolver->RegisterTable("xam.xex", &xam_exports);
|
||||
}
|
||||
|
||||
XamModule::~XamModule() {}
|
||||
|
|
|
@ -23,7 +23,6 @@ class XamModule : public XKernelModule {
|
|||
virtual ~XamModule();
|
||||
|
||||
static void RegisterExportTable(xe::cpu::ExportResolver* export_resolver);
|
||||
static void RegisterExport(xe::cpu::Export* export);
|
||||
|
||||
private:
|
||||
};
|
||||
|
|
|
@ -18,6 +18,8 @@ namespace kernel {
|
|||
|
||||
class KernelState;
|
||||
|
||||
xe::cpu::Export* RegisterExport_xam(xe::cpu::Export* export);
|
||||
|
||||
namespace xam {
|
||||
// Registration functions, one per file.
|
||||
void RegisterContentExports(xe::cpu::ExportResolver* export_resolver,
|
||||
|
|
|
@ -149,22 +149,36 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state)
|
|||
WT_EXECUTEINTIMERTHREAD);
|
||||
}
|
||||
|
||||
std::vector<xe::cpu::Export*> xboxkrnl_exports;
|
||||
|
||||
xe::cpu::Export* RegisterExport_xboxkrnl(xe::cpu::Export* export) {
|
||||
if (xboxkrnl_exports.size() <= export->ordinal) {
|
||||
xboxkrnl_exports.resize(xe::round_up(export->ordinal, 256));
|
||||
}
|
||||
xboxkrnl_exports[export->ordinal] = export;
|
||||
return export;
|
||||
}
|
||||
|
||||
void XboxkrnlModule::RegisterExportTable(
|
||||
xe::cpu::ExportResolver* export_resolver) {
|
||||
assert_not_null(export_resolver);
|
||||
|
||||
if (!export_resolver) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build the export table used for resolution.
|
||||
#include "xenia/kernel/util/export_table_pre.inc"
|
||||
static xe::cpu::Export xboxkrnl_export_table[] = {
|
||||
#include "xenia/kernel/xboxkrnl_table.inc"
|
||||
};
|
||||
#include "xenia/kernel/util/export_table_post.inc"
|
||||
export_resolver->RegisterTable("xboxkrnl.exe", xboxkrnl_export_table,
|
||||
xe::countof(xboxkrnl_export_table));
|
||||
for (size_t i = 0; i < xe::countof(xboxkrnl_export_table); ++i) {
|
||||
auto& export = xboxkrnl_export_table[i];
|
||||
if (xboxkrnl_exports.size() <= export.ordinal) {
|
||||
xboxkrnl_exports.resize(xe::round_up(export.ordinal, 256));
|
||||
}
|
||||
if (!xboxkrnl_exports[export.ordinal]) {
|
||||
xboxkrnl_exports[export.ordinal] = &export;
|
||||
}
|
||||
}
|
||||
export_resolver->RegisterTable("xboxkrnl.exe", &xboxkrnl_exports);
|
||||
}
|
||||
|
||||
XboxkrnlModule::~XboxkrnlModule() {
|
||||
|
|
|
@ -28,7 +28,6 @@ class XboxkrnlModule : public XKernelModule {
|
|||
virtual ~XboxkrnlModule();
|
||||
|
||||
static void RegisterExportTable(xe::cpu::ExportResolver* export_resolver);
|
||||
static void RegisterExport(xe::cpu::Export* export);
|
||||
|
||||
int LaunchModule(const char* path);
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ namespace kernel {
|
|||
|
||||
class KernelState;
|
||||
|
||||
xe::cpu::Export* RegisterExport_xboxkrnl(xe::cpu::Export* export);
|
||||
|
||||
namespace xboxkrnl {
|
||||
// Registration functions, one per file.
|
||||
void RegisterAudioExports(xe::cpu::ExportResolver* export_resolver,
|
||||
|
|
Loading…
Reference in New Issue