#include <Library/UefiBootServicesTableLib.h>\r
\r
#define AP_CHECK_INTERVAL (EFI_TIMER_PERIOD_MILLISECONDS (100))\r
+#define AP_SAFE_STACK_SIZE 128\r
\r
CPU_MP_DATA *mCpuMpData = NULL;\r
EFI_EVENT mCheckAllApsEvent = NULL;\r
EFI_EVENT mLegacyBootEvent = NULL;\r
volatile BOOLEAN mStopCheckAllApsStatus = TRUE;\r
VOID *mReservedApLoopFunc = NULL;\r
+UINTN mReservedTopOfApStack;\r
\r
/**\r
Get the pointer to CPU MP Data structure.\r
CPU_MP_DATA *CpuMpData;\r
BOOLEAN MwaitSupport;\r
ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc;\r
+ UINTN ProcessorNumber;\r
\r
+ MpInitLibWhoAmI (&ProcessorNumber); \r
CpuMpData = GetCpuMpData ();\r
MwaitSupport = IsMwaitSupport ();\r
AsmRelocateApLoopFunc = (ASM_RELOCATE_AP_LOOP) (UINTN) mReservedApLoopFunc;\r
- AsmRelocateApLoopFunc (MwaitSupport, CpuMpData->ApTargetCState, CpuMpData->PmCodeSegment);\r
+ AsmRelocateApLoopFunc (\r
+ MwaitSupport,\r
+ CpuMpData->ApTargetCState,\r
+ CpuMpData->PmCodeSegment,\r
+ mReservedTopOfApStack - ProcessorNumber * AP_SAFE_STACK_SIZE\r
+ );\r
//\r
// It should never reach here\r
//\r
{\r
EFI_STATUS Status;\r
EFI_PHYSICAL_ADDRESS Address;\r
+ UINTN ApSafeBufferSize;\r
\r
SaveCpuMpData (CpuMpData);\r
\r
// Allocating it in advance since memory services are not available in\r
// Exit Boot Services callback function.\r
//\r
+ ApSafeBufferSize = CpuMpData->AddressMap.RelocateApLoopFuncSize;\r
+ ApSafeBufferSize += CpuMpData->CpuCount * AP_SAFE_STACK_SIZE;\r
+\r
Address = BASE_4GB - 1;\r
Status = gBS->AllocatePages (\r
AllocateMaxAddress,\r
EfiReservedMemoryType,\r
- EFI_SIZE_TO_PAGES (sizeof (CpuMpData->AddressMap.RelocateApLoopFuncSize)),\r
+ EFI_SIZE_TO_PAGES (ApSafeBufferSize),\r
&Address\r
);\r
ASSERT_EFI_ERROR (Status);\r
mReservedApLoopFunc = (VOID *) (UINTN) Address;\r
ASSERT (mReservedApLoopFunc != NULL);\r
+ mReservedTopOfApStack = (UINTN) Address + EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (ApSafeBufferSize));\r
+ ASSERT ((mReservedTopOfApStack & (UINTN)(CPU_STACK_ALIGNMENT - 1)) == 0);\r
CopyMem (\r
mReservedApLoopFunc,\r
CpuMpData->AddressMap.RelocateApLoopFuncAddress,\r
RendezvousFunnelProcEnd:\r
\r
;-------------------------------------------------------------------------------------\r
-; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment);\r
+; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack);\r
;-------------------------------------------------------------------------------------\r
global ASM_PFX(AsmRelocateApLoop)\r
ASM_PFX(AsmRelocateApLoop):\r
AsmRelocateApLoopStart:\r
- cmp byte [esp + 4], 1\r
+ mov eax, esp\r
+ mov esp, [eax + 16] ; TopOfApStack\r
+ push dword [eax] ; push return address for stack trace\r
+ push ebp\r
+ mov ebp, esp\r
+ mov ebx, [eax + 8] ; ApTargetCState\r
+ mov ecx, [eax + 4] ; MwaitSupport\r
+ cmp cl, 1 ; Check mwait-monitor support\r
jnz HltLoop\r
MwaitLoop:\r
mov eax, esp\r
xor ecx, ecx\r
xor edx, edx\r
monitor\r
- mov eax, [esp + 8] ; Mwait Cx, Target C-State per eax[7:4]\r
+ mov eax, ebx ; Mwait Cx, Target C-State per eax[7:4]\r
shl eax, 4\r
mwait\r
jmp MwaitLoop\r
RendezvousFunnelProcEnd:\r
\r
;-------------------------------------------------------------------------------------\r
-; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment);\r
+; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack);\r
;-------------------------------------------------------------------------------------\r
global ASM_PFX(AsmRelocateApLoop)\r
ASM_PFX(AsmRelocateApLoop):\r
AsmRelocateApLoopStart:\r
+ mov rsp, r9\r
push rcx\r
push rdx\r
\r