]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/Unix/Host/Ia32/SwitchStack.c
EmulatorPkg: require GCC48 or later
[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
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13\r
14--*/\r
15\r
16#include "Host.h"\r
17\r
18\r
19/**\r
20 Transfers control to a function starting with a new stack.\r
21\r
22 Transfers control to the function specified by EntryPoint using the new stack\r
23 specified by NewStack and passing in the parameters specified by Context1 and\r
24 Context2. Context1 and Context2 are optional and may be NULL. The function\r
25 EntryPoint must never return.\r
26\r
27 If EntryPoint is NULL, then ASSERT().\r
28 If NewStack is NULL, then ASSERT().\r
29\r
30 @param EntryPoint A pointer to function to call with the new stack.\r
31 @param Context1 A pointer to the context to pass into the EntryPoint\r
32 function.\r
33 @param Context2 A pointer to the context to pass into the EntryPoint\r
34 function.\r
35 @param NewStack A pointer to the new stack to use for the EntryPoint\r
36 function.\r
37\r
38**/\r
39VOID\r
40EFIAPI\r
41PeiSwitchStacks (\r
42 IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
43 IN VOID *Context1, OPTIONAL\r
44 IN VOID *Context2, OPTIONAL\r
45 IN VOID *NewStack\r
46 )\r
47{\r
48 BASE_LIBRARY_JUMP_BUFFER JumpBuffer;\r
49\r
50 ASSERT (EntryPoint != NULL);\r
51 ASSERT (NewStack != NULL);\r
52\r
53 //\r
54 // Stack should be aligned with CPU_STACK_ALIGNMENT\r
55 //\r
56 ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0);\r
57\r
58 JumpBuffer.Eip = (UINTN)EntryPoint;\r
59 JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*);\r
60 JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2);\r
61 ((VOID**)JumpBuffer.Esp)[1] = Context1;\r
62 ((VOID**)JumpBuffer.Esp)[2] = Context2;\r
63\r
64 LongJump (&JumpBuffer, (UINTN)-1);\r
65\r
66\r
67 //\r
68 // PeiSwitchStacks () will never return\r
69 //\r
70 ASSERT (FALSE);\r
71}\r
72\r
73\r
74\r