1/* Copyright (C) 2000-2015 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#include "crt.h"
26
27/* The code in sections .init and .fini is supposed to be a single
28   regular function.  The function in .init is called directly from
29   start in crt1.S.  The function in .fini is atexit()ed in crt1.S
30   too.
31
32   crti.S contributes the prologue of a function to these sections,
33   and crtn.S comes up the epilogue.  STARTFILE_SPEC should list
34   crti.o before any other object files that might add code to .init
35   or .fini sections, and ENDFILE_SPEC should list crtn.o after any
36   such object files.  */
37
38	.section .init
39/* The alignment below can't be smaller, otherwise the mova below
40   breaks.  Yes, we might align just the label, but then we'd be
41   exchanging an alignment here for one there, since the code fragment
42   below ensures 4-byte alignment on __ELF__.  */
43#ifdef __ELF__
44	.p2align 2
45#else
46	.p2align 1
47#endif
48	.global	 GLOBAL(_init)
49GLOBAL(_init):
50#if __SHMEDIA__
51	addi	r15, -16, r15
52	st.q	r15, 8, r14
53	st.q	r15, 0, r18
54	add	r15, r63, r14
55#elif __SH5__ && ! __SHMEDIA__
56	mov	r15,r0
57	add	#-8,r15
58	mov.l	r14,@-r0
59	sts.l	pr,@-r0
60	mov	r15,r14
61	nop
62#else
63#ifdef __ELF__
64	mov.l	r12,@-r15
65	mova	0f,r0
66	mov.l	0f,r12
67#endif
68	mov.l	r14,@-r15
69#ifdef __ELF__
70	add	r0,r12
71#endif
72	sts.l	pr,@-r15
73#ifdef __ELF__
74	bra	1f
75#endif
76	mov	r15,r14
77#ifdef __ELF__
780:	.long	_GLOBAL_OFFSET_TABLE_
791:
80#endif
81#endif /* __SHMEDIA__ */
82
83	.section .fini
84/* The alignment below can't be smaller, otherwise the mova below
85   breaks.  Yes, we might align just the label, but then we'd be
86   exchanging an alignment here for one there, since the code fragment
87   below ensures 4-byte alignment on __ELF__.  */
88#ifdef __ELF__
89	.p2align 2
90#else
91	.p2align 1
92#endif
93	.global  GLOBAL(_fini)
94GLOBAL(_fini):
95#if __SHMEDIA__
96	addi	r15, -16, r15
97	st.q	r15, 8, r14
98	st.q	r15, 0, r18
99	add	r15, r63, r14
100#elif __SH5__ && ! __SHMEDIA__
101	mov	r15,r0
102	add	#-8,r15
103	mov.l	r14,@-r0
104	sts.l	pr,@-r0
105	mov	r15,r14
106	nop
107#else
108#ifdef __ELF__
109	mov.l	r12,@-r15
110	mova	0f,r0
111	mov.l	0f,r12
112#endif
113	mov.l	r14,@-r15
114#ifdef __ELF__
115	add	r0,r12
116#endif
117	sts.l	pr,@-r15
118#ifdef __ELF__
119	bra	1f
120#endif
121	mov	r15,r14
122#ifdef __ELF__
1230:	.long	_GLOBAL_OFFSET_TABLE_
1241:
125#endif
126#endif /* __SHMEDIA__ */
127