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) {

View File

@ -28,6 +28,8 @@ typedef uint32_t X_HANDLE;
#define X_INVALID_HANDLE_VALUE ((X_HANDLE)-1)
// TODO(benvanik): type all of this so we get some safety.
// NT_STATUS (STATUS_*)
// http://msdn.microsoft.com/en-us/library/cc704588.aspx
// Adding as needed.
@ -145,7 +147,7 @@ typedef uint32_t X_RESULT;
#define X_LANGUAGE_JAPANESE 2
typedef enum _X_FILE_ATTRIBUTES {
enum X_FILE_ATTRIBUTES {
X_FILE_ATTRIBUTE_NONE = 0x0000,
X_FILE_ATTRIBUTE_READONLY = 0x0001,
X_FILE_ATTRIBUTE_HIDDEN = 0x0002,
@ -157,11 +159,11 @@ typedef enum _X_FILE_ATTRIBUTES {
X_FILE_ATTRIBUTE_TEMPORARY = 0x0100,
X_FILE_ATTRIBUTE_COMPRESSED = 0x0800,
X_FILE_ATTRIBUTE_ENCRYPTED = 0x4000,
} X_FILE_ATTRIBUTES;
};
// http://code.google.com/p/vdash/source/browse/trunk/vdash/include/kernel.h
typedef enum _X_FILE_INFORMATION_CLASS {
enum X_FILE_INFORMATION_CLASS {
XFileDirectoryInformation = 1,
XFileFullDirectoryInformation,
XFileBothDirectoryInformation,
@ -199,20 +201,8 @@ typedef enum _X_FILE_INFORMATION_CLASS {
XFileAttributeTagInformation,
XFileTrackingInformation,
XFileMaximumInformation
} X_FILE_INFORMATION_CLASS;
struct X_MEMORY_BASIC_INFORMATION {
uint32_t base_address;
uint32_t allocation_base;
uint32_t allocation_protect;
uint32_t region_size;
uint32_t state;
uint32_t protect;
uint32_t type;
};
inline void XOverlappedSetResult(void* ptr, uint32_t value) {
auto p = reinterpret_cast<uint32_t*>(ptr);
poly::store_and_swap<uint32_t>(&p[0], value);
@ -284,63 +274,30 @@ public:
//static_assert_size(X_ANSI_STRING, 8);
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));
// Values seem to be all over the place - GUIDs?
typedef uint32_t XNotificationID;
// http://ffplay360.googlecode.com/svn/trunk/Common/XTLOnPC.h
struct X_VIDEO_MODE {
uint32_t display_width;
uint32_t display_height;
uint32_t is_interlaced;
uint32_t is_widescreen;
uint32_t is_hi_def;
float refresh_rate;
uint32_t video_standard;
uint32_t unknown_0x8a;
uint32_t unknown_0x01;
uint32_t reserved[3];
be<uint32_t> display_width;
be<uint32_t> display_height;
be<uint32_t> is_interlaced;
be<uint32_t> is_widescreen;
be<uint32_t> is_hi_def;
be<float> refresh_rate;
be<uint32_t> video_standard;
be<uint32_t> unknown_0x8a;
be<uint32_t> unknown_0x01;
be<uint32_t> reserved[3];
};
static_assert_size(X_VIDEO_MODE, 48);
typedef enum _X_INPUT_FLAG {
enum X_INPUT_FLAG {
X_INPUT_FLAG_GAMEPAD = 0x00000001,
} X_INPUT_FLAG;
};
typedef enum _X_INPUT_GAMEPAD_BUTTON {
enum X_INPUT_GAMEPAD_BUTTON {
X_INPUT_GAMEPAD_DPAD_UP = 0x0001,
X_INPUT_GAMEPAD_DPAD_DOWN = 0x0002,
X_INPUT_GAMEPAD_DPAD_LEFT = 0x0004,
@ -355,7 +312,7 @@ typedef enum _X_INPUT_GAMEPAD_BUTTON {
X_INPUT_GAMEPAD_B = 0x2000,
X_INPUT_GAMEPAD_X = 0x4000,
X_INPUT_GAMEPAD_Y = 0x8000,
} X_INPUT_GAMEPAD_BUTTON;
};
struct X_INPUT_GAMEPAD {
be<uint16_t> buttons;