Fix compiler errors i introduced under clang-cl

remove xe_kernel_export_shim_fn field of Export function_data, trampoline is now the only way exports get invoked
Remove kernelstate argument from string functions in order to conform to the trampoline signature (the argument was unused anyway)
Constant-evaluated initialization of ppc_opcode_disasm_table, removal of unused std::vector fields
Constant-evaluated initialization of export tables
name field on export is just a const char* now, only immutable static strings are ever passed to it
Remove unused callcount field of export.
PM4 compare op function extracted
Globally apply /Oy, /GS-, /Gw on msvc windows
Remove imgui testwindow code call, it took up like 300 kb
This commit is contained in:
chss95cs@gmail.com
2022-09-29 07:04:17 -07:00
parent 203267b106
commit 7e58a3b320
20 changed files with 140 additions and 204 deletions

View File

@@ -81,7 +81,7 @@ void ExportResolver::SetFunctionMapping(const std::string_view module_name,
auto export_entry = GetExportByOrdinal(module_name, ordinal);
assert_not_null(export_entry);
export_entry->tags |= ExportTag::kImplemented;
export_entry->function_data.shim = shim;
export_entry->function_data.trampoline = (ExportTrampoline)(void*)shim;
}
void ExportResolver::SetFunctionMapping(const std::string_view module_name,

View File

@@ -44,57 +44,50 @@ struct ExportTag {
// packed like so:
// ll...... cccccccc ........ ..bihssi
static const int CategoryShift = 16;
static constexpr int CategoryShift = 16;
// Export is implemented in some form and can be used.
static const type kImplemented = 1u << 0;
static constexpr type kImplemented = 1u << 0;
// Export is a stub and is probably bad.
static const type kStub = 1u << 1;
static constexpr type kStub = 1u << 1;
// Export is known to cause problems, or may not be complete.
static const type kSketchy = 1u << 2;
static constexpr type kSketchy = 1u << 2;
// Export is called *a lot*.
static const type kHighFrequency = 1u << 3;
static constexpr type kHighFrequency = 1u << 3;
// Export is important and should always be logged.
static const type kImportant = 1u << 4;
static constexpr type kImportant = 1u << 4;
// Export blocks the calling thread
static const type kBlocking = 1u << 5;
static constexpr type kBlocking = 1u << 5;
static constexpr type kIsVariable = 1u << 6;
// Export will be logged on each call.
static const type kLog = 1u << 30;
static constexpr type kLog = 1u << 30;
// Export's result will be logged on each call.
static const type kLogResult = 1u << 31;
static constexpr type kLogResult = 1u << 31;
};
// DEPRECATED
typedef void (*xe_kernel_export_shim_fn)(void*, void*);
typedef void (*ExportTrampoline)(ppc::PPCContext* ppc_context);
#pragma pack(push, 1)
class Export {
public:
enum class Type {
kFunction = 0,
kVariable = 1,
};
Export(uint16_t ordinal, Type type, const char* name,
ExportTag::type tags = 0)
: ordinal(ordinal),
type(type),
constexpr Export(uint16_t ordinal, Type type, const char* name,
ExportTag::type tags = 0)
: function_data({nullptr}),
name(name ? name : ""),
tags(tags),
function_data({nullptr, nullptr, 0}) {
std::strncpy(this->name, name, xe::countof(this->name));
ordinal(ordinal)
{
if (type == Type::kVariable) {
this->tags |= ExportTag::kIsVariable;
}
}
uint16_t ordinal;
Type type;
char name[96];
ExportTag::type tags;
bool is_implemented() const {
return (tags & ExportTag::kImplemented) == ExportTag::kImplemented;
}
union {
// Variable data. Only valid when kXEKernelExportFlagVariable is set.
// This is an address in the client memory space that the variable can
@@ -102,17 +95,26 @@ class Export {
uint32_t variable_ptr;
struct {
// DEPRECATED
xe_kernel_export_shim_fn shim;
// Trampoline that is called from the guest-to-host thunk.
// Expects only PPC context as first arg.
ExportTrampoline trampoline;
uint64_t call_count;
} function_data;
};
};
const char* const name;
ExportTag::type tags;
uint16_t ordinal;
// Type type;
constexpr bool is_implemented() const {
return (tags & ExportTag::kImplemented) == ExportTag::kImplemented;
}
constexpr Type get_type() const {
return (this->tags & ExportTag::kIsVariable) ? Type::kVariable
: Type::kFunction;
}
};
#pragma pack(pop)
class ExportResolver {
public:
class Table {

View File

@@ -4948,8 +4948,8 @@ void PrintDisasm_xorx(const PPCDecodeData& d, StringBuffer* str) {
}
#define INIT_LIST(...) {__VA_ARGS__}
#define INSTRUCTION(opcode, mnem, form, group, type, desc, reads, writes, fn) \
{PPCOpcodeGroup::group, PPCOpcodeFormat::form, opcode, mnem, desc, INIT_LIST reads, INIT_LIST writes, fn}
PPCOpcodeDisasmInfo ppc_opcode_disasm_table[] = {
{PPCOpcodeGroup::group, PPCOpcodeFormat::form, opcode, mnem, desc, fn}
static constexpr PPCOpcodeDisasmInfo ppc_opcode_disasm_table[] = {
INSTRUCTION(0x7c000014, "addcx" , kXO , kI, kGeneral, "Add Carrying" , (PPCOpcodeField::kRA,PPCOpcodeField::kRB), (PPCOpcodeField::kRD,PPCOpcodeField::kCA,PPCOpcodeField::kOEcond,PPCOpcodeField::kCRcond), PrintDisasm_addcx),
INSTRUCTION(0x7c000114, "addex" , kXO , kI, kGeneral, "Add Extended" , (PPCOpcodeField::kRA,PPCOpcodeField::kRB,PPCOpcodeField::kCA), (PPCOpcodeField::kRD,PPCOpcodeField::kOEcond,PPCOpcodeField::kCRcond), PrintDisasm_addex),
INSTRUCTION(0x38000000, "addi" , kD , kI, kGeneral, "Add Immediate" , (PPCOpcodeField::kRA0,PPCOpcodeField::kSIMM), (PPCOpcodeField::kRD), PrintDisasm_addi),
@@ -5414,7 +5414,7 @@ const PPCOpcodeDisasmInfo& GetOpcodeDisasmInfo(PPCOpcode opcode) {
}
void RegisterOpcodeDisasm(PPCOpcode opcode, InstrDisasmFn fn) {
assert_null(ppc_opcode_disasm_table[static_cast<int>(opcode)].disasm);
ppc_opcode_disasm_table[static_cast<int>(opcode)].disasm = fn;
const_cast<PPCOpcodeDisasmInfo*>( &ppc_opcode_disasm_table[static_cast<int>(opcode)])->disasm = fn;
}
} // namespace ppc

View File

@@ -133,18 +133,18 @@ enum class PPCOpcodeField : uint32_t {
kTO,
kLEV,
};
#pragma pack(push, 1)
struct PPCOpcodeDisasmInfo {
PPCOpcodeGroup group;
PPCOpcodeFormat format;
uint32_t opcode;
const char* name;
const char* description;
std::vector<PPCOpcodeField> reads;
std::vector<PPCOpcodeField> writes;
// std::vector<PPCOpcodeField> reads;
// std::vector<PPCOpcodeField> writes;
InstrDisasmFn disasm;
};
#pragma pack(pop)
PPCOpcode LookupOpcode(uint32_t code);
const PPCOpcodeInfo& GetOpcodeInfo(PPCOpcode opcode);

View File

@@ -1194,11 +1194,11 @@ bool XexModule::SetupLibraryImports(const std::string_view name,
}
if (kernel_export) {
if (kernel_export->type == Export::Type::kFunction) {
if (kernel_export->get_type() == Export::Type::kFunction) {
// Not exactly sure what this should be...
// Appears to be ignored.
*record_slot = 0xDEADC0DE;
} else if (kernel_export->type == Export::Type::kVariable) {
} else if (kernel_export->get_type() == Export::Type::kVariable) {
// Kernel import variable
if (kernel_export->is_implemented()) {
// Implemented - replace with pointer.
@@ -1287,8 +1287,9 @@ bool XexModule::SetupLibraryImports(const std::string_view name,
handler = (GuestFunction::ExternHandler)
kernel_export->function_data.trampoline;
} else {
handler =
(GuestFunction::ExternHandler)kernel_export->function_data.shim;
//__debugbreak();
// handler =
// (GuestFunction::ExternHandler)kernel_export->function_data.shim;
}
} else {
XELOGW("WARNING: Imported kernel function {} is unimplemented!",