OSDN Git Service

* config/ia64/crtend.asm: Include "auto-host.h".
[pf3gnuchains/gcc-fork.git] / gcc / config / ia64 / crtbegin.asm
1 /* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
2    Contributed by Jes Sorensen, <Jes.Sorensen@cern.ch>
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13
14    You should have received a copy of the GNU Library General Public
15    License along with the GNU C Library; see the file COPYING.LIB.  If not,
16    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17    Boston, MA 02111-1307, USA.  */
18
19 #include "auto-host.h"
20
21 .section .ctors,"aw","progbits"
22         .align  8
23 __CTOR_LIST__:
24         data8   -1
25
26 .section .dtors,"aw","progbits"
27         .align  8
28 __DTOR_LIST__:
29         data8   -1
30
31 .section .jcr,"aw","progbits"
32         .align  8
33 __JCR_LIST__:
34
35 .section .sdata
36         .type dtor_ptr#,@object
37         .size dtor_ptr#,8
38 dtor_ptr:
39         data8   @gprel(__DTOR_LIST__# + 8)
40
41         /* A handle for __cxa_finalize to manage c++ local destructors.  */
42         .global __dso_handle#
43         .type __dso_handle#,@object
44         .size __dso_handle#,8
45 #ifdef SHARED
46         .section .data
47 __dso_handle:
48         data8   __dso_handle#
49 #else
50         .section .bss
51 __dso_handle:
52         data8   0
53 #endif
54         .hidden __dso_handle#
55
56
57 #ifdef HAVE_INITFINI_ARRAY
58
59 .section .fini_array,"a","progbits"
60         data8 @fptr(__do_global_dtors_aux)
61
62 .section .init_array,"a","progbits"
63         data8 @fptr(__do_jv_register_classes)
64
65 #else /* !HAVE_INITFINI_ARRAY */
66 /*
67  * Fragment of the ELF _fini routine that invokes our dtor cleanup.
68  *
69  * We make the call by indirection, because in large programs the 
70  * .fini and .init sections are not in range of the destination, and
71  * we cannot allow the linker to insert a stub at the end of this
72  * fragment of the _fini function.  Further, Itanium does not implement
73  * the long branch instructions, and we do not wish every program to
74  * trap to the kernel for emulation.
75  *
76  * Note that we require __do_global_dtors_aux to preserve the GP,
77  * so that the next fragment in .fini gets the right value.
78  */
79 .section .fini,"ax","progbits"
80         { .mlx
81           movl r2 = @pcrel(__do_global_dtors_aux# - 16)
82         }
83         { .mii
84           mov r3 = ip
85           ;;
86           add r2 = r2, r3
87           ;;
88         }
89         { .mib
90           mov b6 = r2
91           br.call.sptk.many b0 = b6
92           ;;
93         }
94
95 /* Likewise for _init.  */
96
97 .section .init,"ax","progbits"
98         { .mlx
99           movl r2 = @pcrel(__do_jv_register_classes# - 16)
100         }
101         { .mii
102           mov r3 = ip
103           ;;
104           add r2 = r2, r3
105           ;;
106         }
107         { .mib
108           mov b6 = r2
109           br.call.sptk.many b0 = b6
110           ;;
111         }
112 #endif /* !HAVE_INITFINI_ARRAY */
113
114 .section .text
115         .align  16
116         .proc   __do_global_dtors_aux#
117 __do_global_dtors_aux:
118 #ifndef SHARED
119         { .mii
120           alloc loc3 = ar.pfs, 0, 4, 1, 0
121           addl loc0 = @gprel(dtor_ptr#), gp
122           mov loc1 = b0
123         }
124         { .mib
125           mov loc2 = gp
126           br.sptk.few 1f
127           ;;
128         }
129 #else
130         /*
131                 if (__cxa_finalize)
132                   __cxa_finalize(__dso_handle)
133         */
134         { .mii
135           alloc loc3 = ar.pfs, 0, 4, 1, 0
136           addl loc0 = @gprel(dtor_ptr#), gp
137           addl r16 = @ltoff(@fptr(__cxa_finalize#)), gp
138           ;;
139         }
140         { .mmi
141           ld8 r16 = [r16]
142           ;;
143           addl out0 = @ltoff(__dso_handle#), gp
144           cmp.ne p7, p0 = r0, r16
145           ;;
146         }
147         { .mmi
148           ld8 out0 = [out0]
149 (p7)      ld8 r18 = [r16], 8
150           mov loc1 = b0
151           ;;
152         }
153         { .mfi
154           mov loc2 = gp
155 (p7)      mov b6 = r18
156         }
157         {
158           .mfb
159 (p7)      ld8 gp = [r16]
160 (p7)      br.call.sptk.many b0 = b6
161         }
162         { .mfb
163           br.sptk.few 1f
164         }
165 #endif
166         /*
167                 do {
168                   dtor_ptr++;
169                   (*(dtor_ptr-1)) ();
170                 } while (dtor_ptr);
171         */
172 0:
173         { .mmi
174           st8 [loc0] = r15
175           ld8 r17 = [r16], 8
176           ;;
177         }
178         { .mib
179           ld8 gp = [r16]
180           mov b6 = r17
181           br.call.sptk.many b0 = b6
182         }
183 1:
184         { .mmi
185           ld8 r15 = [loc0]
186           ;;
187           add r16 = r15, loc2
188           adds r15 = 8, r15
189           ;;
190         }
191         { .mmi
192           ld8 r16 = [r16]
193           mov gp = loc2
194           mov b0 = loc1
195           ;;
196         }
197         { .mib
198           cmp.ne p6, p0 = r0, r16
199           mov ar.pfs = loc3
200 (p6)      br.cond.sptk.few 0b
201         }
202         { .bbb
203           br.ret.sptk.many b0
204           ;;
205         }
206         .endp   __do_global_dtors_aux#
207
208         .align  16
209         .proc   __do_jv_register_classes#
210 __do_jv_register_classes:
211         { .mlx
212           alloc loc2 = ar.pfs, 0, 3, 1, 0
213           movl out0 = @gprel(__JCR_LIST__)
214           ;;
215         }
216         { .mmi
217           addl r14 = @ltoff(@fptr(_Jv_RegisterClasses)), gp
218           add out0 = out0, gp
219           ;;
220         }
221         { .mmi
222           ld8 r14 = [r14]
223           ld8 r15 = [out0]
224           cmp.ne p6, p0 = r0, r0
225           ;;
226         }
227         { .mib
228           cmp.eq.or p6, p0 = r0, r14
229           cmp.eq.or p6, p0 = r0, r15
230 (p6)      br.ret.sptk.many b0
231         }
232         { .mii
233           ld8 r15 = [r14], 8
234           mov loc0 = b0
235           mov loc1 = gp
236           ;;
237         }
238         { .mib
239           ld8 gp = [r14]
240           mov b6 = r15
241           br.call.sptk.many b0 = b6
242           ;;
243         }
244         { .mii
245           mov gp = loc1
246           mov b0 = loc0
247           mov ar.pfs = loc2
248         }
249         { .bbb
250           br.ret.sptk.many b0
251           ;;
252         }
253         .endp   __do_jv_register_classes#
254
255 #ifdef SHARED
256 .weak __cxa_finalize#
257 #endif
258 .weak _Jv_RegisterClasses