public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: edk2-devel@lists.sourceforge.net,
	KVM devel mailing list <kvm@vger.kernel.org>
Subject: Re: [edk2] apparent KVM problem with LRET in TianoCore S3 resume trampoline
Date: Thu, 05 Dec 2013 23:38:37 +0100	[thread overview]
Message-ID: <52A1006D.2070304@redhat.com> (raw)
In-Reply-To: <52A0BB05.8010703@redhat.com>

On 12/05/13 18:42, Paolo Bonzini wrote:

> diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S
> index e59fd04..d1cac9d 100644
> --- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S
> +++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S
> @@ -19,7 +19,7 @@ ASM_PFX(AsmTransferControl):
>      # rcx S3WakingVector    :DWORD
>      # rdx AcpiLowMemoryBase :DWORD
>      lea   _AsmTransferControl_al_0000(%rip), %eax 
> -    movq  $0x2800000000, %r8 
> +    movq  $0x1000000000, %r8 
>      orq   %r8, %rax
>      pushq %rax
>      shrd  $20, %ecx, %ebx
> @@ -28,24 +28,32 @@ ASM_PFX(AsmTransferControl):
>      movl  %ebx, jmp_addr(%rip) 
>      lret
>  _AsmTransferControl_al_0000:
> +    # Old SS should still be okay?
> +    addl  _AsmTransferControl_al_0001-_AsmTransferControl_al_0000, %eax
> +    pushl $0x28
> +    pushl %eax
> +    movq  %cr0, %rax
> +    movq  %cr4, %rbx
> +    andl  $0x7fffffff, %eax
> +    andb  $0xdf, %bl
> +    movq  %rax, %cr0             # sets EFER.LMA=0 too, so says Intel
> +    movl  $0x0c0000080, %ecx
> +    rdmsr
> +    andb  $0xfe, %ah             # set EFER.LME=0
> +    wrmsr
> +    movq  %rbx, %cr4             # only now set CR4.PAE=0
> +    lret
> +_AsmTransferControl_al_0001:
>      .byte    0x0b8, 0x30, 0      # mov ax, 30h as selector
>      movl  %eax, %ds
>      movl  %eax, %es
>      movl  %eax, %fs
>      movl  %eax, %gs
>      movl  %eax, %ss
> -    movq  %cr0, %rax
> -    movq  %cr4, %rbx
> -    .byte    0x66
> -    andl  $0x7ffffffe, %eax 
> -    andb  $0xdf, %bl 
> -    movq  %rax, %cr0
> -    .byte    0x66
> -    movl  $0x0c0000080, %ecx 
> -    rdmsr
> -    andb  $0xfe, %ah 
> -    wrmsr
> -    movq  %rbx, %cr4
> +    movl  %cr0, %rax        # Get control register 0
> +    .byte 0x66
> +    .byte 0x83,0xe0,0xfe    # and    eax, 0fffffffeh  ; Clear PE bit (bit #0)
> +    .byte 0xf,0x22,0xc0     # mov    cr0, eax         ; Activate real mode

I had to add this incremental patch to get it to compile:

diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S
index c28df3f..85d2a36 100644
--- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S
+++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S
@@ -30,8 +30,8 @@ ASM_PFX(AsmTransferControl):
 _AsmTransferControl_al_0000:
     # Old SS should still be okay?
     addl  _AsmTransferControl_al_0001-_AsmTransferControl_al_0000, %eax
-    pushl $0x28
-    pushl %eax
+    .byte 0x6a,0x28              # pushl $0x28 ; opnd sz = 32bits in seg 0x10
+    .byte 0x50                   # pushl %eax
     movq  %cr0, %rax
     movq  %cr4, %rbx
     andl  $0x7fffffff, %eax
@@ -50,7 +50,7 @@ _AsmTransferControl_al_0001:
     movl  %eax, %fs
     movl  %eax, %gs
     movl  %eax, %ss
-    movl  %cr0, %rax        # Get control register 0
+    .byte 0x0f,0x20,0xc0    # movl  %cr0, %eax        ; Get control register 0
     .byte 0x66
     .byte 0x83,0xe0,0xfe    # and    eax, 0fffffffeh  ; Clear PE bit (bit #0)
     .byte 0xf,0x22,0xc0     # mov    cr0, eax         ; Activate real mode

The 2nd lret is reached (just before _AsmTransferControl_al_0001), but then the CPU goes off in the woods. For a while it seems to be spinning who knows where, and in 15-20 seconds or so the guest reboots.

Does gas support mode switches in one file? I found examples on the net (for nasm I think) where people were thunking to real mode and back to protected mode in a single assembly file, and they could use native mnemonics for each part. (They just switched the assembler's mode in sync with execution modes.)

Thanks
Laszlo

Thanks,
Laszlo

------------------------------------------------------------------------------
Sponsored by Intel(R) XDK 
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk

  parent reply	other threads:[~2013-12-05 22:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-05 16:12 [edk2] apparent KVM problem with LRET in TianoCore S3 resume trampoline Laszlo Ersek
2013-12-05 16:50 ` Laszlo Ersek
2013-12-05 17:42 ` Paolo Bonzini
2013-12-05 18:29   ` Laszlo Ersek
2013-12-06 12:03     ` Paolo Bonzini
2013-12-06 13:31       ` Paolo Bonzini
2013-12-06 13:46         ` Yao, Jiewen
2013-12-06 14:29           ` Paolo Bonzini
2013-12-06 14:47             ` Yao, Jiewen
2013-12-06 14:51               ` Paolo Bonzini
2013-12-06 13:31       ` Yao, Jiewen
2013-12-08 17:43       ` Laszlo Ersek
2013-12-08 22:15         ` Laszlo Ersek
2013-12-05 22:38   ` Laszlo Ersek [this message]
2013-12-05 22:53     ` Andrew Fish
2013-12-07 16:25     ` David Woodhouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52A1006D.2070304@redhat.com \
    --to=lersek@redhat.com \
    --cc=edk2-devel@lists.sourceforge.net \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox