Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Лаб2012 / 253665.pdf
Скачиваний:
33
Добавлен:
02.02.2015
Размер:
3.31 Mб
Скачать

CHAPTER 14

PROCESSOR IDENTIFICATION AND

FEATURE DETERMINATION

When writing software intended to run on IA-32 processors, it is necessary to identify the type of processor present in a system and the processor features that are available to an application.

14.1USING THE CPUID INSTRUCTION

Use the CPUID instruction for processor identification in the Pentium M processor family, Pentium 4 processor family, Intel Xeon processor family, P6 family, Pentium processor, and later Intel486 processors. This instruction returns the family, model and (for some processors) a brand string for the processor that executes the instruction. It also indicates the features that are present in the processor and give information about the processors caches and TLB.

The ID flag (bit 21) in the EFLAGS register indicates support for the CPUID instruction. If a software procedure can set and clear this flag, the processor executing the procedure supports the CPUID instruction. The CPUID instruction will cause the invalid opcode exception (#UD) if executed on a processor that does not support it.

To obtain processor identification information, a source operand value is placed in the EAX register to select the type of information to be returned. When the CPUID instruction is executed, selected information is returned in the EAX, EBX, ECX, and EDX registers. For a complete description of the CPUID instruction, tables indicating values returned, and example code, see “CPUID—CPUID Identification” in Chapter 3 of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A.

14.1.1Notes on Where to Start

For detailed application notes on the instruction, see AP-485, Intel Processor Identification and the CPUID Instruction (Order Number 241618). This publication provides additional information and example source code for use in identifying IA-32 processors. It also contains guidelines for using the CPUID instruction to help maintain the widest range of software compatibility. The following guidelines are among the most important, and should always be followed when using the CPUID instruction to determine available features:

Always begin by testing for the “GenuineIntel,” message in the EBX, EDX, and ECX registers when the CPUID instruction is executed with EAX equal to 0. If the processor is not genuine Intel, the feature identification flags may have different meanings than are described in Intel documentation.

Vol. 1 14-1

PROCESSOR IDENTIFICATION AND FEATURE DETERMINATION

Test feature identification flags individually and do not make assumptions about undefined bits.

14.1.2Identification of Earlier IA-32 Processors

The CPUID instruction is not available in earlier IA-32 processors up through the earlier Intel486 processors. For these processors, several other architectural features can be exploited to identify the processor.

The settings of bits 12 and 13 (IOPL), 14 (NT), and 15 (reserved) in the EFLAGS register are different for Intel’s 32-bit processors than for the Intel 8086 and Intel 286 processors. By examining the settings of these bits (with the PUSHF/PUSHFD and POP/POPFD instructions), an application program can determine whether the processor is an 8086, Intel 286, or one of the Intel 32-bit processors:

8086 processor — Bits 12 through 15 of the EFLAGS register are always set.

Intel 286 processor — Bits 12 through 15 are always clear in real-address mode.

32-bit processors — In real-address mode, bit 15 is always clear and bits 12 through 14 have the last value loaded into them. In protected mode, bit 15 is always clear, bit 14 has the last value loaded into it, and the IOPL bits depends on the current privilege level (CPL). The IOPL field can be changed only if the CPL is 0.

Other EFLAG register bits that can be used to differentiate between the 32-bit processors:

Bit 18 (AC) — Implemented only on the Pentium 4, Intel Xeon, P6 family, Pentium, and Intel486 processors. The inability to set or clear this bit distinguishes an Intel386 processor from the later IA-32 processors.

Bit 21 (ID) — Determines if the processor is able to execute the CPUID instruction. The ability to set and clear this bit indicates that it is a Pentium 4, Intel Xeon, P6 family, Pentium, or later-version Intel486 processor.

To determine whether an x87 FPU or NPX is present in a system, applications can write to the x87 FPU status and control registers using the FNINIT instruction and then verify that the correct values are read back using the FNSTENV instruction.

After determining that an x87 FPU or NPX is present, its type can then be determined. In most cases, the processor type will determine the type of FPU or NPX; however, an Intel386 processor is compatible with either an Intel 287 or Intel 387 math coprocessor.

The method the coprocessor uses to represent ∞ (after the execution of the FINIT, FNINIT, or RESET instruction) indicates which coprocessor is present. The Intel 287 math coprocessor uses the same bit representation for +∞ and −∞; whereas, the Intel 387 math coprocessor uses different representations for +∞ and −∞.

14-2 Vol. 1

APPENDIX A

EFLAGS CROSS-REFERENCE

A.1 EFLAGS AND INSTRUCTIONS

Table A-2 summarizes how the instructions affect the flags in the EFLAGS register. The following codes describe how the flags are affected.

 

Table A-1. Codes Describing Flags

 

 

T

Instruction tests flag.

M

Instruction modifies flag (either sets or resets depending on operands).

0

Instruction resets flag.

1

Instruction sets flag.

Instruction's effect on flag is undefined.

R

Instruction restores prior value of flag.

Blank

Instruction does not affect flag.

 

 

Table A-2. EFLAGS Cross-Reference

Instruction

OF

SF

ZF

AF

PF

CF

TF

IF

DF

NT

RF

 

 

 

 

 

 

 

 

 

 

 

 

AAA

TM

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AAD

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AAM

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AAS

TM

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ADC

M

M

M

M

M

TM

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ADD

M

M

M

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AND

0

M

M

M

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ARPL

 

 

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

BOUND

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

BSF/BSR

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

BSWAP

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

BT/BTS/BTR/BTC

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CALL

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CBW

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Vol. 1 A-1

EFLAGS CROSS-REFERENCE

Table A-2. EFLAGS Cross-Reference (Contd.)

Instruction

OF

SF

ZF

AF

PF

CF

TF

IF

DF

NT

RF

 

 

 

 

 

 

 

 

 

 

 

 

CLC

 

 

 

 

 

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CLD

 

 

 

 

 

 

 

 

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CLI

 

 

 

 

 

 

 

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CLTS

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CMC

 

 

 

 

 

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CMOVcc

T

T

T

 

T

T

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CMP

M

M

M

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CMPS

M

M

M

M

M

M

 

 

T

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CMPXCHG

M

M

M

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CMPXCHG8B

 

 

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

COMSID

0

0

M

0

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

COMISS

0

0

M

0

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CPUID

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CWD

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DAA

M

M

TM

M

TM

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DAS

M

M

TM

M

TM

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DEC

M

M

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DIV

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ENTER

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ESC

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

FCMOVcc

 

 

T

 

T

T

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

FCOMI, FCOMIP, FUCOMI,

 

 

M

 

M

M

 

 

 

 

 

FUCOMIP

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

HLT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

IDIV

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

IMUL

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

IN

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

INC

M

M

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

INS

 

 

 

 

 

 

 

 

T

 

 

 

 

 

 

 

 

 

 

 

 

 

 

INT

 

 

 

 

 

 

0

 

 

0

 

 

 

 

 

 

 

 

 

 

 

 

 

INTO

T

 

 

 

 

 

0

 

 

0

 

 

 

 

 

 

 

 

 

 

 

 

 

A-2 Vol. 1

EFLAGS CROSS-REFERENCE

Table A-2. EFLAGS Cross-Reference (Contd.)

Instruction

OF

SF

ZF

AF

PF

CF

TF

IF

DF

NT

RF

 

 

 

 

 

 

 

 

 

 

 

 

INVD

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

INVLPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

UCOMSID

0

0

M

0

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

UCOMISS

0

0

M

0

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

IRET

R

R

R

R

R

R

R

R

R

T

 

 

 

 

 

 

 

 

 

 

 

 

 

Jcc

T

T

T

 

T

T

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

JCXZ

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

JMP

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LAHF

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LAR

 

 

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LDS/LES/LSS/LFS/LGS

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LEA

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LEAVE

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LGDT/LIDT/LLDT/LMSW

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LOCK

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LODS

 

 

 

 

 

 

 

 

T

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LOOP

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LOOPE/LOOPNE

 

 

T

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LSL

 

 

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LTR

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MONITOR

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MWAIT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MOV

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MOV control, debug, test

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MOVS

 

 

 

 

 

 

 

 

T

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MOVSX/MOVZX

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MUL

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

NEG

M

M

M

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

NOP

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

NOT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

OR

0

M

M

M

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Vol. 1 A-3

EFLAGS CROSS-REFERENCE

Table A-2. EFLAGS Cross-Reference (Contd.)

Instruction

OF

SF

ZF

AF

PF

CF

TF

IF

DF

NT

RF

 

 

 

 

 

 

 

 

 

 

 

 

OUT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

OUTS

 

 

 

 

 

 

 

 

T

 

 

 

 

 

 

 

 

 

 

 

 

 

 

POP/POPA

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

POPF

R

R

R

R

R

R

R

R

R

R

 

 

 

 

 

 

 

 

 

 

 

 

 

PUSH/PUSHA/PUSHF

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RCL/RCR 1

M

 

 

 

 

TM

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RCL/RCR count

 

 

 

 

TM

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RDMSR

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RDPMC

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RDTSC

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

REP/REPE/REPNE

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RET

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ROL/ROR 1

M

 

 

 

 

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ROL/ROR count

 

 

 

 

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RSM

M

M

M

M

M

M

M

M

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

SAHF

 

R

R

R

R

R

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SAL/SAR/SHL/SHR 1

M

M

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SAL/SAR/SHL/SHR

M

M

M

M

 

 

 

 

 

count

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SBB

M

M

M

M

M

TM

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SCAS

M

M

M

M

M

M

 

 

T

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SETcc

T

T

T

 

T

T

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SGDT/SIDT/SLDT/SMSW

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SHLD/SHRD

M

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

STC

 

 

 

 

 

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

STD

 

 

 

 

 

 

 

 

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

STI

 

 

 

 

 

 

 

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

STOS

 

 

 

 

 

 

 

 

T

 

 

 

 

 

 

 

 

 

 

 

 

 

 

STR

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SUB

M

M

M

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TEST

0

M

M

M

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

A-4 Vol. 1

EFLAGS CROSS-REFERENCE

Table A-2. EFLAGS Cross-Reference (Contd.)

Instruction

OF

SF

ZF

AF

PF

CF

TF

IF

DF

NT

RF

 

 

 

 

 

 

 

 

 

 

 

 

UD2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

VERR/VERRW

 

 

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

WAIT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

WBINVD

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

WRMSR

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

XADD

M

M

M

M

M

M

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

XCHG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

XLAT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

XOR

0

M

M

M

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Vol. 1 A-5

EFLAGS CROSS-REFERENCE

A-6 Vol. 1

Соседние файлы в папке Лаб2012