svn commit: r187418 - in projects/mips/sys: conf mips/conf mips/mips
Oleksandr Tymoshenko
gonzo at FreeBSD.org
Sun Jan 18 18:37:11 PST 2009
Author: gonzo
Date: Mon Jan 19 02:37:10 2009
New Revision: 187418
URL: http://svn.freebsd.org/changeset/base/187418
Log:
- Add trampoline stuff for bootloaders that do not support ELF
- Replace arm'ish KERNPHYSADDR/KERNVIRTADDR with
KERNLOADADDR/TRAMPLOADADDR and clean configs
Added:
projects/mips/sys/mips/mips/elf_trampoline.c
projects/mips/sys/mips/mips/inckern.S
Modified:
projects/mips/sys/conf/Makefile.mips
projects/mips/sys/conf/ldscript.mips
projects/mips/sys/conf/options.mips
projects/mips/sys/mips/conf/ADM5120
projects/mips/sys/mips/conf/MALTA
projects/mips/sys/mips/conf/QEMU
projects/mips/sys/mips/conf/SENTRY5
Modified: projects/mips/sys/conf/Makefile.mips
==============================================================================
--- projects/mips/sys/conf/Makefile.mips Mon Jan 19 02:31:27 2009 (r187417)
+++ projects/mips/sys/conf/Makefile.mips Mon Jan 19 02:37:10 2009 (r187418)
@@ -28,35 +28,73 @@ S= ../../..
.endif
.include "$S/conf/kern.pre.mk"
+SYSTEM_LD:= ${SYSTEM_LD:$S/conf/ldscript.$M=ldscript.$M}
+SYSTEM_DEP:= ${SYSTEM_DEP:$S/conf/ldscript.$M=ldscript.$M}
+
# XXX: Such sweeping assumptions...
MACHINE=mips
MACHINE_ARCH=mips
+KERNLOADADDR?=0x80001000
+# This obscure value is defined by CFE for WR160N
+# To be changed later
+TRAMPLOADADDR?=0x807963c0
MKMODULESENV+= MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH}
# We default to the MIPS32 ISA, if none specified in the
# kernel configuration file.
ARCH_FLAGS?=-march=mips32
+EXTRA_FLAGS=-fno-pic -mno-abicalls -mno-dsp -G0
HACK_EXTRA_FLAGS=-shared
.if defined(TARGET_BIG_ENDIAN)
CFLAGS+=-EB
SYSTEM_LD+=-EB
+EXTRA_FLAGS+=-EB
+TRAMP_LDFLAGS+=-Wl,-EB
HACK_EXTRA_FLAGS+=-EB -Wl,-EB
.else
CFLAGS+=-EL
SYSTEM_LD+=-EL
+EXTRA_FLAGS+=-EL
+TRAMP_LDFLAGS+=-Wl,-EL
HACK_EXTRA_FLAGS+=-EL -Wl,-EL
.endif
# We add the -fno-pic flag to kernels because otherwise performance
# is extremely poor, as well as -mno-abicalls to force no ABI usage.
-CFLAGS+=-fno-pic -mno-abicalls -G0 $(ARCH_FLAGS)
-HACK_EXTRA_FLAGS+=-fno-pic -mno-abicalls -G0 $(ARCH_FLAGS)
+CFLAGS+=${EXTRA_FLAGS} $(ARCH_FLAGS)
+HACK_EXTRA_FLAGS+=${EXTRA_FLAGS} $(ARCH_FLAGS)
# XXX hardcoded kernel entry point
ASM_CFLAGS+=${CFLAGS} -D_LOCORE -DLOCORE
+KERNEL_EXTRA=trampoline
+trampoline: ${KERNEL_KO}.tramp.bin
+${KERNEL_KO}.tramp.bin: ${KERNEL_KO} $S/$M/$M/elf_trampoline.c \
+ $S/$M/$M/inckern.S
+ ${OBJCOPY} --strip-symbol '$$d' --strip-symbol '$$a' \
+ -g --strip-symbol '$$t' ${FULLKERNEL} ${KERNEL_KO}.tmp
+ sed s/${KERNLOADADDR}/${TRAMPLOADADDR}/ ldscript.$M | \
+ sed s/" + SIZEOF_HEADERS"// > ldscript.$M.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 "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 "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 ${EXTRA_FLAGS} ${TRAMP_LDFLAGS} -Xlinker \
+ -T -Xlinker ldscript.$M.tramp.noheader tmphack.S \
+ $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 \
+
%BEFORE_DEPEND
%OBJS
@@ -69,6 +107,12 @@ ASM_CFLAGS+=${CFLAGS} -D_LOCORE -DLOCORE
%CLEAN
+CLEAN+= ldscript.$M ldscript.$M.tramp.noheader \
+ ${KERNEL_KO}.tramp.noheader ${KERNEL_KO}.tramp.bin
+
+ldscript.$M: $S/conf/ldscript.$M
+ cat $S/conf/ldscript.$M|sed s/KERNLOADADDR/${KERNLOADADDR}/g \
+ > ldscript.$M
%RULES
.include "$S/conf/kern.post.mk"
Modified: projects/mips/sys/conf/ldscript.mips
==============================================================================
--- projects/mips/sys/conf/ldscript.mips Mon Jan 19 02:31:27 2009 (r187417)
+++ projects/mips/sys/conf/ldscript.mips Mon Jan 19 02:37:10 2009 (r187418)
@@ -43,7 +43,7 @@ PROVIDE (_DYNAMIC = 0);
SECTIONS
{
/* Read-only sections, merged into text segment: */
- . = 0x80100000 + SIZEOF_HEADERS;
+ . = KERNLOADADDR + SIZEOF_HEADERS;
.interp : { *(.interp) }
.hash : { *(.hash) }
.dynsym : { *(.dynsym) }
Modified: projects/mips/sys/conf/options.mips
==============================================================================
--- projects/mips/sys/conf/options.mips Mon Jan 19 02:31:27 2009 (r187417)
+++ projects/mips/sys/conf/options.mips Mon Jan 19 02:37:10 2009 (r187418)
@@ -45,8 +45,8 @@ YAMON opt_global.h
CFE opt_global.h
CFE_CONSOLE opt_global.h
-KERNPHYSADDR opt_global.h
-KERNVIRTADDR opt_global.h
+KERNLOADADDR opt_global.h
+TRAMPLOADADDR opt_global.h
PHYSADDR opt_global.h
SOFTFLOAT opt_global.h
Modified: projects/mips/sys/mips/conf/ADM5120
==============================================================================
--- projects/mips/sys/mips/conf/ADM5120 Mon Jan 19 02:31:27 2009 (r187417)
+++ projects/mips/sys/mips/conf/ADM5120 Mon Jan 19 02:37:10 2009 (r187418)
@@ -25,7 +25,6 @@ makeoptions MIPS_LITTLE_ENDIAN=defined
# Don't build any modules yet.
makeoptions MODULES_OVERRIDE=""
-options KERNVIRTADDR=0x80100000
include "../adm5120/std.adm5120"
hints "ADM5120.hints" #Default places to look for devices.
Modified: projects/mips/sys/mips/conf/MALTA
==============================================================================
--- projects/mips/sys/mips/conf/MALTA Mon Jan 19 02:31:27 2009 (r187417)
+++ projects/mips/sys/mips/conf/MALTA Mon Jan 19 02:37:10 2009 (r187418)
@@ -27,7 +27,6 @@ options YAMON
# Don't build any modules yet.
makeoptions MODULES_OVERRIDE=""
-options KERNVIRTADDR=0x80100000
options TICK_USE_YAMON_FREQ=defined
#options TICK_USE_MALTA_RTC=defined
Modified: projects/mips/sys/mips/conf/QEMU
==============================================================================
--- projects/mips/sys/mips/conf/QEMU Mon Jan 19 02:31:27 2009 (r187417)
+++ projects/mips/sys/mips/conf/QEMU Mon Jan 19 02:37:10 2009 (r187418)
@@ -27,7 +27,6 @@ makeoptions ARCH_FLAGS=-march=mips32
# Don't build any modules yet.
makeoptions MODULES_OVERRIDE=""
-options KERNVIRTADDR=0x80100000
include "../adm5120/std.adm5120"
#hints "GENERIC.hints" #Default places to look for devices.
Modified: projects/mips/sys/mips/conf/SENTRY5
==============================================================================
--- projects/mips/sys/mips/conf/SENTRY5 Mon Jan 19 02:31:27 2009 (r187417)
+++ projects/mips/sys/mips/conf/SENTRY5 Mon Jan 19 02:37:10 2009 (r187418)
@@ -41,13 +41,6 @@ options CFE
options CFE_CONSOLE
options ALT_BREAK_TO_DEBUGGER
-# cfe loader expects kernel at 0x80001000 for mips32 w/o backwards
-# offsets in the linked elf image (see ldscript hack)
-# XXX can we conditionalize the linker stuff on options CFE?
-options KERNVIRTADDR=0x80001000
-
-makeoptions LDSCRIPT_NAME= ldscript.mips.cfe
-
#makeoptions ARCH_FLAGS=-march=mips32
makeoptions MIPS_LITTLE_ENDIAN=defined
makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols
Added: projects/mips/sys/mips/mips/elf_trampoline.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/mips/sys/mips/mips/elf_trampoline.c Mon Jan 19 02:37:10 2009 (r187418)
@@ -0,0 +1,133 @@
+/*-
+ * Copyright (c) 2005 Olivier Houchard. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+#include <machine/asm.h>
+#include <sys/param.h>
+#include <sys/elf32.h>
+#include <sys/inflate.h>
+#include <machine/elf.h>
+#include <machine/cpufunc.h>
+#include <machine/stdarg.h>
+
+/*
+ * Since we are compiled outside of the normal kernel build process, we
+ * need to include opt_global.h manually.
+ */
+#include "opt_global.h"
+#include "opt_kernname.h"
+
+extern char kernel_start[];
+extern char kernel_end[];
+
+static __inline void *
+memcpy(void *dst, const void *src, int len)
+{
+ const char *s = src;
+ char *d = dst;
+
+ while (len) {
+ if (0 && len >= 4 && !((vm_offset_t)d & 3) &&
+ !((vm_offset_t)s & 3)) {
+ *(uint32_t *)d = *(uint32_t *)s;
+ s += 4;
+ d += 4;
+ len -= 4;
+ } else {
+ *d++ = *s++;
+ len--;
+ }
+ }
+ return (dst);
+}
+
+static __inline void
+bzero(void *addr, int count)
+{
+ char *tmp = (char *)addr;
+
+ while (count > 0) {
+ if (count >= 4 && !((vm_offset_t)tmp & 3)) {
+ *(uint32_t *)tmp = 0;
+ tmp += 4;
+ count -= 4;
+ } else {
+ *tmp = 0;
+ tmp++;
+ count--;
+ }
+ }
+}
+
+/*
+ * Relocate PT_LOAD segements of kernel ELF image to their respective
+ * virtual addresses and return entry point
+ */
+void *
+load_kernel(void * kstart)
+{
+ Elf32_Ehdr *eh;
+ Elf32_Phdr phdr[64] /* XXX */;
+ int i;
+ void *entry_point;
+
+ eh = (Elf32_Ehdr *)kstart;
+ entry_point = (void*)eh->e_entry;
+ memcpy(phdr, (void *)(kstart + eh->e_phoff ),
+ eh->e_phnum * sizeof(phdr[0]));
+
+ for (i = 0; i < eh->e_phnum; i++) {
+ volatile char c;
+
+ if (phdr[i].p_type != PT_LOAD)
+ continue;
+
+ memcpy((void *)(phdr[i].p_vaddr),
+ (void*)(kstart + phdr[i].p_offset), phdr[i].p_filesz);
+ /* Clean space from oversized segments, eg: bss. */
+ if (phdr[i].p_filesz < phdr[i].p_memsz)
+ bzero((void *)(phdr[i].p_vaddr + phdr[i].p_filesz),
+ phdr[i].p_memsz - phdr[i].p_filesz);
+ }
+
+ return entry_point;
+}
+
+void
+_startC(register_t a0, register_t a1, register_t a2, register_t a3)
+{
+ unsigned int * code;
+ int i;
+ void (*entry_point)(register_t, register_t, register_t, register_t);
+
+ /*
+ * Relocate segment to the predefined memory location
+ * Most likely it will be KSEG0/KSEG1 address
+ */
+ entry_point = load_kernel(kernel_start);
+
+ /* Pass saved registers to original _start */
+ entry_point(a0, a1, a2, a3);
+}
Added: projects/mips/sys/mips/mips/inckern.S
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/mips/sys/mips/mips/inckern.S Mon Jan 19 02:37:10 2009 (r187418)
@@ -0,0 +1,34 @@
+/*-
+ * Copyright (c) 2005 Olivier Houchard. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "opt_kernname.h"
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$")
+.section ".real_kernel","aw"
+.globl kernel_start;
+kernel_start:
+.incbin KERNNAME
+.globl kernel_end;
+kernel_end:
More information about the svn-src-projects
mailing list