diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eb6ac0995..d23faa31a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ env: jobs: build-ubuntu: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: "Checkout repo" uses: actions/checkout@v3 @@ -53,7 +53,7 @@ jobs: - name: "Install system dependencies" run: | sudo apt update -qq - sudo apt install -y clang-12 cmake freeglut3-dev libgcrypt20-dev libglm-dev libgtk-3-dev libpulse-dev libsecret-1-dev libsystemd-dev libudev-dev nasm ninja-build + sudo apt install -y clang-15 cmake freeglut3-dev libgcrypt20-dev libglm-dev libgtk-3-dev libpulse-dev libsecret-1-dev libsystemd-dev libudev-dev nasm ninja-build - name: "Bootstrap vcpkg" run: | @@ -75,7 +75,7 @@ jobs: - name: "cmake" run: | - cmake -S . -B build ${{ env.BUILD_FLAGS }} -DCMAKE_BUILD_TYPE=${{ env.BUILD_MODE }} -DPORTABLE=OFF -DCMAKE_C_COMPILER=/usr/bin/clang-12 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-12 -G Ninja -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja + cmake -S . -B build ${{ env.BUILD_FLAGS }} -DCMAKE_BUILD_TYPE=${{ env.BUILD_MODE }} -DPORTABLE=OFF -DCMAKE_C_COMPILER=/usr/bin/clang-15 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-15 -G Ninja -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja - name: "Build Cemu" run: | @@ -93,7 +93,7 @@ jobs: path: ./bin/Cemu build-appimage: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: build-ubuntu steps: - name: Checkout Upstream Repo @@ -107,7 +107,7 @@ jobs: - name: "Install system dependencies" run: | sudo apt update -qq - sudo apt install -y clang-12 cmake freeglut3-dev libgcrypt20-dev libglm-dev libgtk-3-dev libpulse-dev libsecret-1-dev libsystemd-dev nasm ninja-build appstream + sudo apt install -y clang-15 cmake freeglut3-dev libgcrypt20-dev libglm-dev libgtk-3-dev libpulse-dev libsecret-1-dev libsystemd-dev nasm ninja-build appstream - name: "Build AppImage" run: | diff --git a/.github/workflows/deploy_experimental_release.yml b/.github/workflows/deploy_experimental_release.yml index 9296c1cc0..3bf86db42 100644 --- a/.github/workflows/deploy_experimental_release.yml +++ b/.github/workflows/deploy_experimental_release.yml @@ -10,7 +10,7 @@ jobs: experimentalversion: ${{ github.run_number }} deploy: name: Deploy experimental release - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: call-release-build steps: - uses: actions/checkout@v3 @@ -72,7 +72,7 @@ jobs: ls ./bin/ cp -R ./bin ./${{ env.CEMU_FOLDER_NAME }} mv cemu-bin-linux-x64/Cemu ./${{ env.CEMU_FOLDER_NAME }}/Cemu - zip -9 -r upload/cemu-${{ env.CEMU_VERSION }}-ubuntu-20.04-x64.zip ${{ env.CEMU_FOLDER_NAME }} + zip -9 -r upload/cemu-${{ env.CEMU_VERSION }}-ubuntu-22.04-x64.zip ${{ env.CEMU_FOLDER_NAME }} rm -r ./${{ env.CEMU_FOLDER_NAME }} - name: Create release from macos-bin diff --git a/.gitignore b/.gitignore index 9e9ff7df2..18f14cf33 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ .idea/ build/ -cmake-build-*-*/ +cmake-build-*/ out/ .cache/ bin/Cemu_* diff --git a/BUILD.md b/BUILD.md index c63251d7a..e4993ca1f 100644 --- a/BUILD.md +++ b/BUILD.md @@ -19,17 +19,17 @@ Any other IDE should also work as long as it has CMake and MSVC support. CLion a ## Linux -To compile Cemu, a recent enough compiler and STL with C++20 support is required! clang-12 or higher is what we recommend. +To compile Cemu, a recent enough compiler and STL with C++20 support is required! clang-15 or higher is what we recommend. ### Installing dependencies #### For Ubuntu and derivatives: -`sudo apt install -y cmake curl freeglut3-dev git libgcrypt20-dev libglm-dev libgtk-3-dev libpulse-dev libsecret-1-dev libsystemd-dev nasm ninja-build` +`sudo apt install -y cmake curl clang-15 freeglut3-dev git libgcrypt20-dev libglm-dev libgtk-3-dev libpulse-dev libsecret-1-dev libsystemd-dev nasm ninja-build` -*Additionally, for Ubuntu 22.04 only:* - - `sudo apt install -y clang-12` - - At step 3 while building, use - `cmake -S . -B build -DCMAKE_BUILD_TYPE=release -DCMAKE_C_COMPILER=/usr/bin/clang-12 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-12 -G Ninja -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja` +You may also need to install `libusb-1.0-0-dev` as a workaround for an issue with the vcpkg hidapi package. + +At step 3 while building, use: + `cmake -S . -B build -DCMAKE_BUILD_TYPE=release -DCMAKE_C_COMPILER=/usr/bin/clang-15 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-15 -G Ninja -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja` #### For Arch and derivatives: `sudo pacman -S --needed base-devel clang cmake freeglut git glm gtk3 libgcrypt libpulse libsecret linux-headers llvm nasm ninja systemd unzip zip` diff --git a/generate_vs_solution.bat b/generate_vs_solution.bat deleted file mode 100644 index 21060027e..000000000 --- a/generate_vs_solution.bat +++ /dev/null @@ -1,2 +0,0 @@ -"C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -B build/ -pause \ No newline at end of file diff --git a/src/Cafe/HW/Espresso/Debugger/Debugger.cpp b/src/Cafe/HW/Espresso/Debugger/Debugger.cpp index 6c15f26e1..e99ce5220 100644 --- a/src/Cafe/HW/Espresso/Debugger/Debugger.cpp +++ b/src/Cafe/HW/Espresso/Debugger/Debugger.cpp @@ -210,7 +210,8 @@ void debugger_handleSingleStepException(uint64 dr6) } if (catchBP) { - debugger_createCodeBreakpoint(ppcInterpreterCurrentInstance->instructionPointer + 4, DEBUGGER_BP_T_ONE_SHOT); + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); + debugger_createCodeBreakpoint(hCPU->instructionPointer + 4, DEBUGGER_BP_T_ONE_SHOT); } } diff --git a/src/Cafe/HW/Espresso/Debugger/GDBStub.cpp b/src/Cafe/HW/Espresso/Debugger/GDBStub.cpp index d83ea46be..b7e154075 100644 --- a/src/Cafe/HW/Espresso/Debugger/GDBStub.cpp +++ b/src/Cafe/HW/Espresso/Debugger/GDBStub.cpp @@ -959,8 +959,9 @@ void GDBServer::HandleAccessException(uint64 dr6) if (!response.empty()) { + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); cemuLog_logDebug(LogType::Force, "Received matching breakpoint exception: {}", response); - auto nextInstructions = findNextInstruction(ppcInterpreterCurrentInstance->instructionPointer, ppcInterpreterCurrentInstance->spr.LR, ppcInterpreterCurrentInstance->spr.CTR); + auto nextInstructions = findNextInstruction(hCPU->instructionPointer, hCPU->spr.LR, hCPU->spr.CTR); for (MPTR nextInstr : nextInstructions) { auto bpIt = m_patchedInstructions.find(nextInstr); diff --git a/src/Cafe/HW/Espresso/Interpreter/PPCInterpreterMain.cpp b/src/Cafe/HW/Espresso/Interpreter/PPCInterpreterMain.cpp index 2d808fef5..a9ab49a55 100644 --- a/src/Cafe/HW/Espresso/Interpreter/PPCInterpreterMain.cpp +++ b/src/Cafe/HW/Espresso/Interpreter/PPCInterpreterMain.cpp @@ -6,7 +6,6 @@ thread_local PPCInterpreter_t* ppcInterpreterCurrentInstance; // main thread instruction counter and timing -volatile uint64 ppcMainThreadCycleCounter = 0; uint64 ppcMainThreadDECCycleValue = 0; // value that was set to dec register uint64 ppcMainThreadDECCycleStart = 0; // at which cycle the dec register was set, if == 0 -> dec is 0 uint64 ppcCyclesSince2000 = 0; @@ -29,11 +28,16 @@ PPCInterpreter_t* PPCInterpreter_createInstance(unsigned int Entrypoint) return pData; } -PPCInterpreter_t* PPCInterpreter_getCurrentInstance() +TLS_WORKAROUND_NOINLINE PPCInterpreter_t* PPCInterpreter_getCurrentInstance() { return ppcInterpreterCurrentInstance; } +TLS_WORKAROUND_NOINLINE void PPCInterpreter_setCurrentInstance(PPCInterpreter_t* hCPU) +{ + ppcInterpreterCurrentInstance = hCPU; +} + uint64 PPCInterpreter_getMainCoreCycleCounter() { return PPCTimer_getFromRDTSC(); @@ -78,24 +82,25 @@ uint32 PPCInterpreter_getCoreIndex(PPCInterpreter_t* hCPU) uint32 PPCInterpreter_getCurrentCoreIndex() { - return ppcInterpreterCurrentInstance->spr.UPIR; + return PPCInterpreter_getCurrentInstance()->spr.UPIR; }; uint8* PPCInterpreterGetStackPointer() { - return memory_getPointerFromVirtualOffset(ppcInterpreterCurrentInstance->gpr[1]); + return memory_getPointerFromVirtualOffset(PPCInterpreter_getCurrentInstance()->gpr[1]); } uint8* PPCInterpreterGetAndModifyStackPointer(sint32 offset) { - uint8* result = memory_getPointerFromVirtualOffset(ppcInterpreterCurrentInstance->gpr[1] - offset); - ppcInterpreterCurrentInstance->gpr[1] -= offset; + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); + uint8* result = memory_getPointerFromVirtualOffset(hCPU->gpr[1] - offset); + hCPU->gpr[1] -= offset; return result; } void PPCInterpreterModifyStackPointer(sint32 offset) { - ppcInterpreterCurrentInstance->gpr[1] -= offset; + PPCInterpreter_getCurrentInstance()->gpr[1] -= offset; } uint32 RPLLoader_MakePPCCallable(void(*ppcCallableExport)(PPCInterpreter_t* hCPU)); diff --git a/src/Cafe/HW/Espresso/PPCCallback.h b/src/Cafe/HW/Espresso/PPCCallback.h index fd790f0cc..19fcd4d1c 100644 --- a/src/Cafe/HW/Espresso/PPCCallback.h +++ b/src/Cafe/HW/Espresso/PPCCallback.h @@ -18,19 +18,20 @@ uint32 PPCCoreCallback(MPTR function, PPCCoreCallbackData_t& data, T currentArg, { cemu_assert_debug(data.gprCount <= 8); cemu_assert_debug(data.floatCount <= 8); + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); if constexpr (std::is_pointer_v) { - ppcInterpreterCurrentInstance->gpr[3 + data.gprCount] = MEMPTR(currentArg).GetMPTR(); + hCPU->gpr[3 + data.gprCount] = MEMPTR(currentArg).GetMPTR(); data.gprCount++; } else if constexpr (std::is_base_of_v>) { - ppcInterpreterCurrentInstance->gpr[3 + data.gprCount] = currentArg.GetMPTR(); + hCPU->gpr[3 + data.gprCount] = currentArg.GetMPTR(); data.gprCount++; } else if constexpr (std::is_reference_v) { - ppcInterpreterCurrentInstance->gpr[3 + data.gprCount] = MEMPTR(¤tArg).GetMPTR(); + hCPU->gpr[3 + data.gprCount] = MEMPTR(¤tArg).GetMPTR(); data.gprCount++; } else if constexpr(std::is_enum_v) @@ -40,19 +41,19 @@ uint32 PPCCoreCallback(MPTR function, PPCCoreCallbackData_t& data, T currentArg, } else if constexpr (std::is_floating_point_v) { - ppcInterpreterCurrentInstance->fpr[1 + data.floatCount].fpr = (double)currentArg; + hCPU->fpr[1 + data.floatCount].fpr = (double)currentArg; data.floatCount++; } else if constexpr (std::is_integral_v && sizeof(T) == sizeof(uint64)) { - ppcInterpreterCurrentInstance->gpr[3 + data.gprCount] = (uint32)(currentArg >> 32); // high - ppcInterpreterCurrentInstance->gpr[3 + data.gprCount + 1] = (uint32)currentArg; // low + hCPU->gpr[3 + data.gprCount] = (uint32)(currentArg >> 32); // high + hCPU->gpr[3 + data.gprCount + 1] = (uint32)currentArg; // low data.gprCount += 2; } else { - ppcInterpreterCurrentInstance->gpr[3 + data.gprCount] = (uint32)currentArg; + hCPU->gpr[3 + data.gprCount] = (uint32)currentArg; data.gprCount++; } diff --git a/src/Cafe/HW/Espresso/PPCScheduler.cpp b/src/Cafe/HW/Espresso/PPCScheduler.cpp index 2a3a4aaaa..a4c04aaaa 100644 --- a/src/Cafe/HW/Espresso/PPCScheduler.cpp +++ b/src/Cafe/HW/Espresso/PPCScheduler.cpp @@ -11,21 +11,24 @@ uint32 ppcThreadQuantum = 45000; // execute 45000 instructions before thread res void PPCInterpreter_relinquishTimeslice() { - if( ppcInterpreterCurrentInstance->remainingCycles >= 0 ) + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); + if( hCPU->remainingCycles >= 0 ) { - ppcInterpreterCurrentInstance->skippedCycles = ppcInterpreterCurrentInstance->remainingCycles + 1; - ppcInterpreterCurrentInstance->remainingCycles = -1; + hCPU->skippedCycles = hCPU->remainingCycles + 1; + hCPU->remainingCycles = -1; } } void PPCCore_boostQuantum(sint32 numCycles) { - ppcInterpreterCurrentInstance->remainingCycles += numCycles; + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); + hCPU->remainingCycles += numCycles; } void PPCCore_deboostQuantum(sint32 numCycles) { - ppcInterpreterCurrentInstance->remainingCycles -= numCycles; + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); + hCPU->remainingCycles -= numCycles; } namespace coreinit @@ -36,7 +39,7 @@ namespace coreinit void PPCCore_switchToScheduler() { cemu_assert_debug(__OSHasSchedulerLock() == false); // scheduler lock must not be hold past thread time slice - cemu_assert_debug(ppcInterpreterCurrentInstance->coreInterruptMask != 0 || CafeSystem::GetForegroundTitleId() == 0x000500001019e600); + cemu_assert_debug(PPCInterpreter_getCurrentInstance()->coreInterruptMask != 0 || CafeSystem::GetForegroundTitleId() == 0x000500001019e600); __OSLockScheduler(); coreinit::__OSThreadSwitchToNext(); __OSUnlockScheduler(); @@ -45,7 +48,7 @@ void PPCCore_switchToScheduler() void PPCCore_switchToSchedulerWithLock() { cemu_assert_debug(__OSHasSchedulerLock() == true); // scheduler lock must be hold - cemu_assert_debug(ppcInterpreterCurrentInstance->coreInterruptMask != 0 || CafeSystem::GetForegroundTitleId() == 0x000500001019e600); + cemu_assert_debug(PPCInterpreter_getCurrentInstance()->coreInterruptMask != 0 || CafeSystem::GetForegroundTitleId() == 0x000500001019e600); coreinit::__OSThreadSwitchToNext(); } @@ -58,7 +61,7 @@ void _PPCCore_callbackExit(PPCInterpreter_t* hCPU) PPCInterpreter_t* PPCCore_executeCallbackInternal(uint32 functionMPTR) { cemu_assert_debug(functionMPTR != 0); - PPCInterpreter_t* hCPU = ppcInterpreterCurrentInstance; + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); // remember LR and instruction pointer uint32 lr = hCPU->spr.LR; uint32 ip = hCPU->instructionPointer; diff --git a/src/Cafe/HW/Espresso/PPCSchedulerLLE.cpp b/src/Cafe/HW/Espresso/PPCSchedulerLLE.cpp index 8ef54256a..bb4bf9fff 100644 --- a/src/Cafe/HW/Espresso/PPCSchedulerLLE.cpp +++ b/src/Cafe/HW/Espresso/PPCSchedulerLLE.cpp @@ -220,7 +220,7 @@ void PPCCoreLLE_startSingleCoreScheduler(uint32 entrypoint) for (uint32 coreIndex = 0; coreIndex < 3; coreIndex++) { PPCInterpreter_t* hCPU = cpuContext->cores+coreIndex; - ppcInterpreterCurrentInstance = hCPU; + PPCInterpreter_setCurrentInstance(hCPU); if (coreIndex == 1) { // check SCR core 1 enable bit diff --git a/src/Cafe/HW/Espresso/PPCState.h b/src/Cafe/HW/Espresso/PPCState.h index 2b30326b5..85b2dc046 100644 --- a/src/Cafe/HW/Espresso/PPCState.h +++ b/src/Cafe/HW/Espresso/PPCState.h @@ -149,6 +149,7 @@ static uint64 PPCInterpreter_getCallParamU64(PPCInterpreter_t* hCPU, uint32 inde PPCInterpreter_t* PPCInterpreter_createInstance(unsigned int Entrypoint); PPCInterpreter_t* PPCInterpreter_getCurrentInstance(); +void PPCInterpreter_setCurrentInstance(PPCInterpreter_t* hCPU); uint64 PPCInterpreter_getMainCoreCycleCounter(); @@ -192,7 +193,6 @@ uint32 PPCInterpreter_getCurrentCoreIndex(); void PPCInterpreter_setDEC(PPCInterpreter_t* hCPU, uint32 newValue); // timing for main processor -extern volatile uint64 ppcMainThreadCycleCounter; extern uint64 ppcCyclesSince2000; // on init this is set to the cycles that passed since 1.1.2000 extern uint64 ppcCyclesSince2000TimerClock; // on init this is set to the cycles that passed since 1.1.2000 / 20 extern uint64 ppcCyclesSince2000_UTC; @@ -213,7 +213,6 @@ void PPCTimer_start(); // core info and control extern uint32 ppcThreadQuantum; -extern thread_local PPCInterpreter_t *ppcInterpreterCurrentInstance; uint8* PPCInterpreterGetAndModifyStackPointer(sint32 offset); uint8* PPCInterpreterGetStackPointer(); void PPCInterpreterModifyStackPointer(sint32 offset); diff --git a/src/Cafe/HW/Espresso/Recompiler/PPCRecompilerX64.cpp b/src/Cafe/HW/Espresso/Recompiler/PPCRecompilerX64.cpp index 14d2febb2..a30295b57 100644 --- a/src/Cafe/HW/Espresso/Recompiler/PPCRecompilerX64.cpp +++ b/src/Cafe/HW/Espresso/Recompiler/PPCRecompilerX64.cpp @@ -100,7 +100,7 @@ void* ATTR_MS_ABI PPCRecompiler_virtualHLE(PPCInterpreter_t* hCPU, uint32 hleFun hCPU->remainingCycles -= 500; // let subtract about 500 cycles for each HLE call hCPU->gpr[3] = 0; PPCInterpreter_nextInstruction(hCPU); - return ppcInterpreterCurrentInstance; + return hCPU; } else { @@ -109,7 +109,7 @@ void* ATTR_MS_ABI PPCRecompiler_virtualHLE(PPCInterpreter_t* hCPU, uint32 hleFun hleCall(hCPU); } hCPU->rspTemp = prevRSPTemp; - return ppcInterpreterCurrentInstance; + return PPCInterpreter_getCurrentInstance(); } void ATTR_MS_ABI PPCRecompiler_getTBL(PPCInterpreter_t* hCPU, uint32 gprIndex) diff --git a/src/Cafe/IOSU/legacy/iosu_ioctl.cpp b/src/Cafe/IOSU/legacy/iosu_ioctl.cpp index 00be31b08..1fc2a27a4 100644 --- a/src/Cafe/IOSU/legacy/iosu_ioctl.cpp +++ b/src/Cafe/IOSU/legacy/iosu_ioctl.cpp @@ -23,7 +23,7 @@ sint32 iosuIoctl_pushAndWait(uint32 ioctlHandle, ioQueueEntry_t* ioQueueEntry) } __OSLockScheduler(); ioctlMutex.lock(); - ioQueueEntry->ppcThread = coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance); + ioQueueEntry->ppcThread = coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()); _ioctlRingbuffer[ioctlHandle].Push(ioQueueEntry); ioctlMutex.unlock(); diff --git a/src/Cafe/OS/common/OSUtil.h b/src/Cafe/OS/common/OSUtil.h index 9bf8480bc..6801f6af1 100644 --- a/src/Cafe/OS/common/OSUtil.h +++ b/src/Cafe/OS/common/OSUtil.h @@ -65,7 +65,7 @@ class cafeExportParamWrapper } else if constexpr (std::is_floating_point_v) { - v = (T)ppcInterpreterCurrentInstance->fpr[1 + fprIndex].fpr; + v = (T)hCPU->fpr[1 + fprIndex].fpr; fprIndex++; } else diff --git a/src/Cafe/OS/libs/coreinit/coreinit.cpp b/src/Cafe/OS/libs/coreinit/coreinit.cpp index e8e4ce1f2..8738e3a4a 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit.cpp @@ -204,7 +204,7 @@ namespace coreinit { sint32 OSGetCoreId() { - return PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance); + return PPCInterpreter_getCoreIndex(PPCInterpreter_getCurrentInstance()); } uint32 OSGetCoreCount() @@ -239,7 +239,7 @@ namespace coreinit uint32 OSGetStackPointer() { - return ppcInterpreterCurrentInstance->gpr[1]; + return PPCInterpreter_getCurrentInstance()->gpr[1]; } void coreinitExport_ENVGetEnvironmentVariable(PPCInterpreter_t* hCPU) diff --git a/src/Cafe/OS/libs/coreinit/coreinit_FS.cpp b/src/Cafe/OS/libs/coreinit/coreinit_FS.cpp index a2f59d4db..916563c89 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_FS.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_FS.cpp @@ -691,7 +691,7 @@ namespace coreinit while (OSSendMessage(ioMsgQueue, &fsCmdBlockBody->asyncResult.msgUnion.osMsg, 0) == 0) { cemuLog_log(LogType::Force, "FS driver: Failed to add message to result queue. Retrying..."); - if (ppcInterpreterCurrentInstance) + if (PPCInterpreter_getCurrentInstance()) PPCCore_switchToScheduler(); else std::this_thread::sleep_for(std::chrono::milliseconds(10)); diff --git a/src/Cafe/OS/libs/coreinit/coreinit_Init.cpp b/src/Cafe/OS/libs/coreinit/coreinit_Init.cpp index 51a3f5426..72f6ac117 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_Init.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_Init.cpp @@ -142,10 +142,11 @@ void CafeInit() } } // setup UGQR - ppcInterpreterCurrentInstance->spr.UGQR[0 + 2] = 0x00040004; - ppcInterpreterCurrentInstance->spr.UGQR[0 + 3] = 0x00050005; - ppcInterpreterCurrentInstance->spr.UGQR[0 + 4] = 0x00060006; - ppcInterpreterCurrentInstance->spr.UGQR[0 + 5] = 0x00070007; + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); + hCPU->spr.UGQR[0 + 2] = 0x00040004; + hCPU->spr.UGQR[0 + 3] = 0x00050005; + hCPU->spr.UGQR[0 + 4] = 0x00060006; + hCPU->spr.UGQR[0 + 5] = 0x00070007; coreinit::InitForegroundBucket(); coreinit::InitSysHeap(); } diff --git a/src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp b/src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp index 05660c71d..d5cd0018c 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_Misc.cpp @@ -235,7 +235,7 @@ namespace coreinit sint32 __os_snprintf(char* outputStr, sint32 maxLength, const char* formatStr) { - sint32 r = ppcSprintf(formatStr, outputStr, maxLength, ppcInterpreterCurrentInstance, 3); + sint32 r = ppcSprintf(formatStr, outputStr, maxLength, PPCInterpreter_getCurrentInstance(), 3); return r; } @@ -303,7 +303,7 @@ namespace coreinit void OSReport(const char* format) { char buffer[1024 * 2]; - sint32 len = ppcSprintf(format, buffer, sizeof(buffer), ppcInterpreterCurrentInstance, 1); + sint32 len = ppcSprintf(format, buffer, sizeof(buffer), PPCInterpreter_getCurrentInstance(), 1); WriteCafeConsole(CafeLogType::OSCONSOLE, buffer, len); } @@ -316,7 +316,7 @@ namespace coreinit { char buffer[1024 * 2]; int prefixLen = sprintf(buffer, "[COSWarn-%d] ", moduleId); - sint32 len = ppcSprintf(format, buffer + prefixLen, sizeof(buffer) - prefixLen, ppcInterpreterCurrentInstance, 2); + sint32 len = ppcSprintf(format, buffer + prefixLen, sizeof(buffer) - prefixLen, PPCInterpreter_getCurrentInstance(), 2); WriteCafeConsole(CafeLogType::OSCONSOLE, buffer, len + prefixLen); } @@ -324,7 +324,7 @@ namespace coreinit { char buffer[1024 * 2]; int prefixLen = sprintf(buffer, "[OSLogPrintf-%d-%d-%d] ", ukn1, ukn2, ukn3); - sint32 len = ppcSprintf(format, buffer + prefixLen, sizeof(buffer) - prefixLen, ppcInterpreterCurrentInstance, 4); + sint32 len = ppcSprintf(format, buffer + prefixLen, sizeof(buffer) - prefixLen, PPCInterpreter_getCurrentInstance(), 4); WriteCafeConsole(CafeLogType::OSCONSOLE, buffer, len + prefixLen); } diff --git a/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp b/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp index 59bd034e6..71e5d4939 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp @@ -305,7 +305,7 @@ namespace coreinit affinityMask = attr & 0x7; // if no core is selected -> set current one if (affinityMask == 0) - affinityMask |= (1 << PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance)); + affinityMask |= (1 << PPCInterpreter_getCoreIndex(PPCInterpreter_getCurrentInstance())); // set attr // todo: Support for other attr bits thread->attr = (affinityMask & 0xFF) | (attr & OSThread_t::ATTR_BIT::ATTR_DETACHED); @@ -325,7 +325,7 @@ namespace coreinit { __OSLockScheduler(); - cemu_assert_debug(ppcInterpreterCurrentInstance == nullptr || OSGetCurrentThread() != thread); // called on self, what should this function do? + cemu_assert_debug(PPCInterpreter_getCurrentInstance() == nullptr || OSGetCurrentThread() != thread); // called on self, what should this function do? if (thread->state != OSThread_t::THREAD_STATE::STATE_NONE && thread->state != OSThread_t::THREAD_STATE::STATE_MORIBUND) { @@ -607,7 +607,7 @@ namespace coreinit // todo - only set this once? thread->wakeUpTime = PPCInterpreter_getMainCoreCycleCounter(); // reschedule if thread has higher priority - if (ppcInterpreterCurrentInstance && __OSCoreShouldSwitchToThread(coreinit::OSGetCurrentThread(), thread)) + if (PPCInterpreter_getCurrentInstance() && __OSCoreShouldSwitchToThread(coreinit::OSGetCurrentThread(), thread)) PPCCore_switchToSchedulerWithLock(); } return previousSuspendCount; @@ -930,17 +930,17 @@ namespace coreinit thread->requestFlags = (OSThread_t::REQUEST_FLAG_BIT)(thread->requestFlags & OSThread_t::REQUEST_FLAG_CANCEL); // remove all flags except cancel flag // update total cycles - uint64 remainingCycles = std::min((uint64)ppcInterpreterCurrentInstance->remainingCycles, (uint64)thread->quantumTicks); + uint64 remainingCycles = std::min((uint64)hCPU->remainingCycles, (uint64)thread->quantumTicks); uint64 executedCycles = thread->quantumTicks - remainingCycles; - if (executedCycles < ppcInterpreterCurrentInstance->skippedCycles) + if (executedCycles < hCPU->skippedCycles) executedCycles = 0; else - executedCycles -= ppcInterpreterCurrentInstance->skippedCycles; + executedCycles -= hCPU->skippedCycles; thread->totalCycles += executedCycles; // store context and set current thread to null __OSThreadStoreContext(hCPU, thread); OSSetCurrentThread(OSGetCoreId(), nullptr); - ppcInterpreterCurrentInstance = nullptr; + PPCInterpreter_setCurrentInstance(nullptr); } void __OSLoadThread(OSThread_t* thread, PPCInterpreter_t* hCPU, uint32 coreIndex) @@ -951,7 +951,7 @@ namespace coreinit hCPU->reservedMemValue = 0; hCPU->spr.UPIR = coreIndex; hCPU->coreInterruptMask = 1; - ppcInterpreterCurrentInstance = hCPU; + PPCInterpreter_setCurrentInstance(hCPU); OSSetCurrentThread(OSGetCoreId(), thread); __OSThreadLoadContext(hCPU, thread); thread->context.upir = coreIndex; @@ -1076,7 +1076,7 @@ namespace coreinit // store context of current thread __OSStoreThread(OSGetCurrentThread(), &hostThread->ppcInstance); - cemu_assert_debug(ppcInterpreterCurrentInstance == nullptr); + cemu_assert_debug(PPCInterpreter_getCurrentInstance() == nullptr); if (!sSchedulerActive.load(std::memory_order::relaxed)) { @@ -1165,7 +1165,7 @@ namespace coreinit // create scheduler idle fiber and switch to it g_idleLoopFiber[t_assignedCoreIndex] = new Fiber(__OSThreadCoreIdle, nullptr, nullptr); - cemu_assert_debug(ppcInterpreterCurrentInstance == nullptr); + cemu_assert_debug(PPCInterpreter_getCurrentInstance() == nullptr); __OSLockScheduler(); Fiber::Switch(*g_idleLoopFiber[t_assignedCoreIndex]); // returned from scheduler loop, exit thread diff --git a/src/Cafe/OS/libs/coreinit/coreinit_ThreadQueue.cpp b/src/Cafe/OS/libs/coreinit/coreinit_ThreadQueue.cpp index 38302d5af..68cb22b39 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_ThreadQueue.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_ThreadQueue.cpp @@ -139,7 +139,7 @@ namespace coreinit thread->state = OSThread_t::THREAD_STATE::STATE_READY; thread->currentWaitQueue = nullptr; coreinit::__OSAddReadyThreadToRunQueue(thread); - if (reschedule && thread->suspendCounter == 0 && ppcInterpreterCurrentInstance && __OSCoreShouldSwitchToThread(coreinit::OSGetCurrentThread(), thread)) + if (reschedule && thread->suspendCounter == 0 && PPCInterpreter_getCurrentInstance() && __OSCoreShouldSwitchToThread(coreinit::OSGetCurrentThread(), thread)) shouldReschedule = true; } if (shouldReschedule) @@ -159,7 +159,7 @@ namespace coreinit thread->state = OSThread_t::THREAD_STATE::STATE_READY; thread->currentWaitQueue = nullptr; coreinit::__OSAddReadyThreadToRunQueue(thread); - if (reschedule && thread->suspendCounter == 0 && ppcInterpreterCurrentInstance && __OSCoreShouldSwitchToThread(coreinit::OSGetCurrentThread(), thread)) + if (reschedule && thread->suspendCounter == 0 && PPCInterpreter_getCurrentInstance() && __OSCoreShouldSwitchToThread(coreinit::OSGetCurrentThread(), thread)) shouldReschedule = true; } if (shouldReschedule) diff --git a/src/Cafe/OS/libs/gx2/GX2.cpp b/src/Cafe/OS/libs/gx2/GX2.cpp index 8c3fbc644..82aef1645 100644 --- a/src/Cafe/OS/libs/gx2/GX2.cpp +++ b/src/Cafe/OS/libs/gx2/GX2.cpp @@ -4,8 +4,8 @@ #include "GX2.h" #include "Cafe/HW/Latte/Core/Latte.h" #include "Cafe/OS/libs/coreinit/coreinit_Time.h" +#include "Cafe/OS/libs/coreinit/coreinit_Thread.h" #include "Cafe/CafeSystem.h" - #include "Cafe/HW/Latte/Core/LattePM4.h" #include "GX2_Command.h" @@ -68,7 +68,7 @@ void gx2Export_GX2SwapScanBuffers(PPCInterpreter_t* hCPU) // Orochi Warriors seems to call GX2SwapScanBuffers on arbitrary threads/cores. The PM4 commands should go through to the GPU as long as there is no active display list and no other core is submitting commands simultaneously // right now, we work around this by avoiding the infinite loop below (request counter incremented, but PM4 not sent) - uint32 coreIndex = PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance); + uint32 coreIndex = coreinit::OSGetCoreId(); if (GX2::sGX2MainCoreIndex == coreIndex) LatteGPUState.sharedArea->flipRequestCountBE = _swapEndianU32(_swapEndianU32(LatteGPUState.sharedArea->flipRequestCountBE) + 1); @@ -332,7 +332,7 @@ uint64 Latte_GetTime() void _GX2SubmitToTCL() { - uint32 coreIndex = PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance); + uint32 coreIndex = PPCInterpreter_getCoreIndex(PPCInterpreter_getCurrentInstance()); // do nothing if called from non-main GX2 core if (GX2::sGX2MainCoreIndex != coreIndex) { @@ -373,7 +373,7 @@ uint32 _GX2GetUnflushedBytes(uint32 coreIndex) */ void GX2ReserveCmdSpace(uint32 reservedFreeSpaceInU32) { - uint32 coreIndex = PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance); + uint32 coreIndex = coreinit::OSGetCoreId(); // if we are in a display list then do nothing if( gx2WriteGatherPipe.displayListStart[coreIndex] != MPTR_NULL ) return; diff --git a/src/Cafe/OS/libs/gx2/GX2_Command.cpp b/src/Cafe/OS/libs/gx2/GX2_Command.cpp index 6da197419..804e3da07 100644 --- a/src/Cafe/OS/libs/gx2/GX2_Command.cpp +++ b/src/Cafe/OS/libs/gx2/GX2_Command.cpp @@ -3,6 +3,7 @@ #include "Cafe/OS/common/OSCommon.h" #include "Cafe/HW/Latte/Core/LattePM4.h" #include "Cafe/OS/libs/coreinit/coreinit.h" +#include "Cafe/OS/libs/coreinit/coreinit_Thread.h" #include "Cafe/HW/Latte/ISA/RegDefines.h" #include "GX2.h" #include "GX2_Command.h" @@ -15,7 +16,7 @@ GX2WriteGatherPipeState gx2WriteGatherPipe = { 0 }; void gx2WriteGather_submitU32AsBE(uint32 v) { - uint32 coreIndex = PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance); + uint32 coreIndex = PPCInterpreter_getCoreIndex(PPCInterpreter_getCurrentInstance()); if (gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] == NULL) return; *(uint32*)(*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]) = _swapEndianU32(v); @@ -24,7 +25,7 @@ void gx2WriteGather_submitU32AsBE(uint32 v) void gx2WriteGather_submitU32AsLE(uint32 v) { - uint32 coreIndex = PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance); + uint32 coreIndex = PPCInterpreter_getCoreIndex(PPCInterpreter_getCurrentInstance()); if (gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] == NULL) return; *(uint32*)(*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]) = v; @@ -33,7 +34,7 @@ void gx2WriteGather_submitU32AsLE(uint32 v) void gx2WriteGather_submitU32AsLEArray(uint32* v, uint32 numValues) { - uint32 coreIndex = PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance); + uint32 coreIndex = PPCInterpreter_getCoreIndex(PPCInterpreter_getCurrentInstance()); if (gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] == NULL) return; memcpy_dwords((*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]), v, numValues); @@ -134,7 +135,7 @@ namespace GX2 bool GX2GetCurrentDisplayList(betype* displayListAddr, uint32be* displayListSize) { - uint32 coreIndex = PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance); + uint32 coreIndex = coreinit::OSGetCoreId(); if (gx2WriteGatherPipe.displayListStart[coreIndex] == MPTR_NULL) return false; @@ -149,13 +150,13 @@ namespace GX2 bool GX2GetDisplayListWriteStatus() { // returns true if we are writing to a display list - uint32 coreIndex = PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance); + uint32 coreIndex = coreinit::OSGetCoreId(); return gx2WriteGatherPipe.displayListStart[coreIndex] != MPTR_NULL; } bool GX2WriteGather_isDisplayListActive() { - uint32 coreIndex = PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance); + uint32 coreIndex = coreinit::OSGetCoreId(); if (gx2WriteGatherPipe.displayListStart[coreIndex] != MPTR_NULL) return true; return false; @@ -171,7 +172,7 @@ namespace GX2 void GX2WriteGather_checkAndInsertWrapAroundMark() { - uint32 coreIndex = PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance); + uint32 coreIndex = coreinit::OSGetCoreId(); if (coreIndex != sGX2MainCoreIndex) // only if main gx2 core return; if (gx2WriteGatherPipe.displayListStart[coreIndex] != MPTR_NULL) @@ -187,18 +188,18 @@ namespace GX2 void GX2BeginDisplayList(MEMPTR displayListAddr, uint32 size) { - GX2WriteGather_beginDisplayList(ppcInterpreterCurrentInstance, displayListAddr.GetMPTR(), size); + GX2WriteGather_beginDisplayList(PPCInterpreter_getCurrentInstance(), displayListAddr.GetMPTR(), size); } void GX2BeginDisplayListEx(MEMPTR displayListAddr, uint32 size, bool profiling) { - GX2WriteGather_beginDisplayList(ppcInterpreterCurrentInstance, displayListAddr.GetMPTR(), size); + GX2WriteGather_beginDisplayList(PPCInterpreter_getCurrentInstance(), displayListAddr.GetMPTR(), size); } uint32 GX2EndDisplayList(MEMPTR displayListAddr) { cemu_assert_debug(displayListAddr != nullptr); - uint32 displayListSize = GX2WriteGather_endDisplayList(ppcInterpreterCurrentInstance, displayListAddr.GetMPTR()); + uint32 displayListSize = GX2WriteGather_endDisplayList(PPCInterpreter_getCurrentInstance(), displayListAddr.GetMPTR()); return displayListSize; } @@ -220,7 +221,7 @@ namespace GX2 // its basically a way to manually submit a command buffer to the GPU // as such it also affects the submission and retire timestamps - uint32 coreIndex = PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance); + uint32 coreIndex = PPCInterpreter_getCoreIndex(PPCInterpreter_getCurrentInstance()); cemu_assert_debug(coreIndex == sGX2MainCoreIndex); coreIndex = sGX2MainCoreIndex; // always submit to main queue which is owned by GX2 main core (TCLSubmitToRing does not need this workaround) diff --git a/src/Cafe/OS/libs/gx2/GX2_Event.cpp b/src/Cafe/OS/libs/gx2/GX2_Event.cpp index ba498477d..9748e20b5 100644 --- a/src/Cafe/OS/libs/gx2/GX2_Event.cpp +++ b/src/Cafe/OS/libs/gx2/GX2_Event.cpp @@ -263,7 +263,7 @@ namespace GX2 gx2WriteGather_submitU32AsBE(0x00000000); // unused } // flush pipeline - if (_GX2GetUnflushedBytes(PPCInterpreter_getCoreIndex(ppcInterpreterCurrentInstance)) > 0) + if (_GX2GetUnflushedBytes(coreinit::OSGetCoreId()) > 0) _GX2SubmitToTCL(); uint64 ts = GX2GetLastSubmittedTimeStamp(); diff --git a/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp b/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp index 9afb9f853..ce9501aba 100644 --- a/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp +++ b/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp @@ -225,7 +225,7 @@ void CurlWorkerThread(CURL_t* curl, PPCConcurrentQueue* callerQueue, uint32 SendOrderToWorker(CURL_t* curl, QueueOrder order, uint32 arg1 = 0) { - OSThread_t* currentThread = coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance); + OSThread_t* currentThread = coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()); curl->curlThread = currentThread; // cemuLog_logDebug(LogType::Force, "CURRENTTHREAD: 0x{} -> {}",currentThread, order) @@ -707,7 +707,7 @@ void export_curl_easy_init(PPCInterpreter_t* hCPU) memset(result.GetPtr(), 0, sizeof(CURL_t)); *result = {}; result->curl = curl_easy_init(); - result->curlThread = coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance); + result->curlThread = coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()); result->info_contentType = nullptr; result->info_redirectUrl = nullptr; diff --git a/src/Cafe/OS/libs/nn_save/nn_save.cpp b/src/Cafe/OS/libs/nn_save/nn_save.cpp index 109c00d2c..1311dd468 100644 --- a/src/Cafe/OS/libs/nn_save/nn_save.cpp +++ b/src/Cafe/OS/libs/nn_save/nn_save.cpp @@ -451,14 +451,14 @@ namespace save asyncParams.userCallback = PPCInterpreter_makeCallableExportDepr(AsyncCallback); StackAllocator param; - param->thread = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + param->thread = coreinitThread_getCurrentThreadMPTRDepr(PPCInterpreter_getCurrentInstance()); param->returnStatus = (FSStatus)FS_RESULT::SUCCESS; asyncParams.userContext = param.GetPointer(); SAVEStatus status = SAVEOpenFileOtherApplicationAsync(client, block, titleId, accountSlot, path, mode, hFile, errHandling, &asyncParams); if (status == (FSStatus)FS_RESULT::SUCCESS) { - coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance), 1000); + coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()), 1000); PPCCore_switchToScheduler(); return param->returnStatus; } @@ -685,14 +685,14 @@ namespace save asyncParams.userCallback = _swapEndianU32(PPCInterpreter_makeCallableExportDepr(AsyncCallback)); StackAllocator param; - param->thread = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + param->thread = coreinitThread_getCurrentThreadMPTRDepr(PPCInterpreter_getCurrentInstance()); param->returnStatus = (FSStatus)FS_RESULT::SUCCESS; asyncParams.userContext = param.GetMPTRBE(); SAVEStatus status = SAVEGetFreeSpaceSizeAsync(client, block, accountSlot, freeSize, errHandling, &asyncParams); if (status == (FSStatus)FS_RESULT::SUCCESS) { - coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance), 1000); + coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()), 1000); PPCCore_switchToScheduler(); return param->returnStatus; } @@ -754,14 +754,14 @@ namespace save asyncParams.userCallback = _swapEndianU32(PPCInterpreter_makeCallableExportDepr(AsyncCallback)); StackAllocator param; - param->thread = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + param->thread = coreinitThread_getCurrentThreadMPTRDepr(PPCInterpreter_getCurrentInstance()); param->returnStatus = (FSStatus)FS_RESULT::SUCCESS; asyncParams.userContext = param.GetMPTRBE(); SAVEStatus status = SAVERemoveAsync(client, block, accountSlot, path, errHandling, &asyncParams); if (status == (FSStatus)FS_RESULT::SUCCESS) { - coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance), 1000); + coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()), 1000); PPCCore_switchToScheduler(); return param->returnStatus; } @@ -867,14 +867,14 @@ namespace save asyncParams.userCallback = _swapEndianU32(PPCInterpreter_makeCallableExportDepr(AsyncCallback)); StackAllocator param; - param->thread = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + param->thread = coreinitThread_getCurrentThreadMPTRDepr(PPCInterpreter_getCurrentInstance()); param->returnStatus = (FSStatus)FS_RESULT::SUCCESS; asyncParams.userContext = param.GetMPTRBE(); SAVEStatus status = SAVEOpenDirAsync(client, block, accountSlot, path, hDir, errHandling, &asyncParams); if (status == (FSStatus)FS_RESULT::SUCCESS) { - coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance), 1000); + coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()), 1000); PPCCore_switchToScheduler(); return param->returnStatus; } @@ -940,14 +940,14 @@ namespace save asyncParams.userCallback = _swapEndianU32(PPCInterpreter_makeCallableExportDepr(AsyncCallback)); StackAllocator param; - param->thread = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + param->thread = coreinitThread_getCurrentThreadMPTRDepr(PPCInterpreter_getCurrentInstance()); param->returnStatus = (FSStatus)FS_RESULT::SUCCESS; asyncParams.userContext = param.GetMPTRBE(); SAVEStatus status = SAVEOpenDirOtherApplicationAsync(client, block, titleId, accountSlot, path, hDir, errHandling, &asyncParams); if (status == (FSStatus)FS_RESULT::SUCCESS) { - coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance), 1000); + coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()), 1000); PPCCore_switchToScheduler(); return param->returnStatus; } @@ -1076,14 +1076,14 @@ namespace save asyncParams.userCallback = _swapEndianU32(PPCInterpreter_makeCallableExportDepr(AsyncCallback)); StackAllocator param; - param->thread = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + param->thread = coreinitThread_getCurrentThreadMPTRDepr(PPCInterpreter_getCurrentInstance()); param->returnStatus = (FSStatus)FS_RESULT::SUCCESS; asyncParams.userContext = param.GetMPTRBE(); SAVEStatus status = SAVEMakeDirAsync(client, block, accountSlot, path, errHandling, &asyncParams); if (status == (FSStatus)FS_RESULT::SUCCESS) { - coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance), 1000); + coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()), 1000); PPCCore_switchToScheduler(); return param->returnStatus; } @@ -1127,14 +1127,14 @@ namespace save asyncParams.userCallback = PPCInterpreter_makeCallableExportDepr(AsyncCallback); StackAllocator param; - param->thread = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + param->thread = coreinitThread_getCurrentThreadMPTRDepr(PPCInterpreter_getCurrentInstance()); param->returnStatus = (FSStatus)FS_RESULT::SUCCESS; asyncParams.userContext = param.GetPointer(); SAVEStatus status = SAVEOpenFileAsync(client, block, accountSlot, path, mode, hFile, errHandling, &asyncParams); if (status == (FSStatus)FS_RESULT::SUCCESS) { - coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance), 1000); + coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()), 1000); PPCCore_switchToScheduler(); return param->returnStatus; } @@ -1187,14 +1187,14 @@ namespace save asyncParams.userCallback = _swapEndianU32(PPCInterpreter_makeCallableExportDepr(AsyncCallback)); StackAllocator param; - param->thread = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + param->thread = coreinitThread_getCurrentThreadMPTRDepr(PPCInterpreter_getCurrentInstance()); param->returnStatus = (FSStatus)FS_RESULT::SUCCESS; asyncParams.userContext = param.GetMPTRBE(); SAVEStatus status = SAVEGetStatAsync(client, block, accountSlot, path, stat, errHandling, &asyncParams); if (status == (FSStatus)FS_RESULT::SUCCESS) { - coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance), 1000); + coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()), 1000); PPCCore_switchToScheduler(); return param->returnStatus; } @@ -1238,14 +1238,14 @@ namespace save asyncParams.userCallback = _swapEndianU32(PPCInterpreter_makeCallableExportDepr(AsyncCallback)); StackAllocator param; - param->thread = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + param->thread = coreinitThread_getCurrentThreadMPTRDepr(PPCInterpreter_getCurrentInstance()); param->returnStatus = (FSStatus)FS_RESULT::SUCCESS; asyncParams.userContext = param.GetMPTRBE(); SAVEStatus status = SAVEGetStatOtherApplicationAsync(client, block, titleId, accountSlot, path, stat, errHandling, &asyncParams); if (status == (FSStatus)FS_RESULT::SUCCESS) { - coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance), 1000); + coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()), 1000); PPCCore_switchToScheduler(); return param->returnStatus; } @@ -1427,14 +1427,14 @@ namespace save asyncParams.userCallback = _swapEndianU32(PPCInterpreter_makeCallableExportDepr(AsyncCallback)); StackAllocator param; - param->thread = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + param->thread = coreinitThread_getCurrentThreadMPTRDepr(PPCInterpreter_getCurrentInstance()); param->returnStatus = (FSStatus)FS_RESULT::SUCCESS; asyncParams.userContext = param.GetMPTRBE(); SAVEStatus status = SAVEChangeDirAsync(client, block, accountSlot, path, errHandling, &asyncParams); if (status == (FSStatus)FS_RESULT::SUCCESS) { - coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance), 1000); + coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()), 1000); PPCCore_switchToScheduler(); return param->returnStatus; } @@ -1496,14 +1496,14 @@ namespace save asyncParams.userCallback = _swapEndianU32(PPCInterpreter_makeCallableExportDepr(AsyncCallback)); StackAllocator param; - param->thread = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + param->thread = coreinitThread_getCurrentThreadMPTRDepr(PPCInterpreter_getCurrentInstance()); param->returnStatus = (FSStatus)FS_RESULT::SUCCESS; asyncParams.userContext = param.GetMPTRBE(); SAVEStatus status = SAVEFlushQuotaAsync(client, block, accountSlot, errHandling, &asyncParams); if (status == (FSStatus)FS_RESULT::SUCCESS) { - coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(ppcInterpreterCurrentInstance), 1000); + coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(PPCInterpreter_getCurrentInstance()), 1000); PPCCore_switchToScheduler(); return param->returnStatus; } diff --git a/src/Cafe/OS/libs/snd_core/ax_aux.cpp b/src/Cafe/OS/libs/snd_core/ax_aux.cpp index 837adf065..a91765628 100644 --- a/src/Cafe/OS/libs/snd_core/ax_aux.cpp +++ b/src/Cafe/OS/libs/snd_core/ax_aux.cpp @@ -218,9 +218,10 @@ namespace snd_core AXAUXCBCHANNELINFO* cbStruct = __AXAuxCB_auxCBStruct.GetPtr(); cbStruct->numChannels = tvChannelCount; cbStruct->numSamples = sampleCount; - ppcInterpreterCurrentInstance->gpr[3] = __AXAuxCB_dataPtrs.GetMPTR(); - ppcInterpreterCurrentInstance->gpr[4] = __AXAuxTVCallbackUserParam[auxBusIndex]; - ppcInterpreterCurrentInstance->gpr[5] = __AXAuxCB_auxCBStruct.GetMPTR(); + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); + hCPU->gpr[3] = __AXAuxCB_dataPtrs.GetMPTR(); + hCPU->gpr[4] = __AXAuxTVCallbackUserParam[auxBusIndex]; + hCPU->gpr[5] = __AXAuxCB_auxCBStruct.GetMPTR(); PPCCore_executeCallbackInternal(auxCBFuncMPTR); } else @@ -255,9 +256,10 @@ namespace snd_core AXAUXCBCHANNELINFO* cbStruct = __AXAuxCB_auxCBStruct.GetPtr(); cbStruct->numChannels = drcChannelCount; cbStruct->numSamples = sampleCount; - ppcInterpreterCurrentInstance->gpr[3] = __AXAuxCB_dataPtrs.GetMPTR(); - ppcInterpreterCurrentInstance->gpr[4] = __AXAuxDRCCallbackUserParam[auxBusIndex + drcIndex * 3]; - ppcInterpreterCurrentInstance->gpr[5] = __AXAuxCB_auxCBStruct.GetMPTR(); + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); + hCPU->gpr[3] = __AXAuxCB_dataPtrs.GetMPTR(); + hCPU->gpr[4] = __AXAuxDRCCallbackUserParam[auxBusIndex + drcIndex * 3]; + hCPU->gpr[5] = __AXAuxCB_auxCBStruct.GetMPTR(); PPCCore_executeCallbackInternal(auxCBFuncMPTR); } else diff --git a/src/Cafe/OS/libs/snd_core/ax_voice.cpp b/src/Cafe/OS/libs/snd_core/ax_voice.cpp index 8a49b0f43..877eecab1 100644 --- a/src/Cafe/OS/libs/snd_core/ax_voice.cpp +++ b/src/Cafe/OS/libs/snd_core/ax_voice.cpp @@ -3,6 +3,7 @@ #include "Cafe/HW/Espresso/PPCCallback.h" #include "Cafe/OS/libs/snd_core/ax.h" #include "Cafe/OS/libs/snd_core/ax_internal.h" +#include "Cafe/OS/libs/coreinit/coreinit_Thread.h" #include "util/helpers/fspinlock.h" namespace snd_core @@ -120,7 +121,7 @@ namespace snd_core { return -2; } - MPTR currentThreadMPTR = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + MPTR currentThreadMPTR = memory_getVirtualOffsetFromPointer(coreinit::OSGetCurrentThread()); for (sint32 i = __AXUserProtectionArraySize - 1; i >= 0; i--) { if (__AXUserProtectionArray[i].threadMPTR == currentThreadMPTR) @@ -151,7 +152,7 @@ namespace snd_core PPCCore_deboostQuantum(10000); if (AXIst_IsFrameBeingProcessed()) return -2; - MPTR currentThreadMPTR = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + MPTR currentThreadMPTR = memory_getVirtualOffsetFromPointer(coreinit::OSGetCurrentThread()); for (sint32 i = __AXUserProtectionArraySize - 1; i >= 0; i--) { if (__AXUserProtectionArray[i].threadMPTR == currentThreadMPTR) @@ -206,7 +207,7 @@ namespace snd_core if (AXIst_IsFrameBeingProcessed()) isProtected = __AXVoiceProtection[index].threadMPTR != MPTR_NULL; else - isProtected = __AXVoiceProtection[index].threadMPTR != coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + isProtected = __AXVoiceProtection[index].threadMPTR != memory_getVirtualOffsetFromPointer(coreinit::OSGetCurrentThread()); return isProtected; } @@ -219,7 +220,7 @@ namespace snd_core return; if (__AXVoiceProtection[index].threadMPTR == MPTR_NULL) { - __AXVoiceProtection[index].threadMPTR = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + __AXVoiceProtection[index].threadMPTR = memory_getVirtualOffsetFromPointer(coreinit::OSGetCurrentThread()); // does not set count? } } @@ -246,7 +247,7 @@ namespace snd_core } if (AXIst_IsFrameBeingProcessed()) return -2; - MPTR currentThreadMPTR = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + MPTR currentThreadMPTR = memory_getVirtualOffsetFromPointer(coreinit::OSGetCurrentThread()); if (__AXVoiceProtection[index].threadMPTR == MPTR_NULL) { __AXVoiceProtection[index].threadMPTR = currentThreadMPTR; @@ -286,7 +287,7 @@ namespace snd_core } if (AXIst_IsFrameBeingProcessed()) return -2; - MPTR currentThreadMPTR = coreinitThread_getCurrentThreadMPTRDepr(ppcInterpreterCurrentInstance); + MPTR currentThreadMPTR = memory_getVirtualOffsetFromPointer(coreinit::OSGetCurrentThread()); if (__AXVoiceProtection[index].threadMPTR == currentThreadMPTR) { if (__AXVoiceProtection[index].count > 0) diff --git a/src/Cafe/OS/libs/zlib125/zlib125.cpp b/src/Cafe/OS/libs/zlib125/zlib125.cpp index 72855c616..25df6a9d2 100644 --- a/src/Cafe/OS/libs/zlib125/zlib125.cpp +++ b/src/Cafe/OS/libs/zlib125/zlib125.cpp @@ -28,8 +28,7 @@ static_assert(sizeof(z_stream_ppc2) == 0x38); voidpf zcallocWrapper(voidpf opaque, uInt items, uInt size) { z_stream_ppc2* zstream = (z_stream_ppc2*)opaque; - - PPCInterpreter_t* hCPU = ppcInterpreterCurrentInstance; + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); hCPU->gpr[3] = zstream->opaque.GetMPTR(); hCPU->gpr[4] = items; hCPU->gpr[5] = size; @@ -41,7 +40,7 @@ voidpf zcallocWrapper(voidpf opaque, uInt items, uInt size) void zcfreeWrapper(voidpf opaque, voidpf baseIndex) { z_stream_ppc2* zstream = (z_stream_ppc2*)opaque; - PPCInterpreter_t* hCPU = ppcInterpreterCurrentInstance; + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); hCPU->gpr[3] = zstream->opaque.GetMPTR(); hCPU->gpr[4] = memory_getVirtualOffsetFromPointer(baseIndex); PPCCore_executeCallbackInternal(zstream->zfree.GetMPTR()); diff --git a/src/Common/ExceptionHandler/ExceptionHandler.cpp b/src/Common/ExceptionHandler/ExceptionHandler.cpp index 5308ea8e4..5fefc8caa 100644 --- a/src/Common/ExceptionHandler/ExceptionHandler.cpp +++ b/src/Common/ExceptionHandler/ExceptionHandler.cpp @@ -73,16 +73,17 @@ void ExceptionHandler_LogGeneralInfo() // info about active PPC instance: CrashLog_WriteLine(""); CrashLog_WriteHeader("Active PPC instance"); - if (ppcInterpreterCurrentInstance) + PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance(); + if (hCPU) { OSThread_t* currentThread = coreinit::OSGetCurrentThread(); uint32 threadPtr = memory_getVirtualOffsetFromPointer(coreinit::OSGetCurrentThread()); - sprintf(dumpLine, "IP 0x%08x LR 0x%08x Thread 0x%08x", ppcInterpreterCurrentInstance->instructionPointer, ppcInterpreterCurrentInstance->spr.LR, threadPtr); + sprintf(dumpLine, "IP 0x%08x LR 0x%08x Thread 0x%08x", hCPU->instructionPointer, hCPU->spr.LR, threadPtr); CrashLog_WriteLine(dumpLine); // GPR info CrashLog_WriteLine(""); - auto gprs = ppcInterpreterCurrentInstance->gpr; + auto gprs = hCPU->gpr; sprintf(dumpLine, "r0 =%08x r1 =%08x r2 =%08x r3 =%08x r4 =%08x r5 =%08x r6 =%08x r7 =%08x", gprs[0], gprs[1], gprs[2], gprs[3], gprs[4], gprs[5], gprs[6], gprs[7]); CrashLog_WriteLine(dumpLine); sprintf(dumpLine, "r8 =%08x r9 =%08x r10=%08x r11=%08x r12=%08x r13=%08x r14=%08x r15=%08x", gprs[8], gprs[9], gprs[10], gprs[11], gprs[12], gprs[13], gprs[14], gprs[15]); @@ -93,7 +94,7 @@ void ExceptionHandler_LogGeneralInfo() CrashLog_WriteLine(dumpLine); // stack trace - MPTR currentStackVAddr = ppcInterpreterCurrentInstance->gpr[1]; + MPTR currentStackVAddr = hCPU->gpr[1]; CrashLog_WriteLine(""); CrashLog_WriteHeader("PPC stack trace"); DebugLogStackTrace(currentThread, currentStackVAddr); diff --git a/src/Common/precompiled.h b/src/Common/precompiled.h index 60495f530..c55314d5b 100644 --- a/src/Common/precompiled.h +++ b/src/Common/precompiled.h @@ -236,12 +236,17 @@ inline uint64 _udiv128(uint64 highDividend, uint64 lowDividend, uint64 divisor, #if defined(_MSC_VER) #define UNREACHABLE __assume(false) #define ASSUME(__cond) __assume(__cond) -#elif defined(__GNUC__) + #define TLS_WORKAROUND_NOINLINE // no-op for MSVC as it has a flag for fiber-safe TLS optimizations +#elif defined(__GNUC__) && !defined(__llvm__) #define UNREACHABLE __builtin_unreachable() #define ASSUME(__cond) __attribute__((assume(__cond))) + #define TLS_WORKAROUND_NOINLINE __attribute__((noinline)) +#elif defined(__clang__) + #define UNREACHABLE __builtin_unreachable() + #define ASSUME(__cond) __builtin_assume(__cond) + #define TLS_WORKAROUND_NOINLINE __attribute__((noinline)) #else - #define UNREACHABLE - #define ASSUME(__cond) + #error Unknown compiler #endif #if defined(_MSC_VER)