fixed one bug when copy MAC address.
[edk2.git] / Nt32Pkg / Sec / Stack.asm
blobca6b7faaaadab07b09fa6d28546720d581c2e58f
1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2007, Intel Corporation
4 ; All rights reserved. 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
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.
12 ; Module Name:
14 ; Stack.asm
16 ; Abstract:
18 ; Switch the stack from temporary memory to permenent memory.
20 ;------------------------------------------------------------------------------
22 .586p
23 .model flat,C
24 .code
26 ;------------------------------------------------------------------------------
27 ; VOID
28 ; EFIAPI
29 ; SecSwitchStack (
30 ; UINT32 TemporaryMemoryBase,
31 ; UINT32 PermenentMemoryBase
32 ; );
33 ;------------------------------------------------------------------------------
34 SecSwitchStack PROC
36 ; Save three register: eax, ebx, ecx
38 push eax
39 push ebx
40 push ecx
41 push edx
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!
49 mov ebx, [esp + 20] ; Save the first parameter
50 mov ecx, [esp + 24] ; Save the second parameter
53 ; Save this function's return address into permenent memory at first.
54 ; Then, Fixup the esp point to permenent memory
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
72 ; Fixup the ebp point to permenent memory
74 mov eax, ebp
75 sub eax, ebx
76 add eax, ecx
77 mov ebp, eax ; From now, ebp is pointed to permenent memory
80 ; Fixup callee's ebp point for PeiDispatch
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
87 pop edx
88 pop ecx
89 pop ebx
90 pop eax
91 ret
92 SecSwitchStack ENDP
94 END