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