1 /** @file 2 SwitchStack() function for IA-32. 3 4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR> 5 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 **/ 14 15 #include "BaseLibInternals.h" 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 21 new stack specified by NewStack and passing in the parameters specified 22 by Context1 and Context2. Context1 and Context2 are optional and may 23 be NULL. The function EntryPoint must never return. 24 Marker will be ignored on IA-32, x64, and EBC. 25 IPF CPUs expect one additional parameter of type VOID * that specifies 26 the new backing store pointer. 27 28 If EntryPoint is NULL, then ASSERT(). 29 If NewStack is NULL, then ASSERT(). 30 31 @param EntryPoint A pointer to function to call with the new stack. 32 @param Context1 A pointer to the context to pass into the EntryPoint 33 function. 34 @param Context2 A pointer to the context to pass into the EntryPoint 35 function. 36 @param NewStack A pointer to the new stack to use for the EntryPoint 37 function. 38 @param Marker VA_LIST marker for the variable argument list. 39 40 **/ 41 VOID 42 EFIAPI 43 InternalSwitchStack ( 44 IN SWITCH_STACK_ENTRY_POINT EntryPoint, 45 IN VOID *Context1, OPTIONAL 46 IN VOID *Context2, OPTIONAL 47 IN VOID *NewStack, 48 IN VA_LIST Marker 49 ) 50 { 51 BASE_LIBRARY_JUMP_BUFFER JumpBuffer; 52 53 JumpBuffer.Eip = (UINTN)EntryPoint; 54 JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*); 55 JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2); 56 ((VOID**)JumpBuffer.Esp)[1] = Context1; 57 ((VOID**)JumpBuffer.Esp)[2] = Context2; 58 59 LongJump (&JumpBuffer, (UINTN)-1); 60 } 61