[kvm-unit-tests PATCH v4 02/13] x86: Share realmode trampoline between i386 and x86_64

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Varad Gautam <varad.gautam@xxxxxxxx>

i386 and x86_64 each maintain their own copy of the realmode trampoline
(sipi_entry). Move the 16-bit SIPI vector and GDT to a new trampolines.S
to be shared by both.  The common trampoline file will also be used to
shared 32-bit to 64-bit trampoline code.

Signed-off-by: Varad Gautam <varad.gautam@xxxxxxxx>
[sean: rename to trampolines.S to avoid naming conundrum]
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
 x86/cstart.S      | 20 ++++----------------
 x86/cstart64.S    | 21 ++++-----------------
 x86/trampolines.S | 30 ++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 33 deletions(-)
 create mode 100644 x86/trampolines.S

diff --git a/x86/cstart.S b/x86/cstart.S
index 6db6a38..8aa29ee 100644
--- a/x86/cstart.S
+++ b/x86/cstart.S
@@ -126,10 +126,10 @@ start32:
 
 ap_init:
 	cld
-	sgdtl ap_gdt_descr // must be close to sipi_entry for real mode access to work
-	lea sipi_entry, %esi
+	sgdtl ap_rm_gdt_descr // must be close to rm_trampoline for real mode access to work
+	lea rm_trampoline, %esi
 	xor %edi, %edi
-	mov $(sipi_end - sipi_entry), %ecx
+	mov $(rm_trampoline_end - rm_trampoline), %ecx
 	rep movsb
 	mov $APIC_DEFAULT_PHYS_BASE, %eax
 	movl $(APIC_DEST_ALLBUT | APIC_DEST_PHYSICAL | APIC_DM_INIT | APIC_INT_ASSERT), APIC_ICR(%eax)
@@ -146,16 +146,4 @@ online_cpus:
 .align 2
 cpu_online_count:	.word 1
 
-.code16
-sipi_entry:
-	mov %cr0, %eax
-	or $1, %eax
-	mov %eax, %cr0
-	lgdtl ap_gdt_descr - sipi_entry
-	ljmpl $8, $ap_start32
-
-ap_gdt_descr:
-	.word 0
-	.long 0
-
-sipi_end:
+#include "trampolines.S"
diff --git a/x86/cstart64.S b/x86/cstart64.S
index 7272452..129ef0b 100644
--- a/x86/cstart64.S
+++ b/x86/cstart64.S
@@ -45,8 +45,9 @@ mb_boot_info:	.quad 0
 
 pt_root:	.quad ptl4
 
+#include "trampolines.S"
+
 .section .init
-
 .code32
 
 mb_magic = 0x1BADB002
@@ -156,20 +157,6 @@ gdt32:
 	.quad 0x00cf93000000ffff // flat 32-bit data segment
 gdt32_end:
 
-.code16
-sipi_entry:
-	mov %cr0, %eax
-	or $1, %eax
-	mov %eax, %cr0
-	lgdtl gdt32_descr - sipi_entry
-	ljmpl $8, $ap_start32
-
-gdt32_descr:
-	.word gdt32_end - gdt32 - 1
-	.long gdt32
-
-sipi_end:
-
 .code32
 ap_start32:
 	setup_segments
@@ -243,9 +230,9 @@ online_cpus:
 
 ap_init:
 	cld
-	lea sipi_entry, %rsi
+	lea rm_trampoline, %rsi
 	xor %rdi, %rdi
-	mov $(sipi_end - sipi_entry), %rcx
+	mov $(rm_trampoline_end - rm_trampoline), %rcx
 	rep movsb
 	mov $APIC_DEFAULT_PHYS_BASE, %eax
 	movl $(APIC_DEST_ALLBUT | APIC_DEST_PHYSICAL | APIC_DM_INIT | APIC_INT_ASSERT), APIC_ICR(%rax)
diff --git a/x86/trampolines.S b/x86/trampolines.S
new file mode 100644
index 0000000..9640c66
--- /dev/null
+++ b/x86/trampolines.S
@@ -0,0 +1,30 @@
+/* Common bootstrapping code to transition from 16-bit to 32-bit code. */
+
+/* EFI provides it's own SIPI sequence to handle relocation. */
+#ifndef CONFIG_EFI
+.code16
+.globl rm_trampoline
+rm_trampoline:
+
+/* Store SIPI vector code at the beginning of trampoline. */
+sipi_entry:
+	mov %cr0, %eax
+	or $1, %eax
+	mov %eax, %cr0
+	lgdtl ap_rm_gdt_descr - sipi_entry
+	ljmpl $8, $ap_start32
+sipi_end:
+
+.globl ap_rm_gdt_descr
+ap_rm_gdt_descr:
+#ifdef __i386__
+	.word 0
+	.long 0
+#else
+	.word gdt32_end - gdt32 - 1
+	.long gdt32
+#endif
+
+.globl rm_trampoline_end
+rm_trampoline_end:
+#endif
-- 
2.36.1.476.g0c4daa206d-goog




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux