From a40fbad03f875e07aed9beb8dd29b00f9d550253 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Fri, 25 Apr 2003 16:55:24 +0000 Subject: [PATCH] *** empty log message *** --- Cxbx.dsp | 2 +- Include/Cxbx.h | 2 +- Source/Win32/CxbxKrnl/Emu.cpp | 26 +++++++++++++++++----- Source/Win32/CxbxKrnl/EmuFS.cpp | 36 ++++++++++++++++++------------- Source/Win32/CxbxKrnl/EmuKrnl.cpp | 4 ++-- Source/Win32/Mutex.cpp | 8 +++---- 6 files changed, 50 insertions(+), 28 deletions(-) diff --git a/Cxbx.dsp b/Cxbx.dsp index 93899db57..fedcdc70b 100644 --- a/Cxbx.dsp +++ b/Cxbx.dsp @@ -1,5 +1,5 @@ # Microsoft Developer Studio Project File - Name="Cxbx" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 60000 +# Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Application" 0x0101 diff --git a/Include/Cxbx.h b/Include/Cxbx.h index 6705651cd..c651cc067 100644 --- a/Include/Cxbx.h +++ b/Include/Cxbx.h @@ -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 diff --git a/Source/Win32/CxbxKrnl/Emu.cpp b/Source/Win32/CxbxKrnl/Emu.cpp index 5733abd76..ad1121804 100644 --- a/Source/Win32/CxbxKrnl/Emu.cpp +++ b/Source/Win32/CxbxKrnl/Emu.cpp @@ -452,13 +452,29 @@ void EmuInstallWrappers(OOVPATable *OovpaTable, uint32 OovpaTableSize, void (*En // ****************************************************************** // * func: EmuException -// ****************************************************************** +// ****************************************************************** int EmuException(LPEXCEPTION_POINTERS e) { - int ret = MessageBox(NULL, "ERROR: Recieved Exception.\n\nPress 'OK' to terminate emulation.\nPress 'Cancel' to debug.", "Cxbx", MB_ICONSTOP | MB_OKCANCEL); - - if(ret == IDOK) - ExitProcess(1); + // ****************************************************************** + // * Debugging Information + // ****************************************************************** + { + printf("\n"); + printf("Recieved Exception : 0x%.08X\n", e->ExceptionRecord->ExceptionCode); + printf("\n"); + } + + // ****************************************************************** + // * Notify User + // ****************************************************************** + { + char buffer[256]; + + sprintf(buffer, "Recieved Exception [0x%.08X]\n\nPress 'OK' to terminate emulation.\nPress 'Cancel' to debug.", e->ExceptionRecord->ExceptionCode); + + if(MessageBox(NULL, buffer, "Cxbx", MB_ICONSTOP | MB_OKCANCEL) == IDOK) + ExitProcess(1); + } return EXCEPTION_CONTINUE_SEARCH; } diff --git a/Source/Win32/CxbxKrnl/EmuFS.cpp b/Source/Win32/CxbxKrnl/EmuFS.cpp index dfdc490e8..b041dc30b 100644 --- a/Source/Win32/CxbxKrnl/EmuFS.cpp +++ b/Source/Win32/CxbxKrnl/EmuFS.cpp @@ -48,9 +48,6 @@ namespace xboxkrnl #undef FIELD_OFFSET // prevent macro redefinition warnings #include -static uint16 g_NewFS = -1; -static uint16 g_OrgFS = -1; - // ****************************************************************** // * func: EmuInitFS // ****************************************************************** @@ -67,6 +64,8 @@ void EmuGenerateFS(int TlsAdjust) NT_TIB *OrgNtTib; xboxkrnl::KPCR *NewPcr; + uint16 NewFS = -1, OrgFS = -1; + void *TLSPtr = 0; // ****************************************************************** @@ -79,7 +78,7 @@ void EmuGenerateFS(int TlsAdjust) memset(NewPcr, 0, sizeof(*NewPcr)); - g_NewFS = EmuAllocateLDT((uint32)NewPcr, (uint32)NewPcr + dwSize); + NewFS = EmuAllocateLDT((uint32)NewPcr, (uint32)NewPcr + dwSize); } // ****************************************************************** @@ -89,15 +88,19 @@ void EmuGenerateFS(int TlsAdjust) { // Obtain "OrgFS" mov ax, fs - mov g_OrgFS, ax + mov OrgFS, ax // Obtain "OrgNtTib" mov eax, fs:[0x18] mov OrgNtTib, eax - // Save "NewFS" inside OrgFS.ArbitraryUserPointer - mov ax, g_NewFS - mov fs:[0x14], ax + // Save "NewFS" inside OrgFS.ArbitraryUserPointer.SwapFS + mov ax, NewFS + mov fs:[0x14], ax + + // Save "True" inside OrgFS.ArbitraryUserPointer.isOrgFS + mov ah, 1 + mov fs:[0x16], ah } // ****************************************************************** @@ -144,8 +147,11 @@ void EmuGenerateFS(int TlsAdjust) // ****************************************************************** __asm { - mov ax, g_OrgFS + mov ax, OrgFS mov fs:[0x14], ax // NewFS.ArbitraryUserPointer + + mov ah, 0 + mov fs:[0x16], ah // NewFS.ArbitraryUserPointer.isOrgFS } // ****************************************************************** @@ -168,13 +174,13 @@ void EmuGenerateFS(int TlsAdjust) // ****************************************************************** bool EmuIsXboxFS() { - uint16 chk = 0; + bool chk = 0; __asm { - mov ax, fs:[0x04] - mov chk, ax - } - - return (g_NewFS == chk); + mov ah, fs:[0x16] + mov chk, ah + } + + return chk; } \ No newline at end of file diff --git a/Source/Win32/CxbxKrnl/EmuKrnl.cpp b/Source/Win32/CxbxKrnl/EmuKrnl.cpp index bfd12fc68..e341e7e06 100644 --- a/Source/Win32/CxbxKrnl/EmuKrnl.cpp +++ b/Source/Win32/CxbxKrnl/EmuKrnl.cpp @@ -124,7 +124,7 @@ static DWORD WINAPI PCSTProxy __try { __asm - { + { mov esi, StartRoutine push StartContext2 push StartContext1 @@ -779,7 +779,7 @@ XBSYSAPI EXPORTNUM(255) NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadEx iPCSTProxyParam->StartContext2 = StartContext2; iPCSTProxyParam->StartRoutine = StartRoutine; - *ThreadHandle = CreateThread(NULL, NULL, &PCSTProxy, iPCSTProxyParam, NULL, &dwThreadId); + *ThreadHandle = CreateThread(NULL, NULL, &PCSTProxy, iPCSTProxyParam, CreateSuspended ? CREATE_SUSPENDED : NULL, &dwThreadId); if(ThreadId != NULL) *ThreadId = dwThreadId; diff --git a/Source/Win32/Mutex.cpp b/Source/Win32/Mutex.cpp index 08894279e..6ac299eb1 100644 --- a/Source/Win32/Mutex.cpp +++ b/Source/Win32/Mutex.cpp @@ -52,8 +52,8 @@ void Mutex::Lock() while(true) { // Grab the lock, letting us look at the variables -// while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0)) - while(InterlockedCompareExchange((LPLONG)&m_MutexLock, (LONG)1, (LONG)0)) + while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0)) +// while(InterlockedCompareExchange((LPLONG)&m_MutexLock, (LONG)1, (LONG)0)) Sleep(1); // Are we the the new owner? @@ -99,8 +99,8 @@ void Mutex::Lock() void Mutex::Unlock() { // Grab the lock, letting us look at the variables -// while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0)) - while (InterlockedCompareExchange((LPLONG)&m_MutexLock, (LONG)1, (LONG)0)) + while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0)) +// while (InterlockedCompareExchange((LPLONG)&m_MutexLock, (LONG)1, (LONG)0)) Sleep(1); // Decrement the lock count