Identifying CPU

From AMC-OS Developers
Revision as of 13:30, 15 August 2012 by Kindman (talk | contribs)
Jump to navigation Jump to search

Introduction

All x86 CPUs starting with the 80386 have a signature indicating their type, family, model and stepping.

This signature is placed in EDX register when CPU starts. Starting with some late 486SX, a CPUID instruction has been added to retrieve easily this signature along with other CPU information. When the instruction is not supported, it is necessary to shutdown the CPU and get back control as soon as possible to store the value.

In AMC-OS, CPU identification is done during AMC-OS Loader execution.

Identification process

Identifying an Intel-compatible x86 CPU is done in several steps :

  • Check that we have a 32-bits 80386 minimum CPU.
  • Check the presence of the CPUID instruction.
    • If CPUID is supported, use the instruction to get CPU information and supported instructions.
    • If CPUID is not supported, reset the CPU to get its signature.
  • Calculate the operating frequency of the CPU by timing the execution of a sequence of instructions.

In AMC-OS, CPU identification is done during AMC-OS Loader execution. Code is found in CORE\SRC\AMCOSLDR\CPUID16.ASM.

Intel describes the complete process of CPU identification in Application Note 485.

Checking 80386 CPU

Follow this procedure to determine if we have at least a 386 CPU :

  • On a 8086/8088, bits 12-15 are always set to 1.
    • Put all bits of FLAGS register to 0 using POPF.
    • If bits 12-15 are still set after, we have a 8086/8088.
  • On a 80286, bits 12-14 are always set to 0.
    • Set bits 12-14 of EFLAGS (0x7000) using POPF.
    • If bits 12-14 are unset after, we have a 80286, a 386+ else.

You can also check the presence of a 486 by toggling bit 18 of EFLAGS register. It won't work on a 386.

CPUID instruction

First check that CPUID instruction is supported by trying changing the value of bit 21 of EFLAGS register. If the bit can be toggled, the processor support the CPUID instruction.

The CPUID instruction can provide you :

  • CPU signature (type, family, model, stepping)
  • CPU name, manufacturer signature, brand ID
  • Type and size of embedded code and data caches
  • CPU support of new features

Analyze the results of CPUID instruction called with EAX=0. For detailed specifications of the CPUID instruction, refer to :