1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
3 ; This program and the accompanying materials
4 ; are licensed and made available under the terms and conditions of the BSD License
5 ; which accompanies this distribution. The full text of the license may be found at
6 ; http://opensource.org/licenses/bsd-license.php.
8 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 ; This is the assembly code for MP support
19 ;-------------------------------------------------------------------------------
22 extern ASM_PFX(InitializeFloatingPointUnits)
26 ;-------------------------------------------------------------------------------------
27 ;RendezvousFunnelProc procedure follows. All APs execute their procedure. This
28 ;procedure serializes all the AP processors through an Init sequence. It must be
29 ;noted that APs arrive here very raw...ie: real mode, no stack.
30 ;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC
32 ;-------------------------------------------------------------------------------------
33 global ASM_PFX(RendezvousFunnelProc)
34 ASM_PFX(RendezvousFunnelProc):
35 RendezvousFunnelProcStart:
36 ; At this point CS = 0x(vv00) and ip= 0x0.
38 mov ebp, eax ; save BIST information
48 mov si, BufferStartLocation
51 mov si, DataSegmentLocation
55 ; Get start address of 32-bit code in low memory (<1MB)
57 mov edi, ModeTransitionMemoryLocation
66 ; Switch to protected mode
68 mov eax, cr0 ; Get control register 0
69 or eax, 000000003h ; Set PE bit (bit #0) & MP
72 ; Switch to 32-bit code in executable memory (>1MB)
76 ; Following code may be copied to memory with type of EfiBootServicesCode.
77 ; This is required at DXE phase if NX is enabled for EfiBootServicesCode of
81 Flat32Start: ; protected mode entry point
90 ; Increment the number of APs executing here as early as possible
91 ; This is decremented in C code when AP is finished executing
93 add edi, NumApsExecutingLocation
97 add edi, EnableExecuteDisableLocation
99 jz SkipEnableExecuteDisable
102 ; Enable IA32 PAE execute disable
123 SkipEnableExecuteDisable:
125 add edi, InitFlagLocation
126 cmp dword [edi], 1 ; 1 == ApInitConfig
131 add edi, LockLocation
132 mov eax, NotVacantFlag
136 cmp eax, NotVacantFlag
140 add ecx, ApIndexLocation
149 add edi, StackSizeLocation
153 mul ecx ; EAX = StackSize * (CpuNumber + 1)
155 add edi, StackStartAddressLocation
164 jb NoX2Apic ; CPUID level below CPUID_EXTENDED_TOPOLOGY
170 jz NoX2Apic ; CPUID.0BH:EBX[15:0] is zero
172 ; Processor is x2APIC capable; 32-bit x2APIC ID is already in EDX
173 jmp GetProcessorNumber
176 ; Processor is not x2APIC capable, so get 8-bit APIC ID
184 ; Get processor number for this AP
185 ; Note that BSP may become an AP due to SwitchBsp()
188 lea eax, [esi + CpuInfoLocation]
192 cmp [edi], edx ; APIC ID match?
196 jmp GetNextProcNumber
202 push ebp ; push BIST data at top of AP stack
203 xor ebp, ebp ; clear ebp for call stack trace
207 mov eax, ASM_PFX(InitializeFloatingPointUnits)
208 call eax ; Call assembly function to initialize FPU per UEFI spec
210 push ebx ; Push ApIndex
212 add eax, LockLocation
213 push eax ; push address of exchange info data buffer
216 add edi, ApProcedureLocation
219 call eax ; Invoke C function
221 jmp $ ; Never reach here
222 RendezvousFunnelProcEnd:
224 ;-------------------------------------------------------------------------------------
225 ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish);
226 ;-------------------------------------------------------------------------------------
227 global ASM_PFX(AsmRelocateApLoop)
228 ASM_PFX(AsmRelocateApLoop):
229 AsmRelocateApLoopStart:
231 mov esp, [eax + 16] ; TopOfApStack
232 push dword [eax] ; push return address for stack trace
235 mov ebx, [eax + 8] ; ApTargetCState
236 mov ecx, [eax + 4] ; MwaitSupport
237 mov eax, [eax + 20] ; CountTofinish
238 lock dec dword [eax] ; (*CountTofinish)--
239 cmp cl, 1 ; Check mwait-monitor support
247 mov eax, ebx ; Mwait Cx, Target C-State per eax[7:4]
255 AsmRelocateApLoopEnd:
257 ;-------------------------------------------------------------------------------------
258 ; AsmGetAddressMap (&AddressMap);
259 ;-------------------------------------------------------------------------------------
260 global ASM_PFX(AsmGetAddressMap)
261 ASM_PFX(AsmGetAddressMap):
266 mov dword [ebx], RendezvousFunnelProcStart
267 mov dword [ebx + 4h], Flat32Start - RendezvousFunnelProcStart
268 mov dword [ebx + 8h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart
269 mov dword [ebx + 0Ch], AsmRelocateApLoopStart
270 mov dword [ebx + 10h], AsmRelocateApLoopEnd - AsmRelocateApLoopStart
271 mov dword [ebx + 14h], Flat32Start - RendezvousFunnelProcStart
276 ;-------------------------------------------------------------------------------------
277 ;AsmExchangeRole procedure follows. This procedure executed by current BSP, that is
278 ;about to become an AP. It switches it'stack with the current AP.
279 ;AsmExchangeRole (IN CPU_EXCHANGE_INFO *MyInfo, IN CPU_EXCHANGE_INFO *OthersInfo);
280 ;-------------------------------------------------------------------------------------
281 global ASM_PFX(AsmExchangeRole)
282 ASM_PFX(AsmExchangeRole):
283 ; DO NOT call other functions in this function, since 2 CPU may use 1 stack
284 ; at the same time. If 1 CPU try to call a function, stack will be corrupted.
288 ; esi contains MyInfo pointer
291 ; edi contains OthersInfo pointer
294 ;Store EFLAGS, GDTR and IDTR register to stack
297 push eax ; push cr4 firstly
304 ; Store the its StackPointer
307 ; update its switch state to STORED
308 mov byte [esi], CPU_SWITCH_STATE_STORED
311 ; wait until the other CPU finish storing its state
312 cmp byte [edi], CPU_SWITCH_STATE_STORED
315 jmp WaitForOtherStored
318 ; Since another CPU already stored its state, load them
325 ; load its future StackPointer
328 ; update the other CPU's switch state to LOADED
329 mov byte [edi], CPU_SWITCH_STATE_LOADED
332 ; wait until the other CPU finish loading new state,
333 ; otherwise the data in stack may corrupt
334 cmp byte [esi], CPU_SWITCH_STATE_LOADED
337 jmp WaitForOtherLoaded
340 ; since the other CPU already get the data it want, leave this procedure