diff --git a/libraries/platform/src/MACOSPlatform.cpp b/libraries/platform/src/MACOSPlatform.cpp index 034849817c..9ea2daca52 100644 --- a/libraries/platform/src/MACOSPlatform.cpp +++ b/libraries/platform/src/MACOSPlatform.cpp @@ -12,6 +12,7 @@ #include #include #include +#include using namespace platform; @@ -22,13 +23,44 @@ bool MACOSInstance::enumeratePlatform() { return true; } +static void getCpuId( uint32_t* p, uint32_t ax ) +{ + __asm __volatile + ( "movl %%ebx, %%esi\n\t" + "cpuid\n\t" + "xchgl %%ebx, %%esi" + : "=a" (p[0]), "=S" (p[1]), + "=c" (p[2]), "=d" (p[3]) + : "0" (ax) + ); +} + void MACOSInstance::enumerateCpu() { json *cpu= new json(); - - // (*cpu)["brand"] = ident->getName(); - // (*cpu)["model"] = CPUModelString; - // (*cpu)["clockSpeed"] = CPUClockString; - // (*cpu)["numCores"] = getNumLogicalCores(); + uint32_t cpuInfo[4]={0,0,0,0}; + char CPUBrandString[16]; + char CPUModelString[16]; + char CPUClockString[16]; + uint32_t nExIds; + getCpuId(cpuInfo, 0x80000000); + nExIds = cpuInfo[0]; + + for (uint32_t i = 0x80000000; i <= nExIds; ++i) { + getCpuId(cpuInfo, i); + // Interpret CPU brand string + if (i == 0x80000002) { + memcpy(CPUBrandString, cpuInfo, sizeof(cpuInfo)); + } else if (i == 0x80000003) { + memcpy(CPUModelString, cpuInfo, sizeof(cpuInfo)); + } else if (i == 0x80000004) { + memcpy(CPUClockString, cpuInfo, sizeof(cpuInfo)); + } + } + + (*cpu)["brand"] = ident->getName(); + (*cpu)["model"] = CPUModelString; + (*cpu)["clockSpeed"] = CPUClockString; + (*cpu)["numCores"] = getNumLogicalCores(); _cpu.push_back(cpu); }