1 /*++ @file
2   Temp RAM PPI
3 
4 Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #include <PiPei.h>
10 #include <Library/DebugLib.h>
11 #include <Library/BaseMemoryLib.h>
12 
13 #include <Ppi/TemporaryRamSupport.h>
14 
15 VOID
16 EFIAPI
17 SecSwitchStack (
18   UINT32   TemporaryMemoryBase,
19   UINT32   PermenentMemoryBase
20   );
21 
22 
23 EFI_STATUS
24 EFIAPI
25 SecTemporaryRamSupport (
26   IN CONST EFI_PEI_SERVICES   **PeiServices,
27   IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,
28   IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,
29   IN UINTN                    CopySize
30   )
31 {
32   //
33   // Migrate the whole temporary memory to permanent memory.
34   //
35   CopyMem (
36     (VOID*)(UINTN)PermanentMemoryBase,
37     (VOID*)(UINTN)TemporaryMemoryBase,
38     CopySize
39     );
40 
41   //
42   // SecSwitchStack function must be invoked after the memory migration
43   // immediately, also we need fixup the stack change caused by new call into
44   // permanent memory.
45   //
46   SecSwitchStack ((UINT32) TemporaryMemoryBase, (UINT32) PermanentMemoryBase);
47 
48   //
49   // We need *not* fix the return address because currently,
50   // The PeiCore is executed in flash.
51   //
52 
53   //
54   // Simulate to invalid temporary memory, terminate temporary memory
55   //
56   //ZeroMem ((VOID*)(UINTN)TemporaryMemoryBase, CopySize);
57 
58   return EFI_SUCCESS;
59 }
60