How to switch from unreal mode to real mode?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
alethiophile
Member
Member
Posts: 90
Joined: Sat May 30, 2009 10:28 am

How to switch from unreal mode to real mode?

Post 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.
If I had an OS, there would be a link here.
User avatar
Combuster
Member
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?

Post by Combuster »

If you bothered to read the wiki...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
alethiophile
Member
Member
Posts: 90
Joined: Sat May 30, 2009 10:28 am

Re: How to switch from unreal mode to real mode?

Post 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.
If I had an OS, there would be a link here.
User avatar
Troy Martin
Member
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?

Post 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...
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
Ferrarius
Member
Member
Posts: 69
Joined: Sun Oct 28, 2007 4:10 pm

Re: How to switch from unreal mode to real mode?

Post by Ferrarius »

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 ;)
User avatar
Combuster
Member
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?

Post 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 (...)"
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
alethiophile
Member
Member
Posts: 90
Joined: Sat May 30, 2009 10:28 am

Re: How to switch from unreal mode to real mode?

Post 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?
If I had an OS, there would be a link here.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: How to switch from unreal mode to real mode?

Post 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.
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Re: How to switch from unreal mode to real mode?

Post 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.
ALCA OS: Project temporarity suspended!
Current state: real-mode kernel-FS reader...
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: How to switch from unreal mode to real mode?

Post by kop99 »

Why don't you switch from real mode to protected mode, directly?
User avatar
Combuster
Member
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?

Post 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... :roll:

This place's really going downhill :cry:

-------------

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?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
hailstorm
Member
Member
Posts: 110
Joined: Wed Nov 02, 2005 12:00 am
Location: The Netherlands

Re: How to switch from unreal mode to real mode?

Post 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...
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: How to switch from unreal mode to real mode?

Post 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
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: How to switch from unreal mode to real mode?

Post 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
Post Reply