]> git.proxmox.com Git - mirror_edk2.git/blob - InOsEmuPkg/Unix/Sec/X64/SwitchStack.S
Add InOsEmuPkg. Like UnixPkg and Nt32Pkg, but EFI code can be common and does not...
[mirror_edk2.git] / InOsEmuPkg / Unix / Sec / X64 / SwitchStack.S
1 #------------------------------------------------------------------------------
2 #
3 # Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
4 # Portitions copyright (c) 2011, Apple Inc. All rights reserved.
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 #------------------------------------------------------------------------------
17 # Routine Description:
18 #
19 # Routine for switching stacks with 3 parameters EFI ABI
20 # Convert UNIX to EFI ABI
21 #
22 # Arguments:
23 #
24 # (rdi) EntryPoint - Entry point with new stack.
25 # (rsi) Context1 - Parameter1 for entry point. (rcx)
26 # (rdx) Context2 - Parameter2 for entry point. (rdx)
27 # (rcx) Context3 - Parameter3 for entry point. (r8)
28 # (r8) NewStack - The pointer to new stack.
29 #
30 # Returns:
31 #
32 # None
33 #
34 #------------------------------------------------------------------------------
35 ASM_GLOBAL ASM_PFX(PeiSwitchStacks)
36 ASM_PFX(PeiSwitchStacks):
37 pushq $0 // tells gdb to stop unwinding frame
38 movq %rsp, %rbp
39
40 movq %r8, %rsp
41
42 movq %rdi, %rax
43 movq %rsi, %rcx
44 movq %rcx, %r8
45
46 #
47 # Reserve space for register parameters (rcx, rdx, r8 & r9) on the stack,
48 # in case the callee wishes to spill them.
49 #
50 subq $32, %rsp // 32-byte shadow space plus alignment pad
51 call *%rax
52
53
54
55 // EFI_STATUS
56 // EFIAPI
57 // SecTemporaryRamSupport (
58 // IN CONST EFI_PEI_SERVICES **PeiServices, // %rcx
59 // IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, // %rdx
60 // IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, // %r8
61 // IN UINTN CopySize // %r9
62 // )
63 //
64 ASM_GLOBAL ASM_PFX(GasketSecTemporaryRamSupport)
65 ASM_PFX(GasketSecTemporaryRamSupport):
66 // Adjust callers %rbp to account for stack move
67 subq %rdx, %rbp // Calc offset of %rbp in Temp Memory
68 addq %r8, %rbp // add in permanent base to offset
69
70 pushq %rbp // stack frame is for the debugger
71 movq %rsp, %rbp
72
73 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
74 pushq %rdi
75
76 pushq %rdx // Save TemporaryMemoryBase
77 pushq %r8 // Save PermanentMemoryBase
78 pushq %r9 // Save CopySize
79
80 //
81 // Copy all of temp RAM to permanent memory, including stack
82 //
83 // CopyMem (PermanentMemoryBase, TemporaryMemoryBase, CopySize);
84 // %rdi, %rsi, %rdx
85 movq %r8, %rdi // Swizzle args
86 movq %rdx, %rsi
87 movq %r9, %rdx
88 call ASM_PFX(CopyMem)
89 // Temp mem stack now copied to permanent location. %esp still in temp memory
90
91 popq %r9 // CopySize (old stack)
92 popq %r8 // PermanentMemoryBase (old stack)
93 popq %rdx // TemporaryMemoryBase (old stack)
94
95 movq %rsp, %rcx // Move to new stack
96 subq %rdx, %rcx // Calc offset of stack in Temp Memory
97 addq %r8, %rcx // Calc PermanentMemoryBase address
98 movq %rcx, %rsp // Update stack
99 // Stack now points to permanent memory
100
101 // ZeroMem (TemporaryMemoryBase /* rdi */, CopySize /* rsi */);
102 movq %rdx, %rdi
103 movq %r9, %rsi
104 call ASM_PFX(ZeroMem)
105
106 // This data comes off the NEW stack
107 popq %rdi
108 popq %rsi
109 popq %rbp
110 ret
111
112