From owner-freebsd-hackers Wed Sep 29 13:18:10 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from server.baldwin.cx (jobaldwi.campus.vt.edu [198.82.67.146]) by hub.freebsd.org (Postfix) with ESMTP id 0295014A31 for ; Wed, 29 Sep 1999 13:17:51 -0700 (PDT) (envelope-from jobaldwi@vt.edu) Received: from john.baldwin.cx (john [10.0.0.2]) by server.baldwin.cx (8.9.3/8.9.3) with ESMTP id QAA79832; Wed, 29 Sep 1999 16:18:04 -0400 (EDT) (envelope-from jobaldwi@vt.edu) Message-Id: <199909292018.QAA79832@server.baldwin.cx> X-Mailer: XFMail 1.3.1 [p0] on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: Date: Wed, 29 Sep 1999 16:18:02 -0400 (EDT) From: John Baldwin To: "Ronald G. Minnich" Subject: RE: return to real mode Cc: hackers@freebsd.org Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 -- 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