]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg CapsulePei: Convert X64/PageFaultHandler.asm to NASM
authorJordan Justen <jordan.l.justen@intel.com>
Tue, 31 May 2016 01:52:18 +0000 (18:52 -0700)
committerLiming Gao <liming.gao@intel.com>
Tue, 28 Jun 2016 01:51:55 +0000 (09:51 +0800)
The BaseTools/Scripts/ConvertMasmToNasm.py script was used to convert
X64/PageFaultHandler.asm to X64/PageFaultHandler.nasm

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf
MdeModulePkg/Universal/CapsulePei/X64/PageFaultHandler.nasm [new file with mode: 0644]

index 1630dfc383afaeb6b9fd7844177e7b946415f9c2..8318eaa2d6540caebcbd6edb13ebbc7943068106 100644 (file)
@@ -38,6 +38,7 @@
 \r
 [Sources]\r
   X64/X64Entry.c\r
+  X64/PageFaultHandler.nasm\r
   X64/PageFaultHandler.asm\r
   X64/PageFaultHandler.S\r
   Common/CapsuleCoalesce.c\r
diff --git a/MdeModulePkg/Universal/CapsulePei/X64/PageFaultHandler.nasm b/MdeModulePkg/Universal/CapsulePei/X64/PageFaultHandler.nasm
new file mode 100644 (file)
index 0000000..91ace09
--- /dev/null
@@ -0,0 +1,87 @@
+;; @file\r
+;   This is the assembly code for page fault handler hook.\r
+;\r
+; Copyright (c) 2015, 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
+extern ASM_PFX(PageFaultHandler)\r
+\r
+    DEFAULT REL\r
+    SECTION .text\r
+\r
+global ASM_PFX(PageFaultHandlerHook)\r
+ASM_PFX(PageFaultHandlerHook):\r
+    add     rsp, -0x10\r
+    ; save rax\r
+    mov     [rsp + 0x8], rax\r
+\r
+    ;push    rax                         ; save all volatile registers\r
+    push    rcx\r
+    push    rdx\r
+    push    r8\r
+    push    r9\r
+    push    r10\r
+    push    r11\r
+    ; save volatile fp registers\r
+    ; 68h + 08h(for alignment)\r
+    add     rsp, -0x70\r
+    stmxcsr [rsp + 0x60]\r
+    movdqa  [rsp + 0x0], xmm0\r
+    movdqa  [rsp + 0x10], xmm1\r
+    movdqa  [rsp + 0x20], xmm2\r
+    movdqa  [rsp + 0x30], xmm3\r
+    movdqa  [rsp + 0x40], xmm4\r
+    movdqa  [rsp + 0x50], xmm5\r
+\r
+    add     rsp, -0x20\r
+    call    ASM_PFX(PageFaultHandler)\r
+    add     rsp, 0x20\r
+\r
+    ; load volatile fp registers\r
+    ldmxcsr [rsp + 0x60]\r
+    movdqa  xmm0,  [rsp + 0x0]\r
+    movdqa  xmm1,  [rsp + 0x10]\r
+    movdqa  xmm2,  [rsp + 0x20]\r
+    movdqa  xmm3,  [rsp + 0x30]\r
+    movdqa  xmm4,  [rsp + 0x40]\r
+    movdqa  xmm5,  [rsp + 0x50]\r
+    add     rsp, 0x70\r
+\r
+    pop     r11\r
+    pop     r10\r
+    pop     r9\r
+    pop     r8\r
+    pop     rdx\r
+    pop     rcx\r
+    ;pop     rax                         ; restore all volatile registers\r
+\r
+    add     rsp, 0x10\r
+\r
+    ; rax returned from PageFaultHandler is NULL or OriginalHandler address\r
+    ; NULL if the page fault is handled by PageFaultHandler\r
+    ; OriginalHandler address if the page fault is not handled by PageFaultHandler\r
+    test    rax, rax\r
+\r
+    ; save OriginalHandler address\r
+    mov     [rsp - 0x10], rax\r
+    ; restore rax\r
+    mov     rax, [rsp - 0x8]\r
+\r
+    jz      .0\r
+\r
+    ; jump to OriginalHandler\r
+    jmp     qword [rsp - 0x10]\r
+\r
+.0:\r
+    add     rsp, 0x8                    ; skip error code for PF\r
+    iretq\r
+\r