2 Switch Stack functions.
4 Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 // Include common header file for this module.
20 #include <Library/BaseLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/PeiServicesLib.h>
26 // Type define for PEI Core Entry Point function
30 (EFIAPI
*PEI_CORE_ENTRY_POINT
)(
31 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
32 IN CONST EFI_PEI_PPI_DESCRIPTOR
*PpiList
,
38 Transfers control to a function starting with a new stack.
40 Transfers control to the function specified by EntryPoint using the new stack
41 specified by NewStack and passing in the parameters specified by Context1 and
42 Context2. Context1 and Context2 are optional and may be NULL. The function
43 EntryPoint must never return.
45 If EntryPoint is NULL, then ASSERT().
46 If NewStack is NULL, then ASSERT().
48 @param EntryPoint A pointer to function to call with the new stack.
49 @param Context1 A pointer to the context to pass into the EntryPoint
51 @param Context2 A pointer to the context to pass into the EntryPoint
53 @param NewStack A pointer to the new stack to use for the EntryPoint
55 @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's
56 Reserved on other architectures.
62 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
63 IN VOID
*Context1
, OPTIONAL
64 IN VOID
*Context2
, OPTIONAL
65 IN VOID
*Context3
, OPTIONAL
66 IN VOID
*OldTopOfStack
,
70 BASE_LIBRARY_JUMP_BUFFER JumpBuffer
;
71 UINTN SizeOfStackUsed
;
74 ASSERT (EntryPoint
!= NULL
);
75 ASSERT (NewStack
!= NULL
);
77 SetJumpFlag
= SetJump (&JumpBuffer
);
79 // The initial call to SetJump() must always return 0.
80 // Subsequent calls to LongJump() may cause a non-zero value to be returned by SetJump().
82 if (SetJumpFlag
== 0) {
84 // Stack should be aligned with CPU_STACK_ALIGNMENT
86 ASSERT (((UINTN
)NewStack
& (CPU_STACK_ALIGNMENT
- 1)) == 0);
88 //JumpBuffer.Rip = (UINTN)EntryPoint;
89 SizeOfStackUsed
= (UINTN
)OldTopOfStack
- JumpBuffer
.Rsp
;
90 JumpBuffer
.Rsp
= (UINTN
)NewStack
- SizeOfStackUsed
;
93 (VOID
*) ((UINTN
)NewStack
- SizeOfStackUsed
),
94 (VOID
*) ((UINTN
)OldTopOfStack
- SizeOfStackUsed
),
97 LongJump (&JumpBuffer
, (UINTN
)-1);
99 (*(PEI_CORE_ENTRY_POINT
)(EntryPoint
)) (
100 (EFI_SEC_PEI_HAND_OFF
*) Context1
,
101 (EFI_PEI_PPI_DESCRIPTOR
*) Context2
,
107 // InternalSwitchStack () will never return
113 Transfers control to a function starting with a new stack.
115 Transfers control to the function specified by EntryPoint using the new stack
116 specified by NewStack and passing in the parameters specified by Context1 and
117 Context2. Context1 and Context2 are optional and may be NULL. The function
118 EntryPoint must never return.
120 If EntryPoint is NULL, then ASSERT().
121 If NewStack is NULL, then ASSERT().
123 @param EntryPoint A pointer to function to call with the new stack.
124 @param Context1 A pointer to the context to pass into the EntryPoint
126 @param Context2 A pointer to the context to pass into the EntryPoint
128 @param NewStack A pointer to the new stack to use for the EntryPoint
130 @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's
131 Reserved on other architectures.
137 IN UINTN TemporaryMemoryBase
,
138 IN UINTN PermanentMemoryBase
,
142 BASE_LIBRARY_JUMP_BUFFER JumpBuffer
;
145 ASSERT ((VOID
*)TemporaryMemoryBase
!= NULL
);
146 ASSERT ((VOID
*)PermanentMemoryBase
!= NULL
);
148 SetJumpFlag
= SetJump (&JumpBuffer
);
150 // The initial call to SetJump() must always return 0.
151 // Subsequent calls to LongJump() may cause a non-zero value to be returned by SetJump().
153 if (SetJumpFlag
== 0) {
154 DEBUG ((EFI_D_ERROR
, "SecSwitchStack+%d: Rsp: 0x%xL\n", __LINE__
, JumpBuffer
.Rsp
));
156 (INTN
)JumpBuffer
.Rsp
-
157 (INTN
)TemporaryMemoryBase
+
158 (INTN
)PermanentMemoryBase
;
160 CopyMem((VOID
*)PermanentMemoryBase
, (VOID
*)TemporaryMemoryBase
, CopySize
);
161 LongJump (&JumpBuffer
, (UINTN
)-1);