I'm developing a bootloader that loads a (so far stub) kernel in 32-bit protected mode . In the wiki, on Beginner_Mistakes, specifically in the section Avoid Ignorance, it is suggested not to use flat binaries as kernel images, but ELF images instead, just like I am doing.
I want the kernel to reside at physical address 0x00100000 (1MiB) and it being mapped to virtual address 0xC0000000 (3GiB).
Niether the physical memory address the bootloader loads the (ELF program segments of the) kernel at, nor the virtual address this space of addresses will be mapped to, is statically fixed by the bootloader: it is actually determined at runtime and segment-by-segment according to the contents of corresponding p_paddr and p_vaddr that appear in the corresponding program segement header of the to-be-loaded ELF kernel.
I set these two fields in the process of linking (as well as the virtual addresses that the code must have). In terms of the LD linker these two fields, p_paddr and p_vaddr, are known as LMA and VMA, respectively.
I hope I made myself understood to this point...
In order to make it clearer, assume my kernel is named "kernel.elf". If I run the following command on the shell:
Code: Select all
readelf -l kernel.elf
Code: Select all
Elf file type is EXEC (Executable file)
Entry point 0xc0000000
There are 2 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0xc0000000 0x00100000 0x03c3c 0x03c3c R E 0x1000
LOAD 0x005000 0xc0004000 0x00104000 0x00004 0x01e58 RW 0x1000
Section to Segment mapping:
Segment Sections...
00 .text.start .text .rodata .eh_frame
01 .data .bss
Has anybody here ever had a similar experience? Please, let me know.
Thanks in Advance