• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1;------------------------------------------------------------------------------
2;
3; Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
4; This program and the accompanying materials
5; are licensed and made available under the terms and conditions of the BSD License
6; which accompanies this distribution.  The full text of the license may be found at
7; http://opensource.org/licenses/bsd-license.php
8;
9; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11;
12; Module Name:
13;
14;   Stack.asm
15;
16; Abstract:
17;
18;   Switch the stack from temporary memory to permenent memory.
19;
20;------------------------------------------------------------------------------
21
22    .586p
23    .model  flat,C
24    .code
25
26;------------------------------------------------------------------------------
27; VOID
28; EFIAPI
29; SecSwitchStack (
30;   UINT32   TemporaryMemoryBase,
31;   UINT32   PermenentMemoryBase
32;   );
33;------------------------------------------------------------------------------
34SecSwitchStack   PROC
35    ;
36    ; Save three register: eax, ebx, ecx
37    ;
38    push  eax
39    push  ebx
40    push  ecx
41    push  edx
42
43    ;
44    ; !!CAUTION!! this function address's is pushed into stack after
45    ; migration of whole temporary memory, so need save it to permenent
46    ; memory at first!
47    ;
48
49    mov   ebx, [esp + 20]          ; Save the first parameter
50    mov   ecx, [esp + 24]          ; Save the second parameter
51
52    ;
53    ; Save this function's return address into permenent memory at first.
54    ; Then, Fixup the esp point to permenent memory
55    ;
56    mov   eax, esp
57    sub   eax, ebx
58    add   eax, ecx
59    mov   edx, dword ptr [esp]         ; copy pushed register's value to permenent memory
60    mov   dword ptr [eax], edx
61    mov   edx, dword ptr [esp + 4]
62    mov   dword ptr [eax + 4], edx
63    mov   edx, dword ptr [esp + 8]
64    mov   dword ptr [eax + 8], edx
65    mov   edx, dword ptr [esp + 12]
66    mov   dword ptr [eax + 12], edx
67    mov   edx, dword ptr [esp + 16]    ; Update this function's return address into permenent memory
68    mov   dword ptr [eax + 16], edx
69    mov   esp, eax                     ; From now, esp is pointed to permenent memory
70
71    ;
72    ; Fixup the ebp point to permenent memory
73    ;
74    mov   eax, ebp
75    sub   eax, ebx
76    add   eax, ecx
77    mov   ebp, eax                ; From now, ebp is pointed to permenent memory
78
79    ;
80    ; Fixup callee's ebp point for PeiDispatch
81    ;
82    mov   eax, dword ptr [ebp]
83    sub   eax, ebx
84    add   eax, ecx
85    mov   dword ptr [ebp], eax    ; From now, Temporary's PPI caller's stack is in permenent memory
86
87    pop   edx
88    pop   ecx
89    pop   ebx
90    pop   eax
91    ret
92SecSwitchStack   ENDP
93
94    END
95