TLS
This commit is contained in:
parent
384fdd5cd2
commit
d8e975fc31
12
Doc/Todo.txt
12
Doc/Todo.txt
|
@ -1,11 +1,15 @@
|
|||
Cxbx Todo:
|
||||
Cxbx Todo (* denotes high priority)
|
||||
|
||||
Retail Games!
|
||||
* Verify TLS stability and correctness
|
||||
|
||||
* 3D Textured Demo
|
||||
|
||||
* Retail Games (esp. XDK 4361)
|
||||
|
||||
* Certain SetRenderState's simply update a global..have Cxbx use these
|
||||
|
||||
Perfect the timing on KeTickCount
|
||||
|
||||
Certain SetRenderState's simply update a global..have Cxbx use these
|
||||
|
||||
Some sort of delete-after-emulation type of functionality?
|
||||
|
||||
Use SetDataFormat instead of parsing device input by hand?
|
||||
|
|
|
@ -66,7 +66,7 @@ typedef signed long sint32;
|
|||
// ******************************************************************
|
||||
// * Define this to trace intercepted function calls
|
||||
// ******************************************************************
|
||||
#define _DEBUG_TRACE
|
||||
//#define _DEBUG_TRACE
|
||||
|
||||
// ******************************************************************
|
||||
// * Round up dwValue to nearest multiple of dwMult
|
||||
|
|
|
@ -49,6 +49,11 @@ extern "C" CXBXKRNL_API void NTAPI EmuNoFunc();
|
|||
// ******************************************************************
|
||||
extern "C" CXBXKRNL_API void NTAPI EmuInit(void *pTLSData, Xbe::TLS *pTLS, Xbe::LibraryVersion *LibraryVersion, DebugMode DbgMode, char *szDebugFilename, Xbe::Header *XbeHeader, uint32 XbeHeaderSize, void (*Entry)());
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuCleanThread
|
||||
// ******************************************************************
|
||||
extern "C" CXBXKRNL_API void NTAPI EmuCleanThread();
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuCleanup
|
||||
// ******************************************************************
|
||||
|
|
|
@ -91,7 +91,7 @@ extern "C" CXBXKRNL_API void NTAPI EmuNoFunc()
|
|||
// ******************************************************************
|
||||
// * func: EmuCleanThread
|
||||
// ******************************************************************
|
||||
static void EmuCleanThread()
|
||||
extern "C" CXBXKRNL_API void NTAPI EmuCleanThread()
|
||||
{
|
||||
if(EmuIsXboxFS())
|
||||
EmuSwapFS(); // Win2k/XP FS
|
||||
|
|
|
@ -161,13 +161,8 @@ DWORD WINAPI EmuUpdateTickCount(LPVOID)
|
|||
{
|
||||
while(true)
|
||||
{
|
||||
LARGE_INTEGER PerformanceCount;
|
||||
|
||||
QueryPerformanceCounter(&PerformanceCount);
|
||||
|
||||
xboxkrnl::KeTickCount = PerformanceCount.LowPart / 3000;
|
||||
|
||||
Sleep(10);
|
||||
xboxkrnl::KeTickCount = GetTickCount();
|
||||
Sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,25 +65,41 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
|
|||
NT_TIB *OrgNtTib;
|
||||
xboxkrnl::KPCR *NewPcr;
|
||||
|
||||
uint16 NewFS = -1, OrgFS = -1;
|
||||
uint08 *pNewTLS = NULL;
|
||||
|
||||
uint16 NewFS = -1, OrgFS = -1;
|
||||
|
||||
// ******************************************************************
|
||||
// * Copy Global TLS to Local
|
||||
// ******************************************************************
|
||||
{
|
||||
uint32 dwSize = RoundUp(pTLS->dwDataEndAddr - pTLS->dwDataStartAddr, 0x04);
|
||||
|
||||
if(dwSize == 0)
|
||||
pNewTLS = 0;
|
||||
else
|
||||
pNewTLS = new uint08[dwSize];
|
||||
|
||||
memcpy(pNewTLS, pTLSData, dwSize);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Dump Raw TLS data
|
||||
// ******************************************************************
|
||||
{
|
||||
#ifdef _DEBUG_TRACE
|
||||
printf("CxbxKrnl (0x%.08X) : Dumping TLS Raw Data... \n 0x%.08X: ", GetCurrentThreadId(), pTLSData);
|
||||
printf("CxbxKrnl (0x%.08X) : Dumping TLS Raw Data... \n 0x%.08X: ", GetCurrentThreadId(), pNewTLS);
|
||||
|
||||
uint32 stop = (pTLS->dwDataEndAddr - pTLS->dwDataStartAddr);
|
||||
uint32 stop = pTLS->dwDataEndAddr - pTLS->dwDataStartAddr;
|
||||
|
||||
for(uint32 v=0;v<stop;v++)
|
||||
{
|
||||
uint08 *bByte = (uint08*)pTLSData + v;
|
||||
uint08 *bByte = (uint08*)pNewTLS + v;
|
||||
|
||||
printf("%.01X", (uint32)*bByte);
|
||||
|
||||
if((v+1) % 0x10 == 0)
|
||||
printf("\n 0x%.08X: ", ((uint32)pTLSData + v));
|
||||
printf("\n 0x%.08X: ", ((uint32)pNewTLS + v));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
@ -145,7 +161,7 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
|
|||
|
||||
NewPcr->Prcb = &NewPcr->PrcbData;
|
||||
|
||||
NewPcr->PrcbData.CurrentThread->TlsData = (void*)pTLSData;
|
||||
NewPcr->PrcbData.CurrentThread->TlsData = (void*)pNewTLS;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
|
@ -156,7 +172,8 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
|
|||
*(uint32*)pTLS->dwTLSIndexAddr = 0;
|
||||
|
||||
// dword @ pTLSData := pTLSData
|
||||
*(void**)pTLSData = pTLSData;
|
||||
if(pNewTLS != 0)
|
||||
*(void**)pNewTLS = pNewTLS;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
|
@ -184,7 +201,7 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
|
|||
{
|
||||
__asm
|
||||
{
|
||||
mov eax, pTLSData
|
||||
mov eax, pNewTLS
|
||||
mov fs:[0x04], eax
|
||||
}
|
||||
}
|
||||
|
@ -216,7 +233,21 @@ void EmuCleanupFS()
|
|||
if(wSwapFS == 0)
|
||||
return;
|
||||
|
||||
// TODO: Cleanup TLS data (after it's implemented)
|
||||
if(!EmuIsXboxFS())
|
||||
EmuSwapFS(); // Xbox FS
|
||||
|
||||
uint08 *pTLSData = NULL;
|
||||
|
||||
__asm
|
||||
{
|
||||
mov eax, fs:[0x04]
|
||||
mov pTLSData, eax
|
||||
}
|
||||
|
||||
EmuSwapFS(); // Win2k/XP FS
|
||||
|
||||
if(pTLSData != 0)
|
||||
delete[] pTLSData;
|
||||
|
||||
EmuDeallocateLDT(wSwapFS);
|
||||
}
|
|
@ -143,9 +143,7 @@ callComplete:
|
|||
|
||||
EmuSwapFS(); // Win2k/XP FS
|
||||
|
||||
MessageBox(NULL, "Thread is all done.", "Cxbx", MB_OK);
|
||||
|
||||
EmuCleanupFS();
|
||||
EmuCleanThread();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue