FS: Structure emulation.

This commit is contained in:
Aaron Robinson 2003-01-28 23:54:17 +00:00
parent f99df982b1
commit 5fade39fac
4 changed files with 48 additions and 24 deletions

View File

@ -71,7 +71,7 @@ PostBuild_Cmds=cd PostBuild upxCxbx.bat
# PROP Intermediate_Dir "Bin\Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "Include" /I "Include/Win32/" /I "Include/Win32/Cxbxkrnl" /I "Include/Win32/Cxbx" /I "Resource" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "Include" /I "Include/Win32/" /I "Include/Win32/Cxbxkrnl" /I "Include/Win32/Cxbx" /I "Resource" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /YX /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
@ -118,6 +118,10 @@ SOURCE=.\Include\Cxbx.h
# End Source File
# Begin Source File
SOURCE=.\Include\Win32\CxbxKrnl\CxbxKrnl.h
# End Source File
# Begin Source File
SOURCE=.\Include\Win32\Cxbx\EmuExe.h
# End Source File
# Begin Source File
@ -130,10 +134,6 @@ SOURCE=.\Include\Core\Exe.h
# End Source File
# Begin Source File
SOURCE=.\Include\Win32\CxbxKrnl\CxbxKrnl.h
# End Source File
# Begin Source File
SOURCE=.\Include\Win32\Cxbx\Prolog.h
# End Source File
# Begin Source File

View File

@ -2,7 +2,10 @@ Cxbx Todo:
General Code Cleanup [caustik]
FS: structure construction (EmuXInit)
- 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.

View File

@ -60,6 +60,25 @@ namespace win32
using namespace win32;
// ******************************************************************
// * func: EmuXSwapFS
// ******************************************************************
// *
// * This function is used to swap between the native Win2k/XP FS:
// * structure, and the EmuX FS: structure. Before running Windows
// * code, you *must* swap over to Win2k/XP FS. Similarly, before
// * running Xbox code, you *must* swap back over to EmuX FS.
// *
// ******************************************************************
inline void EmuXSwapFS()
{
__asm
{
mov ax, fs:[0x14]
mov fs, ax
}
}
// ******************************************************************
// * func: EmuXGenerateFS
// ******************************************************************
@ -74,7 +93,7 @@ void EmuXGenerateFS()
uint16 NewFS = LDTAllocate(pNewFS, pNewFS + dwSize);
// ******************************************************************
// * Save the "old" FS : [OrgFS = FS]
// * Obtain "OrgFS"
// ******************************************************************
__asm
{
@ -83,15 +102,26 @@ void EmuXGenerateFS()
}
// ******************************************************************
// * Update "new" FS : [FS = NewFS, FS:[0x025C] = OrgFS]
// * Save "NewFS" inside OrgFS.ArbitraryUserPointer
// ******************************************************************
__asm
{
mov ax, NewFS
mov fs, ax
mov fs:[0x14], ax
}
// ******************************************************************
// * Swap into the "NewFS"
// ******************************************************************
EmuXSwapFS();
// ******************************************************************
// * Save "OrgFS" inside NewFS.ArbitraryUserPointer
// ******************************************************************
__asm
{
mov ax, OrgFS
mov fs:[0x025C], ax
mov fs:[0x14], ax
}
}
@ -156,24 +186,17 @@ CXBXKRNL_API void NTAPI EmuXInit(uint32 DebugConsole, uint08 *XBEHeader, uint32
{
EmuXGenerateFS();
// ******************************************************************
// * Restore "old" FS : [FS = FS:[0x025C]]
// ******************************************************************
__asm
{
mov ax, fs:[0x025C]
mov fs, ax
}
EmuXSwapFS();
NT_TIB *dbgTIB = 0;
// TODO: Store EmuX FS structure within the user data offset of Win2k/XP FS: struct
__asm
{
mov esi, fs:[18h]
mov dbgTIB, esi
}
// TODO: Allocate new FS: within LDT, copy OriginalTIB to KPCR.NtTib, load new FS
printf("CxbxKrnl [0x%.08X]: NT_TIB.Self=0x%.08X\n", GetCurrentThreadId(), dbgTIB->Self);
}

View File

@ -76,8 +76,6 @@ void LDTSystemInit()
// ******************************************************************
uint16 LDTAllocate(uint32 dwBaseAddr, uint32 dwLimit)
{
ULONG_PTR uBase = (ULONG_PTR)dwBaseAddr;
xntdll::LDT_ENTRY LDTEntry;
int x=0;
@ -107,9 +105,9 @@ uint16 LDTAllocate(uint32 dwBaseAddr, uint32 dwLimit)
// * Set up selector information
// ******************************************************************
{
LDTEntry.BaseLow = (WORD)(uBase & 0xFFFF);
LDTEntry.HighWord.Bits.BaseMid = (uBase >> 16) & 0xFF;
LDTEntry.HighWord.Bits.BaseHi = (uBase >> 24) & 0xFF;
LDTEntry.BaseLow = (WORD)(dwBaseAddr & 0xFFFF);
LDTEntry.HighWord.Bits.BaseMid = (dwBaseAddr >> 16) & 0xFF;
LDTEntry.HighWord.Bits.BaseHi = (dwBaseAddr >> 24) & 0xFF;
LDTEntry.HighWord.Bits.Type = 0x13; // RW data segment
LDTEntry.HighWord.Bits.Dpl = 3; // user segment
LDTEntry.HighWord.Bits.Pres = 1; // present