xref: /openbsd/gnu/usr.bin/gcc/gcc/config/sh/crt1.asm (revision c87b03e5)
1/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
2   This file was pretty much copied from newlib.
3
4This file is part of GNU CC.
5
6GNU CC 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 2, or (at your option) any
9later version.
10
11In addition to the permissions in the GNU General Public License, the
12Free Software Foundation gives you unlimited permission to link the
13compiled version of this file into combinations with other programs,
14and to distribute those combinations without any restriction coming
15from the use of this file.  (The General Public License restrictions
16do apply in other respects; for example, they cover modification of
17the file, and distribution when not linked into a combine
18executable.)
19
20GNU CC is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program; see the file COPYING.  If not, write to
27the Free Software Foundation, 59 Temple Place - Suite 330,
28Boston, MA 02111-1307, USA.  */
29
30
31#ifdef __SH5__
32	.section .data,"aw"
33	.global ___data
34___data:
35
36	.section .rodata,"a"
37	.global ___rodata
38___rodata:
39
40#if __SH5__ == 64
41	.section .text,"ax"
42#define LOAD_ADDR(sym, reg) \
43	movi	(sym >> 48) & 65535, reg; \
44	shori	(sym >> 32) & 65535, reg; \
45	shori	(sym >> 16) & 65535, reg; \
46	shori	sym & 65535, reg
47#else
48	.mode	SHmedia
49	.section .text..SHmedia32,"ax"
50#define LOAD_ADDR(sym, reg) \
51	movi	(sym >> 16) & 65535, reg; \
52	shori	sym & 65535, reg
53#endif
54	.global start
55start:
56	LOAD_ADDR (_stack, r15)
57
58	pt/l	.Lzero_bss_loop, tr0
59	pt/l	_atexit, tr1
60	pt/l	_init, tr5
61	pt/l	___setup_argv_and_call_main, tr6
62	pt/l	_exit, tr7
63
64	! zero out bss
65	LOAD_ADDR (_edata, r0)
66	LOAD_ADDR (_end, r1)
67.Lzero_bss_loop:
68	stx.q	r0, r63, r63
69	addi	r0, 8, r0
70	bgt/l	r1, r0, tr0
71
72	LOAD_ADDR (___data, r26)
73	LOAD_ADDR (___rodata, r27)
74
75#if ! __SH4_NOFPU__
76#if __SH5__ == 32
77	pt/l ___set_fpscr, tr0
78	movi	0, r4
79	blink	tr0, r18
80#endif
81	getcon	sr, r0
82	! enable the FP unit, by resetting SR.FD
83	! also zero out SR.FR, SR.SZ and SR.PR, as mandated by the ABI
84	movi	0, r1
85	shori	0xf000, r1
86	andc	r0, r1, r0
87	putcon	r0, sr
88#endif
89
90	! arrange for exit to call fini
91	LOAD_ADDR (_fini, r2)
92	blink	tr1, r18
93
94	! call init
95	blink	tr5, r18
96
97	! call the mainline
98	blink	tr6, r18
99
100	! call exit
101	blink	tr7, r18
102
103#else
104	.section .text
105	.global	start
106start:
107	mov.l	stack_k,r15
108
109	! zero out bss
110	mov.l	edata_k,r0
111	mov.l	end_k,r1
112	mov	#0,r2
113start_l:
114	mov.l	r2,@r0
115	add	#4,r0
116	cmp/ge	r0,r1
117	bt	start_l
118
119#if defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__)
120	mov.l set_fpscr_k, r1
121	jsr @r1
122	mov #0,r4
123	lds r3,fpscr
124#endif /*  defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) */
125
126	! arrange for exit to call fini
127	mov.l	atexit_k,r0
128	mov.l	fini_k,r4
129	jsr	@r0
130	nop
131
132	! call init
133	mov.l	init_k,r0
134	jsr	@r0
135	nop
136
137	! call the mainline
138	mov.l	main_k,r0
139	jsr	@r0
140	nop
141
142	! call exit
143	mov	r0,r4
144	mov.l	exit_k,r0
145	jsr	@r0
146	nop
147
148	.align 2
149#if defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__)
150set_fpscr_k:
151	.long	___set_fpscr
152#endif /*  defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) */
153stack_k:
154	.long	_stack
155edata_k:
156	.long	_edata
157end_k:
158	.long	_end
159main_k:
160	.long	___setup_argv_and_call_main
161exit_k:
162	.long	_exit
163atexit_k:
164	.long	_atexit
165init_k:
166	.long	_init
167fini_k:
168	.long	_fini
169
170	! supplied for backward compatibility only, in case of linking
171	! code whose main() was compiled with an older version of GCC.
172	.global	___main
173___main:
174	rts
175	nop
176#endif
177