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