From ce4210d673a2afd61732fb58a9df4b037b157f1a Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Thu, 24 Nov 2005 02:27:55 +0000 Subject: [PATCH] Use a magic number to know we were started from the elf wrapper. Add a dummy _start function to make the non-elf version of the wrapper work. --- sys/arm/arm/elf_trampoline.c | 18 ++++++++++++++---- sys/arm/include/elf.h | 5 +++++ sys/arm/xscale/i80321/iq31244_machdep.c | 10 +++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/sys/arm/arm/elf_trampoline.c b/sys/arm/arm/elf_trampoline.c index cfe17bab005..aad5d854fe1 100644 --- a/sys/arm/arm/elf_trampoline.c +++ b/sys/arm/arm/elf_trampoline.c @@ -36,6 +36,14 @@ __FBSDID("$FreeBSD$"); extern char kernel_start[]; extern char kernel_end[]; +void __start(void); + +void +_start(void) +{ + __start(); +} + static __inline void * memcpy(void *dst, const void *src, int len) { @@ -168,8 +176,10 @@ load_kernel(unsigned int kstart, unsigned int kend, unsigned int curaddr,unsigne phdr[i].p_filesz); } /* Now grab the symbol tables. */ - *(Elf_Addr *)curaddr = ssym - curaddr + KERNVIRTADDR; - *((Elf_Addr *)curaddr + 1) = lastaddr - curaddr + KERNVIRTADDR; + *(Elf_Addr *)curaddr = MAGIC_TRAMP_NUMBER; + *((Elf_Addr *)curaddr + 1) = ssym - curaddr + KERNVIRTADDR; + *((Elf_Addr *)curaddr + 2) = lastaddr - curaddr + KERNVIRTADDR; + /* Jump to the entry point. */ ((void(*)(void))(entry_point - KERNVIRTADDR + curaddr))(); __asm __volatile(".globl func_end\n" @@ -179,7 +189,7 @@ load_kernel(unsigned int kstart, unsigned int kend, unsigned int curaddr,unsigne extern char func_end[]; -int _start(void) +void __start(void) { void *curaddr; @@ -194,5 +204,5 @@ int _start(void) ((void (*)())dst)((unsigned int)&kernel_start, (unsigned int)&kernel_end, (unsigned int)curaddr, dst + (unsigned int)&func_end - - (unsigned int)(&load_kernel),1); + (unsigned int)(&load_kernel), 1); } diff --git a/sys/arm/include/elf.h b/sys/arm/include/elf.h index a6f1462fb3b..81351e8e91b 100644 --- a/sys/arm/include/elf.h +++ b/sys/arm/include/elf.h @@ -125,4 +125,9 @@ __ElfType(Auxinfo); #define ELF_TARG_MACH EM_ARM #define ELF_TARG_VER 1 +/* + * Magic number for the elf trampoline, chosen wisely to be an immediate + * value. + */ +#define MAGIC_TRAMP_NUMBER 0x5c000003 #endif /* !_MACHINE_ELF_H_ */ diff --git a/sys/arm/xscale/i80321/iq31244_machdep.c b/sys/arm/xscale/i80321/iq31244_machdep.c index a49a3f71ee0..990b5b648cd 100644 --- a/sys/arm/xscale/i80321/iq31244_machdep.c +++ b/sys/arm/xscale/i80321/iq31244_machdep.c @@ -233,16 +233,16 @@ initarm(void *arg, void *arg2) fake_preload[i++] = sizeof(uint32_t); fake_preload[i++] = (uint32_t)&end - KERNBASE - 0x00200000; #ifdef DDB - if (*(uint32_t *)KERNVIRTADDR != 0) { + if (*(uint32_t *)KERNVIRTADDR == MAGIC_TRAMP_NUMBER) { fake_preload[i++] = MODINFO_METADATA|MODINFOMD_SSYM; fake_preload[i++] = sizeof(vm_offset_t); - fake_preload[i++] = *(uint32_t *)KERNVIRTADDR; + fake_preload[i++] = *(uint32_t *)(KERNVIRTADDR + 4); fake_preload[i++] = MODINFO_METADATA|MODINFOMD_ESYM; fake_preload[i++] = sizeof(vm_offset_t); - fake_preload[i++] = *(uint32_t *)(KERNVIRTADDR + 4); - lastaddr = *(uint32_t *)(KERNVIRTADDR + 4); + fake_preload[i++] = *(uint32_t *)(KERNVIRTADDR + 8); + lastaddr = *(uint32_t *)(KERNVIRTADDR + 8); zend = lastaddr; - zstart = *(uint32_t *)KERNVIRTADDR; + zstart = *(uint32_t *)(KERNVIRTADDR + 4); ksym_start = zstart; ksym_end = zend; } else