]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/csu/ia64/crt1.S
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / lib / csu / ia64 / crt1.S
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$"
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 }
53 1:
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 {               .mfb
111                 mov             gp=GP
112                 nop             0
113                 br.call.sptk    b0=_init_tls
114 }
115 #ifdef GCRT
116 {               .mmi
117                 mov             gp=GP
118                 ;;
119                 addl            r14=@ltoff(@fptr(_mcleanup)),gp
120                 nop             0
121                 ;;
122 }
123 {               .mfb
124                 ld8             out0=[r14]
125                 nop             0
126                 br.call.sptk    b0=atexit
127                 ;;
128 }
129 #endif
130 {               .mmi
131                 mov             gp=GP
132                 ;;
133                 addl            r14=@ltoff(@fptr(_fini)),gp
134                 nop             0
135                 ;;
136 }
137 {               .mfb
138                 ld8             out0=[r14]
139                 nop             0
140                 br.call.sptk    b0=atexit
141                 ;;
142 }
143 #ifdef GCRT
144 {               .mmi
145                 mov             gp=GP
146                 ;;
147                 addl            r14=@ltoff(eprol),gp
148                 addl            r15=@ltoff(etext),gp
149                 ;;
150 }
151 {               .mmb
152                 ld8             out0=[r14]
153                 ld8             out1=[r15]
154                 br.call.sptk    b0=monstartup
155                 ;;
156 }
157 #endif
158 {               .mfb
159                 mov             gp=GP
160                 nop             0
161                 br.call.sptk    b0=_init
162                 ;;
163 }
164 {               .mmi
165                 mov             gp=GP
166                 mov             out0=ARGC
167                 mov             out1=ARGV
168 }
169 {               .mfb
170                 mov             out2=ENVP
171                 nop             0
172                 br.call.sptk    b0=main
173                 ;;
174 }
175 {               .mib
176                 mov             gp=GP
177                 mov             out0=r8
178                 br.call.sptk    b0=exit
179                 ;;
180 }
181                 .endp           _start
182
183 #ifdef GCRT
184 eprol:
185 #endif
186
187                 .rodata
188 .empty:         stringz         ""
189
190                 .sdata
191                 .global         __progname
192                 .size           __progname,8
193                 .type           __progname,@object
194 __progname:     data8           .empty
195
196                 .common         environ,8,8