--- /dev/null
+;------------------------------------------------------------------------------\r
+; @file\r
+; Main routine of the pre-SEC code up through the jump into SEC\r
+;\r
+; Copyright (c) 2008 - 2009, Intel Corporation. All rights reserved.<BR>\r
+; SPDX-License-Identifier: BSD-2-Clause-Patent\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+\r
+BITS 16\r
+\r
+;\r
+; Modified: EBX, ECX, EDX, EBP\r
+;\r
+; @param[in,out] RAX/EAX Initial value of the EAX register\r
+; (BIST: Built-in Self Test)\r
+; @param[in,out] DI 'BP': boot-strap processor, or\r
+; 'AP': application processor\r
+; @param[out] RBP/EBP Address of Boot Firmware Volume (BFV)\r
+; @param[out] DS Selector allowing flat access to all addresses\r
+; @param[out] ES Selector allowing flat access to all addresses\r
+; @param[out] FS Selector allowing flat access to all addresses\r
+; @param[out] GS Selector allowing flat access to all addresses\r
+; @param[out] SS Selector allowing flat access to all addresses\r
+;\r
+; @return None This routine jumps to SEC and does not return\r
+;\r
+Main16:\r
+ OneTimeCall EarlyInit16\r
+\r
+ ;\r
+ ; Transition the processor from 16-bit real mode to 32-bit flat mode\r
+ ;\r
+ OneTimeCall TransitionFromReal16To32BitFlat\r
+\r
+BITS 32\r
+\r
+ ;\r
+ ; Search for the Boot Firmware Volume (BFV)\r
+ ;\r
+ OneTimeCall Flat32SearchForBfvBase\r
+\r
+ ;\r
+ ; EBP - Start of BFV\r
+ ;\r
+\r
+ ;\r
+ ; Search for the SEC entry point\r
+ ;\r
+ OneTimeCall Flat32SearchForSecEntryPoint\r
+\r
+ ;\r
+ ; ESI - SEC Core entry point\r
+ ; EBP - Start of BFV\r
+ ;\r
+\r
+%ifdef ARCH_IA32\r
+\r
+ ;\r
+ ; Restore initial EAX value into the EAX register\r
+ ;\r
+ mov eax, esp\r
+\r
+ ;\r
+ ; Jump to the 32-bit SEC entry point\r
+ ;\r
+ jmp esi\r
+\r
+%else\r
+\r
+ ;\r
+ ; Transition the processor from 32-bit flat mode to 64-bit flat mode\r
+ ;\r
+ OneTimeCall Transition32FlatTo64Flat\r
+\r
+BITS 64\r
+\r
+ ;\r
+ ; Some values were calculated in 32-bit mode. Make sure the upper\r
+ ; 32-bits of 64-bit registers are zero for these values.\r
+ ;\r
+ mov rax, 0x00000000ffffffff\r
+ and rsi, rax\r
+ and rbp, rax\r
+ and rsp, rax\r
+\r
+ ;\r
+ ; RSI - SEC Core entry point\r
+ ; RBP - Start of BFV\r
+ ;\r
+\r
+ ;\r
+ ; Restore initial EAX value into the RAX register\r
+ ;\r
+ mov rax, rsp\r
+\r
+ ;\r
+ ; Jump to the 64-bit SEC entry point\r
+ ;\r
+ jmp rsi\r
+\r
+%endif\r