Page 1 of 1
How to switch from unreal mode to real mode?
Posted: Tue Jun 02, 2009 3:05 pm
by alethiophile
I am currently writing a bootloader, and I don't want to make the assumption that my kernel will fit in the space available in real mode. Hence, I need to use unreal mode to load the kernel. How do you switch from unreal mode back to real mode? I don't know how well it will work to try to enable protected mode while in unreal mode.
Re: How to switch from unreal mode to real mode?
Posted: Tue Jun 02, 2009 3:51 pm
by Combuster
If you bothered to read the
wiki...
Re: How to switch from unreal mode to real mode?
Posted: Tue Jun 02, 2009 4:47 pm
by alethiophile
The linked page is not very helpful. I'm looking for actual instructions as to what I do to go back to real mode. Descriptor caches are helpful theory, but I don't know how to use it.
Re: How to switch from unreal mode to real mode?
Posted: Tue Jun 02, 2009 4:52 pm
by Troy Martin
I don't see why you can't just load a real mode segment into DS and ES and use those, or flush the GDT and then do that or something...
Re: How to switch from unreal mode to real mode?
Posted: Tue Jun 02, 2009 4:54 pm
by Ferrarius
You could also just load a minimal kernel and let that do the rest of the loading?
Re: How to switch from unreal mode to real mode?
Posted: Tue Jun 02, 2009 5:02 pm
by Combuster
alethiophile wrote:The linked page is not very helpful. I'm looking for actual instructions as to what I do to go back to real mode. Descriptor caches are helpful theory, but I don't know how to use it.
Read harder.
"Unreal Mode is a 'mode' where the processor runs in real mode (...)"
Re: How to switch from unreal mode to real mode?
Posted: Tue Jun 02, 2009 9:01 pm
by alethiophile
I am aware that unreal mode is really just real mode with some descriptor caches tweaked. My question is, how do I un-tweak the descriptor caches? Is it as simple as overwriting the gdt? I'm sorry if this is a stupid question, but I'm not getting how from the wiki. Alternatively, can I switch directly from unreal mode to protected mode?
Re: How to switch from unreal mode to real mode?
Posted: Tue Jun 02, 2009 10:25 pm
by bewing
All you have to do is load a value into each segment register. Staying in unreal mode is accomplished by not touching the segment registers.
Re: How to switch from unreal mode to real mode?
Posted: Tue Jun 02, 2009 10:51 pm
by Masterkiller
bewing wrote:All you have to do is load a value into each segment register. Staying in unreal mode is accomplished by not touching the segment registers.
Actually the practise shows that descriptor caches are reloaded only when the PE is set. If you change the segment registers while PE cleared, the CPU computes the 32-bit addresses in very interesting mixed manner (Base of the descriptor cache + Selector << 4 + offset). So you may need to go to protected mode for a while, to change the descriptor cache. You may also look at Intel manuals, they shows the values of all registers on restart (which includes the hidden part of the segment) and create GDT base on that.
Re: How to switch from unreal mode to real mode?
Posted: Wed Jun 03, 2009 1:13 am
by kop99
Why don't you switch from real mode to protected mode, directly?
Re: How to switch from unreal mode to real mode?
Posted: Wed Jun 03, 2009 2:26 am
by Combuster
Both bewing (limit is preserved) and masterkiller (selector value is not added) are wrong - which is the main reason that wiki page even exists.
As for kop99's remark...
This place's really going downhill
-------------
I can't stop you from appearing stupid, but everything you need to know is on that page. Being unable to apply theory will not get you anywhere with OS development.
If you know how to get a piano into a building, how would you get a similar piano into that house a few yards down the road?
Re: How to switch from unreal mode to real mode?
Posted: Wed Jun 03, 2009 7:41 am
by hailstorm
Combuster wrote:masterkiller (selector value is not added) are wrong - which is the main reason that wiki page even exists.
Probably, masterkiller does not mean the selector value, but the value of the segment register, which is a slight difference. Should I
be wrong on this, than the wiki is seriously lacking information about this part of the subject...
Re: How to switch from unreal mode to real mode?
Posted: Wed Jun 03, 2009 9:07 am
by jal
Combuster wrote:If you know how to get a piano into a building, how would you get a similar piano into that house a few yards down the road?
It's more like: if you know how to "open a door, go inside, switch on the light, go outside", how do you switch off the light again? Oh no! I don't know! That description is too vague! Please, detailed instructions!
JAL
Re: How to switch from unreal mode to real mode?
Posted: Wed Jun 03, 2009 9:10 am
by jal
alethiophile wrote:Hence, I need to use unreal mode to load the kernel. How do you switch from unreal mode back to real mode? I don't know how well it will work to try to enable protected mode while in unreal mode.
Regardless of you looking rather stupid for not understanding the basic workings of real mode, protected mode and unreal mode, appearently, the main question is: why would you want to switch off unreal mode? Unreal mode works exactly as real mode, so all legacy software written for real mode (e.g. BIOS) works fine in unreal mode. The only programs that do not work will be those that use a 32 bit offset and expect a wrap-around.
Since I assume you are loading the kernel, then jumping to the kernel and enter protected mode, switching off unreal mode is of no use whatsoever.
JAL