Make the ELF trampoline binary ELF executable (and do some cleanup).

- Remove the -shared flag for the trampoline binary, generate an
  ELF executable instead of a shared object.
- No need to generate tmphack.S,  move the code to sys/mips/mips/inckern.S
- No need generate opt_kernname.h, KERNNAME can be passed with -D

Reviewed by:	gonzo, imp
This commit is contained in:
Jayachandran C. 2010-12-16 04:56:03 +00:00
parent eed51a7443
commit d048eaaca7
3 changed files with 24 additions and 18 deletions

View File

@ -50,6 +50,7 @@ HACK_EXTRA_FLAGS=-shared
# is extremely poor, as well as -mno-abicalls to force no ABI usage.
CFLAGS+=${EXTRA_FLAGS} $(ARCH_FLAGS)
HACK_EXTRA_FLAGS+=${EXTRA_FLAGS} $(ARCH_FLAGS)
TRAMP_EXTRA_FLAGS=${EXTRA_FLAGS} $(ARCH_FLAGS)
# XXX hardcoded kernel entry point
ASM_CFLAGS+=${CFLAGS} -D_LOCORE -DLOCORE
@ -62,21 +63,10 @@ ${KERNEL_KO}.tramp.bin: ${KERNEL_KO} $S/$M/$M/elf_trampoline.c \
-g --strip-symbol '$$t' ${FULLKERNEL} ${KERNEL_KO}.tmp
sed s/${KERNLOADADDR}/${TRAMPLOADADDR}/ ${LDSCRIPT_NAME} | \
sed s/" + SIZEOF_HEADERS"// > ${LDSCRIPT_NAME}.tramp.noheader
# Generate .S file that setups stack and jumps to trampoline
echo "#include <machine/asm.h>" >tmphack.S
echo "ENTRY(_start)" >>tmphack.S
echo "PTR_LA t0, kernel_end" >>tmphack.S
echo "move sp, t0" >>tmphack.S
echo "add sp, 0x2000" >>tmphack.S
echo "and sp, ~0x7" >>tmphack.S
echo "PTR_LA t0, _startC" >>tmphack.S
echo "j t0" >>tmphack.S
echo "END(_start)" >>tmphack.S
echo "#define KERNNAME \"${KERNEL_KO}.tmp\"" >opt_kernname.h
${CC} -O -nostdlib -I. -I$S ${HACK_EXTRA_FLAGS} ${TRAMP_LDFLAGS} -Xlinker \
-T -Xlinker ${LDSCRIPT_NAME}.tramp.noheader tmphack.S \
$S/$M/$M/elf_trampoline.c $S/$M/$M/inckern.S \
-o ${KERNEL_KO}.tramp.noheader
${CC} -O -nostdlib -I. -I$S ${TRAMP_EXTRA_FLAGS} ${TRAMP_LDFLAGS} -Xlinker \
-T -Xlinker ${LDSCRIPT_NAME}.tramp.noheader \
-DKERNNAME="\"${KERNEL_KO}.tmp\"" $S/$M/$M/elf_trampoline.c \
$S/$M/$M/inckern.S -o ${KERNEL_KO}.tramp.noheader
${OBJCOPY} -S -O binary ${KERNEL_KO}.tramp.noheader \
${KERNEL_KO}.tramp.bin \

View File

@ -42,7 +42,10 @@ __FBSDID("$FreeBSD$");
* need to include opt_global.h manually.
*/
#include "opt_global.h"
#include "opt_kernname.h"
#ifndef KERNNAME
#error Kernel name not provided
#endif
extern char kernel_start[];
extern char kernel_end[];

View File

@ -22,10 +22,23 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "opt_kernname.h"
#include <machine/asm.h>
__FBSDID("$FreeBSD$")
ENTRY(_start)
PTR_LA t0, kernel_end
move sp, t0
add sp, 0x2000
and sp, ~0x7
PTR_LA t0, _startC
j t0
nop
END(_start)
#ifndef KERNNAME
#error Need a kernel name here
#endif
.section ".real_kernel","aw"
.globl kernel_start;
kernel_start: