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

@@ -209,7 +209,7 @@ void FunctionGenerator::GenerateSharedBlocks() {
SwitchInst* switch_i = b.CreateSwitch(
b.CreateLoad(locals_.indirection_target),
external_indirection_block_,
bbs_.size());
static_cast<int>(bbs_.size()));
for (std::map<uint32_t, BasicBlock*>::iterator it = bbs_.begin();
it != bbs_.end(); ++it) {
switch_i->addCase(b.getInt64(it->first), it->second);
@@ -301,7 +301,7 @@ void FunctionGenerator::GenerateBasicBlock(FunctionBlock* block) {
}
if (!i.type) {
XELOGCPU("Invalid instruction %.8X %.8X", ia, i.code);
XELOGCPU(XT("Invalid instruction %.8X %.8X"), ia, i.code);
SpillRegisters();
b.CreateCall3(
invalidInstruction,
@@ -334,7 +334,7 @@ void FunctionGenerator::GenerateBasicBlock(FunctionBlock* block) {
// This printf is handy for sort/uniquify to find instructions.
//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);
SpillRegisters();
b.CreateCall3(
@@ -353,8 +353,8 @@ void FunctionGenerator::GenerateBasicBlock(FunctionBlock* block) {
} else if (block->outgoing_type == FunctionBlock::kTargetUnknown) {
// Hrm.
// 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",
fn_->start_address, block->start_address);
XELOGCPU(XT("SDB function scan error in %.8X: bb %.8X has unknown exit"),
fn_->start_address, block->start_address);
b.CreateRetVoid();
}
@@ -386,7 +386,8 @@ BasicBlock* FunctionGenerator::GetReturnBasicBlock() {
Function* FunctionGenerator::GetFunction(FunctionSymbol* fn) {
Function* result = gen_module_->getFunction(StringRef(fn->name));
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);
return result;
@@ -601,7 +602,7 @@ void FunctionGenerator::FillRegisters() {
}
// 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]) {
b.CreateStore(LoadStateValue(
offsetof(xe_ppc_state_t, r) + 8 * n,

View File

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

View File

@@ -138,8 +138,8 @@ int ExecModule::Prepare() {
// Dump the symbol database.
if (FLAGS_dump_module_map) {
xesnprintf(file_name, XECOUNT(file_name),
"%s%s.map", FLAGS_dump_path.c_str(), module_name_);
xesnprintfa(file_name, XECOUNT(file_name),
"%s%s.map", FLAGS_dump_path.c_str(), module_name_);
sdb_->Write(file_name);
}
@@ -171,8 +171,8 @@ int ExecModule::Prepare() {
// Dump pre-optimized module to disk.
if (FLAGS_dump_module_bitcode) {
xesnprintf(file_name, XECOUNT(file_name),
"%s%s-preopt.bc", FLAGS_dump_path.c_str(), module_name_);
xesnprintfa(file_name, XECOUNT(file_name),
"%s%s-preopt.bc", FLAGS_dump_path.c_str(), module_name_);
outs = auto_ptr<raw_ostream>(new raw_fd_ostream(
file_name, error_message, raw_fd_ostream::F_Binary));
XEEXPECTTRUE(error_message.empty());
@@ -203,8 +203,8 @@ int ExecModule::Prepare() {
// Dump post-optimized module to disk.
if (FLAGS_optimize_ir_modules && FLAGS_dump_module_bitcode) {
xesnprintf(file_name, XECOUNT(file_name),
"%s%s.bc", FLAGS_dump_path.c_str(), module_name_);
xesnprintfa(file_name, XECOUNT(file_name),
"%s%s.bc", FLAGS_dump_path.c_str(), module_name_);
outs = auto_ptr<raw_ostream>(new raw_fd_ostream(
file_name, error_message, raw_fd_ostream::F_Binary));
XEEXPECTTRUE(error_message.empty());
@@ -397,7 +397,7 @@ int ExecModule::Init() {
} else {
// Not implemented - write with a dummy value.
*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);
}
}
@@ -411,7 +411,7 @@ int ExecModule::Init() {
std::vector<GenericValue> args;
GenericValue ret = engine_->runFunction(xe_module_init, args);
return ret.IntVal.getSExtValue();
return static_cast<int>(ret.IntVal.getSExtValue());
}
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) {
name += "o";
special_registers.push_back((InstrRegister){
InstrRegister i = {
InstrRegister::kXER, 0, InstrRegister::kReadWrite
});
};
special_registers.push_back(i);
}
if (flags & InstrDisasm::kRc) {
name += ".";
special_registers.push_back((InstrRegister){
InstrRegister i = {
InstrRegister::kCR, 0, InstrRegister::kWrite
});
};
special_registers.push_back(i);
}
if (flags & InstrDisasm::kCA) {
special_registers.push_back((InstrRegister){
InstrRegister i = {
InstrRegister::kXER, 0, InstrRegister::kReadWrite
});
};
special_registers.push_back(i);
}
if (flags & InstrDisasm::kLR) {
name += "l";
special_registers.push_back((InstrRegister){
InstrRegister i = {
InstrRegister::kLR, 0, InstrRegister::kWrite
});
};
special_registers.push_back(i);
}
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) {
special_registers.push_back((InstrRegister){
InstrRegister i = {
InstrRegister::kLR, 0, access
});
};
special_registers.push_back(i);
}
void InstrDisasm::AddCTR(InstrRegister::Access access) {
special_registers.push_back((InstrRegister){
InstrRegister i = {
InstrRegister::kCTR, 0, access
});
};
special_registers.push_back(i);
}
void InstrDisasm::AddCR(uint32_t bf, InstrRegister::Access access) {
special_registers.push_back((InstrRegister){
InstrRegister i = {
InstrRegister::kCR, bf, access
});
};
special_registers.push_back(i);
}
void InstrDisasm::AddRegOperand(
InstrRegister::RegisterSet set, uint32_t ordinal,
InstrRegister::Access access, std::string display) {
InstrOperand o;
o.type = InstrOperand::kRegister;
o.reg = (InstrRegister){
InstrRegister i = {
set, ordinal, access
};
InstrOperand o;
o.type = InstrOperand::kRegister;
o.reg = i;
if (!display.size()) {
std::stringstream display_out;
switch (set) {

View File

@@ -21,7 +21,7 @@ namespace tables {
static InstrType* instr_table_prep(
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));
for (int n = 0; n < unprep_count; n++) {
int ordinal = XESELECTBITS(unprep[n].opcode, a, b);

View File

@@ -15,7 +15,7 @@
namespace {
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,
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(
memory_, export_resolver, user_module->name(), user_module->path(),
memory_, export_resolver, name_a, path_a,
engine_);
if (exec_module->PrepareUserModule(user_module)) {
@@ -173,7 +177,7 @@ int Processor::Execute(ThreadState* thread_state, uint32_t address) {
// Find the function to execute.
Function* f = GetFunction(address);
if (!f) {
XELOGCPU("Failed to find function %.8X to execute.\n", address);
XELOGCPU(XT("Failed to find function %.8X to execute."), address);
return 1;
}

View File

@@ -173,7 +173,7 @@ FunctionSymbol* SymbolDatabase::GetOrInsertFunction(uint32_t address) {
// Ignore values outside of the .text range.
if (!IsValueInTextRange(address)) {
XELOGSDB("Ignoring function outside of .text: %.8X\n", address);
XELOGSDB(XT("Ignoring function outside of .text: %.8X"), address);
return NULL;
}
@@ -340,7 +340,7 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
if (*((uint32_t*)(p + fn->start_address)) == 0) {
// 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);
if (!GetFunction(fn->start_address + 4)) {
fn->start_address += 4;
@@ -352,13 +352,13 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
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.
if (!fn->name) {
char name[32];
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.
@@ -378,13 +378,13 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
// If we fetched 0 assume that we somehow hit one of the awesome
// 'no really we meant to end after that bl' functions.
if (!i.code) {
XELOGSDB("function end %.8X (0x00000000 read)\n", addr);
XELOGSDB(XT("function end %.8X (0x00000000 read)"), addr);
break;
}
if (!i.type) {
// Invalid instruction.
XELOGSDB("Invalid instruction at %.8X: %.8X\n", addr, i.code);
XELOGSDB(XT("Invalid instruction at %.8X: %.8X"), addr, i.code);
return 1;
}
@@ -405,10 +405,10 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
block->outgoing_type = FunctionBlock::kTargetLR;
if (furthest_target > addr) {
// 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 {
// Function end point.
XELOGSDB("function end %.8X\n", addr);
XELOGSDB(XT("function end %.8X"), addr);
ends_fn = true;
}
ends_block = true;
@@ -418,11 +418,11 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
block->outgoing_type = FunctionBlock::kTargetCTR;
if (furthest_target > addr) {
// 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);
} else {
// Function end point.
XELOGSDB("function end %.8X\n", addr);
XELOGSDB(XT("function end %.8X"), addr);
ends_fn = true;
}
ends_block = true;
@@ -432,17 +432,17 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
block->outgoing_address = target;
if (i.I.LK) {
XELOGSDB("bl %.8X -> %.8X\n", addr, target);
XELOGSDB(XT("bl %.8X -> %.8X"), addr, target);
// Queue call target if needed.
GetOrInsertFunction(target);
} 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
// we are at the end of a function.
if (target >= fn->start_address &&
target < addr && furthest_target <= addr) {
XELOGSDB("function end %.8X (back b)\n", addr);
XELOGSDB(XT("function end %.8X (back b)"), addr);
ends_fn = true;
}
@@ -452,7 +452,7 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
// it.
if (!ends_fn &&
furthest_target <= addr && IsRestGprLr(target)) {
XELOGSDB("function end %.8X (__restgprlr_*)\n", addr);
XELOGSDB(XT("function end %.8X (__restgprlr_*)"), addr);
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);
block->outgoing_address = target;
if (i.B.LK) {
XELOGSDB("bcl %.8X -> %.8X\n", addr, target);
XELOGSDB(XT("bcl %.8X -> %.8X"), addr, target);
} else {
XELOGSDB("bc %.8X -> %.8X\n", addr, target);
XELOGSDB(XT("bc %.8X -> %.8X"), addr, target);
furthest_target = MAX(furthest_target, target);
}
@@ -477,18 +477,18 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
// bclr/bclrl
block->outgoing_type = FunctionBlock::kTargetLR;
if (i.XL.LK) {
XELOGSDB("bclrl %.8X\n", addr);
XELOGSDB(XT("bclrl %.8X"), addr);
} else {
XELOGSDB("bclr %.8X\n", addr);
XELOGSDB(XT("bclr %.8X"), addr);
}
ends_block = true;
} else if (i.type->opcode == 0x4C000420) {
// bcctr/bcctrl
block->outgoing_type = FunctionBlock::kTargetCTR;
if (i.XL.LK) {
XELOGSDB("bcctrl %.8X\n", addr);
XELOGSDB(XT("bcctrl %.8X"), addr);
} else {
XELOGSDB("bcctr %.8X\n", addr);
XELOGSDB(XT("bcctr %.8X"), addr);
}
ends_block = true;
}
@@ -508,8 +508,8 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
addr += 4;
if (fn->end_address && addr > fn->end_address) {
// Hmm....
XELOGSDB("Ran over function bounds! %.8X-%.8X\n",
fn->start_address, fn->end_address);
XELOGSDB(XT("Ran over function bounds! %.8X-%.8X"),
fn->start_address, fn->end_address);
break;
}
}
@@ -519,7 +519,7 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
// 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
// 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->end_address = addr;
@@ -532,7 +532,7 @@ int SymbolDatabase::AnalyzeFunction(FunctionSymbol* fn) {
// - if present, flag function as needing a stack
// - 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;
}
@@ -573,10 +573,12 @@ int SymbolDatabase::CompleteFunctionGraph(FunctionSymbol* fn) {
return 0;
}
namespace {
typedef struct {
uint32_t start_address;
uint32_t end_address;
} HoleInfo;
}
bool SymbolDatabase::FillHoles() {
// If 4b, check if 0x00000000 and ignore (alignment padding)
@@ -611,11 +613,13 @@ bool SymbolDatabase::FillHoles() {
ees.push_back(previous);
} else {
// Probably legit.
holes.push_back((HoleInfo){previous, fn->start_address});
HoleInfo hole_info = {previous, fn->start_address};
holes.push_back(hole_info);
}
} else {
// 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;
@@ -666,7 +670,7 @@ int SymbolDatabase::FlushQueue() {
FunctionSymbol* fn = scan_queue_.front();
scan_queue_.pop_front();
if (AnalyzeFunction(fn)) {
XELOGSDB("Aborting analysis!\n");
XELOGSDB(XT("Aborting analysis!"));
return 1;
}
}
@@ -806,7 +810,7 @@ int XexSymbolDatabase::FindGplr() {
char name[32];
uint32_t address = gplr_start;
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);
fn->end_address = fn->start_address + (31 - n) * 4 + 2 * 4;
fn->name = xestrdupa(name);
@@ -816,7 +820,7 @@ int XexSymbolDatabase::FindGplr() {
}
address = gplr_start + 20 * 4;
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);
fn->end_address = fn->start_address + (31 - n) * 4 + 3 * 4;
fn->name = xestrdupa(name);

View File

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

View File

@@ -22,6 +22,7 @@ namespace xbdm {
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));
// 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(
name, path, start_address, start_address + length, export_resolver_));
name_a, path_a, start_address, start_address + length,
export_resolver_));
result_code = 0;
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);
XEASSERT(count <= max_count);
if (count > max_count) {
XELOGW(XT("ignoring %zu extra entries in "
"XEX_HEADER_IMPORT_LIBRARIES"), (max_count - count));
XELOGW(XT("ignoring %zu extra entries in ")
XT("XEX_HEADER_IMPORT_LIBRARIES"), (max_count - count));
count = max_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;
XEASSERT(count <= max_count);
if (count > max_count) {
XELOGW(XT("ignoring %zu extra entries in "
"XEX_HEADER_STATIC_LIBRARIES"), (max_count - count));
XELOGW(XT("ignoring %zu extra entries in ")
XT("XEX_HEADER_STATIC_LIBRARIES"), (max_count - count));
count = max_count;
}
header->static_library_count = count;