crt1.S revision 117606
1/*
2 * Copyright (c) 2003 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27		.ident		"$FreeBSD: head/lib/csu/ia64/crt1.S 117606 2003-07-15 03:50:38Z marcel $"
28
29		.text
30
31/*
32 * void _start(char **ap, struct ps_strings *, void (*cleanup)(void));
33 */
34#define	AP		in0
35#define	CLEANUP		in2
36
37#define	GP		loc0
38#define	ARGC		loc1
39#define	ARGV		loc2
40#define	ENVP		loc3
41
42		.global		_start
43		.type		_start, @function
44		.proc		_start
45_start:
46		.prologue
47		.save		rp, r0
48		.body
49{		.mlx
50		alloc		r14=ar.pfs,3,4,3,0
51		movl		r15=@gprel(1f)
52}
531:
54{		.mmi
55		ld4		ARGC=[AP]
56		adds		ARGV=8,AP
57		mov		r16=ip
58		;;
59}
60{		.mmi
61		sub		gp=r16,r15
62		sub		GP=r16,r15
63		shladd		r14=ARGC,3,AP
64		;;
65}
66{		.mii
67		addl		r15=@ltoff(environ),gp
68		cmp4.ge		p6,p7=0,ARGC
69		adds		ENVP=16,r14
70		;;
71}
72{		.mmi
73		ld8		r14=[r15]
74(p7)		ld8		r15=[ARGV]
75		addl		r16=@gprel(__progname),gp
76		;;
77}
78{		.mib
79		st8		[r14]=ENVP
80(p7)		cmp.eq		p6,p0=0,r15
81(p6)		br.dpnt		.L1
82		;;
83}
84		/* Normalize __progname. */
85{		.mmi
86		st8		[r16]=r15
87		ld1		r14=[r15],1
88		nop		0
89		;;
90}
91.L0:
92{		.mib
93		cmp4.eq		p7,p0=0,r14
94		cmp4.eq		p6,p0=0x2f,r14
95(p7)		br.dptk		.L1
96		;;
97}
98{		.mmb
99(p6)		st8		[r16]=r15
100		ld1		r14=[r15],1
101		br.dptk.many	.L0
102}
103.L1:
104{		.mib
105		cmp.ne		p7,p0=0,CLEANUP
106		mov		out0=CLEANUP
107(p7)		br.call.sptk	b0=atexit
108		;;
109}
110#ifdef GCRT
111{		.mmi
112		mov		gp=GP
113		;;
114		addl		r14=@ltoff(@fptr(_mcleanup)),gp
115		nop		0
116		;;
117}
118{		.mfb
119		ld8		out0=[r14]
120		nop		0
121		br.call.sptk	b0=atexit
122		;;
123}
124#endif
125{		.mmi
126		mov		gp=GP
127		;;
128		addl		r14=@ltoff(@fptr(_fini)),gp
129		nop		0
130		;;
131}
132{		.mfb
133		ld8		out0=[r14]
134		nop		0
135		br.call.sptk	b0=atexit
136		;;
137}
138#ifdef GCRT
139{		.mmi
140		mov		gp=GP
141		;;
142		addl		r14=@ltoff(eprol),gp
143		addl		r15=@ltoff(etext),gp
144		;;
145}
146{		.mmb
147		ld8		out0=[r14]
148		ld8		out1=[r15]
149		br.call.sptk	b0=monstartup
150		;;
151}
152#endif
153{		.mfb
154		mov		gp=GP
155		nop		0
156		br.call.sptk	b0=_init
157		;;
158}
159{		.mmi
160		mov		gp=GP
161		mov		out0=ARGC
162		mov		out1=ARGV
163}
164{		.mfb
165		mov		out2=ENVP
166		nop		0
167		br.call.sptk	b0=main
168		;;
169}
170{		.mib
171		mov		gp=GP
172		mov		out0=r8
173		br.call.sptk	b0=exit
174		;;
175}
176		.endp		_start
177
178#ifdef GCRT
179eprol:
180#endif
181
182		.rodata
183.empty:		stringz		""
184
185		.sdata
186		.global		__progname
187		.size		__progname,8
188		.type		__progname,@object
189__progname:	data8		.empty
190
191		.common		environ,8,8
192