diff --git a/.gitmodules b/.gitmodules index 39c01e7..493176d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -21,3 +21,6 @@ [submodule "dependencies/xbyak_aarch64"] path = dependencies/xbyak_aarch64 url = https://github.com/fujitsu/xbyak_aarch64 +[submodule "dependencies/cpuid"] + path = dependencies/cpuid + url = https://github.com/SSimco/cpuid diff --git a/CMakeLists.txt b/CMakeLists.txt index 5621269..be41d05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -248,6 +248,7 @@ add_subdirectory("dependencies/ih264d" EXCLUDE_FROM_ALL) if(CMAKE_SYSTEM_PROCESSOR MATCHES "(aarch64)|(AARCH64)") add_subdirectory("dependencies/xbyak_aarch64" EXCLUDE_FROM_ALL) + add_subdirectory("dependencies/cpuid" EXCLUDE_FROM_ALL) endif() find_package(ZArchive) diff --git a/dependencies/cpuid b/dependencies/cpuid new file mode 160000 index 0000000..45598b9 --- /dev/null +++ b/dependencies/cpuid @@ -0,0 +1 @@ +Subproject commit 45598b97c01ebf2ab760baa737350f64ee81a4c9 diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt index 6cf8d9f..aadec48 100644 --- a/src/Common/CMakeLists.txt +++ b/src/Common/CMakeLists.txt @@ -85,6 +85,9 @@ endif() if (UNIX AND NOT APPLE AND NOT ANDROID) target_link_libraries(CemuCommon PRIVATE X11::X11 X11::Xrender X11::Xutil) endif() +if(CMAKE_SYSTEM_PROCESSOR MATCHES "(aarch64)|(AARCH64)") + target_link_libraries(CemuCommon PRIVATE cpuid) +endif() # PUBLIC because: # - boost/predef/os.h is included in platform.h diff --git a/src/Common/cpu_features.cpp b/src/Common/cpu_features.cpp index dfea885..46718e5 100644 --- a/src/Common/cpu_features.cpp +++ b/src/Common/cpu_features.cpp @@ -27,9 +27,23 @@ inline void cpuidex(int cpuInfo[4], int functionId, int subFunctionId) { } #endif +#if defined(__aarch64__) +#if BOOST_OS_LINUX +#include "cpuid.h" +#endif // BOOST_OS_LINUX +#endif // defined(__aarch64__) CPUFeaturesImpl::CPUFeaturesImpl() { +#if defined(__aarch64__) +#if BOOST_OS_LINUX +#if __ANDROID__ + m_cpuBrandName = cpuid::getCpuBrandNameAndroid().value_or(cpuid::getCpuBrandNameLinux()); +#else + m_cpuBrandName = cpuid::getCpuBrandNameLinux(); +#endif +#endif +#endif #if defined(ARCH_X86_64) int cpuInfo[4]; cpuid(cpuInfo, 0x80000001); @@ -47,19 +61,21 @@ CPUFeaturesImpl::CPUFeaturesImpl() x86.invariant_tsc = ((cpuInfo[3] >> 8) & 1); // get CPU brand name uint32_t nExIds, i = 0; - memset(m_cpuBrandName, 0, sizeof(m_cpuBrandName)); + char cpuBrandName[0x40]{ 0 }; + memset(cpuBrandName, 0, sizeof(cpuBrandName)); cpuid(cpuInfo, 0x80000000); nExIds = (uint32_t)cpuInfo[0]; for (uint32_t i = 0x80000000; i <= nExIds; ++i) { cpuid(cpuInfo, i); if (i == 0x80000002) - memcpy(m_cpuBrandName, cpuInfo, sizeof(cpuInfo)); + memcpy(cpuBrandName, cpuInfo, sizeof(cpuInfo)); else if (i == 0x80000003) - memcpy(m_cpuBrandName + 16, cpuInfo, sizeof(cpuInfo)); + memcpy(cpuBrandName + 16, cpuInfo, sizeof(cpuInfo)); else if (i == 0x80000004) - memcpy(m_cpuBrandName + 32, cpuInfo, sizeof(cpuInfo)); + memcpy(cpuBrandName + 32, cpuInfo, sizeof(cpuInfo)); } + m_cpuBrandName = cpuBrandName; #endif } diff --git a/src/Common/cpu_features.h b/src/Common/cpu_features.h index 130b51a..5afaccc 100644 --- a/src/Common/cpu_features.h +++ b/src/Common/cpu_features.h @@ -30,7 +30,7 @@ public: bool invariant_tsc{ false }; }x86; private: - char m_cpuBrandName[0x40]{ 0 }; + std::string m_cpuBrandName; }; extern CPUFeaturesImpl g_CPUFeatures; \ No newline at end of file