1 #------------------------------------------------------------------------------
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.
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.
13 #------------------------------------------------------------------------------
16 #------------------------------------------------------------------------------
17 # Routine Description:
19 # Routine for switching stacks with 3 parameters EFI ABI
20 # Convert UNIX to EFI ABI
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.
34 #------------------------------------------------------------------------------
35 ASM_GLOBAL ASM_PFX(PeiSwitchStacks)
36 ASM_PFX(PeiSwitchStacks):
37 pushq $0 // tells gdb to stop unwinding frame
47 # Reserve space for register parameters (rcx, rdx, r8 & r9) on the stack,
48 # in case the callee wishes to spill them.
50 subq $32, %rsp // 32-byte shadow space plus alignment pad
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
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
70 pushq %rbp // stack frame is for the debugger
73 pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
76 pushq %rdx // Save TemporaryMemoryBase
77 pushq %r8 // Save PermanentMemoryBase
78 pushq %r9 // Save CopySize
81 // Copy all of temp RAM to permanent memory, including stack
83 // CopyMem (PermanentMemoryBase, TemporaryMemoryBase, CopySize);
85 movq %r8, %rdi // Swizzle args
89 // Temp mem stack now copied to permanent location. %esp still in temp memory
91 popq %r9 // CopySize (old stack)
92 popq %r8 // PermanentMemoryBase (old stack)
93 popq %rdx // TemporaryMemoryBase (old stack)
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
101 // ZeroMem (TemporaryMemoryBase /* rdi */, CopySize /* rsi */);
104 call ASM_PFX(ZeroMem)
106 // This data comes off the NEW stack