Early startup code is equivalent for both, 32 and 64 bit, so let's consolidate them.
This patch introduces an empty start32 hook that is empty at the moment. Later, we will use it to enable SSE, which, again, will be the same code for 32 and 64 bit. There's only one drawback: We need __reset_entry at 0x0, but it's now up to the linker's mood which files it places there first. Enforce to linker to always place __reset_entry to 0x0 by introducing the subsection .boot.reset_entry. Additionally, tweak the Makefile a bit. Signed-off-by: Ralf Ramsauer <[email protected]> --- inmates/lib/x86/Makefile | 7 +++-- inmates/lib/x86/header-32.S | 17 ++-------- inmates/lib/x86/header-64.S | 17 ++-------- inmates/lib/x86/header-common.S | 56 +++++++++++++++++++++++++++++++++ inmates/lib/x86/inmate.lds | 5 ++- 5 files changed, 71 insertions(+), 31 deletions(-) create mode 100644 inmates/lib/x86/header-common.S diff --git a/inmates/lib/x86/Makefile b/inmates/lib/x86/Makefile index f54160de..6a47132a 100644 --- a/inmates/lib/x86/Makefile +++ b/inmates/lib/x86/Makefile @@ -40,7 +40,7 @@ include $(INMATES_LIB)/Makefile.lib always := lib.a lib32.a -TARGETS := excp.o int.o ioapic.o printk.o setup.o uart.o +TARGETS := excp.o header-common.o int.o ioapic.o printk.o setup.o uart.o TARGETS += ../alloc.o ../pci.o ../string.o ../cmdline.o ../setup.o TARGETS += ../uart-8250.o ../printk.o TARGETS_32_ONLY := header-32.o @@ -57,7 +57,10 @@ $(obj)/lib32.a: $(addprefix $(obj)/,$(lib32-y)) targets += header-32.o -$(obj)/%-32.o: a_flags += -m32 $(obj)/%-32.o: c_flags += -m32 $(obj)/%-32.o: $(src)/%.c $(call if_changed_rule,cc_o_c) + +$(obj)/%-32.o: a_flags += -m32 +$(obj)/%-32.o: $(src)/%.S + $(call if_changed_rule,as_o_S) diff --git a/inmates/lib/x86/header-32.S b/inmates/lib/x86/header-32.S index a0f2d878..50001b22 100644 --- a/inmates/lib/x86/header-32.S +++ b/inmates/lib/x86/header-32.S @@ -39,21 +39,9 @@ #include <inmate.h> #include <asm/regs.h> - .code16 - .section ".boot", "ax" - - .globl __reset_entry -__reset_entry: - lgdtl %cs:gdt_ptr - - mov %cr0,%eax - or $X86_CR0_PE,%al - mov %eax,%cr0 - - ljmpl $INMATE_CS32,$start32 - - .code32 + .section ".boot", "ax" + .globl start32 start32: mov %cr4,%eax or $X86_CR4_PSE,%eax @@ -140,6 +128,7 @@ loader_gdt: .quad 0x00af9b000000ffff .quad 0x00cf93000000ffff + .globl gdt_ptr gdt_ptr: .short gdt_ptr - loader_gdt - 1 .long loader_gdt diff --git a/inmates/lib/x86/header-64.S b/inmates/lib/x86/header-64.S index 978decb3..8e49d326 100644 --- a/inmates/lib/x86/header-64.S +++ b/inmates/lib/x86/header-64.S @@ -39,21 +39,9 @@ #include <inmate.h> #include <asm/regs.h> - .code16 - .section ".boot", "ax" - - .globl __reset_entry -__reset_entry: - lgdtl %cs:gdt_ptr - - mov %cr0,%eax - or $X86_CR0_PE,%al - mov %eax,%cr0 - - ljmpl $INMATE_CS32,$start32 - - .code32 + .section ".boot", "ax" + .globl start32 start32: mov %cr4,%eax or $X86_CR4_PAE,%eax @@ -142,6 +130,7 @@ gdt: .quad 0x00c09b000000ffff .quad 0x00af9b000000ffff + .globl gdt_ptr gdt_ptr: .short gdt_ptr - gdt - 1 .long gdt diff --git a/inmates/lib/x86/header-common.S b/inmates/lib/x86/header-common.S new file mode 100644 index 00000000..d40d8d5e --- /dev/null +++ b/inmates/lib/x86/header-common.S @@ -0,0 +1,56 @@ +/* + * Jailhouse, a Linux-based partitioning hypervisor + * + * Copyright (c) OTH Regensburg, 2019 + * + * Authors: + * Ralf Ramsauer <[email protected]> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Alternatively, you can use or redistribute this file under the following + * BSD license: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <inmate.h> +#include <asm/regs.h> + + .code16 + .section ".boot.entry", "ax" + + .globl __reset_entry +__reset_entry: + lgdtl %cs:gdt_ptr + + mov %cr0, %eax + or $X86_CR0_PE, %al + mov %eax, %cr0 + + ljmpl $INMATE_CS32, $start32 + + .code32 + .section ".boot", "ax" diff --git a/inmates/lib/x86/inmate.lds b/inmates/lib/x86/inmate.lds index 95c6ec97..a1ca242f 100644 --- a/inmates/lib/x86/inmate.lds +++ b/inmates/lib/x86/inmate.lds @@ -39,7 +39,10 @@ SECTIONS { . = 0; - .boot : { *(.boot) } + .boot : { + *(.boot.entry) + *(.boot) + } . = 0x1000; .cmdline : { -- 2.22.0 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jailhouse-dev/20190613200442.18984-4-ralf.ramsauer%40oth-regensburg.de. For more options, visit https://groups.google.com/d/optout.
