home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 1998 April / Freeware-CD.bin / cputst / amd_cpu / amd!.EXE / EXTNAME.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-20  |  12.5 KB  |  409 lines

  1. /*      $Archive: /General Utilities/CPUID/extname.cpp $
  2.     $Author : $
  3.     $Date   : $
  4.     $Header : $
  5.     $History: extname.cpp $
  6.  * 
  7.  * *****************  Version 6  *****************
  8.  * User: Hnguyen      Date: 12/04/96   Time: 2:52a
  9.  * Updated in $/General Utilities/CPUID
  10.  * 
  11.  * *****************  Version 5  *****************
  12.  * User: Tanb         Date: 7/18/96    Time: 4:59p
  13.  * Updated in $/General Utilities/CPUID
  14.  * Minor changed in display
  15.  */
  16.  
  17.  
  18. #include "DEFINES.H"
  19. #include <iostream.h>
  20. #include <iomanip.h>
  21. #include <stdlib.h>
  22. #include <conio.h>
  23.  
  24. //cpu_signature identifies the specific CPU by providing information
  25. //regarding the type, instruction family, model, stepping revision and
  26. //feature flags. The feature flags indicates the existence or presence of
  27. // specific features.
  28.  
  29. void cpuid :: ext_cpu_signature (void)
  30. {
  31.   int signature = 0;        //Signature variable
  32.   int stepping_id = 0;      //Stepping id variable
  33.   int model = 0;            //Model variable 
  34.   int inst_family = 0;      //Instruction family variable
  35.   unsigned int reg_ax = 0 ; //AX register variable
  36.   unsigned long reg_eax,reg_edx,test_reg,  //Register variables              
  37.         print_eax,print_ebx,print_ecx,print_edx;  //Display variables
  38.   int maxbit = 18;          //Control loop variable
  39.   int bits ;                //Case statement variable
  40.  
  41.   asm {
  42.          mov EAX,0x80000001        //EAX = 8000_0001h
  43.          db 0x0F, 0xA2            //CPUID opcode
  44.  
  45.   }
  46.   //display the value of the registers
  47.   print_eax = _EAX;
  48.   print_ebx = _EBX;
  49.   print_ecx = _ECX;
  50.   print_edx = _EDX;
  51.  
  52.   reg_edx = _EDX;      //Store the extended feature flags
  53.   reg_ax = _AX;        
  54.   asm mov BX, reg_ax
  55.   asm  and BL,0x0F     //Mask the right most 4 bits
  56.   stepping_id = _BL;   //to get the cpu stepping id
  57.  
  58.   asm  mov BX, reg_ax
  59.   asm  and BL,0xF0    //Mask the left most 4 bits
  60.   asm  ror BL,4       //to get the cpu model
  61.   model = _BL;
  62.  
  63.   asm mov BX, reg_ax   //get the cpu instruction family
  64.   asm and BH, 0x0F
  65.   inst_family = _BH;
  66.  
  67.   asm and EAX,0xFFFFF000  //Get bits[31-12]
  68.   asm ror EAX,12
  69.   reg_eax = _EAX;
  70.  
  71.   asm mov BX, reg_ax     //Get the CPU signature
  72.   asm and BX,0x0FF0
  73.   signature = _BX;
  74.  
  75.   clrscr();
  76.   cout.setf(ios::uppercase);
  77.   cout << "Function 8000_0001h (EAX = 80000001)" << endl;
  78.   cout << "=====================================";
  79.   cout << "\n\n";
  80.   cout << "EAX == "<< setw(8) << hex << print_eax<<"   EBX == " << setw(8)
  81.          << hex << print_ebx << "   ECX == "<< setw (8) << hex << print_ecx
  82.          << "   EDX == " << setw(8) << hex << print_edx << "\n\n";
  83.   cout << "     EAX[3:0]   == " << setw(1) << hex << stepping_id << endl;
  84.   cout << "     EAX[7:4]   == " << setw(1) << hex << model << endl;
  85.   cout << "     EAX[11:8]  == " << setw(1) << hex << inst_family << endl;
  86.   cout << "     EAX[31:12] == " << setw(5) << hex << reg_eax << endl;
  87.   cout.unsetf(ios::uppercase);
  88.  
  89.   cout << "\n";
  90.   cout << "     AMD Processor Signature : ";
  91.  
  92.   if (signature == 0x0660)
  93.      cout << " AMD-K6 " << endl;
  94.   else {
  95.     if(signature == 0x0510)
  96.        cout << " AMD-K5 (Model 1) " << endl;
  97.     if(signature == 0x0520)
  98.        cout << " AMD-K5 (Model 2) " << endl;
  99.     if(signature == 0x0530)
  100.        cout << " AMD-K5 (Model 3) " << endl;
  101.     else cout << " Undefined " << endl;
  102.   }
  103.   cout << "\n";
  104.   cout << "     Feature Flags : " << "\n\n";
  105.   cout << "          EDX == ";
  106.   cout.setf(ios::uppercase);
  107.   cout << setw(8) << hex << reg_edx << "\n\n";
  108.   cout.unsetf(ios::uppercase);
  109.   cout << "                   Press any key for more. " << endl;
  110.   cout << "\n\n";
  111.   getch();
  112.   clrscr();
  113.  
  114.  
  115.   //get the feature flags
  116.   for ( bits = 0; bits <= maxbit; bits++){
  117.      switch (bits) {
  118.         case 0 : test_reg = reg_edx;
  119.              if((test_reg & 0x00000001)== 0x00000001){    //test bit 0
  120.                       cout.width(13);
  121.                       cout.setf(ios::left);
  122.                       cout << "EDX[0]  = 1b ";
  123.                       cout.unsetf(ios::left);
  124.                       cout << " (bit 0==1 indicates FPU present)" << endl;
  125.                     }
  126.                     else {
  127.                       cout.width(13);
  128.                       cout.setf(ios::left);
  129.                       cout << "EDX[0]  = 0b ";
  130.                       cout.unsetf(ios::left);
  131.                       cout << " (bit 0==1 indicates FPU present)" << endl;
  132.                     }
  133.                     test_reg = reg_edx;
  134.                     break;
  135.         case 1 : if ((test_reg & 0x00000002 )==0x00000002){  //test bit 1
  136.                       cout.width(13);
  137.                       cout.setf(ios::left);
  138.                       cout << "EDX[1]  = 1b ";
  139.                       cout.unsetf(ios::left);
  140.                       cout << " (bit 1==1 indicates Virtual Mode Extensions)"
  141.                              << endl;
  142.                     }
  143.                     else {
  144.                       cout.width(13);
  145.                       cout.setf(ios::left);
  146.                       cout << "EDX[1]  = 0b ";
  147.                       cout.unsetf(ios::left);
  148.                       cout << " (bit 1==1 indicates Virtual Mode Extensions)"
  149.                              << endl;
  150.                     }
  151.                     test_reg = reg_edx;
  152.                     break;
  153.         case 2 : if ((test_reg & 0x00000004 )==0x00000004){   //test bit 2
  154.                       cout.width(13);
  155.                       cout.setf(ios::left);
  156.                       cout << "EDX[2]  = 1b ";
  157.                       cout.unsetf(ios::left);
  158.                       cout << " (bit 2==1 indicates Debugging Extensions)" << endl;
  159.                     }
  160.                     else {
  161.                       cout.width(13);
  162.                       cout.setf(ios::left);
  163.                       cout << "EDX[2]  = 0b ";
  164.                       cout.unsetf(ios::left);
  165.                       cout << " (bit 2==1 indicates Debugging Extensions )" << endl;
  166.                     }
  167.                     test_reg = reg_edx;
  168.                     break;
  169.  
  170.         case 3 : if ((test_reg & 0x00000008 )==0x00000008){   //test bit 3
  171.                       cout.width(13);
  172.                       cout.setf(ios::left);
  173.                       cout << "EDX[3]  = 1b ";
  174.                       cout.unsetf(ios::left);
  175.                       cout << " (bit 3==1 indicates Page Size Extensions)" << endl;
  176.                     }
  177.                     else {
  178.                       cout.width(13);
  179.                       cout.setf(ios::left);
  180.                       cout << "EDX[3]  = 0b ";
  181.                       cout.unsetf(ios::left);
  182.                       cout << " (bit 3==1 indicates Page Size Extensions)" << endl;
  183.                     }
  184.                     test_reg = reg_edx;
  185.                     break;
  186.         case 4 : if ((test_reg & 0x00000010 )==0x00000010){    //test bit 4
  187.                       cout.width(13);
  188.                       cout.setf(ios::left);
  189.                       cout << "EDX[4]  = 1b ";
  190.                       cout.unsetf(ios::left);
  191.                       cout << " (bit 4==1 indicates Time Stamp Counter)" << endl;
  192.                     }
  193.                     else {
  194.                       cout.width(13);
  195.                       cout.setf(ios::left);
  196.                       cout << "EDX[4]  = 0b ";
  197.                       cout.unsetf(ios::left);
  198.                       cout << " (bit 4==1 indicates Time Stamp Counter )"<< endl;
  199.                     }
  200.                     test_reg = reg_edx;
  201.                     break;
  202.         case 5 : if ((test_reg & 0x00000020 )==0x00000020){   //test bit 5
  203.                       cout.width(13);
  204.                       cout.setf(ios::left);
  205.                       cout << "EDX[5]  = 1b ";
  206.                       cout.unsetf(ios::left);
  207.                       cout << " (bit 5==1 indicates K86 Model-Specific Registers)"
  208.                              << endl;
  209.                     }
  210.                     else {
  211.                       cout.width(13);
  212.                       cout.setf(ios::left);
  213.                       cout << "EDX[5]  = 0b ";
  214.                       cout.unsetf(ios::left);
  215.                       cout << " (bit 5==1 indicates K86 Model-Specific Registers)"
  216.                              << endl;
  217.                     }
  218.                     test_reg = reg_edx;
  219.                     break;
  220.         case 6 : if((test_reg & 0x00000040) == 0x00000000){   //test bit 6
  221.                       cout.width(13);
  222.                       cout.setf(ios::left);
  223.                       cout << "EDX[6]  = 0b ";
  224.                       cout.unsetf(ios::left);
  225.                       cout << " Reserved" << endl;
  226.                     }
  227.                     test_reg = reg_edx;
  228.                     break;
  229.         case 7 : if ((test_reg & 0x00000080 )==0x00000080){  //test bit 7
  230.                       cout.width(13);
  231.                       cout.setf(ios::left);
  232.                       cout << "EDX[7]  = 1b ";
  233.                       cout.unsetf(ios::left);
  234.                       cout << " (bit 7==1 indicates Support of Machine";
  235.                       cout << " Check Exception)" << endl;
  236.                     }
  237.                     else {
  238.                       cout.width(13);
  239.                       cout.setf(ios::left);
  240.                       cout << "EDX[7]  = 0b ";
  241.                       cout.unsetf(ios::left);
  242.                       cout << " (bit 7==1 indicates Support of Machine";
  243.                       cout << " Check Exception)" << endl;
  244.                     }
  245.                     test_reg = reg_edx;
  246.                     break;
  247.         case 8 : if ((test_reg & 0x00000100 )==0x00000100){    //test bit 9
  248.                       cout.width(13);
  249.                       cout.setf(ios::left);
  250.                       cout << "EDX[8]  = 1b ";
  251.                       cout.unsetf(ios::left);
  252.                       cout << " (bit 8==1 indicates Support of CMPXCHG8B "
  253.                              << "instruction)" << endl;
  254.                     }
  255.                     else {
  256.                       cout.width(13);
  257.                       cout.setf(ios::left);
  258.                       cout << "EDX[8]  = 0b ";
  259.                       cout.unsetf(ios::left);
  260.                       cout << " (bit 8==1 indicates Support of CMPXCHG8B";
  261.                       cout << " instruction)" << endl;
  262.                     }
  263.                     test_reg = reg_edx;
  264.                     break;
  265.         case 9 : if ((test_reg & 0x00000200 )==0x00000000){
  266.                       cout.width(13);
  267.                       cout.setf(ios::left);
  268.                       cout << "EDX[9]  = 0b ";
  269.                       cout.unsetf(ios::left);
  270.                       cout << " Reserved" << endl;
  271.                     }
  272.                     test_reg = reg_edx;
  273.                     break;
  274.       case 10 : if ((test_reg & 0x00000400 )==0x00000400){
  275.                       cout.width(12);
  276.                       cout.setf(ios::left);
  277.                       cout << "EDX[10] = 1b ";
  278.                       cout.unsetf(ios::left);
  279.                       cout << " (bit 10==1 indicates Support of SYSCALL";
  280.                       cout << " and SYSRET Extension)"<< endl;
  281.                     }
  282.                     else {
  283.                       cout.width(12);
  284.                       cout.setf(ios::left);
  285.                       cout << "EDX[10] = 0b ";
  286.                       cout.unsetf(ios::left);
  287.                       cout << " (bit 10==1 indicates Support of SYSCALL";
  288.                       cout << " and SYSRET Extensions)" << endl;
  289.                     }
  290.                     test_reg = reg_edx;
  291.                     break;
  292.         case 11 : if ((test_reg & 0x00001800 )==0x00000000){
  293.                       cout.width(12);
  294.                       cout.setf(ios::left);
  295.                       cout << "EDX[11:12] = ";
  296.                       cout.unsetf(ios::left);
  297.                       cout << " Reserved" << endl;
  298.                     }
  299.                     test_reg = reg_edx;
  300.                     break;
  301.       case 12 : if ((test_reg & 0x00002000 )==0x00002000){
  302.                       cout.width(12);
  303.                       cout.setf(ios::left);
  304.                       cout << "EDX[13] = 1b ";
  305.                       cout.unsetf(ios::left);
  306.                       cout << " (bit 13==1 indicates Support of Global Paging "
  307.                              << "Extensions)" << endl;
  308.                     }
  309.                     else {
  310.                       cout.width(12);
  311.                       cout.setf(ios::left);
  312.                       cout << "EDX[13] = 0b ";
  313.                       cout.unsetf(ios::left);
  314.                       cout << " (bit 13==1 indicates Support of Global Paging "
  315.                              << "Extensions) "<< endl;
  316.                     }
  317.                     test_reg = reg_edx;
  318.                     break;
  319.         case 13 : if ((test_reg & 0x00004000 )==0x00000000){
  320.                       cout.width(12);
  321.                       cout.setf(ios::left);
  322.                       cout << "EDX[14] = 0b";
  323.                       cout.unsetf(ios::left);
  324.                       cout << "  Reserved" << endl;
  325.                     }
  326.                     test_reg = reg_edx;
  327.                     break;
  328.       case 14 : if ((test_reg & 0x00008000 )==0x00008000){
  329.                       cout.width(12);
  330.                       cout.setf(ios::left);
  331.                       cout << "EDX[15] = 1b ";
  332.                       cout.unsetf(ios::left);
  333.                       cout << " (bit 15==1 indicates Support of Integer "
  334.                              << "Conditional Move" << endl;
  335.                       cout << "              Instructions)" << endl;
  336.                     }
  337.                     else {
  338.                       cout.width(12);
  339.                       cout.setf(ios::left);
  340.                       cout << "EDX[15] = 0b ";
  341.                       cout.unsetf(ios::left);
  342.                       cout << " (bit 15==1 indicates Support of Integer"
  343.                              << " Conditional Move" << endl;
  344.                       cout << "              Instructions)" << endl;
  345.                     }
  346.                     test_reg = reg_edx;
  347.                     break;
  348.         case 15 : if ((test_reg & 0x00010000) == 0x00010000){
  349.                       cout.width(12);
  350.                       cout.setf(ios::left);
  351.                       cout << "EDX[16] = 1b ";
  352.                       cout.unsetf(ios::left);
  353.                       cout << " (bit 16==1 indicates Support of Floating-Point"
  354.                              << " Conditional Move" << endl;
  355.                       cout << "              Instructions) " << endl;
  356.                     }
  357.                     else {
  358.                       cout.width(12);
  359.                       cout.setf(ios::left);
  360.                       cout << "EDX[16] = 0b ";
  361.                       cout.unsetf(ios::left);
  362.                       cout << " (bit 16==1 indicates Support of Floating-Point"
  363.                              << " Conditional Move" << endl;
  364.                       cout << "              Instructions) " << endl;
  365.                     }
  366.                     test_reg = reg_edx;
  367.                     break;
  368.       case 16 : if ((test_reg & 0x007E0000) == 0x00000000) {
  369.                     cout.width(12);
  370.                     cout.setf(ios::left);
  371.                     cout << "EDX[17:22] = ";
  372.                     cout.unsetf(ios::left);
  373.                     cout << " Reserved" << endl;
  374.                     }
  375.                     test_reg = reg_edx;
  376.                     break;
  377.       case 17 : if ((test_reg & 0x00800000) == 0x00800000){
  378.                       cout.width(12);
  379.                       cout.setf(ios::left);
  380.                       cout << "EDX[23] = 1b ";
  381.                       cout.unsetf(ios::left);
  382.                       cout << " (bit 23==1 indicates Support of MultiMedia"
  383.                              << " eXtensions) " << endl;
  384.                     }
  385.                     else {
  386.                       cout.width(12);
  387.                       cout.setf(ios::left);
  388.                       cout << "EDX[23] = 0b ";
  389.                       cout.unsetf(ios::left);
  390.                       cout << " (bit 16==1 indicates Support of MultiMedia"
  391.                              << " eXtensions) " << endl;
  392.                     }
  393.                     test_reg = reg_edx;
  394.                     break;
  395.       case 18 : if ((test_reg & 0xFF000000) == 0x00000000) {
  396.                     cout.width(12);
  397.                     cout.setf(ios::left);
  398.                     cout << "EDX[24:31] = ";
  399.                     cout.unsetf(ios::left);
  400.                     cout << " Reserved" << endl;
  401.                     }
  402.  
  403.  
  404.      }
  405.   }
  406.   cout << "\n                   Press any key for more. " << endl;
  407.   getch();
  408. }
  409.