if you specify a linker script like below,
OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
how the boot loader knows to load the kernel at 0x00100000?
i think although the kernel is binary file, the kernel must has some header to tell the loader how to load it, i think it is same as elf,fat file.
how the boot loader knows kernel start address?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:how the boot loader knows kernel start address?
most of the time, this is a convention between the OS and the loader itself. IIrc, the multiboot specs states that the kernel will be loaded at 1MB physical. Now, if you're using ELF (or maybe appropriate MB header extensions), you can give an alternate physical location ...
Re:how the boot loader knows kernel start address?
If it's your own loader and kernel then the assumption is that it knows to load it there because you decided that's where it should be loaded.
Re:how the boot loader knows kernel start address?
As Pype said a kernel in ELF format already has all needed information. Other formats (binary, a.out) will need to append various addresses at the end of their multiboot header.
This is allows Grub to load .text and .data from disk and to zero .bss.
Code: Select all
mboot:
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
dd mboot
dd code ; start of .text
dd bss ; start of .bss
dd end ; end of bss
dd start ; kernel entry