So I made the raw output cpuid utility that outputs the eax, ebx, ecx and edx:
for eax=0 through 3: simply run: cpuid
for other cpuid: run: cpuid <eax in value>
Any suggestion, comments or critisizm (but not trolling ) is welcomed.
Just drop it into vi editor and
Code: Select all
cc cpuid.c
Code: Select all
(virtualenv) [root@localhost C]# cc --v
gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
(virtualenv) [root@localhost C]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.7 (Santiago)
(virtualenv) [root@localhost C]#
cpuid.c
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <fcntl.h>
typedef u_int8_t u8;
typedef u_int16_t u16;
typedef u_int32_t u32;
typedef u_int64_t u64;
int
main(int argc, char *argv[])
{
register int i;
register int k;
//int k;
int j;
int * cpuidInputs;
int tmpList[] = {0, 1, 2, 3};
int arrSize;
if (argc != 2 && argc != 1) {
printf("\nUsage: %s <cpuid initial eax value>\n", argv[0]);
printf("\nUsage: %s (prints our CPUID EAX=0 through EAX=3)\n", argv[0]);
exit(0);
}
if (argc == 2) {
printf("cmdline mode.");
int cpuidInput = strtoull(argv[1], NULL, 0);
printf("\nInput being assigned to eax: %x", cpuidInput);
cpuidInputs = (int*)malloc(sizeof(int));
cpuidInputs[0] = cpuidInput;
arrSize = 1;
printf("\ncpuidInputs[0]: %x", cpuidInputs[0]);
} else {
printf("default mode.");
cpuidInputs = (int*)calloc(sizeof(int), sizeof(tmpList)/sizeof(int));
for (j = 0; j < sizeof(tmpList)/sizeof(int); j++) {
printf("\nConstructing default array: %x...", tmpList[j]);
cpuidInputs[j] = tmpList[j];
}
arrSize = 4;
}
for (j = 0; j < arrSize; j ++) {
k = cpuidInputs[j];
printf("\n----------------------------");
printf("\nIssuing CPUID %x", k);
asm("\t movl %0,%%eax" : "=r"(k));
//asm("\t movl $0,%eax");
//asm("\t movl $1,%eax");
//asm("\t movl %%eax,%0" : "=r"(i));
//printf("\neax: %x", i);
//printf("\nChecking back eax...%x", i);
asm("\t cpuid");
asm("\t movl %%eax,%0" : "=r"(i));
printf("\n--cpuid %04x, --eax: %08x", k, i);
asm("\t movl %%ebx,%0" : "=r"(i));
printf("\n--cpuid %04x, --ebx: %08x", k, i);
asm("\t movl %%ecx,%0" : "=r"(i));
printf("\n--cpuid %04x, --ecx: %08x", k, i);
asm("\t movl %%edx,%0" : "=r"(i));
printf("\n--cpuid %04x, --edx: %08x", k, i);
}
printf("\nDone.\n");
exit(0);
}
output, friendly for automation, scripting and/or regexp/grep-ping:
Code: Select all
(virtualenv) [root@localhost C]# ./a.out
default mode.
Constructing default array: 0...
Constructing default array: 1...
Constructing default array: 2...
Constructing default array: 3...
----------------------------
Issuing CPUID 0
--cpuid 0000, --eax: 00000014
--cpuid 0000, --ebx: 00000014
--cpuid 0000, --ecx: 00400ac8
--cpuid 0000, --edx: fbf8fe10
----------------------------
Issuing CPUID 1
--cpuid 0001, --eax: 000406f1
--cpuid 0001, --ebx: 000406f1
--cpuid 0001, --ecx: 00400ac8
--cpuid 0001, --edx: fbf8fe10
----------------------------
Issuing CPUID 2
--cpuid 0002, --eax: 76036301
--cpuid 0002, --ebx: 76036301
--cpuid 0002, --ecx: 00400ac8
--cpuid 0002, --edx: fbf8fe10
----------------------------
Issuing CPUID 3
--cpuid 0003, --eax: 00000000
--cpuid 0003, --ebx: 00000000
--cpuid 0003, --ecx: 00400ac8
--cpuid 0003, --edx: fbf8fe10
Done.
(virtualenv) [root@localhost C]#