On 21.05.19 16:34, Ralf Ramsauer wrote:
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 | 20 ++---------
inmates/lib/x86/header-64.S | 20 ++---------
inmates/lib/x86/header-common.S | 62 +++++++++++++++++++++++++++++++++
inmates/lib/x86/inmate.lds | 5 ++-
5 files changed, 77 insertions(+), 37 deletions(-)
create mode 100644 inmates/lib/x86/header-common.S
diff --git a/inmates/lib/x86/Makefile b/inmates/lib/x86/Makefile
index bae59025..e474ffd0 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 := ioapic.o printk.o setup.o smp.o uart.o
+TARGETS := header-common.o ioapic.o printk.o setup.o smp.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 006cce9a..30b3f5e3 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
@@ -107,11 +95,8 @@ call_entry:
mov $stack_top,%esp
call *%ebx
-stop: cli
- hlt
jmp stop
-
.pushsection ".data"
.globl ap_entry
@@ -139,6 +124,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 cb886b8e..2c4caace 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
@@ -111,11 +99,8 @@ call_entry:
mov $stack_top,%rsp
callq *%rbx
-stop: cli
- hlt
jmp stop
-
.pushsection ".data"
.globl ap_entry
@@ -141,6 +126,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..139d4ae2
--- /dev/null
+++ b/inmates/lib/x86/header-common.S
@@ -0,0 +1,62 @@
+/*
+ * 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"
+
+ .globl stop
+stop:
+ cli
+1: hlt
+ jmp 1b
This is conceptually risky: If we should ever place some opcodes here that are
not 32/64 invariant, things will subtly break. So better avoid this false
sharing.
Jan
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 : {
--
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/507e40c8-75c7-9ebb-745e-1ccdc4d30d72%40web.de.
For more options, visit https://groups.google.com/d/optout.