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