Loader Stages

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
whiteOS
Member
Member
Posts: 29
Joined: Mon Oct 06, 2008 12:38 am

Loader Stages

Post by whiteOS »

hi. i started work on my loader and I have now a second stage which halts in pmode i do purposely because i can not have my second stage read floppy disk. it does nothing, but that is not my question. my question is why do people load their stage 2 from disk rather than dd'ing both stage 1 and stage 2 to the front of disk right behind each other and then load the kernel from disk? what is the benefit of loading the stage 2 from disk too?
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

Re: Loader Stages

Post by kmtdk »

are you asking about; why dont we place a secoundstage bootloader after the bootloader ( sector 2 ,3 ... ) ?
or what do you mean ?

KMT DK
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
whiteOS
Member
Member
Posts: 29
Joined: Mon Oct 06, 2008 12:38 am

Re: Loader Stages

Post by whiteOS »

no, I understand that. what I mean is why read the stage 2 from disk rather than write it to the disk to begin with? what benefit is it to read it off disk using stage 1 v. just hopping to it because it already exists on disk behind stage 1? so i do:

dd if=stage1 of=/dev/fd0 bs=512 count=1
dd if=stage2 of=/dev/fd0 bs=512 seek=1

i don't have to read stage 2 from disk, i jmp to it.
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: Loader Stages

Post by Combuster »

The reason is to maintain the file system. Stage 2 is not required constant in size and if it grows it can start overwriting the FAT tables. It also makes life much easier with tools that do not allow you to set the number of reserved sectors. (and there are quite a few of those)

Having a file system allows you to tell the size of the second stage, and to be very dynamic about what programs/drivers you include. GRUB floppies are very handy because all you need to do is overwrite the kernel file instead of rewriting the whole disk.

In any case you *will* need to read stage 2 from disk and jump to it because the BIOS doesn't do that for you, independent of where you put it...
"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 ]
whiteOS
Member
Member
Posts: 29
Joined: Mon Oct 06, 2008 12:38 am

Re: Loader Stages

Post by whiteOS »

that makes a lot of sense. i thought that if i keep my stage2 the same it is ok to write it to disk behind stage 1 but i see why it is benefits me to do it the other way. thanks you
Post Reply