trying to clean up the asm for linux and macos

This commit is contained in:
Sam Gateau 2019-05-28 12:27:26 -07:00
parent 2d1b06a1ba
commit a168109588
6 changed files with 44 additions and 145 deletions

View file

@ -43,6 +43,5 @@ void AndroidInstance::enumerateComputer(){
_computer[keys::computer::OS] = keys::computer::OS_ANDROID;
_computer[keys::computer::vendor] = "";
_computer[keys::computer::model] = "";
}

View file

@ -25,38 +25,6 @@ void LinuxInstance::enumerateCpu() {
_cpu.push_back(cpu);
}
/*
void LinuxInstance::enumerateCpu() {
json cpu = {};
uint32_t cpuInfo[4]={0,0,0,0};
char CPUBrandString[16];
char CPUModelString[16];
char CPUClockString[16];
uint32_t nExIds;
getLCpuId(cpuInfo, 0x80000000);
nExIds = cpuInfo[0];
for (uint32_t i = 0x80000000; i <= nExIds; ++i) {
getLCpuId(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[keys::cpu::vendor] = CPUBrandString;
cpu[keys::cpu::model] = CPUModelString;
cpu[keys::cpu::clockSpeed] = CPUClockString;
cpu[keys::cpu::numCores] = std::thread::hardware_concurrency();
_cpu.push_back(cpu);
}
*/
void LinuxInstance::enumerateGpu() {
GPUIdent* ident = GPUIdent::getInstance();
@ -82,6 +50,5 @@ void LinuxInstance::enumerateComputer(){
_computer[keys::computer::OS] = keys::computer::OS_LINUX;
_computer[keys::computer::vendor] = "";
_computer[keys::computer::model] = "";
//no implememntation at this time
}

View file

@ -31,52 +31,7 @@ void MACOSInstance::enumerateCpu() {
_cpu.push_back(cpu);
}
/*
static void getCpuId( uint32_t* p, uint32_t ax )
{
#ifdef Q_OS_MAC
__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)
);
#endif
}
void MACOSInstance::enumerateCpu() {
json cpu = {};
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[keys::cpu::vendor] = CPUBrandString;
cpu[keys::cpu::model] = CPUModelString;
cpu[keys::cpu::clockSpeed] = CPUClockString;
cpu[keys::cpu::numCores] = std::thread::hardware_concurrency();
_cpu.push_back(cpu);
}
*/
void MACOSInstance::enumerateGpu() {
GPUIdent* ident = GPUIdent::getInstance();
json gpu = {};

View file

@ -15,51 +15,57 @@
#ifdef Q_OS_WIN
#include <intrin.h>
void getCPUID(int32_t* p, int32_t ax) {
__cpuid(p, ax);
void getCPUID(uint32_t* p, uint32_t eax) {
__cpuid((int*) p, (int) eax);
}
void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) {
__cpuidex(p, ax, ecx);
void getCPUIDEX(uint32_t* p, uint32_t eax, uint32_t ecx) {
__cpuidex((int*) p, (int) eax, (int) ecx);
}
#elif defined(Q_OS_MAC)
void getCPUID(int32_t* p, int32_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 getCPUID(uint32_t* p, uint32_t eax) {
__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" (eax)
);
}
void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) {
getCPUID(p, ax);
void getCPUIDEX(uint32_t* p, uint32_t eax, uint32_t ecx) {
getCPUID(p, eax);
}
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
void getCPUID(int32_t* p, int32_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 getCPUID(uint32_t* p, uint32_t eax) {
__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" (eax)
);
}
void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) {
getCPUID(p, ax);
void getCPUIDEX(uint32_t* p, uint32_t eax, uint32_t ecx) {
getCPUID(p, eax);
}
#else
void getCPUID(int32_t* p, int32_t ax) {
void getCPUID(uint32_t* p, uint32_t eax) {
if (p) {
memset(p, 0, 4*4);
p[0] = 0;
p[1] = 0;
p[2] = 0;
p[3] = 0;
}
}
void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) {
getCPUID(p, ax);
void getCPUIDEX(uint32_t* p, uint32_t eax, uint32_t ecx) {
if (p) {
p[0] = 0;
p[1] = 0;
p[2] = 0;
p[3] = 0;
}
}
#endif
@ -141,7 +147,7 @@ CPUIdent::CPUIdent_Internal::CPUIdent_Internal()
extdata_{}
{
//int cpuInfo[4] = {-1};
std::array<int, 4> cpui;
std::array<uint32_t, 4> cpui;
// Calling __cpuid with 0x0 as the function_id argument
// gets the number of the highest valid function ID.

View file

@ -105,8 +105,8 @@ private:
public:
CPUIdent_Internal();
int nIds_;
int nExIds_;
uint32_t nIds_;
uint32_t nExIds_;
std::string vendor_;
std::string brand_;
bool isIntel_;
@ -117,8 +117,8 @@ private:
std::bitset<32> f_7_ECX_;
std::bitset<32> f_81_ECX_;
std::bitset<32> f_81_EDX_;
std::vector<std::array<int, 4>> data_;
std::vector<std::array<int, 4>> extdata_;
std::vector<std::array<uint32_t, 4>> data_;
std::vector<std::array<uint32_t, 4>> extdata_;
};
};

View file

@ -10,37 +10,9 @@ PlatformInfo.getNumGPUs()
PlatformInfo.getGPU(0)
// {"driver":"25.21.14.1967","model":"NVIDIA GeForce GTX 1080","vendor":"NVIDIA GeForce GTX 1080","videoMemory":8079}
var Page = Script.require('./luci/Page.js');
var window = Desktop.createWindow(Script.resolvePath('./platform.qml'), {
title: "Platform",
presentationMode: Desktop.PresentationMode.NATIVE,
size: {x: 350, y: 700}
});
function openView() {
var pages = new Pages();
function fromQml(message) {
if (pages.open(message.method)) {
return;
}
}
var platformWindow
function closeLuciWindow() {
if (luciWindow !== undefined) {
activeWindow.fromQml.disconnect(fromQml);
}
luciWindow = {};
Controller.mousePressEvent.disconnect(onMousePressEvent);
Controller.mouseReleaseEvent.disconnect(onMouseReleaseEvent);
Controller.mouseMoveEvent.disconnect(onMouseMoveEvent);
pages.clear();
}
pages.addPage('Platform', 'Platform', '../platform.qml', 350, 700);
pages.open('Platform');
return pages;
}
openView();