blob: 39c80e134fceab6026788fadd07df5195139cf88 [file] [log] [blame]
Stefan Kristiansson952db942011-11-26 19:04:51 +00001/*
2 * (C) Copyright 2011, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
3 * (C) Copyright 2011, Julius Baxter <julius@opencores.org>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 * MA 02111-1307 USA
19 */
20
21#include <config.h>
22#include <asm-offsets.h>
23#include <asm/spr-defs.h>
24
25#define EXCEPTION_STACK_SIZE (128+128)
26
27#define HANDLE_EXCEPTION \
28 l.addi r1, r1, -EXCEPTION_STACK_SIZE ;\
Julius Baxterb59dc4a2012-05-05 12:32:11 +000029 l.sw 0x00(r1), r2 ;\
Stefan Kristiansson952db942011-11-26 19:04:51 +000030 l.sw 0x1c(r1), r9 ;\
Julius Baxterb59dc4a2012-05-05 12:32:11 +000031 l.movhi r2,hi(_exception_handler) ;\
32 l.ori r2,r2,lo(_exception_handler) ;\
33 l.jalr r2 ;\
Stefan Kristiansson952db942011-11-26 19:04:51 +000034 l.nop ;\
35 l.lwz r9, 0x1c(r1) ;\
36 l.addi r1, r1, EXCEPTION_STACK_SIZE ;\
37 l.rfe ;\
38 l.nop
39
40 .section .vectors, "ax"
41 .global __reset
42
43 /* reset */
44 .org 0x100
45__reset:
46 /* there is no guarantee r0 is hardwired to zero, clear it here */
47 l.andi r0, r0, 0
48 /* reset stack and frame pointers */
49 l.andi r1, r0, 0
50 l.andi r2, r0, 0
51
52 /* set supervisor mode */
53 l.ori r3,r0,SPR_SR_SM
54 l.mtspr r0,r3,SPR_SR
55
56 /* Relocate u-boot */
57 l.movhi r3,hi(__start) /* source start address */
58 l.ori r3,r3,lo(__start)
59 l.movhi r4,hi(_stext) /* dest start address */
60 l.ori r4,r4,lo(_stext)
61 l.movhi r5,hi(__end) /* dest end address */
62 l.ori r5,r5,lo(__end)
63
64.L_reloc:
65 l.lwz r6,0(r3)
66 l.sw 0(r4),r6
67 l.addi r3,r3,4
68 l.sfltu r4,r5
69 l.bf .L_reloc
70 l.addi r4,r4,4 /* delay slot */
71
72#ifdef CONFIG_SYS_RELOCATE_VECTORS
73 /* Relocate vectors from 0xf0000000 to 0x00000000 */
74 l.movhi r4, 0xf000 /* source */
75 l.movhi r5, 0 /* destination */
76 l.addi r6, r5, CONFIG_SYS_VECTORS_LEN /* length */
77.L_relocvectors:
78 l.lwz r7, 0(r4)
79 l.sw 0(r5), r7
80 l.addi r5, r5, 4
81 l.sfeq r5,r6
82 l.bnf .L_relocvectors
83 l.addi r4,r4, 4
84#endif
Julius Baxterb59dc4a2012-05-05 12:32:11 +000085 l.movhi r4,hi(_start)
86 l.ori r4,r4,lo(_start)
87 l.jr r4
Stefan Kristiansson952db942011-11-26 19:04:51 +000088 l.nop
89
90 /* bus error */
91 .org 0x200
92 HANDLE_EXCEPTION
93
94 /* data page fault */
95 .org 0x300
96 HANDLE_EXCEPTION
97
98 /* instruction page fault */
99 .org 0x400
100 HANDLE_EXCEPTION
101
102 /* tick timer */
103 .org 0x500
104 HANDLE_EXCEPTION
105
106 /* alignment */
107 .org 0x600
108 HANDLE_EXCEPTION
109
110 /* illegal instruction */
111 .org 0x700
112 HANDLE_EXCEPTION
113
114 /* external interrupt */
115 .org 0x800
116 HANDLE_EXCEPTION
117
118 /* D-TLB miss */
119 .org 0x900
120 HANDLE_EXCEPTION
121
122 /* I-TLB miss */
123 .org 0xa00
124 HANDLE_EXCEPTION
125
126 /* range */
127 .org 0xb00
128 HANDLE_EXCEPTION
129
130 /* system call */
131 .org 0xc00
132 HANDLE_EXCEPTION
133
134 /* floating point */
135 .org 0xd00
136 HANDLE_EXCEPTION
137
138 /* trap */
139 .org 0xe00
140 HANDLE_EXCEPTION
141
142 /* reserved */
143 .org 0xf00
144 HANDLE_EXCEPTION
145
146 /* reserved */
147 .org 0x1100
148 HANDLE_EXCEPTION
149
150 /* reserved */
151 .org 0x1200
152 HANDLE_EXCEPTION
153
154 /* reserved */
155 .org 0x1300
156 HANDLE_EXCEPTION
157
158 /* reserved */
159 .org 0x1400
160 HANDLE_EXCEPTION
161
162 /* reserved */
163 .org 0x1500
164 HANDLE_EXCEPTION
165
166 /* reserved */
167 .org 0x1600
168 HANDLE_EXCEPTION
169
170 /* reserved */
171 .org 0x1700
172 HANDLE_EXCEPTION
173
174 /* reserved */
175 .org 0x1800
176 HANDLE_EXCEPTION
177
178 /* reserved */
179 .org 0x1900
180 HANDLE_EXCEPTION
181
182 /* reserved */
183 .org 0x1a00
184 HANDLE_EXCEPTION
185
186 /* reserved */
187 .org 0x1b00
188 HANDLE_EXCEPTION
189
190 /* reserved */
191 .org 0x1c00
192 HANDLE_EXCEPTION
193
194 /* reserved */
195 .org 0x1d00
196 HANDLE_EXCEPTION
197
198 /* reserved */
199 .org 0x1e00
200 HANDLE_EXCEPTION
201
202 /* reserved */
203 .org 0x1f00
204 HANDLE_EXCEPTION
205
206 /* Startup routine */
207 .text
208 .global _start
209_start:
210 /* Init stack and frame pointers */
211 l.movhi r1, hi(CONFIG_SYS_INIT_SP_ADDR)
212 l.ori r1, r1, lo(CONFIG_SYS_INIT_SP_ADDR)
213 l.or r2, r0, r1
214
215 /* clear BSS segments */
216 l.movhi r4, hi(_bss_start)
217 l.ori r4, r4, lo(_bss_start)
218 l.movhi r5, hi(_bss_end)
219 l.ori r5, r5, lo(_bss_end)
220.L_clear_bss:
221 l.sw 0(r4), r0
222 l.sfltu r4,r5
223 l.bf .L_clear_bss
224 l.addi r4,r4,4
225
226 /* Reset registers before jumping to board_init */
227 l.andi r3, r0, 0
228 l.andi r4, r0, 0
229 l.andi r5, r0, 0
230 l.andi r6, r0, 0
231 l.andi r7, r0, 0
232 l.andi r8, r0, 0
233 l.andi r9, r0, 0
234 l.andi r10, r0, 0
235 l.andi r11, r0, 0
236 l.andi r12, r0, 0
237 l.andi r13, r0, 0
238 l.andi r14, r0, 0
239 l.andi r15, r0, 0
240 l.andi r17, r0, 0
241 l.andi r18, r0, 0
242 l.andi r19, r0, 0
243 l.andi r20, r0, 0
244 l.andi r21, r0, 0
245 l.andi r22, r0, 0
246 l.andi r23, r0, 0
247 l.andi r24, r0, 0
248 l.andi r25, r0, 0
249 l.andi r26, r0, 0
250 l.andi r27, r0, 0
251 l.andi r28, r0, 0
252 l.andi r29, r0, 0
253 l.andi r30, r0, 0
254 l.andi r31, r0, 0
255
256 l.j board_init
257 l.nop
258
259 .size _start, .-_start
260
261/*
262 * Store state onto stack and call the real exception handler
263 */
264 .section .text
265 .extern exception_handler
266 .type _exception_handler,@function
267
268_exception_handler:
Julius Baxterb59dc4a2012-05-05 12:32:11 +0000269 /* Store state (r2 and r9 already saved)*/
Stefan Kristiansson952db942011-11-26 19:04:51 +0000270 l.sw 0x04(r1), r3
271 l.sw 0x08(r1), r4
272 l.sw 0x0c(r1), r5
273 l.sw 0x10(r1), r6
274 l.sw 0x14(r1), r7
275 l.sw 0x18(r1), r8
276 l.sw 0x20(r1), r10
277 l.sw 0x24(r1), r11
278 l.sw 0x28(r1), r12
279 l.sw 0x2c(r1), r13
280 l.sw 0x30(r1), r14
281 l.sw 0x34(r1), r15
282 l.sw 0x38(r1), r16
283 l.sw 0x3c(r1), r17
284 l.sw 0x40(r1), r18
285 l.sw 0x44(r1), r19
286 l.sw 0x48(r1), r20
287 l.sw 0x4c(r1), r21
288 l.sw 0x50(r1), r22
289 l.sw 0x54(r1), r23
290 l.sw 0x58(r1), r24
291 l.sw 0x5c(r1), r25
292 l.sw 0x60(r1), r26
293 l.sw 0x64(r1), r27
294 l.sw 0x68(r1), r28
295 l.sw 0x6c(r1), r29
296 l.sw 0x70(r1), r30
297 l.sw 0x74(r1), r31
298
299 /* Save return address */
300 l.or r14, r0, r9
301 /* Call exception handler with the link address as argument */
302 l.jal exception_handler
303 l.or r3, r0, r14
304 /* Load return address */
305 l.or r9, r0, r14
306
307 /* Restore state */
308 l.lwz r2, 0x00(r1)
309 l.lwz r3, 0x04(r1)
310 l.lwz r4, 0x08(r1)
311 l.lwz r5, 0x0c(r1)
312 l.lwz r6, 0x10(r1)
313 l.lwz r7, 0x14(r1)
314 l.lwz r8, 0x18(r1)
315 l.lwz r10, 0x20(r1)
316 l.lwz r11, 0x24(r1)
317 l.lwz r12, 0x28(r1)
318 l.lwz r13, 0x2c(r1)
319 l.lwz r14, 0x30(r1)
320 l.lwz r15, 0x34(r1)
321 l.lwz r16, 0x38(r1)
322 l.lwz r17, 0x3c(r1)
323 l.lwz r18, 0x40(r1)
324 l.lwz r19, 0x44(r1)
325 l.lwz r20, 0x48(r1)
326 l.lwz r21, 0x4c(r1)
327 l.lwz r22, 0x50(r1)
328 l.lwz r23, 0x54(r1)
329 l.lwz r24, 0x58(r1)
330 l.lwz r25, 0x5c(r1)
331 l.lwz r26, 0x60(r1)
332 l.lwz r27, 0x64(r1)
333 l.lwz r28, 0x68(r1)
334 l.lwz r29, 0x6c(r1)
335 l.lwz r30, 0x70(r1)
336 l.lwz r31, 0x74(r1)
337 l.jr r9
338 l.nop