UefiPayloadPkg: Enhance UEFI payload for coreboot and Slim Bootloader
[mirror_edk2.git] / UefiPayloadPkg / SecCore / Ia32 / Stack.nasm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
5 ;
6 ; Abstract:
7 ;
8 ; Switch the stack from temporary memory to permanent memory.
9 ;
10 ;------------------------------------------------------------------------------
11
12 SECTION .text
13
14 ;------------------------------------------------------------------------------
15 ; VOID
16 ; EFIAPI
17 ; SecSwitchStack (
18 ; UINT32 TemporaryMemoryBase,
19 ; UINT32 PermenentMemoryBase
20 ; );
21 ;------------------------------------------------------------------------------
22 global ASM_PFX(SecSwitchStack)
23 ASM_PFX(SecSwitchStack):
24 ;
25 ; Save three register: eax, ebx, ecx
26 ;
27 push eax
28 push ebx
29 push ecx
30 push edx
31
32 ;
33 ; !!CAUTION!! this function address's is pushed into stack after
34 ; migration of whole temporary memory, so need save it to permanent
35 ; memory at first!
36 ;
37
38 mov ebx, [esp + 20] ; Save the first parameter
39 mov ecx, [esp + 24] ; Save the second parameter
40
41 ;
42 ; Save this function's return address into permanent memory at first.
43 ; Then, Fixup the esp point to permanent memory
44 ;
45 mov eax, esp
46 sub eax, ebx
47 add eax, ecx
48 mov edx, [esp] ; copy pushed register's value to permanent memory
49 mov [eax], edx
50 mov edx, [esp + 4]
51 mov [eax + 4], edx
52 mov edx, [esp + 8]
53 mov [eax + 8], edx
54 mov edx, [esp + 12]
55 mov [eax + 12], edx
56 mov edx, [esp + 16] ; Update return address into permanent memory
57 mov [eax + 16], edx
58 mov esp, eax ; From now, esp is pointed to permanent memory
59
60 ;
61 ; Fixup the ebp point to permanent memory
62 ;
63 mov eax, ebp
64 sub eax, ebx
65 add eax, ecx
66 mov ebp, eax ; From now, ebp is pointed to permanent memory
67
68 pop edx
69 pop ecx
70 pop ebx
71 pop eax
72 ret