--- /dev/null
+;; @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