Page 1 of 1

Second Stage Bootloader

Posted: Sat Jan 11, 2014 7:00 pm
by Bob201400
Hi there, I am completely new to assembly and OS dev.

As a project I am trying to learn OS dev and this is not possible without knowing assembly.

To date I have a very simple but working bootloader which I want to extend. I want it to load the 2nd stage of loading. How do I do this in assembly. Thanks.

Re: Second Stage Bootloader

Posted: Sat Jan 11, 2014 8:19 pm
by Octocontrabass
What part of it are you having trouble with?

Re: Second Stage Bootloader

Posted: Sat Jan 11, 2014 11:05 pm
by brunexgeek
You must load the second bootloader binary from some disk and "jump" to it entry point.

A simple search on the web can provide some tutorials
http://www.brokenthorn.com/Resources/OSDev6.html

Re: Second Stage Bootloader

Posted: Sun Jan 12, 2014 2:27 am
by nerdguy
Hi there, I am completely new to assembly and OS dev
First off don't OSDev if you don't know assembly, try to learn it, shouldn't take more than
a month to understand simple instructions.
As for the question, here's an outline :
The First Stage loader, is a boot sector (usually), 512 bytes in size loaded at 0x0000:0x7C00,
(I am talking about BIOS Systems and booting from HD/FD, can't assume that the OP is interested in UEFI)
Note : You only have 510 bytes of space for code the last 2 being 0x55AA (BIOS boot signature)
You need a file system, something like FATXX, EXT4, or whatever you prefer, FAT is easier and simple but
has limitations. More information can be found if you care to research. (Hint: INT 0x13)
Once the second stage loader is loaded, you either do one of these 5 things :
1. Switch directly to PM/LM and use your own drivers and load the kernel. (Not recommended for newbies)
2. Stay in RM, load the kernel using int 13h, use a rep movsd (or similar) and copy it to the 1MB mark or whatever. (Highly limiting but easy kernel can't be more than 64KB + BIOS Drivers are crap)
3. Stay in RM, use segmentation techniques to load the kernel, (ridiculous, segment registers are probably the one of the worst, or maybe the worst thing that has ever existed)
4. Use hacks, switch to FRM, or unreal mode and then load the kernel.
5. Make the second stage loader as your kernel 8) (the simplest method)
After loading the kernel you would switch to your preferred CPU Mode, (if you haven't)
How do I do this in assembly. Thanks
Well, in really simple words, research.
This page may help : http://wiki.osdev.org/Rolling_Your_Own_Bootloader

Re: Second Stage Bootloader

Posted: Sun Jan 12, 2014 6:23 am
by Antti
My recommendations for assembly programming:

1. Understand the FLAGS register.

2. Understand the stack.

3. Understand segmentation.

If you understand these things, then you avoid a lot of problems.