1/* $NetBSD: crt0-efi-ia32.S,v 1.1.1.2 2021/09/30 18:50:09 jmcneill Exp $ */ 2 3/* crt0-efi-ia32.S - x86 EFI startup code. 4 Copyright (C) 1999 Hewlett-Packard Co. 5 Contributed by David Mosberger <davidm@hpl.hp.com>. 6 7 All rights reserved. 8 9 Redistribution and use in source and binary forms, with or without 10 modification, are permitted provided that the following conditions 11 are met: 12 13 * Redistributions of source code must retain the above copyright 14 notice, this list of conditions and the following disclaimer. 15 * Redistributions in binary form must reproduce the above 16 copyright notice, this list of conditions and the following 17 disclaimer in the documentation and/or other materials 18 provided with the distribution. 19 * Neither the name of Hewlett-Packard Co. nor the names of its 20 contributors may be used to endorse or promote products derived 21 from this software without specific prior written permission. 22 23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 28 BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 29 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 33 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 34 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 SUCH DAMAGE. 36*/ 37 38 .text 39 .align 4 40 41 .globl _start 42_start: 43 pushl %ebp 44 movl %esp,%ebp 45 46 pushl 12(%ebp) # copy "image" argument 47 pushl 8(%ebp) # copy "systab" argument 48 49 call 0f 500: popl %eax 51 movl %eax,%ebx 52 53 addl $ImageBase-0b,%eax # %eax = ldbase 54 addl $_DYNAMIC-0b,%ebx # %ebx = _DYNAMIC 55 56 pushl %ebx # pass _DYNAMIC as second argument 57 pushl %eax # pass ldbase as first argument 58 call _relocate 59 popl %ebx 60 popl %ebx 61 testl %eax,%eax 62 jne .exit 63 64 call efi_main # call app with "image" and "systab" argument 65 66.exit: leave 67 ret 68 69 // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: 70 71 .data 72dummy: .long 0 73 74#define IMAGE_REL_ABSOLUTE 0 75 .section .reloc 76 .long dummy // Page RVA 77 .long 12 // Block Size (2*4+2*2), must be aligned by 32 Bits 78 .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy 79 .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy 80