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