]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/Sec/Stack.asm
UefiCpuPkg: Remove double \r
[mirror_edk2.git] / Nt32Pkg / Sec / Stack.asm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
5 ;
6 ; Module Name:
7 ;
8 ; Stack.asm
9 ;
10 ; Abstract:
11 ;
12 ; Switch the stack from temporary memory to permenent memory.
13 ;
14 ;------------------------------------------------------------------------------
15
16 .586p
17 .model flat,C
18 .code
19
20 ;------------------------------------------------------------------------------
21 ; VOID
22 ; EFIAPI
23 ; SecSwitchStack (
24 ; UINT32 TemporaryMemoryBase,
25 ; UINT32 PermenentMemoryBase
26 ; );
27 ;------------------------------------------------------------------------------
28 SecSwitchStack PROC
29 ;
30 ; Save three register: eax, ebx, ecx
31 ;
32 push eax
33 push ebx
34 push ecx
35 push edx
36
37 ;
38 ; !!CAUTION!! this function address's is pushed into stack after
39 ; migration of whole temporary memory, so need save it to permenent
40 ; memory at first!
41 ;
42
43 mov ebx, [esp + 20] ; Save the first parameter
44 mov ecx, [esp + 24] ; Save the second parameter
45
46 ;
47 ; Save this function's return address into permenent memory at first.
48 ; Then, Fixup the esp point to permenent memory
49 ;
50 mov eax, esp
51 sub eax, ebx
52 add eax, ecx
53 mov edx, dword ptr [esp] ; copy pushed register's value to permenent memory
54 mov dword ptr [eax], edx
55 mov edx, dword ptr [esp + 4]
56 mov dword ptr [eax + 4], edx
57 mov edx, dword ptr [esp + 8]
58 mov dword ptr [eax + 8], edx
59 mov edx, dword ptr [esp + 12]
60 mov dword ptr [eax + 12], edx
61 mov edx, dword ptr [esp + 16] ; Update this function's return address into permenent memory
62 mov dword ptr [eax + 16], edx
63 mov esp, eax ; From now, esp is pointed to permenent memory
64
65 ;
66 ; Fixup the ebp point to permenent memory
67 ;
68 mov eax, ebp
69 sub eax, ebx
70 add eax, ecx
71 mov ebp, eax ; From now, ebp is pointed to permenent memory
72
73 ;
74 ; Fixup callee's ebp point for PeiDispatch
75 ;
76 mov eax, dword ptr [ebp]
77 sub eax, ebx
78 add eax, ecx
79 mov dword ptr [ebp], eax ; From now, Temporary's PPI caller's stack is in permenent memory
80
81 pop edx
82 pop ecx
83 pop ebx
84 pop eax
85 ret
86 SecSwitchStack ENDP
87
88 END