]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c
UefiCpuPkg/PiSmmCpuDxeSmm: patch "gSmmCr3" with PatchInstructionX86()
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / X64 / Semaphore.c
CommitLineData
427e3573
MK
1/** @file\r
2Semaphore mechanism to indicate to the BSP that an AP has exited SMM\r
3after SMBASE relocation.\r
4\r
5Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "PiSmmCpuDxeSmm.h"\r
17\r
18extern UINT32 mSmmRelocationOriginalAddressPtr32;\r
19extern UINT32 mRebasedFlagAddr32;\r
20\r
21UINTN mSmmRelocationOriginalAddress;\r
22volatile BOOLEAN *mRebasedFlag;\r
23\r
24/**\r
25AP Semaphore operation in 32-bit mode while BSP runs in 64-bit mode.\r
26**/\r
27VOID\r
28SmmRelocationSemaphoreComplete32 (\r
29 VOID\r
30 );\r
31\r
32/**\r
33 Hook return address of SMM Save State so that semaphore code\r
34 can be executed immediately after AP exits SMM to indicate to\r
35 the BSP that an AP has exited SMM after SMBASE relocation.\r
36\r
37 @param[in] CpuIndex The processor index.\r
38 @param[in] RebasedFlag A pointer to a flag that is set to TRUE\r
39 immediately after AP exits SMM.\r
40\r
41**/\r
42VOID\r
43SemaphoreHook (\r
44 IN UINTN CpuIndex,\r
45 IN volatile BOOLEAN *RebasedFlag\r
46 )\r
47{\r
48 SMRAM_SAVE_STATE_MAP *CpuState;\r
49 UINTN TempValue;\r
50\r
51 mRebasedFlag = RebasedFlag;\r
52 mRebasedFlagAddr32 = (UINT32)(UINTN)mRebasedFlag;\r
53\r
54 CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);\r
55 mSmmRelocationOriginalAddress = HookReturnFromSmm (\r
56 CpuIndex,\r
57 CpuState,\r
58 (UINT64)(UINTN)&SmmRelocationSemaphoreComplete32,\r
59 (UINT64)(UINTN)&SmmRelocationSemaphoreComplete\r
60 );\r
61\r
62 //\r
63 // Use temp value to fix ICC complier warning\r
64 //\r
65 TempValue = (UINTN)&mSmmRelocationOriginalAddress;\r
66 mSmmRelocationOriginalAddressPtr32 = (UINT32)TempValue;\r
67}\r