how the boot loader knows kernel start address?

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
asmboozer

how the boot loader knows kernel start address?

Post by asmboozer »

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.
User avatar
Pype.Clicker
Member
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?

Post by Pype.Clicker »

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 ...
Kemp

Re:how the boot loader knows kernel start address?

Post by Kemp »

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.
timmy_isdaman

Re:how the boot loader knows kernel start address?

Post by timmy_isdaman »

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.

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
This is allows Grub to load .text and .data from disk and to zero .bss.
Post Reply