mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
Moved to asm cpuid call. Support for CPU name string. Output skecth on main
This commit is contained in:
15
02h.c
15
02h.c
@@ -1,6 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "02h.h"
|
||||
#include "cpuid.h"
|
||||
|
||||
#define MASK1 0xFF;
|
||||
#define MASK2 0xFF00;
|
||||
@@ -23,18 +24,6 @@ struct TLB {
|
||||
//http://www.sandpile.org/x86/cpuid.htm
|
||||
//http://www.hugi.scene.org/online/coding/hugi%2016%20-%20corawhd4.htm
|
||||
|
||||
/*** EXEC CPUID INSTRUCTION ***/
|
||||
static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
|
||||
unsigned int *ecx, unsigned int *edx)
|
||||
{
|
||||
asm volatile("cpuid"
|
||||
: "=a" (*eax),
|
||||
"=b" (*ebx),
|
||||
"=c" (*ecx),
|
||||
"=d" (*edx)
|
||||
: "0" (*eax), "2" (*ecx));
|
||||
}
|
||||
|
||||
/*** ACCORDING TO CPUID TABLE ***/
|
||||
//TO BE IMPLEMENTED
|
||||
void fillWithDescriptor(unsigned int desc, struct level2* data) {
|
||||
@@ -328,7 +317,7 @@ struct level2* fillLevel2(struct level2* data) {
|
||||
|
||||
unsigned eax, ebx, ecx, edx;
|
||||
eax = 2;
|
||||
native_cpuid(&eax, &ebx, &ecx, &edx);
|
||||
cpuid(&eax, &ebx, &ecx, &edx);
|
||||
|
||||
unsigned int desc[16];
|
||||
|
||||
|
||||
7
Makefile
7
Makefile
@@ -2,12 +2,13 @@ CXX=gcc
|
||||
|
||||
CXXFLAGS=-g
|
||||
|
||||
MAIN=main.c
|
||||
SOURCE=main.c 02h.c extended.c cpuid.c
|
||||
HEADERS=02h.h extended.h cpuid.h
|
||||
|
||||
OUTPUT=cpufetch
|
||||
|
||||
$(OUTPUT): Makefile $(MAIN) 02h.c 02h.h
|
||||
$(CXX) $(CXXFLAGS) $(MAIN) 02h.c -o $(OUTPUT)
|
||||
$(OUTPUT): Makefile $(SOURCE) $(HEADERS)
|
||||
$(CXX) $(CXXFLAGS) $(SOURCE) -o $(OUTPUT)
|
||||
|
||||
clean:
|
||||
@rm $(OUTPUT1) $(OUTPUT2)
|
||||
|
||||
12
cpuid.c
Normal file
12
cpuid.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "cpuid.h"
|
||||
|
||||
void cpuid(unsigned int *eax, unsigned int *ebx,
|
||||
unsigned int *ecx, unsigned int *edx)
|
||||
{
|
||||
asm volatile("cpuid"
|
||||
: "=a" (*eax),
|
||||
"=b" (*ebx),
|
||||
"=c" (*ecx),
|
||||
"=d" (*edx)
|
||||
: "0" (*eax), "2" (*ecx));
|
||||
}
|
||||
6
cpuid.h
Normal file
6
cpuid.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef __CPUID__
|
||||
#define __CPUID__
|
||||
|
||||
void cpuid(unsigned int *eax, unsigned int *ebx,unsigned int *ecx, unsigned int *edx);
|
||||
|
||||
#endif
|
||||
77
extended.c
Normal file
77
extended.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "extended.h"
|
||||
|
||||
char* getCPUName() {
|
||||
unsigned eax, ebx, ecx, edx;
|
||||
|
||||
//First, check we can use extended
|
||||
eax = 0x80000000;
|
||||
cpuid(&eax, &ebx, &ecx, &edx);
|
||||
if(eax < 0x80000001)
|
||||
return NULL;
|
||||
|
||||
//We can, fetch name
|
||||
char* name = malloc(sizeof(char)*64);
|
||||
|
||||
eax = 0x80000002;
|
||||
cpuid(&eax, &ebx, &ecx, &edx);
|
||||
|
||||
name[__COUNTER__] = eax & MASK;
|
||||
name[__COUNTER__] = (eax>>8) & MASK;
|
||||
name[__COUNTER__] = (eax>>16) & MASK;
|
||||
name[__COUNTER__] = (eax>>24) & MASK;
|
||||
name[__COUNTER__] = ebx & MASK;
|
||||
name[__COUNTER__] = (ebx>>8) & MASK;
|
||||
name[__COUNTER__] = (ebx>>16) & MASK;
|
||||
name[__COUNTER__] = (ebx>>24) & MASK;
|
||||
name[__COUNTER__] = ecx & MASK;
|
||||
name[__COUNTER__] = (ecx>>8) & MASK;
|
||||
name[__COUNTER__] = (ecx>>16) & MASK;
|
||||
name[__COUNTER__] = (ecx>>24) & MASK;
|
||||
name[__COUNTER__] = edx & MASK;
|
||||
name[__COUNTER__] = (edx>>8) & MASK;
|
||||
name[__COUNTER__] = (edx>>16) & MASK;
|
||||
name[__COUNTER__] = (edx>>24) & MASK;
|
||||
|
||||
eax = 0x80000003;
|
||||
cpuid(&eax, &ebx, &ecx, &edx);
|
||||
|
||||
name[__COUNTER__] = eax & MASK;
|
||||
name[__COUNTER__] = (eax>>8) & MASK;
|
||||
name[__COUNTER__] = (eax>>16) & MASK;
|
||||
name[__COUNTER__] = (eax>>24) & MASK;
|
||||
name[__COUNTER__] = ebx & MASK;
|
||||
name[__COUNTER__] = (ebx>>8) & MASK;
|
||||
name[__COUNTER__] = (ebx>>16) & MASK;
|
||||
name[__COUNTER__] = (ebx>>24) & MASK;
|
||||
name[__COUNTER__] = ecx & MASK;
|
||||
name[__COUNTER__] = (ecx>>8) & MASK;
|
||||
name[__COUNTER__] = (ecx>>16) & MASK;
|
||||
name[__COUNTER__] = (ecx>>24) & MASK;
|
||||
name[__COUNTER__] = edx & MASK;
|
||||
name[__COUNTER__] = (edx>>8) & MASK;
|
||||
name[__COUNTER__] = (edx>>16) & MASK;
|
||||
name[__COUNTER__] = (edx>>24) & MASK;
|
||||
|
||||
eax = 0x80000004;
|
||||
cpuid(&eax, &ebx, &ecx, &edx);
|
||||
|
||||
name[__COUNTER__] = eax & MASK;
|
||||
name[__COUNTER__] = (eax>>8) & MASK;
|
||||
name[__COUNTER__] = (eax>>16) & MASK;
|
||||
name[__COUNTER__] = (eax>>24) & MASK;
|
||||
name[__COUNTER__] = ebx & MASK;
|
||||
name[__COUNTER__] = (ebx>>8) & MASK;
|
||||
name[__COUNTER__] = (ebx>>16) & MASK;
|
||||
name[__COUNTER__] = (ebx>>24) & MASK;
|
||||
name[__COUNTER__] = ecx & MASK;
|
||||
name[__COUNTER__] = (ecx>>8) & MASK;
|
||||
name[__COUNTER__] = (ecx>>16) & MASK;
|
||||
name[__COUNTER__] = (ecx>>24) & MASK;
|
||||
name[__COUNTER__] = edx & MASK;
|
||||
name[__COUNTER__] = (edx>>8) & MASK;
|
||||
name[__COUNTER__] = (edx>>16) & MASK;
|
||||
name[__COUNTER__] = (edx>>24) & MASK;
|
||||
|
||||
name[__COUNTER__] = '\0';
|
||||
return name;
|
||||
}
|
||||
10
extended.h
Normal file
10
extended.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef __EXTENDED__
|
||||
#define __EXTENDED__
|
||||
|
||||
#define MASK 0xFF
|
||||
#include "cpuid.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char* getCPUName();
|
||||
|
||||
#endif
|
||||
21
main.c
21
main.c
@@ -1,9 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "02h.h"
|
||||
#include "extended.h"
|
||||
|
||||
/***
|
||||
SAMPLE OUTPUT
|
||||
|
||||
Name: Intel Core i7-4790K
|
||||
Arch: 64 Bits
|
||||
Frecuency: 4.0 GHz
|
||||
NºCores: 4 cores(8 threads)
|
||||
AXV: AVX,AVX2
|
||||
SSE: SSE,SSE2,SSE4.1,SSE4.2
|
||||
FMA: FMA3
|
||||
AES: Yes
|
||||
SHA: No
|
||||
L1 Size: 32KB(Data)32KB(Instructions)
|
||||
L2 Size: 512KB
|
||||
L3 Size: 8MB
|
||||
Peak FLOPS: 512 GFLOP/s(in simple precision)
|
||||
|
||||
***/
|
||||
|
||||
int main() {
|
||||
struct level2* level2 = fillLevel2(level2);
|
||||
debugLevel2(level2);
|
||||
freeLevel2(level2);
|
||||
printf("%s\n",getCPUName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user