]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.asm
Create 4G page table by default, and using PF to handle >4G MMIO access, to improve...
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / BootScriptExecutorDxe / X64 / S3Asm.asm
1 ;; @file
2 ; This is the assembly code for transferring to control to OS S3 waking vector
3 ; for X64 platform
4 ;
5 ; Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
6 ;
7 ; This program and the accompanying materials
8 ; are licensed and made available under the terms and conditions of the BSD License
9 ; which accompanies this distribution. The full text of the license may be found at
10 ; http://opensource.org/licenses/bsd-license.php
11 ;
12 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 ;
15 ;;
16
17 EXTERN mOriginalHandler:QWORD
18 EXTERN PageFaultHandler:PROC
19
20 .code
21
22 EXTERNDEF AsmFixAddress16:DWORD
23 EXTERNDEF AsmJmpAddr32:DWORD
24
25 AsmTransferControl PROC
26 ; rcx S3WakingVector :DWORD
27 ; rdx AcpiLowMemoryBase :DWORD
28 lea eax, @F
29 mov r8, 2800000000h
30 or rax, r8
31 push rax
32 shrd ebx, ecx, 20
33 and ecx, 0fh
34 mov bx, cx
35 mov @jmp_addr, ebx
36 retf
37 @@:
38 DB 0b8h, 30h, 0 ; mov ax, 30h as selector
39 mov ds, eax
40 mov es, eax
41 mov fs, eax
42 mov gs, eax
43 mov ss, eax
44 mov rax, cr0
45 mov rbx, cr4
46 DB 66h
47 and eax, ((NOT 080000001h) AND 0ffffffffh)
48 and bl, NOT (1 SHL 5)
49 mov cr0, rax
50 DB 66h
51 mov ecx, 0c0000080h
52 rdmsr
53 and ah, NOT 1
54 wrmsr
55 mov cr4, rbx
56 DB 0eah ; jmp far @jmp_addr
57 @jmp_addr DD ?
58 AsmTransferControl ENDP
59
60 AsmTransferControl32 PROC
61 ; S3WakingVector :DWORD
62 ; AcpiLowMemoryBase :DWORD
63 push rbp
64 mov ebp, esp
65 DB 8dh, 05h ; lea eax, AsmTransferControl16
66 AsmFixAddress16 DD ?
67 push 28h ; CS
68 push rax
69 retf
70 AsmTransferControl32 ENDP
71
72 AsmTransferControl16 PROC
73 DB 0b8h, 30h, 0 ; mov ax, 30h as selector
74 mov ds, ax
75 mov es, ax
76 mov fs, ax
77 mov gs, ax
78 mov ss, ax
79 mov rax, cr0 ; Get control register 0
80 DB 66h
81 DB 83h, 0e0h, 0feh ; and eax, 0fffffffeh ; Clear PE bit (bit #0)
82 DB 0fh, 22h, 0c0h ; mov cr0, eax ; Activate real mode
83 DB 0eah ; jmp far AsmJmpAddr32
84 AsmJmpAddr32 DD ?
85 AsmTransferControl16 ENDP
86
87 PageFaultHandlerHook PROC
88 push rax ; save all volatile registers
89 push rcx
90 push rdx
91 push r8
92 push r9
93 push r10
94 push r11
95 ; save volatile fp registers
96 add rsp, -68h
97 stmxcsr [rsp + 60h]
98 movdqa [rsp + 0h], xmm0
99 movdqa [rsp + 10h], xmm1
100 movdqa [rsp + 20h], xmm2
101 movdqa [rsp + 30h], xmm3
102 movdqa [rsp + 40h], xmm4
103 movdqa [rsp + 50h], xmm5
104
105 add rsp, -20h
106 call PageFaultHandler
107 add rsp, 20h
108
109 ; load volatile fp registers
110 ldmxcsr [rsp + 60h]
111 movdqa xmm0, [rsp + 0h]
112 movdqa xmm1, [rsp + 10h]
113 movdqa xmm2, [rsp + 20h]
114 movdqa xmm3, [rsp + 30h]
115 movdqa xmm4, [rsp + 40h]
116 movdqa xmm5, [rsp + 50h]
117 add rsp, 68h
118
119 test al, al
120
121 pop r11
122 pop r10
123 pop r9
124 pop r8
125 pop rdx
126 pop rcx
127 pop rax ; restore all volatile registers
128 jnz @F
129 jmp mOriginalHandler
130 @@:
131 add rsp, 08h ; skip error code for PF
132 iretq
133 PageFaultHandlerHook ENDP
134
135 END