386+ CPU detection routine
Posted: Thu Oct 18, 2001 9:24 am
First of all, I would like to say "Hello" to all of you, since I am new to this board and this is my first post .
Now, on to the reason of my post: detecting at the boot time if we run on a machine with an intel 386 (or compatible) CPU or higher.
I found the following code in Till Gerken's Protected Mode Tutorial V0.02 (is there any newer out there? , which he uses for this purpose:
Now, studying the above code and overlooking one of the intel manuals I came up with the following code:
It's shorter and should be aquivalent to Till's code.
It is to be placed in the boot sector on a diskette (or MBR if booting from a hard drive). Now, my problem is: is this code correct? It seems logical to me that it is correct, the problem is that all computers I can test this code on have at least a 386 CPU or higher, so no warranty that one would not get unexpected results on older CPUs...
Is there anybody who can confirm the correctness of my code, or is there something I am missing and why my code should not work properly? Thanks in advance.
Now, on to the reason of my post: detecting at the boot time if we run on a machine with an intel 386 (or compatible) CPU or higher.
I found the following code in Till Gerken's Protected Mode Tutorial V0.02 (is there any newer out there? , which he uses for this purpose:
Code: Select all
<--- cut --->
proc check_processor
pushf ; save flags
xor ah,ah ; clear high byte
push ax ; push AX onto the stack
popf ; pop this value into the flag register
pushf ; push flags onto the stack
pop ax ; ...and get flags into AX
and ah,0f0h ; try to set the high nibble
cmp ah,0f0h ; the high nibble is never 0f0h on a
je no386 ; 80386!
mov ah,70h ; now try to set NT and IOPL
push ax
popf
pushf
pop ax
and ah,70h ; if they couldn't be modified, there
jz no386 ; is no 80386 installed
popf ; restore the flags
ret ; ...and return
no386: ; if there isn't a 80386, put a msg
mov dx,offset no386e ; and exit
jmp err16exit
endp check_processor
<--- cut --->
Code: Select all
pushf
mov ah, 0f0h
push ax
popf
pushf
pop ax
popf
cmp ah, 070h
jz .386detected
; we land here if we do not detect a 386
.386detected:
; we land here if we detect a 386
It is to be placed in the boot sector on a diskette (or MBR if booting from a hard drive). Now, my problem is: is this code correct? It seems logical to me that it is correct, the problem is that all computers I can test this code on have at least a 386 CPU or higher, so no warranty that one would not get unexpected results on older CPUs...
Is there anybody who can confirm the correctness of my code, or is there something I am missing and why my code should not work properly? Thanks in advance.