]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Sec/Ia32/SwitchRam.S
EmulatorPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmulatorPkg / Sec / Ia32 / SwitchRam.S
1 #------------------------------------------------------------------------------
2 #
3 # Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
4 # SPDX-License-Identifier: BSD-2-Clause-Patent
5 #
6 # Module Name:
7 #
8 # Stack.asm
9 #
10 # Abstract:
11 #
12 # Switch the stack from temporary memory to permenent memory.
13 #
14 #------------------------------------------------------------------------------
15
16 .text
17
18
19 //------------------------------------------------------------------------------
20 // VOID
21 // EFIAPI
22 // SecSwitchStack (
23 // UINT32 TemporaryMemoryBase,
24 // UINT32 PermenentMemoryBase
25 // )//
26 //------------------------------------------------------------------------------
27 ASM_GLOBAL ASM_PFX(SecSwitchStack)
28 ASM_PFX(SecSwitchStack):
29 #
30 # Save three register: eax, ebx, ecx
31 #
32 push %eax
33 push %ebx
34 push %ecx
35 push %edx
36
37 #
38 # !!CAUTION!! this function address's is pushed into stack after
39 # migration of whole temporary memory, so need save it to permenent
40 # memory at first!
41 #
42
43 movl 20(%esp), %ebx # Save the first parameter
44 movl 24(%esp), %ecx # Save the second parameter
45
46 #
47 # Save this function's return address into permenent memory at first.
48 # Then, Fixup the esp point to permenent memory
49 #
50
51 movl %esp, %eax
52 subl %ebx, %eax
53 addl %ecx, %eax
54 movl (%esp), %edx # copy pushed register's value to permenent memory
55 movl %edx, (%eax)
56 movl 4(%esp), %edx
57 movl %edx, 4(%eax)
58 movl 8(%esp), %edx
59 movl %edx, 8(%eax)
60 movl 12(%esp), %edx
61 movl %edx, 12(%eax)
62 movl 16(%esp), %edx
63 movl %edx, 16(%eax)
64 movl %eax, %esp # From now, esp is pointed to permenent memory
65
66 #
67 # Fixup the ebp point to permenent memory
68 #
69 #ifndef __APPLE__
70 movl %ebp, %eax
71 subl %ebx, %eax
72 addl %ecx, %eax
73 movl %eax, %ebp # From now, ebp is pointed to permenent memory
74
75 #
76 # Fixup callee's ebp point for PeiDispatch
77 #
78 movl (%ebp), %eax
79 subl %ebx, %eax
80 addl %ecx, %eax
81 movl %eax, (%ebp) # From now, Temporary's PPI caller's stack is in permenent memory
82 #endif
83
84 pop %edx
85 pop %ecx
86 pop %ebx
87 pop %eax
88 ret
89