blob: d10231ee9485fc4da9932343f4aa5f7f0b77cd50 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +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
30 * in memory, but as long we don't jump around before relocating.
31 * 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
35 * the flash somewhere up there in the memorymap.
36 *
37 * board_init will change CS0 to be positioned at the correct
38 * address and (s)dram will be positioned at address 0
39 */
40#include <config.h>
41#include <mpc824x.h>
Peter Tyser561858e2008-11-03 09:30:59 -060042#include <timestamp.h>
wdenkc6097192002-11-03 00:24:07 +000043#include <version.h>
44
45#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
46
47#include <ppc_asm.tmpl>
48#include <ppc_defs.h>
49
50#include <asm/cache.h>
51#include <asm/mmu.h>
Peter Tyserd98b0522010-10-14 23:33:24 -050052#include <asm/u-boot.h>
wdenkc6097192002-11-03 00:24:07 +000053
54#ifndef CONFIG_IDENT_STRING
55#define CONFIG_IDENT_STRING ""
56#endif
57
58/* We don't want the MMU yet.
59*/
60#undef MSR_KERNEL
61/* FP, Machine Check and Recoverable Interr. */
62#define MSR_KERNEL ( MSR_FP | MSR_ME | MSR_RI )
63
64/*
65 * Set up GOT: Global Offset Table
66 *
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +010067 * Use r12 to access the GOT
wdenkc6097192002-11-03 00:24:07 +000068 */
69 START_GOT
70 GOT_ENTRY(_GOT2_TABLE_)
71 GOT_ENTRY(_FIXUP_TABLE_)
72
73 GOT_ENTRY(_start)
74 GOT_ENTRY(_start_of_vectors)
75 GOT_ENTRY(_end_of_vectors)
76 GOT_ENTRY(transfer_to_handler)
77
wdenk3b57fe02003-05-30 12:48:29 +000078 GOT_ENTRY(__init_end)
wdenkc6097192002-11-03 00:24:07 +000079 GOT_ENTRY(_end)
wdenk5d232d02003-05-22 22:52:13 +000080 GOT_ENTRY(__bss_start)
wdenkc6097192002-11-03 00:24:07 +000081#if defined(CONFIG_FADS)
82 GOT_ENTRY(environment)
83#endif
84 END_GOT
85
86/*
87 * r3 - 1st arg to board_init(): IMMP pointer
88 * r4 - 2nd arg to board_init(): boot flag
89 */
90 .text
91 .long 0x27051956 /* U-Boot Magic Number */
92 .globl version_string
93version_string:
94 .ascii U_BOOT_VERSION
Peter Tyser561858e2008-11-03 09:30:59 -060095 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
wdenkc6097192002-11-03 00:24:07 +000096 .ascii CONFIG_IDENT_STRING, "\0"
97
98 . = EXC_OFF_SYS_RESET
99 .globl _start
100_start:
wdenkc6097192002-11-03 00:24:07 +0000101 /* Initialize machine status; enable machine check interrupt */
102 /*----------------------------------------------------------------------*/
103 li r3, MSR_KERNEL /* Set FP, ME, RI flags */
104 mtmsr r3
105 mtspr SRR1, r3 /* Make SRR1 match MSR */
106
107 addis r0,0,0x0000 /* lets make sure that r0 is really 0 */
108 mtspr HID0, r0 /* disable I and D caches */
109
110 mfspr r3, ICR /* clear Interrupt Cause Register */
111
112 mfmsr r3 /* turn off address translation */
113 addis r4,0,0xffff
114 ori r4,r4,0xffcf
115 and r3,r3,r4
116 mtmsr r3
117 isync
118 sync /* the MMU should be off... */
119
120
121in_flash:
122#if defined(CONFIG_BMW)
123 bl early_init_f /* Must be ASM: no stack yet! */
124#endif
125 /*
126 * Setup BATs - cannot be done in C since we don't have a stack yet
127 */
128 bl setup_bats
129
130 /* Enable MMU.
131 */
132 mfmsr r3
133 ori r3, r3, (MSR_IR | MSR_DR)
134 mtmsr r3
135#if !defined(CONFIG_BMW)
136 /* Enable and invalidate data cache.
137 */
138 mfspr r3, HID0
139 mr r2, r3
140 ori r3, r3, HID0_DCE | HID0_DCI
141 ori r2, r2, HID0_DCE
142 sync
143 mtspr HID0, r3
144 mtspr HID0, r2
145 sync
146
147 /* Allocate Initial RAM in data cache.
148 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200149 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
150 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
wdenkc6097192002-11-03 00:24:07 +0000151 li r2, 128
152 mtctr r2
1531:
154 dcbz r0, r3
155 addi r3, r3, 32
156 bdnz 1b
157
158 /* Lock way0 in data cache.
159 */
160 mfspr r3, 1011
161 lis r2, 0xffff
162 ori r2, r2, 0xff1f
163 and r3, r3, r2
164 ori r3, r3, 0x0080
165 sync
166 mtspr 1011, r3
167#endif /* !CONFIG_BMW */
168 /*
169 * Thisk the stack pointer *somewhere* sensible. Doesnt
170 * matter much where as we'll move it when we relocate
171 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200172 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
173 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
wdenkc6097192002-11-03 00:24:07 +0000174
175 li r0, 0 /* Make room for stack frame header and */
176 stwu r0, -4(r1) /* clear final stack frame so that */
177 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
178
179 /* let the C-code set up the rest */
180 /* */
181 /* Be careful to keep code relocatable ! */
182 /*----------------------------------------------------------------------*/
183
184 GET_GOT /* initialize GOT access */
185
186 /* r3: IMMR */
187 bl cpu_init_f /* run low-level CPU init code (from Flash) */
188
wdenkc6097192002-11-03 00:24:07 +0000189 bl board_init_f /* run 1st part of board init code (from Flash) */
190
Peter Tyser52ebd9c2010-09-14 19:13:53 -0500191 /* NOTREACHED - board_init_f() does not return */
192
wdenkc6097192002-11-03 00:24:07 +0000193
wdenkc6097192002-11-03 00:24:07 +0000194 .globl _start_of_vectors
195_start_of_vectors:
196
197/* Machine check */
198 STD_EXCEPTION(EXC_OFF_MACH_CHCK, MachineCheck, MachineCheckException)
199
200/* Data Storage exception. "Never" generated on the 860. */
201 STD_EXCEPTION(EXC_OFF_DATA_STOR, DataStorage, UnknownException)
202
203/* Instruction Storage exception. "Never" generated on the 860. */
204 STD_EXCEPTION(EXC_OFF_INS_STOR, InstStorage, UnknownException)
205
206/* External Interrupt exception. */
207 STD_EXCEPTION(EXC_OFF_EXTERNAL, ExtInterrupt, external_interrupt)
208
209/* Alignment exception. */
210 . = EXC_OFF_ALIGN
211Alignment:
Rafal Jaworowski02032e82007-06-22 14:58:04 +0200212 EXCEPTION_PROLOG(SRR0, SRR1)
wdenkc6097192002-11-03 00:24:07 +0000213 mfspr r4,DAR
214 stw r4,_DAR(r21)
215 mfspr r5,DSISR
216 stw r5,_DSISR(r21)
217 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlundfc4e1882010-01-19 14:41:55 +0100218 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
wdenkc6097192002-11-03 00:24:07 +0000219
220/* Program check exception */
221 . = EXC_OFF_PROGRAM
222ProgramCheck:
Rafal Jaworowski02032e82007-06-22 14:58:04 +0200223 EXCEPTION_PROLOG(SRR0, SRR1)
wdenkc6097192002-11-03 00:24:07 +0000224 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlundfc4e1882010-01-19 14:41:55 +0100225 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
226 MSR_KERNEL, COPY_EE)
wdenkc6097192002-11-03 00:24:07 +0000227
228 /* No FPU on MPC8xx. This exception is not supposed to happen.
229 */
230 STD_EXCEPTION(EXC_OFF_FPUNAVAIL, FPUnavailable, UnknownException)
231
232 /* I guess we could implement decrementer, and may have
233 * to someday for timekeeping.
234 */
235 STD_EXCEPTION(EXC_OFF_DECR, Decrementer, timer_interrupt)
236 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
237 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
wdenk27b207f2003-07-24 23:38:38 +0000238 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
wdenkc6097192002-11-03 00:24:07 +0000239
240 STD_EXCEPTION(EXC_OFF_TRACE, SingleStep, UnknownException)
241
242 STD_EXCEPTION(EXC_OFF_FPUNASSIST, Trap_0e, UnknownException)
243 STD_EXCEPTION(EXC_OFF_PMI, Trap_0f, UnknownException)
244
245 STD_EXCEPTION(EXC_OFF_ITME, InstructionTransMiss, UnknownException)
246 STD_EXCEPTION(EXC_OFF_DLTME, DataLoadTransMiss, UnknownException)
247 STD_EXCEPTION(EXC_OFF_DSTME, DataStoreTransMiss, UnknownException)
wdenk43d96162003-03-06 00:02:04 +0000248 STD_EXCEPTION(EXC_OFF_IABE, InstructionBreakpoint, DebugException)
wdenkc6097192002-11-03 00:24:07 +0000249 STD_EXCEPTION(EXC_OFF_SMIE, SysManageInt, UnknownException)
250 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
251 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
252 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
253 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
254 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
255 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
256 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
257 STD_EXCEPTION(0x1c00, ReservedC, UnknownException)
258 STD_EXCEPTION(0x1d00, ReservedD, UnknownException)
259 STD_EXCEPTION(0x1e00, ReservedE, UnknownException)
260 STD_EXCEPTION(0x1f00, ReservedF, UnknownException)
261
262 STD_EXCEPTION(EXC_OFF_RMTE, RunModeTrace, UnknownException)
263
264 .globl _end_of_vectors
265_end_of_vectors:
266
267
268 . = 0x3000
269
270/*
271 * This code finishes saving the registers to the exception frame
272 * and jumps to the appropriate handler for the exception.
273 * Register r21 is pointer into trap frame, r1 has new stack pointer.
274 */
275 .globl transfer_to_handler
276transfer_to_handler:
277 stw r22,_NIP(r21)
278 lis r22,MSR_POW@h
279 andc r23,r23,r22
280 stw r23,_MSR(r21)
281 SAVE_GPR(7, r21)
282 SAVE_4GPRS(8, r21)
283 SAVE_8GPRS(12, r21)
284 SAVE_8GPRS(24, r21)
285#if 0
286 andi. r23,r23,MSR_PR
287 mfspr r23,SPRG3 /* if from user, fix up tss.regs */
288 beq 2f
289 addi r24,r1,STACK_FRAME_OVERHEAD
290 stw r24,PT_REGS(r23)
2912: addi r2,r23,-TSS /* set r2 to current */
292 tovirt(r2,r2,r23)
293#endif
294 mflr r23
295 andi. r24,r23,0x3f00 /* get vector offset */
296 stw r24,TRAP(r21)
297 li r22,0
298 stw r22,RESULT(r21)
299 mtspr SPRG2,r22 /* r1 is now kernel sp */
300#if 0
301 addi r24,r2,TASK_STRUCT_SIZE /* check for kernel stack overflow */
302 cmplw 0,r1,r2
303 cmplw 1,r1,r24
304 crand 1,1,4
305 bgt stack_ovf /* if r2 < r1 < r2+TASK_STRUCT_SIZE */
306#endif
307 lwz r24,0(r23) /* virtual address of handler */
308 lwz r23,4(r23) /* where to go when done */
309 mtspr SRR0,r24
310 ori r20,r20,0x30 /* enable IR, DR */
311 mtspr SRR1,r20
312 mtlr r23
313 SYNC
314 rfi /* jump to handler, enable MMU */
315
316int_return:
317 mfmsr r28 /* Disable interrupts */
318 li r4,0
319 ori r4,r4,MSR_EE
320 andc r28,r28,r4
321 SYNC /* Some chip revs need this... */
322 mtmsr r28
323 SYNC
324 lwz r2,_CTR(r1)
325 lwz r0,_LINK(r1)
326 mtctr r2
327 mtlr r0
328 lwz r2,_XER(r1)
329 lwz r0,_CCR(r1)
330 mtspr XER,r2
331 mtcrf 0xFF,r0
332 REST_10GPRS(3, r1)
333 REST_10GPRS(13, r1)
334 REST_8GPRS(23, r1)
335 REST_GPR(31, r1)
336 lwz r2,_NIP(r1) /* Restore environment */
337 lwz r0,_MSR(r1)
338 mtspr SRR0,r2
339 mtspr SRR1,r0
340 lwz r0,GPR0(r1)
341 lwz r2,GPR2(r1)
342 lwz r1,GPR1(r1)
343 SYNC
344 rfi
345
346/* Cache functions.
347*/
348 .globl icache_enable
349icache_enable:
350 mfspr r5,HID0 /* turn on the I cache. */
351 ori r5,r5,0x8800 /* Instruction cache only! */
352 addis r6,0,0xFFFF
353 ori r6,r6,0xF7FF
354 and r6,r5,r6 /* clear the invalidate bit */
355 sync
356 mtspr HID0,r5
357 mtspr HID0,r6
358 isync
359 sync
360 blr
361
362 .globl icache_disable
363icache_disable:
364 mfspr r5,HID0
365 addis r6,0,0xFFFF
366 ori r6,r6,0x7FFF
367 and r5,r5,r6
368 sync
369 mtspr HID0,r5
370 isync
371 sync
372 blr
373
374 .globl icache_status
375icache_status:
376 mfspr r3, HID0
377 srwi r3, r3, 15 /* >>15 & 1=> select bit 16 */
378 andi. r3, r3, 1
379 blr
380
381 .globl dcache_enable
382dcache_enable:
383 mfspr r5,HID0 /* turn on the D cache. */
384 ori r5,r5,0x4400 /* Data cache only! */
385 mfspr r4, PVR /* read PVR */
386 srawi r3, r4, 16 /* shift off the least 16 bits */
387 cmpi 0, 0, r3, 0xC /* Check for Max pvr */
388 bne NotMax
389 ori r5,r5,0x0040 /* setting the DCFA bit, for Max rev 1 errata */
390NotMax:
391 addis r6,0,0xFFFF
392 ori r6,r6,0xFBFF
393 and r6,r5,r6 /* clear the invalidate bit */
394 sync
395 mtspr HID0,r5
396 mtspr HID0,r6
397 isync
398 sync
399 blr
400
401 .globl dcache_disable
402dcache_disable:
403 mfspr r5,HID0
404 addis r6,0,0xFFFF
405 ori r6,r6,0xBFFF
406 and r5,r5,r6
407 sync
408 mtspr HID0,r5
409 isync
410 sync
411 blr
412
413 .globl dcache_status
414dcache_status:
415 mfspr r3, HID0
416 srwi r3, r3, 14 /* >>14 & 1=> select bit 17 */
417 andi. r3, r3, 1
418 blr
419
420 .globl dc_read
421dc_read:
422/*TODO : who uses this, what should it do?
423*/
424 blr
425
426
427 .globl get_pvr
428get_pvr:
429 mfspr r3, PVR
430 blr
431
432
433/*------------------------------------------------------------------------------*/
434
435/*
436 * void relocate_code (addr_sp, gd, addr_moni)
437 *
438 * This "function" does not return, instead it continues in RAM
439 * after relocating the monitor code.
440 *
441 * r3 = dest
442 * r4 = src
443 * r5 = length in bytes
444 * r6 = cachelinesize
445 */
446 .globl relocate_code
447relocate_code:
448
449 mr r1, r3 /* Set new stack pointer */
450 mr r9, r4 /* Save copy of Global Data pointer */
451 mr r10, r5 /* Save copy of Destination Address */
452
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100453 GET_GOT
wdenkc6097192002-11-03 00:24:07 +0000454 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200455#ifdef CONFIG_SYS_RAMBOOT
456 lis r4, CONFIG_SYS_SDRAM_BASE@h /* Source Address */
457 ori r4, r4, CONFIG_SYS_SDRAM_BASE@l
wdenkc6097192002-11-03 00:24:07 +0000458#else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200459 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
460 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
wdenkc6097192002-11-03 00:24:07 +0000461#endif
wdenk3b57fe02003-05-30 12:48:29 +0000462 lwz r5, GOT(__init_end)
463 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200464 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
wdenkc6097192002-11-03 00:24:07 +0000465
466 /*
467 * Fix GOT pointer:
468 *
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200469 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
wdenkc6097192002-11-03 00:24:07 +0000470 *
471 * Offset:
472 */
473 sub r15, r10, r4
474
475 /* First our own GOT */
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100476 add r12, r12, r15
wdenkc6097192002-11-03 00:24:07 +0000477 /* the the one used by the C code */
478 add r30, r30, r15
479
480 /*
481 * Now relocate code
482 */
483
484 cmplw cr1,r3,r4
485 addi r0,r5,3
486 srwi. r0,r0,2
487 beq cr1,4f /* In place copy is not necessary */
488 beq 7f /* Protect against 0 count */
489 mtctr r0
490 bge cr1,2f
491
492 la r8,-4(r4)
493 la r7,-4(r3)
4941: lwzu r0,4(r8)
495 stwu r0,4(r7)
496 bdnz 1b
497 b 4f
498
4992: slwi r0,r0,2
500 add r8,r4,r0
501 add r7,r3,r0
5023: lwzu r0,-4(r8)
503 stwu r0,-4(r7)
504 bdnz 3b
505
wdenk7205e402003-09-10 22:30:53 +00005064:
507#if !defined(CONFIG_BMW)
508/* Unlock the data cache and invalidate locked area */
509 xor r0, r0, r0
510 mtspr 1011, r0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200511 lis r4, CONFIG_SYS_INIT_RAM_ADDR@h
512 ori r4, r4, CONFIG_SYS_INIT_RAM_ADDR@l
wdenk7205e402003-09-10 22:30:53 +0000513 li r0, 128
514 mtctr r0
51541:
516 dcbi r0, r4
517 addi r4, r4, 32
518 bdnz 41b
519#endif
520
wdenkc6097192002-11-03 00:24:07 +0000521/*
522 * Now flush the cache: note that we must start from a cache aligned
523 * address. Otherwise we might miss one cache line.
524 */
wdenk7205e402003-09-10 22:30:53 +0000525 cmpwi r6,0
wdenkc6097192002-11-03 00:24:07 +0000526 add r5,r3,r5
527 beq 7f /* Always flush prefetch queue in any case */
528 subi r0,r6,1
529 andc r3,r3,r0
530 mr r4,r3
5315: dcbst 0,r4
532 add r4,r4,r6
533 cmplw r4,r5
534 blt 5b
535 sync /* Wait for all dcbst to complete on bus */
536 mr r4,r3
5376: icbi 0,r4
538 add r4,r4,r6
539 cmplw r4,r5
540 blt 6b
5417: sync /* Wait for all icbi to complete on bus */
542 isync
543
544/*
545 * We are done. Do not return, instead branch to second part of board
546 * initialization, now running from RAM.
547 */
548
549 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
550 mtlr r0
551 blr
552
553in_ram:
554
555 /*
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100556 * Relocation Function, r12 point to got2+0x8000
wdenkc6097192002-11-03 00:24:07 +0000557 *
558 * Adjust got2 pointers, no need to check for 0, this code
559 * already puts a few entries in the table.
560 */
561 li r0,__got2_entries@sectoff@l
562 la r3,GOT(_GOT2_TABLE_)
563 lwz r11,GOT(_GOT2_TABLE_)
564 mtctr r0
565 sub r11,r3,r11
566 addi r3,r3,-4
5671: lwzu r0,4(r3)
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +0200568 cmpwi r0,0
569 beq- 2f
wdenkc6097192002-11-03 00:24:07 +0000570 add r0,r0,r11
571 stw r0,0(r3)
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +02005722: bdnz 1b
wdenkc6097192002-11-03 00:24:07 +0000573
574 /*
575 * Now adjust the fixups and the pointers to the fixups
576 * in case we need to move ourselves again.
577 */
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +0200578 li r0,__fixup_entries@sectoff@l
wdenkc6097192002-11-03 00:24:07 +0000579 lwz r3,GOT(_FIXUP_TABLE_)
580 cmpwi r0,0
581 mtctr r0
582 addi r3,r3,-4
583 beq 4f
5843: lwzu r4,4(r3)
585 lwzux r0,r4,r11
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +0200586 cmpwi r0,0
wdenkc6097192002-11-03 00:24:07 +0000587 add r0,r0,r11
588 stw r10,0(r3)
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +0200589 beq- 5f
wdenkc6097192002-11-03 00:24:07 +0000590 stw r0,0(r4)
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +02005915: bdnz 3b
wdenkc6097192002-11-03 00:24:07 +00005924:
593clear_bss:
594 /*
595 * Now clear BSS segment
596 */
wdenk5d232d02003-05-22 22:52:13 +0000597 lwz r3,GOT(__bss_start)
wdenkc6097192002-11-03 00:24:07 +0000598 lwz r4,GOT(_end)
599
600 cmplw 0, r3, r4
601 beq 6f
602
603 li r0, 0
6045:
605 stw r0, 0(r3)
606 addi r3, r3, 4
607 cmplw 0, r3, r4
608 blt 5b
6096:
610
611 mr r3, r9 /* Global Data pointer */
612 mr r4, r10 /* Destination Address */
613 bl board_init_r
614
wdenkc6097192002-11-03 00:24:07 +0000615 /*
616 * Copy exception vector code to low memory
617 *
618 * r3: dest_addr
619 * r7: source address, r8: end address, r9: target address
620 */
621 .globl trap_init
622trap_init:
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100623 mflr r4 /* save link register */
624 GET_GOT
wdenkc6097192002-11-03 00:24:07 +0000625 lwz r7, GOT(_start)
626 lwz r8, GOT(_end_of_vectors)
627
wdenk682011f2003-06-03 23:54:09 +0000628 li r9, 0x100 /* reset vector always at 0x100 */
wdenkc6097192002-11-03 00:24:07 +0000629
630 cmplw 0, r7, r8
631 bgelr /* return if r7>=r8 - just in case */
wdenkc6097192002-11-03 00:24:07 +00006321:
633 lwz r0, 0(r7)
634 stw r0, 0(r9)
635 addi r7, r7, 4
636 addi r9, r9, 4
637 cmplw 0, r7, r8
638 bne 1b
639
640 /*
641 * relocate `hdlr' and `int_return' entries
642 */
643 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
644 li r8, Alignment - _start + EXC_OFF_SYS_RESET
6452:
646 bl trap_reloc
647 addi r7, r7, 0x100 /* next exception vector */
648 cmplw 0, r7, r8
649 blt 2b
650
651 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
652 bl trap_reloc
653
654 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
655 bl trap_reloc
656
657 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
658 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
6593:
660 bl trap_reloc
661 addi r7, r7, 0x100 /* next exception vector */
662 cmplw 0, r7, r8
663 blt 3b
664
665 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
666 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
6674:
668 bl trap_reloc
669 addi r7, r7, 0x100 /* next exception vector */
670 cmplw 0, r7, r8
671 blt 4b
672
673 mtlr r4 /* restore link register */
674 blr
675
wdenkc6097192002-11-03 00:24:07 +0000676 /* Setup the BAT registers.
677 */
678setup_bats:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200679 lis r4, CONFIG_SYS_IBAT0L@h
680 ori r4, r4, CONFIG_SYS_IBAT0L@l
681 lis r3, CONFIG_SYS_IBAT0U@h
682 ori r3, r3, CONFIG_SYS_IBAT0U@l
wdenkc6097192002-11-03 00:24:07 +0000683 mtspr IBAT0L, r4
684 mtspr IBAT0U, r3
685 isync
686
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200687 lis r4, CONFIG_SYS_DBAT0L@h
688 ori r4, r4, CONFIG_SYS_DBAT0L@l
689 lis r3, CONFIG_SYS_DBAT0U@h
690 ori r3, r3, CONFIG_SYS_DBAT0U@l
wdenkc6097192002-11-03 00:24:07 +0000691 mtspr DBAT0L, r4
692 mtspr DBAT0U, r3
693 isync
694
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200695 lis r4, CONFIG_SYS_IBAT1L@h
696 ori r4, r4, CONFIG_SYS_IBAT1L@l
697 lis r3, CONFIG_SYS_IBAT1U@h
698 ori r3, r3, CONFIG_SYS_IBAT1U@l
wdenkc6097192002-11-03 00:24:07 +0000699 mtspr IBAT1L, r4
700 mtspr IBAT1U, r3
701 isync
702
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200703 lis r4, CONFIG_SYS_DBAT1L@h
704 ori r4, r4, CONFIG_SYS_DBAT1L@l
705 lis r3, CONFIG_SYS_DBAT1U@h
706 ori r3, r3, CONFIG_SYS_DBAT1U@l
wdenkc6097192002-11-03 00:24:07 +0000707 mtspr DBAT1L, r4
708 mtspr DBAT1U, r3
709 isync
710
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200711 lis r4, CONFIG_SYS_IBAT2L@h
712 ori r4, r4, CONFIG_SYS_IBAT2L@l
713 lis r3, CONFIG_SYS_IBAT2U@h
714 ori r3, r3, CONFIG_SYS_IBAT2U@l
wdenkc6097192002-11-03 00:24:07 +0000715 mtspr IBAT2L, r4
716 mtspr IBAT2U, r3
717 isync
718
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200719 lis r4, CONFIG_SYS_DBAT2L@h
720 ori r4, r4, CONFIG_SYS_DBAT2L@l
721 lis r3, CONFIG_SYS_DBAT2U@h
722 ori r3, r3, CONFIG_SYS_DBAT2U@l
wdenkc6097192002-11-03 00:24:07 +0000723 mtspr DBAT2L, r4
724 mtspr DBAT2U, r3
725 isync
726
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200727 lis r4, CONFIG_SYS_IBAT3L@h
728 ori r4, r4, CONFIG_SYS_IBAT3L@l
729 lis r3, CONFIG_SYS_IBAT3U@h
730 ori r3, r3, CONFIG_SYS_IBAT3U@l
wdenkc6097192002-11-03 00:24:07 +0000731 mtspr IBAT3L, r4
732 mtspr IBAT3U, r3
733 isync
734
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200735 lis r4, CONFIG_SYS_DBAT3L@h
736 ori r4, r4, CONFIG_SYS_DBAT3L@l
737 lis r3, CONFIG_SYS_DBAT3U@h
738 ori r3, r3, CONFIG_SYS_DBAT3U@l
wdenkc6097192002-11-03 00:24:07 +0000739 mtspr DBAT3L, r4
740 mtspr DBAT3U, r3
741 isync
742
743 /* Invalidate TLBs.
744 * -> for (val = 0; val < 0x20000; val+=0x1000)
745 * -> tlbie(val);
746 */
747 lis r3, 0
748 lis r5, 2
749
7501:
751 tlbie r3
752 addi r3, r3, 0x1000
753 cmp 0, 0, r3, r5
754 blt 1b
755
756 blr