[Kernel] add object type stub functions, export object types
This commit is contained in:
committed by
Radosław Gliński
parent
6a08208dc8
commit
9b3601c6fa
@@ -22,7 +22,9 @@
|
||||
#include "xenia/kernel/user_module.h"
|
||||
#include "xenia/kernel/util/shim_utils.h"
|
||||
#include "xenia/kernel/xam/xam_module.h"
|
||||
#include "xenia/kernel/xboxkrnl/xboxkrnl_memory.h"
|
||||
#include "xenia/kernel/xboxkrnl/xboxkrnl_module.h"
|
||||
#include "xenia/kernel/xboxkrnl/xboxkrnl_ob.h"
|
||||
#include "xenia/kernel/xboxkrnl/xboxkrnl_threading.h"
|
||||
#include "xenia/kernel/xevent.h"
|
||||
#include "xenia/kernel/xmodule.h"
|
||||
@@ -48,7 +50,10 @@ KernelState::KernelState(Emulator* emulator)
|
||||
: emulator_(emulator),
|
||||
memory_(emulator->memory()),
|
||||
dispatch_thread_running_(false),
|
||||
dpc_list_(emulator->memory()) {
|
||||
dpc_list_(emulator->memory()),
|
||||
kernel_trampoline_group_(emulator->processor()->backend()) {
|
||||
assert_null(shared_kernel_state_);
|
||||
shared_kernel_state_ = this;
|
||||
processor_ = emulator->processor();
|
||||
file_system_ = emulator->file_system();
|
||||
|
||||
@@ -64,9 +69,6 @@ KernelState::KernelState(Emulator* emulator)
|
||||
}
|
||||
content_manager_ = std::make_unique<xam::ContentManager>(this, content_root);
|
||||
|
||||
assert_null(shared_kernel_state_);
|
||||
shared_kernel_state_ = this;
|
||||
|
||||
// Hardcoded maximum of 2048 TLS slots.
|
||||
tls_bitmap_.Resize(2048);
|
||||
|
||||
@@ -1148,6 +1150,64 @@ void KernelState::SetProcessTLSVars(X_KPROCESS* process, int num_slots,
|
||||
if (((num_slots + 3) & 0x1C) != 0)
|
||||
process->bitmap[count_div32] = -1 << (32 - ((num_slots + 3) & 0x1C));
|
||||
}
|
||||
void AllocateThread(PPCContext* context) {
|
||||
uint32_t thread_mem_size = static_cast<uint32_t>(context->r[3]);
|
||||
uint32_t a2 = static_cast<uint32_t>(context->r[4]);
|
||||
uint32_t a3 = static_cast<uint32_t>(context->r[5]);
|
||||
if (thread_mem_size <= 0xFD8) thread_mem_size += 8;
|
||||
uint32_t result =
|
||||
xboxkrnl::xeAllocatePoolTypeWithTag(context, thread_mem_size, a2, a3);
|
||||
if (((unsigned short)result & 0xFFF) != 0) {
|
||||
result += 2;
|
||||
}
|
||||
|
||||
context->r[3] = static_cast<uint64_t>(result);
|
||||
}
|
||||
void FreeThread(PPCContext* context) {
|
||||
uint32_t thread_memory = static_cast<uint32_t>(context->r[3]);
|
||||
if ((thread_memory & 0xFFF) != 0) {
|
||||
thread_memory -= 8;
|
||||
}
|
||||
xboxkrnl::xeFreePool(context, thread_memory);
|
||||
}
|
||||
|
||||
void SimpleForwardAllocatePoolTypeWithTag(PPCContext* context) {
|
||||
uint32_t a1 = static_cast<uint32_t>(context->r[3]);
|
||||
uint32_t a2 = static_cast<uint32_t>(context->r[4]);
|
||||
uint32_t a3 = static_cast<uint32_t>(context->r[5]);
|
||||
context->r[3] = static_cast<uint64_t>(
|
||||
xboxkrnl::xeAllocatePoolTypeWithTag(context, a1, a2, a3));
|
||||
}
|
||||
void SimpleForwardFreePool(PPCContext* context) {
|
||||
xboxkrnl::xeFreePool(context, static_cast<uint32_t>(context->r[3]));
|
||||
}
|
||||
|
||||
void DeleteMutant(PPCContext* context) {
|
||||
// todo: this should call kereleasemutant with some specific args
|
||||
|
||||
xe::FatalError("DeleteMutant - need KeReleaseMutant(mutant, 1, 1, 0) ");
|
||||
}
|
||||
void DeleteTimer(PPCContext* context) {
|
||||
// todo: this should call KeCancelTimer
|
||||
xe::FatalError("DeleteTimer - need KeCancelTimer(mutant, 1, 1, 0) ");
|
||||
}
|
||||
|
||||
void DeleteIoCompletion(PPCContext* context) {}
|
||||
|
||||
void UnknownProcIoDevice(PPCContext* context) {}
|
||||
|
||||
void CloseFileProc(PPCContext* context) {}
|
||||
|
||||
void DeleteFileProc(PPCContext* context) {}
|
||||
|
||||
void UnknownFileProc(PPCContext* context) {}
|
||||
|
||||
void DeleteSymlink(PPCContext* context) {
|
||||
X_KSYMLINK* lnk = context->TranslateVirtualGPR<X_KSYMLINK*>(context->r[3]);
|
||||
|
||||
context->r[3] = lnk->refed_object_maybe;
|
||||
xboxkrnl::xeObDereferenceObject(context, lnk->refed_object_maybe);
|
||||
}
|
||||
void KernelState::InitializeKernelGuestGlobals() {
|
||||
kernel_guest_globals_ = memory_->SystemHeapAlloc(sizeof(KernelGuestGlobals));
|
||||
|
||||
@@ -1162,6 +1222,120 @@ void KernelState::InitializeKernelGuestGlobals() {
|
||||
memory()->TranslateVirtual<X_KPROCESS*>(GetSystemProcess());
|
||||
InitializeProcess(system_process, X_PROCTYPE_SYSTEM, 2, 5, 9);
|
||||
SetProcessTLSVars(system_process, 32, 0, 0);
|
||||
|
||||
uint32_t oddobject_offset =
|
||||
kernel_guest_globals_ + offsetof(KernelGuestGlobals, OddObj);
|
||||
|
||||
// init unknown object
|
||||
|
||||
block->OddObj.field0 = 0x1000000;
|
||||
block->OddObj.field4 = 1;
|
||||
block->OddObj.points_to_self =
|
||||
oddobject_offset + offsetof(X_UNKNOWN_TYPE_REFED, points_to_self);
|
||||
block->OddObj.points_to_prior = block->OddObj.points_to_self;
|
||||
|
||||
// init thread object
|
||||
block->ExThreadObjectType.pool_tag = 0x65726854;
|
||||
block->ExThreadObjectType.allocate_proc =
|
||||
kernel_trampoline_group_.NewLongtermTrampoline(AllocateThread);
|
||||
|
||||
block->ExThreadObjectType.free_proc =
|
||||
kernel_trampoline_group_.NewLongtermTrampoline(FreeThread);
|
||||
|
||||
// several object types just call freepool/allocatepool
|
||||
uint32_t trampoline_allocatepool =
|
||||
kernel_trampoline_group_.NewLongtermTrampoline(
|
||||
SimpleForwardAllocatePoolTypeWithTag);
|
||||
uint32_t trampoline_freepool =
|
||||
kernel_trampoline_group_.NewLongtermTrampoline(SimpleForwardFreePool);
|
||||
|
||||
// init event object
|
||||
block->ExEventObjectType.pool_tag = 0x76657645;
|
||||
block->ExEventObjectType.allocate_proc = trampoline_allocatepool;
|
||||
block->ExEventObjectType.free_proc = trampoline_freepool;
|
||||
|
||||
// init mutant object
|
||||
block->ExMutantObjectType.pool_tag = 0x6174754D;
|
||||
block->ExMutantObjectType.allocate_proc = trampoline_allocatepool;
|
||||
block->ExMutantObjectType.free_proc = trampoline_freepool;
|
||||
|
||||
block->ExMutantObjectType.delete_proc =
|
||||
kernel_trampoline_group_.NewLongtermTrampoline(DeleteMutant);
|
||||
// init semaphore obj
|
||||
block->ExSemaphoreObjectType.pool_tag = 0x616D6553;
|
||||
block->ExSemaphoreObjectType.allocate_proc = trampoline_allocatepool;
|
||||
block->ExSemaphoreObjectType.free_proc = trampoline_freepool;
|
||||
// init timer obj
|
||||
block->ExTimerObjectType.pool_tag = 0x656D6954;
|
||||
block->ExTimerObjectType.allocate_proc = trampoline_allocatepool;
|
||||
block->ExTimerObjectType.free_proc = trampoline_freepool;
|
||||
block->ExTimerObjectType.delete_proc =
|
||||
kernel_trampoline_group_.NewLongtermTrampoline(DeleteTimer);
|
||||
// iocompletion object
|
||||
block->IoCompletionObjectType.pool_tag = 0x706D6F43;
|
||||
block->IoCompletionObjectType.allocate_proc = trampoline_allocatepool;
|
||||
block->IoCompletionObjectType.free_proc = trampoline_freepool;
|
||||
block->IoCompletionObjectType.delete_proc =
|
||||
kernel_trampoline_group_.NewLongtermTrampoline(DeleteIoCompletion);
|
||||
block->IoCompletionObjectType.unknown_size_or_object_ = oddobject_offset;
|
||||
|
||||
// iodevice object
|
||||
block->IoDeviceObjectType.pool_tag = 0x69766544;
|
||||
block->IoDeviceObjectType.allocate_proc = trampoline_allocatepool;
|
||||
block->IoDeviceObjectType.free_proc = trampoline_freepool;
|
||||
block->IoDeviceObjectType.unknown_size_or_object_ = oddobject_offset;
|
||||
block->IoDeviceObjectType.unknown_proc =
|
||||
kernel_trampoline_group_.NewLongtermTrampoline(UnknownProcIoDevice);
|
||||
|
||||
// file object
|
||||
block->IoFileObjectType.pool_tag = 0x656C6946;
|
||||
block->IoFileObjectType.allocate_proc = trampoline_allocatepool;
|
||||
block->IoFileObjectType.free_proc = trampoline_freepool;
|
||||
block->IoFileObjectType.unknown_size_or_object_ =
|
||||
0x38; // sizeof fileobject, i believe
|
||||
block->IoFileObjectType.close_proc =
|
||||
kernel_trampoline_group_.NewLongtermTrampoline(CloseFileProc);
|
||||
block->IoFileObjectType.delete_proc =
|
||||
kernel_trampoline_group_.NewLongtermTrampoline(DeleteFileProc);
|
||||
block->IoFileObjectType.unknown_proc =
|
||||
kernel_trampoline_group_.NewLongtermTrampoline(UnknownFileProc);
|
||||
|
||||
// directory object
|
||||
block->ObDirectoryObjectType.pool_tag = 0x65726944;
|
||||
block->ObDirectoryObjectType.allocate_proc = trampoline_allocatepool;
|
||||
block->ObDirectoryObjectType.free_proc = trampoline_freepool;
|
||||
block->ObDirectoryObjectType.unknown_size_or_object_ = oddobject_offset;
|
||||
|
||||
// symlink object
|
||||
block->ObSymbolicLinkObjectType.pool_tag = 0x626D7953;
|
||||
block->ObSymbolicLinkObjectType.allocate_proc = trampoline_allocatepool;
|
||||
block->ObSymbolicLinkObjectType.free_proc = trampoline_freepool;
|
||||
block->ObSymbolicLinkObjectType.unknown_size_or_object_ = oddobject_offset;
|
||||
block->ObSymbolicLinkObjectType.delete_proc =
|
||||
kernel_trampoline_group_.NewLongtermTrampoline(DeleteSymlink);
|
||||
|
||||
#define offsetof32(s, m) static_cast<uint32_t>( offsetof(s, m) )
|
||||
|
||||
host_object_type_enum_to_guest_object_type_ptr_ = {
|
||||
{XObject::Type::Event,
|
||||
kernel_guest_globals_ +
|
||||
offsetof32(KernelGuestGlobals, ExEventObjectType)},
|
||||
{XObject::Type::Semaphore,
|
||||
kernel_guest_globals_ +
|
||||
offsetof32(KernelGuestGlobals, ExSemaphoreObjectType)},
|
||||
{XObject::Type::Thread,
|
||||
kernel_guest_globals_ +
|
||||
offsetof32(KernelGuestGlobals, ExThreadObjectType)},
|
||||
{XObject::Type::File,
|
||||
kernel_guest_globals_ +
|
||||
offsetof32(KernelGuestGlobals, IoFileObjectType)},
|
||||
{XObject::Type::Mutant,
|
||||
kernel_guest_globals_ +
|
||||
offsetof32(KernelGuestGlobals, ExMutantObjectType)},
|
||||
{XObject::Type::Device,
|
||||
kernel_guest_globals_ +
|
||||
offsetof32(KernelGuestGlobals, IoDeviceObjectType)}};
|
||||
xboxkrnl::xeKeSetEvent(&block->UsbdBootEnumerationDoneEvent, 1, 0);
|
||||
}
|
||||
} // namespace kernel
|
||||
} // namespace xe
|
||||
|
||||
Reference in New Issue
Block a user