From f8536c88779e75a20253358b54661b01a861881f Mon Sep 17 00:00:00 2001 From: Maxim Baryshnikov Date: Tue, 22 Mar 2016 03:08:38 +0100 Subject: [PATCH] fiasco: bootstrap: some other tries to link it all together. --- bootstrap-relink/all-linked-try.ld | 61 +++++++++++++ bootstrap-relink/header-32-inmate.S | 127 ++++++++++++++++++++++++++++ bootstrap-relink/link_objects.sh | 19 ++++- 3 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 bootstrap-relink/all-linked-try.ld create mode 100644 bootstrap-relink/header-32-inmate.S diff --git a/bootstrap-relink/all-linked-try.ld b/bootstrap-relink/all-linked-try.ld new file mode 100644 index 0000000..8a1e8a8 --- /dev/null +++ b/bootstrap-relink/all-linked-try.ld @@ -0,0 +1,61 @@ +SECTIONS +{ + . = 0; + .startup : { *(.startup) } + + . = 0xfff0; + .boot : { + *(.boot) + . = ALIGN(16); + } + + . = 0xe0000; + + _image_start = .; + + stack_top = .; + bss_start = .; + + .bss : { + *(.bss .bss.*) + /*COMMON may intersect with something from header-32.S*/ + *(COMMON) + . = ALIGN(8); + } + + bss_dwords = SIZEOF(.bss) / 4; + bss_qwords = SIZEOF(.bss) / 8; + + . = 0xf0000 + SIZEOF(.startup); + .text : AT (ADDR(.text) & 0xffff) { + *(.text .text.*) + } + + . = ALIGN(16); + .rodata : AT (ADDR(.rodata) & 0xffff) { + *(.rodata .rodata.*) + } + + . = ALIGN(16); + .data : AT (ADDR(.data) & 0xffff) { + *(.data .data.*) + + } + _image_end = .; + + .sixtyfour 0x2d0000 : + { + . = . + 500000; + } + + /DISCARD/ : { + *(.note.gnu.build-id) + *(.interp) + *(.comment) + *(.note) + *(.eh_frame) + } +} +ENTRY(_reset_entry) + + diff --git a/bootstrap-relink/header-32-inmate.S b/bootstrap-relink/header-32-inmate.S new file mode 100644 index 0000000..054ac70 --- /dev/null +++ b/bootstrap-relink/header-32-inmate.S @@ -0,0 +1,127 @@ +#include + +#define X86_CR0_PE 0x00000001 +#define X86_CR0_WP 0x00010000 +#define X86_CR0_PG 0x80000000 + +#define X86_CR4_PSE 0x00000010 + +#define MSR_MTRR_DEF_TYPE 0x000002ff +#define MTRR_ENABLE 0x00000800 + + .code16 + .section ".boot", "ax" + + .globl __reset_entry + .extern _start +__reset_entry: + ljmp $0xf000,$start16 + + + .section ".startup", "ax" + +start16: + lgdtl %cs:gdt_ptr + + mov %cr0,%eax + or $X86_CR0_PE,%al + mov %eax,%cr0 + + ljmpl $INMATE_CS32,$start32 + FSEGMENT_BASE + + + .code32 +start32: + mov %cr4,%eax + or $X86_CR4_PSE,%eax + mov %eax,%cr4 + + mov $loader_pdpt + FSEGMENT_BASE,%eax + mov %eax,%cr3 + + mov $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE),%eax + mov %eax,%cr0 + + movl $MSR_MTRR_DEF_TYPE,%ecx + rdmsr + or $MTRR_ENABLE,%eax + wrmsr + + mov $INMATE_DS32,%eax + mov %eax,%ds + mov %eax,%es + mov %eax,%ss + + xor %ebx,%ebx + xchg ap_entry,%ebx + or %ebx,%ebx + jnz call_entry + + mov $1,%edi + lock xadd %edi,cpu_number + FSEGMENT_BASE + + cmp $SMP_MAX_CPUS,%edi + jae stop + + mov $0x01,%eax + cpuid + shr $24,%ebx + mov %bl,smp_cpu_ids(%edi) + + lock incl smp_num_cpus + + cmp $0,%edi + jne stop + + xor %eax,%eax + mov $bss_start,%edi + mov $bss_dwords,%ecx + rep stosl + + mov $_start,%ebx + +call_entry: + mov $stack_top,%esp + call *%ebx + +stop: cli + hlt + jmp stop + + + .pushsection ".data" + + .globl ap_entry +ap_entry: + .long 0 + + .globl smp_num_cpus +smp_num_cpus: + .long 0 + + .globl smp_cpu_ids +smp_cpu_ids: + .fill SMP_MAX_CPUS, 1, 0 + + .popsection + +cpu_number: + .long 0 + + .align(16) + .global loader_gdt +loader_gdt: + .quad 0 + .quad 0x00cf9b000000ffff + .quad 0x00af9b000000ffff + .quad 0x00cf93000000ffff + +gdt_ptr: + .short gdt_ptr - loader_gdt - 1 + .long loader_gdt + FSEGMENT_BASE + + .align(4096) + .global loader_pdpt +loader_pdpt: + .long 0x00000083 + .align(4096) \ No newline at end of file diff --git a/bootstrap-relink/link_objects.sh b/bootstrap-relink/link_objects.sh index 7456e8d..7bc23b4 100755 --- a/bootstrap-relink/link_objects.sh +++ b/bootstrap-relink/link_objects.sh @@ -1,7 +1,7 @@ #!/bin/bash BUILD_DIR=$PWD/build #LD_SCRIPT64=$PWD/bootstrap.ld -LD_SCRIPT32=$PWD/bootstrap32.ld +LD_SCRIPT32=$PWD/all-linked-try.ld SNAP_DIR=$1 set -e; @@ -56,6 +56,22 @@ BOOTST_OBJ_DIR=$SNAP_DIR/obj/l4/amd64/pkg/bootstrap/server/src/OBJ-amd64_K8 # 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 +cd ../ +JAIL_DIR=$PWD/jailhouse/inmates +cd $START_DIR +echo "[inmate-header] Compiling..." + gcc-4.8 -Wp,-MD,$BUILD_DIR/.header-32.o.d -nostdinc \ + -isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/include \ + -D__KERNEL__ -D__ASSEMBLY__ -m64 -DCONFIG_X86_X32_ABI \ + -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 \ + -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 \ + -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 \ + -Wa,-gdwarf-2 -mfentry -DCC_USING_FENTRY \ + -I$JAIL_DIR/lib/x86 \ + -I$JAIL_DIR/../hypervisor/arch/x86/include \ + -I$JAIL_DIR../hypervisor/include -m32 \ + -c -o $BUILD_DIR/header-32-inmate.o \ + ./header-32-inmate.S echo "[boot.S] Compiling the header of image.." gcc -m32 -o $BUILD_DIR/boot.o32 -c \ @@ -98,6 +114,7 @@ gcc -m32 -o $BUILD_DIR/bootstrap32.elf -nostdlib -static \ $BOOTST_OBJ_DIR/load_elf.o32 \ $BOOTST_OBJ_DIR/minilibc_support.o32 \ $BOOTST_OBJ_DIR/bootstrap32.bin \ + $BUILD_DIR/header-32-inmate.o\ $LD_SCRIPT32 \ $SNAP_DIR/obj/l4/amd64/pkg/bootstrap/server/src/ARCH-amd64/libc32/OBJ-amd64_K8/libc32.a \ -lgcc -- 2.39.2