gcc/ChangeLog:
[official-gcc.git] / gcc / config / sh / crt1.asm
blobaf7d8ae3b95c31734942a030787b7f5571857707
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__
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 defined (__SH2E__) || 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 (__SH2E__) || defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) */
126 ! arrange for exit to call fini
127 mov.l atexit_k,r0
128 mov.l fini_k,r4
129 jsr @r0
132 ! call init
133 mov.l init_k,r0
134 jsr @r0
137 ! call the mainline
138 mov.l main_k,r0
139 jsr @r0
142 ! call exit
143 mov r0,r4
144 mov.l exit_k,r0
145 jsr @r0
148 .align 2
149 #if defined (__SH2E__) || defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__)
150 set_fpscr_k:
151 .long ___set_fpscr
152 #endif /* defined (__SH2E__) || defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) */
154 stack_k:
155 .long _stack
156 edata_k:
157 .long _edata
158 end_k:
159 .long _end
160 main_k:
161 .long ___setup_argv_and_call_main
162 exit_k:
163 .long _exit
164 atexit_k:
165 .long _atexit
166 init_k:
167 .long _init
168 fini_k:
169 .long _fini
171 ! supplied for backward compatibility only, in case of linking
172 ! code whose main() was compiled with an older version of GCC.
173 .global ___main
174 ___main:
177 #endif