Auto swap for a few structs and shifting code around.

This commit is contained in:
Ben Vanik
2014-08-19 22:55:09 -07:00
parent fb98683ed3
commit d33cae1baf
4 changed files with 72 additions and 101 deletions

View File

@@ -23,6 +23,38 @@ namespace kernel {
using namespace xe::kernel::fs;
class X_OBJECT_ATTRIBUTES {
public:
uint32_t root_directory;
uint32_t object_name_ptr;
X_ANSI_STRING object_name;
uint32_t attributes;
X_OBJECT_ATTRIBUTES() {
Zero();
}
X_OBJECT_ATTRIBUTES(const uint8_t* base, uint32_t p) {
Read(base, p);
}
void Read(const uint8_t* base, uint32_t p) {
root_directory = poly::load_and_swap<uint32_t>(base + p);
object_name_ptr = poly::load_and_swap<uint32_t>(base + p + 4);
if (object_name_ptr) {
object_name.Read(base, object_name_ptr);
} else {
object_name.Zero();
}
attributes = poly::load_and_swap<uint32_t>(base + p + 8);
}
void Zero() {
root_directory = 0;
object_name_ptr = 0;
object_name.Zero();
attributes = 0;
}
};
static_assert_size(X_OBJECT_ATTRIBUTES, 12 + sizeof(X_ANSI_STRING));
SHIM_CALL NtCreateFile_shim(PPCContext* ppc_state, KernelState* state) {
uint32_t handle_ptr = SHIM_GET_ARG_32(0);
uint32_t desired_access = SHIM_GET_ARG_32(1);

View File

@@ -149,49 +149,42 @@ SHIM_CALL NtFreeVirtualMemory_shim(PPCContext* ppc_state, KernelState* state) {
SHIM_SET_RETURN_32(X_STATUS_SUCCESS);
}
struct X_MEMORY_BASIC_INFORMATION {
be<uint32_t> base_address;
be<uint32_t> allocation_base;
be<uint32_t> allocation_protect;
be<uint32_t> region_size;
be<uint32_t> state;
be<uint32_t> protect;
be<uint32_t> type;
};
SHIM_CALL NtQueryVirtualMemory_shim(PPCContext* ppc_state, KernelState* state) {
uint32_t base_address = SHIM_GET_ARG_32(0);
uint32_t memory_basic_information_ptr = SHIM_GET_ARG_32(1);
X_MEMORY_BASIC_INFORMATION* memory_basic_information =
(X_MEMORY_BASIC_INFORMATION*)SHIM_MEM_ADDR(memory_basic_information_ptr);
auto memory_basic_information =
SHIM_STRUCT(X_MEMORY_BASIC_INFORMATION, memory_basic_information_ptr);
XELOGD("NtQueryVirtualMemory(%.8X, %.8X)", base_address,
memory_basic_information_ptr);
AllocationInfo mem_info;
size_t result = state->memory()->QueryInformation(base_address, &mem_info);
AllocationInfo alloc_info;
size_t result = state->memory()->QueryInformation(base_address, &alloc_info);
if (!result) {
SHIM_SET_RETURN_32(X_STATUS_INVALID_PARAMETER);
return;
}
auto membase = state->memory()->membase();
memory_basic_information->base_address =
static_cast<uint32_t>(mem_info.base_address);
static_cast<uint32_t>(alloc_info.base_address);
memory_basic_information->allocation_base =
static_cast<uint32_t>(mem_info.allocation_base);
memory_basic_information->allocation_protect = mem_info.allocation_protect;
static_cast<uint32_t>(alloc_info.allocation_base);
memory_basic_information->allocation_protect = alloc_info.allocation_protect;
memory_basic_information->region_size =
static_cast<uint32_t>(mem_info.region_size);
memory_basic_information->state = mem_info.state;
memory_basic_information->protect = mem_info.protect;
memory_basic_information->type = mem_info.type;
// TODO(benvanik): auto swap structure.
memory_basic_information->base_address =
poly::byte_swap(memory_basic_information->base_address);
memory_basic_information->allocation_base =
poly::byte_swap(memory_basic_information->allocation_base);
memory_basic_information->allocation_protect =
poly::byte_swap(memory_basic_information->allocation_protect);
memory_basic_information->region_size =
poly::byte_swap(memory_basic_information->region_size);
memory_basic_information->state =
poly::byte_swap(memory_basic_information->state);
memory_basic_information->protect =
poly::byte_swap(memory_basic_information->protect);
memory_basic_information->type =
poly::byte_swap(memory_basic_information->type);
static_cast<uint32_t>(alloc_info.region_size);
memory_basic_information->state = alloc_info.state;
memory_basic_information->protect = alloc_info.protect;
memory_basic_information->type = alloc_info.type;
XELOGE("NtQueryVirtualMemory NOT IMPLEMENTED");

View File

@@ -100,17 +100,6 @@ void xeVdQueryVideoMode(X_VIDEO_MODE* video_mode) {
video_mode->video_standard = 1; // NTSC
video_mode->unknown_0x8a = 0x8A;
video_mode->unknown_0x01 = 0x01;
// TODO(benvanik): auto swap structure.
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);
}
SHIM_CALL VdQueryVideoMode_shim(PPCContext* ppc_state, KernelState* state) {