简体   繁体   中英

entry() get into the different address from the entry point I set in the Elf

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 ELFHDR is 0x8000 and offset of e_entry in the header is 0x18 .

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 p_vaddr is 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.

Source: http://www.skyfree.org/linux/references/ELF_Format.pdf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM