Rather than trying to reconstruct the ISA bit by hand use the ELF entry point recorded in the kernel executable itself, by parsing the output of `objdump -f' and sign-extending the address retrieved if 32-bit. The tool always prints the entry point using either 8 or 16 hexadecimal digits even in the presence of leading zeros, matching the address width (class) of the ELF file. Signed-off-by: Maciej W. Rozycki <macro@xxxxxxxxxx> --- On Sat, 19 Aug 2017, James Hogan wrote: > >+# Knowing that a 32-bit kernel will be linked at a KSEG address > > thats not true with CONFIG_KVM_GUEST kernels, which use a separate set > of emulated guest kernel segments in useg, i.e. at 0x40000000. I've also > seen EVA kernels linked at low addresses like around 0x20000000, though > entry gets a bit fiddly for EVA depending on whether bootloader already > has the chosen segment configuration set up. I wasn't aware of that. So we need a slightly more robust `sed' program, like the below. It handles any 32-bit address now. I hope the formatting is fine. Please apply. Maciej --- arch/mips/Makefile | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) linux-mips-start-address.diff Index: linux-sfr-usead/arch/mips/Makefile =================================================================== --- linux-sfr-usead.orig/arch/mips/Makefile 2017-08-18 22:17:42.962681000 +0100 +++ linux-sfr-usead/arch/mips/Makefile 2017-08-21 17:47:16.802753000 +0100 @@ -244,20 +244,11 @@ ifdef CONFIG_PHYSICAL_START load-y = $(CONFIG_PHYSICAL_START) endif -entry-noisa-y = 0x$(shell $(NM) vmlinux 2>/dev/null \ - | grep "\bkernel_entry\b" | cut -f1 -d \ ) -ifdef CONFIG_CPU_MICROMIPS - # - # Set the ISA bit, since the kernel_entry symbol in the ELF will have it - # clear which would lead to images containing addresses which bootloaders may - # jump to as MIPS32 code. - # - entry-y = $(patsubst %0,%1,$(patsubst %2,%3,$(patsubst %4,%5, \ - $(patsubst %6,%7,$(patsubst %8,%9,$(patsubst %a,%b, \ - $(patsubst %c,%d,$(patsubst %e,%f,$(entry-noisa-y))))))))) -else - entry-y = $(entry-noisa-y) -endif +# Sign-extend the entry point to 64 bits if retrieved as a 32-bit number. +entry-y = $(shell $(OBJDUMP) -f vmlinux 2>/dev/null \ + | sed -n '/^start address / { \ + s/^.*0x\([0-7].......\)$$/0x00000000\1/; \ + s/^.*0x\(........\)$$/0xffffffff\1/; p }') cflags-y += -I$(srctree)/arch/mips/include/asm/mach-generic drivers-$(CONFIG_PCI) += arch/mips/pci/