]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.asm
MdeModulePkg: Add BootScriptExecutorDxe driver
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / BootScriptExecutorDxe / X64 / S3Asm.asm
diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.asm b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.asm
new file mode 100644 (file)
index 0000000..f3d327d
--- /dev/null
@@ -0,0 +1,84 @@
+;; @file\r
+;   This is the assembly code for transferring to control to OS S3 waking vector\r
+;   for X64 platform\r
+;\r
+; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+;\r
+; This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution.  The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+;;\r
+\r
+    .code\r
+    \r
+EXTERNDEF   AsmFixAddress16:DWORD\r
+EXTERNDEF   AsmJmpAddr32:DWORD\r
+    \r
+AsmTransferControl  PROC\r
+    ; rcx S3WakingVector    :DWORD\r
+    ; rdx AcpiLowMemoryBase :DWORD\r
+    lea   eax, @F\r
+    mov   r8, 2800000000h\r
+    or    rax, r8\r
+    push  rax\r
+    shrd  ebx, ecx, 20\r
+    and   ecx, 0fh          \r
+    mov   bx, cx          \r
+    mov   @jmp_addr, ebx\r
+    retf\r
+@@:\r
+    DB    0b8h, 30h, 0      ; mov ax, 30h as selector\r
+    mov   ds, eax\r
+    mov   es, eax\r
+    mov   fs, eax\r
+    mov   gs, eax\r
+    mov   ss, eax\r
+    mov   rax, cr0\r
+    mov   rbx, cr4        \r
+    DB    66h\r
+    and   eax, ((NOT 080000001h) AND 0ffffffffh)\r
+    and   bl, NOT (1 SHL 5)\r
+    mov   cr0, rax\r
+    DB    66h\r
+    mov   ecx, 0c0000080h\r
+    rdmsr\r
+    and   ah, NOT 1\r
+    wrmsr\r
+    mov   cr4, rbx\r
+    DB    0eah              ; jmp far @jmp_addr\r
+@jmp_addr DD  ?\r
+AsmTransferControl  ENDP\r
+\r
+AsmTransferControl32  PROC\r
+    ; S3WakingVector    :DWORD\r
+    ; AcpiLowMemoryBase :DWORD\r
+    push  rbp\r
+    mov   ebp, esp    \r
+    DB    8dh, 05h          ;  lea   eax, AsmTransferControl16\r
+AsmFixAddress16  DD ?\r
+    push  28h               ; CS\r
+    push  rax\r
+    retf\r
+AsmTransferControl32  ENDP\r
+\r
+AsmTransferControl16  PROC\r
+    DB    0b8h, 30h, 0      ; mov ax, 30h as selector\r
+    mov   ds, ax\r
+    mov   es, ax\r
+    mov   fs, ax\r
+    mov   gs, ax\r
+    mov   ss, ax\r
+    mov   rax, cr0          ; Get control register 0  \r
+    DB    66h\r
+    DB    83h, 0e0h, 0feh   ; and    eax, 0fffffffeh  ; Clear PE bit (bit #0)\r
+    DB    0fh, 22h, 0c0h    ; mov    cr0, eax         ; Activate real mode\r
+    DB    0eah              ; jmp far AsmJmpAddr32\r
+AsmJmpAddr32 DD  ?\r
+AsmTransferControl16  ENDP\r
+\r
+    END\r