diff --git a/Cxbe.vcproj b/Cxbe.vcproj index c37a4b258..14c706d02 100644 --- a/Cxbe.vcproj +++ b/Cxbe.vcproj @@ -134,6 +134,19 @@ + + + + + + + + @@ -156,6 +169,10 @@ RelativePath=".\Include\Core\Xbe.h"> + + @@ -172,14 +189,6 @@ RelativePath=".\Source\Core\Xbe.cpp"> - - - - diff --git a/Cxbx.vcproj b/Cxbx.vcproj index 633d8f450..9caa743ab 100644 --- a/Cxbx.vcproj +++ b/Cxbx.vcproj @@ -132,6 +132,27 @@ upxCxbx.bat + + + + + + + + + + + + @@ -144,6 +165,9 @@ upxCxbx.bat + + @@ -153,9 +177,6 @@ upxCxbx.bat - - @@ -234,18 +255,6 @@ upxCxbx.bat RelativePath=".\Source\Core\Xbe.cpp"> - - - - - - diff --git a/CxbxKrnl.vcproj b/CxbxKrnl.vcproj index e9064391b..6199f05a7 100644 --- a/CxbxKrnl.vcproj +++ b/CxbxKrnl.vcproj @@ -129,6 +129,27 @@ + + + + + + + + + + + + @@ -142,6 +163,10 @@ RelativePath=".\Include\Win32\CxbxKrnl\xntdll.h"> + + @@ -155,22 +180,6 @@ RelativePath="Source\Win32\CxbxKrnl\LDT.cpp"> - - - - - - - - diff --git a/Doc/Thanks.txt b/Doc/Thanks.txt index c640e19fe..eba4013e1 100644 --- a/Doc/Thanks.txt +++ b/Doc/Thanks.txt @@ -1 +1 @@ -Special Thanks to the authors of UPX file compressor (http://upx.sourceforge.net/). \ No newline at end of file +Special thanks to the authors of UPX file compressor (http://upx.sourceforge.net/). \ No newline at end of file diff --git a/Include/Win32/CxbxKrnl/CxbxKrnl.h b/Include/Win32/CxbxKrnl/CxbxKrnl.h index ce58c8ae1..0dc5d3cfa 100644 --- a/Include/Win32/CxbxKrnl/CxbxKrnl.h +++ b/Include/Win32/CxbxKrnl/CxbxKrnl.h @@ -76,6 +76,21 @@ 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/Source/Win32/CxbxKrnl/CxbxKrnl.cpp b/Source/Win32/CxbxKrnl/CxbxKrnl.cpp index 8191b1877..d350eccdf 100644 --- a/Source/Win32/CxbxKrnl/CxbxKrnl.cpp +++ b/Source/Win32/CxbxKrnl/CxbxKrnl.cpp @@ -65,36 +65,33 @@ using namespace win32; // ****************************************************************** void EmuXGenerateFS() { - NT_TIB *OrgFS = 0; + uint16 OrgFS = 0; - uint32 dwFSSize = sizeof(NT_TIB); + uint32 dwSize = sizeof(EMUX_KPCR); + + uint32 pNewFS = (uint32)new char[dwSize]; + + uint16 NewFS = LDTAllocate(pNewFS, pNewFS + dwSize); // ****************************************************************** - // * Retrieve the "old" FS + // * Save the "old" FS : [OrgFS = FS] // ****************************************************************** __asm { - mov esi, fs:[18h] - mov OrgFS, esi + mov ax, fs + mov OrgFS, ax } // ****************************************************************** - // * Allocate and update the new FS + // * Update "new" FS : [FS = NewFS, FS:[0x025C] = OrgFS] // ****************************************************************** + __asm { - uint32 AllocFS = (uint32)new char[dwFSSize]; + mov ax, NewFS + mov fs, ax - memcpy((void*)AllocFS, OrgFS, dwFSSize); - - uint16 SelectorFS = LDTAllocate(AllocFS, AllocFS+dwFSSize); - - __asm - { - mov ax, SelectorFS - - push ax - pop fs - } + mov ax, OrgFS + mov fs:[0x025C], ax } } @@ -157,13 +154,16 @@ CXBXKRNL_API void NTAPI EmuXInit(uint32 DebugConsole, uint08 *XBEHeader, uint32 // * Initialize FS:* structure // ****************************************************************** { - // Calling this function will overwrite the Win2k/XP FS: structure, - // which will cause an immediate or eventual crash. In order to avoid - // this, it is going to be necessary to store the Win2k/XP FS: in a - // special un-used slot in the XBox FS:* structure, and bring it back - // in whenever we need to use Win2k/XP functions + EmuXGenerateFS(); - // EmuXGenerateFS(); + // ****************************************************************** + // * Restore "old" FS : [FS = FS:[0x025C]] + // ****************************************************************** + __asm + { + mov ax, fs:[0x025C] + mov fs, ax + } NT_TIB *dbgTIB = 0;