1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2015, 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 di, PmodeOffsetLocation
67 mov eax, cr0 ;Get control register 0
68 or eax, 000000003h ;Set PE bit (bit #0) & MP
71 jmp PROTECT_MODE_CS:strict dword 0 ; far jump to protected mode
73 Flat32Start: ; protected mode entry point
74 mov ax, PROTECT_MODE_DS
84 mov eax, NotVacantFlag
88 cmp eax, NotVacantFlag
92 add edi, NumApsExecutingLoction
98 add edi, StackSizeLocation
101 add edi, StackStartAddressLocation
109 add edi, LockLocation
113 push ebp ; push BIST data at top of AP stack
114 xor ebp, ebp ; clear ebp for call stack trace
118 mov eax, ASM_PFX(InitializeFloatingPointUnits)
119 call eax ; Call assembly function to initialize FPU per UEFI spec
121 push ebx ; Push NumApsExecuting
123 add eax, LockLocation
124 push eax ; push address of exchange info data buffer
127 add edi, ApProcedureLocation
130 call eax ; invoke C function
132 jmp $ ; never reach here
133 RendezvousFunnelProcEnd:
135 ;-------------------------------------------------------------------------------------
136 ; AsmGetAddressMap (&AddressMap);
137 ;-------------------------------------------------------------------------------------
138 global ASM_PFX(AsmGetAddressMap)
139 ASM_PFX(AsmGetAddressMap):
144 mov dword [ebx], RendezvousFunnelProcStart
145 mov dword [ebx + 4h], Flat32Start - RendezvousFunnelProcStart
146 mov dword [ebx + 8h], 0
147 mov dword [ebx + 0ch], RendezvousFunnelProcEnd - RendezvousFunnelProcStart
152 ;-------------------------------------------------------------------------------------
153 ;AsmExchangeRole procedure follows. This procedure executed by current BSP, that is
154 ;about to become an AP. It switches it'stack with the current AP.
155 ;AsmExchangeRole (IN CPU_EXCHANGE_INFO *MyInfo, IN CPU_EXCHANGE_INFO *OthersInfo);
156 ;-------------------------------------------------------------------------------------
157 global ASM_PFX(AsmExchangeRole)
158 ASM_PFX(AsmExchangeRole):
159 ; DO NOT call other functions in this function, since 2 CPU may use 1 stack
160 ; at the same time. If 1 CPU try to call a function, stack will be corrupted.
164 ; esi contains MyInfo pointer
167 ; edi contains OthersInfo pointer
170 ;Store EFLAGS, GDTR and IDTR register to stack
173 push eax ; push cr4 firstly
180 ; Store the its StackPointer
183 ; update its switch state to STORED
184 mov byte [esi], CPU_SWITCH_STATE_STORED
187 ; wait until the other CPU finish storing its state
188 cmp byte [edi], CPU_SWITCH_STATE_STORED
191 jmp WaitForOtherStored
194 ; Since another CPU already stored its state, load them
201 ; load its future StackPointer
204 ; update the other CPU's switch state to LOADED
205 mov byte [edi], CPU_SWITCH_STATE_LOADED
208 ; wait until the other CPU finish loading new state,
209 ; otherwise the data in stack may corrupt
210 cmp byte [esi], CPU_SWITCH_STATE_LOADED
213 jmp WaitForOtherLoaded
216 ; since the other CPU already get the data it want, leave this procedure
226 global ASM_PFX(AsmInitializeGdt)
227 ASM_PFX(AsmInitializeGdt):
231 mov edi, [ebp + 8] ; Load GDT register
233 lgdt [edi] ; and update the GDTR
236 mov eax, ASM_PFX(SetCodeSelectorFarJump)
239 ASM_PFX(SetCodeSelectorFarJump):
240 mov ax, PROTECT_MODE_DS ; Update the Base for the new selectors, too