I can return to real mode from 16bit protect-mode.
but when I try to return from 32bit protect-mode, it always restart. I think the key point is segment selector and JMP instruction.

here is my code

......
; enter 32bit PM
mov eax,cr0
or al,1
mov cr0,eax

;
DB 0eah
DW 0
DW 8
jmp $

real:
push ax
in al,92h
and al,11111101b
out 92h,al
pop ax

sti

mov ax,4c00h
int 21h

CSEG_REAL ENDS

CSEG_PM32 SEGMENT USE32
ASSUME CS:CSEG_PM32
PM32 PROC

mov ax,10h ; reset the segment reg
mov ds,ax
mov ss,ax
mov es,ax
mov fs,ax
mov gs,ax

mov eax,cr0
add al,11111110b
mov cr0,eax

jmp far ptr real ; return to real mode
......
Posted on 2003-07-08 22:06:08 by estar
well not that easy. do the following:
. when going to pm save cs, ds and ss in memory
. to return to realmode clear the pe-bit (and al,11111110b)
. jump far to the saved cs:ip. you'll have to use a far return:


push old_cs ;the saved cs
push ip ;the code to "jump" to
retf

i think you have already 16bits at this point.
. immediately set ds and ss with the old values.
Posted on 2003-07-09 13:59:25 by hartyl
You have to do it from a 16-bit segment. Otherwise you'll have 32-bit real mode, which is no good. :P

hartyl: Why can't you just use a far jump?
Posted on 2003-07-15 00:40:37 by Sephiroth3

hartyl: Why can't you just use a far jump?

um... good question. actually you can use it, i think. i've never returned from pmode - my computer has a reset-button :). i read this code out of a tutorial.
Posted on 2003-07-15 04:11:44 by hartyl
Originally posted by hartyl


push old_cs ;the saved cs
push ip ;the code to "jump" to
retf



It will push 32-bit each push function.
Posted on 2003-08-11 22:44:33 by realvampire
But I know that attempts from even Intel have been unreliable. So probably still what they do is reset the machine and the Bios looks in the RAM at I can't remember exactly the address but after reset there is no power down so the pointer is preserved. 63 comes to mind. Anyway the system says if there are parameters and not NULL then load SS:SP with the list of values pointed by this address. At that location is a total machine state that places you back to previous real mode.
Posted on 2003-12-31 23:42:29 by mrgone
*cough* Do you know how long this thread has been lying in the attic?
Posted on 2004-01-01 16:39:31 by Sephiroth3