Second Stage Bootloader

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Bob201400
Posts: 1
Joined: Sat Jan 11, 2014 6:21 pm

Second Stage Bootloader

Post 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.
Octocontrabass
Member
Member
Posts: 5604
Joined: Mon Mar 25, 2013 7:01 pm

Re: Second Stage Bootloader

Post by Octocontrabass »

What part of it are you having trouble with?
brunexgeek
Member
Member
Posts: 45
Joined: Wed Dec 25, 2013 11:51 am

Re: Second Stage Bootloader

Post 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
User avatar
nerdguy
Member
Member
Posts: 70
Joined: Wed Oct 30, 2013 8:11 am

Re: Second Stage Bootloader

Post 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
When you say, "I wrote a program that crashed Windows," people just stare at you blankly and say, "Hey, I got those with the system, for free." - Linus Torvalds
64 bit Kernel in early development
http://github.com/nerdguy12/core64
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Second Stage Bootloader

Post 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.
Post Reply