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