Code fixes to get things somewhat compiling on Windows.

This commit is contained in:
Ben Vanik 2013-01-30 01:35:08 -08:00
parent 5da1fd66d1
commit ae4d8ad40e
25 changed files with 136 additions and 92 deletions

View File

@ -61,7 +61,7 @@ XEFORCEINLINE void* xe_atomic_stack_dequeue(xe_atomic_stack_t* stack,
const size_t offset) { const size_t offset) {
void* ptr = (void*)InterlockedPopEntrySList((PSLIST_HEADER)stack); void* ptr = (void*)InterlockedPopEntrySList((PSLIST_HEADER)stack);
if (ptr) { if (ptr) {
return (void*)(((byte*)ptr) - offset); return (void*)(((uint8_t*)ptr) - offset);
} else { } else {
return NULL; return NULL;
} }

View File

@ -13,8 +13,6 @@
#include <xenia/common.h> #include <xenia/common.h>
#include <xenia/core.h> #include <xenia/core.h>
#include <tr1/unordered_map>
#include <xenia/cpu/sdb.h> #include <xenia/cpu/sdb.h>
#include <xenia/core/memory.h> #include <xenia/core/memory.h>
#include <xenia/kernel/export.h> #include <xenia/kernel/export.h>

View File

@ -13,8 +13,6 @@
#include <xenia/common.h> #include <xenia/common.h>
#include <xenia/core.h> #include <xenia/core.h>
#include <tr1/unordered_map>
#include <xenia/cpu/sdb.h> #include <xenia/cpu/sdb.h>
#include <xenia/kernel/export.h> #include <xenia/kernel/export.h>
#include <xenia/kernel/user_module.h> #include <xenia/kernel/user_module.h>

View File

@ -12,7 +12,6 @@
#include <xenia/core.h> #include <xenia/core.h>
#include <tr1/unordered_map>
#include <vector> #include <vector>
#include <xenia/cpu/exec_module.h> #include <xenia/cpu/exec_module.h>

View File

@ -10,6 +10,8 @@
#ifndef XENIA_LOGGING_H_ #ifndef XENIA_LOGGING_H_
#define XENIA_LOGGING_H_ #define XENIA_LOGGING_H_
#include <xenia/platform.h>
#include <xenia/platform_includes.h>
#include <xenia/config.h> #include <xenia/config.h>
#include <xenia/string.h> #include <xenia/string.h>

View File

@ -19,6 +19,8 @@
#endif #endif
#include <SDKDDKVer.h> #include <SDKDDKVer.h>
#include <windows.h> #include <windows.h>
#undef min
#undef max
#endif // WINCE || WIN32 #endif // WINCE || WIN32
#if XE_PLATFORM(XBOX360) #if XE_PLATFORM(XBOX360)
@ -46,6 +48,15 @@
#include <errno.h> #include <errno.h>
#include <string> #include <string>
#include <assert.h> #include <assert.h>
#include <stdint.h>
#if XE_COMPILER(MSVC)
#include <memory>
#include <unordered_map>
#else
#include <tr1/memory>
#include <tr1/unordered_map>
#endif // MSVC
#endif // XENIA_PLATFORM_INCLUDES_H_ #endif // XENIA_PLATFORM_INCLUDES_H_

View File

@ -23,15 +23,20 @@
int strncpy_s(char* dest, size_t destLength, const char* source, size_t count); int strncpy_s(char* dest, size_t destLength, const char* source, size_t count);
#define strcpy_s(dest, destLength, source) !(strcpy(dest, source) == dest + (destLength*0)) #define strcpy_s(dest, destLength, source) !(strcpy(dest, source) == dest + (destLength*0))
#define strcat_s(dest, destLength, source) !(strcat(dest, source) == dest + (destLength*0)) #define strcat_s(dest, destLength, source) !(strcat(dest, source) == dest + (destLength*0))
#define _snprintf_s(dest, destLength, format, ...) snprintf(dest, destLength, format, ##__VA_ARGS__) #define _snprintf_s(dest, destLength, x, format, ...) snprintf(dest, destLength, format, ##__VA_ARGS__)
#define xestrdupa strdup
#define xestrtoulla strtoull
#else #else
#define strcasecmp _stricmp #define strcasecmp _stricmp
#define xestrdupa _strdup
#define xestrtoullw _wcstoui64
#define xestrtoulla _strtoui64
#endif #endif
#define xestrlenw wcslen #define xestrlenw wcslen
#define xestrcmpw wcscmp #define xestrcmpw wcscmp
#define xestrcasecmpw _wcsicmp #define xestrcasecmpw _wcsicmp
#define xsstrdupw wcsdup #define xestrdupw wcsdup
#define xestrchrw wcschr #define xestrchrw wcschr
#define xestrrchrw wcsrchr #define xestrrchrw wcsrchr
#define xestrstrw wcsstr #define xestrstrw wcsstr
@ -45,14 +50,13 @@ int strncpy_s(char* dest, size_t destLength, const char* source, size_t count);
#define xestrlena strlen #define xestrlena strlen
#define xestrcmpa strcmp #define xestrcmpa strcmp
#define xestrcasecmpa strcasecmp #define xestrcasecmpa strcasecmp
#define xestrdupa strdup
#define xestrchra strchr #define xestrchra strchr
#define xestrrchra strrchr #define xestrrchra strrchr
#define xestrstra strstr #define xestrstra strstr
#define xestrcpya(dest, destLength, source) (strcpy_s(dest, destLength, source) == 0) #define xestrcpya(dest, destLength, source) (strcpy_s(dest, destLength, source) == 0)
#define xestrncpya(dest, destLength, source, count) (strncpy_s(dest, destLength, source, count) == 0) #define xestrncpya(dest, destLength, source, count) (strncpy_s(dest, destLength, source, count) == 0)
#define xestrcata(dest, destLength, source) (strcat_s(dest, destLength, source) == 0) #define xestrcata(dest, destLength, source) (strcat_s(dest, destLength, source) == 0)
#define xesnprintfa(buffer, bufferCount, format, ...) _snprintf_s(buffer, bufferCount, format, ##__VA_ARGS__) #define xesnprintfa(buffer, bufferCount, format, ...) _snprintf_s(buffer, bufferCount, bufferCount, format, ##__VA_ARGS__)
#define xevsnprintfa(buffer, bufferCount, format, args) vsnprintf(buffer, bufferCount, format, args) #define xevsnprintfa(buffer, bufferCount, format, args) vsnprintf(buffer, bufferCount, format, args)
#if XE_PLATFORM(WIN32) #if XE_PLATFORM(WIN32)
@ -68,6 +72,7 @@ typedef wchar_t xechar_t;
#define xestrchr xestrchrw #define xestrchr xestrchrw
#define xestrrchr xestrrchrw #define xestrrchr xestrrchrw
#define xestrstr xestrstrw #define xestrstr xestrstrw
#define xestrtoull xestrtoullw
#define xestrcpy xestrcpyw #define xestrcpy xestrcpyw
#define xestrncpy xestrncpyw #define xestrncpy xestrncpyw
#define xestrcat xestrcatw #define xestrcat xestrcatw
@ -89,6 +94,7 @@ typedef char xechar_t;
#define xestrchr xestrchra #define xestrchr xestrchra
#define xestrrchr xestrrchra #define xestrrchr xestrrchra
#define xestrstr xestrstra #define xestrstr xestrstra
#define xestrtoull xestrtoulla
#define xestrcpy xestrcpya #define xestrcpy xestrcpya
#define xestrncpy xestrncpya #define xestrncpy xestrncpya
#define xestrcat xestrcata #define xestrcat xestrcata

View File

@ -13,7 +13,6 @@
#include <xenia/platform.h> #include <xenia/platform.h>
#include <xenia/platform_includes.h> #include <xenia/platform_includes.h>
#include <tr1/memory>
namespace xe { namespace xe {
// TODO(benvanik): support other compilers/etc // TODO(benvanik): support other compilers/etc
using std::auto_ptr; using std::auto_ptr;

View File

@ -209,7 +209,7 @@ void FunctionGenerator::GenerateSharedBlocks() {
SwitchInst* switch_i = b.CreateSwitch( SwitchInst* switch_i = b.CreateSwitch(
b.CreateLoad(locals_.indirection_target), b.CreateLoad(locals_.indirection_target),
external_indirection_block_, external_indirection_block_,
bbs_.size()); static_cast<int>(bbs_.size()));
for (std::map<uint32_t, BasicBlock*>::iterator it = bbs_.begin(); for (std::map<uint32_t, BasicBlock*>::iterator it = bbs_.begin();
it != bbs_.end(); ++it) { it != bbs_.end(); ++it) {
switch_i->addCase(b.getInt64(it->first), it->second); switch_i->addCase(b.getInt64(it->first), it->second);
@ -301,7 +301,7 @@ void FunctionGenerator::GenerateBasicBlock(FunctionBlock* block) {
} }
if (!i.type) { if (!i.type) {
XELOGCPU("Invalid instruction %.8X %.8X", ia, i.code); XELOGCPU(XT("Invalid instruction %.8X %.8X"), ia, i.code);
SpillRegisters(); SpillRegisters();
b.CreateCall3( b.CreateCall3(
invalidInstruction, invalidInstruction,
@ -334,7 +334,7 @@ void FunctionGenerator::GenerateBasicBlock(FunctionBlock* block) {
// This printf is handy for sort/uniquify to find instructions. // This printf is handy for sort/uniquify to find instructions.
//printf("unimplinstr %s\n", i.type->name); //printf("unimplinstr %s\n", i.type->name);
XELOGCPU("Unimplemented instr %.8X %.8X %s", XELOGCPU(XT("Unimplemented instr %.8X %.8X %s"),
ia, i.code, i.type->name); ia, i.code, i.type->name);
SpillRegisters(); SpillRegisters();
b.CreateCall3( b.CreateCall3(
@ -353,8 +353,8 @@ void FunctionGenerator::GenerateBasicBlock(FunctionBlock* block) {
} else if (block->outgoing_type == FunctionBlock::kTargetUnknown) { } else if (block->outgoing_type == FunctionBlock::kTargetUnknown) {
// Hrm. // Hrm.
// TODO(benvanik): assert this doesn't occur - means a bad sdb run! // TODO(benvanik): assert this doesn't occur - means a bad sdb run!
XELOGCPU("SDB function scan error in %.8X: bb %.8X has unknown exit\n", XELOGCPU(XT("SDB function scan error in %.8X: bb %.8X has unknown exit"),
fn_->start_address, block->start_address); fn_->start_address, block->start_address);
b.CreateRetVoid(); b.CreateRetVoid();
} }
@ -386,7 +386,8 @@ BasicBlock* FunctionGenerator::GetReturnBasicBlock() {
Function* FunctionGenerator::GetFunction(FunctionSymbol* fn) { Function* FunctionGenerator::GetFunction(FunctionSymbol* fn) {
Function* result = gen_module_->getFunction(StringRef(fn->name)); Function* result = gen_module_->getFunction(StringRef(fn->name));
if (!result) { if (!result) {
XELOGE("Static function not found: %.8X %s\n", fn->start_address, fn->name); XELOGE(XT("Static function not found: %.8X %s"),
fn->start_address, fn->name);
} }
XEASSERTNOTNULL(result); XEASSERTNOTNULL(result);
return result; return result;
@ -601,7 +602,7 @@ void FunctionGenerator::FillRegisters() {
} }
// Note that we skip zero. // Note that we skip zero.
for (size_t n = 0; n < XECOUNT(locals_.gpr); n++) { for (int n = 0; n < XECOUNT(locals_.gpr); n++) {
if (locals_.gpr[n]) { if (locals_.gpr[n]) {
b.CreateStore(LoadStateValue( b.CreateStore(LoadStateValue(
offsetof(xe_ppc_state_t, r) + 8 * n, offsetof(xe_ppc_state_t, r) + 8 * n,

View File

@ -71,9 +71,9 @@ int ModuleGenerator::Generate() {
// Setup a debug info builder. // Setup a debug info builder.
// This is used when creating any debug info. We may want to go more // This is used when creating any debug info. We may want to go more
// fine grained than this, but for now it's something. // fine grained than this, but for now it's something.
xechar_t dir[2048]; char dir[2048];
XEIGNORE(xestrcpy(dir, XECOUNT(dir), module_path_)); XEIGNORE(xestrcpya(dir, XECOUNT(dir), module_path_));
xechar_t* slash = xestrrchr(dir, '/'); char* slash = xestrrchra(dir, '/');
if (slash) { if (slash) {
*(slash + 1) = 0; *(slash + 1) = 0;
} }

View File

@ -138,8 +138,8 @@ int ExecModule::Prepare() {
// Dump the symbol database. // Dump the symbol database.
if (FLAGS_dump_module_map) { if (FLAGS_dump_module_map) {
xesnprintf(file_name, XECOUNT(file_name), xesnprintfa(file_name, XECOUNT(file_name),
"%s%s.map", FLAGS_dump_path.c_str(), module_name_); "%s%s.map", FLAGS_dump_path.c_str(), module_name_);
sdb_->Write(file_name); sdb_->Write(file_name);
} }
@ -171,8 +171,8 @@ int ExecModule::Prepare() {
// Dump pre-optimized module to disk. // Dump pre-optimized module to disk.
if (FLAGS_dump_module_bitcode) { if (FLAGS_dump_module_bitcode) {
xesnprintf(file_name, XECOUNT(file_name), xesnprintfa(file_name, XECOUNT(file_name),
"%s%s-preopt.bc", FLAGS_dump_path.c_str(), module_name_); "%s%s-preopt.bc", FLAGS_dump_path.c_str(), module_name_);
outs = auto_ptr<raw_ostream>(new raw_fd_ostream( outs = auto_ptr<raw_ostream>(new raw_fd_ostream(
file_name, error_message, raw_fd_ostream::F_Binary)); file_name, error_message, raw_fd_ostream::F_Binary));
XEEXPECTTRUE(error_message.empty()); XEEXPECTTRUE(error_message.empty());
@ -203,8 +203,8 @@ int ExecModule::Prepare() {
// Dump post-optimized module to disk. // Dump post-optimized module to disk.
if (FLAGS_optimize_ir_modules && FLAGS_dump_module_bitcode) { if (FLAGS_optimize_ir_modules && FLAGS_dump_module_bitcode) {
xesnprintf(file_name, XECOUNT(file_name), xesnprintfa(file_name, XECOUNT(file_name),
"%s%s.bc", FLAGS_dump_path.c_str(), module_name_); "%s%s.bc", FLAGS_dump_path.c_str(), module_name_);
outs = auto_ptr<raw_ostream>(new raw_fd_ostream( outs = auto_ptr<raw_ostream>(new raw_fd_ostream(
file_name, error_message, raw_fd_ostream::F_Binary)); file_name, error_message, raw_fd_ostream::F_Binary));
XEEXPECTTRUE(error_message.empty()); XEEXPECTTRUE(error_message.empty());
@ -397,7 +397,7 @@ int ExecModule::Init() {
} else { } else {
// Not implemented - write with a dummy value. // Not implemented - write with a dummy value.
*slot = XESWAP32BE(0xDEADBEEF); *slot = XESWAP32BE(0xDEADBEEF);
XELOGCPU("WARNING: imported a variable with no value: %s", XELOGCPU(XT("WARNING: imported a variable with no value: %s"),
kernel_export->name); kernel_export->name);
} }
} }
@ -411,7 +411,7 @@ int ExecModule::Init() {
std::vector<GenericValue> args; std::vector<GenericValue> args;
GenericValue ret = engine_->runFunction(xe_module_init, args); GenericValue ret = engine_->runFunction(xe_module_init, args);
return ret.IntVal.getSExtValue(); return static_cast<int>(ret.IntVal.getSExtValue());
} }
int ExecModule::Uninit() { int ExecModule::Uninit() {

View File

@ -150,26 +150,30 @@ void InstrDisasm::Init(std::string name, std::string info, uint32_t flags) {
if (flags & InstrDisasm::kOE) { if (flags & InstrDisasm::kOE) {
name += "o"; name += "o";
special_registers.push_back((InstrRegister){ InstrRegister i = {
InstrRegister::kXER, 0, InstrRegister::kReadWrite InstrRegister::kXER, 0, InstrRegister::kReadWrite
}); };
special_registers.push_back(i);
} }
if (flags & InstrDisasm::kRc) { if (flags & InstrDisasm::kRc) {
name += "."; name += ".";
special_registers.push_back((InstrRegister){ InstrRegister i = {
InstrRegister::kCR, 0, InstrRegister::kWrite InstrRegister::kCR, 0, InstrRegister::kWrite
}); };
special_registers.push_back(i);
} }
if (flags & InstrDisasm::kCA) { if (flags & InstrDisasm::kCA) {
special_registers.push_back((InstrRegister){ InstrRegister i = {
InstrRegister::kXER, 0, InstrRegister::kReadWrite InstrRegister::kXER, 0, InstrRegister::kReadWrite
}); };
special_registers.push_back(i);
} }
if (flags & InstrDisasm::kLR) { if (flags & InstrDisasm::kLR) {
name += "l"; name += "l";
special_registers.push_back((InstrRegister){ InstrRegister i = {
InstrRegister::kLR, 0, InstrRegister::kWrite InstrRegister::kLR, 0, InstrRegister::kWrite
}); };
special_registers.push_back(i);
} }
XEIGNORE(xestrcpya(this->name, XECOUNT(this->name), name.c_str())); XEIGNORE(xestrcpya(this->name, XECOUNT(this->name), name.c_str()));
@ -178,31 +182,35 @@ void InstrDisasm::Init(std::string name, std::string info, uint32_t flags) {
} }
void InstrDisasm::AddLR(InstrRegister::Access access) { void InstrDisasm::AddLR(InstrRegister::Access access) {
special_registers.push_back((InstrRegister){ InstrRegister i = {
InstrRegister::kLR, 0, access InstrRegister::kLR, 0, access
}); };
special_registers.push_back(i);
} }
void InstrDisasm::AddCTR(InstrRegister::Access access) { void InstrDisasm::AddCTR(InstrRegister::Access access) {
special_registers.push_back((InstrRegister){ InstrRegister i = {
InstrRegister::kCTR, 0, access InstrRegister::kCTR, 0, access
}); };
special_registers.push_back(i);
} }
void InstrDisasm::AddCR(uint32_t bf, InstrRegister::Access access) { void InstrDisasm::AddCR(uint32_t bf, InstrRegister::Access access) {
special_registers.push_back((InstrRegister){ InstrRegister i = {
InstrRegister::kCR, bf, access InstrRegister::kCR, bf, access
}); };
special_registers.push_back(i);
} }
void InstrDisasm::AddRegOperand( void InstrDisasm::AddRegOperand(
InstrRegister::RegisterSet set, uint32_t ordinal, InstrRegister::RegisterSet set, uint32_t ordinal,
InstrRegister::Access access, std::string display) { InstrRegister::Access access, std::string display) {
InstrOperand o; InstrRegister i = {
o.type = InstrOperand::kRegister;
o.reg = (InstrRegister){
set, ordinal, access set, ordinal, access
}; };
InstrOperand o;
o.type = InstrOperand::kRegister;
o.reg = i;
if (!display.size()) { if (!display.size()) {
std::stringstream display_out; std::stringstream display_out;
switch (set) { switch (set) {

View File

@ -21,7 +21,7 @@ namespace tables {
static InstrType* instr_table_prep( static InstrType* instr_table_prep(
InstrType* unprep, int unprep_count, int a, int b) { InstrType* unprep, int unprep_count, int a, int b) {
int prep_count = pow(2, b - a + 1); int prep_count = pow(2.0, b - a + 1);
InstrType* prep = (InstrType*)xe_calloc(prep_count * sizeof(InstrType)); InstrType* prep = (InstrType*)xe_calloc(prep_count * sizeof(InstrType));
for (int n = 0; n < unprep_count; n++) { for (int n = 0; n < unprep_count; n++) {
int ordinal = XESELECTBITS(unprep[n].opcode, a, b); int ordinal = XESELECTBITS(unprep[n].opcode, a, b);

View File

@ -15,7 +15,7 @@
namespace { namespace {
uint64_t ParseInt64(const char* value) { uint64_t ParseInt64(const char* value) {
return strtoull(value, NULL, 0); return xestrtoulla(value, NULL, 0);
} }
} }

View File

@ -135,8 +135,12 @@ int Processor::PrepareModule(
int Processor::PrepareModule(UserModule* user_module, int Processor::PrepareModule(UserModule* user_module,
shared_ptr<ExportResolver> export_resolver) { shared_ptr<ExportResolver> export_resolver) {
char name_a[2048];
char path_a[2048];
XEIGNORE(xestrnarrow(name_a, XECOUNT(name_a), user_module->name()));
XEIGNORE(xestrnarrow(path_a, XECOUNT(path_a), user_module->path()));
ExecModule* exec_module = new ExecModule( ExecModule* exec_module = new ExecModule(
memory_, export_resolver, user_module->name(), user_module->path(), memory_, export_resolver, name_a, path_a,
engine_); engine_);
if (exec_module->PrepareUserModule(user_module)) { if (exec_module->PrepareUserModule(user_module)) {
@ -173,7 +177,7 @@ int Processor::Execute(ThreadState* thread_state, uint32_t address) {
// Find the function to execute. // Find the function to execute.
Function* f = GetFunction(address); Function* f = GetFunction(address);
if (!f) { if (!f) {
XELOGCPU("Failed to find function %.8X to execute.\n", address); XELOGCPU(XT("Failed to find function %.8X to execute."), address);
return 1; return 1;
} }

View File

@ -173,7 +173,7 @@ FunctionSymbol* SymbolDatabase::GetOrInsertFunction(uint32_t address) {
// Ignore values outside of the .text range. // Ignore values outside of the .text range.
if (!IsValueInTextRange(address)) { if (!IsValueInTextRange(address)) {
XELOGSDB("Ignoring function outside of .text: %.8X\n", address); XELOGSDB(XT("Ignoring function outside of .text: %.8X"), address);
return NULL; return NULL;
} }
@ -340,7 +340,7 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
if (*((uint32_t*)(p + fn->start_address)) == 0) { if (*((uint32_t*)(p + fn->start_address)) == 0) {
// Function starts with 0x00000000 - we want to skip this and split. // Function starts with 0x00000000 - we want to skip this and split.
XELOGSDB("function starts with 0: %.8X\n", fn->start_address); XELOGSDB(XT("function starts with 0: %.8X"), fn->start_address);
symbols_.erase(fn->start_address); symbols_.erase(fn->start_address);
if (!GetFunction(fn->start_address + 4)) { if (!GetFunction(fn->start_address + 4)) {
fn->start_address += 4; fn->start_address += 4;
@ -352,13 +352,13 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
return 0; return 0;
} }
XELOGSDB("Analyzing function %.8X...\n", fn->start_address); XELOGSDB(XT("Analyzing function %.8X..."), fn->start_address);
// Set a default name, if it hasn't been named already. // Set a default name, if it hasn't been named already.
if (!fn->name) { if (!fn->name) {
char name[32]; char name[32];
xesnprintfa(name, XECOUNT(name), "sub_%.8X", fn->start_address); xesnprintfa(name, XECOUNT(name), "sub_%.8X", fn->start_address);
fn->name = xestrdup(name); fn->name = xestrdupa(name);
} }
// Set type, if needed. We assume user if not set. // Set type, if needed. We assume user if not set.
@ -378,13 +378,13 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
// If we fetched 0 assume that we somehow hit one of the awesome // If we fetched 0 assume that we somehow hit one of the awesome
// 'no really we meant to end after that bl' functions. // 'no really we meant to end after that bl' functions.
if (!i.code) { if (!i.code) {
XELOGSDB("function end %.8X (0x00000000 read)\n", addr); XELOGSDB(XT("function end %.8X (0x00000000 read)"), addr);
break; break;
} }
if (!i.type) { if (!i.type) {
// Invalid instruction. // Invalid instruction.
XELOGSDB("Invalid instruction at %.8X: %.8X\n", addr, i.code); XELOGSDB(XT("Invalid instruction at %.8X: %.8X"), addr, i.code);
return 1; return 1;
} }
@ -405,10 +405,10 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
block->outgoing_type = FunctionBlock::kTargetLR; block->outgoing_type = FunctionBlock::kTargetLR;
if (furthest_target > addr) { if (furthest_target > addr) {
// Remaining targets within function, not end. // Remaining targets within function, not end.
XELOGSDB("ignoring blr %.8X (branch to %.8X)\n", addr, furthest_target); XELOGSDB(XT("ignoring blr %.8X (branch to %.8X)"), addr, furthest_target);
} else { } else {
// Function end point. // Function end point.
XELOGSDB("function end %.8X\n", addr); XELOGSDB(XT("function end %.8X"), addr);
ends_fn = true; ends_fn = true;
} }
ends_block = true; ends_block = true;
@ -418,11 +418,11 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
block->outgoing_type = FunctionBlock::kTargetCTR; block->outgoing_type = FunctionBlock::kTargetCTR;
if (furthest_target > addr) { if (furthest_target > addr) {
// Remaining targets within function, not end. // Remaining targets within function, not end.
XELOGSDB("ignoring bctr %.8X (branch to %.8X)\n", addr, XELOGSDB(XT("ignoring bctr %.8X (branch to %.8X)"), addr,
furthest_target); furthest_target);
} else { } else {
// Function end point. // Function end point.
XELOGSDB("function end %.8X\n", addr); XELOGSDB(XT("function end %.8X"), addr);
ends_fn = true; ends_fn = true;
} }
ends_block = true; ends_block = true;
@ -432,17 +432,17 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
block->outgoing_address = target; block->outgoing_address = target;
if (i.I.LK) { if (i.I.LK) {
XELOGSDB("bl %.8X -> %.8X\n", addr, target); XELOGSDB(XT("bl %.8X -> %.8X"), addr, target);
// Queue call target if needed. // Queue call target if needed.
GetOrInsertFunction(target); GetOrInsertFunction(target);
} else { } else {
XELOGSDB("b %.8X -> %.8X\n", addr, target); XELOGSDB(XT("b %.8X -> %.8X"), addr, target);
// If the target is back into the function and there's no further target // If the target is back into the function and there's no further target
// we are at the end of a function. // we are at the end of a function.
if (target >= fn->start_address && if (target >= fn->start_address &&
target < addr && furthest_target <= addr) { target < addr && furthest_target <= addr) {
XELOGSDB("function end %.8X (back b)\n", addr); XELOGSDB(XT("function end %.8X (back b)"), addr);
ends_fn = true; ends_fn = true;
} }
@ -452,7 +452,7 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
// it. // it.
if (!ends_fn && if (!ends_fn &&
furthest_target <= addr && IsRestGprLr(target)) { furthest_target <= addr && IsRestGprLr(target)) {
XELOGSDB("function end %.8X (__restgprlr_*)\n", addr); XELOGSDB(XT("function end %.8X (__restgprlr_*)"), addr);
ends_fn = true; ends_fn = true;
} }
@ -466,9 +466,9 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
uint32_t target = XEEXTS16(i.B.BD << 2) + (i.B.AA ? 0 : (int32_t)addr); uint32_t target = XEEXTS16(i.B.BD << 2) + (i.B.AA ? 0 : (int32_t)addr);
block->outgoing_address = target; block->outgoing_address = target;
if (i.B.LK) { if (i.B.LK) {
XELOGSDB("bcl %.8X -> %.8X\n", addr, target); XELOGSDB(XT("bcl %.8X -> %.8X"), addr, target);
} else { } else {
XELOGSDB("bc %.8X -> %.8X\n", addr, target); XELOGSDB(XT("bc %.8X -> %.8X"), addr, target);
furthest_target = MAX(furthest_target, target); furthest_target = MAX(furthest_target, target);
} }
@ -477,18 +477,18 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
// bclr/bclrl // bclr/bclrl
block->outgoing_type = FunctionBlock::kTargetLR; block->outgoing_type = FunctionBlock::kTargetLR;
if (i.XL.LK) { if (i.XL.LK) {
XELOGSDB("bclrl %.8X\n", addr); XELOGSDB(XT("bclrl %.8X"), addr);
} else { } else {
XELOGSDB("bclr %.8X\n", addr); XELOGSDB(XT("bclr %.8X"), addr);
} }
ends_block = true; ends_block = true;
} else if (i.type->opcode == 0x4C000420) { } else if (i.type->opcode == 0x4C000420) {
// bcctr/bcctrl // bcctr/bcctrl
block->outgoing_type = FunctionBlock::kTargetCTR; block->outgoing_type = FunctionBlock::kTargetCTR;
if (i.XL.LK) { if (i.XL.LK) {
XELOGSDB("bcctrl %.8X\n", addr); XELOGSDB(XT("bcctrl %.8X"), addr);
} else { } else {
XELOGSDB("bcctr %.8X\n", addr); XELOGSDB(XT("bcctr %.8X"), addr);
} }
ends_block = true; ends_block = true;
} }
@ -508,8 +508,8 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
addr += 4; addr += 4;
if (fn->end_address && addr > fn->end_address) { if (fn->end_address && addr > fn->end_address) {
// Hmm.... // Hmm....
XELOGSDB("Ran over function bounds! %.8X-%.8X\n", XELOGSDB(XT("Ran over function bounds! %.8X-%.8X"),
fn->start_address, fn->end_address); fn->start_address, fn->end_address);
break; break;
} }
} }
@ -519,7 +519,7 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
// from someplace valid (like method hints) this may indicate an error. // from someplace valid (like method hints) this may indicate an error.
// It's also possible that we guessed in hole-filling and there's another // It's also possible that we guessed in hole-filling and there's another
// function below this one. // function below this one.
XELOGSDB("Function ran under: %.8X-%.8X ended at %.8X\n", XELOGSDB(XT("Function ran under: %.8X-%.8X ended at %.8X"),
fn->start_address, fn->end_address, addr + 4); fn->start_address, fn->end_address, addr + 4);
} }
fn->end_address = addr; fn->end_address = addr;
@ -532,7 +532,7 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
// - if present, flag function as needing a stack // - if present, flag function as needing a stack
// - record prolog/epilog lengths/stack size/etc // - record prolog/epilog lengths/stack size/etc
XELOGSDB("Finished analyzing %.8X\n", fn->start_address); XELOGSDB(XT("Finished analyzing %.8X"), fn->start_address);
return 0; return 0;
} }
@ -573,10 +573,12 @@ int SymbolDatabase::CompleteFunctionGraph(FunctionSymbol* fn) {
return 0; return 0;
} }
namespace {
typedef struct { typedef struct {
uint32_t start_address; uint32_t start_address;
uint32_t end_address; uint32_t end_address;
} HoleInfo; } HoleInfo;
}
bool SymbolDatabase::FillHoles() { bool SymbolDatabase::FillHoles() {
// If 4b, check if 0x00000000 and ignore (alignment padding) // If 4b, check if 0x00000000 and ignore (alignment padding)
@ -611,11 +613,13 @@ bool SymbolDatabase::FillHoles() {
ees.push_back(previous); ees.push_back(previous);
} else { } else {
// Probably legit. // Probably legit.
holes.push_back((HoleInfo){previous, fn->start_address}); HoleInfo hole_info = {previous, fn->start_address};
holes.push_back(hole_info);
} }
} else { } else {
// Probably legit. // Probably legit.
holes.push_back((HoleInfo){previous, fn->start_address}); HoleInfo hole_info = {previous, fn->start_address};
holes.push_back(hole_info);
} }
} }
previous = fn->end_address + 4; previous = fn->end_address + 4;
@ -666,7 +670,7 @@ int SymbolDatabase::FlushQueue() {
FunctionSymbol* fn = scan_queue_.front(); FunctionSymbol* fn = scan_queue_.front();
scan_queue_.pop_front(); scan_queue_.pop_front();
if (AnalyzeFunction(fn)) { if (AnalyzeFunction(fn)) {
XELOGSDB("Aborting analysis!\n"); XELOGSDB(XT("Aborting analysis!"));
return 1; return 1;
} }
} }
@ -806,7 +810,7 @@ int XexSymbolDatabase::FindGplr() {
char name[32]; char name[32];
uint32_t address = gplr_start; uint32_t address = gplr_start;
for (int n = 14; n <= 31; n++) { for (int n = 14; n <= 31; n++) {
xesnprintf(name, XECOUNT(name), "__savegprlr_%d", n); xesnprintfa(name, XECOUNT(name), "__savegprlr_%d", n);
FunctionSymbol* fn = GetOrInsertFunction(address); FunctionSymbol* fn = GetOrInsertFunction(address);
fn->end_address = fn->start_address + (31 - n) * 4 + 2 * 4; fn->end_address = fn->start_address + (31 - n) * 4 + 2 * 4;
fn->name = xestrdupa(name); fn->name = xestrdupa(name);
@ -816,7 +820,7 @@ int XexSymbolDatabase::FindGplr() {
} }
address = gplr_start + 20 * 4; address = gplr_start + 20 * 4;
for (int n = 14; n <= 31; n++) { for (int n = 14; n <= 31; n++) {
xesnprintf(name, XECOUNT(name), "__restgprlr_%d", n); xesnprintfa(name, XECOUNT(name), "__restgprlr_%d", n);
FunctionSymbol* fn = GetOrInsertFunction(address); FunctionSymbol* fn = GetOrInsertFunction(address);
fn->end_address = fn->start_address + (31 - n) * 4 + 3 * 4; fn->end_address = fn->start_address + (31 - n) * 4 + 3 * 4;
fn->name = xestrdupa(name); fn->name = xestrdupa(name);

View File

@ -41,7 +41,7 @@ KernelExport* ExportResolver::GetExportByOrdinal(const char* library_name,
const uint32_t ordinal) { const uint32_t ordinal) {
for (std::vector<ExportTable>::iterator it = tables_.begin(); for (std::vector<ExportTable>::iterator it = tables_.begin();
it != tables_.end(); ++it) { it != tables_.end(); ++it) {
if (!xestrcmp(library_name, it->name)) { if (!xestrcmpa(library_name, it->name)) {
// TODO(benvanik): binary search? // TODO(benvanik): binary search?
for (size_t n = 0; n < it->count; n++) { for (size_t n = 0; n < it->count; n++) {
if (it->exports[n].ordinal == ordinal) { if (it->exports[n].ordinal == ordinal) {

View File

@ -22,6 +22,7 @@ namespace xbdm {
static KernelExport xbdm_export_table[] = { static KernelExport xbdm_export_table[] = {
0,
}; };

View File

@ -85,8 +85,13 @@ int Runtime::LoadBinaryModule(const xechar_t* path, uint32_t start_address) {
addr, length)); addr, length));
// Prepare the module. // Prepare the module.
char name_a[2048];
XEEXPECTTRUE(xestrnarrow(name_a, XECOUNT(name_a), name));
char path_a[2048];
XEEXPECTTRUE(xestrnarrow(path_a, XECOUNT(path_a), path));
XEEXPECTZERO(processor_->PrepareModule( XEEXPECTZERO(processor_->PrepareModule(
name, path, start_address, start_address + length, export_resolver_)); name_a, path_a, start_address, start_address + length,
export_resolver_));
result_code = 0; result_code = 0;
XECLEANUP: XECLEANUP:

View File

@ -205,8 +205,8 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
size_t count = XEGETUINT32BE(pp + 0x08); size_t count = XEGETUINT32BE(pp + 0x08);
XEASSERT(count <= max_count); XEASSERT(count <= max_count);
if (count > max_count) { if (count > max_count) {
XELOGW(XT("ignoring %zu extra entries in " XELOGW(XT("ignoring %zu extra entries in ")
"XEX_HEADER_IMPORT_LIBRARIES"), (max_count - count)); XT("XEX_HEADER_IMPORT_LIBRARIES"), (max_count - count));
count = max_count; count = max_count;
} }
header->import_library_count = count; header->import_library_count = count;
@ -259,8 +259,8 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
size_t count = (opt_header->length - 4) / 16; size_t count = (opt_header->length - 4) / 16;
XEASSERT(count <= max_count); XEASSERT(count <= max_count);
if (count > max_count) { if (count > max_count) {
XELOGW(XT("ignoring %zu extra entries in " XELOGW(XT("ignoring %zu extra entries in ")
"XEX_HEADER_STATIC_LIBRARIES"), (max_count - count)); XT("XEX_HEADER_STATIC_LIBRARIES"), (max_count - count));
count = max_count; count = max_count;
} }
header->static_library_count = count; header->static_library_count = count;

View File

@ -12,6 +12,12 @@
#pragma pack (1) #pragma pack (1)
#endif #endif
// MODIFIED: on Windows a few definitions aren't in WINNT
#ifdef IMAGE_NT_SIGNATURE
#define IMAGE_SIZEOF_NT_OPTIONAL_HEADER 224
#define IMAGE_FILE_MACHINE_POWERPCBE 0x01F2 // IBM PowerPC Big-Endian
#endif
/* Skip if WINNT.H already included. We check IMAGE_NT_SIGNATURE instead of _WINNT_, /* Skip if WINNT.H already included. We check IMAGE_NT_SIGNATURE instead of _WINNT_,
* because WinCE's version of WINNT.H defines _WINNT_ but it doesn't include everything here * because WinCE's version of WINNT.H defines _WINNT_ but it doesn't include everything here
*/ */

View File

@ -19,7 +19,7 @@ using namespace xe::kernel;
int xenia_info(int argc, xechar_t **argv) { int xenia_info(int argc, xechar_t **argv) {
std::string usage = "usage: "; std::string usage = "usage: ";
usage = usage + argv[0] + " some.xex"; usage += "xenia-info some.xex";
google::SetUsageMessage(usage); google::SetUsageMessage(usage);
google::SetVersionString("1.0"); google::SetVersionString("1.0");
google::ParseCommandLineFlags(&argc, &argv, true); google::ParseCommandLineFlags(&argc, &argv, true);
@ -33,7 +33,7 @@ int xenia_info(int argc, xechar_t **argv) {
// Grab path. // Grab path.
if (argc < 2) { if (argc < 2) {
google::ShowUsageWithFlags(argv[0]); google::ShowUsageWithFlags("xenia-info");
return 1; return 1;
} }
const xechar_t *path = argv[1]; const xechar_t *path = argv[1];

View File

@ -81,7 +81,7 @@ int Run::Launch() {
int xenia_run(int argc, xechar_t **argv) { int xenia_run(int argc, xechar_t **argv) {
std::string usage = "usage: "; std::string usage = "usage: ";
usage = usage + argv[0] + " some.xex"; usage += "xenia-run some.xex";
google::SetUsageMessage(usage); google::SetUsageMessage(usage);
google::SetVersionString("1.0"); google::SetVersionString("1.0");
google::ParseCommandLineFlags(&argc, &argv, true); google::ParseCommandLineFlags(&argc, &argv, true);
@ -93,7 +93,7 @@ int xenia_run(int argc, xechar_t **argv) {
// Grab path. // Grab path.
if (argc < 2) { if (argc < 2) {
google::ShowUsageWithFlags(argv[0]); google::ShowUsageWithFlags("xenia-run");
return 1; return 1;
} }
const xechar_t *path = argv[1]; const xechar_t *path = argv[1];

View File

@ -226,7 +226,7 @@ XECLEANUP:
int xenia_test(int argc, xechar_t **argv) { int xenia_test(int argc, xechar_t **argv) {
string usage = "usage: "; string usage = "usage: ";
usage = usage + argv[0] + " some.xex"; usage += "xenia-test some.xex";
google::SetUsageMessage(usage); google::SetUsageMessage(usage);
google::SetVersionString("1.0"); google::SetVersionString("1.0");
google::ParseCommandLineFlags(&argc, &argv, true); google::ParseCommandLineFlags(&argc, &argv, true);

View File

@ -364,8 +364,10 @@ def run_all_gyps():
"""Runs all gyp configurations. """Runs all gyp configurations.
""" """
run_gyp('ninja') run_gyp('ninja')
run_gyp('xcode') if sys.platform == 'darwin':
run_gyp('msvs') run_gyp('xcode')
elif sys.platform == 'win32':
run_gyp('msvs')
class GypCommand(Command): class GypCommand(Command):