1/* crt0-efi-ia64.S - IA-64 EFI startup code.
2   Copyright (C) 1999 Hewlett-Packard Co.
3	Contributed by David Mosberger <davidm@hpl.hp.com>.
4
5    All rights reserved.
6
7    Redistribution and use in source and binary forms, with or without
8    modification, are permitted provided that the following conditions
9    are met:
10
11    * Redistributions of source code must retain the above copyright
12      notice, this list of conditions and the following disclaimer.
13    * Redistributions in binary form must reproduce the above
14      copyright notice, this list of conditions and the following
15      disclaimer in the documentation and/or other materials
16      provided with the distribution.
17    * Neither the name of Hewlett-Packard Co. nor the names of its
18      contributors may be used to endorse or promote products derived
19      from this software without specific prior written permission.
20
21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
22    CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
26    BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31    TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
32    THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33    SUCH DAMAGE.
34*/
35	.text
36	.psr abi64
37	.psr lsb
38	.lsb
39
40	.proc _start
41_start:
42	alloc loc0=ar.pfs,2,2,2,0
43	mov loc1=rp
44	movl out0=@gprel(ImageBase)	// out0 <- ImageBase (ldbase)
45	;;
46	add out0=out0,gp
47	movl out1=@gprel(_DYNAMIC)	// out1 <- _DYNAMIC
48	;;		// avoid WAW on CFM
49	add out1=out1,gp
50	br.call.sptk.few rp=_relocate
51.Lret0:
52	cmp.ne p6,p0=r0,r8		// r8 == EFI_SUCCESS?
53(p6)	br.cond.sptk.few .exit		// no ->
54
55.Lret1:
56
57	mov out0=in0			// image handle
58	mov out1=in1			// systab
59	br.call.sptk.few rp=efi_main
60.Lret2:
61.exit:
62	mov ar.pfs=loc0
63	mov rp=loc1
64	;;
65	br.ret.sptk.few rp
66
67	.endp _start
68
69
70	// PE32+ wants a PLABEL, not the code address of the entry point:
71
72	.align 16
73	.global _start_plabel
74	.section .plabel, "a"
75_start_plabel:
76	data8	_start
77	data8	__gp
78
79	// hand-craft a .reloc section for the plabel:
80
81#define IMAGE_REL_BASED_DIR64	10
82
83	.section .reloc, "a"
84	data4	_start_plabel				// Page RVA
85	data4	12					// Block Size (2*4+2*2)
86	data2	(IMAGE_REL_BASED_DIR64<<12) +  0	// reloc for plabel's entry point
87	data2	(IMAGE_REL_BASED_DIR64<<12) +  8	// reloc for plabel's global pointer
88