blob: fe3daa2b9f79a8e0c62347aec7b59edba7f641ca [file] [log] [blame]
wdenk5b1d7132002-11-03 00:07:02 +00001/*
2 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
4 * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25/* U-Boot - Startup Code for PowerPC based Embedded Boards
26 *
27 *
28 * The processor starts at 0x00000100 and the code is executed
29 * from flash. The code is organized to be at an other address
wdenk7e780362004-04-08 22:31:29 +000030 * in memory, but as long we don't jump around before relocating,
wdenk5b1d7132002-11-03 00:07:02 +000031 * board_init lies at a quite high address and when the cpu has
32 * jumped there, everything is ok.
33 * This works because the cpu gives the FLASH (CS0) the whole
34 * address space at startup, and board_init lies as a echo of
wdenk7e780362004-04-08 22:31:29 +000035 * the flash somewhere up there in the memory map.
wdenk5b1d7132002-11-03 00:07:02 +000036 *
37 * board_init will change CS0 to be positioned at the correct
38 * address and (s)dram will be positioned at address 0
39 */
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020040#include <asm-offsets.h>
wdenk5b1d7132002-11-03 00:07:02 +000041#include <config.h>
42#include <mpc8xx.h>
Peter Tyser561858e2008-11-03 09:30:59 -060043#include <timestamp.h>
wdenk5b1d7132002-11-03 00:07:02 +000044#include <version.h>
45
46#define CONFIG_8xx 1 /* needed for Linux kernel header files */
47#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
48
49#include <ppc_asm.tmpl>
50#include <ppc_defs.h>
51
52#include <asm/cache.h>
53#include <asm/mmu.h>
Peter Tyserd98b0522010-10-14 23:33:24 -050054#include <asm/u-boot.h>
wdenk5b1d7132002-11-03 00:07:02 +000055
56#ifndef CONFIG_IDENT_STRING
57#define CONFIG_IDENT_STRING ""
58#endif
59
60/* We don't want the MMU yet.
61*/
62#undef MSR_KERNEL
63#define MSR_KERNEL ( MSR_ME | MSR_RI ) /* Machine Check and Recoverable Interr. */
64
65/*
66 * Set up GOT: Global Offset Table
67 *
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +010068 * Use r12 to access the GOT
wdenk5b1d7132002-11-03 00:07:02 +000069 */
70 START_GOT
71 GOT_ENTRY(_GOT2_TABLE_)
72 GOT_ENTRY(_FIXUP_TABLE_)
73
74 GOT_ENTRY(_start)
75 GOT_ENTRY(_start_of_vectors)
76 GOT_ENTRY(_end_of_vectors)
77 GOT_ENTRY(transfer_to_handler)
78
wdenk3b57fe02003-05-30 12:48:29 +000079 GOT_ENTRY(__init_end)
Po-Yu Chuang44c6e652011-03-01 22:59:59 +000080 GOT_ENTRY(__bss_end__)
wdenk5d232d02003-05-22 22:52:13 +000081 GOT_ENTRY(__bss_start)
wdenk5b1d7132002-11-03 00:07:02 +000082 END_GOT
83
84/*
85 * r3 - 1st arg to board_init(): IMMP pointer
86 * r4 - 2nd arg to board_init(): boot flag
87 */
88 .text
89 .long 0x27051956 /* U-Boot Magic Number */
90 .globl version_string
91version_string:
92 .ascii U_BOOT_VERSION
Peter Tyser561858e2008-11-03 09:30:59 -060093 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
wdenk5b1d7132002-11-03 00:07:02 +000094 .ascii CONFIG_IDENT_STRING, "\0"
95
96 . = EXC_OFF_SYS_RESET
97 .globl _start
98_start:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020099 lis r3, CONFIG_SYS_IMMR@h /* position IMMR */
wdenk5b1d7132002-11-03 00:07:02 +0000100 mtspr 638, r3
wdenk5b1d7132002-11-03 00:07:02 +0000101
102 /* Initialize machine status; enable machine check interrupt */
103 /*----------------------------------------------------------------------*/
104 li r3, MSR_KERNEL /* Set ME, RI flags */
105 mtmsr r3
106 mtspr SRR1, r3 /* Make SRR1 match MSR */
107
108 mfspr r3, ICR /* clear Interrupt Cause Register */
109
110 /* Initialize debug port registers */
111 /*----------------------------------------------------------------------*/
112 xor r0, r0, r0 /* Clear R0 */
113 mtspr LCTRL1, r0 /* Initialize debug port regs */
114 mtspr LCTRL2, r0
115 mtspr COUNTA, r0
116 mtspr COUNTB, r0
117
118 /* Reset the caches */
119 /*----------------------------------------------------------------------*/
120
121 mfspr r3, IC_CST /* Clear error bits */
122 mfspr r3, DC_CST
123
124 lis r3, IDC_UNALL@h /* Unlock all */
125 mtspr IC_CST, r3
126 mtspr DC_CST, r3
127
128 lis r3, IDC_INVALL@h /* Invalidate all */
129 mtspr IC_CST, r3
130 mtspr DC_CST, r3
131
132 lis r3, IDC_DISABLE@h /* Disable data cache */
133 mtspr DC_CST, r3
134
Heiko Schocher506f3912009-03-12 07:37:15 +0100135#if !defined(CONFIG_SYS_DELAYED_ICACHE)
wdenk5b1d7132002-11-03 00:07:02 +0000136 /* On IP860 and PCU E,
137 * we cannot enable IC yet
138 */
139 lis r3, IDC_ENABLE@h /* Enable instruction cache */
140#endif
141 mtspr IC_CST, r3
142
143 /* invalidate all tlb's */
144 /*----------------------------------------------------------------------*/
145
146 tlbia
147 isync
148
149 /*
150 * Calculate absolute address in FLASH and jump there
151 *----------------------------------------------------------------------*/
152
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200153 lis r3, CONFIG_SYS_MONITOR_BASE@h
154 ori r3, r3, CONFIG_SYS_MONITOR_BASE@l
wdenk5b1d7132002-11-03 00:07:02 +0000155 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
156 mtlr r3
157 blr
158
159in_flash:
160
161 /* initialize some SPRs that are hard to access from C */
162 /*----------------------------------------------------------------------*/
163
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200164 lis r3, CONFIG_SYS_IMMR@h /* pass IMMR as arg1 to C routine */
165 ori r1, r3, CONFIG_SYS_INIT_SP_OFFSET /* set up the stack in internal DPRAM */
wdenk5b1d7132002-11-03 00:07:02 +0000166 /* Note: R0 is still 0 here */
167 stwu r0, -4(r1) /* clear final stack frame so that */
168 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
169
170 /*
171 * Disable serialized ifetch and show cycles
172 * (i.e. set processor to normal mode).
173 * This is also a silicon bug workaround, see errata
174 */
175
176 li r2, 0x0007
177 mtspr ICTRL, r2
178
179 /* Set up debug mode entry */
180
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200181 lis r2, CONFIG_SYS_DER@h
182 ori r2, r2, CONFIG_SYS_DER@l
wdenk5b1d7132002-11-03 00:07:02 +0000183 mtspr DER, r2
184
185 /* let the C-code set up the rest */
186 /* */
187 /* Be careful to keep code relocatable ! */
188 /*----------------------------------------------------------------------*/
189
190 GET_GOT /* initialize GOT access */
191
192 /* r3: IMMR */
193 bl cpu_init_f /* run low-level CPU init code (from Flash) */
194
wdenk5b1d7132002-11-03 00:07:02 +0000195 bl board_init_f /* run 1st part of board init code (from Flash) */
196
Peter Tyser52ebd9c2010-09-14 19:13:53 -0500197 /* NOTREACHED - board_init_f() does not return */
198
wdenk5b1d7132002-11-03 00:07:02 +0000199
wdenk5b1d7132002-11-03 00:07:02 +0000200 .globl _start_of_vectors
201_start_of_vectors:
202
203/* Machine check */
204 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
205
206/* Data Storage exception. "Never" generated on the 860. */
207 STD_EXCEPTION(0x300, DataStorage, UnknownException)
208
209/* Instruction Storage exception. "Never" generated on the 860. */
210 STD_EXCEPTION(0x400, InstStorage, UnknownException)
211
212/* External Interrupt exception. */
213 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
214
215/* Alignment exception. */
216 . = 0x600
217Alignment:
Rafal Jaworowski02032e82007-06-22 14:58:04 +0200218 EXCEPTION_PROLOG(SRR0, SRR1)
wdenk5b1d7132002-11-03 00:07:02 +0000219 mfspr r4,DAR
220 stw r4,_DAR(r21)
221 mfspr r5,DSISR
222 stw r5,_DSISR(r21)
223 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlundfc4e1882010-01-19 14:41:55 +0100224 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
wdenk5b1d7132002-11-03 00:07:02 +0000225
226/* Program check exception */
227 . = 0x700
228ProgramCheck:
Rafal Jaworowski02032e82007-06-22 14:58:04 +0200229 EXCEPTION_PROLOG(SRR0, SRR1)
wdenk5b1d7132002-11-03 00:07:02 +0000230 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlundfc4e1882010-01-19 14:41:55 +0100231 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
232 MSR_KERNEL, COPY_EE)
wdenk5b1d7132002-11-03 00:07:02 +0000233
234 /* No FPU on MPC8xx. This exception is not supposed to happen.
235 */
236 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
237
238 /* I guess we could implement decrementer, and may have
239 * to someday for timekeeping.
240 */
241 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
242 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
243 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
wdenk27b207f2003-07-24 23:38:38 +0000244 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
wdenk5b1d7132002-11-03 00:07:02 +0000245 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
246
247 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
248 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
249
250 /* On the MPC8xx, this is a software emulation interrupt. It occurs
251 * for all unimplemented and illegal instructions.
252 */
253 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
254
255 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
256 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
257 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
258 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
259
260 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
261 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
262 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
263 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
264 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
265 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
266 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
267
268 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
269 STD_EXCEPTION(0x1d00, InstructionBreakpoint, DebugException)
270 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
271 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
272
273
274 .globl _end_of_vectors
275_end_of_vectors:
276
277
278 . = 0x2000
279
280/*
281 * This code finishes saving the registers to the exception frame
282 * and jumps to the appropriate handler for the exception.
283 * Register r21 is pointer into trap frame, r1 has new stack pointer.
284 */
285 .globl transfer_to_handler
286transfer_to_handler:
287 stw r22,_NIP(r21)
288 lis r22,MSR_POW@h
289 andc r23,r23,r22
290 stw r23,_MSR(r21)
291 SAVE_GPR(7, r21)
292 SAVE_4GPRS(8, r21)
293 SAVE_8GPRS(12, r21)
294 SAVE_8GPRS(24, r21)
295 mflr r23
296 andi. r24,r23,0x3f00 /* get vector offset */
297 stw r24,TRAP(r21)
298 li r22,0
299 stw r22,RESULT(r21)
300 mtspr SPRG2,r22 /* r1 is now kernel sp */
301 lwz r24,0(r23) /* virtual address of handler */
302 lwz r23,4(r23) /* where to go when done */
303 mtspr SRR0,r24
304 mtspr SRR1,r20
305 mtlr r23
306 SYNC
307 rfi /* jump to handler, enable MMU */
308
309int_return:
310 mfmsr r28 /* Disable interrupts */
311 li r4,0
312 ori r4,r4,MSR_EE
313 andc r28,r28,r4
314 SYNC /* Some chip revs need this... */
315 mtmsr r28
316 SYNC
317 lwz r2,_CTR(r1)
318 lwz r0,_LINK(r1)
319 mtctr r2
320 mtlr r0
321 lwz r2,_XER(r1)
322 lwz r0,_CCR(r1)
323 mtspr XER,r2
324 mtcrf 0xFF,r0
325 REST_10GPRS(3, r1)
326 REST_10GPRS(13, r1)
327 REST_8GPRS(23, r1)
328 REST_GPR(31, r1)
329 lwz r2,_NIP(r1) /* Restore environment */
330 lwz r0,_MSR(r1)
331 mtspr SRR0,r2
332 mtspr SRR1,r0
333 lwz r0,GPR0(r1)
334 lwz r2,GPR2(r1)
335 lwz r1,GPR1(r1)
336 SYNC
337 rfi
338
339/* Cache functions.
340*/
341 .globl icache_enable
342icache_enable:
343 SYNC
344 lis r3, IDC_INVALL@h
345 mtspr IC_CST, r3
346 lis r3, IDC_ENABLE@h
347 mtspr IC_CST, r3
348 blr
349
350 .globl icache_disable
351icache_disable:
352 SYNC
353 lis r3, IDC_DISABLE@h
354 mtspr IC_CST, r3
355 blr
356
357 .globl icache_status
358icache_status:
359 mfspr r3, IC_CST
360 srwi r3, r3, 31 /* >>31 => select bit 0 */
361 blr
362
363 .globl dcache_enable
364dcache_enable:
365#if 0
366 SYNC
367#endif
368#if 1
369 lis r3, 0x0400 /* Set cache mode with MMU off */
370 mtspr MD_CTR, r3
371#endif
372
373 lis r3, IDC_INVALL@h
374 mtspr DC_CST, r3
375#if 0
376 lis r3, DC_SFWT@h
377 mtspr DC_CST, r3
378#endif
379 lis r3, IDC_ENABLE@h
380 mtspr DC_CST, r3
381 blr
382
383 .globl dcache_disable
384dcache_disable:
385 SYNC
386 lis r3, IDC_DISABLE@h
387 mtspr DC_CST, r3
388 lis r3, IDC_INVALL@h
389 mtspr DC_CST, r3
390 blr
391
392 .globl dcache_status
393dcache_status:
394 mfspr r3, DC_CST
395 srwi r3, r3, 31 /* >>31 => select bit 0 */
396 blr
397
398 .globl dc_read
399dc_read:
400 mtspr DC_ADR, r3
401 mfspr r3, DC_DAT
402 blr
403
404/*
405 * unsigned int get_immr (unsigned int mask)
406 *
407 * return (mask ? (IMMR & mask) : IMMR);
408 */
409 .globl get_immr
410get_immr:
411 mr r4,r3 /* save mask */
412 mfspr r3, IMMR /* IMMR */
413 cmpwi 0,r4,0 /* mask != 0 ? */
414 beq 4f
415 and r3,r3,r4 /* IMMR & mask */
4164:
417 blr
418
419 .globl get_pvr
420get_pvr:
421 mfspr r3, PVR
422 blr
423
424
425 .globl wr_ic_cst
426wr_ic_cst:
427 mtspr IC_CST, r3
428 blr
429
430 .globl rd_ic_cst
431rd_ic_cst:
432 mfspr r3, IC_CST
433 blr
434
435 .globl wr_ic_adr
436wr_ic_adr:
437 mtspr IC_ADR, r3
438 blr
439
440
441 .globl wr_dc_cst
442wr_dc_cst:
443 mtspr DC_CST, r3
444 blr
445
446 .globl rd_dc_cst
447rd_dc_cst:
448 mfspr r3, DC_CST
449 blr
450
451 .globl wr_dc_adr
452wr_dc_adr:
453 mtspr DC_ADR, r3
454 blr
455
456/*------------------------------------------------------------------------------*/
457
458/*
459 * void relocate_code (addr_sp, gd, addr_moni)
460 *
461 * This "function" does not return, instead it continues in RAM
462 * after relocating the monitor code.
463 *
464 * r3 = dest
465 * r4 = src
466 * r5 = length in bytes
467 * r6 = cachelinesize
468 */
469 .globl relocate_code
470relocate_code:
471 mr r1, r3 /* Set new stack pointer */
472 mr r9, r4 /* Save copy of Global Data pointer */
473 mr r10, r5 /* Save copy of Destination Address */
474
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100475 GET_GOT
wdenk5b1d7132002-11-03 00:07:02 +0000476 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200477 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
478 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
wdenk3b57fe02003-05-30 12:48:29 +0000479 lwz r5, GOT(__init_end)
480 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200481 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
wdenk5b1d7132002-11-03 00:07:02 +0000482
483 /*
484 * Fix GOT pointer:
485 *
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200486 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
wdenk5b1d7132002-11-03 00:07:02 +0000487 *
488 * Offset:
489 */
490 sub r15, r10, r4
491
492 /* First our own GOT */
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100493 add r12, r12, r15
wdenkd0fb80c2003-01-11 09:48:40 +0000494 /* then the one used by the C code */
wdenk5b1d7132002-11-03 00:07:02 +0000495 add r30, r30, r15
496
497 /*
498 * Now relocate code
499 */
500
501 cmplw cr1,r3,r4
502 addi r0,r5,3
503 srwi. r0,r0,2
504 beq cr1,4f /* In place copy is not necessary */
505 beq 7f /* Protect against 0 count */
506 mtctr r0
507 bge cr1,2f
508
509 la r8,-4(r4)
510 la r7,-4(r3)
5111: lwzu r0,4(r8)
512 stwu r0,4(r7)
513 bdnz 1b
514 b 4f
515
5162: slwi r0,r0,2
517 add r8,r4,r0
518 add r7,r3,r0
5193: lwzu r0,-4(r8)
520 stwu r0,-4(r7)
521 bdnz 3b
522
523/*
524 * Now flush the cache: note that we must start from a cache aligned
525 * address. Otherwise we might miss one cache line.
526 */
5274: cmpwi r6,0
528 add r5,r3,r5
529 beq 7f /* Always flush prefetch queue in any case */
530 subi r0,r6,1
531 andc r3,r3,r0
532 mr r4,r3
5335: dcbst 0,r4
534 add r4,r4,r6
535 cmplw r4,r5
536 blt 5b
537 sync /* Wait for all dcbst to complete on bus */
538 mr r4,r3
5396: icbi 0,r4
540 add r4,r4,r6
541 cmplw r4,r5
542 blt 6b
5437: sync /* Wait for all icbi to complete on bus */
544 isync
545
546/*
547 * We are done. Do not return, instead branch to second part of board
548 * initialization, now running from RAM.
549 */
550
551 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
552 mtlr r0
553 blr
554
555in_ram:
556
557 /*
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100558 * Relocation Function, r12 point to got2+0x8000
wdenk5b1d7132002-11-03 00:07:02 +0000559 *
wdenk8bde7f72003-06-27 21:31:46 +0000560 * Adjust got2 pointers, no need to check for 0, this code
561 * already puts a few entries in the table.
wdenk5b1d7132002-11-03 00:07:02 +0000562 */
563 li r0,__got2_entries@sectoff@l
564 la r3,GOT(_GOT2_TABLE_)
565 lwz r11,GOT(_GOT2_TABLE_)
566 mtctr r0
567 sub r11,r3,r11
568 addi r3,r3,-4
5691: lwzu r0,4(r3)
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +0200570 cmpwi r0,0
571 beq- 2f
wdenk5b1d7132002-11-03 00:07:02 +0000572 add r0,r0,r11
573 stw r0,0(r3)
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +02005742: bdnz 1b
wdenk5b1d7132002-11-03 00:07:02 +0000575
576 /*
wdenk8bde7f72003-06-27 21:31:46 +0000577 * Now adjust the fixups and the pointers to the fixups
wdenk5b1d7132002-11-03 00:07:02 +0000578 * in case we need to move ourselves again.
579 */
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +0200580 li r0,__fixup_entries@sectoff@l
wdenk5b1d7132002-11-03 00:07:02 +0000581 lwz r3,GOT(_FIXUP_TABLE_)
582 cmpwi r0,0
583 mtctr r0
584 addi r3,r3,-4
585 beq 4f
5863: lwzu r4,4(r3)
587 lwzux r0,r4,r11
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +0200588 cmpwi r0,0
wdenk5b1d7132002-11-03 00:07:02 +0000589 add r0,r0,r11
Joakim Tjernlund34bbf612010-11-04 19:02:00 +0100590 stw r4,0(r3)
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +0200591 beq- 5f
wdenk5b1d7132002-11-03 00:07:02 +0000592 stw r0,0(r4)
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +02005935: bdnz 3b
wdenk5b1d7132002-11-03 00:07:02 +00005944:
595clear_bss:
596 /*
597 * Now clear BSS segment
598 */
wdenk5d232d02003-05-22 22:52:13 +0000599 lwz r3,GOT(__bss_start)
Po-Yu Chuang44c6e652011-03-01 22:59:59 +0000600 lwz r4,GOT(__bss_end__)
wdenk5b1d7132002-11-03 00:07:02 +0000601
602 cmplw 0, r3, r4
603 beq 6f
604
605 li r0, 0
6065:
607 stw r0, 0(r3)
608 addi r3, r3, 4
609 cmplw 0, r3, r4
610 bne 5b
6116:
612
613 mr r3, r9 /* Global Data pointer */
614 mr r4, r10 /* Destination Address */
615 bl board_init_r
616
wdenk5b1d7132002-11-03 00:07:02 +0000617 /*
618 * Copy exception vector code to low memory
619 *
620 * r3: dest_addr
621 * r7: source address, r8: end address, r9: target address
622 */
623 .globl trap_init
624trap_init:
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100625 mflr r4 /* save link register */
626 GET_GOT
wdenk5b1d7132002-11-03 00:07:02 +0000627 lwz r7, GOT(_start)
628 lwz r8, GOT(_end_of_vectors)
629
wdenk682011f2003-06-03 23:54:09 +0000630 li r9, 0x100 /* reset vector always at 0x100 */
wdenk5b1d7132002-11-03 00:07:02 +0000631
632 cmplw 0, r7, r8
633 bgelr /* return if r7>=r8 - just in case */
wdenk5b1d7132002-11-03 00:07:02 +00006341:
635 lwz r0, 0(r7)
636 stw r0, 0(r9)
637 addi r7, r7, 4
638 addi r9, r9, 4
639 cmplw 0, r7, r8
640 bne 1b
641
642 /*
643 * relocate `hdlr' and `int_return' entries
644 */
645 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
646 li r8, Alignment - _start + EXC_OFF_SYS_RESET
6472:
648 bl trap_reloc
649 addi r7, r7, 0x100 /* next exception vector */
650 cmplw 0, r7, r8
651 blt 2b
652
653 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
654 bl trap_reloc
655
656 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
657 bl trap_reloc
658
659 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
660 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
6613:
662 bl trap_reloc
663 addi r7, r7, 0x100 /* next exception vector */
664 cmplw 0, r7, r8
665 blt 3b
666
667 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
668 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
6694:
670 bl trap_reloc
671 addi r7, r7, 0x100 /* next exception vector */
672 cmplw 0, r7, r8
673 blt 4b
674
675 mtlr r4 /* restore link register */
676 blr