1 /* getprocessor() - determine processor type Author: Kees J. Bot */
3 #include <machine/asm.h>
5 /* int getprocessor(void); */
6 /* Return 386, 486, 586, ... */
10 andl $0xFFFFFFFC, %esp /* Align stack to avoid AC fault */
11 movl $0x00040000, %ecx /* Try to flip the AC bit introduced on the 486 */
13 movl $386, %eax /* 386 if it didn't react to "flipping" */
15 movl $0x00200000, %ecx /* Try to flip the ID bit introduced on the 586 */
17 movl $486, %eax /* 486 if it didn't react */
20 pusha /* Save the world */
22 .byte 0x0F, 0xA2 /* CPUID instruction tells the processor type */
23 andb $0x0F, %ah /* Extract the family (5, 6, ...) */
25 cmpl $15, %eax /* 15: extended family */
27 movl $6, %eax /* Make it 686 */
29 imull $100, %eax /* 500, 600, ... */
30 addl $86, %eax /* 586, 686, ... */
31 movl %eax, 7*4(%esp) /* Pass eax through */
39 pushf /* Push eflags */
40 pop %eax /* eax = eflags */
41 movl %eax, %edx /* Save original eflags */
42 xorl %ecx, %eax /* Flip the bit to test */
43 push %eax /* Push modified eflags value */
44 popf /* Load modified eflags register */
46 pop %eax /* Get it again */
48 popf /* Restore original eflags register */
49 xorl %edx, %eax /* See if the bit changed */