]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/ResetVector/Vtf0/Ia32/SearchForSecEntry.asm
Adding files from OvmfPkg to common location. This is so multiple packages can use...
[mirror_edk2.git] / UefiCpuPkg / ResetVector / Vtf0 / Ia32 / SearchForSecEntry.asm
diff --git a/UefiCpuPkg/ResetVector/Vtf0/Ia32/SearchForSecEntry.asm b/UefiCpuPkg/ResetVector/Vtf0/Ia32/SearchForSecEntry.asm
new file mode 100644 (file)
index 0000000..01d0519
--- /dev/null
@@ -0,0 +1,196 @@
+;------------------------------------------------------------------------------\r
+; @file\r
+; Search for the SEC Core entry point\r
+;\r
+; Copyright (c) 2008 - 2009, 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
+;------------------------------------------------------------------------------\r
+\r
+BITS    32\r
+\r
+%define EFI_FV_FILETYPE_SECURITY_CORE         0x03\r
+\r
+;\r
+; Modified:  EAX, EBX, ECX, EDX\r
+; Preserved: EDI, EBP, ESP\r
+;\r
+; @param[in]   EBP  Address of Boot Firmware Volume (BFV)\r
+; @param[out]  ESI  SEC Core Entry Point Address\r
+;\r
+Flat32SearchForSecEntryPoint:\r
+\r
+    ;\r
+    ; Initialize EBP and ESI to 0\r
+    ;\r
+    xor     ebx, ebx\r
+    mov     esi, 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      secEntryPointWasNotFound\r
+\r
+    jmp     searchingForFfsFileHeaderLoop\r
+\r
+moveForwardWhileSearchingForFfsFileHeaderLoop:\r
+    ;\r
+    ; Make forward progress in the search\r
+    ;\r
+    inc     eax\r
+    jc      secEntryPointWasNotFound\r
+\r
+searchingForFfsFileHeaderLoop:\r
+    test    eax, eax\r
+    jz      secEntryPointWasNotFound\r
+\r
+    ;\r
+    ; Ensure 8 byte alignment\r
+    ;\r
+    add     eax, 7\r
+    jc      secEntryPointWasNotFound\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
+    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
+    cmp     byte [eax + 0x12], EFI_FV_FILETYPE_SECURITY_CORE ; Check File Type\r
+    jne     readyToTryFfsFileAtEcx\r
+\r
+fileTypeIsSecCore:\r
+    OneTimeCall GetEntryPointOfFfsFile\r
+    test    eax, eax\r
+    jnz     doneSeachingForSecEntryPoint\r
+\r
+readyToTryFfsFileAtEcx:\r
+    ;\r
+    ; Try the next FFS file at ECX\r
+    ;\r
+    mov     eax, ecx\r
+    jmp     searchingForFfsFileHeaderLoop\r
+\r
+secEntryPointWasNotFound:\r
+    xor     eax, eax\r
+\r
+doneSeachingForSecEntryPoint:\r
+    mov     esi, eax\r
+\r
+    test    esi, esi\r
+    jnz     secCoreEntryPointWasFound\r
+\r
+secCoreEntryPointWasNotFound:\r
+    ;\r
+    ; Hang if the SEC entry point was not found\r
+    ;\r
+    debugShowPostCode POSTCODE_SEC_NOT_FOUND\r
+    jz      $\r
+\r
+secCoreEntryPointWasFound:\r
+    debugShowPostCode POSTCODE_SEC_FOUND\r
+\r
+    OneTimeCallRet Flat32SearchForSecEntryPoint\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
+GetEntryPointOfFfsFile:\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
+    OneTimeCallRet GetEntryPointOfFfsFile\r
+\r