]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Sec/X64/SwitchRam.S
EmulatorPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmulatorPkg / Sec / X64 / SwitchRam.S
1 #------------------------------------------------------------------------------
2 #
3 # Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
4 # Portitions copyright (c) 2011, Apple Inc. All rights reserved.
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
6 #
7 #------------------------------------------------------------------------------
8
9
10
11 // EFI_STATUS
12 // EFIAPI
13 // SecTemporaryRamSupport (
14 // IN CONST EFI_PEI_SERVICES **PeiServices, // %rcx
15 // IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, // %rdx
16 // IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, // %r8
17 // IN UINTN CopySize // %r9
18 // )
19 //
20 ASM_GLOBAL ASM_PFX(SecTemporaryRamSupport)
21 ASM_PFX(SecTemporaryRamSupport):
22 // Adjust callers %rbp to account for stack move
23 subq %rdx, %rbp // Calc offset of %rbp in Temp Memory
24 addq %r8, %rbp // add in permanent base to offset
25
26 pushq %rbp // stack frame is for the debugger
27 movq %rsp, %rbp
28
29 pushq %rdx // Save TemporaryMemoryBase
30 pushq %r8 // Save PermanentMemoryBase
31 pushq %r9 // Save CopySize
32
33 //
34 // Copy all of temp RAM to permanent memory, including stack
35 //
36 // CopyMem (PermanentMemoryBase, TemporaryMemoryBase, CopySize);
37 // %rcx, %rdx, %r8
38 movq %r8, %rcx // Shift arguments
39 movq %r9, %r8
40 subq $0x28, %rsp // Allocate register spill area & 16-byte align stack
41 call ASM_PFX(CopyMem)
42 // Temp mem stack now copied to permanent location. %esp still in temp memory
43 addq $0x28, %rsp
44
45 popq %r9 // CopySize (old stack)
46 popq %r8 // PermanentMemoryBase (old stack)
47 popq %rdx // TemporaryMemoryBase (old stack)
48
49 movq %rsp, %rcx // Move to new stack
50 subq %rdx, %rcx // Calc offset of stack in Temp Memory
51 addq %r8, %rcx // Calc PermanentMemoryBase address
52 movq %rcx, %rsp // Update stack
53 // Stack now points to permanent memory
54
55 // ZeroMem (TemporaryMemoryBase /* rcx */, CopySize /* rdx */);
56 movq %rdx, %rcx
57 movq %r9, %rdx
58 subq $0x28, %rsp // Allocate register spill area & 16-byte align stack
59 call ASM_PFX(ZeroMem)
60 addq $0x28, %rsp
61
62 // This data comes off the NEW stack
63 popq %rbp
64 ret
65
66