home *** CD-ROM | disk | FTP | other *** search
- /* $Archive: /General Utilities/CPUID/extname.cpp $
- $Author : $
- $Date : $
- $Header : $
- $History: extname.cpp $
- *
- * ***************** Version 6 *****************
- * User: Hnguyen Date: 12/04/96 Time: 2:52a
- * Updated in $/General Utilities/CPUID
- *
- * ***************** Version 5 *****************
- * User: Tanb Date: 7/18/96 Time: 4:59p
- * Updated in $/General Utilities/CPUID
- * Minor changed in display
- */
-
-
- #include "DEFINES.H"
- #include <iostream.h>
- #include <iomanip.h>
- #include <stdlib.h>
- #include <conio.h>
-
- //cpu_signature identifies the specific CPU by providing information
- //regarding the type, instruction family, model, stepping revision and
- //feature flags. The feature flags indicates the existence or presence of
- // specific features.
-
- void cpuid :: ext_cpu_signature (void)
- {
- int signature = 0; //Signature variable
- int stepping_id = 0; //Stepping id variable
- int model = 0; //Model variable
- int inst_family = 0; //Instruction family variable
- unsigned int reg_ax = 0 ; //AX register variable
- unsigned long reg_eax,reg_edx,test_reg, //Register variables
- print_eax,print_ebx,print_ecx,print_edx; //Display variables
- int maxbit = 18; //Control loop variable
- int bits ; //Case statement variable
-
- asm {
- mov EAX,0x80000001 //EAX = 8000_0001h
- db 0x0F, 0xA2 //CPUID opcode
-
- }
- //display the value of the registers
- print_eax = _EAX;
- print_ebx = _EBX;
- print_ecx = _ECX;
- print_edx = _EDX;
-
- reg_edx = _EDX; //Store the extended feature flags
- reg_ax = _AX;
- asm mov BX, reg_ax
- asm and BL,0x0F //Mask the right most 4 bits
- stepping_id = _BL; //to get the cpu stepping id
-
- asm mov BX, reg_ax
- asm and BL,0xF0 //Mask the left most 4 bits
- asm ror BL,4 //to get the cpu model
- model = _BL;
-
- asm mov BX, reg_ax //get the cpu instruction family
- asm and BH, 0x0F
- inst_family = _BH;
-
- asm and EAX,0xFFFFF000 //Get bits[31-12]
- asm ror EAX,12
- reg_eax = _EAX;
-
- asm mov BX, reg_ax //Get the CPU signature
- asm and BX,0x0FF0
- signature = _BX;
-
- clrscr();
- cout.setf(ios::uppercase);
- cout << "Function 8000_0001h (EAX = 80000001)" << endl;
- cout << "=====================================";
- cout << "\n\n";
- cout << "EAX == "<< setw(8) << hex << print_eax<<" EBX == " << setw(8)
- << hex << print_ebx << " ECX == "<< setw (8) << hex << print_ecx
- << " EDX == " << setw(8) << hex << print_edx << "\n\n";
- cout << " EAX[3:0] == " << setw(1) << hex << stepping_id << endl;
- cout << " EAX[7:4] == " << setw(1) << hex << model << endl;
- cout << " EAX[11:8] == " << setw(1) << hex << inst_family << endl;
- cout << " EAX[31:12] == " << setw(5) << hex << reg_eax << endl;
- cout.unsetf(ios::uppercase);
-
- cout << "\n";
- cout << " AMD Processor Signature : ";
-
- if (signature == 0x0660)
- cout << " AMD-K6 " << endl;
- else {
- if(signature == 0x0510)
- cout << " AMD-K5 (Model 1) " << endl;
- if(signature == 0x0520)
- cout << " AMD-K5 (Model 2) " << endl;
- if(signature == 0x0530)
- cout << " AMD-K5 (Model 3) " << endl;
- else cout << " Undefined " << endl;
- }
- cout << "\n";
- cout << " Feature Flags : " << "\n\n";
- cout << " EDX == ";
- cout.setf(ios::uppercase);
- cout << setw(8) << hex << reg_edx << "\n\n";
- cout.unsetf(ios::uppercase);
- cout << " Press any key for more. " << endl;
- cout << "\n\n";
- getch();
- clrscr();
-
-
- //get the feature flags
- for ( bits = 0; bits <= maxbit; bits++){
- switch (bits) {
- case 0 : test_reg = reg_edx;
- if((test_reg & 0x00000001)== 0x00000001){ //test bit 0
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[0] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 0==1 indicates FPU present)" << endl;
- }
- else {
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[0] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 0==1 indicates FPU present)" << endl;
- }
- test_reg = reg_edx;
- break;
- case 1 : if ((test_reg & 0x00000002 )==0x00000002){ //test bit 1
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[1] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 1==1 indicates Virtual Mode Extensions)"
- << endl;
- }
- else {
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[1] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 1==1 indicates Virtual Mode Extensions)"
- << endl;
- }
- test_reg = reg_edx;
- break;
- case 2 : if ((test_reg & 0x00000004 )==0x00000004){ //test bit 2
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[2] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 2==1 indicates Debugging Extensions)" << endl;
- }
- else {
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[2] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 2==1 indicates Debugging Extensions )" << endl;
- }
- test_reg = reg_edx;
- break;
-
- case 3 : if ((test_reg & 0x00000008 )==0x00000008){ //test bit 3
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[3] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 3==1 indicates Page Size Extensions)" << endl;
- }
- else {
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[3] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 3==1 indicates Page Size Extensions)" << endl;
- }
- test_reg = reg_edx;
- break;
- case 4 : if ((test_reg & 0x00000010 )==0x00000010){ //test bit 4
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[4] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 4==1 indicates Time Stamp Counter)" << endl;
- }
- else {
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[4] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 4==1 indicates Time Stamp Counter )"<< endl;
- }
- test_reg = reg_edx;
- break;
- case 5 : if ((test_reg & 0x00000020 )==0x00000020){ //test bit 5
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[5] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 5==1 indicates K86 Model-Specific Registers)"
- << endl;
- }
- else {
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[5] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 5==1 indicates K86 Model-Specific Registers)"
- << endl;
- }
- test_reg = reg_edx;
- break;
- case 6 : if((test_reg & 0x00000040) == 0x00000000){ //test bit 6
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[6] = 0b ";
- cout.unsetf(ios::left);
- cout << " Reserved" << endl;
- }
- test_reg = reg_edx;
- break;
- case 7 : if ((test_reg & 0x00000080 )==0x00000080){ //test bit 7
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[7] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 7==1 indicates Support of Machine";
- cout << " Check Exception)" << endl;
- }
- else {
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[7] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 7==1 indicates Support of Machine";
- cout << " Check Exception)" << endl;
- }
- test_reg = reg_edx;
- break;
- case 8 : if ((test_reg & 0x00000100 )==0x00000100){ //test bit 9
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[8] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 8==1 indicates Support of CMPXCHG8B "
- << "instruction)" << endl;
- }
- else {
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[8] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 8==1 indicates Support of CMPXCHG8B";
- cout << " instruction)" << endl;
- }
- test_reg = reg_edx;
- break;
- case 9 : if ((test_reg & 0x00000200 )==0x00000000){
- cout.width(13);
- cout.setf(ios::left);
- cout << "EDX[9] = 0b ";
- cout.unsetf(ios::left);
- cout << " Reserved" << endl;
- }
- test_reg = reg_edx;
- break;
- case 10 : if ((test_reg & 0x00000400 )==0x00000400){
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[10] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 10==1 indicates Support of SYSCALL";
- cout << " and SYSRET Extension)"<< endl;
- }
- else {
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[10] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 10==1 indicates Support of SYSCALL";
- cout << " and SYSRET Extensions)" << endl;
- }
- test_reg = reg_edx;
- break;
- case 11 : if ((test_reg & 0x00001800 )==0x00000000){
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[11:12] = ";
- cout.unsetf(ios::left);
- cout << " Reserved" << endl;
- }
- test_reg = reg_edx;
- break;
- case 12 : if ((test_reg & 0x00002000 )==0x00002000){
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[13] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 13==1 indicates Support of Global Paging "
- << "Extensions)" << endl;
- }
- else {
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[13] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 13==1 indicates Support of Global Paging "
- << "Extensions) "<< endl;
- }
- test_reg = reg_edx;
- break;
- case 13 : if ((test_reg & 0x00004000 )==0x00000000){
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[14] = 0b";
- cout.unsetf(ios::left);
- cout << " Reserved" << endl;
- }
- test_reg = reg_edx;
- break;
- case 14 : if ((test_reg & 0x00008000 )==0x00008000){
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[15] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 15==1 indicates Support of Integer "
- << "Conditional Move" << endl;
- cout << " Instructions)" << endl;
- }
- else {
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[15] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 15==1 indicates Support of Integer"
- << " Conditional Move" << endl;
- cout << " Instructions)" << endl;
- }
- test_reg = reg_edx;
- break;
- case 15 : if ((test_reg & 0x00010000) == 0x00010000){
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[16] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 16==1 indicates Support of Floating-Point"
- << " Conditional Move" << endl;
- cout << " Instructions) " << endl;
- }
- else {
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[16] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 16==1 indicates Support of Floating-Point"
- << " Conditional Move" << endl;
- cout << " Instructions) " << endl;
- }
- test_reg = reg_edx;
- break;
- case 16 : if ((test_reg & 0x007E0000) == 0x00000000) {
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[17:22] = ";
- cout.unsetf(ios::left);
- cout << " Reserved" << endl;
- }
- test_reg = reg_edx;
- break;
- case 17 : if ((test_reg & 0x00800000) == 0x00800000){
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[23] = 1b ";
- cout.unsetf(ios::left);
- cout << " (bit 23==1 indicates Support of MultiMedia"
- << " eXtensions) " << endl;
- }
- else {
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[23] = 0b ";
- cout.unsetf(ios::left);
- cout << " (bit 16==1 indicates Support of MultiMedia"
- << " eXtensions) " << endl;
- }
- test_reg = reg_edx;
- break;
- case 18 : if ((test_reg & 0xFF000000) == 0x00000000) {
- cout.width(12);
- cout.setf(ios::left);
- cout << "EDX[24:31] = ";
- cout.unsetf(ios::left);
- cout << " Reserved" << endl;
- }
-
-
- }
- }
- cout << "\n Press any key for more. " << endl;
- getch();
- }
-