]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/PiSmmCpuDxeSmm/X64/MpFuncs.nasm
UefiCpuPkg/PiSmmCpuDxeSmm: patch "gSmbase" with PatchInstructionX86()
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / X64 / MpFuncs.nasm
CommitLineData
78cf66ee 1;------------------------------------------------------------------------------ ;\r
e21e355e 2; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r
78cf66ee
LG
3; This program and the accompanying materials\r
4; are licensed and made available under the terms and conditions of the BSD License\r
5; which accompanies this distribution. The full text of the license may be found at\r
6; http://opensource.org/licenses/bsd-license.php.\r
7;\r
8; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
9; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
10;\r
11; Module Name:\r
12;\r
13; MpFuncs.nasm\r
14;\r
15; Abstract:\r
16;\r
17; This is the assembly code for Multi-processor S3 support\r
18;\r
19;-------------------------------------------------------------------------------\r
20\r
78cf66ee
LG
21%define VacantFlag 0x0\r
22%define NotVacantFlag 0xff\r
23\r
24%define LockLocation RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
25%define StackStartAddressLocation LockLocation + 0x8\r
26%define StackSizeLocation LockLocation + 0x10\r
27%define CProcedureLocation LockLocation + 0x18\r
28%define GdtrLocation LockLocation + 0x20\r
29%define IdtrLocation LockLocation + 0x2A\r
30%define BufferStartLocation LockLocation + 0x34\r
31%define Cr3OffsetLocation LockLocation + 0x38\r
e21e355e 32%define InitializeFloatingPointUnitsAddress LockLocation + 0x3C\r
78cf66ee
LG
33\r
34;-------------------------------------------------------------------------------------\r
35;RendezvousFunnelProc procedure follows. All APs execute their procedure. This\r
36;procedure serializes all the AP processors through an Init sequence. It must be\r
37;noted that APs arrive here very raw...ie: real mode, no stack.\r
38;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC\r
39;IS IN MACHINE CODE.\r
40;-------------------------------------------------------------------------------------\r
41;RendezvousFunnelProc (&WakeUpBuffer,MemAddress);\r
42\r
43;text SEGMENT\r
44DEFAULT REL\r
45SECTION .text\r
46\r
e1f0eed1 47BITS 16\r
78cf66ee
LG
48global ASM_PFX(RendezvousFunnelProc)\r
49ASM_PFX(RendezvousFunnelProc):\r
50RendezvousFunnelProcStart:\r
51\r
52; At this point CS = 0x(vv00) and ip= 0x0.\r
53\r
e1f0eed1
LG
54 mov ax, cs\r
55 mov ds, ax\r
56 mov es, ax\r
57 mov ss, ax\r
58 xor ax, ax\r
59 mov fs, ax\r
60 mov gs, ax\r
78cf66ee
LG
61\r
62flat32Start:\r
63\r
e1f0eed1
LG
64 mov si, BufferStartLocation\r
65 mov edx,dword [si] ; EDX is keeping the start address of wakeup buffer\r
78cf66ee 66\r
e1f0eed1
LG
67 mov si, Cr3OffsetLocation\r
68 mov ecx,dword [si] ; ECX is keeping the value of CR3\r
78cf66ee 69\r
e1f0eed1
LG
70 mov si, GdtrLocation\r
71o32 lgdt [cs:si]\r
78cf66ee 72\r
e1f0eed1
LG
73 mov si, IdtrLocation\r
74o32 lidt [cs:si]\r
78cf66ee 75\r
e1f0eed1
LG
76 xor ax, ax\r
77 mov ds, ax\r
78cf66ee 78\r
e1f0eed1
LG
79 mov eax, cr0 ; Get control register 0\r
80 or eax, 0x000000001 ; Set PE bit (bit #0)\r
81 mov cr0, eax\r
78cf66ee
LG
82\r
83FLAT32_JUMP:\r
84\r
e1f0eed1 85a32 jmp dword 0x20:0x0\r
78cf66ee 86\r
e1f0eed1 87BITS 32\r
78cf66ee
LG
88PMODE_ENTRY: ; protected mode entry point\r
89\r
e1f0eed1
LG
90 mov ax, 0x18\r
91o16 mov ds, ax\r
92o16 mov es, ax\r
93o16 mov fs, ax\r
94o16 mov gs, ax\r
95o16 mov ss, ax ; Flat mode setup.\r
78cf66ee 96\r
e1f0eed1
LG
97 mov eax, cr4\r
98 bts eax, 5\r
99 mov cr4, eax\r
78cf66ee 100\r
e1f0eed1 101 mov cr3, ecx\r
78cf66ee 102\r
e1f0eed1 103 mov esi, edx ; Save wakeup buffer address\r
78cf66ee 104\r
e1f0eed1
LG
105 mov ecx, 0xc0000080 ; EFER MSR number.\r
106 rdmsr ; Read EFER.\r
107 bts eax, 8 ; Set LME=1.\r
108 wrmsr ; Write EFER.\r
78cf66ee 109\r
e1f0eed1
LG
110 mov eax, cr0 ; Read CR0.\r
111 bts eax, 31 ; Set PG=1.\r
112 mov cr0, eax ; Write CR0.\r
78cf66ee
LG
113\r
114LONG_JUMP:\r
115\r
e1f0eed1 116a16 jmp dword 0x38:0x0\r
78cf66ee 117\r
e1f0eed1 118BITS 64\r
78cf66ee
LG
119LongModeStart:\r
120\r
121 mov ax, 0x30\r
122o16 mov ds, ax\r
123o16 mov es, ax\r
124o16 mov ss, ax\r
125\r
126 mov edi, esi\r
127 add edi, LockLocation\r
128 mov al, NotVacantFlag\r
129TestLock:\r
130 xchg byte [edi], al\r
131 cmp al, NotVacantFlag\r
132 jz TestLock\r
133\r
134ProgramStack:\r
135\r
136 mov edi, esi\r
137 add edi, StackSizeLocation\r
138 mov rax, qword [edi]\r
139 mov edi, esi\r
140 add edi, StackStartAddressLocation\r
141 add rax, qword [edi]\r
142 mov rsp, rax\r
143 mov qword [edi], rax\r
144\r
145Releaselock:\r
146\r
147 mov al, VacantFlag\r
148 mov edi, esi\r
149 add edi, LockLocation\r
150 xchg byte [edi], al\r
151\r
152 ;\r
153 ; Call assembly function to initialize FPU.\r
154 ;\r
e21e355e 155 mov rax, qword [esi + InitializeFloatingPointUnitsAddress]\r
78cf66ee
LG
156 sub rsp, 0x20\r
157 call rax\r
158 add rsp, 0x20\r
159\r
160 ;\r
161 ; Call C Function\r
162 ;\r
163 mov edi, esi\r
164 add edi, CProcedureLocation\r
165 mov rax, qword [edi]\r
166\r
167 test rax, rax\r
168 jz GoToSleep\r
169\r
170 sub rsp, 0x20\r
171 call rax\r
172 add rsp, 0x20\r
173\r
174GoToSleep:\r
175 cli\r
176 hlt\r
177 jmp $-2\r
178\r
179RendezvousFunnelProcEnd:\r
180\r
181;-------------------------------------------------------------------------------------\r
182; AsmGetAddressMap (&AddressMap);\r
183;-------------------------------------------------------------------------------------\r
184; comments here for definition of address map\r
185global ASM_PFX(AsmGetAddressMap)\r
186ASM_PFX(AsmGetAddressMap):\r
e21e355e 187 lea rax, [RendezvousFunnelProcStart]\r
78cf66ee
LG
188 mov qword [rcx], rax\r
189 mov qword [rcx+0x8], PMODE_ENTRY - RendezvousFunnelProcStart\r
190 mov qword [rcx+0x10], FLAT32_JUMP - RendezvousFunnelProcStart\r
191 mov qword [rcx+0x18], RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
192 mov qword [rcx+0x20], LongModeStart - RendezvousFunnelProcStart\r
193 mov qword [rcx+0x28], LONG_JUMP - RendezvousFunnelProcStart\r
194 ret\r
195\r