Code cleanup: moving ExportResolver to xe::cpu

This commit is contained in:
Ben Vanik
2015-05-02 02:11:11 -07:00
parent d76998915a
commit 642259e16f
50 changed files with 148 additions and 124 deletions

View File

@@ -0,0 +1,70 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/cpu/export_resolver.h"
#include "poly/assert.h"
#include "poly/math.h"
namespace xe {
namespace cpu {
ExportResolver::ExportResolver() {}
ExportResolver::~ExportResolver() {}
void ExportResolver::RegisterTable(const std::string& library_name,
KernelExport* exports, const size_t count) {
tables_.emplace_back(library_name, exports, count);
for (size_t n = 0; n < count; n++) {
exports[n].is_implemented = false;
exports[n].variable_ptr = 0;
exports[n].function_data.shim_data = nullptr;
exports[n].function_data.shim = nullptr;
}
}
KernelExport* ExportResolver::GetExportByOrdinal(
const std::string& library_name, const uint32_t ordinal) {
for (const auto& table : tables_) {
if (table.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];
}
}
return nullptr;
}
}
return nullptr;
}
void ExportResolver::SetVariableMapping(const std::string& library_name,
const uint32_t ordinal,
uint32_t value) {
auto kernel_export = GetExportByOrdinal(library_name, ordinal);
assert_not_null(kernel_export);
kernel_export->is_implemented = true;
kernel_export->variable_ptr = value;
}
void ExportResolver::SetFunctionMapping(const std::string& library_name,
const uint32_t ordinal, void* shim_data,
xe_kernel_export_shim_fn shim) {
auto kernel_export = GetExportByOrdinal(library_name, ordinal);
assert_not_null(kernel_export);
kernel_export->is_implemented = true;
kernel_export->function_data.shim_data = shim_data;
kernel_export->function_data.shim = shim;
}
} // namespace cpu
} // namespace xe

View File

@@ -0,0 +1,84 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_CPU_EXPORT_RESOLVER_H_
#define XENIA_CPU_EXPORT_RESOLVER_H_
#include <string>
#include <vector>
namespace xe {
namespace cpu {
typedef void (*xe_kernel_export_shim_fn)(void*, void*);
class KernelExport {
public:
enum ExportType {
Function = 0,
Variable = 1,
};
uint32_t ordinal;
ExportType type;
uint32_t flags;
char name[96];
bool is_implemented;
union {
// Variable data. Only valid when kXEKernelExportFlagVariable is set.
// This is an address in the client memory space that the variable can
// be found at.
uint32_t variable_ptr;
struct {
// Second argument passed to the shim function.
void* shim_data;
// Shimmed implementation.
// This is called directly from generated code.
// It should parse args, do fixups, and call the impl.
xe_kernel_export_shim_fn shim;
} function_data;
};
};
class ExportResolver {
public:
ExportResolver();
~ExportResolver();
void RegisterTable(const std::string& library_name, KernelExport* exports,
const size_t count);
KernelExport* GetExportByOrdinal(const std::string& library_name,
const uint32_t ordinal);
void SetVariableMapping(const std::string& library_name,
const uint32_t ordinal, uint32_t value);
void SetFunctionMapping(const std::string& library_name,
const uint32_t ordinal, void* shim_data,
xe_kernel_export_shim_fn shim);
private:
struct ExportTable {
std::string name;
KernelExport* exports;
size_t count;
ExportTable(const std::string& name, KernelExport* exports, size_t count)
: name(name), exports(exports), count(count) {}
};
std::vector<ExportTable> tables_;
};
} // namespace cpu
} // namespace xe
#endif // XENIA_CPU_EXPORT_RESOLVER_H_

View File

@@ -10,9 +10,9 @@
#include "xenia/cpu/processor.h"
#include "xenia/cpu/cpu-private.h"
#include "xenia/cpu/export_resolver.h"
#include "xenia/cpu/runtime.h"
#include "xenia/cpu/xex_module.h"
#include "xenia/export_resolver.h"
#include "xenia/logging.h"
#include "xenia/profiling.h"

View File

@@ -13,7 +13,7 @@
#include <mutex>
#include <vector>
#include "xenia/export_resolver.h"
#include "xenia/cpu/export_resolver.h"
#include "xenia/memory.h"
namespace xe {

View File

@@ -13,11 +13,11 @@
#include "xenia/cpu/backend/backend.h"
#include "xenia/cpu/debugger.h"
#include "xenia/cpu/entry_table.h"
#include "xenia/cpu/export_resolver.h"
#include "xenia/cpu/frontend/ppc_frontend.h"
#include "xenia/cpu/function.h"
#include "xenia/cpu/module.h"
#include "xenia/cpu/thread_state.h"
#include "xenia/export_resolver.h"
#include "xenia/memory.h"
namespace xe {

View File

@@ -10,6 +10,8 @@
'debugger.h',
'entry_table.cc',
'entry_table.h',
'export_resolver.cc',
'export_resolver.h',
'function.cc',
'function.h',
'instrument.cc',

View File

@@ -13,8 +13,8 @@
#include "poly/math.h"
#include "xenia/cpu/cpu-private.h"
#include "xenia/cpu/export_resolver.h"
#include "xenia/cpu/runtime.h"
#include "xenia/export_resolver.h"
#include "xenia/logging.h"
namespace xe {