Page 1 of 1
Getting my Bootloader to load a second stage bootloader?
Posted: Wed Aug 24, 2011 12:05 pm
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.
Re: Getting my Bootloader to load a second stage bootloader?
Posted: Wed Aug 24, 2011 1:30 pm
by Combuster
How about reading the wiki? Did you try that?
Re: Getting my Bootloader to load a second stage bootloader?
Posted: Wed Aug 24, 2011 2:06 pm
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.
Re: Getting my Bootloader to load a second stage bootloader?
Posted: Wed Aug 24, 2011 2:57 pm
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
Re: Getting my Bootloader to load a second stage bootloader?
Posted: Wed Aug 24, 2011 3:29 pm
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?
Re: Getting my Bootloader to load a second stage bootloader?
Posted: Wed Aug 24, 2011 4:19 pm
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
Re: Getting my Bootloader to load a second stage bootloader?
Posted: Wed Aug 24, 2011 4:21 pm
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.
Re: Getting my Bootloader to load a second stage bootloader?
Posted: Wed Aug 24, 2011 4:36 pm
by theelitenoob
ok, thanks for the input i'll test it out now.
Re: Getting my Bootloader to load a second stage bootloader?
Posted: Wed Aug 24, 2011 6:40 pm
by Bietje
http://www.google.nl/search?client=oper ... el=suggest
That is all the information you need to load your second stage.
Re: Getting my Bootloader to load a second stage bootloader?
Posted: Wed Aug 24, 2011 7:07 pm
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!
Re: Getting my Bootloader to load a second stage bootloader?
Posted: Wed Aug 24, 2011 8:22 pm
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.
Re: Getting my Bootloader to load a second stage bootloader?
Posted: Thu Aug 25, 2011 8:21 am
by theelitenoob
my main reason is i want to try it myself, as well as it seems fun.