source: trunk/minix/lib/i386/misc/getprocessor.s@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.3 KB
RevLine 
[9]1! getprocessor() - determine processor type Author: Kees J. Bot
2! 26 Jan 1994
3
4.sect .text; .sect .rom; .sect .data; .sect .bss
5.sect .text
6
7! int getprocessor(void);
8! Return 386, 486, 586, ...
9
10.define _getprocessor
11
12_getprocessor:
13 push ebp
14 mov ebp, esp
15 and esp, 0xFFFFFFFC ! Align stack to avoid AC fault
16 mov ecx, 0x00040000 ! Try to flip the AC bit introduced on the 486
17 call flip
18 mov eax, 386 ! 386 if it didn't react to "flipping"
19 jz gotprocessor
20 mov ecx, 0x00200000 ! Try to flip the ID bit introduced on the 586
21 call flip
22 mov eax, 486 ! 486 if it didn't react
23 jz gotprocessor
24 pushf
25 pusha ! Save the world
26 mov eax, 1
27 .data1 0x0F, 0xA2 ! CPUID instruction tells the processor type
28 andb ah, 0x0F ! Extract the family (5, 6, ...)
29 movzxb eax, ah
30 cmp eax, 15 ! 15: extended family
31 jne direct
32 mov eax, 6 ! Make it 686
33direct:
34 imul eax, 100 ! 500, 600, ...
35 add eax, 86 ! 586, 686, ...
36 mov 7*4(esp), eax ! Pass eax through
37 popa
38 popf
39gotprocessor:
40 leave
41 ret
42
43flip:
44 pushf ! Push eflags
45 pop eax ! eax = eflags
46 mov edx, eax ! Save original eflags
47 xor eax, ecx ! Flip the bit to test
48 push eax ! Push modified eflags value
49 popf ! Load modified eflags register
50 pushf
51 pop eax ! Get it again
52 push edx
53 popf ! Restore original eflags register
54 xor eax, edx ! See if the bit changed
55 test eax, ecx
56 ret
Note: See TracBrowser for help on using the repository browser.