]> git.proxmox.com Git - mirror_edk2.git/blame - CorebootModulePkg/SecCore/Ia32/Stack.nasm
CorebootModulePkg/SecCore: Adding NASM files in SecCore module
[mirror_edk2.git] / CorebootModulePkg / SecCore / Ia32 / Stack.nasm
CommitLineData
365a3aab
MM
1;------------------------------------------------------------------------------\r
2;\r
3; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
4; This program and the accompanying materials\r
5; are licensed and made available under the terms and conditions of the BSD License\r
6; which accompanies this distribution. The full text of the license may be found at\r
7; http://opensource.org/licenses/bsd-license.php.\r
8;\r
9; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11;\r
12; Abstract:\r
13;\r
14; Switch the stack from temporary memory to permanent memory.\r
15;\r
16;------------------------------------------------------------------------------\r
17\r
18SECTION .text\r
19\r
20;------------------------------------------------------------------------------\r
21; VOID\r
22; EFIAPI\r
23; SecSwitchStack (\r
24; UINT32 TemporaryMemoryBase,\r
25; UINT32 PermenentMemoryBase\r
26; );\r
27;------------------------------------------------------------------------------\r
28global ASM_PFX(SecSwitchStack)\r
29ASM_PFX(SecSwitchStack):\r
30 ;\r
31 ; Save three register: eax, ebx, ecx\r
32 ;\r
33 push eax\r
34 push ebx\r
35 push ecx\r
36 push edx\r
37\r
38 ;\r
39 ; !!CAUTION!! this function address's is pushed into stack after\r
40 ; migration of whole temporary memory, so need save it to permanent\r
41 ; memory at first!\r
42 ;\r
43\r
44 mov ebx, [esp + 20] ; Save the first parameter\r
45 mov ecx, [esp + 24] ; Save the second parameter\r
46\r
47 ;\r
48 ; Save this function's return address into permanent memory at first.\r
49 ; Then, Fixup the esp point to permanent memory\r
50 ;\r
51 mov eax, esp\r
52 sub eax, ebx\r
53 add eax, ecx\r
54 mov edx, [esp] ; copy pushed register's value to permanent memory\r
55 mov [eax], edx\r
56 mov edx, [esp + 4]\r
57 mov [eax + 4], edx\r
58 mov edx, [esp + 8]\r
59 mov [eax + 8], edx\r
60 mov edx, [esp + 12]\r
61 mov [eax + 12], edx\r
62 mov edx, [esp + 16] ; Update return address into permanent memory\r
63 mov [eax + 16], edx\r
64 mov esp, eax ; From now, esp is pointed to permanent memory\r
65\r
66 ;\r
67 ; Fixup the ebp point to permenent memory\r
68 ;\r
69 mov eax, ebp\r
70 sub eax, ebx\r
71 add eax, ecx\r
72 mov ebp, eax ; From now, ebp is pointed to permanent memory\r
73\r
74 pop edx\r
75 pop ecx\r
76 pop ebx\r
77 pop eax\r
78 ret\r