]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/CapsulePei/X64/PageFaultHandler.nasm
IntelSiliconPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / CapsulePei / X64 / PageFaultHandler.nasm
CommitLineData
3763cfc1
JJ
1;; @file\r
2; This is the assembly code for page fault handler hook.\r
3;\r
4; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
5;\r
6; This program and the accompanying materials\r
7; are licensed and made available under the terms and conditions of the BSD License\r
8; which accompanies this distribution. The full text of the license may be found at\r
9; http://opensource.org/licenses/bsd-license.php\r
10;\r
11; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13;\r
14;;\r
15\r
16extern ASM_PFX(PageFaultHandler)\r
17\r
18 DEFAULT REL\r
19 SECTION .text\r
20\r
21global ASM_PFX(PageFaultHandlerHook)\r
22ASM_PFX(PageFaultHandlerHook):\r
23 add rsp, -0x10\r
24 ; save rax\r
25 mov [rsp + 0x8], rax\r
26\r
27 ;push rax ; save all volatile registers\r
28 push rcx\r
29 push rdx\r
30 push r8\r
31 push r9\r
32 push r10\r
33 push r11\r
34 ; save volatile fp registers\r
35 ; 68h + 08h(for alignment)\r
36 add rsp, -0x70\r
37 stmxcsr [rsp + 0x60]\r
38 movdqa [rsp + 0x0], xmm0\r
39 movdqa [rsp + 0x10], xmm1\r
40 movdqa [rsp + 0x20], xmm2\r
41 movdqa [rsp + 0x30], xmm3\r
42 movdqa [rsp + 0x40], xmm4\r
43 movdqa [rsp + 0x50], xmm5\r
44\r
45 add rsp, -0x20\r
46 call ASM_PFX(PageFaultHandler)\r
47 add rsp, 0x20\r
48\r
49 ; load volatile fp registers\r
50 ldmxcsr [rsp + 0x60]\r
51 movdqa xmm0, [rsp + 0x0]\r
52 movdqa xmm1, [rsp + 0x10]\r
53 movdqa xmm2, [rsp + 0x20]\r
54 movdqa xmm3, [rsp + 0x30]\r
55 movdqa xmm4, [rsp + 0x40]\r
56 movdqa xmm5, [rsp + 0x50]\r
57 add rsp, 0x70\r
58\r
59 pop r11\r
60 pop r10\r
61 pop r9\r
62 pop r8\r
63 pop rdx\r
64 pop rcx\r
65 ;pop rax ; restore all volatile registers\r
66\r
67 add rsp, 0x10\r
68\r
69 ; rax returned from PageFaultHandler is NULL or OriginalHandler address\r
70 ; NULL if the page fault is handled by PageFaultHandler\r
71 ; OriginalHandler address if the page fault is not handled by PageFaultHandler\r
72 test rax, rax\r
73\r
74 ; save OriginalHandler address\r
75 mov [rsp - 0x10], rax\r
76 ; restore rax\r
77 mov rax, [rsp - 0x8]\r
78\r
79 jz .0\r
80\r
81 ; jump to OriginalHandler\r
82 jmp qword [rsp - 0x10]\r
83\r
84.0:\r
85 add rsp, 0x8 ; skip error code for PF\r
86 iretq\r
87\r