/* Hook return address of SMM Save State so that semaphore code can be executed immediately after AP exits SMM to indicate to the BSP that an AP has exited SMM after SMBASE relocation. */
VOID SemaphoreHook(IN UINTN CpuIndex, IN volatile BOOLEAN *RebasedFlag)
/* Hook return address of SMM Save State so that semaphore code can be executed immediately after AP exits SMM to indicate to the BSP that an AP has exited SMM after SMBASE relocation. */
VOID SemaphoreHook(IN UINTN CpuIndex, IN volatile BOOLEAN *RebasedFlag)
{
  SMRAM_SAVE_STATE_MAP  *CpuState;
  UINTN                 TempValue;
  mRebasedFlag = RebasedFlag;
  PatchInstructionX86 (
    gPatchRebasedFlagAddr32,
    (UINT32)(UINTN)mRebasedFlag,
    4
    );
  CpuState                      = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);
  mSmmRelocationOriginalAddress = HookReturnFromSmm (
                                    CpuIndex,
                                    CpuState,
                                    (UINT64)(UINTN)&SmmRelocationSemaphoreComplete32,
                                    (UINT64)(UINTN)&SmmRelocationSemaphoreComplete
                                    );
  TempValue = (UINTN)&mSmmRelocationOriginalAddress;
  PatchInstructionX86 (
    gPatchSmmRelocationOriginalAddressPtr32,
    (UINT32)TempValue,
    4
    );
}