Page 1 of 1

Need help getting past bootload.asm

Posted: Thu Aug 09, 2007 5:36 am
by ubergeek
Hi,
I've been able to create a bootloader using the "Hello World" bootloader tutorial on osdever.net, however, I can't figure out how to make the bootloader load the kernel. I want to write the kernel in C++, but obviously I can't assemble it all into the bootload.bin file that will go on the first 512 bytes of the floppy cause it won't all fit in 512 bytes :D. So my questions are:

1. How do I compile C++ code into .bin (or whatever I need)?
2. How do I put that on the floppy and start it from the bootloader?

Thanks.

Re: Need help getting past bootload.asm

Posted: Thu Aug 09, 2007 5:53 am
by AJ
ubergeek wrote: 1. How do I compile C++ code into .bin (or whatever I need)?
You will need to either compile your kernel in to flat binary format, or use something more structured like ELF. For the latter, your boot loader needs to know how to relocate executable files.

Using C++, compile all your objects as usual and then link with a linker script. A good example of this is shown at http://www.osdever.net/bkerndev/index.php (only thing you will find is that you need an .rodata section along with the data section). Although Bran's tutorial is C, I would recommend at least reading through all the sections before you attempt a C++ kernel.

Another thing you will eventually need is a section for *.ctors and *.dtors. When you write your C++ kernel, you will have to write run time support for global and static constructors and destructors, new and delete operators, rtti, exceptions etc... Once you have a good memory manager in your kernel, the constructors and destructors, new and delete are pretty easy to implement. Even using C++, you will probably find that your memory manager ends up being 'C-Style'.
2. How do I put that on the floppy and start it from the bootloader?
I would suggest using GRUB here (you will find heaps of information on this in the wiki, on osdever and around the web). This will switch to protected mode, read from the disk, relocate your kernel and load any modules you require.

If you want to roll your own boot loader, you will have to do all this yourself. For reading from a FAT12 floppy disk, I learned this from BOS, which has a very easy-to-understand boot loader.

The general idea with that is that your FAT12-reading code goes in the 512 byte boot sector. It loads a second-stage loader from the disk which can then be any size (up to the size of a real-mode segment). That then sets up the machine properly and loads your kernel.

HTH
Adam

Re: Need help getting past bootload.asm

Posted: Fri Aug 10, 2007 3:35 am
by xlq
AJ wrote:I would suggest using GRUB
I concur. A good bootloader is like a miniature operating system in itself. Start with GRUB, then make your own bootloader later if you really want.

Also GRUB is really easy to use.

But then that's me; I'm using tcc to do all my compiling and linking.

Re: Need help getting past bootload.asm

Posted: Fri Aug 10, 2007 8:08 am
by sancho1980
ubergeek wrote:1. How do I compile C++ code into .bin (or whatever I need)?
Read here:

http://www.google.es/url?sa=t&ct=res&cd ... QvQNdDpspg