Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I've been trying to get back into writing a kernel, so I've been reading everything I can get my hands on. I stumbled upon brokenthorn.com and was reading this tutorial:
Officially you shouldn't use 32-bit code unless you know you have a 386+
But who cares?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
;CPU detect <80286, 80286, 80386+
;OUT: ax = CPU type ;destroys all other registers! no register save!!!
;0 = older then 286 O.o
;1 = 286 -_-
;2 = 386 or better ^.^
init1.cpu.dedect:
;test 286
pushf
pop bx
and bx, 0x0FFF
push bx
popf
pushf
pop bx
and bx, 0x0F000
cmp bx, 0x0F000
jne .its286orbetter
xor ax, ax ;older then a 286
ret
.its286orbetter:
;test 386 (Set bit18, read bit18, result=0 then <386)
pushfd
pop eax
or eax, 0x40000 ;bit 18
push eax
popfd
pushfd
pop eax
and eax, 0x40000
cmp eax, 0x40000
je .its386orbetter
mov ax, 1
ret
.its386orbetter:
mov ax, 2
ret
that is (in my personal opinion) ugly and inefficient 386-detect code, as there is no reason to test 286 and 386 separately (this code was originally written on this forum 4+ years ago, to demonstrate the 386-detect algorithm, and surprised myself that it was actually correct, and with how well its written)