Home | History | Annotate | Download | only in Ia32
      1 /*++
      2 
      3 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
      4 Portions copyright (c) 2008 - 2009, Apple Inc. 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 
     16 #include "Host.h"
     17 
     18 
     19 /**
     20   Transfers control to a function starting with a new stack.
     21 
     22   Transfers control to the function specified by EntryPoint using the new stack
     23   specified by NewStack and passing in the parameters specified by Context1 and
     24   Context2. Context1 and Context2 are optional and may be NULL. The function
     25   EntryPoint must never return.
     26 
     27   If EntryPoint is NULL, then ASSERT().
     28   If NewStack is NULL, then ASSERT().
     29 
     30   @param  EntryPoint  A pointer to function to call with the new stack.
     31   @param  Context1    A pointer to the context to pass into the EntryPoint
     32                       function.
     33   @param  Context2    A pointer to the context to pass into the EntryPoint
     34                       function.
     35   @param  NewStack    A pointer to the new stack to use for the EntryPoint
     36                       function.
     37 
     38 **/
     39 VOID
     40 EFIAPI
     41 PeiSwitchStacks (
     42   IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,
     43   IN      VOID                      *Context1,  OPTIONAL
     44   IN      VOID                      *Context2,  OPTIONAL
     45   IN      VOID                      *NewStack
     46   )
     47 {
     48   BASE_LIBRARY_JUMP_BUFFER  JumpBuffer;
     49 
     50   ASSERT (EntryPoint != NULL);
     51   ASSERT (NewStack != NULL);
     52 
     53   //
     54   // Stack should be aligned with CPU_STACK_ALIGNMENT
     55   //
     56   ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0);
     57 
     58   JumpBuffer.Eip = (UINTN)EntryPoint;
     59   JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*);
     60   JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2);
     61   ((VOID**)JumpBuffer.Esp)[1] = Context1;
     62   ((VOID**)JumpBuffer.Esp)[2] = Context2;
     63 
     64   LongJump (&JumpBuffer, (UINTN)-1);
     65 
     66 
     67   //
     68   // PeiSwitchStacks () will never return
     69   //
     70   ASSERT (FALSE);
     71 }
     72 
     73 
     74 
     75