]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Sec/X64/SwitchStack.c
Update the copyright notice format
[mirror_edk2.git] / OvmfPkg / Sec / X64 / SwitchStack.c
CommitLineData
49ba9447 1/** @file\r
2 Switch Stack functions.\r
3\r
56d7640a
HT
4 Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
49ba9447 6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15//\r
16// Include common header file for this module.\r
17//\r
18\r
19\r
20#include <Library/BaseLib.h>\r
21#include <Library/BaseMemoryLib.h>\r
22#include <Library/DebugLib.h>\r
23#include <Library/PeiServicesLib.h>\r
24\r
25//\r
26// Type define for PEI Core Entry Point function\r
27//\r
28typedef\r
29VOID\r
30(EFIAPI *PEI_CORE_ENTRY_POINT)(\r
31 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
32 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r
33 IN VOID *Data\r
34 )\r
35;\r
36\r
37/**\r
38 Transfers control to a function starting with a new stack.\r
39\r
40 Transfers control to the function specified by EntryPoint using the new stack\r
41 specified by NewStack and passing in the parameters specified by Context1 and\r
42 Context2. Context1 and Context2 are optional and may be NULL. The function\r
43 EntryPoint must never return.\r
44\r
45 If EntryPoint is NULL, then ASSERT().\r
46 If NewStack is NULL, then ASSERT().\r
47\r
48 @param EntryPoint A pointer to function to call with the new stack.\r
49 @param Context1 A pointer to the context to pass into the EntryPoint\r
50 function.\r
51 @param Context2 A pointer to the context to pass into the EntryPoint\r
52 function.\r
53 @param NewStack A pointer to the new stack to use for the EntryPoint\r
54 function.\r
55 @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's\r
56 Reserved on other architectures.\r
57\r
58**/\r
59VOID\r
60EFIAPI\r
61PeiSwitchStacks (\r
62 IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
63 IN VOID *Context1, OPTIONAL\r
64 IN VOID *Context2, OPTIONAL\r
65 IN VOID *Context3, OPTIONAL\r
66 IN VOID *OldTopOfStack,\r
67 IN VOID *NewStack\r
68 )\r
69{\r
70 BASE_LIBRARY_JUMP_BUFFER JumpBuffer;\r
71 UINTN SizeOfStackUsed;\r
72 UINTN SetJumpFlag;\r
73 \r
74 ASSERT (EntryPoint != NULL);\r
75 ASSERT (NewStack != NULL);\r
76\r
77 SetJumpFlag = SetJump (&JumpBuffer);\r
78 //\r
79 // The initial call to SetJump() must always return 0.\r
80 // Subsequent calls to LongJump() may cause a non-zero value to be returned by SetJump().\r
81 //\r
82 if (SetJumpFlag == 0) {\r
83 //\r
84 // Stack should be aligned with CPU_STACK_ALIGNMENT\r
85 //\r
86 ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0);\r
87 \r
88 //JumpBuffer.Rip = (UINTN)EntryPoint;\r
89 SizeOfStackUsed = (UINTN)OldTopOfStack - JumpBuffer.Rsp;\r
90 JumpBuffer.Rsp = (UINTN)NewStack - SizeOfStackUsed;\r
91 MemoryFence ();\r
92 CopyMem (\r
93 (VOID*) ((UINTN)NewStack - SizeOfStackUsed),\r
94 (VOID*) ((UINTN)OldTopOfStack - SizeOfStackUsed),\r
95 SizeOfStackUsed\r
96 );\r
97 LongJump (&JumpBuffer, (UINTN)-1);\r
98 } else {\r
99 (*(PEI_CORE_ENTRY_POINT)(EntryPoint)) (\r
100 (EFI_SEC_PEI_HAND_OFF *) Context1,\r
101 (EFI_PEI_PPI_DESCRIPTOR *) Context2,\r
102 Context3\r
103 );\r
104 }\r
105\r
106 //\r
107 // InternalSwitchStack () will never return\r
108 //\r
109 ASSERT (FALSE); \r
110}\r
111\r
112/**\r
113 Transfers control to a function starting with a new stack.\r
114\r
115 Transfers control to the function specified by EntryPoint using the new stack\r
116 specified by NewStack and passing in the parameters specified by Context1 and\r
117 Context2. Context1 and Context2 are optional and may be NULL. The function\r
118 EntryPoint must never return.\r
119\r
120 If EntryPoint is NULL, then ASSERT().\r
121 If NewStack is NULL, then ASSERT().\r
122\r
123 @param EntryPoint A pointer to function to call with the new stack.\r
124 @param Context1 A pointer to the context to pass into the EntryPoint\r
125 function.\r
126 @param Context2 A pointer to the context to pass into the EntryPoint\r
127 function.\r
128 @param NewStack A pointer to the new stack to use for the EntryPoint\r
129 function.\r
130 @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's\r
131 Reserved on other architectures.\r
132\r
133**/\r
134VOID\r
135EFIAPI\r
136SecSwitchStack (\r
137 IN UINTN TemporaryMemoryBase,\r
138 IN UINTN PermanentMemoryBase,\r
139 IN UINTN CopySize\r
140 )\r
141{\r
142 BASE_LIBRARY_JUMP_BUFFER JumpBuffer;\r
143 UINTN SetJumpFlag;\r
144\r
145 ASSERT ((VOID*)TemporaryMemoryBase != NULL);\r
146 ASSERT ((VOID*)PermanentMemoryBase != NULL);\r
147\r
148 SetJumpFlag = SetJump (&JumpBuffer);\r
149 //\r
150 // The initial call to SetJump() must always return 0.\r
151 // Subsequent calls to LongJump() may cause a non-zero value to be returned by SetJump().\r
152 //\r
153 if (SetJumpFlag == 0) {\r
154 DEBUG ((EFI_D_ERROR, "SecSwitchStack+%d: Rsp: 0x%xL\n", __LINE__, JumpBuffer.Rsp));\r
155 JumpBuffer.Rsp =\r
156 (INTN)JumpBuffer.Rsp -\r
157 (INTN)TemporaryMemoryBase +\r
158 (INTN)PermanentMemoryBase;\r
159 MemoryFence ();\r
160 CopyMem((VOID*)PermanentMemoryBase, (VOID*)TemporaryMemoryBase, CopySize);\r
161 LongJump (&JumpBuffer, (UINTN)-1);\r
162 }\r
163\r
164}\r
165\r