--- /dev/null
+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)
+
+
--- /dev/null
+#include <inmate.h>
+
+#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
#!/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;
# 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 \
$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