diff --git a/src/CxbxKrnl/EmuFS.cpp b/src/CxbxKrnl/EmuFS.cpp index 145d20aa9..3627de099 100644 --- a/src/CxbxKrnl/EmuFS.cpp +++ b/src/CxbxKrnl/EmuFS.cpp @@ -92,10 +92,7 @@ void EmuKeSetPcr(xboxkrnl::KPCR *Pcr) // the user data-slot of each Windows thread Cxbx uses for an // Xbox thread. // - __asm { - mov eax, Pcr - mov fs : [TIB_ArbitraryDataSlot], eax - } + __writefsdword(TIB_ArbitraryDataSlot, (DWORD)Pcr); } __declspec(naked) void EmuFS_CmpEsiFs00() diff --git a/src/CxbxKrnl/EmuKrnlKe.cpp b/src/CxbxKrnl/EmuKrnlKe.cpp index 230ee71ec..51fb5d0d2 100644 --- a/src/CxbxKrnl/EmuKrnlKe.cpp +++ b/src/CxbxKrnl/EmuKrnlKe.cpp @@ -138,12 +138,16 @@ BOOLEAN KiInsertTreeTimer( // ****************************************************************** xboxkrnl::KPCR* KeGetPcr() { - xboxkrnl::KPCR* Pcr; + xboxkrnl::PKPCR Pcr; // See EmuKeSetPcr() - __asm { - mov eax, fs : [TIB_ArbitraryDataSlot] - mov Pcr, eax + Pcr = (xboxkrnl::PKPCR)__readfsdword(TIB_ArbitraryDataSlot); + + if (Pcr == nullptr) { + EmuWarning("KeGetPCR returned nullptr: Was this called from a non-xbox thread?"); + // Attempt to salvage the situation by calling InitXboxThread to setup KPCR in place + InitXboxThread(g_CPUXbox); + Pcr = (xboxkrnl::PKPCR)__readfsdword(TIB_ArbitraryDataSlot); } return Pcr;