OSDN Git Service

2000-07-30 Anthony Green <green@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / ia64 / crtbegin.asm
1 /* Copyright (C) 2000 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 .section .ctors,"aw","progbits"
20         .align  8
21 __CTOR_LIST__:
22         data8   -1
23
24 .section .dtors,"aw","progbits"
25         .align  8
26 __DTOR_LIST__:
27         data8   -1
28
29 .section .IA_64.unwind
30         .align  8
31 __EH_FRAME_BEGIN__:
32
33 .section .sdata
34         .type dtor_ptr#,@object
35         .size dtor_ptr#,8
36 dtor_ptr:
37         data8   __DTOR_LIST__# + 8
38
39         .type segrel_ofs#,@object
40         .size segrel_ofs#,8
41 segrel_ofs:
42         data8   @segrel(.Lsegrel_ref#)
43
44         /* A handle for __cxa_finalize to manage c++ local destructors.  */
45         .global __dso_handle#
46         .type __dso_handle#,@object
47         .size __dso_handle#,8
48 #ifdef SHARED
49         .section .data
50 __dso_handle:
51         data8   __dso_handle#
52 #else
53         .section .bss
54 __dso_handle:
55         data8   0
56 #endif
57 #ifdef HAVE_GAS_HIDDEN
58         .hidden __dso_handle#
59 #endif
60
61         /* The frame object.  */
62         /* ??? How can we rationally keep this size correct?  */
63 .section .bss
64         .type frame_object#,@object
65         .size frame_object#,64
66         .align 8
67 frame_object:
68         .zero 64
69
70 /*
71  * Fragment of the ELF _fini routine that invokes our dtor cleanup.
72  *
73  * We make the call by indirection, because in large programs the 
74  * .fini and .init sections are not in range of the destination, and
75  * we cannot allow the linker to insert a stub at the end of this
76  * fragment of the _fini function.  Further, Itanium does not implement
77  * the long branch instructions, and we do not wish every program to
78  * trap to the kernel for emulation.
79  *
80  * Note that we require __do_global_dtors_aux to preserve the GP,
81  * so that the next fragment in .fini gets the right value.
82  */
83 .section .fini,"ax","progbits"
84         { .mlx
85           movl r2 = @gprel(__do_global_dtors_aux#)
86           ;;
87         }
88         { .mii
89           nop.m 0
90           add r2 = r2, gp
91           ;;
92           mov b6 = r2
93         }
94         { .bbb
95           br.call.sptk.many b0 = b6
96           ;;
97         }
98
99 /*
100  * Fragment of the ELF _init routine that sets up the frame info.
101  */
102
103 .section .init,"ax","progbits"
104         { .mlx
105           movl r2 = @gprel(__do_frame_setup#)
106           ;;
107         }
108         { .mii
109           nop.m 0
110           add r2 = r2, gp
111           ;;
112           mov b6 = r2
113         }
114         { .bbb
115           br.call.sptk.many b0 = b6
116           ;;
117         }
118
119 .section .text
120         .align  16
121         .proc   __do_global_dtors_aux#
122 __do_global_dtors_aux:
123 #ifndef SHARED
124         { .mii
125           alloc loc3 = ar.pfs, 0, 4, 1, 0
126           addl loc0 = @gprel(dtor_ptr#), gp
127           mov loc1 = b0
128         }
129         { .mib
130           mov loc2 = gp
131           br.sptk.few 1f
132           ;;
133         }
134 #else
135         /*
136                 if (__cxa_finalize)
137                   __cxa_finalize(__dso_handle)
138         */
139         { .mii
140           alloc loc3 = ar.pfs, 0, 4, 1, 0
141           addl loc0 = @gprel(dtor_ptr#), gp
142           addl r16 = @ltoff(@fptr(__cxa_finalize#)), gp
143           ;;
144         }
145         { .mmi
146           ld8 r16 = [r16]
147           ;;
148           addl out0 = @ltoff(__dso_handle#), gp
149           cmp.ne p7, p0 = r0, r16
150           ;;
151         }
152         { .mmi
153           ld8 out0 = [out0]
154 (p7)      ld8 r18 = [r16], 8
155           mov loc1 = b0
156           ;;
157         }
158         { .mfi
159           mov loc2 = gp
160 (p7)      mov b6 = r18
161         }
162         {
163           .mfb
164 (p7)      ld8 gp = [r16]
165 (p7)      br.call.sptk.many b0 = b6
166         }
167         { .mfb
168           br.sptk.few 1f
169         }
170 #endif
171         /*
172                 do {
173                   dtor_ptr++;
174                   (*(dtor_ptr-1)) ();
175                 } while (dtor_ptr);
176         */
177 0:
178         { .mmi
179           st8 [loc0] = r15
180           ld8 r17 = [r16], 8
181           ;;
182         }
183         { .mib
184           ld8 gp = [r16]
185           mov b6 = r17
186           br.call.sptk.many b0 = b6
187         }
188 1:
189         { .mmi
190           ld8 r15 = [loc0]
191           ;;
192           ld8 r16 = [r15], 8
193           ;;
194         }
195         { .mfb
196           cmp.ne p6, p0 = r0, r16
197 (p6)      br.cond.sptk.few 0b
198         }
199         /*
200                 if (__deregister_frame_info)
201                   __deregister_frame_info(__EH_FRAME_BEGIN__)
202         */
203         { .mmi
204           mov gp = loc2
205           ;;
206           addl r16 = @ltoff(@fptr(__deregister_frame_info#)), gp
207           addl out0 = @ltoff(__EH_FRAME_BEGIN__#), gp
208           ;;
209         }
210         { .mmi
211           ld8 r16 = [r16]
212           ld8 out0 = [out0]
213           ;;
214         }
215         { .mmi
216           cmp.ne p7, p0 = r0, r16
217           ;;
218 (p7)      ld8 r18 = [r16], 8
219           ;;
220         }
221         { .mib
222 (p7)      ld8 gp = [r16]
223 (p7)      mov b6 = r18
224 (p7)      br.call.sptk.many b0 = b6
225         }
226         { .mii
227           mov gp = loc2
228           mov b0 = loc1
229           mov ar.pfs = loc3
230         }
231         { .bbb
232           br.ret.sptk.many b0
233           ;;
234         }
235         .endp   __do_global_dtors_aux#
236
237         .proc   __do_frame_setup#
238 __do_frame_setup:
239         /*
240                 if (__register_frame_info)
241                   __register_frame_info(__EH_FRAME_BEGIN__)
242         */
243         { .mii
244           alloc loc2 = ar.pfs, 0, 3, 2, 0
245           addl r16 = @ltoff(@fptr(__register_frame_info#)), gp
246           addl out0 = @ltoff(__EH_FRAME_BEGIN__#), gp
247         }
248         /* frame_object.pc_base = segment_base_offset;
249            pc_base is at offset 0 within frame_object.  */
250 .Lsegrel_ref:
251         { .mmi
252           addl out1 = @ltoff(frame_object#), gp
253           ;;
254           addl r2 = @gprel(segrel_ofs#), gp
255           mov r3 = ip
256           ;;
257         }
258         { .mmi
259           ld8 r2 = [r2]
260           ld8 r16 = [r16]
261           mov loc0 = b0
262           ;;
263         }
264         { .mii
265           ld8 out1 = [out1]
266           cmp.ne p7, p0 = r0, r16
267           sub r3 = r3, r2
268           ;;
269         }
270         { .mmi
271           st8 [out1] = r3 
272 (p7)      ld8 r18 = [r16], 8
273           mov loc1 = gp
274           ;;
275         }
276         { .mfb
277           ld8 out0 = [out0]  
278         }
279         { .mib
280 (p7)      ld8 gp = [r16]
281 (p7)      mov b6 = r18
282 (p7)      br.call.sptk.many b0 = b6
283         }
284         { .mii
285           mov gp = loc1
286           mov b0 = loc0
287           mov ar.pfs = loc2
288         }
289         { .bbb
290           br.ret.sptk.many b0
291           ;;
292         }
293         .endp   __do_frame_setup#
294
295 #ifdef SHARED
296 .weak __cxa_finalize#
297 #endif
298 .weak __deregister_frame_info#
299 .weak __register_frame_info#