AMD AMD-K6-2/450 Design Guide - Page 71

Using CPUID Functions, When software uses the CPUID instruction to identify

Page 71 highlights

23913A/0-November 2000 Preliminary Information Embedded AMD-K6™ Processors BIOS Design Guide If the value has changed, the CPUID instruction is available for identifying the processor and its features. The following code sample demonstrates the way a program uses the PUSHFD and POPFD instructions to test the ID bit. pushfd pop eax mov ebx, eax xor eax, 00200000h push eax popfd pushfd pop eax cmp eax, ebx jz NO_CPUID ; Save EFLAGS to stack ; Store EFLAGS in EAX ; Save in EBX for testing later ; Switch bit 21 ; Copy changed value to stack ; Save changed EAX to EFLAGS ; Push EFLAGS to top of stack ; Store EFLAGS in EAX ; See if bit 21 has changed ; If no change, no CPUID A potential problem with this approach is that an interrupt or a trap (such as a debug trap) can occur between the POPFD and the following PUSHFD, and that the interrupt or trap handler code destroys the value of the ID bit. Where possible, the above code should be preceded by a CLI instruction and followed by an STI instruction, which ensures that no interrupts occur between the POPFD and the PUSHFD. However, traps can still occur, even if the code is preceded by a CLI instruction and followed by an STI instruction. Using CPUID Functions When software uses the CPUID instruction to identify a process or, it is impo rt ant t hat it uses t he inst ruc tio n appropriately. The instruction has been defined to make it easy to identify the type and features of x86 processors manufactured by many different vendors. The standard functions (EAX=0 and EAX=1) are the same for all processors. Having standard functions simplifies software's task of testing for and implementing features common to x86 processors. Software can test for these features and, as new x86 processors are released, benefit from these capabilities immediately. Extended functions are specific to a vendor's processor. These functions provide additional information about AMD processors that software can use to identify enhanced features and functions. To test for extended functions, software checks Embedded AMD Processor Recognition 59

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98

Embedded AMD Processor Recognition
59
23913A/0—November 2000
Embedded AMD-K6™ Processors BIOS Design Guide
Preliminary Information
If the value has changed, the CPUID instruction is available for
identifying the processor and its features. The following code
sample demonstrates the way a program uses the PUSHFD and
POPFD instructions to test the ID bit.
pushfd
; Save EFLAGS to stack
pop
eax
; Store EFLAGS in EAX
mov
ebx, eax
; Save in EBX for testing later
xor
eax, 00200000h
; Switch bit 21
push
eax
; Copy changed value to stack
popfd
; Save changed EAX to EFLAGS
pushfd
; Push EFLAGS to top of stack
pop
eax
; Store EFLAGS in EAX
cmp
eax, ebx
; See if bit 21 has changed
jz
NO_CPUID
; If no change, no CPUID
A potential problem with this approach is that an interrupt or a
trap (such as a debug trap) can occur between the POPFD and
the following PUSHFD, and that the interrupt or trap handler
code destroys the value of the ID bit. Where possible, the above
code should be preceded by a CLI instruction and followed by
an STI instruction, which ensures that no interrupts occur
between the POPFD and the PUSHFD. However, traps can still
occur, even if the code is preceded by a CLI instruction and
followed by an STI instruction.
Using CPUID Functions
When software uses the CPUID instruction to identify a
processor, it is important that it uses the instruction
appropriately. The instruction has been defined to make it easy
to identify the type and features of x86 processors
manufactured by many different vendors.
The standard functions (EAX=0 and EAX=1) are the same for
all processors. Having standard functions simplifies software’s
task of testing for and implementing features common to x86
processors. Software can test for these features and, as new x86
processors are released, benefit from these capabilities
immediately.
Extended functions are specific to a vendor’s processor. These
functions provide additional information about AMD
processors that software can use to identify enhanced features
and functions. To test for extended functions, software checks