Page 1 of 1

What is the best place to enter protected mode?

Posted: Sat Mar 29, 2014 4:27 am
by Roman
What is the best place to enter protected mode? (bootloader stage 1, stage 2 or kernel or something else?)

Re: What is the best place to enter protected mode?

Posted: Sat Mar 29, 2014 2:04 pm
by DavidCooper
Roman wrote:What is the best place to enter protected mode? (bootloader stage 1, stage 2 or kernel or something else?)
What is protected mode for? Do your loader stages need protection from apps? Do they need to access memory above the 1MB point? If not, stay in real mode while you're still working with the BIOS to load your code, to set up a better screen mode and to get a map of usable memory. If you need to load in lots of code above the 1MB point, write code to go in and out of protected mode so that you can use the BIOS to load it to a buffer in low memory and then switch in and out of protected mode to shift it up memory. Once you've finished using the BIOS you can stay in protected mode, though you will need to limit how far you change the set-up of the machine if you want to change back into real mode to use the BIOS again to save or load more data later on, because every time you switch to real mode you'll need to undo all those changes.

Whatever you do, don't return to your original plan of writing a real-mode OS: protected mode will enable you to access a linear frame buffer for high-resolution graphics modes and make your OS a lot more capable than a real-mode OS as a result, as well as giving you gigabytes of memory to play with.

Re: What is the best place to enter protected mode?

Posted: Wed Apr 02, 2014 2:13 am
by hometue
My view on this is you load protected mode once you are done with things you want to do in real mode (things that can only be done in real mode, if there is, or things you prefer done in real mode due to the BIOS functions available to you etc.) I don't suggest switching between Real mode and Protected mode unless there is a must.