#include #include #include // declare function as extern because it will be resolved during link-time extern void cpuid_query(unsigned long, unsigned long far *); void main() { int i = 0; // our output buffer, 4x4 = 16 bytes long unsigned long far * theptr = (unsigned long far *)malloc(4 * sizeof(long)); // define initial values of this array because I want to show that the ASM routine will // overwrite these numbers theptr[0] = 10; theptr[1] = 20; theptr[2] = 30; theptr[3] = 40; printf("Original theptr array: "); for(i = 0; i < 4; i++) printf("%d ", theptr[i]); // Just to demonstrate the difference between a straight C pointer and a seg:offset combo printf( "\nThe ptr in C %lX", theptr ); printf( "\nPTR seg and offset %X %X\n", FP_SEG(theptr), FP_OFF(theptr) ); // Check out Intel docs for the list of valid function IDs that can be passed to the CPUID // instruction. The values used below are some function IDs that I know my CPU supports. // These values are also probably meaningless if you don't look it up in the Intel docs. cpuid_query((unsigned long)0x00, theptr); for(i = 0; i < 4; i++) printf("%08lX ", theptr[i]); printf("\n"); cpuid_query((unsigned long)0x01, theptr); for(i = 0; i < 4; i++) printf("%08lX ", theptr[i]); printf("\n"); cpuid_query((unsigned long)0x02, theptr); for(i = 0; i < 4; i++) printf("%08lX ", theptr[i]); printf("\n"); cpuid_query((unsigned long)0x03, theptr); for(i = 0; i < 4; i++) printf("%08lX ", theptr[i]); printf("\n"); cpuid_query((unsigned long)0x04, theptr); for(i = 0; i < 4; i++) printf("%08lX ", theptr[i]); printf("\n"); cpuid_query((unsigned long)0x05, theptr); for(i = 0; i < 4; i++) printf("%08lX ", theptr[i]); printf("\n"); cpuid_query((unsigned long)0x80000000, theptr); for(i = 0; i < 4; i++) printf("%08lX ", theptr[i]); printf("\n"); cpuid_query((unsigned long)0x80000001, theptr); for(i = 0; i < 4; i++) printf("%08lX ", theptr[i]); printf("\n"); cpuid_query((unsigned long)0x80000002, theptr); for(i = 0; i < 4; i++) printf("%08lX ", theptr[i]); printf("\n"); cpuid_query((unsigned long)0x80000003, theptr); for(i = 0; i < 4; i++) printf("%08lX ", theptr[i]); printf("\n"); cpuid_query((unsigned long)0x80000004, theptr); for(i = 0; i < 4; i++) printf("%08lX ", theptr[i]); printf("\n"); cpuid_query((unsigned long)0x80000006, theptr); for(i = 0; i < 4; i++) printf("%08lX ", theptr[i]); printf("\n"); }