Page 4 of 4

Re:can't re-enter realmode

Posted: Tue Apr 13, 2004 4:12 am
by tom1000000
Candy wrote: you don't need a new GDT entry

Actually Candy if you read the Intel manual it says that you must reload CS with a segment that has a limit of 64K before returning to Real Mode.

So you do have to create a new entry in your GDT (if you want to follow Intel's instructions). Admittedly it doesn't have to be 16 bit, and could be a 32 bit code segment with a limit of 64K, so I was wrong there. But u may as well go to 16 bit mode as well.

Also its a lot easier to do this in raw assembly rather than trying to write inline asm. I still haven't managed to understand inline ASM.

Re:can't re-enter realmode

Posted: Tue Apr 13, 2004 4:33 am
by ich_will
@candy: i've, simply type shutdown [RETURN] in my console to call the shutdown fucntion

Re:can't re-enter realmode

Posted: Tue Apr 13, 2004 5:07 am
by Candy
tom1000000 wrote: Actually Candy if you read the Intel manual it says that you must reload CS with a segment that has a limit of 64K before returning to Real Mode.

So you do have to create a new entry in your GDT (if you want to follow Intel's instructions). Admittedly it doesn't have to be 16 bit, and could be a 32 bit code segment with a limit of 64K, so I was wrong there. But u may as well go to 16 bit mode as well.
*goes back under his rock and fires up his bochs debugger to help ich_will* - will do so tomorrow 6pm when I'm home again...

Re:can't re-enter realmode

Posted: Fri Apr 16, 2004 4:03 am
by ich_will
had someone of you found out something about my problem? Candy?

Re:can't re-enter realmode

Posted: Sun Apr 18, 2004 8:38 am
by ich_will
Now the first things work:
cs is reloaded correctly and the other registers, too! ;D

the code posted by Pype.Clicker doesn't work. Now I only have a [ORG 0x500] statement in my shutdown.asm, move it there jump there and voil? it works.

Thanks alot for the help.

;D :D ;) 8)

Re:can't re-enter realmode

Posted: Sun Apr 18, 2004 8:56 am
by ich_will
do you have to reload the idt with real-mode base and limt if you want to use int instructions f.e.:

...
int 0x15

if you what are the real-mode values for the descriptor

Re:can't re-enter realmode

Posted: Sun Apr 18, 2004 9:00 am
by DennisCGc
ich_will wrote: do you have to reload the idt with real-mode base and limt if you want to use int instructions f.e.:

...
int 0x15

if you how can i load it to this.
Yes, you have to.
Because since the i386 was "born" the processor made the lidt command also available for the real mode.
And because of this, it's neccesary to reload the (original ?) IDT.
For more documentation, read the intel manual.

Re:can't re-enter realmode

Posted: Sun Apr 18, 2004 12:10 pm
by beyondsociety
Actually, in real-mode you have access to all the interrupts through the IVT (interrupt vector table). Once you enter into protected mode, you dont have access to those interrupts anymore.

So in order to use interrupts you must re-map the PIC (programmable interrupt controller) or the interrupts will be the same number as in real-mode, setup an idt with the base and limit just like you did with the GDT upon entering pmode and with entries for exceptions/interrupts, initalize it, enable interrupts.

I suggest either taking a look at osdever.net for tutorials on this, or look through the intel manuals. Also check the quicklinks for this forum for info and possibly http://my.execpc.com/~geezer/os/ for help.

EDIT: I just realized this thread is about going back to real-mode. In this case, the lidt does need to be re-initialized with real-mode values. Other wise, you probably wont have ints.

Re:can't re-enter realmode

Posted: Mon Apr 19, 2004 2:52 am
by Pype.Clicker
and, as a final stuff, if you ever want your RealMode code to play with FPU after your Pmode code made some task switch, remember to CLearTaskSwitch in your "back to real mode" procedure.

This is certainly useless for just shutting down the system, but you'll need it for instance if you want to recover to some DOS session and run heavy programs like a borland IDE, a DOS game, etc.

Just for the sake of Completeness :)