xref: /DragonStub/gnuefi/crt0-efi-x86_64.S (revision deb8a7f267d96299b9aa41300539f617db54c2a9)
1/* crt0-efi-x86_64.S - x86_64 EFI startup code.
2   Copyright (C) 1999 Hewlett-Packard Co.
3	Contributed by David Mosberger <davidm@hpl.hp.com>.
4   Copyright (C) 2005 Intel Co.
5	Contributed by Fenghua Yu <fenghua.yu@intel.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	.text
38	.align 4
39
40	.globl _start
41	.type _start,%function
42_start:
43	subq $8, %rsp
44	pushq %rcx
45	pushq %rdx
46
470:
48	lea ImageBase(%rip), %rdi
49	lea _DYNAMIC(%rip), %rsi
50
51	popq %rcx
52	popq %rdx
53	pushq %rcx
54	pushq %rdx
55	call _relocate
56
57	popq %rdi
58	popq %rsi
59
60	call _entry
61	addq $8, %rsp
62
63.exit:
64  	ret
65
66 	// hand-craft a dummy .reloc section so EFI knows it's a relocatable executable:
67
68 	.data
69dummy:	.4byte	0
70
71#define IMAGE_REL_ABSOLUTE	0
72 	.section .reloc, "a"
73label1:
74	.4byte	dummy-label1				// Page RVA
75	.4byte	12					// Block Size (2*4+2*2), must be aligned by 32 Bits
76	.2byte	(IMAGE_REL_ABSOLUTE<<12) +  0		// reloc for dummy
77	.2byte	(IMAGE_REL_ABSOLUTE<<12) +  0		// reloc for dummy
78
79#if defined(__ELF__) && defined(__linux__)
80	.section .note.GNU-stack,"",%progbits
81#endif
82