1;------------------------------------------------------------------------------
2;
3; Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
4; Portions copyright (c) 2011, Apple Inc. All rights reserved.
5; SPDX-License-Identifier: BSD-2-Clause-Patent
6;
7;------------------------------------------------------------------------------
8
9EXTERN CopyMem:PROC
10EXTERN ZeroMem:PROC
11
12    .code
13
14;------------------------------------------------------------------------------
15;  EFI_STATUS
16;  EFIAPI
17;  SecTemporaryRamSupport (
18;    IN CONST EFI_PEI_SERVICES   **PeiServices,         // %rcx
19;    IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,   // %rdx
20;    IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,   // %r8
21;    IN UINTN                    CopySize               // %r9
22;    )
23;------------------------------------------------------------------------------
24SecTemporaryRamSupport PROC
25  ; Adjust callers %rbp to account for stack move
26  sub     rbp, rdx      ; Calc offset of %rbp in Temp Memory
27  add     rbp, r8       ; add in permanent base to offset
28
29  push    rbp           ; stack frame is for the debugger
30  mov     rbp, rsp
31
32  push    rdx           ; Save TemporaryMemoryBase
33  push    r8            ; Save PermanentMemoryBase
34  push    r9            ; Save CopySize
35
36  ;
37  ; Copy all of temp RAM to permanent memory, including stack
38  ;
39  ; CopyMem (PermanentMemoryBase, TemporaryMemoryBase, CopySize);
40  ;          %rcx,                %rdx,                %r8
41  mov     rcx, r8       ; Shift arguments
42  mov     r8, r9
43  sub     rsp, 028h     ; Allocate register spill area & 16-byte align stack
44  call    CopyMem
45  ; Temp mem stack now copied to permanent location. %esp still in temp memory
46  add     rsp, 028h
47
48  pop     r9            ; CopySize (old stack)
49  pop     r8            ; PermanentMemoryBase (old stack)
50  pop     rdx           ; TemporaryMemoryBase (old stack)
51
52  mov     rcx, rsp      ; Move to new stack
53  sub     rcx, rdx      ; Calc offset of stack in Temp Memory
54  add     rcx, r8       ; Calc PermanentMemoryBase address
55  mov     rsp, rcx      ; Update stack
56  ; Stack now points to permanent memory
57
58  ; ZeroMem (TemporaryMemoryBase /* rcx */, CopySize /* rdx */);
59  mov     rcx, rdx
60  mov     rdx, r9
61  sub     rsp, 028h     ; Allocate register spill area & 16-byte align stack
62  call    ZeroMem
63  add     rsp, 028h
64
65  ; This data comes off the NEW stack
66  pop     rbp
67  ret
68SecTemporaryRamSupport ENDP
69
70  END
71