Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Sep 1999 16:18:02 -0400 (EDT)
From:      John Baldwin <jobaldwi@vt.edu>
To:        "Ronald G. Minnich" <rminnich@lanl.gov>
Cc:        hackers@freebsd.org
Subject:   RE: return to real mode
Message-ID:  <199909292018.QAA79832@server.baldwin.cx>
In-Reply-To: <Pine.SGI.4.10.9909291116550.218081-100000@acl.lanl.gov>

next in thread | previous in thread | raw e-mail | index | archive | help

On 29-Sep-99 Ronald G. Minnich wrote:
> anybody got some reliable, tested, known-good code for getting back
> to
> real mode? I'm to the point where I have a working GDT, and paging is
> turned off, but the last step -- turning off protection enable -- is
> not
> working for me. 

Well, initialize all of your selectors to descriptors that have 64k
limits (0xffff).  Jump into a 16bit code segment with a 64k limit on
the CS selector, turn off bit 0 in cr0 to actually enter real mode,
then jump to the next instruction so that the cache is flushed.  I
believe it needs to be a far jmp, and then you should be fine.  For
example:  (this is TASM, so it's Intel syntax and not AT&T)

GROUP     CodeGroup _TEXT32, _TEXT16

ASSUME    CS:CodeGroup, DS:_PMDATA

....

SEGMENT   _TEXT32 Byte  Public Use32 'CODE'

....

          db      0EAh
          dd      OFFSET ExitPM
          dw      Sel_CS16

ENDP

ENDS

SEGMENT   _TEXT16 Word  Public Use16 'CODE'

ExitPM:   mov     ax,Sel_ESeg
          mov     es,ax
          mov     fs,ax
          mov     gs,ax
;         mov     ss,ax
          mov     eax,cr0
          xor     eax,eax               ;clear bit 0, (i.e. leave PM)
          mov     cr0,eax               ;leave protected mode
;         jmp     FAR CleanUp
          db      0EAh                  ;jmp     far CleanUp
          dw      OFFSET CleanUp
          dw      CodeGroup

.....

CleanUp:  mov     ax,_PMDATA
          mov     ds,ax                 ;restore DS
          lss     sp,[DWORD PTR OFFSET SaveSP] ;restore SS:SP

.....   Now you are in Real Mode


> This is on a PII.

This code has been tested (and works) on 386, 386, and Pentium. 
Presumably it should work on later chips as well.

> Thanks
> 
> ron

---

John Baldwin <jobaldwi@vt.edu> -- http://www.cslab.vt.edu/~jobaldwi/
PGP Key: http://www.cslab.vt.edu/~jobaldwi/pgpkey.asc
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199909292018.QAA79832>