From b29961a8a9bb7cb92afcb32ee044a5b5cf384049 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Thu, 12 Sep 2024 08:05:15 +0800 Subject: [PATCH 03/12] Support PowerPC CPU detection --- src/detection/cpu/cpu.c | 11 +++++++++++ src/detection/cpu/cpu.h | 1 + src/detection/cpu/cpu_apple.c | 12 +++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/detection/cpu/cpu.c b/src/detection/cpu/cpu.c index 774e747a..f4ea970d 100644 --- a/src/detection/cpu/cpu.c +++ b/src/detection/cpu/cpu.c @@ -41,6 +41,17 @@ const char* ffCPUAppleCodeToName(uint32_t code) } } +const char* ffCPUApplePPCCodeToName(int cpuSubType) +{ + switch (cpuSubType) + { + case 10: return "PowerPC 7400"; + case 11: return "PowerPC 7450"; + case 100: return "PowerPC 970"; + default: return "PowerPC"; + } +} + const char* ffCPUQualcommCodeToName(uint32_t code) { // https://github.com/AsahiLinux/docs/wiki/Codenames diff --git a/src/detection/cpu/cpu.h b/src/detection/cpu/cpu.h index eb5bd90f..8f5f6e86 100644 --- a/src/detection/cpu/cpu.h +++ b/src/detection/cpu/cpu.h @@ -29,6 +29,7 @@ typedef struct FFCPUResult const char* ffDetectCPU(const FFCPUOptions* options, FFCPUResult* cpu); const char* ffCPUAppleCodeToName(uint32_t code); +const char* ffCPUApplePPCCodeToName(int cpuSubType); const char* ffCPUQualcommCodeToName(uint32_t code); #if defined(__x86_64__) || defined(__i386__) diff --git a/src/detection/cpu/cpu_apple.c b/src/detection/cpu/cpu_apple.c index 3c5f4594..02f56e4c 100644 --- a/src/detection/cpu/cpu_apple.c +++ b/src/detection/cpu/cpu_apple.c @@ -100,13 +100,23 @@ static const char* detectCoreCount(FFCPUResult* cpu) const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) { +#ifdef __POWERPC__ + int cpuSubType; + size_t size = sizeof(cpuSubType); + if (sysctlbyname("hw.cpusubtype", &cpuSubType, &size, NULL, 0) == 0) { + const char *cpuName = ffCPUApplePPCCodeToName(cpuSubType); + ffStrbufAppendS(&cpu->name, cpuName); + } else { + return "sysctlbyname(hw.cpusubtype) failed"; + } +#else if (ffSysctlGetString("machdep.cpu.brand_string", &cpu->name) != NULL) return "sysctlbyname(machdep.cpu.brand_string) failed"; ffSysctlGetString("machdep.cpu.vendor", &cpu->vendor); if (cpu->vendor.length == 0 && ffStrbufStartsWithS(&cpu->name, "Apple ")) ffStrbufAppendS(&cpu->vendor, "Apple"); - +#endif cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu_max", 1); if(cpu->coresPhysical == 1) cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu", 1); -- 2.47.0