diff --git a/Doc/Todo.txt b/Doc/Todo.txt index 40aa5ff36..fceb22d60 100644 --- a/Doc/Todo.txt +++ b/Doc/Todo.txt @@ -2,15 +2,10 @@ Cxbx Todo: General Code Cleanup [caustik] - - FS: structure construction (EmuXInit) - - - Initialize necessary components of EmuXFS - - SwapFS before *all* Win32/NT calls. - - Debug outputs should be configurable to STDOUT (console) or text file. - - - Passing a ptr to CxbxKrnl is not enough (seperate process) pass the - full DebugFilename. + 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. 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/Include/Win32/CxbxKrnl/CxbxKrnl.h b/Include/Win32/CxbxKrnl/CxbxKrnl.h index be768ae7f..c8b8f11f2 100644 --- a/Include/Win32/CxbxKrnl/CxbxKrnl.h +++ b/Include/Win32/CxbxKrnl/CxbxKrnl.h @@ -76,21 +76,6 @@ CXBXKRNL_API void NTAPI EmuXDummy(); // ****************************************************************** CXBXKRNL_API void NTAPI EmuXPanic(); -// ****************************************************************** -// * _EMUX_KPCR -// ****************************************************************** -// * -// * Emulated Xbox KPCR. Includes special field(s) for emulation -// * purposes. -// * -// ****************************************************************** -typedef struct _EMUX_KPCR -{ - struct xboxkrnl::_KPCR Pcr; - uint16 OriginalFS; // 0x025C (our cached FS register from win2k/XP) -} -EMUX_KPCR, *PEMUX_KPCR; - #if defined(__cplusplus) } #endif diff --git a/Resource/Cxbx.rc b/Resource/Cxbx.rc index 6ac03474d..cea4582ae 100644 --- a/Resource/Cxbx.rc +++ b/Resource/Cxbx.rc @@ -97,7 +97,7 @@ BEGIN POPUP "&Patch", GRAYED BEGIN MENUITEM "&Allow >64 MB", ID_EDIT_PATCH_ALLOW64MB - MENUITEM "Debug Mode", ID_EDIT_PATCH_DEBUGMODE + MENUITEM "&Debug Mode", ID_EDIT_PATCH_DEBUGMODE END MENUITEM SEPARATOR MENUITEM "Extract &Xbe Info...", ID_EDIT_EXTRACTXBEINFO @@ -112,7 +112,7 @@ BEGIN MENUITEM "&File...", ID_VIEW_DEBUGOUTPUTGUI_FILE END - POPUP "Debug Output (Kernel)" + POPUP "Debug Output (&Kernel)" BEGIN MENUITEM "&Console", ID_VIEW_DEBUGOUTPUTKERNEL_CONSOLE diff --git a/Source/Win32/CxbxKrnl/CxbxKrnl.cpp b/Source/Win32/CxbxKrnl/CxbxKrnl.cpp index 7afb8257f..cefe93d3b 100644 --- a/Source/Win32/CxbxKrnl/CxbxKrnl.cpp +++ b/Source/Win32/CxbxKrnl/CxbxKrnl.cpp @@ -84,13 +84,17 @@ inline void EmuXSwapFS() // ****************************************************************** void EmuXGenerateFS() { - uint16 OrgFS = 0; + NT_TIB *OrgNtTib; + xboxkrnl::KPCR *NewPcr; - uint32 dwSize = sizeof(EMUX_KPCR); + uint16 NewFS=0; + uint16 OrgFS=0; - uint32 pNewFS = (uint32)new char[dwSize]; + uint32 dwSize = sizeof(xboxkrnl::KPCR); - uint16 NewFS = LDTAllocate(pNewFS, pNewFS + dwSize); + NewPcr = (xboxkrnl::KPCR*)new char[dwSize]; + + NewFS = LDTAllocate((uint32)NewPcr, (uint32)NewPcr + dwSize); // ****************************************************************** // * Obtain "OrgFS" @@ -101,13 +105,31 @@ void EmuXGenerateFS() mov OrgFS, ax } + // ****************************************************************** + // * Obtain "OrgNtTib" + // ****************************************************************** + __asm + { + mov eax, fs:[0x18] + mov OrgNtTib, eax + } + // ****************************************************************** // * Save "NewFS" inside OrgFS.ArbitraryUserPointer // ****************************************************************** __asm { mov ax, NewFS - mov fs:[0x14], ax // FS.ArbitraryUserPointer + mov fs:[0x14], ax // OrgFS.ArbitraryUserPointer + } + + // ****************************************************************** + // * Generate TIB + // ****************************************************************** + { + memcpy(&NewPcr->NtTib, OrgNtTib, sizeof(NT_TIB)); + + NewPcr->NtTib.Self = &NewPcr->NtTib; } // ****************************************************************** @@ -121,7 +143,7 @@ void EmuXGenerateFS() __asm { mov ax, OrgFS - mov fs:[0x14], ax // FS.ArbitraryUserPointer + mov fs:[0x14], ax // NewFS.ArbitraryUserPointer } // ******************************************************************