]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe: Add support for PCD PcdPteMemoryEn...
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / BootScriptExecutorDxe / X64 / S3Asm.S
CommitLineData
be46cd5f 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
d9a1844e 5# Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
be46cd5f 6#\r
7# This program and the accompanying materials are\r
8# 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
17ASM_GLOBAL ASM_PFX(AsmTransferControl)\r
18ASM_PFX(AsmTransferControl):\r
19 # rcx S3WakingVector :DWORD\r
20 # rdx AcpiLowMemoryBase :DWORD\r
d9a1844e 21 lea _AsmTransferControl_al_0000(%rip), %eax \r
be46cd5f 22 movq $0x2800000000, %r8 \r
23 orq %r8, %rax\r
24 pushq %rax\r
25 shrd $20, %ecx, %ebx\r
26 andl $0x0f, %ecx \r
27 movw %cx, %bx\r
d9a1844e 28 movl %ebx, jmp_addr(%rip) \r
be46cd5f 29 lret\r
30_AsmTransferControl_al_0000:\r
31 .byte 0x0b8, 0x30, 0 # mov ax, 30h as selector\r
32 movl %eax, %ds\r
33 movl %eax, %es\r
34 movl %eax, %fs\r
35 movl %eax, %gs\r
36 movl %eax, %ss\r
37 movq %cr0, %rax\r
38 movq %cr4, %rbx\r
39 .byte 0x66\r
40 andl $0x7ffffffe, %eax \r
41 andb $0xdf, %bl \r
42 movq %rax, %cr0\r
43 .byte 0x66\r
44 movl $0x0c0000080, %ecx \r
45 rdmsr\r
46 andb $0xfe, %ah \r
47 wrmsr\r
48 movq %rbx, %cr4\r
49 .byte 0x0ea # jmp far jmp_addr\r
50jmp_addr:\r
51 .long 0\r
52\r
53ASM_GLOBAL ASM_PFX(AsmTransferControl32)\r
54ASM_PFX(AsmTransferControl32):\r
55 # S3WakingVector :DWORD\r
56 # AcpiLowMemoryBase :DWORD\r
57 pushq %rbp\r
58 movl %esp,%ebp\r
59 .byte 0x8d, 0x05 # lea eax, AsmTransferControl16\r
60ASM_GLOBAL ASM_PFX(AsmFixAddress16)\r
61ASM_PFX(AsmFixAddress16):\r
62 .long 0\r
63 pushq $0x28 # CS\r
64 pushq %rax\r
65 lret\r
66\r
67ASM_GLOBAL ASM_PFX(AsmTransferControl16)\r
68ASM_PFX(AsmTransferControl16):\r
69 .byte 0xb8,0x30,0 # mov ax, 30h as selector\r
70 movw %ax,%ds\r
71 movw %ax,%es\r
72 movw %ax,%fs\r
73 movw %ax,%gs\r
74 movw %ax,%ss\r
75 movq %cr0, %rax # Get control register 0 \r
76 .byte 0x66\r
77 .byte 0x83,0xe0,0xfe # and eax, 0fffffffeh ; Clear PE bit (bit #0)\r
78 .byte 0xf,0x22,0xc0 # mov cr0, eax ; Activate real mode\r
79 .byte 0xea # jmp far AsmJmpAddr32\r
80ASM_GLOBAL ASM_PFX(AsmJmpAddr32)\r
81ASM_PFX(AsmJmpAddr32):\r
82 .long 0\r
d0bf5623
JY
83\r
84ASM_GLOBAL ASM_PFX(PageFaultHandlerHook)\r
85ASM_PFX(PageFaultHandlerHook):\r
86 pushq %rax # save all volatile registers\r
87 pushq %rcx\r
88 pushq %rdx\r
89 pushq %r8\r
90 pushq %r9\r
91 pushq %r10\r
92 pushq %r11\r
93 # save volatile fp registers\r
94 addq $-0x68, %rsp\r
95 stmxcsr 0x60(%rsp)\r
96 movdqa %xmm0, 0x0(%rsp) \r
97 movdqa %xmm1, 0x10(%rsp) \r
98 movdqa %xmm2, 0x20(%rsp) \r
99 movdqa %xmm3, 0x30(%rsp) \r
100 movdqa %xmm4, 0x40(%rsp) \r
101 movdqa %xmm5, 0x50(%rsp) \r
102\r
103 addq $-0x20, %rsp\r
104 call ASM_PFX(PageFaultHandler)\r
105 addq $0x20, %rsp\r
106\r
107 # load volatile fp registers\r
108 ldmxcsr 0x60(%rsp)\r
109 movdqa 0x0(%rsp), %xmm0\r
110 movdqa 0x10(%rsp), %xmm1\r
111 movdqa 0x20(%rsp), %xmm2\r
112 movdqa 0x30(%rsp), %xmm3\r
113 movdqa 0x40(%rsp), %xmm4\r
114 movdqa 0x50(%rsp), %xmm5\r
115 addq $0x68, %rsp\r
116\r
117 testb %al, %al\r
118\r
119 popq %r11\r
120 popq %r10\r
121 popq %r9\r
122 popq %r8\r
123 popq %rdx\r
124 popq %rcx\r
125 popq %rax # restore all volatile registers\r
126 jnz L1\r
d9a1844e 127 jmpq *ASM_PFX(mOriginalHandler)(%rip)\r
d0bf5623
JY
128L1:\r
129 addq $0x08, %rsp # skip error code for PF\r
130 iretq\r