STFS loading... xex's load, but files seem broken. Ugh.

This commit is contained in:
Ben Vanik
2014-01-18 22:23:26 -08:00
parent 69320ed94b
commit 6b633e4e28
24 changed files with 1049 additions and 29 deletions

View File

@@ -11,6 +11,7 @@
#include <xenia/emulator.h>
#include <xenia/cpu/cpu.h>
#include <xenia/kernel/objects/xfile.h>
#include <xenia/kernel/objects/xthread.h>
@@ -37,32 +38,66 @@ const xe_xex2_header_t* XUserModule::xex_header() {
}
X_STATUS XUserModule::LoadFromFile(const char* path) {
X_STATUS result = X_STATUS_UNSUCCESSFUL;
XFile* file = NULL;
uint8_t* buffer = 0;
// Resolve the file to open.
// TODO(benvanik): make this code shared?
fs::Entry* fs_entry = kernel_state()->file_system()->ResolvePath(path);
if (!fs_entry) {
XELOGE("File not found: %s", path);
return X_STATUS_NO_SUCH_FILE;
result = X_STATUS_NO_SUCH_FILE;
XEFAIL();
}
if (fs_entry->type() != fs::Entry::kTypeFile) {
XELOGE("Invalid file type: %s", path);
return X_STATUS_NO_SUCH_FILE;
result = X_STATUS_NO_SUCH_FILE;
XEFAIL();
}
// Map into memory.
fs::MemoryMapping* mmap = fs_entry->CreateMemoryMapping(kXEFileModeRead, 0, 0);
if (!mmap) {
return X_STATUS_UNSUCCESSFUL;
// If the FS supports mapping, map the file in and load from that.
if (fs_entry->can_map()) {
// Map.
fs::MemoryMapping* mmap = fs_entry->CreateMemoryMapping(kXEFileModeRead, 0, 0);
XEEXPECTNOTNULL(mmap);
// Load the module.
result = LoadFromMemory(mmap->address(), mmap->length());
// Unmap memory and cleanup.
delete mmap;
} else {
XFileInfo file_info;
result = fs_entry->QueryInfo(&file_info);
XEEXPECTZERO(result);
size_t buffer_length = file_info.file_length;
buffer = (uint8_t*)xe_malloc(buffer_length);
// Open file for reading.
result = fs_entry->Open(kernel_state(), kXEFileModeRead, false, &file);
XEEXPECTZERO(result);
// Read entire file into memory.
// Ugh.
size_t bytes_read = 0;
result = file->Read(buffer, buffer_length, 0, &bytes_read);
XEEXPECTZERO(result);
// Load the module.
result = LoadFromMemory(buffer, bytes_read);
}
// Load the module.
X_STATUS return_code = LoadFromMemory(mmap->address(), mmap->length());
// Unmap memory and cleanup.
delete mmap;
XECLEANUP:
if (buffer) {
xe_free(buffer);
}
if (file) {
file->Release();
}
delete fs_entry;
return return_code;
return result;
}
X_STATUS XUserModule::LoadFromMemory(const void* addr, const size_t length) {