Make the elf trampoline disable the MMU, and link it at physical address,

to avoid bad surprises.
This commit is contained in:
Olivier Houchard 2005-12-20 01:28:17 +00:00
parent 5776f433ab
commit fe516e3c17
2 changed files with 59 additions and 18 deletions

View File

@ -47,9 +47,10 @@ memcpy(void *dst, const void *src, int len)
{
const char *s = src;
char *d = dst;
while (len) {
if (len >= 4 && !((vm_offset_t)d & 3) && !((vm_offset_t)s & 3)) {
if (0 && len >= 4 && !((vm_offset_t)d & 3) &&
!((vm_offset_t)s & 3)) {
*(uint32_t *)d = *(uint32_t *)s;
s += 4;
d += 4;
@ -83,6 +84,29 @@ bzero(void *addr, int count)
void
_start(void)
{
int physaddr = KERNPHYSADDR;
int tmp1;
__asm __volatile("adr %0, 2f\n"
"bic %0, %0, #0xff000000\n"
"bic sp, sp, #0xff000000\n"
"and %1, %1, #0xff000000\n"
"orr %0, %0, %1\n"
"orr sp, sp, %1\n"
"mrc p15, 0, %1, c1, c0, 0\n"
"bic %1, %1, #1\n" /* Disable MMU */
"orr %1, %1, #(4 | 8)\n" /* Add DC enable,
WBUF enable */
"orr %1, %1, #0x1000\n" /* Add IC enable */
"orr %1, %1, #(0x800)\n" /* BPRD enable */
"mcr p15, 0, %1, c1, c0, 0\n"
"nop\n"
"nop\n"
"nop\n"
"mov pc, %0\n"
"2: nop\n"
: "=r" (tmp1), "+r" (physaddr));
__start();
}
@ -156,6 +180,7 @@ inflate_kernel(void *kernel, void *startaddr)
char slide[GZ_WSIZE];
orig_input = kernel;
memcnt = memtot = 0;
i_input = (char *)kernel + GZ_HEAD;
if (((char *)kernel)[3] & 0x18) {
while (*i_input)
@ -173,7 +198,6 @@ inflate_kernel(void *kernel, void *startaddr)
#endif
void *
load_kernel(unsigned int kstart, unsigned int curaddr,unsigned int func_end,
int d)
@ -194,6 +218,7 @@ load_kernel(unsigned int kstart, unsigned int curaddr,unsigned int func_end,
entry_point = (void*)eh->e_entry;
memcpy(phdr, (void *)(kstart + eh->e_phoff ),
eh->e_phnum * sizeof(phdr[0]));
/* Determine lastaddr. */
for (i = 0; i < eh->e_phnum; i++) {
if (lastaddr < (phdr[i].p_vaddr - KERNVIRTADDR + curaddr
@ -204,9 +229,12 @@ load_kernel(unsigned int kstart, unsigned int curaddr,unsigned int func_end,
/* Save the symbol tables, as there're about to be scratched. */
lastaddr = roundup(lastaddr, sizeof(long));
shdr = (Elf_Shdr *)lastaddr;
lastaddr += sizeof(*shdr) * eh->e_shnum;
memcpy(shdr, (void *)(kstart + eh->e_shoff),
sizeof(*shdr) * eh->e_shnum);
if (eh->e_shnum * eh->e_shentsize != 0 &&
eh->e_shoff != 0) {
shdr = (Elf_Shdr *)(kstart + eh->e_shoff);
for (i = 0; i < eh->e_shnum; i++) {
if (shdr[i].sh_type == SHT_SYMTAB) {
for (j = 0; j < eh->e_phnum; j++) {
@ -295,6 +323,10 @@ load_kernel(unsigned int kstart, unsigned int curaddr,unsigned int func_end,
*((Elf_Addr *)curaddr + 2) = lastaddr - curaddr + KERNVIRTADDR;
} else
*(Elf_Addr *)curaddr = 0;
/* Invalidate the instruction cache. */
__asm __volatile("mcr p15, 0, %0, c7, c5, 0\n"
"mcr p15, 0, %0, c7, c10, 4\n"
: : "r" (curaddr));
/* Jump to the entry point. */
((void(*)(void))(entry_point - KERNVIRTADDR + curaddr))();
__asm __volatile(".globl func_end\n"

View File

@ -52,8 +52,7 @@ DDB_ENABLED!= grep DDB opt_ddb.h || true
SYSTEM_LD_ = ${LD} -Bdynamic -T ldscript.$M.noheader \
-warn-common -export-dynamic -dynamic-linker /red/herring -o \
${FULLKERNEL}.noheader -X ${SYSTEM_OBJS} vers.o
SYSTEM_LD_TAIL +=; cat ldscript.$M| \
sed s/" + SIZEOF_HEADERS"// \
SYSTEM_LD_TAIL +=;sed s/" + SIZEOF_HEADERS"// ldscript.$M\
>ldscript.$M.noheader; \
${SYSTEM_LD_}; \
${OBJCOPY} -S -O binary ${FULLKERNEL}.noheader \
@ -62,33 +61,38 @@ SYSTEM_LD_TAIL +=; cat ldscript.$M| \
.if ${DDB_ENABLED} != "" || defined(BUILD_ELF_TRAMPOLINE)
SYSTEM_LD_TAIL += ;echo "\#define KERNNAME \"${KERNEL_KO}.tmp\"" \
>opt_kernname.h ;\
${OBJCOPY} ${STRIP_FLAGS} --strip-symbol '$$d' --strip-symbol '$$a' \
sed s/${KERNVIRTADDR}/${KERNPHYSADDR}/ ldscript.$M > \
ldscript.$M.tramp; \
sed s/" + SIZEOF_HEADERS"// ldscript.$M.tramp > \
ldscript.$M.tramp.noheader; \
${OBJCOPY} --strip-symbol '$$d' --strip-symbol '$$a' \
-g --strip-symbol '$$t' ${FULLKERNEL} ${KERNEL_KO}.tmp;\
${CC} -O -nostdlib -I. -Xlinker -T -Xlinker ldscript.arm \
${CC} -O -nostdlib -I. -Xlinker -T -Xlinker ldscript.$M.tramp \
$S/$M/$M/elf_trampoline.c $S/$M/$M/inckern.S -o ${KERNEL_KO}.tramp;\
${CC} -O -nostdlib -I. -Xlinker -T -Xlinker ldscript.arm.noheader \
${CC} -O -nostdlib -I. -Xlinker -T -Xlinker ldscript.$M.tramp.noheader \
$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; \
gzip -9 ${KERNEL_KO}.tmp; \
${OBJCOPY} ${STRIP_FLAGS} ${KERNEL_KO}.tmp; \
echo "\#define KERNNAME \"${KERNEL_KO}.tmp.gz\"" \
>opt_kernname.h ;\
gzip -9 ${KERNEL_KO}.tmp; \
eval $$(stat -s ${KERNEL_KO}.tmp.gz) && \
echo "\#define KERNSIZE $$st_size" >>opt_kernname.h;\
${CC} -O -nostdlib -I. -Xlinker -T -Xlinker ldscript.arm \
-DKZIP $S/$M/$M/elf_trampoline.c $S/kern/inflate.c $S/$M/$M/inckern.S \
${CC} -O2 -DKZIP -I. -c $S/kern/inflate.c -o inflate-tramp.o; \
${CC} -O -nostdlib -I. -Xlinker -T -Xlinker ldscript.$M.tramp \
-DKZIP $S/$M/$M/elf_trampoline.c inflate-tramp.o $S/$M/$M/inckern.S \
-o ${KERNEL_KO}.gz.tramp;\
${CC} -O -nostdlib -I. -Xlinker -T -Xlinker ldscript.arm.noheader \
-DKZIP $S/$M/$M/elf_trampoline.c $S/kern/inflate.c $S/$M/$M/inckern.S \
${CC} -O -nostdlib -I. -Xlinker -T -Xlinker ldscript.$M.tramp.noheader \
-DKZIP $S/$M/$M/elf_trampoline.c inflate-tramp.o $S/$M/$M/inckern.S \
-o ${KERNEL_KO}.tramp.noheader; \
${OBJCOPY} -S -O binary ${KERNEL_KO}.tramp.noheader \
${KERNEL_KO}.gz.tramp.bin; \
rm ${KERNEL_KO}.tmp.gz ${KERNEL_KO}.tramp.noheader opt_kernname.h;
rm ${KERNEL_KO}.tmp.gz ${KERNEL_KO}.tramp.noheader opt_kernname.h \
inflate-tramp.o;
.endif
CLEANFILES += ldscript.$M ldscript.$M.noheader ${KERNEL_KO}.bin \
${KERNEL_KO}.tramp ${KERNEL_KO}.tramp.bin
%BEFORE_DEPEND
%OBJS
@ -101,8 +105,13 @@ CLEANFILES += ldscript.$M ldscript.$M.noheader ${KERNEL_KO}.bin \
%CLEAN
CLEAN+= ldscript.$M ${KERNEL_KO}.bin ldscript.$M.noheader
.if ${DDB_ENABLED} != ""
CLEAN+= kernel.tramp
CLEAN+= ${KERNEL_KO}.tramp ${KERNEL_KO}.tramp.bin ldscript.$M.tramp \
ldscript.$M.tramp.noheader ${KERNEL_KO}.gz.tramp \
${KERNEL_KO}.gz.tramp.bin
.endif
ldscript.$M: $S/conf/ldscript.$M
cat $S/conf/ldscript.$M|sed s/KERNPHYSADDR/${KERNPHYSADDR}/g| \