How about just getting it from the ELF header? It's trivial.
Because a bare bones bootloader may not know anything about ELF. The
simplest solution is to just stick a "jmp start_kernel" at LOADADDR
right before the fill. Then the load address and the entry point are
the same. Once the exception vectors get loaded, they'll overwrite the
jmp, so no space is wasted and none of the LOADADDRs have to be
That was my thinking.
Except the fill has nothing to do with exception vectors any more. It
looks like at one time LOADADDR was always 0x8000_0000. Now that it's
set to something else, the fill just leaves a hole for no reason. That's
why I recommend removing it regardless of whether there's a use for my
With the fill is gone, and since the kernel is not normally placed
at 0x8000_0000, I suggest just moving kernel_entry to the top of head.S
instead of putting a jump at the top of the file.
Also, compile tricks won't work (at least in my case). Normally the bootloader
and the kernel are in two memories, often programmed in different ways. For
example, a system normally has rom at the boot address at 0x1fc0_0000, ram at
0x8000_0000, and some other memory (flash, hard disk, whatever) storing a kernel
(or kernels) somewhere else. Any compile time tricks require the boot rom to be
reprogrammed when the kernel changes. That's part of what I wanted to avoid.