]>
Commit | Line | Data |
---|---|---|
49ba9447 | 1 | /** @file\r |
2 | Switch Stack functions.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2007, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
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 | Transfers control to a function starting with a new stack.\r | |
27 | \r | |
28 | Transfers control to the function specified by EntryPoint using the new stack\r | |
29 | specified by NewStack and passing in the parameters specified by Context1 and\r | |
30 | Context2. Context1 and Context2 are optional and may be NULL. The function\r | |
31 | EntryPoint must never return.\r | |
32 | \r | |
33 | If EntryPoint is NULL, then ASSERT().\r | |
34 | If NewStack is NULL, then ASSERT().\r | |
35 | \r | |
36 | @param EntryPoint A pointer to function to call with the new stack.\r | |
37 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
38 | function.\r | |
39 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
40 | function.\r | |
41 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
42 | function.\r | |
43 | @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's\r | |
44 | Reserved on other architectures.\r | |
45 | \r | |
46 | **/\r | |
47 | VOID\r | |
48 | EFIAPI\r | |
49 | PeiSwitchStacks (\r | |
50 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r | |
51 | IN VOID *Context1, OPTIONAL\r | |
52 | IN VOID *Context2, OPTIONAL\r | |
53 | IN VOID *Context3, OPTIONAL\r | |
54 | IN VOID *OldTopOfStack,\r | |
55 | IN VOID *NewStack\r | |
56 | )\r | |
57 | {\r | |
58 | BASE_LIBRARY_JUMP_BUFFER JumpBuffer;\r | |
59 | \r | |
60 | ASSERT (EntryPoint != NULL);\r | |
61 | ASSERT (NewStack != NULL);\r | |
62 | \r | |
63 | //\r | |
64 | // Stack should be aligned with CPU_STACK_ALIGNMENT\r | |
65 | //\r | |
66 | ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0);\r | |
67 | \r | |
68 | JumpBuffer.Eip = (UINTN)EntryPoint;\r | |
69 | JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*);\r | |
70 | JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2) + sizeof(Context3);\r | |
71 | ((VOID**)JumpBuffer.Esp)[1] = Context1;\r | |
72 | ((VOID**)JumpBuffer.Esp)[2] = Context2;\r | |
73 | ((VOID**)JumpBuffer.Esp)[3] = Context3;\r | |
74 | \r | |
75 | LongJump (&JumpBuffer, (UINTN)-1);\r | |
76 | \r | |
77 | //\r | |
78 | // InternalSwitchStack () will never return\r | |
79 | //\r | |
80 | ASSERT (FALSE); \r | |
81 | }\r | |
82 | \r | |
83 | /**\r | |
84 | Transfers control to a function starting with a new stack.\r | |
85 | \r | |
86 | Transfers control to the function specified by EntryPoint using the new stack\r | |
87 | specified by NewStack and passing in the parameters specified by Context1 and\r | |
88 | Context2. Context1 and Context2 are optional and may be NULL. The function\r | |
89 | EntryPoint must never return.\r | |
90 | \r | |
91 | If EntryPoint is NULL, then ASSERT().\r | |
92 | If NewStack is NULL, then ASSERT().\r | |
93 | \r | |
94 | @param EntryPoint A pointer to function to call with the new stack.\r | |
95 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
96 | function.\r | |
97 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
98 | function.\r | |
99 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
100 | function.\r | |
101 | @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's\r | |
102 | Reserved on other architectures.\r | |
103 | \r | |
104 | **/\r | |
105 | VOID\r | |
106 | EFIAPI\r | |
107 | SecSwitchStack (\r | |
108 | IN UINTN TemporaryMemoryBase,\r | |
109 | IN UINTN PermanentMemoryBase,\r | |
110 | IN UINTN CopySize\r | |
111 | )\r | |
112 | {\r | |
113 | BASE_LIBRARY_JUMP_BUFFER JumpBuffer;\r | |
114 | UINTN SetJumpFlag;\r | |
115 | \r | |
116 | ASSERT ((VOID*)TemporaryMemoryBase != NULL);\r | |
117 | ASSERT ((VOID*)PermanentMemoryBase != NULL);\r | |
118 | \r | |
119 | SetJumpFlag = SetJump (&JumpBuffer);\r | |
120 | //\r | |
121 | // The initial call to SetJump() must always return 0.\r | |
122 | // Subsequent calls to LongJump() may cause a non-zero value to be returned by SetJump().\r | |
123 | //\r | |
124 | if (SetJumpFlag == 0) {\r | |
125 | DEBUG ((EFI_D_ERROR, "SecSwitchStack+%d: Esp: 0x%xL\n", __LINE__, JumpBuffer.Esp));\r | |
126 | JumpBuffer.Esp =\r | |
127 | (INTN)JumpBuffer.Esp -\r | |
128 | (INTN)TemporaryMemoryBase +\r | |
129 | (INTN)PermanentMemoryBase;\r | |
130 | MemoryFence ();\r | |
131 | CopyMem((VOID*)PermanentMemoryBase, (VOID*)TemporaryMemoryBase, CopySize);\r | |
132 | LongJump (&JumpBuffer, (UINTN)-1);\r | |
133 | }\r | |
134 | \r | |
135 | }\r | |
136 | \r |