Getting my Bootloader to load a 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
theelitenoob
Posts: 16
Joined: Wed Aug 24, 2011 11:19 am

Getting my Bootloader to load a second stage bootloader?

Post by theelitenoob »

hi, so i just started work on my two stage boot loader in ASM.
and after a bit of testing, i got a basic hello world boot-loader working.
however in my first boot-loader i cannot seem to figure out how to
load and give control to the second stage boot-loader.

Would you try and do this using a include in the asm code, or is there a different way?
a simple sample or snippet would be really helpful. and thank you for reading.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Getting my Bootloader to load a second stage bootloader?

Post by Combuster »

How about reading the wiki? Did you try that?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
theelitenoob
Posts: 16
Joined: Wed Aug 24, 2011 11:19 am

Re: Getting my Bootloader to load a second stage bootloader?

Post by theelitenoob »

yes i did, but it doesn't seem to tell how i would load a secondary file.
i get that you need to transfer control, or jump to its location, but i can't figure out how.
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Re: Getting my Bootloader to load a second stage bootloader?

Post by mark3094 »

Assuming you have already loaded the second stage into memory, and are still in real mode, try something like this (shown in NASM):

Code: Select all

PUSH	WORD 0x0050
PUSH	WORD 0x0000
RETF
RETF will pop CS:IP from the stack (0050:0000 in this case)


Hope this helps
theelitenoob
Posts: 16
Joined: Wed Aug 24, 2011 11:19 am

Re: Getting my Bootloader to load a second stage bootloader?

Post by theelitenoob »

thanks that useful, but as a question, when you load the second stage,
does it have to be loaded into a special place, like a certain memory address,
for this code, or can it be anywhere?
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Re: Getting my Bootloader to load a second stage bootloader?

Post by mark3094 »

theelitenoob wrote: when you load the second stage,
does it have to be loaded into a special place, like a certain memory address,
for this code, or can it be anywhere?
In real mode, it has to be below the 1MB mark. Also, don't overwrite anything you have already loaded (ie, stage 1)
Also remember not to write to the memory mapped I/O region.

If you're not sure, just write to 0050:0000 as I have done. I guarantee it works :)
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Re: Getting my Bootloader to load a second stage bootloader?

Post by mark3094 »

To expand on my previous comment, apart from the restrictions listed, no, you don't have to load it to a specific area of memory.

Just make sure that where you pass control to is the same location in memory that you loaded to.
theelitenoob
Posts: 16
Joined: Wed Aug 24, 2011 11:19 am

Re: Getting my Bootloader to load a second stage bootloader?

Post by theelitenoob »

ok, thanks for the input i'll test it out now.
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: Getting my Bootloader to load a second stage bootloader?

Post by Bietje »

http://www.google.nl/search?client=oper ... el=suggest

That is all the information you need to load your second stage.
theelitenoob
Posts: 16
Joined: Wed Aug 24, 2011 11:19 am

Re: Getting my Bootloader to load a second stage bootloader?

Post by theelitenoob »

Bietje wrote:http://www.google.nl/search?client=opera&rls=en&q=bios+int+0x13&sourceid=opera&ie=utf-8&oe=utf-8&channel=suggest

That is all the information you need to load your second stage.
thanks, this is perfect!
torshie
Member
Member
Posts: 89
Joined: Sun Jan 11, 2009 7:41 pm

Re: Getting my Bootloader to load a second stage bootloader?

Post by torshie »

My suggestion is, try multiboot unless you have a real good reason to craft your own boot loader. If you want a 64-bit kernel, write a loader on top of multiboot. It's much easier.
theelitenoob
Posts: 16
Joined: Wed Aug 24, 2011 11:19 am

Re: Getting my Bootloader to load a second stage bootloader?

Post by theelitenoob »

my main reason is i want to try it myself, as well as it seems fun.
Post Reply