Introduce sh2a support.
[official-gcc.git] / gcc / config / sh / crt1.asm
blobf2c4e0d7bebc7843f5fd0979d03158171b561d2b
1 /* Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc.
2 This file was pretty much copied from newlib.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file into combinations with other programs,
14 and to distribute those combinations without any restriction coming
15 from the use of this file. (The General Public License restrictions
16 do apply in other respects; for example, they cover modification of
17 the file, and distribution when not linked into a combine
18 executable.)
20 GCC is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; see the file COPYING. If not, write to
27 the Free Software Foundation, 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
31 #ifdef __SH5__
32 .section .data,"aw"
33 .global ___data
34 ___data:
36 .section .rodata,"a"
37 .global ___rodata
38 ___rodata:
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
55 start:
56 LOAD_ADDR (_stack, r15)
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
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
72 LOAD_ADDR (___data, r26)
73 LOAD_ADDR (___rodata, r27)
75 #if ! __SH4_NOFPU__ && ! __SH2A_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
90 ! arrange for exit to call fini
91 LOAD_ADDR (_fini, r2)
92 blink tr1, r18
94 ! call init
95 blink tr5, r18
97 ! call the mainline
98 blink tr6, r18
100 ! call exit
101 blink tr7, r18
103 #else
104 .section .text
105 .global start
106 start:
107 mov.l stack_k,r15
109 ! zero out bss
110 mov.l edata_k,r0
111 mov.l end_k,r1
112 mov #0,r2
113 start_l:
114 mov.l r2,@r0
115 add #4,r0
116 cmp/ge r0,r1
117 bt start_l
119 #if ! __SH2A_NOFPU__
120 #if defined (__SH2E__) || defined (__SH2A__) || defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__)
121 mov.l set_fpscr_k, r1
122 jsr @r1
123 mov #0,r4
124 lds r3,fpscr
125 #endif /* defined (__SH2E__) || defined (__SH2A__) || defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) */
126 #endif /* ! __SH2A_NOFPU__ */
128 ! arrange for exit to call fini
129 mov.l atexit_k,r0
130 mov.l fini_k,r4
131 jsr @r0
134 ! call init
135 mov.l init_k,r0
136 jsr @r0
139 ! call the mainline
140 mov.l main_k,r0
141 jsr @r0
144 ! call exit
145 mov r0,r4
146 mov.l exit_k,r0
147 jsr @r0
150 .align 2
151 #if ! __SH2A_NOFPU__
152 #if defined (__SH2E__) || defined (__SH2A__) || defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__)
153 set_fpscr_k:
154 .long ___set_fpscr
155 #endif /* defined (__SH2E__) || defined (__SH2A__) || defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) */
156 #endif /* ! __SH2A_NOFPU__ */
158 stack_k:
159 .long _stack
160 edata_k:
161 .long _edata
162 end_k:
163 .long _end
164 main_k:
165 .long ___setup_argv_and_call_main
166 exit_k:
167 .long _exit
168 atexit_k:
169 .long _atexit
170 init_k:
171 .long _init
172 fini_k:
173 .long _fini
175 ! supplied for backward compatibility only, in case of linking
176 ! code whose main() was compiled with an older version of GCC.
177 .global ___main
178 ___main:
181 #endif