From 9f66052c11e4a277d4427c296d0b444f41d86ba4 Mon Sep 17 00:00:00 2001 From: kraemmax Date: Fri, 21 Aug 2020 07:06:10 -0400 Subject: [PATCH 1/8] renaming .init with .bootlower --- kernel/boot/kernel-amd64-ihk/boot/start.S | 2 +- kernel/boot/kernel-amd64-knc/boot/boot.ld | 4 ++-- kernel/boot/kernel-amd64-knc/boot/start.S | 2 +- kernel/boot/kernel-amd64-pc/boot/boot.ld | 8 ++++---- kernel/boot/kernel-amd64-pc/boot/start.S | 2 +- kernel/build/gcc-host-pc/util/compiler.hh | 2 +- kernel/runtime/crt-init/runtime/crtend.S | 2 +- kernel/runtime/crt-init/runtime/start.S | 8 ++++---- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/kernel/boot/kernel-amd64-ihk/boot/start.S b/kernel/boot/kernel-amd64-ihk/boot/start.S index f05ca38c..020828e4 100644 --- a/kernel/boot/kernel-amd64-ihk/boot/start.S +++ b/kernel/boot/kernel-amd64-ihk/boot/start.S @@ -31,7 +31,7 @@ .extern entry_bsp .extern entry_ap -.section .init, "awx" // the following code and data is in the low memory init section +.section .bootlower, "awx" // the following code and data is in the low memory init section // EFER bit 0: SYSCALL instruction enable // EFER bit 8: IA-32e mode enable diff --git a/kernel/boot/kernel-amd64-knc/boot/boot.ld b/kernel/boot/kernel-amd64-knc/boot/boot.ld index e997aa06..f78be214 100644 --- a/kernel/boot/kernel-amd64-knc/boot/boot.ld +++ b/kernel/boot/kernel-amd64-knc/boot/boot.ld @@ -49,8 +49,8 @@ SECTIONS /* load the boot code at VMA=LMA LOAD_ADDR */ .init LOAD_ADDR : AT(LOAD_ADDR) { - KEEP(*(.init)) - } : init /* put into init segment */ + KEEP(*(.bootlower)) + } : bootlower /* put into init segment */ PROVIDE (LOAD_END = .); /* the begin of the upper half code and data in physical memory */ diff --git a/kernel/boot/kernel-amd64-knc/boot/start.S b/kernel/boot/kernel-amd64-knc/boot/start.S index d22ab0ee..9b812234 100644 --- a/kernel/boot/kernel-amd64-knc/boot/start.S +++ b/kernel/boot/kernel-amd64-knc/boot/start.S @@ -31,7 +31,7 @@ .extern entry_bsp .extern entry_ap -.section .init, "awx" // the following code and data is in the low memory init section +.section .bootlower, "awx" // the following code and data is in the low memory init section // EFER bit 0: SYSCALL instruction enable // EFER bit 8: IA-32e mode enable diff --git a/kernel/boot/kernel-amd64-pc/boot/boot.ld b/kernel/boot/kernel-amd64-pc/boot/boot.ld index e997aa06..c4bc576a 100644 --- a/kernel/boot/kernel-amd64-pc/boot/boot.ld +++ b/kernel/boot/kernel-amd64-pc/boot/boot.ld @@ -38,7 +38,7 @@ ENTRY(_start_bsp) */ PHDRS { - init PT_LOAD; + bootlower PT_LOAD; kern PT_LOAD; data PT_LOAD; } @@ -47,10 +47,10 @@ SECTIONS { /* LOAD_ADDR is begin of the init code and data */ /* load the boot code at VMA=LMA LOAD_ADDR */ - .init LOAD_ADDR : AT(LOAD_ADDR) + .bootlower LOAD_ADDR : AT(LOAD_ADDR) { - KEEP(*(.init)) - } : init /* put into init segment */ + KEEP(*(.bootlower)) + } : bootlower /* put into init segment */ PROVIDE (LOAD_END = .); /* the begin of the upper half code and data in physical memory */ diff --git a/kernel/boot/kernel-amd64-pc/boot/start.S b/kernel/boot/kernel-amd64-pc/boot/start.S index 01a5f3ab..4224a04f 100644 --- a/kernel/boot/kernel-amd64-pc/boot/start.S +++ b/kernel/boot/kernel-amd64-pc/boot/start.S @@ -31,7 +31,7 @@ .extern entry_bsp .extern entry_ap -.section .init, "awx" // the following code and data is in the low memory init section +.section .bootlower, "awx" // the following code and data is in the low memory init section // EFER bit 0: SYSCALL instruction enable // EFER bit 8: IA-32e mode enable diff --git a/kernel/build/gcc-host-pc/util/compiler.hh b/kernel/build/gcc-host-pc/util/compiler.hh index 6afca3e4..e3d17ea8 100644 --- a/kernel/build/gcc-host-pc/util/compiler.hh +++ b/kernel/build/gcc-host-pc/util/compiler.hh @@ -30,7 +30,7 @@ #define ALIGNED(X) alignas(X) #define ALIGN_4K alignas(4096) #define ALWAYS_INLINE __attribute__((always_inline)) -#define INIT __attribute__((section (".init"))) +#define INIT __attribute__((section (".bootlower"))) #define INITDATA __attribute__((section (".initdata"))) #define NORETURN [[noreturn]] //__attribute__((noreturn)) diff --git a/kernel/runtime/crt-init/runtime/crtend.S b/kernel/runtime/crt-init/runtime/crtend.S index 7f19539b..b803441d 100644 --- a/kernel/runtime/crt-init/runtime/crtend.S +++ b/kernel/runtime/crt-init/runtime/crtend.S @@ -24,7 +24,7 @@ * Copyright 2016 Randolf Rotta, Robert Kuban, and contributors, BTU Cottbus-Senftenberg */ -.section .init +.section .bootlower pop %rbp ret diff --git a/kernel/runtime/crt-init/runtime/start.S b/kernel/runtime/crt-init/runtime/start.S index d2a26107..111895bf 100644 --- a/kernel/runtime/crt-init/runtime/start.S +++ b/kernel/runtime/crt-init/runtime/start.S @@ -53,10 +53,10 @@ __dso_handle: .skip 8 .hidden __dso_handle -.section .init -.global _init -.type _init,@function -_init: +.section .bootlower +.global _bootlower +.type _bootlower,@function +_bootlower: push %rbp mov %rsp, %rbp From 6dea94648f222282aed2ba15def74b8a493ea889 Mon Sep 17 00:00:00 2001 From: Randolf Rotta Date: Wed, 7 Oct 2020 21:29:24 +0200 Subject: [PATCH 2/8] removed unused preprocessor macros --- kernel/build/gcc-host-pc/util/compiler.hh | 2 -- kernel/build/gcc-kernel-knc/util/compiler.hh | 2 -- kernel/build/gcc-kernel-pc/util/compiler.hh | 2 -- 3 files changed, 6 deletions(-) diff --git a/kernel/build/gcc-host-pc/util/compiler.hh b/kernel/build/gcc-host-pc/util/compiler.hh index e3d17ea8..d79cc467 100644 --- a/kernel/build/gcc-host-pc/util/compiler.hh +++ b/kernel/build/gcc-host-pc/util/compiler.hh @@ -30,8 +30,6 @@ #define ALIGNED(X) alignas(X) #define ALIGN_4K alignas(4096) #define ALWAYS_INLINE __attribute__((always_inline)) -#define INIT __attribute__((section (".bootlower"))) -#define INITDATA __attribute__((section (".initdata"))) #define NORETURN [[noreturn]] //__attribute__((noreturn)) #define NOINLINE __attribute__((noinline)) diff --git a/kernel/build/gcc-kernel-knc/util/compiler.hh b/kernel/build/gcc-kernel-knc/util/compiler.hh index 4dfbce92..8b4200a0 100644 --- a/kernel/build/gcc-kernel-knc/util/compiler.hh +++ b/kernel/build/gcc-kernel-knc/util/compiler.hh @@ -30,8 +30,6 @@ #define ALIGNED(X) alignas(X) #define ALIGN_4K alignas(4096) #define ALWAYS_INLINE __attribute__((always_inline)) -// #define INIT __attribute__((section (".init"))) -// #define INITDATA __attribute__((section (".initdata"))) #define NORETURN [[noreturn]] //__attribute__((noreturn)) #define NOINLINE __attribute__((noinline)) diff --git a/kernel/build/gcc-kernel-pc/util/compiler.hh b/kernel/build/gcc-kernel-pc/util/compiler.hh index 4dfbce92..8b4200a0 100644 --- a/kernel/build/gcc-kernel-pc/util/compiler.hh +++ b/kernel/build/gcc-kernel-pc/util/compiler.hh @@ -30,8 +30,6 @@ #define ALIGNED(X) alignas(X) #define ALIGN_4K alignas(4096) #define ALWAYS_INLINE __attribute__((always_inline)) -// #define INIT __attribute__((section (".init"))) -// #define INITDATA __attribute__((section (".initdata"))) #define NORETURN [[noreturn]] //__attribute__((noreturn)) #define NOINLINE __attribute__((noinline)) From 5e4e2ab110b896355d2f89d6f827371ee025b113 Mon Sep 17 00:00:00 2001 From: Randolf Rotta Date: Wed, 7 Oct 2020 21:36:51 +0200 Subject: [PATCH 3/8] updated comment for init to bootlower change --- kernel/boot/kernel-amd64-pc/boot/boot.ld | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/boot/kernel-amd64-pc/boot/boot.ld b/kernel/boot/kernel-amd64-pc/boot/boot.ld index c4bc576a..940a8038 100644 --- a/kernel/boot/kernel-amd64-pc/boot/boot.ld +++ b/kernel/boot/kernel-amd64-pc/boot/boot.ld @@ -45,12 +45,12 @@ PHDRS SECTIONS { - /* LOAD_ADDR is begin of the init code and data */ + /* LOAD_ADDR is begin of the lower half boot code and data */ /* load the boot code at VMA=LMA LOAD_ADDR */ .bootlower LOAD_ADDR : AT(LOAD_ADDR) { KEEP(*(.bootlower)) - } : bootlower /* put into init segment */ + } : bootlower /* put into boot segment */ PROVIDE (LOAD_END = .); /* the begin of the upper half code and data in physical memory */ From f42cdf67909c62086789ad2dfd5fd8d4e62983ff Mon Sep 17 00:00:00 2001 From: Randolf Rotta Date: Wed, 7 Oct 2020 21:57:56 +0200 Subject: [PATCH 4/8] reverted accidential renaming of init section in user space --- kernel/runtime/crt-init/runtime/crtend.S | 2 +- kernel/runtime/crt-init/runtime/start.S | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/kernel/runtime/crt-init/runtime/crtend.S b/kernel/runtime/crt-init/runtime/crtend.S index b803441d..7f19539b 100644 --- a/kernel/runtime/crt-init/runtime/crtend.S +++ b/kernel/runtime/crt-init/runtime/crtend.S @@ -24,7 +24,7 @@ * Copyright 2016 Randolf Rotta, Robert Kuban, and contributors, BTU Cottbus-Senftenberg */ -.section .bootlower +.section .init pop %rbp ret diff --git a/kernel/runtime/crt-init/runtime/start.S b/kernel/runtime/crt-init/runtime/start.S index 7c1627e2..712e1fd7 100644 --- a/kernel/runtime/crt-init/runtime/start.S +++ b/kernel/runtime/crt-init/runtime/start.S @@ -35,13 +35,9 @@ _start: mov initstack_top, %rsp xor %rbp, %rbp - mov %rdi, msg_ptr // store first argument to global variable -/* fninit // initialize the FPU - call __libc_init_array*/ + mov %rdi, msg_ptr /* store first argument to global variable */ call start_c -/* mov $0, %rdi - call exit -1: jmp 1b*/ +1: jmp 1b /* should never return from start_c anyway */ /* A handle for __cxa_finalize to manage c++ local destructors. */ .global __dso_handle From ce0961ba5c489b1624403535c9ed1832d815b4a9 Mon Sep 17 00:00:00 2001 From: Randolf Rotta Date: Thu, 8 Oct 2020 12:49:59 +0200 Subject: [PATCH 5/8] init segment vs sections cleanup --- kernel/boot/kernel-amd64-ihk/boot/start.S | 121 ---------------------- kernel/boot/kernel-amd64-knc/boot/boot.ld | 4 +- kernel/boot/kernel-amd64-pc/boot/boot.ld | 4 +- 3 files changed, 4 insertions(+), 125 deletions(-) diff --git a/kernel/boot/kernel-amd64-ihk/boot/start.S b/kernel/boot/kernel-amd64-ihk/boot/start.S index 020828e4..2f229d75 100644 --- a/kernel/boot/kernel-amd64-ihk/boot/start.S +++ b/kernel/boot/kernel-amd64-ihk/boot/start.S @@ -31,8 +31,6 @@ .extern entry_bsp .extern entry_ap -.section .bootlower, "awx" // the following code and data is in the low memory init section - // EFER bit 0: SYSCALL instruction enable // EFER bit 8: IA-32e mode enable // EFER bit 11: enable noexecute bit in page tables @@ -64,125 +62,6 @@ #define CR4_MASK 0xFFFFFFFF #define CR4_ENABLE 0x00000020 -/** magic number for the Multiboot header. */ -#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 - -/** multiboot flags towards the bootloader. - * - * https://www.gnu.org/software/grub/manual/multiboot/multiboot.html - * If bit 0 in the ‘flags’ word is set, then all boot modules loaded along with the operating system must be aligned on page (4KB) boundaries. - * If bit 1 in the ‘flags’ word is set, then information on available memory via at least the ‘mem_*’ fields of the Multiboot information structure must be included. If the boot loader is capable of passing a memory map (the ‘mmap_*’ fields) and one exists, then it may be included as well. - * If bit 2 in the ‘flags’ word is set, information about the video mode table must be available to the kernel. - * If bit 16 in the ‘flags’ word is set, then the fields at offsets 12-28 in the Multiboot header are valid, and the boot loader should use them instead of the fields in the actual executable header to calculate where to load the OS image. This information does not need to be provided if the kernel image is in elf format. - */ -#define MULTIBOOT_HEADER_FLAGS 0x00000000 - -.align 4 -/** multiboot header: just magic, flags and checksum without the optional fields */ -/*_mboot_header: - .long MULTIBOOT_HEADER_MAGIC - .long MULTIBOOT_HEADER_FLAGS - .long -(MULTIBOOT_HEADER_MAGIC+MULTIBOOT_HEADER_FLAGS)*/ - -/** Global Descriptor Table (GDT) during boot. - * see 3.4.5.1 Code- and Data-Segment Descriptor Types in Intel 253668-048US. - * granularity 0xa0 = 10100000b => limit granularity 4kb, operand size unset, 64bit mode - * access 0x9b = 10011011b => present, ring0, code/data, Execute/Read accessed - * 0011 read/write accessed - * 1001 execute only accessed - * 1011 execute/read accessed - * access 0xfb = 11111011 => present, ring3, code/data, Execute/Read accessed - * limit can be 0 because it is not used in 64bit mode - */ -.align 8 -.global _boot_gdt_start -_boot_gdt_start: - .quad 0x0000000000000000 // null descriptor - .quad 0x0000000000000000 // 0x08 unused - .quad 0x00a09b000000ffff // 0x10 kernel code - .quad 0x00a093000000ffff // 0x18 kernel data -_boot_gdt_end: - .word 0 // padding to align ... -_boot_gdt: - .word _boot_gdt_end - _boot_gdt_start - 1 // limit: length of the GDT - .quad _boot_gdt_start // base - -/*.align 8 -.global _mboot_table -_mboot_table: .quad 0 -.global _mboot_magic -_mboot_magic: .quad 0*/ - -/* just for testing */ -//.global _host_info_ptr -//_host_info_ptr: .quad 0 - -/* start code for the bootstrap processor BSP, i.e. the first core */ -/*.code32 -.align 8 -.global _start_bsp -.type _start_bsp, @function -_start_bsp: - // eax and ebx contains the multiboot magic and table pointer, - // lets store this for later. - mov %eax, _mboot_magic - mov %ebx, _mboot_table - - // activate the initial page table - mov $(EFER_MSR), %ecx // select the EFER MSR - rdmsr // read EFER - and $(EFER_MASK), %eax - or $(EFER_ENABLE), %eax - wrmsr // write EFER - mov %cr4, %edx - and $(CR4_MASK), %edx - or $(CR4_ENABLE), %edx - mov %edx, %cr4 - mov $(BOOT_PML4-VIRT_ADDR), %edx // pointer to the Page Directory - mov %edx, %cr3 - mov %cr0, %edx - and $(CR0_MASK), %edx - or $(CR0_ENABLE), %edx - mov %edx, %cr0 // switch to protected mode, with paging enabled and write protect - - // load our own segment descriptor table - lgdt _boot_gdt - ljmp $0x10, $_start_bsp64 // switch CS to 64bit mode -*/ -.code64 -.align 8 -.global _start_bsp64_pregdt -.type _start_bsp64_pregdt, @function -_start_bsp64_pregdt: - mov $(BOOT_STACK+BOOT_STACK_SIZE), %rsp // set up boot kernel stack - // load our own segment descriptor table, see above in this file - // the segments 0x10 and 0x18 match the final GDT of the kernel - lgdt _boot_gdt - // switch code segment to 0x10 instead of leftovers from the loader - // create a stack frame like from a far call and return - push $0x10 // KERNEL_CS - push $_start_bsp64 - retfq - -_start_bsp64: - mov $0x18, %cx // kernel data selector - mov %cx, %ss - mov %cx, %ds - mov %cx, %es - mov %cx, %fs - mov %cx, %gs - cld // for gcc code - - mov $(EFER_MSR), %ecx // select the EFER MSR - rdmsr // read EFER - and $(EFER_MASK), %eax - or $(EFER_ENABLE), %eax - wrmsr // write EFER - - // go to the stage 3 boot code, and never come back - xor %rbp, %rbp - pushq $0 // fake return address as first stack frame - jmp entry_bsp .section .text diff --git a/kernel/boot/kernel-amd64-knc/boot/boot.ld b/kernel/boot/kernel-amd64-knc/boot/boot.ld index f78be214..cd1fdd3e 100644 --- a/kernel/boot/kernel-amd64-knc/boot/boot.ld +++ b/kernel/boot/kernel-amd64-knc/boot/boot.ld @@ -47,10 +47,10 @@ SECTIONS { /* LOAD_ADDR is begin of the init code and data */ /* load the boot code at VMA=LMA LOAD_ADDR */ - .init LOAD_ADDR : AT(LOAD_ADDR) + .bootlower LOAD_ADDR : AT(LOAD_ADDR) { KEEP(*(.bootlower)) - } : bootlower /* put into init segment */ + } : init /* put into init segment */ PROVIDE (LOAD_END = .); /* the begin of the upper half code and data in physical memory */ diff --git a/kernel/boot/kernel-amd64-pc/boot/boot.ld b/kernel/boot/kernel-amd64-pc/boot/boot.ld index 940a8038..26687ebe 100644 --- a/kernel/boot/kernel-amd64-pc/boot/boot.ld +++ b/kernel/boot/kernel-amd64-pc/boot/boot.ld @@ -38,7 +38,7 @@ ENTRY(_start_bsp) */ PHDRS { - bootlower PT_LOAD; + init PT_LOAD; kern PT_LOAD; data PT_LOAD; } @@ -50,7 +50,7 @@ SECTIONS .bootlower LOAD_ADDR : AT(LOAD_ADDR) { KEEP(*(.bootlower)) - } : bootlower /* put into boot segment */ + } : init /* put into init segment */ PROVIDE (LOAD_END = .); /* the begin of the upper half code and data in physical memory */ From b5233b94751f8071162ea9eb0d1027c8009dadf3 Mon Sep 17 00:00:00 2001 From: Randolf Rotta Date: Thu, 8 Oct 2020 14:23:19 +0200 Subject: [PATCH 6/8] added bsp trampoline for GDT setup back again --- kernel/boot/kernel-amd64-ihk/boot/start.S | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/kernel/boot/kernel-amd64-ihk/boot/start.S b/kernel/boot/kernel-amd64-ihk/boot/start.S index 2f229d75..8da232a1 100644 --- a/kernel/boot/kernel-amd64-ihk/boot/start.S +++ b/kernel/boot/kernel-amd64-ihk/boot/start.S @@ -62,9 +62,62 @@ #define CR4_MASK 0xFFFFFFFF #define CR4_ENABLE 0x00000020 +.section .rodata + +.align 8 +//.global _boot_gdt_start +_boot_gdt_start: + .quad 0x0000000000000000 // null descriptor + .quad 0x0000000000000000 // 0x08 unused + .quad 0x00a09b000000ffff // 0x10 kernel code + .quad 0x00a093000000ffff // 0x18 kernel data +_boot_gdt_end: + .word 0 // padding to align ... +_boot_gdt: + .word _boot_gdt_end - _boot_gdt_start - 1 // limit: length of the GDT + .quad _boot_gdt_start // base + .section .text +/** \f _start_bsp64_pregdt is called from ihk-entry.cc */ +.code64 +.align 8 +.global _start_bsp64_pregdt +.type _start_bsp64_pregdt, @function +_start_bsp64_pregdt: + mov $(BOOT_STACK+BOOT_STACK_SIZE), %rsp // set up boot kernel stack + // load our own segment descriptor table, see above in this file + // the segments 0x10 and 0x18 match the final GDT of the kernel + lgdt _boot_gdt + // switch code segment to 0x10 instead of leftovers from the loader + // create a stack frame like from a far call and return + push $0x10 // KERNEL_CS + push $_start_bsp64 + retfq + +_start_bsp64: + mov $0x18, %cx // kernel data selector + mov %cx, %ss + mov %cx, %ds + 2mov %cx, %es + mov %cx, %fs + mov %cx, %gs + cld // for gcc code + + mov $(EFER_MSR), %ecx // select the EFER MSR + rdmsr // read EFER + and $(EFER_MASK), %eax + or $(EFER_ENABLE), %eax + wrmsr // write EFER + + // go to the stage 3 boot code, and never come back + xor %rbp, %rbp + pushq $0 // fake return address as first stack frame + jmp entry_bsp + + + .code16 .align 8 .global _dbg_trampoline From 98c21de2f93576b6e0bfa286a7541960b90955ef Mon Sep 17 00:00:00 2001 From: rottaran Date: Thu, 8 Oct 2020 16:26:09 +0200 Subject: [PATCH 7/8] removed typo, changed to .balign for consistency --- kernel/boot/kernel-amd64-ihk/boot/start.S | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/kernel/boot/kernel-amd64-ihk/boot/start.S b/kernel/boot/kernel-amd64-ihk/boot/start.S index 8da232a1..c8be0dca 100644 --- a/kernel/boot/kernel-amd64-ihk/boot/start.S +++ b/kernel/boot/kernel-amd64-ihk/boot/start.S @@ -64,7 +64,7 @@ .section .rodata -.align 8 +.balign 8 //.global _boot_gdt_start _boot_gdt_start: .quad 0x0000000000000000 // null descriptor @@ -82,7 +82,7 @@ _boot_gdt: /** \f _start_bsp64_pregdt is called from ihk-entry.cc */ .code64 -.align 8 +.balign 8 .global _start_bsp64_pregdt .type _start_bsp64_pregdt, @function _start_bsp64_pregdt: @@ -100,7 +100,7 @@ _start_bsp64: mov $0x18, %cx // kernel data selector mov %cx, %ss mov %cx, %ds - 2mov %cx, %es + mov %cx, %es mov %cx, %fs mov %cx, %gs cld // for gcc code @@ -119,12 +119,12 @@ _start_bsp64: .code16 -.align 8 +.balign 8 .global _dbg_trampoline base = . _dbg_trampoline: -.align 8 +.balign 8 jmp _dbg_trampoline_code .org 8 @@ -138,7 +138,7 @@ _dbg_startap: .quad 0x0 dbg_ljmp32: // overwritten in (II) - .long dbg_32prot - base + .long dbg_32prot - base .word 0x20 boot_gdtptr: @@ -199,13 +199,13 @@ test: ljmpl *(dbg_ljmp32 - base) -.align 4 +.balign 4 boot_idtptr: .short 0 .long 0 - .align 4 + .balign 4 boot_gdt32: .quad 0 .quad 0 @@ -283,7 +283,7 @@ _dbg_trampoline_end: .code64 -.align 8 +.balign 8 .global _start_ap64_pregdt .type _start_ap64_pregdt, @function From 6e11dfbae4558a040e766a89fd292e1df5443ab2 Mon Sep 17 00:00:00 2001 From: Philipp Gypser Date: Tue, 13 Oct 2020 11:21:52 +0200 Subject: [PATCH 8/8] moved some code in start.S for IHK --- kernel/boot/kernel-amd64-ihk/boot/start.S | 70 +++++++++++------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/kernel/boot/kernel-amd64-ihk/boot/start.S b/kernel/boot/kernel-amd64-ihk/boot/start.S index c8be0dca..14acc66d 100644 --- a/kernel/boot/kernel-amd64-ihk/boot/start.S +++ b/kernel/boot/kernel-amd64-ihk/boot/start.S @@ -80,41 +80,6 @@ _boot_gdt: .section .text -/** \f _start_bsp64_pregdt is called from ihk-entry.cc */ -.code64 -.balign 8 -.global _start_bsp64_pregdt -.type _start_bsp64_pregdt, @function -_start_bsp64_pregdt: - mov $(BOOT_STACK+BOOT_STACK_SIZE), %rsp // set up boot kernel stack - // load our own segment descriptor table, see above in this file - // the segments 0x10 and 0x18 match the final GDT of the kernel - lgdt _boot_gdt - // switch code segment to 0x10 instead of leftovers from the loader - // create a stack frame like from a far call and return - push $0x10 // KERNEL_CS - push $_start_bsp64 - retfq - -_start_bsp64: - mov $0x18, %cx // kernel data selector - mov %cx, %ss - mov %cx, %ds - mov %cx, %es - mov %cx, %fs - mov %cx, %gs - cld // for gcc code - - mov $(EFER_MSR), %ecx // select the EFER MSR - rdmsr // read EFER - and $(EFER_MASK), %eax - or $(EFER_ENABLE), %eax - wrmsr // write EFER - - // go to the stage 3 boot code, and never come back - xor %rbp, %rbp - pushq $0 // fake return address as first stack frame - jmp entry_bsp @@ -281,6 +246,41 @@ dbg_loop: .global _dbg_trampoline_end _dbg_trampoline_end: +/** \f _start_bsp64_pregdt is called from ihk-entry.cc */ +.code64 +.balign 8 +.global _start_bsp64_pregdt +.type _start_bsp64_pregdt, @function +_start_bsp64_pregdt: + mov $(BOOT_STACK+BOOT_STACK_SIZE), %rsp // set up boot kernel stack + // load our own segment descriptor table, see above in this file + // the segments 0x10 and 0x18 match the final GDT of the kernel + lgdt _boot_gdt + // switch code segment to 0x10 instead of leftovers from the loader + // create a stack frame like from a far call and return + push $0x10 // KERNEL_CS + push $_start_bsp64 + retfq + +_start_bsp64: + mov $0x18, %cx // kernel data selector + mov %cx, %ss + mov %cx, %ds + mov %cx, %es + mov %cx, %fs + mov %cx, %gs + cld // for gcc code + + mov $(EFER_MSR), %ecx // select the EFER MSR + rdmsr // read EFER + and $(EFER_MASK), %eax + or $(EFER_ENABLE), %eax + wrmsr // write EFER + + // go to the stage 3 boot code, and never come back + xor %rbp, %rbp + pushq $0 // fake return address as first stack frame + jmp entry_bsp .code64 .balign 8