1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
/* List of known Vendor Strings */
#define AMD_OLD "AMDisbetter!" /* Truer words were never stuck inside a piece of silicon... */
#define AMD_CURRENT "AuthenticAMD" /* I prefer the other one tbh */
#define CENTAUR "CentaurHauls"
#define CYRIX "CyrixInstead"
#define INTEL "GenuineIntel" /* How boring. Just what happened to
* "HOLY SHIT INTEL CORE 2 EXTREEEEEEEEEEEEME"?
* Oh wait, that's a marketing technique. I get it.
*/
#define TRANSMETA_1 "TransmetaCPU"
#define TRANSMETA_2 "GenuineTMx86" /* Huh. They spelt "GenuineIntel" wrong... */
#define NAT_SEMICON "Geode by NSC"
#define NEXGEN "NexGenDriven"
/* Now we're done with those CPUs made by imaginative people, here come the
* vendor strings which, frankly, are boring as hell:
*/
#define RISE "RiseRiseRise" /* OOH IMAGINATIVE */
#define SIS "SiS SiS SiS " /* How *did* you come up with that? */
#define UMC "UMC UMC UMC " /* Anyone else noticing a pattern? */
#define VIA "VIA VIA VIA " /* Blatant plagiarism of awesome vendor string idea is blatant. */
void sighandle(int sig) {
printf("Your segments;\n\n\nThey have faulted.\n");
exit(1);
}
typedef struct cpuid {
char vendor_string[12];
char manufacturer[24];
} cpuid_t;
char* get_manufacturer(const char*);
cpuid_t do_cpuid(void);
int main() {
signal(SIGSEGV, sighandle);
cpuid_t stcpuid;
stcpuid = do_cpuid();
printf("Dumping processor information...\n\n");
printf("Manufacturer:\t%s\tVendor string:\t%s\n",
stcpuid.manufacturer, stcpuid.vendor_string
);
return 0;
}
char* get_manufacturer(const char* vstring) {
if (strcmp(AMD_OLD, vstring) == 0 || strcmp(AMD_CURRENT, vstring) == 0)
return "AMD";
if (strcmp(CENTAUR, vstring) == 0)
return "Centaur";
if (strcmp(CYRIX, vstring) == 0)
return "Cyrix";
if (strcmp(INTEL, vstring) == 0)
return "Intel";
if (strcmp(TRANSMETA_1, vstring) == 0 || strcmp(TRANSMETA_2, vstring) == 0)
return "Transmeta";
if (strcmp(NAT_SEMICON, vstring) == 0)
return "National Semiconductor";
if (strcmp(NEXGEN, vstring) == 0)
return "NexGen";
return "Unknown";
}
cpuid_t do_cpuid(void) {
cpuid_t stcpuid;
void* pvstring = (void*)stcpuid.vendor_string;
asm volatile(
"mov $0, %%eax\n\t"
"cpuid \n\t"
"mov %0, %%rsi\n\t"
"mov %%ebx, 0(%%rsi)\n\t"
"mov %%edx, 4(%%rsi)\n\t"
"mov %%ecx, 8(%%rsi)\n\t"
:"=m"(pvstring)
);
printf("%s\n", get_manufacturer(stcpuid.vendor_string));
return stcpuid;
}
|
output:
$ ./cpuid
Intel
Your segments;
They have faulted. |