xref: /netbsd-src/external/gpl3/gcc.old/dist/libgcc/config/sh/crti.S (revision fa28c6faa16e0b00edee7acdcaf4899797043def)
1/* Copyright (C) 2000-2013 Free Software Foundation, Inc.
2   This file was adapted from glibc sources.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 3, or (at your option) any
9later version.
10
11GCC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14General Public License for more details.
15
16Under Section 7 of GPL version 3, you are granted additional
17permissions described in the GCC Runtime Library Exception, version
183.1, as published by the Free Software Foundation.
19
20You should have received a copy of the GNU General Public License and
21a copy of the GCC Runtime Library Exception along with this program;
22see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23<http://www.gnu.org/licenses/>.  */
24
25
26/* The code in sections .init and .fini is supposed to be a single
27   regular function.  The function in .init is called directly from
28   start in crt1.S.  The function in .fini is atexit()ed in crt1.S
29   too.
30
31   crti.S contributes the prologue of a function to these sections,
32   and crtn.S comes up the epilogue.  STARTFILE_SPEC should list
33   crti.o before any other object files that might add code to .init
34   or .fini sections, and ENDFILE_SPEC should list crtn.o after any
35   such object files.  */
36
37	.section .init
38/* The alignment below can't be smaller, otherwise the mova below
39   breaks.  Yes, we might align just the label, but then we'd be
40   exchanging an alignment here for one there, since the code fragment
41   below ensures 4-byte alignment on __ELF__.  */
42#ifdef __ELF__
43	.p2align 2
44#else
45	.p2align 1
46#endif
47	.global	 _init
48_init:
49#if __SHMEDIA__
50	addi	r15, -16, r15
51	st.q	r15, 8, r14
52	st.q	r15, 0, r18
53	add	r15, r63, r14
54#elif __SH5__ && ! __SHMEDIA__
55	mov	r15,r0
56	add	#-8,r15
57	mov.l	r14,@-r0
58	sts.l	pr,@-r0
59	mov	r15,r14
60	nop
61#else
62#ifdef __ELF__
63	mov.l	r12,@-r15
64	mova	0f,r0
65	mov.l	0f,r12
66#endif
67	mov.l	r14,@-r15
68#ifdef __ELF__
69	add	r0,r12
70#endif
71	sts.l	pr,@-r15
72#ifdef __ELF__
73	bra	1f
74#endif
75	mov	r15,r14
76#ifdef __ELF__
770:	.long	_GLOBAL_OFFSET_TABLE_
781:
79#endif
80#endif /* __SHMEDIA__ */
81
82	.section .fini
83/* The alignment below can't be smaller, otherwise the mova below
84   breaks.  Yes, we might align just the label, but then we'd be
85   exchanging an alignment here for one there, since the code fragment
86   below ensures 4-byte alignment on __ELF__.  */
87#ifdef __ELF__
88	.p2align 2
89#else
90	.p2align 1
91#endif
92	.global  _fini
93_fini:
94#if __SHMEDIA__
95	addi	r15, -16, r15
96	st.q	r15, 8, r14
97	st.q	r15, 0, r18
98	add	r15, r63, r14
99#elif __SH5__ && ! __SHMEDIA__
100	mov	r15,r0
101	add	#-8,r15
102	mov.l	r14,@-r0
103	sts.l	pr,@-r0
104	mov	r15,r14
105	nop
106#else
107#ifdef __ELF__
108	mov.l	r12,@-r15
109	mova	0f,r0
110	mov.l	0f,r12
111#endif
112	mov.l	r14,@-r15
113#ifdef __ELF__
114	add	r0,r12
115#endif
116	sts.l	pr,@-r15
117#ifdef __ELF__
118	bra	1f
119#endif
120	mov	r15,r14
121#ifdef __ELF__
1220:	.long	_GLOBAL_OFFSET_TABLE_
1231:
124#endif
125#endif /* __SHMEDIA__ */
126