+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2008, Intel Corporation\r
-; All rights reserved. This program and the accompanying materials\r
-; are licensed and made available under the terms and conditions of the BSD License\r
-; which accompanies this distribution. The full text of the license may be found at\r
-; http://opensource.org/licenses/bsd-license.php\r
-;\r
-; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-;\r
-; Module Name:\r
-;\r
-; SearchForSecAndPeiEntry.asm\r
-;\r
-; Abstract:\r
-;\r
-; Search for the SEC Core and PEI Core entry points\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
-BITS 32\r
-\r
-%define EFI_FV_FILETYPE_SECURITY_CORE 0x03\r
-%define EFI_FV_FILETYPE_PEI_CORE 0x04\r
-\r
-;\r
-; Input:\r
-; EBP - BFV Base Address\r
-;\r
-; Output:\r
-; ESI - SEC Core Entry Point Address (or 0 if not found)\r
-; EDI - PEI Core Entry Point Address (or 0 if not found)\r
-;\r
-; Modified:\r
-; EAX, EBX, ECX\r
-;\r
-Flat32SearchForSecAndPeiEntries:\r
-\r
- ;\r
- ; Initialize EBP and ESI to 0\r
- ;\r
- xor ebx, ebx\r
- mov esi, ebx\r
- mov edi, ebx\r
-\r
- ;\r
- ; Pass over the BFV header\r
- ;\r
- mov eax, ebp\r
- mov bx, [ebp + 0x30]\r
- add eax, ebx\r
- jc doneSeachingForSecAndPeiEntries\r
-\r
- jmp searchingForFfsFileHeaderLoop\r
-\r
-moveForwardWhileSearchingForFfsFileHeaderLoop:\r
- ;\r
- ; Make forward progress in the search\r
- ;\r
- inc eax\r
- jc doneSeachingForSecAndPeiEntries\r
-\r
-searchingForFfsFileHeaderLoop:\r
- test eax, eax\r
- jz doneSeachingForSecAndPeiEntries\r
-\r
- ;\r
- ; Ensure 8 byte alignment\r
- ;\r
- add eax, 7\r
- jc doneSeachingForSecAndPeiEntries\r
- and al, 0xf8\r
-\r
- ;\r
- ; Look to see if there is an FFS file at eax\r
- ;\r
- mov bl, [eax + 0x17]\r
- test bl, 0x20\r
- jz moveForwardWhileSearchingForFfsFileHeaderLoop\r
- mov ecx, [eax + 0x14]\r
- and ecx, 0x00ffffff\r
- or ecx, ecx\r
- jz moveForwardWhileSearchingForFfsFileHeaderLoop\r
-; jmp $\r
- add ecx, eax\r
- jz jumpSinceWeFoundTheLastFfsFile\r
- jc moveForwardWhileSearchingForFfsFileHeaderLoop\r
-jumpSinceWeFoundTheLastFfsFile:\r
-\r
- ;\r
- ; There seems to be a valid file at eax\r
- ;\r
- mov bl, [eax + 0x12] ; BL - File Type\r
- cmp bl, EFI_FV_FILETYPE_PEI_CORE\r
- je fileTypeIsPeiCore\r
- cmp bl, EFI_FV_FILETYPE_SECURITY_CORE\r
- jne readyToTryFfsFileAtEcx\r
-\r
-fileTypeIsSecCore:\r
- callEdx GetEntryPointOfFfsFileReturnEdx\r
- test eax, eax\r
- jz readyToTryFfsFileAtEcx\r
-\r
- mov esi, eax\r
- jmp readyToTryFfsFileAtEcx\r
-\r
-fileTypeIsPeiCore:\r
- callEdx GetEntryPointOfFfsFileReturnEdx\r
- test eax, eax\r
- jz readyToTryFfsFileAtEcx\r
-\r
- mov edi, eax\r
-\r
-readyToTryFfsFileAtEcx:\r
- mov eax, ecx\r
- jmp searchingForFfsFileHeaderLoop\r
-\r
-doneSeachingForSecAndPeiEntries:\r
-\r
- test esi, esi\r
- jnz secCoreEntryPointWasFound\r
- writeToSerialPort '!'\r
-secCoreEntryPointWasFound:\r
- writeToSerialPort 'S'\r
- writeToSerialPort 'E'\r
- writeToSerialPort 'C'\r
- writeToSerialPort ' '\r
-\r
- test edi, edi\r
- jnz peiCoreEntryPointWasFound\r
- writeToSerialPort '!'\r
-peiCoreEntryPointWasFound:\r
- writeToSerialPort 'P'\r
- writeToSerialPort 'E'\r
- writeToSerialPort 'I'\r
- writeToSerialPort ' '\r
-\r
- OneTimeCallRet Flat32SearchForSecAndPeiEntries\r
-\r
-\r
-%define EFI_SECTION_PE32 0x10\r
-\r
-;\r
-; Input:\r
-; EAX - Start of FFS file\r
-; ECX - End of FFS file\r
-;\r
-; Output:\r
-; EAX - Entry point of PE32 (or 0 if not found)\r
-;\r
-; Modified:\r
-; EBX\r
-;\r
-GetEntryPointOfFfsFileReturnEdx:\r
- test eax, eax\r
- jz getEntryPointOfFfsFileErrorReturn\r
- add eax, 0x18 ; EAX = Start of section\r
-\r
-getEntryPointOfFfsFileLoopForSections:\r
- cmp eax, ecx\r
- jae getEntryPointOfFfsFileErrorReturn\r
-\r
- cmp byte [eax + 3], EFI_SECTION_PE32\r
- je getEntryPointOfFfsFileFoundPe32Section\r
-\r
- ;\r
- ; The section type was not PE32, so move to next section\r
- ;\r
- mov ebx, dword [eax]\r
- and ebx, 0x00ffffff\r
- add eax, ebx\r
- jc getEntryPointOfFfsFileErrorReturn\r
-\r
- ;\r
- ; Ensure that FFS section is 32-bit aligned\r
- ;\r
- add eax, 3\r
- jc getEntryPointOfFfsFileErrorReturn\r
- and al, 0xfc\r
- jmp getEntryPointOfFfsFileLoopForSections\r
-\r
-getEntryPointOfFfsFileFoundPe32Section:\r
- add eax, 4 ; EAX = Start of PE32 image\r
-\r
- mov ebx, eax\r
- cmp word [eax], 'MZ'\r
- jne thereIsNotAnMzSignature\r
- movzx ebx, word [eax + 0x3c]\r
- add ebx, eax\r
-thereIsNotAnMzSignature:\r
-\r
- ; if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE)\r
- cmp word [ebx], 'VZ'\r
- jne thereIsNoVzSignature\r
- ; *EntryPoint = (VOID *)((UINTN)Pe32Data +\r
- ; (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) +\r
- ; sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);\r
- add eax, [ebx + 0x8]\r
- add eax, 0x28\r
- movzx ebx, word [ebx + 0x6]\r
- sub eax, ebx\r
- jmp getEntryPointOfFfsFileReturn\r
-\r
-thereIsNoVzSignature:\r
-\r
- ; if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)\r
- cmp dword [ebx], `PE\x00\x00`\r
- jne getEntryPointOfFfsFileErrorReturn\r
-\r
- ; *EntryPoint = (VOID *)((UINTN)Pe32Data +\r
- ; (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));\r
- add eax, [ebx + 0x4 + 0x14 + 0x10]\r
- jmp getEntryPointOfFfsFileReturn\r
-\r
-getEntryPointOfFfsFileErrorReturn:\r
- mov eax, 0\r
-\r
-getEntryPointOfFfsFileReturn:\r
- jmp edx\r
-\r
-\r