32bit registers in 16bit real mode.

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.
Post Reply
User avatar
jinksys
Posts: 20
Joined: Tue May 20, 2008 4:52 pm
Location: St Louis, Missouri, USA

32bit registers in 16bit real mode.

Post by jinksys »

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:

http://www.brokenthorn.com/Resources/OSDev4.html

When describing real mode the author writes...
# Is limited to 16 bit registers only.
Please tell me he's dead wrong.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

He's dead wrong.

[edit]I've just e-mailed the author to let him correct it.[/edit]

Cheers,
Adam
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Officially you shouldn't use 32-bit code unless you know you have a 386+

But who cares? :D
"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 ]
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

Its been corrected--Sorry about that :)
Osbios
Member
Member
Posts: 116
Joined: Fri Jun 10, 2005 11:00 pm

Post by Osbios »

I used 16bit only in the boot loader. Then I test for 386+ and stop and complain about the system if the CPU is too old.

Some detection for 386+

Code: Select all

 ;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
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

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)

here is mine, from my bootloader:

Code: Select all

386detect:
	PUSHF
	MOV AX, 0xF000
	PUSH AX
	POPF
	PUSHF
	POP AX
					; REMOVED POPF
	AND AH, 0xF0
	JNG ErrorCrash:				; unrecoverable ERROR (#1 == no386)(z=0,s=0)
Post Reply