GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Jun-2009, 05:27
aska aska is offline
New Member
 
Join Date: Jul 2008
Posts: 5
aska is on a distinguished road
Post

Type of microprocessor with C?


hi everyone , i write a program in C to determine the type of microprocessor ,so for this task i include in c code source a assembler code ,,,,

this my code
CPP / C++ / C Code:
// Compile by BC++version 3.1
#include <stdio.h>
#include <string.h>
#include <conio.h>

void main() {
  char VendorSign[13];   // for to store our vendorstring
  unsigned long MaxEAX;  //This will be used to store the maximum EAX
  char* Comp1[32];  //This is the array that will hold the short names
                    //for our features bitmap.
  unsigned long REGEAX, REGEBX, REGECX, REGEDX;
  int dFamily, dModel, dStepping, dFamilyEx, dModelEx;
  char dType[10];
  int dComp1Supported[32];
  int dBrand, dCacheLineSize, dLogicalProcessorCount, dLocalAPICID;
  asm {
    XOR EAX, EAX
    //An efficient alternatvie to MOV EAX, 0x0
    db 0fh,0a2h
    //=cpuID,This instruction will load our registers.
    MOV dword ptr [VendorSign], EBX
    //Copy the first 4 bytes in the VendorString from EBX.
    MOV dword ptr [VendorSign+4], EDX
    //Copy the next 4 bytes.
    MOV  dword ptr [VendorSign+8],   ECX
    //Copy the next 4 bytes.
    MOV  dword ptr MaxEAX,           EAX
    //EAX contains the maximum value to call CPUID with. Copy 
    //it to the MaxEAX variable.
  }
  VendorSign[12]=0;  
//The last character in the VendorSign can be anything.
//To make sure that it stops at the last character we add
//a zero character at the end
  printf("Vendor string: %s\n", VendorSign);
  printf("Maximum EAX value: %i\n", MaxEAX);
  if(strcmp(VendorSign, "GenuineIntel")==0) {
    Comp1[0]="FPU";   //Floating Point Unit
    Comp1[1]="VME";   //Virtual Mode Extension
    Comp1[2]="DE";    //Debugging Extension
    Comp1[3]="PSE";   //Page Size Extension
    Comp1[4]="TSC";   //Time Stamp Counter
    Comp1[5]="MSR";   //Model Specific Registers
    Comp1[6]="PAE";   //Physical Address Extesnion
    Comp1[7]="MCE";   //Machine Check Extension
    Comp1[8]="CX8";   //CMPXCHG8 Instruction
    Comp1[9]="APIC";  //On-chip APIC Hardware
    Comp1[10]="";     //Reserved
    Comp1[11]="SEP";  //SYSENTER SYSEXIT
    Comp1[12]="MTRR"; //Machine Type Range Registers
    Comp1[13]="PGE";  //Global Paging Extension
    Comp1[14]="MCA";  //Machine Check Architecture
    Comp1[15]="CMOV"; //Conditional Move Instrction
    Comp1[16]="PAT";  //Page Attribute Table
    Comp1[17]="PSE-36"; //36-bit Page Size Extension
    Comp1[18]="PSN";  //96-bit Processor Serial Number
    Comp1[19]="CLFSH"; //CLFLUSH Instruction
    Comp1[20]="";     //Reserved
    Comp1[21]="DS";   //Debug Trace Store
    Comp1[22]="ACPI"; //ACPI Support
    Comp1[23]="MMX";  //MMX Technology
    Comp1[24]="FXSR"; //FXSAVE FXRSTOR (Fast save and restore)
    Comp1[25]="SSE";  //Streaming SIMD Extensions
    Comp1[26]="SSE2"; //Streaming SIMD Extensions 2
    Comp1[27]="SS";   //Self-Snoop
    Comp1[28]="HTT";  //Hyper-Threading Technology
    Comp1[29]="TM";   //Thermal Monitor Supported
    Comp1[30]="IA-64"; //IA-64 capable
    Comp1[31]="";     //Reserved
  }
  else if(strcmp(VendorSign, "AuthenticAMD")==0) {
    Comp1[0]="FPU";   //Floating Point Unit
    Comp1[1]="VME";   //Virtual Mode Extension
    Comp1[2]="DE";    //Debugging Extension
    Comp1[3]="PSE";   //Page Size Extension
    Comp1[4]="TSC";   //Time Stamp Counter
    Comp1[5]="MSR";   //Model Specific Registers
    Comp1[6]="PAE";   //Physical Address Extesnion
    Comp1[7]="MCE";   //Machine Check Extension
    Comp1[8]="CX8";   //CMPXCHG8 Instruction
    Comp1[9]="APIC";  //On-chip APIC Hardware
    Comp1[10]="";     //Reserved
    Comp1[11]="SEP";  //SYSENTER SYSEXIT
    Comp1[12]="MTRR"; //Machine Type Range Registers
    Comp1[13]="PGE";  //Global Paging Extension
    Comp1[14]="MCA";  //Machine Check Architecture
    Comp1[15]="CMOV"; //Conditional Move Instrction
    Comp1[16]="PAT";  //Page Attribute Table
    Comp1[17]="PSE-36"; //36-bit Page Size Extension
    Comp1[18]="";     //?
    Comp1[19]="MPC";  //MultiProcessing Capable
    Comp1[20]="";     //Reserved
    Comp1[21]="";     //?
    Comp1[22]="MIE";  //AMD Multimedia Instruction Extensions
    Comp1[23]="MMX";  //MMX Technology
    Comp1[24]="FXSR"; //FXSAVE FXRSTOR (Fast save and restore)
    Comp1[25]="SSE";  //Streaming SIMD Extensions
    Comp1[26]="";     //?
    Comp1[27]="";     //?
    Comp1[28]="";     //?
    Comp1[29]="";     //?
    Comp1[30]="3DNowExt"; //3DNow Instruction Extensions
    Comp1[31]="3DNow"; //3DNow Instructions 
  }
  if(MaxEAX>=1) {
    asm {
      MOV     EAX,                    1
      db 0fh,0a2h
      MOV     [REGEAX],               EAX
      MOV     [REGEBX],               EBX
      MOV     [REGECX],               ECX
      MOV     [REGEDX],               EDX
    }
    dFamily=((REGEAX>>8)&0xF);
    dModel=((REGEAX>>4)&0xF);
    dStepping=(REGEAX&0xF);
    dFamilyEx=((REGEAX>>20)&0xFF);
    dModelEx=((REGEAX>>16)&0xF);
    switch(((REGEAX>>12)&0x7)) {
      case 0:
        strcpy(dType, "Original");
        break;
      case 1:
        strcpy(dType, "OverDrive");
        break;
      case 2:
        strcpy(dType, "Dual");
        break;
    }

    for(unsigned long C=1, Q=0;Q<32;C*=2, Q++) {
      dComp1Supported[Q]=(REGEDX&C)!=0?1:0;
    }


    dBrand=REGEBX&0xFF;
    dCacheLineSize=((strcmp(Comp1[19], "CLFSH")==0)
	&&(dComp1Supported[19]==1))?((REGEBX>>8)&0xFF)*8:-1;
    dLogicalProcessorCount=((strcmp(Comp1[28], "HTT")==0)
	&&(dComp1Supported[28]==1))?((REGEBX>>16)&0xFF):-1;
    dLocalAPICID=((REGEBX>>24)&0xFF); //This works on P4 or later
  }
  printf("%s\n", dType);
  printf("Family %i, Model %i, Stepping %i\n", dFamily, dModel, dStepping);
  printf("Extended Family %i, Extended Model %i\n", dFamilyEx, dModelEx);
  printf("Supported flags: ");
  for(unsigned long Q=0;Q<27;Q++) {
    if(dComp1Supported[Q]) {
      printf("%s ", Comp1[Q]);
    }
  }
  printf("\n");
  printf("CacheLineSize: %i\n", dCacheLineSize);
  printf("Logical processor count: %i\n", dLogicalProcessorCount);
  printf("Local APIC ID: %i\n", dLocalAPICID);
}
so in resulr i have one error in 17 line ,undefined symbole EAX ,,,so perhap i need to include another header file or what? thanks before for all helps
Last edited by LuciWiz : 01-Jun-2009 at 05:42. Reason: Please insert your C code between [cpp] & [/cpp] tags
  #2  
Old 01-Jun-2009, 15:40
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,217
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Type of microprocessor with C?


Quote:
Originally Posted by aska
hi everyone , i write a program in C to determine the type of microprocesso

For current Windows operating systems and compilers, look for information on msdn.

For example you can try using the GetSystemInfo() function: http://msdn.microsoft.com/en-us/libr...81(VS.85).aspx

The following works for me with fairly recent Borland and Microsoft compilers:
CPP / C++ / C Code:
#include <windows.h>
#include <stdio.h>
int main()
{
    SYSTEM_INFO system_info;
    GetSystemInfo(&system_info);
    printf("ProcessorType         =   %4d\n", system_info.dwProcessorType);
    printf("ProcessorArchitecture = 0x%04x\n",
            system_info.wProcessorArchitecture);
    printf("ProcessorLevel        = 0x%04x\n",
            system_info.wProcessorLevel);
    printf("ProcessorRevision     = 0x%04x\n",
            system_info.wProcessorRevision);
    return 0;
}

On my old, creaky (but not cranky) Windows xp platform, I see
Code:
ProcessorType = 586 ProcessorArchitecture = 0x0000 ProcessorLevel = 0x0006 ProcessorRevision = 0x0801

For Linux users: open /proc/cpuinfo as a file and read the stuff a line at a time. (Try cat /proc/cpuinfo from a command line to see what your program can expect to see.)

Regards,

Dave

Footnote: I hate to repeat myself, but if people are using ancient operating systems and/or old compilers (or anything other than ones that I mention above), things may not work the same. There are no standard C or C++ library functions that address hardware considerations, so, even though I show stuff that works for me, YMMV. (Your Mileage May Vary.)
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
template <class Data> problem, more than one data type qboy C++ Forum 1 13-Oct-2006 17:08
type* identifier or type *identifier for pointers? BobbyMurcerFan C Programming Language 3 07-Dec-2004 08:41
Error C2143: syntax error : missing ';' before 'type' small_ticket C Programming Language 6 15-May-2004 12:59
How Do i get php to find out the file type of a file for me? viperman95833 MySQL / PHP Forum 2 08-Mar-2003 10:48

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:01.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.