Moving on to PMode
- Firestryke31
- Member
- Posts: 550
- Joined: Sat Nov 29, 2008 1:07 pm
- Location: Throw a dart at central Texas
- Contact:
Moving on to PMode
Hello all! I've decided to move Socks on from Real Mode. I was just wondering what would be a good idea to do before making the switch to PMode in the loader. I know that A20 is practically a must, switching the video mode is a good idea, and getting the memory map stored somewhere is pretty nice too, but beyond that I haven't really had much inspiration. So I was wondering, what do you do in your bootloader before the switch? I already know how to make the switch itself (CR0, GDT and whatnot) and just want to know the setup stuff.
This could also be a nice, central place for ideas regarding the topic. Keeping info in a central place is always good.
Edit: I've already looked in the wiki, and couldn't really find anything regarding setup. Just the actual switch and what to do once there.
This could also be a nice, central place for ideas regarding the topic. Keeping info in a central place is always good.
Edit: I've already looked in the wiki, and couldn't really find anything regarding setup. Just the actual switch and what to do once there.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
Re: Moving on to PMode
Hi,
Although it's not a "must", my boot loader sets up paging too, meaning that the kernel can be located anywhere without the need for the GDT trick.
I also set up a kernel stack and push any arguments I want passed to the kernel in a traditional 'argc, argv' way. This means that my kernel launches directly in to the main routine with no asm stub. It also means that both my 32 and 64 bit kernel launch directly in to the architecture-independent portion and it allows me to get some nice C++ runtime stuff up fairly soon in to the kernel launch process. My loader currently even provides the page frame allocation structure for the kernel.
There are several reasons why you wouldn't want to do the above, but I like doing it that way
Cheers,
Adam
Although it's not a "must", my boot loader sets up paging too, meaning that the kernel can be located anywhere without the need for the GDT trick.
I also set up a kernel stack and push any arguments I want passed to the kernel in a traditional 'argc, argv' way. This means that my kernel launches directly in to the main routine with no asm stub. It also means that both my 32 and 64 bit kernel launch directly in to the architecture-independent portion and it allows me to get some nice C++ runtime stuff up fairly soon in to the kernel launch process. My loader currently even provides the page frame allocation structure for the kernel.
There are several reasons why you wouldn't want to do the above, but I like doing it that way
Cheers,
Adam
Re: Moving on to PMode
Disable interrupts?So I was wondering, what do you do in your bootloader before the switch?
In my system, the very first thing in its startup program is to switch to protected mode and enable A20. Everything else is done through a real mode<>pmode interface so that I can call the bios through the interface running in protected mode. Because of this, there is nothing that I need to do before the switch as I can just do it from pmode without any problems.
A little slow this way, but works great
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: Moving on to PMode
I do the same thing, but with one small difference; I even able A20 after switching to protected mode. I find this way allows me to accomplish anything I want rather easily since my C is a lot better than my ASM. Even video mode switching is easy as pie.neon wrote:Disable interrupts?So I was wondering, what do you do in your bootloader before the switch?
In my system, the very first thing in its startup program is to switch to protected mode and enable A20. Everything else is done through a real mode<>pmode interface so that I can call the bios through the interface running in protected mode. Because of this, there is nothing that I need to do before the switch as I can just do it from pmode without any problems.
A little slow this way, but works great
- Firestryke31
- Member
- Posts: 550
- Joined: Sat Nov 29, 2008 1:07 pm
- Location: Throw a dart at central Texas
- Contact:
Re: Moving on to PMode
If you set up the ISRs and the IDT, do you even need to disable interrupts? Or am I missing something stupidly obvious (I get the feeling I am)?
Edit: and should I change the title to the slightly more descriptive "What to do before leaving Real Mode" for future searchers?
Edit: and should I change the title to the slightly more descriptive "What to do before leaving Real Mode" for future searchers?
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
Re: Moving on to PMode
The thing is, you do not need to enable interrupts: there's absolutely no use for them at this stage, so setting up an IDT is useless. One of the first things your OS (any OS, for that matter) is going to do is set up one itself.Firestryke31 wrote:If you set up the ISRs and the IDT, do you even need to disable interrupts?
JAL
Re: Moving on to PMode
In my case, I hit protected mode as soon as I can, and switch back and forth between real mode and protected mode to use any BIOS functions I may need. I do that by calling interrupts, so I DO need an IDT. There's other ways I could have done this, but I found this one to be pretty easy.jal wrote:The thing is, you do not need to enable interrupts: there's absolutely no use for them at this stage, so setting up an IDT is useless. One of the first things your OS (any OS, for that matter) is going to do is set up one itself.Firestryke31 wrote:If you set up the ISRs and the IDT, do you even need to disable interrupts?
JAL
For the little bit that my bootloader runs in real mode, I load the BIOS IVT and enable interrupts there so BIOS can handle anything that occurs. Before the switch back to protected mode, I disable interrupts and after the pmode switch I reload my pmode IDT. I tried running with interrupts disabled all the time (and never bothered to make sure interrupts were still disabled after using the BIOS) only to find that some BIOS functions do enable interrupts and leave them that way.
So, you may need an IDT depending on how you handle any protected mode to real mode switching. As jal said, there's really no need to enable interrupts. Just make sure that interrupts are still disabled after using the BIOS and you should be okay.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Moving on to PMode
My 32-bit bootloader loads only, no switch. The switch and A20 and GDT and IDT and all things that go bump in the night are handled in the 16-bit header of the kernel.
Re: Moving on to PMode
Looks like your system and mine is a little different My interface is a single routine that provides input/output services. It follows the format of the old dos.h int86 routine and works the same way. ie, a call such as io_services (0x10, &in, &out); in turn calls bios int 0x10 in real mode.quok wrote:In my case, I hit protected mode as soon as I can, and switch back and forth between real mode and protected mode to use any BIOS functions I may need. I do that by calling interrupts, so I DO need an IDT. There's other ways I could have done this, but I found this one to be pretty easy.
(Although it does still set up an IDT, but its only for exception trapping.)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
- Firestryke31
- Member
- Posts: 550
- Joined: Sat Nov 29, 2008 1:07 pm
- Location: Throw a dart at central Texas
- Contact:
Re: Moving on to PMode
Okay, so I have getting the memory map and setting the video mode, and am going to get paging set up, but I had one (or three) more question(s):
How do you organize data before going to Pmode? Do you have a real-mode memory manager, or do you just dump the data at a few specific points and go? If the latter, where do you typically put what data?
How do you organize data before going to Pmode? Do you have a real-mode memory manager, or do you just dump the data at a few specific points and go? If the latter, where do you typically put what data?
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?