Page 1 of 1
[Solved]Switch From Protected Mode to Real Mode and reverse
Posted: Wed Jul 13, 2011 1:44 am
by melgmry0101b
Hi everyone,
I want to use BIOS interrupts in protected mode but setting up user mode, multitasking and vm86 for this purpose only is useless for my small OS.
So that i want to back to real mode and call the BIOS interrupt then back again to protected mode.
My question is : Can i do that ?
If yes: how can i do that ?
If no : why?
My OS is in C++ language and i am using MSVS 2005.
----------------------------------------------------
Thanks in advance
Re: Switch From Protected Mode to Real Mode and reverse
Posted: Wed Jul 13, 2011 2:33 am
by Chandra
You can do that though it is not always the clean way. And regarding your HOW question, there are plenty of posts on this subject lying here. I too, did post a fully working code somewhere over here, though I don't exactly remember the thread title. Search Task left as assignment.
Cheers#
Re: Switch From Protected Mode to Real Mode and reverse
Posted: Wed Jul 13, 2011 12:54 pm
by DavidCooper
Start off by writing code to take the processor into protected mode and back to real mode - if you've changed nothing else, the BIOS should function fine after this. Then add more changes, one at a time and see if you can undo them and get the BIOS to work again each time before you take things further. You can leave the A20 enabled, and you'll probably get away with not restoring any GDT that the BIOS might have set up for itself. If you change the pic masks, store the original ones so that you can restore them when returning to real mode - on real hardware I found things worked fine without restoring them, but Bochs didn't like that at all. I also leave the RTC clock and periodic interrupts active on return to real mode on the assumption that the BIOS won't be thrown by them if it hasn't masked them out - it hasn't caused any problem so far. At some point you might find something that you can't undo, but I'm not aware of anything of that kind - no one supplied any details of such a thing the last time I asked, so I'm guessing that everything can be restored.
You certainly won't want to use the BIOS to print to the screen or collect input from keyboard and mouse, but it isn't too damaging for a hobby OS to use it for loading and saving files or to change screen mode.
Re: Switch From Protected Mode to Real Mode and reverse
Posted: Wed Jul 13, 2011 1:03 pm
by melgmry0101b
Thank you DavidCooper.
Re: [Solved]Switch From Protected Mode to Real Mode and reve
Posted: Thu Jul 14, 2011 2:16 pm
by shedokan
Just remember that you have to keep the original IVT intact so that yo can use 16bit interrupts, and that paging won't work in real mode.