From: Maxim Baryshnikov Date: Mon, 21 Mar 2016 01:24:00 +0000 (+0100) Subject: fiasco: bootstrap: Some tries to relink fiasco image on 0x0 address. X-Git-Url: https://rtime.felk.cvut.cz/gitweb/jailhouse-test.git/commitdiff_plain/83271935e542fa50d01e056c856b88663f5b6efe fiasco: bootstrap: Some tries to relink fiasco image on 0x0 address. linkerscript changed a little. link_objects.sh does linking of bootstrap32.elf in fiasco/l4 build dir. Must make a little correction for $BOOTST_OBJ_DIR variable before launch. --- diff --git a/bootstrap-relink/boot.S b/bootstrap-relink/boot.S new file mode 100644 index 0000000..ef13a9f --- /dev/null +++ b/bootstrap-relink/boot.S @@ -0,0 +1,63 @@ +/* + * (c) 2009 Frank Mehnert , + * Torsten Frenzel + * economic rights: Technische Universität Dresden (Germany) + * + * This file is part of TUD:OS and distributed under the terms of the + * GNU General Public License 2. + * Please see the COPYING-GPL-2 file for details. + */ +/* -*- c -*- */ + + .globl _start + .p2align 4 +_start: +#ifdef REALMODE_LOADING + cld + cli + mov $(3 * 8), %eax + mov %eax, %ds + mov %eax, %es + mov %eax, %fs + mov %eax, %gs + + /* We have the following problem: Our image is loaded at 0x00100000 + * by the boot loader but we don't want to get into conflict with + * the AMD64 executable. Therefore we move ourself out of the way. + * We are linked to 0x01000000 (see ARCH-amd64/boot32/bootstrap.ld) */ + mov %esi, %ebx + mov $0x00100000, %esi + mov $0x01000000, %edi + mov $_image_end, %ecx + sub $_image_start, %ecx + rep movsb + mov $1f, %eax + jmp *%eax + 1: mov %ebx, %esi + lss _stack_seg, %esp + #else + leal _stack,%esp +#endif + + pushl %esi /* ptr to real mode */ + pushl %eax + pushl %ebx + pushl $0 /* no return address */ + jmp bootstrap + + .align 4 + + .p2align(2), 0x90 + .long 0x1BADB002 /* magic */ + .long 0x00000000 /* feature flags */ + .long 0 - 0x1BADB002 + +#ifdef REALMODE_LOADING +_stack_seg: + .long _stack + .word (3 * 8) +#endif + + .bss + .space 8192 +_stack: diff --git a/bootstrap-relink/bootstrap32.ld b/bootstrap-relink/bootstrap32.ld new file mode 100644 index 0000000..9c19255 --- /dev/null +++ b/bootstrap-relink/bootstrap32.ld @@ -0,0 +1,33 @@ +ENTRY(_start) +SECTIONS +{ + . = 0x00000000; + _image_start = .; + .text : + { + *(.text .text.*) + *(.rodata .rodata.*) + } =0x9090 + + .data : + { + *(.data .data.*) + *(.bss .bss.*) + *(COMMON) + } + _image_end = .; + + /* Value of DEFAULT_RELOC_amd64 */ + .sixtyfour 0x2d0000 : + { + . = . + 500000; + } + + /DISCARD/ : { + *(.note.gnu.build-id) + *(.interp) + *(.comment) + *(.note) + *(.eh_frame) + } +} diff --git a/bootstrap-relink/link_objects.sh b/bootstrap-relink/link_objects.sh new file mode 100755 index 0000000..df2c6b9 --- /dev/null +++ b/bootstrap-relink/link_objects.sh @@ -0,0 +1,110 @@ +#!/bin/bash +BUILD_DIR=$PWD/build +#LD_SCRIPT64=$PWD/bootstrap.ld +LD_SCRIPT32=$PWD/bootstrap32.ld +SNAP_DIR=$1 + +set -e; + +echo "[bootstrap] remake..." +START_DIR=$PWD +cd $SNAP_DIR/obj/l4/amd64/pkg/bootstrap +make +cd $START_DIR + +BOOTST_OBJ_DIR=$SNAP_DIR/obj/l4/amd64/pkg/bootstrap/server/src/OBJ-amd64_K8 + +# echo "[bootstrap] linking..." +# cd $BOOTST_OBJ_DIR +# LD_PRELOAD=libgendep.so \ +# LD_LIBRARY_PATH=$SNAP_DIR/obj/l4/amd64/tool/gendep/64:$SNAP_DIR/obj/l4/amd64/tool/gendep/32 \ +# GENDEP_TARGET=$BUILD_DIR/bootstrap.elf \ +# GENDEP_BINARY=ld \ +# GENDEP_BINARY_ALT1=ld \ +# ld -m elf_x86_64 -o $BUILD_DIR/bootstrap.elf \ +# --whole-archive \ +# ARCH-amd64/crt0.o \ +# exec.o \ +# module.o \ +# base_critical.o \ +# region.o \ +# startup.o \ +# init_kip_f.o \ +# libc_support+.o \ +# patch.o \ +# koptions.o \ +# platform_common.o \ +# memory.o \ +# boot_modules.o \ +# platform/x86_pc.o \ +# ARCH-x86/reboot.o \ +# --no-whole-archive -nostdlib -static -Bstatic --eh-frame-hdr -m elf_x86_64 -z max-page-size=0x1000 -z common-page-size=0x1000 \ +# --defsym=__executable_start=0x2d0000 -m elf_x86_64 -z max-page-size=0x1000 -z common-page-size=0x1000 \ +# --defsym __L4_KIP_ADDR__=0x6ffff000 --defsym __L4_STACK_ADDR__=0x70000000 -L$SNAP_DIR/obj/l4/amd64/lib/amd64_K8 \ +# -L$SNAP_DIR/obj/l4/amd64/lib \ +# -T$LD_SCRIPT64\ +# --start-group \ +# -ldrivers_uart -lcxx_base -lcxx_io -luc_c_minimal $SNAP_DIR/obj/l4/amd64/lib/amd64_K8/libgcc.a \ +# --end-group \ +# --warn-common \ +# --defsym=__executable_start=0x2d0000 \ +# /usr/lib/gcc/x86_64-linux-gnu/4.9/crtend.o \ +# $SNAP_DIR/obj/l4/amd64/lib/amd64_K8/crtn.o +# cd $START_DIR +# echo "[bootstrap64] Preparing binary to include.." +# objcopy -S $BUILD_DIR/bootstrap.elf $BUILD_DIR/bootstrap64.bin +# objdump -D $BUILD_DIR/bootstrap.elf > disasms/bootstrap64.elf.s +# chmod -x $BUILD_DIR/bootstrap64.bin +# objcopy -B i386 -I binary -O elf32-i386 $BUILD_DIR/bootstrap64.bin $BUILD_DIR/bootstrap32.bin + +echo "[boot.S] Compiling the header of image.." +gcc -m32 -o $BUILD_DIR/boot.o32 -c \ + -DMODADDR=0x02000000 \ + -DRAM_BASE=0 \ + -DL4_MINIMAL_LIBC=1 \ + -DCMDLINE="\"\"" \ + -DPLATFORM_TYPE=\"pc\" \ + -DPLATFORM_TYPE_pc \ + -DPLATFORM_UART_NR= \ + -DSYSTEM_amd64_K8 \ + -DARCH_amd64 \ + -DCPUTYPE_K8 \ + -DL4API_ \ + -D_GNU_SOURCE \ + -DL4_MINIMAL_LIBC \ + -I$SNAP_DIR/src/l4/pkg/bootstrap/server/src \ + -I$SNAP_DIR/src/l4/pkg/bootstrap/server/src/ARCH-amd64 \ + -I$SNAP_DIR/obj/l4/amd64/include/amd64 \ + -I$SNAP_DIR/obj/l4/amd64/include \ + -isystem $SNAP_DIR/obj/l4/amd64/include/sys/amd64 \ + -isystem $SNAP_DIR/obj/l4/amd64/include/sys -nostdinc \ + -I$SNAP_DIR/obj/l4/amd64/include/uclibc \ + -I$SNAP_DIR/obj/l4/amd64/include/contrib/libstdc++-v3 \ + -isystem /usr/lib/gcc/x86_64-linux-gnu/4.9/include \ + -isystem /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed \ + -fno-omit-frame-pointer -mno-sse -g -Os -mno-red-zone -march=k8 -Wextra -Wall \ + -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -fno-common -std=gnu99 \ + -mno-red-zone -march=k8 -fno-stack-protector -mno-sse -m32 -fno-stack-protector \ + ./boot.S + +echo "[bootstrap32] Linking final image.." + +gcc -m32 -o $BUILD_DIR/bootstrap32.elf -nostdlib -static \ + -Wl,-T,$LD_SCRIPT32,--gc-sections \ + $BUILD_DIR/boot.o32 \ + $BOOTST_OBJ_DIR/boot_idt.o32 \ + $BOOTST_OBJ_DIR/boot_cpu.o32 \ + $BOOTST_OBJ_DIR/boot_kernel.o32 \ + $BOOTST_OBJ_DIR/load_elf.o32 \ + $BOOTST_OBJ_DIR/minilibc_support.o32 \ + $BOOTST_OBJ_DIR/bootstrap32.bin \ + $LD_SCRIPT32 \ + $SNAP_DIR/obj/l4/amd64/pkg/bootstrap/server/src/ARCH-amd64/libc32/OBJ-amd64_K8/libc32.a \ + -lgcc + +chmod 755 $BUILD_DIR/bootstrap32.elf + +objdump -D $BUILD_DIR/bootstrap32.elf > disasms/bootstrap32.elf.s +objcopy -O binary $BUILD_DIR/bootstrap32.elf $BUILD_DIR/bootstrap32-jh.bin +cp $BUILD_DIR/bootstrap32-jh-bin ../buildroot-overlay/jailhouse/bootstrap32-jh.bin +echo done!