diff --git a/FEXCore/Source/Interface/Core/CPUID.cpp b/FEXCore/Source/Interface/Core/CPUID.cpp index 7fd4e4c45b..7bbba7052d 100644 --- a/FEXCore/Source/Interface/Core/CPUID.cpp +++ b/FEXCore/Source/Interface/Core/CPUID.cpp @@ -798,9 +798,13 @@ FEXCore::CPUID::FunctionResults CPUIDEmu::Function_4000_0000h(uint32_t Leaf) con return Res; } +constexpr std::array::length(GIT_DESCRIBE_STRING) + 1> GitString = {GIT_DESCRIBE_STRING}; +static_assert(GitString.size() < 32); + // Hypervisor CPUID information leaf FEXCore::CPUID::FunctionResults CPUIDEmu::Function_4000_0001h(uint32_t Leaf) const { FEXCore::CPUID::FunctionResults Res {}; + constexpr uint32_t MaximumSubLeafNumber = 2; if (Leaf == 0) { // EAX[3:0] Is the host architecture that FEX is running under #ifdef _M_X86_64 @@ -812,6 +816,15 @@ FEXCore::CPUID::FunctionResults CPUIDEmu::Function_4000_0001h(uint32_t Leaf) con #else // EAX[3:0] = 0 = Unknown architecture #endif + + // EAX[15:4] = Reserved + + // EAX[31:16] = Maximum sub-leaf value. + Res.eax |= MaximumSubLeafNumber << 16; + } else if (Leaf == 1) { + memcpy(&Res, GitString.data(), std::min(GitString.size(), sizeof(FEXCore::CPUID::FunctionResults))); + } else if (Leaf == 2) { + memcpy(&Res, GitString.data() + 16, std::min(std::max(0, GitString.size() - 16), sizeof(FEXCore::CPUID::FunctionResults))); } return Res; @@ -917,11 +930,6 @@ FEXCore::CPUID::FunctionResults CPUIDEmu::Function_8000_0001h(uint32_t Leaf) con return Res; } -constexpr char ProcessorBrand[32] = {GIT_DESCRIBE_STRING}; - -constexpr ssize_t DESCRIBE_STR_SIZE = std::char_traits::length(GIT_DESCRIBE_STRING); -static_assert(DESCRIBE_STR_SIZE < 32); - // Processor brand string FEXCore::CPUID::FunctionResults CPUIDEmu::Function_8000_0002h(uint32_t Leaf) const { return Function_8000_0002h(Leaf, GetCPUID()); @@ -937,22 +945,24 @@ FEXCore::CPUID::FunctionResults CPUIDEmu::Function_8000_0004h(uint32_t Leaf) con FEXCore::CPUID::FunctionResults CPUIDEmu::Function_8000_0002h(uint32_t Leaf, uint32_t CPU) const { FEXCore::CPUID::FunctionResults Res {}; - memset(&Res, ' ', sizeof(FEXCore::CPUID::FunctionResults)); - memcpy(&Res, &ProcessorBrand[0], std::min(ssize_t {16L}, DESCRIBE_STR_SIZE)); + auto& Data = PerCPUData[CPU]; + memcpy(&Res, Data.ProductName, std::min(strlen(Data.ProductName), sizeof(FEXCore::CPUID::FunctionResults))); return Res; } FEXCore::CPUID::FunctionResults CPUIDEmu::Function_8000_0003h(uint32_t Leaf, uint32_t CPU) const { FEXCore::CPUID::FunctionResults Res {}; - memset(&Res, ' ', sizeof(FEXCore::CPUID::FunctionResults)); - memcpy(&Res, &ProcessorBrand[16], std::max(ssize_t {0L}, DESCRIBE_STR_SIZE - 16)); + auto& Data = PerCPUData[CPU]; + const auto RemainingStringSize = std::max(0, strlen(Data.ProductName) - 16); + memcpy(&Res, Data.ProductName + 16, std::min(RemainingStringSize, sizeof(FEXCore::CPUID::FunctionResults))); return Res; } FEXCore::CPUID::FunctionResults CPUIDEmu::Function_8000_0004h(uint32_t Leaf, uint32_t CPU) const { FEXCore::CPUID::FunctionResults Res {}; auto& Data = PerCPUData[CPU]; - memcpy(&Res, Data.ProductName, std::min(strlen(Data.ProductName), sizeof(FEXCore::CPUID::FunctionResults))); + const auto RemainingStringSize = std::max(0, strlen(Data.ProductName) - 32); + memcpy(&Res, Data.ProductName + 32, std::min(RemainingStringSize, sizeof(FEXCore::CPUID::FunctionResults))); return Res; } diff --git a/docs/CPUID.md b/docs/CPUID.md index 1b8667ac3b..3657dc2c3d 100644 --- a/docs/CPUID.md +++ b/docs/CPUID.md @@ -25,11 +25,21 @@ * 1 - x86_64 * 2 - AArch64 * 3-15: **Reserved** + * Bits EAX[15:4] - **Reserved** + * Bits EAX[31:16] - Maximum subleaf input value for CPUID function 4000_0001h * EBX - **Reserved** - Read as zero * ECX - **Reserved** - Read as zero * EDX - **Reserved** - Read as zero -### Sub-Leaf 0000_0001 - FFFF_FFFF: **Reserved** +### Sub-leaf 1: ECX == 1 +* FEX version string signature. First 16-bytes +* memcpy eax:ebx:ecx:edx in to the first 16-bytes of a string. + +### Sub-leaf 2: ECX == 2 +* FEX version string signature. Second 16-bytes +* memcpy eax:ebx:ecx:edx in to the second 16-bytes of a string. + +### Sub-Leaf 0000_0003 - FFFF_FFFF: **Reserved** ## 4000_0002h - 4000_000Fh * **Reserved range**