crt0-efi-ia32.S revision 1.1.1.2
11.1Sjakllsch/* $NetBSD: crt0-efi-ia32.S,v 1.1.1.2 2021/09/30 18:50:09 jmcneill Exp $ */ 21.1Sjakllsch 31.1Sjakllsch/* crt0-efi-ia32.S - x86 EFI startup code. 41.1Sjakllsch Copyright (C) 1999 Hewlett-Packard Co. 51.1Sjakllsch Contributed by David Mosberger <davidm@hpl.hp.com>. 61.1Sjakllsch 71.1Sjakllsch All rights reserved. 81.1Sjakllsch 91.1Sjakllsch Redistribution and use in source and binary forms, with or without 101.1Sjakllsch modification, are permitted provided that the following conditions 111.1Sjakllsch are met: 121.1Sjakllsch 131.1Sjakllsch * Redistributions of source code must retain the above copyright 141.1Sjakllsch notice, this list of conditions and the following disclaimer. 151.1Sjakllsch * Redistributions in binary form must reproduce the above 161.1Sjakllsch copyright notice, this list of conditions and the following 171.1Sjakllsch disclaimer in the documentation and/or other materials 181.1Sjakllsch provided with the distribution. 191.1Sjakllsch * Neither the name of Hewlett-Packard Co. nor the names of its 201.1Sjakllsch contributors may be used to endorse or promote products derived 211.1Sjakllsch from this software without specific prior written permission. 221.1Sjakllsch 231.1Sjakllsch THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 241.1Sjakllsch CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 251.1Sjakllsch INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 261.1Sjakllsch MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 271.1Sjakllsch DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 281.1Sjakllsch BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 291.1Sjakllsch OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 301.1Sjakllsch PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 311.1Sjakllsch PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 321.1Sjakllsch THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 331.1Sjakllsch TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 341.1Sjakllsch THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 351.1Sjakllsch SUCH DAMAGE. 361.1Sjakllsch*/ 371.1Sjakllsch 381.1Sjakllsch .text 391.1Sjakllsch .align 4 401.1Sjakllsch 411.1Sjakllsch .globl _start 421.1Sjakllsch_start: 431.1Sjakllsch pushl %ebp 441.1Sjakllsch movl %esp,%ebp 451.1Sjakllsch 461.1Sjakllsch pushl 12(%ebp) # copy "image" argument 471.1Sjakllsch pushl 8(%ebp) # copy "systab" argument 481.1Sjakllsch 491.1Sjakllsch call 0f 501.1Sjakllsch0: popl %eax 511.1Sjakllsch movl %eax,%ebx 521.1Sjakllsch 531.1Sjakllsch addl $ImageBase-0b,%eax # %eax = ldbase 541.1Sjakllsch addl $_DYNAMIC-0b,%ebx # %ebx = _DYNAMIC 551.1Sjakllsch 561.1Sjakllsch pushl %ebx # pass _DYNAMIC as second argument 571.1Sjakllsch pushl %eax # pass ldbase as first argument 581.1Sjakllsch call _relocate 591.1Sjakllsch popl %ebx 601.1Sjakllsch popl %ebx 611.1Sjakllsch testl %eax,%eax 621.1Sjakllsch jne .exit 631.1Sjakllsch 641.1Sjakllsch call efi_main # call app with "image" and "systab" argument 651.1Sjakllsch 661.1Sjakllsch.exit: leave 671.1Sjakllsch ret 681.1Sjakllsch 691.1Sjakllsch // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: 701.1Sjakllsch 711.1Sjakllsch .data 721.1Sjakllschdummy: .long 0 731.1Sjakllsch 741.1Sjakllsch#define IMAGE_REL_ABSOLUTE 0 751.1Sjakllsch .section .reloc 761.1Sjakllsch .long dummy // Page RVA 771.1.1.2Sjmcneill .long 12 // Block Size (2*4+2*2), must be aligned by 32 Bits 781.1.1.2Sjmcneill .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy 791.1.1.2Sjmcneill .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy 80