]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/InternalSwitchStack.c
2bd46a0ffbdc5b37b6f063e7d84bdf2051e25125
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / InternalSwitchStack.c
1 /** @file
2 SwitchStack() function for IA-32.
3
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>
5 All rights reserved. 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
9
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.
12
13 Module Name: InternalSwitchStack.c
14
15 **/
16
17 //
18 // Include common header file for this module.
19 //
20 #include <BaseLibInternals.h>
21
22
23 /**
24 Transfers control to a function starting with a new stack.
25
26 Transfers control to the function specified by EntryPoint using the
27 new stack specified by NewStack and passing in the parameters specified
28 by Context1 and Context2. Context1 and Context2 are optional and may
29 be NULL. The function EntryPoint must never return.
30 Marker will be ignored on IA-32, x64, and EBC.
31 IPF CPUs expect one additional parameter of type VOID * that specifies
32 the new backing store pointer.
33
34 If EntryPoint is NULL, then ASSERT().
35 If NewStack is NULL, then ASSERT().
36
37 @param EntryPoint A pointer to function to call with the new stack.
38 @param Context1 A pointer to the context to pass into the EntryPoint
39 function.
40 @param Context2 A pointer to the context to pass into the EntryPoint
41 function.
42 @param NewStack A pointer to the new stack to use for the EntryPoint
43 function.
44 @param Marker VA_LIST marker for the variable argument list.
45
46 **/
47 VOID
48 EFIAPI
49 InternalSwitchStack (
50 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
51 IN VOID *Context1, OPTIONAL
52 IN VOID *Context2, OPTIONAL
53 IN VOID *NewStack,
54 IN VA_LIST Marker
55 )
56 {
57 BASE_LIBRARY_JUMP_BUFFER JumpBuffer;
58
59 //
60 // Stack should be aligned with CPU_STACK_ALIGNMENT
61 //
62 ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0);
63
64 JumpBuffer.Eip = (UINTN)EntryPoint;
65 JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*);
66 JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2);
67 ((VOID**)JumpBuffer.Esp)[1] = Context1;
68 ((VOID**)JumpBuffer.Esp)[2] = Context2;
69
70 LongJump (&JumpBuffer, (UINTN)-1);
71 }