]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/InternalSwitchStack.c
ab8116b4b5a882236fc2eff75b0a663eff0e33e3
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / InternalSwitchStack.c
1 /** @file
2 SwitchStack() function for IA-32.
3
4 Copyright (c) 2006, 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 Transfers control to a function starting with a new stack.
19
20 Transfers control to the function specified by EntryPoint using the new stack
21 specified by NewStack and passing in the parameters specified by Context1 and
22 Context2. Context1 and Context2 are optional and may be NULL. The function
23 EntryPoint must never return.
24
25 @param EntryPoint A pointer to function to call with the new stack.
26 @param Context1 A pointer to the context to pass into the EntryPoint
27 function.
28 @param Context2 A pointer to the context to pass into the EntryPoint
29 function.
30 @param NewStack A pointer to the new stack to use for the EntryPoint
31 function.
32
33 **/
34 VOID
35 EFIAPI
36 InternalSwitchStack (
37 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
38 IN VOID *Context1,
39 IN VOID *Context2,
40 IN VOID *NewStack
41 )
42 {
43 BASE_LIBRARY_JUMP_BUFFER JumpBuffer;
44
45 JumpBuffer.Eip = (UINTN)EntryPoint;
46 JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*);
47 JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2);
48 ((VOID**)JumpBuffer.Esp)[1] = Context1;
49 ((VOID**)JumpBuffer.Esp)[2] = Context2;
50
51 LongJump (&JumpBuffer, (UINTN)-1);
52 }