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