1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2015 - 2016, 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, ModeOffsetLocation
53 mov si, CodeSegmentLocation
62 mov si, DataSegmentLocation
74 mov eax, cr0 ; Get control register 0
75 or eax, 000000003h ; Set PE bit (bit #0) & MP
78 jmp 0:strict dword 0 ; far jump to protected mode
80 Flat32Start: ; protected mode entry point
90 add edi, EnableExecuteDisableLocation
92 jz SkipEnableExecuteDisable
95 ; Enable IA32 PAE execute disable
116 SkipEnableExecuteDisable:
118 add edi, InitFlagLocation
119 cmp dword [edi], 1 ; 1 == ApInitConfig
124 add edi, LockLocation
125 mov eax, NotVacantFlag
129 cmp eax, NotVacantFlag
133 add ecx, ApIndexLocation
142 add edi, StackSizeLocation
146 mul ecx ; EAX = StackSize * (CpuNumber + 1)
148 add edi, StackStartAddressLocation
157 jb NoX2Apic ; CPUID level below CPUID_EXTENDED_TOPOLOGY
163 jz NoX2Apic ; CPUID.0BH:EBX[15:0] is zero
165 ; Processor is x2APIC capable; 32-bit x2APIC ID is already in EDX
166 jmp GetProcessorNumber
169 ; Processor is not x2APIC capable, so get 8-bit APIC ID
177 ; Get processor number for this AP
178 ; Note that BSP may become an AP due to SwitchBsp()
181 lea eax, [esi + CpuInfoLocation]
185 cmp [edi], edx ; APIC ID match?
189 jmp GetNextProcNumber
195 push ebp ; push BIST data at top of AP stack
196 xor ebp, ebp ; clear ebp for call stack trace
200 mov eax, ASM_PFX(InitializeFloatingPointUnits)
201 call eax ; Call assembly function to initialize FPU per UEFI spec
203 push ebx ; Push ApIndex
205 add eax, LockLocation
206 push eax ; push address of exchange info data buffer
209 add edi, ApProcedureLocation
212 call eax ; Invoke C function
214 jmp $ ; Never reach here
215 RendezvousFunnelProcEnd:
217 ;-------------------------------------------------------------------------------------
218 ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish);
219 ;-------------------------------------------------------------------------------------
220 global ASM_PFX(AsmRelocateApLoop)
221 ASM_PFX(AsmRelocateApLoop):
222 AsmRelocateApLoopStart:
224 mov esp, [eax + 16] ; TopOfApStack
225 push dword [eax] ; push return address for stack trace
228 mov ebx, [eax + 8] ; ApTargetCState
229 mov ecx, [eax + 4] ; MwaitSupport
230 mov eax, [eax + 20] ; CountTofinish
231 lock dec dword [eax] ; (*CountTofinish)--
232 cmp cl, 1 ; Check mwait-monitor support
239 mov eax, ebx ; Mwait Cx, Target C-State per eax[7:4]
247 AsmRelocateApLoopEnd:
249 ;-------------------------------------------------------------------------------------
250 ; AsmGetAddressMap (&AddressMap);
251 ;-------------------------------------------------------------------------------------
252 global ASM_PFX(AsmGetAddressMap)
253 ASM_PFX(AsmGetAddressMap):
258 mov dword [ebx], RendezvousFunnelProcStart
259 mov dword [ebx + 4h], Flat32Start - RendezvousFunnelProcStart
260 mov dword [ebx + 8h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart
261 mov dword [ebx + 0Ch], AsmRelocateApLoopStart
262 mov dword [ebx + 10h], AsmRelocateApLoopEnd - AsmRelocateApLoopStart
267 ;-------------------------------------------------------------------------------------
268 ;AsmExchangeRole procedure follows. This procedure executed by current BSP, that is
269 ;about to become an AP. It switches it'stack with the current AP.
270 ;AsmExchangeRole (IN CPU_EXCHANGE_INFO *MyInfo, IN CPU_EXCHANGE_INFO *OthersInfo);
271 ;-------------------------------------------------------------------------------------
272 global ASM_PFX(AsmExchangeRole)
273 ASM_PFX(AsmExchangeRole):
274 ; DO NOT call other functions in this function, since 2 CPU may use 1 stack
275 ; at the same time. If 1 CPU try to call a function, stack will be corrupted.
279 ; esi contains MyInfo pointer
282 ; edi contains OthersInfo pointer
285 ;Store EFLAGS, GDTR and IDTR register to stack
288 push eax ; push cr4 firstly
295 ; Store the its StackPointer
298 ; update its switch state to STORED
299 mov byte [esi], CPU_SWITCH_STATE_STORED
302 ; wait until the other CPU finish storing its state
303 cmp byte [edi], CPU_SWITCH_STATE_STORED
306 jmp WaitForOtherStored
309 ; Since another CPU already stored its state, load them
316 ; load its future StackPointer
319 ; update the other CPU's switch state to LOADED
320 mov byte [edi], CPU_SWITCH_STATE_LOADED
323 ; wait until the other CPU finish loading new state,
324 ; otherwise the data in stack may corrupt
325 cmp byte [esi], CPU_SWITCH_STATE_LOADED
328 jmp WaitForOtherLoaded
331 ; since the other CPU already get the data it want, leave this procedure