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.
According to GRUB's documentation, and my knowledge of GRUB, stage 2 is put in the file system of a disk as a normal file.
We embed Stage 1 in a MBR or in the boot sector of a partition, and place Stage 2 in a filesystem.
Now, if stage 1 is loaded onto the MBR of the disk, which then loads the first sector of stage 2, and stage 2 is a normal file in the file system, how does stage 1 find stage 2?
In stage1.S, stage1 uses int 13h to load logical sector 1.
It may also be "stage 1.5", which holds the filesystem-dependent code and acts as an intermediate step between stage 1 and stage 2
"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 ]
The only moment you'd not be using it is on a non-formatted media (floppy with grub alone)
"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 ]
So, on, say, a hard disk, GRUB would write stage1.5 on the sectors following the MBR, and then that would load stage 2 following its own load on stage 1? Thus, stage1.5 has all of the drivers and FS stuff in it?
Isn't it rather ugly for both stage1.5 and stage2 to contain the same FS and driver code duplicated?
Alboin wrote:Isn't it rather ugly for both stage1.5 and stage2 to contain the same FS and driver code duplicated?
Some of GRUB's stages might use a list of sectors. For example, when the boot loader is installed you find out which sectors are being used for the next stage and record them somewhere, so that the previous stage only needs to load the sectors in the list and doesn't need to contain any file system code.
Also, there's no reason why the next stage can't call functions, etc in the previous stage...
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.