From 6f08cd4ed23d2e31dfc741a531047c24588ea7f0 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Fri, 31 Jan 2003 18:10:38 +0000 Subject: [PATCH] FS emulation : KThread --- Doc/Todo.txt | 5 +---- Source/Win32/CxbxKrnl/CxbxKrnl.cpp | 33 ++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Doc/Todo.txt b/Doc/Todo.txt index fceb22d60..2fd68d400 100644 --- a/Doc/Todo.txt +++ b/Doc/Todo.txt @@ -2,10 +2,7 @@ Cxbx Todo: General Code Cleanup [caustik] - Use KeGetCurrentThread for fs:28h (May not be able to w/out kernel mode) - If not, fake it by constructing a fake KTHREAD possibly. In any event, - the current crashing method is an attempt to locate TLSData inside of a - KTHREAD object returned by fs:28h. + Find out where NewPcr->PrcbData.CurrentThread->TlsData should point. Exe->Xbe should use an "OpenXDK" logo bitmap by default. This can be done by having a debug version of Cxbx output the necessary raw data. Then, you diff --git a/Source/Win32/CxbxKrnl/CxbxKrnl.cpp b/Source/Win32/CxbxKrnl/CxbxKrnl.cpp index cefe93d3b..cc37cf3dd 100644 --- a/Source/Win32/CxbxKrnl/CxbxKrnl.cpp +++ b/Source/Win32/CxbxKrnl/CxbxKrnl.cpp @@ -127,9 +127,14 @@ void EmuXGenerateFS() // * Generate TIB // ****************************************************************** { + xboxkrnl::KTHREAD *KThread = new xboxkrnl::KTHREAD(); + memcpy(&NewPcr->NtTib, OrgNtTib, sizeof(NT_TIB)); NewPcr->NtTib.Self = &NewPcr->NtTib; + NewPcr->PrcbData.CurrentThread = KThread; + + KThread->TlsData = (void*)0xCDCDCDCD; } // ****************************************************************** @@ -222,13 +227,13 @@ CXBXKRNL_API void NTAPI EmuXInit(DebugMode DebugConsole, char *DebugFilename, ui // ****************************************************************** { EmuXGenerateFS(); - - // TODO: Initialize "new" FS structure } printf("CxbxKrnl [0x%.08X]: Initial thread starting.\n", GetCurrentThreadId()); + EmuXSwapFS(); // XBox FS Entry(); + EmuXSwapFS(); // Win2k/XP FS printf("CxbxKrnl [0x%.08X]: Initial thread ended.\n", GetCurrentThreadId()); @@ -244,7 +249,11 @@ CXBXKRNL_API void NTAPI EmuXInit(DebugMode DebugConsole, char *DebugFilename, ui // ****************************************************************** CXBXKRNL_API void NTAPI EmuXDummy() { + EmuXSwapFS(); // Win2k/XP FS + MessageBox(NULL, "EmuXDummy()", "CxbxKrnl", MB_OK); + + EmuXSwapFS(); // XBox FS } // ****************************************************************** @@ -252,10 +261,14 @@ CXBXKRNL_API void NTAPI EmuXDummy() // ****************************************************************** CXBXKRNL_API void NTAPI EmuXPanic() { + EmuXSwapFS(); // Win2k/XP FS + printf("CxbxKrnl [0x%.08X]: EmuXPanic()\n", GetCurrentThreadId()); MessageBox(NULL, "Kernel Panic! Process will now terminate.", "CxbxKrnl", MB_OK | MB_ICONEXCLAMATION); + EmuXSwapFS(); // XBox FS + exit(1); } @@ -288,6 +301,10 @@ DWORD WINAPI PsCreateSystemThreadExProxy delete iPsCreateSystemThreadExProxyParam; + EmuXGenerateFS(); + + EmuXSwapFS(); // XBox FS + __asm { mov esi, StartRoutine @@ -312,6 +329,8 @@ XBSYSAPI EXPORTNUM(187) NTSTATUS NTAPI xboxkrnl::NtClose IN HANDLE Handle ) { + EmuXSwapFS(); // Win2k/XP FS + // ****************************************************************** // * debug trace // ****************************************************************** @@ -328,6 +347,8 @@ XBSYSAPI EXPORTNUM(187) NTSTATUS NTAPI xboxkrnl::NtClose if(CloseHandle(Handle) != TRUE) return STATUS_UNSUCCESSFUL; + EmuXSwapFS(); // XBox FS + return STATUS_SUCCESS; } @@ -348,6 +369,8 @@ XBSYSAPI EXPORTNUM(255) NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadEx IN PKSTART_ROUTINE StartRoutine ) { + EmuXSwapFS(); // Win2k/XP FS + // ****************************************************************** // * debug trace // ****************************************************************** @@ -385,6 +408,8 @@ XBSYSAPI EXPORTNUM(255) NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadEx if(ThreadId != NULL) *ThreadId = dwThreadId; + EmuXSwapFS(); // XBox FS + return STATUS_SUCCESS; } @@ -396,6 +421,8 @@ XBSYSAPI EXPORTNUM(49) VOID DECLSPEC_NORETURN xboxkrnl::HalReturnToFirmware RETURN_FIRMWARE Routine ) { + EmuXSwapFS(); // Win2k/XP FS + MessageBox(NULL, "HalReturnToFirmware()", "CxbxKrnl", MB_OK); /* ReturnFirmwareHalt = 0x0, @@ -406,5 +433,7 @@ XBSYSAPI EXPORTNUM(49) VOID DECLSPEC_NORETURN xboxkrnl::HalReturnToFirmware ReturnFirmwareAll = 0x5 */ + EmuXSwapFS(); // XBox FS + exit(1); } \ No newline at end of file