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

[PATCH 05/11] x86/boot: Share the switch to 64-bit mode between SIPI and S3 paths



The S3 wakeup path duplicated the protected mode to 64-bit mode switch
of the SIPI path: CR4, CR3, IA32_MISC_ENABLE, PAT, EFER and CR0 are set
up the same way, with the same values (0x80050033 is the same CR0 value
the SIPI path builds from the X86_CR0_* constants).

Move this into common_64, entered with DS set to BOOT_DS_TRAMP and EBP
pointing to the 64-bit address to jump to, which is the only difference
left between the two paths.  The S3 data is moved after the code.

There are two functional changes for S3:

- The FPU is now initialised, as on the SIPI path.  Firmware can leave
  it in any state, and the old code even had a "fpu init?" note.

- WBINVD before enabling paging is dropped.  Caches are flushed with
  ACPI_FLUSH_CPU_CACHE() before entering S3, and CR0.CD/NW are already
  cleared by the first write to CR0 in real mode, so caches are enabled
  with nothing stale to write back.  The SIPI path, which has the same
  requirements, never had it.

Signed-off-by: Frediano Ziglio <freddy77@xxxxxxxxx>
---
 xen/arch/x86/boot/trampoline.S | 38 ++++++++++++++++---
 xen/arch/x86/boot/wakeup.S     | 69 +++++-----------------------------
 2 files changed, 41 insertions(+), 66 deletions(-)

diff --git a/xen/arch/x86/boot/trampoline.S b/xen/arch/x86/boot/trampoline.S
index c34ca9beae..c52c27795d 100644
--- a/xen/arch/x86/boot/trampoline.S
+++ b/xen/arch/x86/boot/trampoline.S
@@ -59,10 +59,20 @@ GLOBAL(entry_SIPI16)
 
         .code32
 trampoline_protmode_entry:
+        mov     $bootsym(high_start_address), %ebp
+
         /* Set up a few descriptors: on entry only CS is guaranteed good. */
         mov     $BOOT_DS_TRAMP, %eax
         mov     %eax,%ds
 
+        /*
+         * Common path to 64-bit mode, used by SIPI and S3.
+         * On entry:
+         * - DS is BOOT_DS_TRAMP;
+         * - EBP is the trampoline offset of the 64-bit address to jump to;
+         * - EBX is passed on unchanged.
+         */
+common_64:
         /* Set up FPU. */
         fninit
 
@@ -101,26 +111,42 @@ trampoline_protmode_entry:
         or      bootsym(trampoline_efer), %eax
         wrmsr
 
+        /* Enable paging */
         mov     $(X86_CR0_PG | X86_CR0_AM | X86_CR0_WP | X86_CR0_NE |\
                   X86_CR0_ET | X86_CR0_MP | X86_CR0_PE), %eax
         mov     %eax,%cr0
 
-        /* Now in compatibility mode. Long-jump into 64-bit mode. */
-        mov     $BOOT_DS, %eax
-        mov     %eax, %ds
-        mov     %eax, %es
+        /*
+         * Now in compatibility mode.  Load the target address before
+         * switching DS: (%ebp) would use SS, which isn't set up on the SIPI
+         * path.
+         */
+        mov     %ebp, %eax
+        mov     4(%eax), %edx
+        mov     (%eax), %eax
+
+        /* Load correct selectors */
+        mov     $BOOT_DS, %ecx
+        mov     %ecx, %ds
+        mov     %ecx, %es
+
+        /* Long-jump into 64-bit mode. */
         ljmp    $BOOT_CS64,$bootsym_rel(start64,6)
 
         .code64
 start64:
+        movl    %eax, %eax
+        shl     $32, %rdx
+        or      %rdx, %rax
         /* Jump to high mappings. */
-        movabs  $(abs___high_start + XEN_VIRT_START), %rdi
-        jmpq    *%rdi
+        jmpq    *%rax
 
 #include "video.h"
 #include "wakeup.S"
 
         .balign 8
+high_start_address:
+        .quad   abs___high_start + XEN_VIRT_START
         .word   0
 idt_48: .word   0, 0, 0 # base = limit = 0
 
diff --git a/xen/arch/x86/boot/wakeup.S b/xen/arch/x86/boot/wakeup.S
index 6d24ab2bdd..ecbf2852d8 100644
--- a/xen/arch/x86/boot/wakeup.S
+++ b/xen/arch/x86/boot/wakeup.S
@@ -101,12 +101,6 @@ bogus_real_magic:
         movw    $0x0e00 + 'B', %fs:(0x12)
         jmp     1b
 
-        .align 4
-real_magic:     .long 0x12345678
-video_mode:     .word 0
-GLOBAL(video_flags)
-        .byte 0
-
         .code32
 
         # Now in protect mode, with paging disabled
@@ -126,64 +120,19 @@ wakeup_32:
         mov     %ss:(%eax), %eax
         cmp     $0x9abcdef0, %eax
         jne     bogus_saved_magic
-        
-        /* fpu init? */
-
-        /* Initialise CR4. */
-        mov     $X86_CR4_PAE, %ecx
-        mov     %ecx, %cr4
-
-        /* Load pagetable base register */
-        mov     $abs_idle_pg_table, %eax
-        add     bootsym(trampoline_xen_phys_start), %eax
-        mov     %eax,%cr3
-
-        /* Reapply IA32_MISC_ENABLE modifications from early_init_intel(). */
-        mov     bootsym(trampoline_misc_enable_off), %esi
-        mov     bootsym(trampoline_misc_enable_off + 4), %edi
-        mov     %esi, %eax
-        or      %edi, %eax
-        jz      1f
-        mov     $MSR_IA32_MISC_ENABLE, %ecx
-        rdmsr
-        not     %esi
-        not     %edi
-        and     %esi, %eax
-        and     %edi, %edx
-        wrmsr
-1:
-        /* Set up PAT before enabling paging. */
-        mov     $XEN_MSR_PAT & 0xffffffff, %eax
-        mov     $XEN_MSR_PAT >> 32, %edx
-        mov     $MSR_IA32_CR_PAT, %ecx
-        wrmsr
-
-        /* Set up EFER (Extended Feature Enable Register). */
-        movl    $MSR_EFER,%ecx
-        rdmsr
-        or      bootsym(trampoline_efer), %eax
-        wrmsr
-
-        wbinvd
-
-        /* Enable paging and flush prefetch queue */
-        mov     $0x80050033,%eax /* hi-to-lo: PG,AM,WP,NE,ET,MP,PE */
-        mov     %eax,%cr0
-        jmp     1f
-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)
+        mov     $bootsym(s3_start_address), %ebp
+        jmp     common_64
 
 FUNC_LOCAL(bogus_saved_magic, 0)
         movw    $0x0e00 + 'S', %ss:0xb8014
         jmp     bogus_saved_magic
 END(bogus_saved_magic)
 
-        .code64
-wakeup_64:
-        /* Jump to high mappings and the higher-level wakeup code. */
-        movabs  $(abs_s3_resume + XEN_VIRT_START), %rbx
-        jmp     *%rbx
+        .align 8
+s3_start_address:
+        .quad   abs_s3_resume + XEN_VIRT_START
+real_magic:     .long 0x12345678
+video_mode:     .word 0
+GLOBAL(video_flags)
+        .byte 0
-- 
2.43.0




 


Rackspace

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