1/* Copyright (C) 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
2   Contributed by Jes Sorensen, <Jes.Sorensen@cern.ch>
3
4   This file is part of GCC.
5
6   GCC is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   GCC is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with GCC; see the file COPYING.  If not, write to
18   the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19   Boston, MA 02110-1301, USA.  */
20
21/* As a special exception, if you link this library with other files,
22   some of which are compiled with GCC, to produce an executable,
23   this library does not by itself cause the resulting executable
24   to be covered by the GNU General Public License.
25   This exception does not however invalidate any other reasons why
26   the executable file might be covered by the GNU General Public License.  */
27
28#include "auto-host.h"
29
30.section .ctors,"aw","progbits"
31	.align	8
32__CTOR_END__:
33	data8	0
34
35.section .dtors,"aw","progbits"
36	.align 8
37__DTOR_END__:
38	data8	0
39
40.section .jcr,"aw","progbits"
41	.align 8
42__JCR_END__:
43	data8	0
44
45#ifdef HAVE_INITFINI_ARRAY
46	.global __do_global_ctors_aux
47	.hidden	__do_global_ctors_aux
48#else /* !HAVE_INITFINI_ARRAY */
49/*
50 * Fragment of the ELF _init routine that invokes our dtor cleanup.
51 *
52 * We make the call by indirection, because in large programs the 
53 * .fini and .init sections are not in range of the destination, and
54 * we cannot allow the linker to insert a stub at the end of this
55 * fragment of the _fini function.  Further, Itanium does not implement
56 * the long branch instructions, and we do not wish every program to
57 * trap to the kernel for emulation.
58 *
59 * Note that we require __do_global_ctors_aux to preserve the GP,
60 * so that the next fragment in .fini gets the right value.
61 */
62.section .init,"ax","progbits"
63	{ .mlx
64	  movl r2 = @pcrel(__do_global_ctors_aux - 16)
65	}
66	{ .mii
67	  mov r3 = ip
68	  ;;
69	  add r2 = r2, r3
70	  ;;
71	}
72	{ .mib
73	  mov b6 = r2
74	  br.call.sptk.many b0 = b6
75	  ;;
76	}
77#endif /* !HAVE_INITFINI_ARRAY */
78
79.text
80	.align 32
81	.proc __do_global_ctors_aux
82__do_global_ctors_aux:
83	.prologue
84	/*
85		for (loc0 = __CTOR_END__-1; *p != -1; --p)
86		  (*p) ();
87	*/
88	.save ar.pfs, r34
89	alloc loc2 = ar.pfs, 0, 5, 0, 0
90	movl loc0 = @gprel(__CTOR_END__ - 8)
91	;;
92
93	add loc0 = loc0, gp
94	;;
95	ld8 loc3 = [loc0], -8
96	.save rp, loc1
97	mov loc1 = rp
98	.body
99	;;
100
101	cmp.eq p6, p0 = -1, loc3
102	mov loc4 = gp
103(p6)	br.cond.spnt.few .exit
104
105.loop:	ld8 r15 = [loc3], 8
106	;;
107	ld8 gp = [loc3]
108	mov b6 = r15
109
110	ld8 loc3 = [loc0], -8
111	nop 0
112	br.call.sptk.many rp = b6
113	;;
114
115	cmp.ne p6, p0 = -1, loc3
116	nop 0
117(p6)	br.cond.sptk.few .loop
118
119.exit:	mov gp = loc3
120	mov rp = loc1
121	mov ar.pfs = loc2
122
123	br.ret.sptk.many rp
124	.endp __do_global_ctors_aux
125