Moving byte order/memory access to poly.

This commit is contained in:
Ben Vanik
2014-07-17 19:20:17 -07:00
parent ce70978ef6
commit ec4f41fec4
42 changed files with 608 additions and 486 deletions

View File

@@ -122,8 +122,8 @@ GDFX::Error GDFX::Verify(ParseState& state) {
return kErrorReadError;
}
uint8_t* fs_ptr = state.ptr + state.game_offset + (32 * kXESectorSize);
state.root_sector = XEGETUINT32LE(fs_ptr + 20);
state.root_size = XEGETUINT32LE(fs_ptr + 24);
state.root_sector = poly::load<uint32_t>(fs_ptr + 20);
state.root_size = poly::load<uint32_t>(fs_ptr + 24);
state.root_offset = state.game_offset + (state.root_sector * kXESectorSize);
if (state.root_size < 13 ||
state.root_size > 32 * 1024 * 1024) {
@@ -157,12 +157,12 @@ bool GDFX::ReadEntry(ParseState& state, const uint8_t* buffer,
uint16_t entry_ordinal, GDFXEntry* parent) {
const uint8_t* p = buffer + (entry_ordinal * 4);
uint16_t node_l = XEGETUINT16LE(p + 0);
uint16_t node_r = XEGETUINT16LE(p + 2);
size_t sector = XEGETUINT32LE(p + 4);
size_t length = XEGETUINT32LE(p + 8);
uint8_t attributes = XEGETUINT8LE(p + 12);
uint8_t name_length = XEGETUINT8LE(p + 13);
uint16_t node_l = poly::load<uint16_t>(p + 0);
uint16_t node_r = poly::load<uint16_t>(p + 2);
size_t sector = poly::load<uint32_t>(p + 4);
size_t length = poly::load<uint32_t>(p + 8);
uint8_t attributes = poly::load<uint8_t>(p + 12);
uint8_t name_length = poly::load<uint8_t>(p + 13);
char* name = (char*)(p + 14);
if (node_l && !ReadEntry(state, buffer, node_l, parent)) {

View File

@@ -16,21 +16,29 @@ using namespace xe;
using namespace xe::kernel;
using namespace xe::kernel::fs;
#define XEGETUINT24BE(p) \
(((uint32_t)poly::load_and_swap<uint8_t>((p) + 0) << 16) | \
((uint32_t)poly::load_and_swap<uint8_t>((p) + 1) << 8) | \
(uint32_t)poly::load_and_swap<uint8_t>((p) + 2))
#define XEGETUINT24LE(p) \
(((uint32_t)poly::load<uint8_t>((p) + 2) << 16) | \
((uint32_t)poly::load<uint8_t>((p) + 1) << 8) | \
(uint32_t)poly::load<uint8_t>((p) + 0))
bool STFSVolumeDescriptor::Read(const uint8_t* p) {
descriptor_size = XEGETUINT8BE(p + 0x00);
descriptor_size = poly::load_and_swap<uint8_t>(p + 0x00);
if (descriptor_size != 0x24) {
XELOGE("STFS volume descriptor size mismatch, expected 0x24 but got 0x%X",
descriptor_size);
return false;
}
reserved = XEGETUINT8BE(p + 0x01);
block_separation = XEGETUINT8BE(p + 0x02);
file_table_block_count = XEGETUINT16BE(p + 0x03);
reserved = poly::load_and_swap<uint8_t>(p + 0x01);
block_separation = poly::load_and_swap<uint8_t>(p + 0x02);
file_table_block_count = poly::load_and_swap<uint16_t>(p + 0x03);
file_table_block_number = XEGETUINT24BE(p + 0x05);
xe_copy_struct(top_hash_table_hash, p + 0x08, 0x14);
total_allocated_block_count = XEGETUINT32BE(p + 0x1C);
total_unallocated_block_count = XEGETUINT32BE(p + 0x20);
total_allocated_block_count = poly::load_and_swap<uint32_t>(p + 0x1C);
total_unallocated_block_count = poly::load_and_swap<uint32_t>(p + 0x20);
return true;
};
@@ -38,29 +46,29 @@ bool STFSVolumeDescriptor::Read(const uint8_t* p) {
bool STFSHeader::Read(const uint8_t* p) {
xe_copy_struct(license_entries, p + 0x22C, 0x100);
xe_copy_struct(header_hash, p + 0x32C, 0x14);
header_size = XEGETUINT32BE(p + 0x340);
content_type = (STFSContentType)XEGETUINT32BE(p + 0x344);
metadata_version = XEGETUINT32BE(p + 0x348);
header_size = poly::load_and_swap<uint32_t>(p + 0x340);
content_type = (STFSContentType)poly::load_and_swap<uint32_t>(p + 0x344);
metadata_version = poly::load_and_swap<uint32_t>(p + 0x348);
if (metadata_version > 1) {
// This is a variant of thumbnail data/etc.
// Can just ignore it for now (until we parse thumbnails).
XELOGW("STFSContainer doesn't support version %d yet", metadata_version);
}
content_size = XEGETUINT32BE(p + 0x34C);
media_id = XEGETUINT32BE(p + 0x354);
version = XEGETUINT32BE(p + 0x358);
base_version = XEGETUINT32BE(p + 0x35C);
title_id = XEGETUINT32BE(p + 0x360);
platform = (STFSPlatform)XEGETUINT8BE(p + 0x364);
executable_type = XEGETUINT8BE(p + 0x365);
disc_number = XEGETUINT8BE(p + 0x366);
disc_in_set = XEGETUINT8BE(p + 0x367);
save_game_id = XEGETUINT32BE(p + 0x368);
content_size = poly::load_and_swap<uint32_t>(p + 0x34C);
media_id = poly::load_and_swap<uint32_t>(p + 0x354);
version = poly::load_and_swap<uint32_t>(p + 0x358);
base_version = poly::load_and_swap<uint32_t>(p + 0x35C);
title_id = poly::load_and_swap<uint32_t>(p + 0x360);
platform = (STFSPlatform)poly::load_and_swap<uint8_t>(p + 0x364);
executable_type = poly::load_and_swap<uint8_t>(p + 0x365);
disc_number = poly::load_and_swap<uint8_t>(p + 0x366);
disc_in_set = poly::load_and_swap<uint8_t>(p + 0x367);
save_game_id = poly::load_and_swap<uint32_t>(p + 0x368);
xe_copy_struct(console_id, p + 0x36C, 0x5);
xe_copy_struct(profile_id, p + 0x371, 0x8);
data_file_count = XEGETUINT32BE(p + 0x39D);
data_file_combined_size = XEGETUINT64BE(p + 0x3A1);
descriptor_type = (STFSDescriptorType)XEGETUINT8BE(p + 0x3A9);
data_file_count = poly::load_and_swap<uint32_t>(p + 0x39D);
data_file_combined_size = poly::load_and_swap<uint64_t>(p + 0x3A1);
descriptor_type = (STFSDescriptorType)poly::load_and_swap<uint8_t>(p + 0x3A9);
if (descriptor_type != STFS_DESCRIPTOR_STFS) {
XELOGE("STFS descriptor format not supported: %d", descriptor_type);
return false;
@@ -70,16 +78,16 @@ bool STFSHeader::Read(const uint8_t* p) {
}
xe_copy_struct(device_id, p + 0x3FD, 0x14);
for (size_t n = 0; n < 0x900 / 2; n++) {
display_names[n] = XEGETUINT16BE(p + 0x411 + n * 2);
display_descs[n] = XEGETUINT16BE(p + 0xD11 + n * 2);
display_names[n] = poly::load_and_swap<uint16_t>(p + 0x411 + n * 2);
display_descs[n] = poly::load_and_swap<uint16_t>(p + 0xD11 + n * 2);
}
for (size_t n = 0; n < 0x80 / 2; n++) {
publisher_name[n] = XEGETUINT16BE(p + 0x1611 + n * 2);
title_name[n] = XEGETUINT16BE(p + 0x1691 + n * 2);
publisher_name[n] = poly::load_and_swap<uint16_t>(p + 0x1611 + n * 2);
title_name[n] = poly::load_and_swap<uint16_t>(p + 0x1691 + n * 2);
}
transfer_flags = XEGETUINT8BE(p + 0x1711);
thumbnail_image_size = XEGETUINT32BE(p + 0x1712);
title_thumbnail_image_size = XEGETUINT32BE(p + 0x1716);
transfer_flags = poly::load_and_swap<uint8_t>(p + 0x1711);
thumbnail_image_size = poly::load_and_swap<uint32_t>(p + 0x1712);
title_thumbnail_image_size = poly::load_and_swap<uint32_t>(p + 0x1716);
xe_copy_struct(thumbnail_image, p + 0x171A, 0x4000);
xe_copy_struct(title_thumbnail_image, p + 0x571A, 0x4000);
return true;
@@ -203,13 +211,13 @@ STFS::Error STFS::ReadAllEntries(const uint8_t* map_ptr) {
// Done.
break;
}
uint8_t filename_length_flags = XEGETUINT8BE(p + 0x28);
uint8_t filename_length_flags = poly::load_and_swap<uint8_t>(p + 0x28);
uint32_t allocated_block_count = XEGETUINT24LE(p + 0x29);
uint32_t start_block_index = XEGETUINT24LE(p + 0x2F);
uint16_t path_indicator = XEGETUINT16BE(p + 0x32);
uint32_t file_size = XEGETUINT32BE(p + 0x34);
uint32_t update_timestamp = XEGETUINT32BE(p + 0x38);
uint32_t access_timestamp = XEGETUINT32BE(p + 0x3C);
uint16_t path_indicator = poly::load_and_swap<uint16_t>(p + 0x32);
uint32_t file_size = poly::load_and_swap<uint32_t>(p + 0x34);
uint32_t update_timestamp = poly::load_and_swap<uint32_t>(p + 0x38);
uint32_t access_timestamp = poly::load_and_swap<uint32_t>(p + 0x3C);
p += 0x40;
STFSEntry* entry = new STFSEntry();
@@ -337,7 +345,7 @@ STFS::BlockHash_t STFS::GetBlockHash(
//table_index += table_offset - (1 << table_size_shift_);
const uint8_t* hash_data = map_ptr + BlockToOffset(table_index);
const uint8_t* record_data = hash_data + record * 0x18;
uint32_t info = XEGETUINT8BE(record_data + 0x14);
uint32_t info = poly::load_and_swap<uint8_t>(record_data + 0x14);
uint32_t next_block_index = XEGETUINT24BE(record_data + 0x15);
return{ next_block_index, info };
}

View File

@@ -21,40 +21,40 @@ NativeList::NativeList(Memory* memory) :
void NativeList::Insert(uint32_t ptr) {
uint8_t* mem = memory_->membase();
XESETUINT32BE(mem + ptr + 0, head_);
XESETUINT32BE(mem + ptr + 4, 0);
poly::store_and_swap<uint32_t>(mem + ptr + 0, head_);
poly::store_and_swap<uint32_t>(mem + ptr + 4, 0);
if (head_) {
XESETUINT32BE(mem + head_ + 4, ptr);
poly::store_and_swap<uint32_t>(mem + head_ + 4, ptr);
}
head_ = ptr;
}
bool NativeList::IsQueued(uint32_t ptr) {
uint8_t* mem = memory_->membase();
uint32_t flink = XEGETUINT32BE(mem + ptr + 0);
uint32_t blink = XEGETUINT32BE(mem + ptr + 4);
uint32_t flink = poly::load_and_swap<uint32_t>(mem + ptr + 0);
uint32_t blink = poly::load_and_swap<uint32_t>(mem + ptr + 4);
return head_ == ptr || flink || blink;
}
void NativeList::Remove(uint32_t ptr) {
uint8_t* mem = memory_->membase();
uint32_t flink = XEGETUINT32BE(mem + ptr + 0);
uint32_t blink = XEGETUINT32BE(mem + ptr + 4);
uint32_t flink = poly::load_and_swap<uint32_t>(mem + ptr + 0);
uint32_t blink = poly::load_and_swap<uint32_t>(mem + ptr + 4);
if (ptr == head_) {
head_ = flink;
if (flink) {
XESETUINT32BE(mem + flink + 4, 0);
poly::store_and_swap<uint32_t>(mem + flink + 4, 0);
}
} else {
if (blink) {
XESETUINT32BE(mem + blink + 0, flink);
poly::store_and_swap<uint32_t>(mem + blink + 0, flink);
}
if (flink) {
XESETUINT32BE(mem + flink + 4, blink);
poly::store_and_swap<uint32_t>(mem + flink + 4, blink);
}
}
XESETUINT32BE(mem + ptr + 0, 0);
XESETUINT32BE(mem + ptr + 4, 0);
poly::store_and_swap<uint32_t>(mem + ptr + 0, 0);
poly::store_and_swap<uint32_t>(mem + ptr + 4, 0);
}
uint32_t NativeList::Shift() {

View File

@@ -33,14 +33,14 @@ public:
X_FILE_ATTRIBUTES attributes;
void Write(uint8_t* base, uint32_t p) {
XESETUINT64BE(base + p, creation_time);
XESETUINT64BE(base + p + 8, last_access_time);
XESETUINT64BE(base + p + 16, last_write_time);
XESETUINT64BE(base + p + 24, change_time);
XESETUINT64BE(base + p + 32, allocation_size);
XESETUINT64BE(base + p + 40, file_length);
XESETUINT32BE(base + p + 48, attributes);
XESETUINT32BE(base + p + 52, 0); // pad
poly::store_and_swap<uint64_t>(base + p, creation_time);
poly::store_and_swap<uint64_t>(base + p + 8, last_access_time);
poly::store_and_swap<uint64_t>(base + p + 16, last_write_time);
poly::store_and_swap<uint64_t>(base + p + 24, change_time);
poly::store_and_swap<uint64_t>(base + p + 32, allocation_size);
poly::store_and_swap<uint64_t>(base + p + 40, file_length);
poly::store_and_swap<uint32_t>(base + p + 48, attributes);
poly::store_and_swap<uint32_t>(base + p + 52, 0); // pad
}
};
@@ -65,16 +65,16 @@ public:
XDirectoryInfo* info;
do {
info = (XDirectoryInfo*)src;
XESETUINT32BE(dst, info->next_entry_offset);
XESETUINT32BE(dst + 4, info->file_index);
XESETUINT64BE(dst + 8, info->creation_time);
XESETUINT64BE(dst + 16, info->last_access_time);
XESETUINT64BE(dst + 24, info->last_write_time);
XESETUINT64BE(dst + 32, info->change_time);
XESETUINT64BE(dst + 40, info->end_of_file);
XESETUINT64BE(dst + 48, info->allocation_size);
XESETUINT32BE(dst + 56, info->attributes);
XESETUINT32BE(dst + 60, info->file_name_length);
poly::store_and_swap<uint32_t>(dst, info->next_entry_offset);
poly::store_and_swap<uint32_t>(dst + 4, info->file_index);
poly::store_and_swap<uint64_t>(dst + 8, info->creation_time);
poly::store_and_swap<uint64_t>(dst + 16, info->last_access_time);
poly::store_and_swap<uint64_t>(dst + 24, info->last_write_time);
poly::store_and_swap<uint64_t>(dst + 32, info->change_time);
poly::store_and_swap<uint64_t>(dst + 40, info->end_of_file);
poly::store_and_swap<uint64_t>(dst + 48, info->allocation_size);
poly::store_and_swap<uint32_t>(dst + 56, info->attributes);
poly::store_and_swap<uint32_t>(dst + 60, info->file_name_length);
xe_copy_memory(dst + 64, info->file_name_length, info->file_name, info->file_name_length);
dst += info->next_entry_offset;
src += info->next_entry_offset;
@@ -95,10 +95,10 @@ public:
void Write(uint8_t* base, uint32_t p) {
uint8_t* dst = base + p;
XESETUINT64BE(dst + 0, this->creation_time);
XESETUINT32BE(dst + 8, this->serial_number);
XESETUINT32BE(dst + 12, this->label_length);
XESETUINT32BE(dst + 16, this->supports_objects);
poly::store_and_swap<uint64_t>(dst + 0, this->creation_time);
poly::store_and_swap<uint32_t>(dst + 8, this->serial_number);
poly::store_and_swap<uint32_t>(dst + 12, this->label_length);
poly::store_and_swap<uint32_t>(dst + 16, this->supports_objects);
xe_copy_memory(dst + 20, this->label_length, this->label, this->label_length);
}
};
@@ -115,9 +115,9 @@ public:
void Write(uint8_t* base, uint32_t p) {
uint8_t* dst = base + p;
XESETUINT32BE(dst + 0, this->attributes);
XESETUINT32BE(dst + 4, this->maximum_component_name_length);
XESETUINT32BE(dst + 8, this->fs_name_length);
poly::store_and_swap<uint32_t>(dst + 0, this->attributes);
poly::store_and_swap<uint32_t>(dst + 4, this->maximum_component_name_length);
poly::store_and_swap<uint32_t>(dst + 8, this->fs_name_length);
xe_copy_memory(dst + 12, this->fs_name_length, this->fs_name, this->fs_name_length);
}
};

View File

@@ -120,7 +120,7 @@ uint32_t XThread::GetCurrentThreadHandle() {
}
uint32_t XThread::GetCurrentThreadId(const uint8_t* thread_state_block) {
return XEGETUINT32BE(thread_state_block + 0x14C);
return poly::load_and_swap<uint32_t>(thread_state_block + 0x14C);
}
uint32_t XThread::thread_state() {
@@ -133,12 +133,12 @@ uint32_t XThread::thread_id() {
uint32_t XThread::last_error() {
uint8_t *p = memory()->Translate(thread_state_address_);
return XEGETUINT32BE(p + 0x160);
return poly::load_and_swap<uint32_t>(p + 0x160);
}
void XThread::set_last_error(uint32_t error_code) {
uint8_t *p = memory()->Translate(thread_state_address_);
XESETUINT32BE(p + 0x160, error_code);
poly::store_and_swap<uint32_t>(p + 0x160, error_code);
}
void XThread::set_name(const char* name) {
@@ -221,11 +221,11 @@ X_STATUS XThread::Create() {
// Setup the thread state block (last error/etc).
uint8_t *p = memory()->Translate(thread_state_address_);
XESETUINT32BE(p + 0x000, tls_address_);
XESETUINT32BE(p + 0x100, thread_state_address_);
XESETUINT32BE(p + 0x14C, thread_id_);
XESETUINT32BE(p + 0x150, 0); // ?
XESETUINT32BE(p + 0x160, 0); // last error
poly::store_and_swap<uint32_t>(p + 0x000, tls_address_);
poly::store_and_swap<uint32_t>(p + 0x100, thread_state_address_);
poly::store_and_swap<uint32_t>(p + 0x14C, thread_id_);
poly::store_and_swap<uint32_t>(p + 0x150, 0); // ?
poly::store_and_swap<uint32_t>(p + 0x160, 0); // last error
// Allocate processor thread state.
// This is thread safe.
@@ -440,25 +440,25 @@ void XThread::DeliverAPCs(void* data) {
// Calling the routine may delete the memory/overwrite it.
uint32_t apc_address = apc_list->Shift() - 8;
uint8_t* apc_ptr = membase + apc_address;
uint32_t kernel_routine = XEGETUINT32BE(apc_ptr + 16);
uint32_t normal_routine = XEGETUINT32BE(apc_ptr + 24);
uint32_t normal_context = XEGETUINT32BE(apc_ptr + 28);
uint32_t system_arg1 = XEGETUINT32BE(apc_ptr + 32);
uint32_t system_arg2 = XEGETUINT32BE(apc_ptr + 36);
uint32_t kernel_routine = poly::load_and_swap<uint32_t>(apc_ptr + 16);
uint32_t normal_routine = poly::load_and_swap<uint32_t>(apc_ptr + 24);
uint32_t normal_context = poly::load_and_swap<uint32_t>(apc_ptr + 28);
uint32_t system_arg1 = poly::load_and_swap<uint32_t>(apc_ptr + 32);
uint32_t system_arg2 = poly::load_and_swap<uint32_t>(apc_ptr + 36);
// Mark as uninserted so that it can be reinserted again by the routine.
uint32_t old_flags = XEGETUINT32BE(apc_ptr + 40);
XESETUINT32BE(apc_ptr + 40, old_flags & ~0xFF00);
uint32_t old_flags = poly::load_and_swap<uint32_t>(apc_ptr + 40);
poly::store_and_swap<uint32_t>(apc_ptr + 40, old_flags & ~0xFF00);
// Call kernel routine.
// The routine can modify all of its arguments before passing it on.
// Since we need to give guest accessible pointers over, we copy things
// into and out of scratch.
uint8_t* scratch_ptr = membase + thread->scratch_address_;
XESETUINT32BE(scratch_ptr + 0, normal_routine);
XESETUINT32BE(scratch_ptr + 4, normal_context);
XESETUINT32BE(scratch_ptr + 8, system_arg1);
XESETUINT32BE(scratch_ptr + 12, system_arg2);
poly::store_and_swap<uint32_t>(scratch_ptr + 0, normal_routine);
poly::store_and_swap<uint32_t>(scratch_ptr + 4, normal_context);
poly::store_and_swap<uint32_t>(scratch_ptr + 8, system_arg1);
poly::store_and_swap<uint32_t>(scratch_ptr + 12, system_arg2);
// kernel_routine(apc_address, &normal_routine, &normal_context, &system_arg1, &system_arg2)
uint64_t kernel_args[] = {
apc_address,
@@ -469,10 +469,10 @@ void XThread::DeliverAPCs(void* data) {
};
processor->ExecuteInterrupt(
0, kernel_routine, kernel_args, XECOUNT(kernel_args));
normal_routine = XEGETUINT32BE(scratch_ptr + 0);
normal_context = XEGETUINT32BE(scratch_ptr + 4);
system_arg1 = XEGETUINT32BE(scratch_ptr + 8);
system_arg2 = XEGETUINT32BE(scratch_ptr + 12);
normal_routine = poly::load_and_swap<uint32_t>(scratch_ptr + 0);
normal_context = poly::load_and_swap<uint32_t>(scratch_ptr + 4);
system_arg1 = poly::load_and_swap<uint32_t>(scratch_ptr + 8);
system_arg2 = poly::load_and_swap<uint32_t>(scratch_ptr + 12);
// Call the normal routine. Note that it may have been killed by the kernel
// routine.
@@ -496,11 +496,11 @@ void XThread::RundownAPCs() {
// Calling the routine may delete the memory/overwrite it.
uint32_t apc_address = apc_list_->Shift() - 8;
uint8_t* apc_ptr = membase + apc_address;
uint32_t rundown_routine = XEGETUINT32BE(apc_ptr + 20);
uint32_t rundown_routine = poly::load_and_swap<uint32_t>(apc_ptr + 20);
// Mark as uninserted so that it can be reinserted again by the routine.
uint32_t old_flags = XEGETUINT32BE(apc_ptr + 40);
XESETUINT32BE(apc_ptr + 40, old_flags & ~0xFF00);
uint32_t old_flags = poly::load_and_swap<uint32_t>(apc_ptr + 40);
poly::store_and_swap<uint32_t>(apc_ptr + 40, old_flags & ~0xFF00);
// Call the rundown routine.
if (rundown_routine) {

View File

@@ -35,15 +35,15 @@ using PPCContext = alloy::frontend::ppc::PPCContext;
#define SHIM_MEM_ADDR(a) (a ? (ppc_state->membase + a) : NULL)
#define SHIM_MEM_8(a) (*(uint8_t*)SHIM_MEM_ADDR(a))
#define SHIM_MEM_16(a) (uint16_t)XEGETUINT16BE(SHIM_MEM_ADDR(a))
#define SHIM_MEM_32(a) (uint32_t)XEGETUINT32BE(SHIM_MEM_ADDR(a))
#define SHIM_MEM_64(a) (uint64_t)XEGETUINT64BE(SHIM_MEM_ADDR(a))
#define SHIM_MEM_16(a) (uint16_t)poly::load_and_swap<uint16_t>(SHIM_MEM_ADDR(a))
#define SHIM_MEM_32(a) (uint32_t)poly::load_and_swap<uint32_t>(SHIM_MEM_ADDR(a))
#define SHIM_MEM_64(a) (uint64_t)poly::load_and_swap<uint64_t>(SHIM_MEM_ADDR(a))
#define SHIM_SET_MEM_8(a, v) (*(uint8_t*)SHIM_MEM_ADDR(a)) = v
#define SHIM_SET_MEM_16(a, v) (*(uint16_t*)SHIM_MEM_ADDR(a)) = XESWAP16(v)
#define SHIM_SET_MEM_32(a, v) (*(uint32_t*)SHIM_MEM_ADDR(a)) = XESWAP32(v)
#define SHIM_SET_MEM_64(a, v) (*(uint64_t*)SHIM_MEM_ADDR(a)) = XESWAP64(v)
#define SHIM_SET_MEM_F32(a, v) (*(float*)SHIM_MEM_ADDR(a)) = XESWAPF32BE(v)
#define SHIM_SET_MEM_F64(a, v) (*(double*)SHIM_MEM_ADDR(a)) = XESWAPF64BE(v)
#define SHIM_SET_MEM_16(a, v) (*(uint16_t*)SHIM_MEM_ADDR(a)) = poly::byte_swap(v)
#define SHIM_SET_MEM_32(a, v) (*(uint32_t*)SHIM_MEM_ADDR(a)) = poly::byte_swap(v)
#define SHIM_SET_MEM_64(a, v) (*(uint64_t*)SHIM_MEM_ADDR(a)) = poly::byte_swap(v)
#define SHIM_SET_MEM_F32(a, v) (*(float*)SHIM_MEM_ADDR(a)) = poly::byte_swap(v)
#define SHIM_SET_MEM_F64(a, v) (*(double*)SHIM_MEM_ADDR(a)) = poly::byte_swap(v)
#define SHIM_GPR_8(n) (uint8_t)(ppc_state->r[n])
#define SHIM_GPR_16(n) (uint16_t)(ppc_state->r[n])
@@ -63,11 +63,11 @@ using PPCContext = alloy::frontend::ppc::PPCContext;
#define IMPL_MEM_ADDR(a) (a ? state->memory()->Translate(a) : NULL)
#define IMPL_MEM_8(a) (*(uint8_t*)(IMPL_MEM_ADDR(a)))
#define IMPL_MEM_16(a) (uint16_t)XEGETUINT16BE(IMPL_MEM_ADDR(a))
#define IMPL_MEM_32(a) (uint32_t)XEGETUINT32BE(IMPL_MEM_ADDR(a))
#define IMPL_MEM_16(a) (uint16_t)poly::load_and_swap<uint16_t>(IMPL_MEM_ADDR(a))
#define IMPL_MEM_32(a) (uint32_t)poly::load_and_swap<uint32_t>(IMPL_MEM_ADDR(a))
#define IMPL_SET_MEM_8(a, v) (*(uint8_t*)IMPL_MEM_ADDR(a)) = v
#define IMPL_SET_MEM_16(a, v) (*(uint16_t*)IMPL_MEM_ADDR(a)) = XESWAP16(v)
#define IMPL_SET_MEM_32(a, v) (*(uint32_t*)IMPL_MEM_ADDR(a)) = XESWAP32(v)
#define IMPL_SET_MEM_16(a, v) (*(uint16_t*)IMPL_MEM_ADDR(a)) = poly::byte_swap(v)
#define IMPL_SET_MEM_32(a, v) (*(uint32_t*)IMPL_MEM_ADDR(a)) = poly::byte_swap(v)
} // namespace kernel

View File

@@ -125,21 +125,21 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
const uint8_t *ps;
xe_xex2_loader_info_t *ldr;
header->xex2 = XEGETUINT32BE(p + 0x00);
header->xex2 = poly::load_and_swap<uint32_t>(p + 0x00);
if (header->xex2 != 0x58455832) {
return 1;
}
header->module_flags = (xe_xex2_module_flags)XEGETUINT32BE(p + 0x04);
header->exe_offset = XEGETUINT32BE(p + 0x08);
header->unknown0 = XEGETUINT32BE(p + 0x0C);
header->certificate_offset = XEGETUINT32BE(p + 0x10);
header->header_count = XEGETUINT32BE(p + 0x14);
header->module_flags = (xe_xex2_module_flags)poly::load_and_swap<uint32_t>(p + 0x04);
header->exe_offset = poly::load_and_swap<uint32_t>(p + 0x08);
header->unknown0 = poly::load_and_swap<uint32_t>(p + 0x0C);
header->certificate_offset = poly::load_and_swap<uint32_t>(p + 0x10);
header->header_count = poly::load_and_swap<uint32_t>(p + 0x14);
for (size_t n = 0; n < header->header_count; n++) {
const uint8_t *ph = p + 0x18 + (n * 8);
const uint32_t key = XEGETUINT32BE(ph + 0x00);
const uint32_t data_offset = XEGETUINT32BE(ph + 0x04);
const uint32_t key = poly::load_and_swap<uint32_t>(ph + 0x00);
const uint32_t data_offset = poly::load_and_swap<uint32_t>(ph + 0x04);
xe_xex2_opt_header_t *opt_header = &header->headers[n];
opt_header->key = key;
@@ -151,7 +151,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
break;
case 0xFF:
// dataOffset = offset (first dword in data is size)
opt_header->length = XEGETUINT32BE(p + data_offset);
opt_header->length = poly::load_and_swap<uint32_t>(p + data_offset);
opt_header->offset = data_offset;
break;
default:
@@ -176,8 +176,8 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
auto& res = header->resource_infos[n];
XEEXPECTZERO(xe_copy_memory(res.name,
sizeof(res.name), ph + 0x00, 8));
res.address = XEGETUINT32BE(ph + 0x08);
res.size = XEGETUINT32BE(ph + 0x0C);
res.address = poly::load_and_swap<uint32_t>(ph + 0x08);
res.size = poly::load_and_swap<uint32_t>(ph + 0x0C);
ph += 16;
}
}
@@ -185,41 +185,41 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
case XEX_HEADER_EXECUTION_INFO:
{
xe_xex2_execution_info_t *ex = &header->execution_info;
ex->media_id = XEGETUINT32BE(pp + 0x00);
ex->version.value = XEGETUINT32BE(pp + 0x04);
ex->base_version.value = XEGETUINT32BE(pp + 0x08);
ex->title_id = XEGETUINT32BE(pp + 0x0C);
ex->platform = XEGETUINT8BE(pp + 0x10);
ex->executable_table = XEGETUINT8BE(pp + 0x11);
ex->disc_number = XEGETUINT8BE(pp + 0x12);
ex->disc_count = XEGETUINT8BE(pp + 0x13);
ex->savegame_id = XEGETUINT32BE(pp + 0x14);
ex->media_id = poly::load_and_swap<uint32_t>(pp + 0x00);
ex->version.value = poly::load_and_swap<uint32_t>(pp + 0x04);
ex->base_version.value = poly::load_and_swap<uint32_t>(pp + 0x08);
ex->title_id = poly::load_and_swap<uint32_t>(pp + 0x0C);
ex->platform = poly::load_and_swap<uint8_t>(pp + 0x10);
ex->executable_table = poly::load_and_swap<uint8_t>(pp + 0x11);
ex->disc_number = poly::load_and_swap<uint8_t>(pp + 0x12);
ex->disc_count = poly::load_and_swap<uint8_t>(pp + 0x13);
ex->savegame_id = poly::load_and_swap<uint32_t>(pp + 0x14);
}
break;
case XEX_HEADER_GAME_RATINGS:
{
xe_xex2_game_ratings_t *ratings = &header->game_ratings;
ratings->esrb = (xe_xex2_rating_esrb_value)XEGETUINT8BE(pp + 0x00);
ratings->pegi = (xe_xex2_rating_pegi_value)XEGETUINT8BE(pp + 0x01);
ratings->pegifi = (xe_xex2_rating_pegi_fi_value)XEGETUINT8BE(pp + 0x02);
ratings->pegipt = (xe_xex2_rating_pegi_pt_value)XEGETUINT8BE(pp + 0x03);
ratings->bbfc = (xe_xex2_rating_bbfc_value)XEGETUINT8BE(pp + 0x04);
ratings->cero = (xe_xex2_rating_cero_value)XEGETUINT8BE(pp + 0x05);
ratings->usk = (xe_xex2_rating_usk_value)XEGETUINT8BE(pp + 0x06);
ratings->oflcau = (xe_xex2_rating_oflc_au_value)XEGETUINT8BE(pp + 0x07);
ratings->oflcnz = (xe_xex2_rating_oflc_nz_value)XEGETUINT8BE(pp + 0x08);
ratings->kmrb = (xe_xex2_rating_kmrb_value)XEGETUINT8BE(pp + 0x09);
ratings->brazil = (xe_xex2_rating_brazil_value)XEGETUINT8BE(pp + 0x0A);
ratings->fpb = (xe_xex2_rating_fpb_value)XEGETUINT8BE(pp + 0x0B);
ratings->esrb = (xe_xex2_rating_esrb_value)poly::load_and_swap<uint8_t>(pp + 0x00);
ratings->pegi = (xe_xex2_rating_pegi_value)poly::load_and_swap<uint8_t>(pp + 0x01);
ratings->pegifi = (xe_xex2_rating_pegi_fi_value)poly::load_and_swap<uint8_t>(pp + 0x02);
ratings->pegipt = (xe_xex2_rating_pegi_pt_value)poly::load_and_swap<uint8_t>(pp + 0x03);
ratings->bbfc = (xe_xex2_rating_bbfc_value)poly::load_and_swap<uint8_t>(pp + 0x04);
ratings->cero = (xe_xex2_rating_cero_value)poly::load_and_swap<uint8_t>(pp + 0x05);
ratings->usk = (xe_xex2_rating_usk_value)poly::load_and_swap<uint8_t>(pp + 0x06);
ratings->oflcau = (xe_xex2_rating_oflc_au_value)poly::load_and_swap<uint8_t>(pp + 0x07);
ratings->oflcnz = (xe_xex2_rating_oflc_nz_value)poly::load_and_swap<uint8_t>(pp + 0x08);
ratings->kmrb = (xe_xex2_rating_kmrb_value)poly::load_and_swap<uint8_t>(pp + 0x09);
ratings->brazil = (xe_xex2_rating_brazil_value)poly::load_and_swap<uint8_t>(pp + 0x0A);
ratings->fpb = (xe_xex2_rating_fpb_value)poly::load_and_swap<uint8_t>(pp + 0x0B);
}
break;
case XEX_HEADER_TLS_INFO:
{
xe_xex2_tls_info_t *tls = &header->tls_info;
tls->slot_count = XEGETUINT32BE(pp + 0x00);
tls->raw_data_address = XEGETUINT32BE(pp + 0x04);
tls->data_size = XEGETUINT32BE(pp + 0x08);
tls->raw_data_size = XEGETUINT32BE(pp + 0x0C);
tls->slot_count = poly::load_and_swap<uint32_t>(pp + 0x00);
tls->raw_data_address = poly::load_and_swap<uint32_t>(pp + 0x04);
tls->data_size = poly::load_and_swap<uint32_t>(pp + 0x08);
tls->raw_data_size = poly::load_and_swap<uint32_t>(pp + 0x0C);
}
break;
case XEX_HEADER_IMAGE_BASE_ADDRESS:
@@ -237,7 +237,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
case XEX_HEADER_IMPORT_LIBRARIES:
{
const size_t max_count = XECOUNT(header->import_libraries);
size_t count = XEGETUINT32BE(pp + 0x08);
size_t count = poly::load_and_swap<uint32_t>(pp + 0x08);
assert_true(count <= max_count);
if (count > max_count) {
XELOGW("ignoring %zu extra entries in XEX_HEADER_IMPORT_LIBRARIES",
@@ -246,7 +246,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
}
header->import_library_count = count;
uint32_t string_table_size = XEGETUINT32BE(pp + 0x04);
uint32_t string_table_size = poly::load_and_swap<uint32_t>(pp + 0x04);
const char *string_table = (const char*)(pp + 0x0C);
pp += 12 + string_table_size;
@@ -254,11 +254,11 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
xe_xex2_import_library_t *library = &header->import_libraries[m];
XEEXPECTZERO(xe_copy_memory(library->digest, sizeof(library->digest),
pp + 0x04, 20));
library->import_id = XEGETUINT32BE(pp + 0x18);
library->version.value = XEGETUINT32BE(pp + 0x1C);
library->min_version.value = XEGETUINT32BE(pp + 0x20);
library->import_id = poly::load_and_swap<uint32_t>(pp + 0x18);
library->version.value = poly::load_and_swap<uint32_t>(pp + 0x1C);
library->min_version.value = poly::load_and_swap<uint32_t>(pp + 0x20);
const uint16_t name_index = XEGETUINT16BE(pp + 0x24) & 0xFF;
const uint16_t name_index = poly::load_and_swap<uint16_t>(pp + 0x24) & 0xFF;
for (size_t i = 0, j = 0; i < string_table_size;) {
assert_true(j <= 0xFF);
if (j == name_index) {
@@ -277,13 +277,13 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
}
}
library->record_count = XEGETUINT16BE(pp + 0x26);
library->record_count = poly::load_and_swap<uint16_t>(pp + 0x26);
library->records = (uint32_t*)xe_calloc(
library->record_count * sizeof(uint32_t));
XEEXPECTNOTNULL(library->records);
pp += 0x28;
for (size_t i = 0; i < library->record_count; i++) {
library->records[i] = XEGETUINT32BE(pp);
library->records[i] = poly::load_and_swap<uint32_t>(pp);
pp += 4;
}
}
@@ -306,10 +306,10 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
XEEXPECTZERO(xe_copy_memory(library->name, sizeof(library->name),
pp + 0x00, 8));
library->name[8] = 0;
library->major = XEGETUINT16BE(pp + 0x08);
library->minor = XEGETUINT16BE(pp + 0x0A);
library->build = XEGETUINT16BE(pp + 0x0C);
uint16_t qfeapproval = XEGETUINT16BE(pp + 0x0E);
library->major = poly::load_and_swap<uint16_t>(pp + 0x08);
library->minor = poly::load_and_swap<uint16_t>(pp + 0x0A);
library->build = poly::load_and_swap<uint16_t>(pp + 0x0C);
uint16_t qfeapproval = poly::load_and_swap<uint16_t>(pp + 0x0E);
library->approval = (xe_xex2_approval_type)(qfeapproval & 0x8000);
library->qfe = qfeapproval & ~0x8000;
pp += 16;
@@ -320,9 +320,9 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
{
xe_xex2_file_format_info_t *fmt = &header->file_format_info;
fmt->encryption_type =
(xe_xex2_encryption_type)XEGETUINT16BE(pp + 0x04);
(xe_xex2_encryption_type)poly::load_and_swap<uint16_t>(pp + 0x04);
fmt->compression_type =
(xe_xex2_compression_type)XEGETUINT16BE(pp + 0x06);
(xe_xex2_compression_type)poly::load_and_swap<uint16_t>(pp + 0x06);
switch (fmt->compression_type) {
case XEX_COMPRESSION_NONE:
// TODO: XEX_COMPRESSION_NONE
@@ -332,7 +332,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
{
xe_xex2_file_basic_compression_info_t *comp_info =
&fmt->compression_info.basic;
uint32_t info_size = XEGETUINT32BE(pp + 0x00);
uint32_t info_size = poly::load_and_swap<uint32_t>(pp + 0x00);
comp_info->block_count = (info_size - 8) / 8;
comp_info->blocks = (xe_xex2_file_basic_compression_block_t*)
xe_calloc(comp_info->block_count *
@@ -341,8 +341,8 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
for (size_t m = 0; m < comp_info->block_count; m++) {
xe_xex2_file_basic_compression_block_t *block =
&comp_info->blocks[m];
block->data_size = XEGETUINT32BE(pp + 0x08 + (m * 8));
block->zero_size = XEGETUINT32BE(pp + 0x0C + (m * 8));
block->data_size = poly::load_and_swap<uint32_t>(pp + 0x08 + (m * 8));
block->zero_size = poly::load_and_swap<uint32_t>(pp + 0x0C + (m * 8));
}
}
break;
@@ -350,7 +350,7 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
{
xe_xex2_file_normal_compression_info_t *comp_info =
&fmt->compression_info.normal;
uint32_t window_size = XEGETUINT32BE(pp + 0x08);
uint32_t window_size = poly::load_and_swap<uint32_t>(pp + 0x08);
uint32_t window_bits = 0;
for (size_t m = 0; m < 32; m++, window_bits++) {
window_size <<= 1;
@@ -358,9 +358,9 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
break;
}
}
comp_info->window_size = XEGETUINT32BE(pp + 0x08);
comp_info->window_size = poly::load_and_swap<uint32_t>(pp + 0x08);
comp_info->window_bits = window_bits;
comp_info->block_size = XEGETUINT32BE(pp + 0x0C);
comp_info->block_size = poly::load_and_swap<uint32_t>(pp + 0x0C);
XEEXPECTZERO(xe_copy_memory(comp_info->block_hash,
sizeof(comp_info->block_hash),
pp + 0x10, 20));
@@ -379,16 +379,16 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
// Loader info.
pc = p + header->certificate_offset;
ldr = &header->loader_info;
ldr->header_size = XEGETUINT32BE(pc + 0x000);
ldr->image_size = XEGETUINT32BE(pc + 0x004);
ldr->header_size = poly::load_and_swap<uint32_t>(pc + 0x000);
ldr->image_size = poly::load_and_swap<uint32_t>(pc + 0x004);
XEEXPECTZERO(xe_copy_memory(ldr->rsa_signature, sizeof(ldr->rsa_signature),
pc + 0x008, 256));
ldr->unklength = XEGETUINT32BE(pc + 0x108);
ldr->image_flags = (xe_xex2_image_flags)XEGETUINT32BE(pc + 0x10C);
ldr->load_address = XEGETUINT32BE(pc + 0x110);
ldr->unklength = poly::load_and_swap<uint32_t>(pc + 0x108);
ldr->image_flags = (xe_xex2_image_flags)poly::load_and_swap<uint32_t>(pc + 0x10C);
ldr->load_address = poly::load_and_swap<uint32_t>(pc + 0x110);
XEEXPECTZERO(xe_copy_memory(ldr->section_digest, sizeof(ldr->section_digest),
pc + 0x114, 20));
ldr->import_table_count = XEGETUINT32BE(pc + 0x128);
ldr->import_table_count = poly::load_and_swap<uint32_t>(pc + 0x128);
XEEXPECTZERO(xe_copy_memory(ldr->import_table_digest,
sizeof(ldr->import_table_digest),
pc + 0x12C, 20));
@@ -396,22 +396,22 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
pc + 0x140, 16));
XEEXPECTZERO(xe_copy_memory(ldr->file_key, sizeof(ldr->file_key),
pc + 0x150, 16));
ldr->export_table = XEGETUINT32BE(pc + 0x160);
ldr->export_table = poly::load_and_swap<uint32_t>(pc + 0x160);
XEEXPECTZERO(xe_copy_memory(ldr->header_digest, sizeof(ldr->header_digest),
pc + 0x164, 20));
ldr->game_regions = (xe_xex2_region_flags)XEGETUINT32BE(pc + 0x178);
ldr->media_flags = (xe_xex2_media_flags)XEGETUINT32BE(pc + 0x17C);
ldr->game_regions = (xe_xex2_region_flags)poly::load_and_swap<uint32_t>(pc + 0x178);
ldr->media_flags = (xe_xex2_media_flags)poly::load_and_swap<uint32_t>(pc + 0x17C);
// Section info follows loader info.
ps = p + header->certificate_offset + 0x180;
header->section_count = XEGETUINT32BE(ps + 0x000);
header->section_count = poly::load_and_swap<uint32_t>(ps + 0x000);
ps += 4;
header->sections = (xe_xex2_section_t*)xe_calloc(
header->section_count * sizeof(xe_xex2_section_t));
XEEXPECTNOTNULL(header->sections);
for (size_t n = 0; n < header->section_count; n++) {
xe_xex2_section_t *section = &header->sections[n];
section->info.value = XEGETUINT32BE(ps);
section->info.value = poly::load_and_swap<uint32_t>(ps);
ps += 4;
XEEXPECTZERO(xe_copy_memory(section->digest, sizeof(section->digest), ps,
sizeof(section->digest)));
@@ -717,7 +717,7 @@ int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
block_size = header->file_format_info.compression_info.normal.block_size;
while (block_size) {
const uint8_t *pnext = p + block_size;
const size_t next_size = XEGETINT32BE(p);
const size_t next_size = poly::load_and_swap<int32_t>(p);
p += 4;
p += 20; // skip 20b hash
@@ -935,7 +935,7 @@ int xe_xex2_find_import_infos(xe_xex2_ref xex,
size_t info_count = 0;
for (size_t n = 0; n < library->record_count; n++) {
const uint32_t record = library->records[n];
const uint32_t value = XEGETUINT32BE(mem + record);
const uint32_t value = poly::load_and_swap<uint32_t>(mem + record);
if (value & 0xFF000000) {
// Thunk for previous record - ignore.
} else {
@@ -954,7 +954,7 @@ int xe_xex2_find_import_infos(xe_xex2_ref xex,
// Construct infos.
for (size_t n = 0, i = 0; n < library->record_count; n++) {
const uint32_t record = library->records[n];
const uint32_t value = XEGETUINT32BE(mem + record);
const uint32_t value = poly::load_and_swap<uint32_t>(mem + record);
const uint32_t type = (value & 0xFF000000) >> 24;
// Verify library index matches given library.

View File

@@ -125,7 +125,7 @@ SHIM_CALL XAudioRegisterRenderDriverClient_shim(
}
assert_true(!(index & ~0x0000FFFF));
SHIM_SET_MEM_32(driver_ptr, 0x41550000 | (index & 0x0000FFFF));
SHIM_SET_MEM_32(driver_ptr, 0x41550000 | (static_cast<uint32_t>(index) & 0x0000FFFF));
SHIM_SET_RETURN_32(X_ERROR_SUCCESS);
}

View File

@@ -435,7 +435,7 @@ SHIM_CALL NtQueryInformationFile_shim(
if (XSUCCEEDED(result)) {
if (bytes_read == sizeof(magic)) {
info = 4;
SHIM_SET_MEM_32(file_info_ptr, magic == XESWAP32BE(0x0FF512ED));
SHIM_SET_MEM_32(file_info_ptr, magic == poly::byte_swap(0x0FF512ED));
}
else {
result = X_STATUS_UNSUCCESSFUL;

View File

@@ -63,7 +63,7 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) :
export_resolver_->SetVariableMapping(
"xboxkrnl.exe", ordinals::KeDebugMonitorData,
pKeDebugMonitorData);
XESETUINT32BE(mem + pKeDebugMonitorData, 0);
poly::store_and_swap<uint32_t>(mem + pKeDebugMonitorData, 0);
// KeCertMonitorData (?*)
// Always set to zero, ignored.
@@ -71,7 +71,7 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) :
export_resolver_->SetVariableMapping(
"xboxkrnl.exe", ordinals::KeCertMonitorData,
pKeCertMonitorData);
XESETUINT32BE(mem + pKeCertMonitorData, 0);
poly::store_and_swap<uint32_t>(mem + pKeCertMonitorData, 0);
// XboxHardwareInfo (XboxHardwareInfo_t, 16b)
// flags cpu# ? ? ? ? ? ?
@@ -82,8 +82,8 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) :
export_resolver_->SetVariableMapping(
"xboxkrnl.exe", ordinals::XboxHardwareInfo,
pXboxHardwareInfo);
XESETUINT32BE(mem + pXboxHardwareInfo + 0, 0x00000000); // flags
XESETUINT8BE (mem + pXboxHardwareInfo + 4, 0x06); // cpu count
poly::store_and_swap<uint32_t>(mem + pXboxHardwareInfo + 0, 0x00000000); // flags
poly::store_and_swap<uint8_t> (mem + pXboxHardwareInfo + 4, 0x06); // cpu count
// Remaining 11b are zeroes?
// XexExecutableModuleHandle (?**)
@@ -101,8 +101,8 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) :
ppXexExecutableModuleHandle);
uint32_t pXexExecutableModuleHandle =
(uint32_t)memory_->HeapAlloc(0, 256, 0);
XESETUINT32BE(mem + ppXexExecutableModuleHandle, pXexExecutableModuleHandle);
XESETUINT32BE(mem + pXexExecutableModuleHandle + 0x58, 0x80101100);
poly::store_and_swap<uint32_t>(mem + ppXexExecutableModuleHandle, pXexExecutableModuleHandle);
poly::store_and_swap<uint32_t>(mem + pXexExecutableModuleHandle + 0x58, 0x80101100);
// ExLoadedCommandLine (char*)
// The name of the xex. Not sure this is ever really used on real devices.
@@ -123,19 +123,19 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) :
export_resolver_->SetVariableMapping(
"xboxkrnl.exe", ordinals::XboxKrnlVersion,
pXboxKrnlVersion);
XESETUINT16BE(mem + pXboxKrnlVersion + 0, 2);
XESETUINT16BE(mem + pXboxKrnlVersion + 2, 0xFFFF);
XESETUINT16BE(mem + pXboxKrnlVersion + 4, 0xFFFF);
XESETUINT16BE(mem + pXboxKrnlVersion + 6, 0xFFFF);
poly::store_and_swap<uint16_t>(mem + pXboxKrnlVersion + 0, 2);
poly::store_and_swap<uint16_t>(mem + pXboxKrnlVersion + 2, 0xFFFF);
poly::store_and_swap<uint16_t>(mem + pXboxKrnlVersion + 4, 0xFFFF);
poly::store_and_swap<uint16_t>(mem + pXboxKrnlVersion + 6, 0xFFFF);
// KeTimeStampBundle (ad)
uint32_t pKeTimeStampBundle = (uint32_t)memory_->HeapAlloc(0, 24, 0);
export_resolver_->SetVariableMapping(
"xboxkrnl.exe", ordinals::KeTimeStampBundle,
pKeTimeStampBundle);
XESETUINT64BE(mem + pKeTimeStampBundle + 0, 0);
XESETUINT64BE(mem + pKeTimeStampBundle + 8, 0);
XESETUINT32BE(mem + pKeTimeStampBundle + 12, 0);
poly::store_and_swap<uint64_t>(mem + pKeTimeStampBundle + 0, 0);
poly::store_and_swap<uint64_t>(mem + pKeTimeStampBundle + 8, 0);
poly::store_and_swap<uint32_t>(mem + pKeTimeStampBundle + 12, 0);
}
XboxkrnlModule::~XboxkrnlModule() {

View File

@@ -97,7 +97,7 @@ X_STATUS xeExGetXConfigSetting(
}
if (buffer) {
XESETUINT32BE(buffer, value);
poly::store_and_swap<uint32_t>(buffer, value);
}
if (required_size) {
*required_size = setting_size;

View File

@@ -91,7 +91,7 @@ uint32_t xeRtlCompareMemoryUlong(uint32_t source_ptr, uint32_t length,
// TODO(benvanik): ensure byte order of pattern is correct.
// Since we are doing byte-by-byte comparison we may not want to swap.
// GET_ARG swaps, so this is a swap back. Ugly.
const uint32_t pb32 = XESWAP32BE(pattern);
const uint32_t pb32 = poly::byte_swap(pattern);
const uint8_t* pb = (uint8_t*)&pb32;
uint32_t c = 0;
@@ -138,7 +138,7 @@ void xeRtlFillMemoryUlong(uint32_t destination_ptr, uint32_t length,
// swapped arg value.
uint32_t count = length >> 2;
uint32_t native_pattern = XESWAP32BE(pattern);
uint32_t native_pattern = poly::byte_swap(pattern);
// TODO: unroll loop?
@@ -364,7 +364,7 @@ SHIM_CALL RtlMultiByteToUnicodeN_shim(
auto destination = (uint16_t*)SHIM_MEM_ADDR(destination_ptr);
for (uint32_t i = 0; i < copy_len; i++)
{
*destination++ = XESWAP16(*source++);
*destination++ = poly::byte_swap(*source++);
}
if (written_ptr != 0)
@@ -393,7 +393,7 @@ SHIM_CALL RtlUnicodeToMultiByteN_shim(
auto destination = (uint8_t*)SHIM_MEM_ADDR(destination_ptr);
for (uint32_t i = 0; i < copy_len; i++)
{
uint16_t c = XESWAP16(*source++);
uint16_t c = poly::byte_swap(*source++);
*destination++ = c < 256 ? (uint8_t)c : '?';
}

View File

@@ -472,9 +472,8 @@ SHIM_CALL _vswprintf_shim(
// swap the format buffer
wchar_t* swapped_format = (wchar_t*)xe_malloc((format_length + 1) * sizeof(wchar_t));
for (size_t i = 0; i < format_length; ++i)
{
swapped_format[i] = XESWAP16(format[i]);
for (size_t i = 0; i < format_length; ++i) {
swapped_format[i] = poly::byte_swap(format[i]);
}
swapped_format[format_length] = '\0';
@@ -676,9 +675,8 @@ SHIM_CALL _vswprintf_shim(
const wchar_t* data = (const wchar_t*)SHIM_MEM_ADDR(value);
size_t data_length = wcslen(data);
wchar_t* swapped_data = (wchar_t*)xe_malloc((data_length + 1) * sizeof(wchar_t));
for (size_t i = 0; i < data_length; ++i)
{
swapped_data[i] = XESWAP16(data[i]);
for (size_t i = 0; i < data_length; ++i) {
swapped_data[i] = poly::byte_swap(data[i]);
}
swapped_data[data_length] = '\0';
int result = wsprintf(b, local, swapped_data);
@@ -703,7 +701,7 @@ SHIM_CALL _vswprintf_shim(
// swap the result buffer
for (wchar_t* swap = buffer; swap != b; ++swap)
{
*swap = XESWAP16(*swap);
*swap = poly::byte_swap(*swap);
}
SHIM_SET_RETURN_32((uint32_t)((b - buffer) / sizeof(wchar_t)));

View File

@@ -117,15 +117,15 @@ void xeVdQueryVideoMode(X_VIDEO_MODE *video_mode, bool swap) {
video_mode->unknown_0x01 = 0x01;
if (swap) {
video_mode->display_width = XESWAP32BE(video_mode->display_width);
video_mode->display_height = XESWAP32BE(video_mode->display_height);
video_mode->is_interlaced = XESWAP32BE(video_mode->is_interlaced);
video_mode->is_widescreen = XESWAP32BE(video_mode->is_widescreen);
video_mode->is_hi_def = XESWAP32BE(video_mode->is_hi_def);
video_mode->refresh_rate = XESWAPF32BE(video_mode->refresh_rate);
video_mode->video_standard = XESWAP32BE(video_mode->video_standard);
video_mode->unknown_0x8a = XESWAP32BE(video_mode->unknown_0x8a);
video_mode->unknown_0x01 = XESWAP32BE(video_mode->unknown_0x01);
video_mode->display_width = poly::byte_swap(video_mode->display_width);
video_mode->display_height = poly::byte_swap(video_mode->display_height);
video_mode->is_interlaced = poly::byte_swap(video_mode->is_interlaced);
video_mode->is_widescreen = poly::byte_swap(video_mode->is_widescreen);
video_mode->is_hi_def = poly::byte_swap(video_mode->is_hi_def);
video_mode->refresh_rate = poly::byte_swap(video_mode->refresh_rate);
video_mode->video_standard = poly::byte_swap(video_mode->video_standard);
video_mode->unknown_0x8a = poly::byte_swap(video_mode->unknown_0x8a);
video_mode->unknown_0x01 = poly::byte_swap(video_mode->unknown_0x01);
}
}
@@ -430,9 +430,9 @@ SHIM_CALL VdSwap_shim(
// use this method.
xe_zero_struct(SHIM_MEM_ADDR(unk0), 64 * 4);
auto dwords = reinterpret_cast<uint32_t*>(SHIM_MEM_ADDR(unk0));
dwords[0] = XESWAP32((0x03 << 30) |
((1 - 1) << 16) |
(xenos::PM4_XE_SWAP << 8));
dwords[0] = poly::byte_swap((0x03 << 30) |
((1 - 1) << 16) |
(xenos::PM4_XE_SWAP << 8));
SHIM_SET_RETURN_64(0);
}
@@ -472,7 +472,7 @@ void xe::kernel::xboxkrnl::RegisterVideoExports(
export_resolver->SetVariableMapping(
"xboxkrnl.exe", ordinals::VdGlobalDevice,
pVdGlobalDevice);
XESETUINT32BE(mem + pVdGlobalDevice, 0);
poly::store_and_swap<uint32_t>(mem + pVdGlobalDevice, 0);
// VdGlobalXamDevice (4b)
// Pointer to the XAM D3D device, which we don't have.
@@ -480,7 +480,7 @@ void xe::kernel::xboxkrnl::RegisterVideoExports(
export_resolver->SetVariableMapping(
"xboxkrnl.exe", ordinals::VdGlobalXamDevice,
pVdGlobalXamDevice);
XESETUINT32BE(mem + pVdGlobalXamDevice, 0);
poly::store_and_swap<uint32_t>(mem + pVdGlobalXamDevice, 0);
// VdGpuClockInMHz (4b)
// GPU clock. Xenos is 500MHz. Hope nothing is relying on this timing...
@@ -488,7 +488,7 @@ void xe::kernel::xboxkrnl::RegisterVideoExports(
export_resolver->SetVariableMapping(
"xboxkrnl.exe", ordinals::VdGpuClockInMHz,
pVdGpuClockInMHz);
XESETUINT32BE(mem + pVdGpuClockInMHz, 500);
poly::store_and_swap<uint32_t>(mem + pVdGpuClockInMHz, 500);
// VdHSIOCalibrationLock (28b)
// CriticalSection.

View File

@@ -162,18 +162,18 @@ void XObject::SetNativePointer(uint32_t native_ptr) {
DISPATCH_HEADER* header_be =
(DISPATCH_HEADER*)kernel_state_->memory()->Translate(native_ptr);
DISPATCH_HEADER header;
header.type_flags = XESWAP32(header_be->type_flags);
header.signal_state = XESWAP32(header_be->signal_state);
header.wait_list_flink = XESWAP32(header_be->wait_list_flink);
header.wait_list_blink = XESWAP32(header_be->wait_list_blink);
header.type_flags = poly::byte_swap(header_be->type_flags);
header.signal_state = poly::byte_swap(header_be->signal_state);
header.wait_list_flink = poly::byte_swap(header_be->wait_list_flink);
header.wait_list_blink = poly::byte_swap(header_be->wait_list_blink);
assert_true(!(header.wait_list_blink & 0x1));
// Stash pointer in struct.
uint64_t object_ptr = reinterpret_cast<uint64_t>(this);
object_ptr |= 0x1;
header_be->wait_list_flink = XESWAP32((uint32_t)(object_ptr >> 32));
header_be->wait_list_blink = XESWAP32((uint32_t)(object_ptr & 0xFFFFFFFF));
header_be->wait_list_flink = poly::byte_swap((uint32_t)(object_ptr >> 32));
header_be->wait_list_blink = poly::byte_swap((uint32_t)(object_ptr & 0xFFFFFFFF));
XObject::UnlockType();
}
@@ -193,10 +193,10 @@ XObject* XObject::GetObject(KernelState* kernel_state, void* native_ptr,
DISPATCH_HEADER* header_be = (DISPATCH_HEADER*)native_ptr;
DISPATCH_HEADER header;
header.type_flags = XESWAP32(header_be->type_flags);
header.signal_state = XESWAP32(header_be->signal_state);
header.wait_list_flink = XESWAP32(header_be->wait_list_flink);
header.wait_list_blink = XESWAP32(header_be->wait_list_blink);
header.type_flags = poly::byte_swap(header_be->type_flags);
header.signal_state = poly::byte_swap(header_be->signal_state);
header.wait_list_flink = poly::byte_swap(header_be->wait_list_flink);
header.wait_list_blink = poly::byte_swap(header_be->wait_list_blink);
if (as_type == -1) {
as_type = header.type_flags & 0xFF;
@@ -260,8 +260,8 @@ XObject* XObject::GetObject(KernelState* kernel_state, void* native_ptr,
// Stash pointer in struct.
uint64_t object_ptr = reinterpret_cast<uint64_t>(object);
object_ptr |= 0x1;
header_be->wait_list_flink = XESWAP32((uint32_t)(object_ptr >> 32));
header_be->wait_list_blink = XESWAP32((uint32_t)(object_ptr & 0xFFFFFFFF));
header_be->wait_list_flink = poly::byte_swap((uint32_t)(object_ptr >> 32));
header_be->wait_list_blink = poly::byte_swap((uint32_t)(object_ptr & 0xFFFFFFFF));
XObject::UnlockType();
return object;