Home | History | Annotate | Download | only in BaseLib
      1 /** @file
      2   Switch Stack functions.
      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.  This function
     24   supports a variable number of arguments following the NewStack parameter.
     25   These additional arguments are ignored on IA-32, x64, and EBC.
     26   IPF CPUs expect one additional parameter of type VOID * that specifies
     27   the new backing store pointer.
     28 
     29   If EntryPoint is NULL, then ASSERT().
     30   If NewStack is NULL, then ASSERT().
     31 
     32   @param  EntryPoint  A pointer to function to call with the new stack.
     33   @param  Context1    A pointer to the context to pass into the EntryPoint
     34                       function.
     35   @param  Context2    A pointer to the context to pass into the EntryPoint
     36                       function.
     37   @param  NewStack    A pointer to the new stack to use for the EntryPoint
     38                       function.
     39   @param  ...         This variable argument list is ignored for IA32, x64, and EBC.
     40                       For IPF, this variable argument list is expected to contain
     41                       a single parameter of type VOID * that specifies the new backing
     42                       store pointer.
     43 
     44 
     45 **/
     46 VOID
     47 EFIAPI
     48 SwitchStack (
     49   IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,
     50   IN      VOID                      *Context1,  OPTIONAL
     51   IN      VOID                      *Context2,  OPTIONAL
     52   IN      VOID                      *NewStack,
     53   ...
     54   )
     55 {
     56   VA_LIST    Marker;
     57 
     58   ASSERT (EntryPoint != NULL);
     59   ASSERT (NewStack != NULL);
     60 
     61   //
     62   // New stack must be aligned with CPU_STACK_ALIGNMENT
     63   //
     64   ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0);
     65 
     66   VA_START (Marker, NewStack);
     67 
     68   InternalSwitchStack (EntryPoint, Context1, Context2, NewStack, Marker);
     69 
     70   VA_END (Marker);
     71 
     72   //
     73   // InternalSwitchStack () will never return
     74   //
     75   ASSERT (FALSE);
     76 }
     77