OSDN Git Service

Update FSF address.
[pf3gnuchains/gcc-fork.git] / gcc / config / ia64 / crtbegin.asm
1 /* Copyright (C) 2000, 2001, 2003 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., 51 Franklin Street, Fifth Floor,
17    Boston, MA 02110-1301, 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         .align 8
52 __dso_handle:
53         .skip   8
54 #endif
55         .hidden __dso_handle
56
57
58 #ifdef HAVE_INITFINI_ARRAY
59
60 .section .fini_array, "a"
61         data8 @fptr(__do_global_dtors_aux)
62
63 .section .init_array, "a"
64         data8 @fptr(__do_jv_register_classes)
65         data8 @fptr(__do_global_ctors_aux)
66
67 #else /* !HAVE_INITFINI_ARRAY */
68 /*
69  * Fragment of the ELF _fini routine that invokes our dtor cleanup.
70  *
71  * We make the call by indirection, because in large programs the 
72  * .fini and .init sections are not in range of the destination, and
73  * we cannot allow the linker to insert a stub at the end of this
74  * fragment of the _fini function.  Further, Itanium does not implement
75  * the long branch instructions, and we do not wish every program to
76  * trap to the kernel for emulation.
77  *
78  * Note that we require __do_global_dtors_aux to preserve the GP,
79  * so that the next fragment in .fini gets the right value.
80  */
81 .section .fini,"ax","progbits"
82         { .mlx
83           movl r2 = @pcrel(__do_global_dtors_aux - 16)
84         }
85         { .mii
86           mov r3 = ip
87           ;;
88           add r2 = r2, r3
89           ;;
90         }
91         { .mib
92           nop 0
93           mov b6 = r2
94           br.call.sptk.many b0 = b6
95         }
96
97 /* Likewise for _init.  */
98
99 .section .init,"ax","progbits"
100         { .mlx
101           movl r2 = @pcrel(__do_jv_register_classes - 16)
102         }
103         { .mii
104           mov r3 = ip
105           ;;
106           add r2 = r2, r3
107           ;;
108         }
109         { .mib
110           nop 0
111           mov b6 = r2
112           br.call.sptk.many b0 = b6
113         }
114 #endif /* !HAVE_INITFINI_ARRAY */
115
116 .section .text
117         .align  32
118         .proc   __do_global_dtors_aux
119 __do_global_dtors_aux:
120         .prologue
121 #ifndef SHARED
122         .save ar.pfs, r35
123         alloc loc3 = ar.pfs, 0, 4, 1, 0
124         addl loc0 = @gprel(dtor_ptr), gp
125         .save rp, loc1
126         mov loc1 = rp
127         .body
128
129         mov loc2 = gp
130         nop 0
131         br.sptk.many .entry
132 #else
133         /*
134                 if (__cxa_finalize)
135                   __cxa_finalize(__dso_handle)
136         */
137         .save ar.pfs, r35
138         alloc loc3 = ar.pfs, 0, 4, 1, 0
139         addl loc0 = @gprel(dtor_ptr), gp
140         addl r16 = @ltoff(@fptr(__cxa_finalize)), gp
141         ;;
142
143         ld8 r16 = [r16]
144         ;;
145         addl out0 = @ltoff(__dso_handle), gp
146         cmp.ne p7, p0 = r0, r16
147         ;;
148
149         ld8 out0 = [out0]
150 (p7)    ld8 r18 = [r16], 8
151         .save rp, loc1
152         mov loc1 = rp
153         .body
154         ;;
155
156         mov loc2 = gp
157 (p7)    ld8 gp = [r16]
158 (p7)    mov b6 = r18
159
160         nop 0
161         nop 0
162 (p7)    br.call.sptk.many rp = b6
163         ;;
164
165         nop 0
166         nop 0
167         br.sptk.many .entry
168 #endif
169         /*
170                 do {
171                   dtor_ptr++;
172                   (*(dtor_ptr-1)) ();
173                 } while (dtor_ptr);
174         */
175 .loop:
176         st8 [loc0] = r15                // update dtor_ptr (in memory)
177         ld8 r17 = [r16], 8              // r17 <- dtor's entry-point
178         nop 0
179         ;;
180
181         ld8 gp = [r16]                  // gp <- dtor's gp
182         mov b6 = r17
183         br.call.sptk.many rp = b6
184
185 .entry: ld8 r15 = [loc0]                // r15 <- dtor_ptr (gp-relative)
186         ;;
187         add r16 = r15, loc2             // r16 <- dtor_ptr (absolute)
188         adds r15 = 8, r15
189         ;;
190
191         ld8 r16 = [r16]                 // r16 <- pointer to dtor's fdesc
192         mov rp = loc1
193         mov ar.pfs = loc3
194         ;;
195
196         cmp.ne p6, p0 = r0, r16
197 (p6)    br.cond.sptk.few .loop
198         br.ret.sptk.many rp
199         .endp __do_global_dtors_aux
200
201         .align  32
202         .proc   __do_jv_register_classes
203 __do_jv_register_classes:
204         .prologue
205         .save ar.pfs, r33
206         alloc loc1 = ar.pfs, 0, 3, 1, 0
207         movl out0 = @gprel(__JCR_LIST__)
208         ;;
209
210         addl r14 = @ltoff(@fptr(_Jv_RegisterClasses)), gp
211         add out0 = out0, gp
212         .save rp, loc0
213         mov loc0 = rp
214         .body
215         ;;
216
217         ld8 r14 = [r14]
218         ld8 r15 = [out0]
219         cmp.ne p6, p0 = r0, r0
220         ;;
221
222         cmp.eq.or p6, p0 = r0, r14
223         cmp.eq.or p6, p0 = r0, r15
224 (p6)    br.ret.sptk.many rp
225
226         ld8 r15 = [r14], 8
227         ;;
228         nop 0
229         mov b6 = r15
230
231         mov loc2 = gp
232         ld8 gp = [r14]
233         br.call.sptk.many rp = b6
234         ;;
235
236         mov gp = loc2
237         mov rp = loc0
238         mov ar.pfs = loc1
239
240         nop 0
241         nop 0
242         br.ret.sptk.many rp
243         .endp   __do_jv_register_classes
244
245 #ifdef SHARED
246 .weak __cxa_finalize
247 #endif
248 .weak _Jv_RegisterClasses