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

[PATCH 04/11] x86/boot: Reduce relocations in the trampoline



Use code and data selectors based on the trampoline to avoid relocations
to simple symbols and for far jumps from 16 bits code to 32 bits code.
Avoid wakesym macro reusing bootsym one.

This also remove the need to pass the relative position of the
relocation (second argument of bootsym_rel) keeping normal parameter
separation.

Signed-off-by: Frediano Ziglio <freddy77@xxxxxxxxx>
---
 xen/arch/x86/boot/head.S       |  6 +++--
 xen/arch/x86/boot/trampoline.S | 31 +++++++++++++++---------
 xen/arch/x86/boot/wakeup.S     | 43 ++++++++++++++++++++--------------
 3 files changed, 49 insertions(+), 31 deletions(-)

diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
index 77e5a86a1d..0e1388ac1f 100644
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -31,6 +31,8 @@
 #define BOOT_DS          0x0018
 #define BOOT_PSEUDORM_CS 0x0020
 #define BOOT_PSEUDORM_DS 0x0028
+#define BOOT_CS32_TRAMP  0x0030
+#define BOOT_DS_TRAMP    0x0038
 
 #define MB2_HT(name)      (MULTIBOOT2_HEADER_TAG_##name)
 #define MB2_TT(name)      (MULTIBOOT2_TAG_TYPE_##name)
@@ -699,8 +701,8 @@ trampoline_setup:
         /* Switch to low-memory stack which lives at the end of trampoline 
region. */
         mov     sym_esi(trampoline_phys), %edi
         lea     TRAMPOLINE_SIZE(%edi), %esp
-        lea     trampoline_boot_cpu_entry-trampoline_start(%edi),%eax
-        pushl   $BOOT_CS32
+        mov     $(trampoline_boot_cpu_entry-trampoline_start), %eax
+        pushl   $BOOT_CS32_TRAMP
         push    %eax
 
         /* Copy bootstrap trampoline to low memory, below 1MB. */
diff --git a/xen/arch/x86/boot/trampoline.S b/xen/arch/x86/boot/trampoline.S
index 0be6fe0006..c34ca9beae 100644
--- a/xen/arch/x86/boot/trampoline.S
+++ b/xen/arch/x86/boot/trampoline.S
@@ -16,7 +16,7 @@
  * not guaranteed to persist.
  */
 
-/* NB. bootsym() is only usable in real mode, or via BOOT_PSEUDORM_DS. */
+/* NB. bootsym() is usable in real mode, via BOOT_PSEUDORM_DS or via 
BOOT_DS_TRAMP. */
 #undef bootsym
 #define bootsym(s) ((s)-trampoline_start)
 
@@ -55,14 +55,13 @@ GLOBAL(entry_SIPI16)
         mov     $X86_CR0_PE, %ebx         # EBX != 0 indicates we are an AP
         mov     %ebx, %cr0                # Alias with CR0.PE for brevity
 
-        ljmpl   $BOOT_CS32,$bootsym_rel(trampoline_protmode_entry,6)
+        ljmp    $BOOT_CS32_TRAMP, $bootsym(trampoline_protmode_entry)
 
         .code32
 trampoline_protmode_entry:
         /* Set up a few descriptors: on entry only CS is guaranteed good. */
-        mov     $BOOT_DS,%eax
+        mov     $BOOT_DS_TRAMP, %eax
         mov     %eax,%ds
-        mov     %eax,%es
 
         /* Set up FPU. */
         fninit
@@ -73,12 +72,12 @@ trampoline_protmode_entry:
 
         /* Load pagetable base register. */
         mov     $abs_idle_pg_table, %eax
-        add     bootsym_rel(trampoline_xen_phys_start,4,%eax)
+        add     bootsym(trampoline_xen_phys_start), %eax
         mov     %eax,%cr3
 
         /* Adjust IA32_MISC_ENABLE if needed (for NX enabling below). */
-        mov     bootsym_rel(trampoline_misc_enable_off,4,%esi)
-        mov     bootsym_rel(trampoline_misc_enable_off+4,4,%edi)
+        mov     bootsym(trampoline_misc_enable_off), %esi
+        mov     bootsym(trampoline_misc_enable_off+4), %edi
         mov     %esi,%eax
         or      %edi,%eax
         jz      1f
@@ -99,7 +98,7 @@ trampoline_protmode_entry:
         /* Set up EFER (Extended Feature Enable Register). */
         movl    $MSR_EFER,%ecx
         rdmsr
-        or      bootsym_rel(trampoline_efer, 4, %eax)
+        or      bootsym(trampoline_efer), %eax
         wrmsr
 
         mov     $(X86_CR0_PG | X86_CR0_AM | X86_CR0_WP | X86_CR0_NE |\
@@ -107,6 +106,9 @@ trampoline_protmode_entry:
         mov     %eax,%cr0
 
         /* Now in compatibility mode. Long-jump into 64-bit mode. */
+        mov     $BOOT_DS, %eax
+        mov     %eax, %ds
+        mov     %eax, %es
         ljmp    $BOOT_CS64,$bootsym_rel(start64,6)
 
         .code64
@@ -133,12 +135,16 @@ gdt_48:
         .quad   0x00cf93000000ffff /* 0x0018: ring 0 data */
         .quad   0x00009b000000ffff /* 0x0020: real-mode code @ BOOT_TRAMPOLINE 
*/
         .quad   0x000093000000ffff /* 0x0028: real-mode data @ BOOT_TRAMPOLINE 
*/
+        .quad   0x00cf9b000000ffff /* 0x0030: ring 0 code, 32-bit mode @ 
BOOT_TRAMPOLINE */
+        .quad   0x00cf93000000ffff /* 0x0038: ring 0 data @ BOOT_TRAMPOLINE */
 .Ltrampoline_gdt_end:
 
         /* Relocations for trampoline Real Mode segments. */
         .pushsection .trampoline_rel, "a"
         .long   trampoline_gdt + BOOT_PSEUDORM_CS + 2 - .
         .long   trampoline_gdt + BOOT_PSEUDORM_DS + 2 - .
+        .long   trampoline_gdt + BOOT_DS_TRAMP+ 2 - .
+        .long   trampoline_gdt + BOOT_CS32_TRAMP + 2 - .
         .popsection
 
 GLOBAL(trampoline_misc_enable_off)
@@ -162,9 +168,12 @@ LABEL(trampoline_perm_end, 0)
         .code32
 trampoline_boot_cpu_entry:
         /* Switch to relocated trampoline GDT. */
-        lgdt    bootsym_rel(gdt_48, 4)
+        lgdt    %cs:bootsym(gdt_48)
+
+        mov     $BOOT_DS_TRAMP, %eax
+        mov     %eax, %ds
 
-        cmpb    $0,bootsym_rel(skip_realmode,5)
+        cmpb    $0, bootsym(skip_realmode)
         jnz     .Lskip_realmode
 
         /* Load pseudo-real-mode segments. */
@@ -236,7 +245,7 @@ trampoline_boot_cpu_entry:
         mov     %eax, %cr0
 
         /* Load proper protected-mode values into all segment registers. */
-        ljmpl   $BOOT_CS32,$bootsym_rel(1f,6)
+        ljmp    $BOOT_CS32_TRAMP, $bootsym(1f)
         .code32
 1:      mov     $BOOT_DS,%eax
         mov     %eax,%ds
diff --git a/xen/arch/x86/boot/wakeup.S b/xen/arch/x86/boot/wakeup.S
index fb9b3da205..6d24ab2bdd 100644
--- a/xen/arch/x86/boot/wakeup.S
+++ b/xen/arch/x86/boot/wakeup.S
@@ -7,8 +7,6 @@
         .equ    wakeup_stack, trampoline_start + PAGE_SIZE
         .local  wakeup_stack
 
-#define wakesym(sym) (sym - entry_S3)
-
 /*
  * acpi_sleep_prepare() programs the S3 wakeup vector to point here.
  *
@@ -24,20 +22,26 @@ ENTRY(entry_S3)
 
         # setup data segment
         movw    %cs, %ax
+        sub     $bootsym(entry_S3) / 16, %ax
         movw    %ax, %ds
         movw    %ax, %ss        # A stack required for BIOS call
-        movw    $wakesym(wakeup_stack), %sp
+        movw    $bootsym(wakeup_stack), %sp
 
         pushl   $0              # Kill dangerous flag early
         popfl
 
         # check magic number
-        movl    wakesym(real_magic), %eax
+        movl    bootsym(real_magic), %eax
         cmpl    $0x12345678, %eax
         jne     bogus_real_magic
 
+        push    %ds
+        push    $bootsym(1f)
+        lret
+1:
+
         # for acpi_sleep=s3_bios
-        testb   $1, wakesym(video_flags)
+        testb   $1, bootsym(video_flags)
         jz      1f
         mov     $0xc000, %ax
         mov     %ax, %fs
@@ -52,9 +56,9 @@ ENTRY(entry_S3)
         popfl
 
 1:      # for acpi_sleep=s3_mode
-        testb   $2, wakesym(video_flags)
+        testb   $2, bootsym(video_flags)
         jz      1f
-        movw    wakesym(video_mode), %ax
+        movw    bootsym(video_mode), %ax
         call    mode_setw
 
 1:      # Show some progress if VGA is resumed
@@ -62,13 +66,13 @@ ENTRY(entry_S3)
         movw    %ax, %fs
         movw    $0x0e00 + 'L', %fs:(0x10)
 
-        lidt    wakesym(idt_48)
-        lgdt    wakesym(gdt_48)
+        lidt    bootsym(idt_48)
+        lgdt    bootsym(gdt_48)
 
         mov     $X86_CR0_PE, %eax
         mov     %eax, %cr0
 
-        ljmpl   $BOOT_CS32, $bootsym_rel(wakeup_32, 6)
+        ljmp    $BOOT_CS32_TRAMP, $bootsym(wakeup_32)
 
 # Setting of user mode (AX=mode ID) => CF=success
 mode_setw:
@@ -110,15 +114,16 @@ GLOBAL(video_flags)
 
 wakeup_32:
         /* Set up segment registers and initial stack for protected mode */
-        mov     $BOOT_DS, %eax
+        mov     $BOOT_DS_TRAMP, %eax
         mov     %eax, %ds
+        mov     $BOOT_DS, %eax
         mov     %eax, %ss
         mov     $bootsym_rel(wakeup_stack, 4, %esp)
 
         # check saved magic again
         mov     $abs_saved_magic, %eax
-        add     bootsym_rel(trampoline_xen_phys_start, 4, %eax)
-        mov     (%eax), %eax
+        add     bootsym(trampoline_xen_phys_start), %eax
+        mov     %ss:(%eax), %eax
         cmp     $0x9abcdef0, %eax
         jne     bogus_saved_magic
         
@@ -130,12 +135,12 @@ wakeup_32:
 
         /* Load pagetable base register */
         mov     $abs_idle_pg_table, %eax
-        add     bootsym_rel(trampoline_xen_phys_start,4,%eax)
+        add     bootsym(trampoline_xen_phys_start), %eax
         mov     %eax,%cr3
 
         /* Reapply IA32_MISC_ENABLE modifications from early_init_intel(). */
-        mov     bootsym_rel(trampoline_misc_enable_off, 4, %esi)
-        mov     bootsym_rel(trampoline_misc_enable_off + 4, 4, %edi)
+        mov     bootsym(trampoline_misc_enable_off), %esi
+        mov     bootsym(trampoline_misc_enable_off + 4), %edi
         mov     %esi, %eax
         or      %edi, %eax
         jz      1f
@@ -156,7 +161,7 @@ wakeup_32:
         /* Set up EFER (Extended Feature Enable Register). */
         movl    $MSR_EFER,%ecx
         rdmsr
-        or      bootsym_rel(trampoline_efer, 4, %eax)
+        or      bootsym(trampoline_efer), %eax
         wrmsr
 
         wbinvd
@@ -168,10 +173,12 @@ wakeup_32:
 1:
 
         /* Now in compatibility mode. Long-jump to 64-bit mode */
+        mov     $BOOT_DS, %eax
+        mov     %eax, %ds
         ljmp    $BOOT_CS64, $bootsym_rel(wakeup_64,6)
 
 FUNC_LOCAL(bogus_saved_magic, 0)
-        movw    $0x0e00 + 'S', 0xb8014
+        movw    $0x0e00 + 'S', %ss:0xb8014
         jmp     bogus_saved_magic
 END(bogus_saved_magic)
 
-- 
2.43.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.