]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/Sec/Ia32/SwitchStack.c
Started trying to get the UnixPkg to compile for X64 with UnixABI. So far only have...
[mirror_edk2.git] / UnixPkg / Sec / Ia32 / SwitchStack.c
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 Module Name:
14
15 SecMain.c
16
17 Abstract:
18 Unix emulator of SEC phase. It's really a Posix application, but this is
19 Ok since all the other modules for NT32 are NOT Posix applications.
20
21 This program processes host environment variables and figures out
22 what the memory layout will be, how may FD's will be loaded and also
23 what the boot mode is.
24
25 The SEC registers a set of services with the SEC core. gPrivateDispatchTable
26 is a list of PPI's produced by the SEC that are availble for usage in PEI.
27
28 This code produces 128 K of temporary memory for the PEI stack by opening a
29 host file and mapping it directly to memory addresses.
30
31 The system.cmd script is used to set host environment variables that drive
32 the configuration opitons of the SEC.
33
34 --*/
35
36 #include "SecMain.h"
37
38
39 /**
40 Transfers control to a function starting with a new stack.
41
42 Transfers control to the function specified by EntryPoint using the new stack
43 specified by NewStack and passing in the parameters specified by Context1 and
44 Context2. Context1 and Context2 are optional and may be NULL. The function
45 EntryPoint must never return.
46
47 If EntryPoint is NULL, then ASSERT().
48 If NewStack is NULL, then ASSERT().
49
50 @param EntryPoint A pointer to function to call with the new stack.
51 @param Context1 A pointer to the context to pass into the EntryPoint
52 function.
53 @param Context2 A pointer to the context to pass into the EntryPoint
54 function.
55 @param NewStack A pointer to the new stack to use for the EntryPoint
56 function.
57 @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's
58 Reserved on other architectures.
59
60 **/
61 VOID
62 EFIAPI
63 PeiSwitchStacks (
64 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
65 IN VOID *Context1, OPTIONAL
66 IN VOID *Context2, OPTIONAL
67 IN VOID *Context3, OPTIONAL
68 IN VOID *NewStack
69 )
70 {
71 BASE_LIBRARY_JUMP_BUFFER JumpBuffer;
72
73 ASSERT (EntryPoint != NULL);
74 ASSERT (NewStack != NULL);
75
76 //
77 // Stack should be aligned with CPU_STACK_ALIGNMENT
78 //
79 ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0);
80
81 JumpBuffer.Eip = (UINTN)EntryPoint;
82 JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*);
83 JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2) + sizeof(Context3);
84 ((VOID**)JumpBuffer.Esp)[1] = Context1;
85 ((VOID**)JumpBuffer.Esp)[2] = Context2;
86 ((VOID**)JumpBuffer.Esp)[3] = Context3;
87
88 LongJump (&JumpBuffer, (UINTN)-1);
89
90
91 //
92 // InternalSwitchStack () will never return
93 //
94 ASSERT (FALSE);
95 }
96
97
98