]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/Unix/Host/Ia32/SwitchStack.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / EmulatorPkg / Unix / Host / Ia32 / SwitchStack.c
CommitLineData
79e4f2a5
RN
1/*++\r
2\r
3Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
4Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
e3ba31da 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
79e4f2a5
RN
6\r
7\r
8--*/\r
9\r
10#include "Host.h"\r
11\r
79e4f2a5
RN
12/**\r
13 Transfers control to a function starting with a new stack.\r
14\r
15 Transfers control to the function specified by EntryPoint using the new stack\r
16 specified by NewStack and passing in the parameters specified by Context1 and\r
17 Context2. Context1 and Context2 are optional and may be NULL. The function\r
18 EntryPoint must never return.\r
19\r
20 If EntryPoint is NULL, then ASSERT().\r
21 If NewStack is NULL, then ASSERT().\r
22\r
23 @param EntryPoint A pointer to function to call with the new stack.\r
24 @param Context1 A pointer to the context to pass into the EntryPoint\r
25 function.\r
26 @param Context2 A pointer to the context to pass into the EntryPoint\r
27 function.\r
28 @param NewStack A pointer to the new stack to use for the EntryPoint\r
29 function.\r
30\r
31**/\r
32VOID\r
33EFIAPI\r
34PeiSwitchStacks (\r
35 IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
c69fc80c
MK
36 IN VOID *Context1 OPTIONAL,\r
37 IN VOID *Context2 OPTIONAL,\r
79e4f2a5
RN
38 IN VOID *NewStack\r
39 )\r
40{\r
41 BASE_LIBRARY_JUMP_BUFFER JumpBuffer;\r
42\r
43 ASSERT (EntryPoint != NULL);\r
44 ASSERT (NewStack != NULL);\r
45\r
46 //\r
47 // Stack should be aligned with CPU_STACK_ALIGNMENT\r
48 //\r
49 ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0);\r
50\r
a550d468
MK
51 JumpBuffer.Eip = (UINTN)EntryPoint;\r
52 JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID *);\r
53 JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2);\r
54 ((VOID **)JumpBuffer.Esp)[1] = Context1;\r
55 ((VOID **)JumpBuffer.Esp)[2] = Context2;\r
79e4f2a5
RN
56\r
57 LongJump (&JumpBuffer, (UINTN)-1);\r
58\r
79e4f2a5
RN
59 //\r
60 // PeiSwitchStacks () will never return\r
61 //\r
62 ASSERT (FALSE);\r
63}\r