How to switch from unreal mode to real mode?
- alethiophile
- Member
- Posts: 90
- Joined: Sat May 30, 2009 10:28 am
How to switch from unreal mode to real mode?
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.
If I had an OS, there would be a link here.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: How to switch from unreal mode to real mode?
If you bothered to read the wiki...
- alethiophile
- Member
- Posts: 90
- Joined: Sat May 30, 2009 10:28 am
Re: How to switch from unreal mode to real mode?
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.
If I had an OS, there would be a link here.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: How to switch from unreal mode to real mode?
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?
You could also just load a minimal kernel and let that do the rest of the loading?
Modular Interface Kernel With a lot of bugs
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: How to switch from unreal mode to real mode?
Read harder.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.
"Unreal Mode is a 'mode' where the processor runs in real mode (...)"
- alethiophile
- Member
- Posts: 90
- Joined: Sat May 30, 2009 10:28 am
Re: How to switch from unreal mode to real mode?
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?
If I had an OS, there would be a link here.
Re: How to switch from unreal mode to real mode?
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.
- Masterkiller
- Member
- Posts: 153
- Joined: Sat May 05, 2007 6:20 pm
Re: How to switch from unreal mode to real mode?
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.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.
ALCA OS: Project temporarity suspended!
Current state: real-mode kernel-FS reader...
Current state: real-mode kernel-FS reader...
Re: How to switch from unreal mode to real mode?
Why don't you switch from real mode to protected mode, directly?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: How to switch from unreal mode to real mode?
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?
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?
Probably, masterkiller does not mean the selector value, but the value of the segment register, which is a slight difference. Should ICombuster wrote:masterkiller (selector value is not added) are wrong - which is the main reason that wiki page even exists.
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?
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!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?
JAL
Re: How to switch from unreal mode to real 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.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.
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