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