Recently I'm learning about the OS. And I want to write a simple bootloader, which change the real mode to protect mode and then load the simple kernel.
But I can't figure out the entry address problem.
At first I put the bootloader in the first sector of the OS.img(qemu), and then the kernel begin at the second sector.
Here's readelf result of my kernel:
The entry point address is 0x800c.
And the LMA and VMA are below:
A part of the bootloader which read elf-type kernel and then get into the entry(),which is the entry point address.
However, when I disassemble the bootloader, the entry() is below:
Call *0x8018, not *0x800c.
I don't know why this happen.
Could you please help me?
call *0x8018 performs a call to an address that is stored at
0x8018, that's correct since
0x8000 and offset of
e_entry in the header is
The real problem is in the way you load segments into memory. Each segment should be loaded at address
p_vaddr from file offset
p_offset. Notice that in your case
0x8000, that the same place in memory you loaded elf header to and that's why
ELFHDR->e_entry gets overwritten. The easiest solution would be to load elf header at different address.