diff options
Diffstat (limited to 'firmware/target/sh')
-rw-r--r-- | firmware/target/sh/crt0.S | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/firmware/target/sh/crt0.S b/firmware/target/sh/crt0.S new file mode 100644 index 0000000000..87cef56e96 --- /dev/null +++ b/firmware/target/sh/crt0.S | |||
@@ -0,0 +1,214 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include "cpu.h" | ||
21 | |||
22 | .section .init.text,"ax",@progbits | ||
23 | |||
24 | .global start | ||
25 | start: | ||
26 | |||
27 | mov.l .vbr_k,r1 | ||
28 | #ifdef DEBUG | ||
29 | /* If we have built our code to be loaded via the standalone GDB | ||
30 | * stub, we will have out VBR at some other location than 0x9000000. | ||
31 | * We must copy the trap vectors for the GDB stub to our vector table. */ | ||
32 | mov.l .orig_vbr_k,r2 | ||
33 | |||
34 | /* Move the invalid instruction vector (4) */ | ||
35 | mov #4,r0 | ||
36 | shll2 r0 | ||
37 | mov.l @(r0,r2),r3 | ||
38 | mov.l r3,@(r0,r1) | ||
39 | |||
40 | /* Move the invalid slot vector (6) */ | ||
41 | mov #6,r0 | ||
42 | shll2 r0 | ||
43 | mov.l @(r0,r2),r3 | ||
44 | mov.l r3,@(r0,r1) | ||
45 | |||
46 | /* Move the bus error vector (9) */ | ||
47 | mov #9,r0 | ||
48 | shll2 r0 | ||
49 | mov.l @(r0,r2),r3 | ||
50 | mov.l r3,@(r0,r1) | ||
51 | |||
52 | /* Move the DMA bus error vector (10) */ | ||
53 | mov #10,r0 | ||
54 | shll2 r0 | ||
55 | mov.l @(r0,r2),r3 | ||
56 | mov.l r3,@(r0,r1) | ||
57 | |||
58 | /* Move the NMI vector as well (11) */ | ||
59 | mov #11,r0 | ||
60 | shll2 r0 | ||
61 | mov.l @(r0,r2),r3 | ||
62 | mov.l r3,@(r0,r1) | ||
63 | |||
64 | /* Move the UserBreak vector as well (12) */ | ||
65 | mov #12,r0 | ||
66 | shll2 r0 | ||
67 | mov.l @(r0,r2),r3 | ||
68 | mov.l r3,@(r0,r1) | ||
69 | |||
70 | /* Move the breakpoint trap vector (32) */ | ||
71 | mov #32,r0 | ||
72 | shll2 r0 | ||
73 | mov.l @(r0,r2),r3 | ||
74 | mov.l r3,@(r0,r1) | ||
75 | |||
76 | /* Move the IO trap vector (33) */ | ||
77 | mov #33,r0 | ||
78 | shll2 r0 | ||
79 | mov.l @(r0,r2),r3 | ||
80 | mov.l r3,@(r0,r1) | ||
81 | |||
82 | /* Move the serial Rx interrupt vector (105) */ | ||
83 | mov #105,r0 | ||
84 | shll2 r0 | ||
85 | mov.l @(r0,r2),r3 | ||
86 | mov.l r3,@(r0,r1) | ||
87 | |||
88 | /* Move the single step trap vector (127) */ | ||
89 | mov #127,r0 | ||
90 | shll2 r0 | ||
91 | mov.l @(r0,r2),r3 | ||
92 | mov.l r3,@(r0,r1) | ||
93 | #endif /* DEBUG */ | ||
94 | ldc r1,vbr | ||
95 | |||
96 | mov #0,r0 | ||
97 | ldc r0,gbr | ||
98 | |||
99 | /* zero out .ibss */ | ||
100 | mov.l .iedata_k,r0 | ||
101 | mov.l .iend_k,r1 | ||
102 | bra .iedatastart | ||
103 | mov #0,r2 | ||
104 | .iedataloop: /* backwards is faster and shorter */ | ||
105 | mov.l r2,@-r1 | ||
106 | .iedatastart: | ||
107 | cmp/hi r0,r1 | ||
108 | bt .iedataloop | ||
109 | |||
110 | /* copy the .iram section */ | ||
111 | mov.l .iramcopy_k,r0 | ||
112 | mov.l .iram_k,r1 | ||
113 | mov.l .iramend_k,r2 | ||
114 | /* Note: We cannot put a PC relative load into the delay slot of a 'bra' | ||
115 | instruction (the offset would be wrong), but there is nothing else to | ||
116 | do before the loop, so the delay slot would be 'nop'. The cmp / bf | ||
117 | sequence is the same length, but more efficient. */ | ||
118 | cmp/hi r1,r2 | ||
119 | bf .noiramcopy | ||
120 | .iramloop: | ||
121 | mov.l @r0+,r3 | ||
122 | mov.l r3,@r1 | ||
123 | add #4,r1 | ||
124 | cmp/hi r1,r2 | ||
125 | bt .iramloop | ||
126 | .noiramcopy: | ||
127 | |||
128 | /* zero out bss */ | ||
129 | mov.l .edata_k,r0 | ||
130 | mov.l .end_k,r1 | ||
131 | bra .edatastart | ||
132 | mov #0,r2 | ||
133 | .edataloop: /* backwards is faster and shorter */ | ||
134 | mov.l r2,@-r1 | ||
135 | .edatastart: | ||
136 | cmp/hi r0,r1 | ||
137 | bt .edataloop | ||
138 | |||
139 | /* copy the .data section, for rombased execution */ | ||
140 | mov.l .datacopy_k,r0 | ||
141 | mov.l .data_k,r1 | ||
142 | cmp/eq r0,r1 | ||
143 | bt .nodatacopy /* Don't copy if src and dest are equal */ | ||
144 | mov.l .dataend_k,r2 | ||
145 | cmp/hi r1,r2 | ||
146 | bf .nodatacopy | ||
147 | .dataloop: | ||
148 | mov.l @r0+,r3 | ||
149 | mov.l r3,@r1 | ||
150 | add #4,r1 | ||
151 | cmp/hi r1,r2 | ||
152 | bt .dataloop | ||
153 | .nodatacopy: | ||
154 | |||
155 | /* Munge the main thread stack */ | ||
156 | mov.l .stackbegin_k,r0 | ||
157 | mov.l .stackend_k,r1 | ||
158 | mov r1,r15 | ||
159 | mov.l .deadbeef_k,r2 | ||
160 | .mungeloop: /* backwards is faster and shorter */ | ||
161 | mov.l r2,@-r1 | ||
162 | cmp/hi r0,r1 | ||
163 | bt .mungeloop | ||
164 | |||
165 | /* call the mainline */ | ||
166 | mov.l .main_k,r0 | ||
167 | jsr @r0 | ||
168 | nop | ||
169 | .hoo: | ||
170 | bra .hoo | ||
171 | nop | ||
172 | |||
173 | .align 2 | ||
174 | .vbr_k: | ||
175 | .long vectors | ||
176 | #ifdef DEBUG | ||
177 | .orig_vbr_k: | ||
178 | .long 0x09000000 | ||
179 | #endif | ||
180 | .iedata_k: | ||
181 | .long _iedata | ||
182 | .iend_k: | ||
183 | .long _iend | ||
184 | .iramcopy_k: | ||
185 | .long _iramcopy | ||
186 | .iram_k: | ||
187 | .long _iramstart | ||
188 | .iramend_k: | ||
189 | .long _iramend | ||
190 | .edata_k: | ||
191 | .long _edata | ||
192 | .end_k: | ||
193 | .long _end | ||
194 | .datacopy_k: | ||
195 | .long _datacopy | ||
196 | .data_k: | ||
197 | .long _datastart | ||
198 | .dataend_k: | ||
199 | .long _dataend | ||
200 | .stackbegin_k: | ||
201 | .long _stackbegin | ||
202 | .stackend_k: | ||
203 | .long _stackend | ||
204 | .deadbeef_k: | ||
205 | .long 0xdeadbeef | ||
206 | .main_k: | ||
207 | .long _main | ||
208 | |||
209 | .section .resetvectors | ||
210 | vectors: | ||
211 | .long start | ||
212 | .long _stackend | ||
213 | .long start | ||
214 | .long _stackend | ||