Next: , Previous: Check_CPU Procedure, Up: A Complete Example


24.7.2 Intel_CPU Package Specification

     -------------------------------------------------------------------------
     --                                                                     --
     --  file: intel_cpu.ads                                                --
     --                                                                     --
     --           *********************************************             --
     --           * WARNING: for 32-bit Intel processors only *             --
     --           *********************************************             --
     --                                                                     --
     --  This package contains a number of subprograms that are useful in   --
     --  determining the Intel x86 CPU (and the features it supports) on    --
     --  which the program is running.                                      --
     --                                                                     --
     --  The package is based upon the information given in the Intel       --
     --  Application Note AP-485: "Intel Processor Identification and the   --
     --  CPUID Instruction" as of April 1998. This application note can be  --
     --  found on www.intel.com.                                            --
     --                                                                     --
     --  It currently deals with 32-bit processors only, will not detect    --
     --  features added after april 1998, and does not guarantee proper     --
     --  results on Intel-compatible processors.                            --
     --                                                                     --
     --  Cache info and x386 fpu type detection are not supported.          --
     --                                                                     --
     --  This package does not use any privileged instructions, so should   --
     --  work on any OS running on a 32-bit Intel processor.                --
     --                                                                     --
     -------------------------------------------------------------------------
     
     with Interfaces;             use Interfaces;
     --  for using unsigned types
     
     with System.Machine_Code;    use System.Machine_Code;
     --  for using inline assembler code
     
     with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
     --  for inserting control characters
     
     package Intel_CPU is
     
        ----------------------
        --  Processor bits  --
        ----------------------
     
        subtype Num_Bits is Natural range 0 .. 31;
        --  the number of processor bits (32)
     
        --------------------------
        --  Processor register  --
        --------------------------
     
        --  define a processor register type for easy access to
        --  the individual bits
     
        type Processor_Register is array (Num_Bits) of Boolean;
        pragma Pack (Processor_Register);
        for Processor_Register'Size use 32;
     
        -------------------------
        --  Unsigned register  --
        -------------------------
     
        --  define a processor register type for easy access to
        --  the individual bytes
     
        type Unsigned_Register is
           record
              L1 : Unsigned_8;
              H1 : Unsigned_8;
              L2 : Unsigned_8;
              H2 : Unsigned_8;
           end record;
     
        for Unsigned_Register use
           record
              L1 at 0 range  0 ..  7;
              H1 at 0 range  8 .. 15;
              L2 at 0 range 16 .. 23;
              H2 at 0 range 24 .. 31;
           end record;
     
        for Unsigned_Register'Size use 32;
     
        ---------------------------------
        --  Intel processor vendor ID  --
        ---------------------------------
     
        Intel_Processor : constant String (1 .. 12) := "GenuineIntel";
        --  indicates an Intel manufactured processor
     
        ------------------------------------
        --  Processor signature register  --
        ------------------------------------
     
        --  a register type to hold the processor signature
     
        type Processor_Signature is
           record
              Stepping       : Natural range 0 .. 15;
              Model          : Natural range 0 .. 15;
              Family         : Natural range 0 .. 15;
              Processor_Type : Natural range 0 .. 3;
              Reserved       : Natural range 0 .. 262143;
           end record;
     
        for Processor_Signature use
           record
              Stepping       at 0 range  0 ..  3;
              Model          at 0 range  4 ..  7;
              Family         at 0 range  8 .. 11;
              Processor_Type at 0 range 12 .. 13;
              Reserved       at 0 range 14 .. 31;
           end record;
     
        for Processor_Signature'Size use 32;
     
        -----------------------------------
        --  Processor features register  --
        -----------------------------------
     
        --  a processor register to hold the processor feature flags
     
        type Processor_Features is
           record
              FPU    : Boolean;                --  floating point unit on chip
              VME    : Boolean;                --  virtual mode extension
              DE     : Boolean;                --  debugging extension
              PSE    : Boolean;                --  page size extension
              TSC    : Boolean;                --  time stamp counter
              MSR    : Boolean;                --  model specific registers
              PAE    : Boolean;                --  physical address extension
              MCE    : Boolean;                --  machine check extension
              CX8    : Boolean;                --  cmpxchg8 instruction
              APIC   : Boolean;                --  on-chip apic hardware
              Res_1  : Boolean;                --  reserved for extensions
              SEP    : Boolean;                --  fast system call
              MTRR   : Boolean;                --  memory type range registers
              PGE    : Boolean;                --  page global enable
              MCA    : Boolean;                --  machine check architecture
              CMOV   : Boolean;                --  conditional move supported
              PAT    : Boolean;                --  page attribute table
              PSE_36 : Boolean;                --  36-bit page size extension
              Res_2  : Natural range 0 .. 31;  --  reserved for extensions
              MMX    : Boolean;                --  MMX technology supported
              FXSR   : Boolean;                --  fast FP save and restore
              Res_3  : Natural range 0 .. 127; --  reserved for extensions
           end record;
     
        for Processor_Features use
           record
              FPU    at 0 range  0 ..  0;
              VME    at 0 range  1 ..  1;
              DE     at 0 range  2 ..  2;
              PSE    at 0 range  3 ..  3;
              TSC    at 0 range  4 ..  4;
              MSR    at 0 range  5 ..  5;
              PAE    at 0 range  6 ..  6;
              MCE    at 0 range  7 ..  7;
              CX8    at 0 range  8 ..  8;
              APIC   at 0 range  9 ..  9;
              Res_1  at 0 range 10 .. 10;
              SEP    at 0 range 11 .. 11;
              MTRR   at 0 range 12 .. 12;
              PGE    at 0 range 13 .. 13;
              MCA    at 0 range 14 .. 14;
              CMOV   at 0 range 15 .. 15;
              PAT    at 0 range 16 .. 16;
              PSE_36 at 0 range 17 .. 17;
              Res_2  at 0 range 18 .. 22;
              MMX    at 0 range 23 .. 23;
              FXSR   at 0 range 24 .. 24;
              Res_3  at 0 range 25 .. 31;
           end record;
     
        for Processor_Features'Size use 32;
     
        -------------------
        --  Subprograms  --
        -------------------
     
        function Has_FPU return Boolean;
        --  return True if a FPU is found
        --  use only if CPUID is not supported
     
        function Has_CPUID return Boolean;
        --  return True if the processor supports the CPUID instruction
     
        function CPUID_Level return Natural;
        --  return the CPUID support level (0, 1 or 2)
        --  can only be called if the CPUID instruction is supported
     
        function Vendor_ID return String;
        --  return the processor vendor identification string
        --  can only be called if the CPUID instruction is supported
     
        function Signature return Processor_Signature;
        --  return the processor signature
        --  can only be called if the CPUID instruction is supported
     
        function Features return Processor_Features;
        --  return the processors features
        --  can only be called if the CPUID instruction is supported
     
     private
     
        ------------------------
        --  EFLAGS bit names  --
        ------------------------
     
        ID_Flag : constant Num_Bits := 21;
        --  ID flag bit
     
     end Intel_CPU;