GRUB Stage2 Load Location
Posted: Sat Aug 13, 2011 11:53 pm
I've got a rather simple question today, simply where does stage1 loads stage2, or where does it expect to be loaded, and also, does it require PM before it is being called.
The Place to Start for Operating System Developers
http://f.osdev.org/
Code: Select all
struc kernelstart
{
.boot_version db MAJOR_VERSION,MINOR_VERSION
.boot_drive db 0xFF
.force_lba db 0
.kernel_address dw KERNEL_ADDR
.kernel_sector dd KERNEL_SECT
.kernel_segment dw KERNEL_SEG
}
Code: Select all
if STAGE1_5
kernel_address=2000h
kernel_sector=fatstage_base/512
kernel_segment=200h
else
kernel_address=8000h
kernel_sector=stage2_base/512
kernel_segment=800h
end if
No....does it require PM before it is being called.
No. You should jump to 0:0x2000. Why do you not use GRUB stage1? Anyway you should know that GRUB requires additional configuring after/before it was placed on the disk. Default value of field kernel_sector for stage1_5 is 1. It is mean that stage1_5 usually is located on the disk after MBR, i.e. after stage1. Also you should know that kernelstart.kernel_sector holds the number only for first sector of the "kernel" (stage1_5 or stage2). Geneneral location of the kernel is described in the structure located within its first sector.Nessphoro wrote:Hold on, I can't get it working,
So I int13 the fat_stage_1_5 (located on the first sector on the hard drive)
and jump to 0x200:0x2000?
GRUB Manual - InstallationEDIT: Or if you know how to install grub from within the OS?
It is floppy specific code. If you use stage1 as MBR boot loader you can replace its code starting from offset 446 with partition table.Nessphoro wrote:Hmm I'm looking at Ubuntu's stage1 and if I copy it to the disk it'll overwrite the partition table
Hex editor?And I meant install GRUB from within non-UNIX os.
Code: Select all
#define GRUB_BOOT_MACHINE_BUFFER_SEG 0x7000
movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx
movw %bx, %es /* load %es segment with disk buffer */
xorw %bx, %bx /* %bx = 0, put it at 0 in the segment */
movw $0x0201, %ax /* function 2 */
int $0x13
jc LOCAL(read_error)
Code: Select all
#define GRUB_BOOT_I386_PC_KERNEL_SEG 0x800
#define GRUB_BOOT_MACHINE_KERNEL_SEG GRUB_OFFSETS_CONCAT (GRUB_BOOT_, GRUB_MACHINE, _KERNEL_SEG)
LOCAL(copy_buffer):
/*
* We need to save %cx and %si because the startup code in
* kernel uses them without initializing them.
*/
pusha
pushw %ds
movw $0x100, %cx
movw %bx, %ds
xorw %si, %si
movw $GRUB_BOOT_MACHINE_KERNEL_ADDR, %di
movw %si, %es
cld
rep
movsw
popw %ds
popa
You're gonna laugh - but I actually did that.egos wrote:It is floppy specific code. If you use stage1 as MBR boot loader you can replace its code starting from offset 446 with partition table.Nessphoro wrote:Hmm I'm looking at Ubuntu's stage1 and if I copy it to the disk it'll overwrite the partition table
Hex editor?And I meant install GRUB from within non-UNIX os.