\r
UINT8 *mApHltLoopCode = NULL;\r
UINT8 mApHltLoopCodeTemplate[] = {\r
- 0xFA, // cli\r
- 0xF4, // hlt\r
- 0xEB, 0xFC // jmp $-2\r
+ 0x8B, 0x44, 0x24, 0x04, // mov eax, dword ptr [esp+4]\r
+ 0xF0, 0xFF, 0x08, // lock dec dword ptr [eax]\r
+ 0xFA, // cli\r
+ 0xF4, // hlt\r
+ 0xEB, 0xFC // jmp $-2\r
};\r
\r
/**\r
}\r
\r
//\r
- // Count down the number with lock mechanism.\r
- //\r
- InterlockedDecrement (&mNumberToFinish);\r
-\r
- //\r
- // Place AP into the safe code\r
+ // Place AP into the safe code, count down the number with lock mechanism in the safe code.\r
//\r
TopOfStack = (UINT32) (UINTN) Stack + sizeof (Stack);\r
TopOfStack &= ~(UINT32) (CPU_STACK_ALIGNMENT - 1);\r
CopyMem ((VOID *) (UINTN) mApHltLoopCode, mApHltLoopCodeTemplate, sizeof (mApHltLoopCodeTemplate));\r
- TransferApToSafeState ((UINT32) (UINTN) mApHltLoopCode, TopOfStack);\r
+ TransferApToSafeState ((UINT32) (UINTN) mApHltLoopCode, TopOfStack, &mNumberToFinish);\r
}\r
\r
/**\r
\r
@param[in] ApHltLoopCode The 32-bit address of the safe hlt-loop function.\r
@param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode.\r
+ @param[in] NumberToFinish Semaphore of APs finish count.\r
\r
**/\r
VOID\r
TransferApToSafeState (\r
IN UINT32 ApHltLoopCode,\r
- IN UINT32 TopOfStack\r
+ IN UINT32 TopOfStack,\r
+ IN UINT32 *NumberToFinish\r
)\r
{\r
SwitchStack (\r
(SWITCH_STACK_ENTRY_POINT) (UINTN) ApHltLoopCode,\r
- NULL,\r
+ NumberToFinish,\r
NULL,\r
(VOID *) (UINTN) TopOfStack\r
);\r
\r
@param[in] ApHltLoopCode The 32-bit address of the safe hlt-loop function.\r
@param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode.\r
+ @param[in] NumberToFinish Semaphore of APs finish count.\r
\r
**/\r
VOID\r
TransferApToSafeState (\r
IN UINT32 ApHltLoopCode,\r
- IN UINT32 TopOfStack\r
+ IN UINT32 TopOfStack,\r
+ IN UINT32 *NumberToFinish\r
);\r
\r
#endif\r
\r
@param[in] ApHltLoopCode The 32-bit address of the safe hlt-loop function.\r
@param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode.\r
+ @param[in] NumberToFinish Semaphore of APs finish count.\r
\r
**/\r
VOID\r
TransferApToSafeState (\r
IN UINT32 ApHltLoopCode,\r
- IN UINT32 TopOfStack\r
+ IN UINT32 TopOfStack,\r
+ IN UINT32 *NumberToFinish\r
)\r
{\r
AsmDisablePaging64 (\r
GetProtectedModeCS (),\r
(UINT32) (UINTN) ApHltLoopCode,\r
- 0,\r
+ (UINT32) (UINTN) NumberToFinish,\r
0,\r
TopOfStack\r
);\r