mirror of https://github.com/a0rtega/pafish
Add cpu functions to query Processor Brand String
This commit is contained in:
parent
89cf87ead9
commit
94dca540db
41
pafish/cpu.c
41
pafish/cpu.c
|
@ -2,6 +2,7 @@
|
|||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "cpu.h"
|
||||
|
@ -34,8 +35,8 @@ static inline void cpuid_vendor_00(char * vendor) {
|
|||
|
||||
__asm__ volatile("cpuid" \
|
||||
: "=b"(ebx), \
|
||||
"=c"(ecx), \
|
||||
"=d"(edx) \
|
||||
"=c"(ecx), \
|
||||
"=d"(edx) \
|
||||
: "a"(0x00));
|
||||
sprintf(vendor , "%c%c%c%c", ebx, (ebx >> 8), (ebx >> 16), (ebx >> 24));
|
||||
sprintf(vendor+4, "%c%c%c%c", edx, (edx >> 8), (edx >> 16), (edx >> 24));
|
||||
|
@ -43,6 +44,21 @@ static inline void cpuid_vendor_00(char * vendor) {
|
|||
vendor[12] = 0x00;
|
||||
}
|
||||
|
||||
static inline void cpuid_brand(char * brand, uint32_t eax_value) {
|
||||
int eax, ebx, ecx, edx;
|
||||
|
||||
__asm__ volatile("cpuid" \
|
||||
: "=a"(eax), \
|
||||
"=b"(ebx), \
|
||||
"=c"(ecx), \
|
||||
"=d"(edx) \
|
||||
: "a"(eax_value));
|
||||
sprintf(brand , "%c%c%c%c", eax, (eax >> 8), (eax >> 16), (eax >> 24));
|
||||
sprintf(brand+4 , "%c%c%c%c", ebx, (ebx >> 8), (ebx >> 16), (ebx >> 24));
|
||||
sprintf(brand+8 , "%c%c%c%c", ecx, (ecx >> 8), (ecx >> 16), (ecx >> 24));
|
||||
sprintf(brand+12, "%c%c%c%c", edx, (edx >> 8), (edx >> 16), (edx >> 24));
|
||||
}
|
||||
|
||||
static inline int cpuid_hv_bit() {
|
||||
int ecx;
|
||||
__asm__ volatile("cpuid" \
|
||||
|
@ -81,6 +97,27 @@ void cpu_write_vendor(char * vendor) {
|
|||
cpuid_vendor_00(vendor);
|
||||
}
|
||||
|
||||
void cpu_write_brand(char * brand) {
|
||||
int eax;
|
||||
/* Check if Processor Brand String is supported */
|
||||
__asm__ volatile(".intel_syntax noprefix;"
|
||||
"mov eax, 0x80000000;"
|
||||
"cpuid;"
|
||||
"cmp eax, 0x80000004;"
|
||||
"xor eax, eax;"
|
||||
"setge al;"
|
||||
".att_syntax;"
|
||||
: "=a"(eax)
|
||||
);
|
||||
/* It's supported, so fill char * brand */
|
||||
if (eax) {
|
||||
cpuid_brand(brand, 0x80000002);
|
||||
cpuid_brand(brand+16, 0x80000003);
|
||||
cpuid_brand(brand+32, 0x80000004);
|
||||
brand[48] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
int cpu_known_vm_vendors(char * vendor) {
|
||||
const int count = 4;
|
||||
int i;
|
||||
|
|
|
@ -9,6 +9,7 @@ int cpu_rdtsc_force_vmexit();
|
|||
int cpu_hv();
|
||||
|
||||
void cpu_write_vendor(char *);
|
||||
void cpu_write_brand(char *);
|
||||
|
||||
int cpu_known_vm_vendors(char *);
|
||||
|
||||
|
|
Loading…
Reference in New Issue