What does kernel.ld do in XV6?
There is a kernel.ld file in xv6.
It tells linker to build the executable image entry point to _entry
. . = 0x80000000;
ensures the first line of _entry
starts from 0x80000000. See the generated ASM:
The will let boot loader to load this kernel image to the specified memory position. Note: qemu -kernel
starts at 0x1000. And the code in 0x1000 jumps to 0x8000000. That’s why we must define our linker config file so that qemu could find the correct address and code to execute.
If we don’t put any address in linker config file, by default, the image files are generated starting from address 0. But our case is special, it is a kernel image, and qemu -kernel
knows that. Qemu will jump to 0x8000000 no matter what, so we have to put our code starting from that address.
Summary
qemu load the kernel image, and put in memory from the specified address. Then it jumps to 0x8000000 and starts from there!
Last updated