]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/Sec/Ia32/Stack.S
Integrate patch from Andrew Fish to make it run on OS X.
[mirror_edk2.git] / UnixPkg / Sec / Ia32 / Stack.S
1 #------------------------------------------------------------------------------
2 #
3 # Copyright (c) 2008 - 2009, Intel Corporation
4 # Portions copyright (c) 2008-2009 Apple Inc.
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:
14 #
15 # Stack.asm
16 #
17 # Abstract:
18 #
19 # Switch the stack from temporary memory to permenent memory.
20 #
21 #------------------------------------------------------------------------------
22
23 #------------------------------------------------------------------------------
24 # VOID
25 # EFIAPI
26 # SecSwitchStack (
27 # UINT32 TemporaryMemoryBase,
28 # UINT32 PermenentMemoryBase
29 # );
30 #------------------------------------------------------------------------------
31
32 #include <ProcessorBind.h>
33
34 ASM_GLOBAL ASM_PFX(SecSwitchStack)
35 ASM_PFX(SecSwitchStack):
36 #
37 # Save three register: eax, ebx, ecx
38 #
39 push %eax
40 push %ebx
41 push %ecx
42 push %edx
43
44 #
45 # !!CAUTION!! this function address's is pushed into stack after
46 # migration of whole temporary memory, so need save it to permenent
47 # memory at first!
48 #
49
50 movl 20(%esp), %ebx # Save the first parameter
51 movl 24(%esp), %ecx # Save the second parameter
52
53 #
54 # Save this function's return address into permenent memory at first.
55 # Then, Fixup the esp point to permenent memory
56 #
57
58 movl %esp, %eax
59 subl %ebx, %eax
60 addl %ecx, %eax
61 movl (%esp), %edx # copy pushed register's value to permenent memory
62 movl %edx, (%eax)
63 movl 4(%esp), %edx
64 movl %edx, 4(%eax)
65 movl 8(%esp), %edx
66 movl %edx, 8(%eax)
67 movl 12(%esp), %edx
68 movl %edx, 12(%eax)
69 movl 16(%esp), %edx
70 movl %edx, 16(%eax)
71 movl %eax, %esp # From now, esp is pointed to permenent memory
72
73 #
74 # Fixup the ebp point to permenent memory
75 #
76 #ifndef __APPLE__
77 movl %ebp, %eax
78 subl %ebx, %eax
79 addl %ecx, %eax
80 movl %eax, %ebp # From now, ebp is pointed to permenent memory
81
82 #
83 # Fixup callee's ebp point for PeiDispatch
84 #
85 movl (%ebp), %eax
86 subl %ebx, %eax
87 addl %ecx, %eax
88 movl %eax, (%ebp) # From now, Temporary's PPI caller's stack is in permenent memory
89 #endif
90
91 pop %edx
92 pop %ecx
93 pop %ebx
94 pop %eax
95 ret