blob: 70db73e1569c2b495eb5d8609f05a63d8612bdca [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 */
Wolfgang Denk0191e472010-10-26 14:34:52 +020040#include <asm-offsets.h>
wdenkc6097192002-11-03 00:24:07 +000041#include <config.h>
42#include <mpc824x.h>
43#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 Tyser3a1362d2010-10-14 23:33:24 -050052#include <asm/u-boot.h>
wdenkc6097192002-11-03 00:24:07 +000053
wdenkc6097192002-11-03 00:24:07 +000054/* We don't want the MMU yet.
55*/
56#undef MSR_KERNEL
57/* FP, Machine Check and Recoverable Interr. */
58#define MSR_KERNEL ( MSR_FP | MSR_ME | MSR_RI )
59
60/*
61 * Set up GOT: Global Offset Table
62 *
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +010063 * Use r12 to access the GOT
wdenkc6097192002-11-03 00:24:07 +000064 */
65 START_GOT
66 GOT_ENTRY(_GOT2_TABLE_)
67 GOT_ENTRY(_FIXUP_TABLE_)
68
69 GOT_ENTRY(_start)
70 GOT_ENTRY(_start_of_vectors)
71 GOT_ENTRY(_end_of_vectors)
72 GOT_ENTRY(transfer_to_handler)
73
wdenkb9a83a92003-05-30 12:48:29 +000074 GOT_ENTRY(__init_end)
Po-Yu Chuangcedbf4b2011-03-01 22:59:59 +000075 GOT_ENTRY(__bss_end__)
wdenkbf2f8c92003-05-22 22:52:13 +000076 GOT_ENTRY(__bss_start)
wdenkc6097192002-11-03 00:24:07 +000077#if defined(CONFIG_FADS)
78 GOT_ENTRY(environment)
79#endif
80 END_GOT
81
82/*
83 * r3 - 1st arg to board_init(): IMMP pointer
84 * r4 - 2nd arg to board_init(): boot flag
85 */
86 .text
87 .long 0x27051956 /* U-Boot Magic Number */
88 .globl version_string
89version_string:
Andreas Bießmann61d01952011-07-18 20:24:04 +020090 .ascii U_BOOT_VERSION_STRING, "\0"
wdenkc6097192002-11-03 00:24:07 +000091
92 . = EXC_OFF_SYS_RESET
93 .globl _start
94_start:
wdenkc6097192002-11-03 00:24:07 +000095 /* Initialize machine status; enable machine check interrupt */
96 /*----------------------------------------------------------------------*/
97 li r3, MSR_KERNEL /* Set FP, ME, RI flags */
98 mtmsr r3
99 mtspr SRR1, r3 /* Make SRR1 match MSR */
100
101 addis r0,0,0x0000 /* lets make sure that r0 is really 0 */
102 mtspr HID0, r0 /* disable I and D caches */
103
104 mfspr r3, ICR /* clear Interrupt Cause Register */
105
106 mfmsr r3 /* turn off address translation */
107 addis r4,0,0xffff
108 ori r4,r4,0xffcf
109 and r3,r3,r4
110 mtmsr r3
111 isync
112 sync /* the MMU should be off... */
113
114
115in_flash:
116#if defined(CONFIG_BMW)
117 bl early_init_f /* Must be ASM: no stack yet! */
118#endif
119 /*
120 * Setup BATs - cannot be done in C since we don't have a stack yet
121 */
122 bl setup_bats
123
124 /* Enable MMU.
125 */
126 mfmsr r3
127 ori r3, r3, (MSR_IR | MSR_DR)
128 mtmsr r3
129#if !defined(CONFIG_BMW)
130 /* Enable and invalidate data cache.
131 */
132 mfspr r3, HID0
133 mr r2, r3
134 ori r3, r3, HID0_DCE | HID0_DCI
135 ori r2, r2, HID0_DCE
136 sync
137 mtspr HID0, r3
138 mtspr HID0, r2
139 sync
140
141 /* Allocate Initial RAM in data cache.
142 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200143 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
144 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
wdenkc6097192002-11-03 00:24:07 +0000145 li r2, 128
146 mtctr r2
1471:
148 dcbz r0, r3
149 addi r3, r3, 32
150 bdnz 1b
151
152 /* Lock way0 in data cache.
153 */
154 mfspr r3, 1011
155 lis r2, 0xffff
156 ori r2, r2, 0xff1f
157 and r3, r3, r2
158 ori r3, r3, 0x0080
159 sync
160 mtspr 1011, r3
161#endif /* !CONFIG_BMW */
162 /*
163 * Thisk the stack pointer *somewhere* sensible. Doesnt
164 * matter much where as we'll move it when we relocate
165 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200166 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
167 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
wdenkc6097192002-11-03 00:24:07 +0000168
169 li r0, 0 /* Make room for stack frame header and */
170 stwu r0, -4(r1) /* clear final stack frame so that */
171 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
172
173 /* let the C-code set up the rest */
174 /* */
175 /* Be careful to keep code relocatable ! */
176 /*----------------------------------------------------------------------*/
177
178 GET_GOT /* initialize GOT access */
Wolfgang Denkb2d36ea2011-04-20 22:11:21 +0200179
wdenkc6097192002-11-03 00:24:07 +0000180 /* r3: IMMR */
181 bl cpu_init_f /* run low-level CPU init code (from Flash) */
182
wdenkc6097192002-11-03 00:24:07 +0000183 bl board_init_f /* run 1st part of board init code (from Flash) */
184
Peter Tyser0c44caf2010-09-14 19:13:53 -0500185 /* NOTREACHED - board_init_f() does not return */
186
wdenkc6097192002-11-03 00:24:07 +0000187
wdenkc6097192002-11-03 00:24:07 +0000188 .globl _start_of_vectors
189_start_of_vectors:
190
191/* Machine check */
192 STD_EXCEPTION(EXC_OFF_MACH_CHCK, MachineCheck, MachineCheckException)
193
194/* Data Storage exception. "Never" generated on the 860. */
195 STD_EXCEPTION(EXC_OFF_DATA_STOR, DataStorage, UnknownException)
196
197/* Instruction Storage exception. "Never" generated on the 860. */
198 STD_EXCEPTION(EXC_OFF_INS_STOR, InstStorage, UnknownException)
199
200/* External Interrupt exception. */
201 STD_EXCEPTION(EXC_OFF_EXTERNAL, ExtInterrupt, external_interrupt)
202
203/* Alignment exception. */
204 . = EXC_OFF_ALIGN
205Alignment:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200206 EXCEPTION_PROLOG(SRR0, SRR1)
wdenkc6097192002-11-03 00:24:07 +0000207 mfspr r4,DAR
208 stw r4,_DAR(r21)
209 mfspr r5,DSISR
210 stw r5,_DSISR(r21)
211 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100212 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
wdenkc6097192002-11-03 00:24:07 +0000213
214/* Program check exception */
215 . = EXC_OFF_PROGRAM
216ProgramCheck:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200217 EXCEPTION_PROLOG(SRR0, SRR1)
wdenkc6097192002-11-03 00:24:07 +0000218 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100219 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
220 MSR_KERNEL, COPY_EE)
wdenkc6097192002-11-03 00:24:07 +0000221
222 /* No FPU on MPC8xx. This exception is not supposed to happen.
223 */
224 STD_EXCEPTION(EXC_OFF_FPUNAVAIL, FPUnavailable, UnknownException)
225
226 /* I guess we could implement decrementer, and may have
227 * to someday for timekeeping.
228 */
229 STD_EXCEPTION(EXC_OFF_DECR, Decrementer, timer_interrupt)
230 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
231 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
wdenk874ac262003-07-24 23:38:38 +0000232 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
wdenkc6097192002-11-03 00:24:07 +0000233
234 STD_EXCEPTION(EXC_OFF_TRACE, SingleStep, UnknownException)
235
236 STD_EXCEPTION(EXC_OFF_FPUNASSIST, Trap_0e, UnknownException)
237 STD_EXCEPTION(EXC_OFF_PMI, Trap_0f, UnknownException)
238
239 STD_EXCEPTION(EXC_OFF_ITME, InstructionTransMiss, UnknownException)
240 STD_EXCEPTION(EXC_OFF_DLTME, DataLoadTransMiss, UnknownException)
241 STD_EXCEPTION(EXC_OFF_DSTME, DataStoreTransMiss, UnknownException)
wdenk4a5c8a72003-03-06 00:02:04 +0000242 STD_EXCEPTION(EXC_OFF_IABE, InstructionBreakpoint, DebugException)
wdenkc6097192002-11-03 00:24:07 +0000243 STD_EXCEPTION(EXC_OFF_SMIE, SysManageInt, UnknownException)
244 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
245 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
246 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
247 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
248 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
249 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
250 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
251 STD_EXCEPTION(0x1c00, ReservedC, UnknownException)
252 STD_EXCEPTION(0x1d00, ReservedD, UnknownException)
253 STD_EXCEPTION(0x1e00, ReservedE, UnknownException)
254 STD_EXCEPTION(0x1f00, ReservedF, UnknownException)
255
256 STD_EXCEPTION(EXC_OFF_RMTE, RunModeTrace, UnknownException)
257
258 .globl _end_of_vectors
259_end_of_vectors:
260
261
262 . = 0x3000
263
264/*
265 * This code finishes saving the registers to the exception frame
266 * and jumps to the appropriate handler for the exception.
267 * Register r21 is pointer into trap frame, r1 has new stack pointer.
268 */
269 .globl transfer_to_handler
270transfer_to_handler:
271 stw r22,_NIP(r21)
272 lis r22,MSR_POW@h
273 andc r23,r23,r22
274 stw r23,_MSR(r21)
275 SAVE_GPR(7, r21)
276 SAVE_4GPRS(8, r21)
277 SAVE_8GPRS(12, r21)
278 SAVE_8GPRS(24, r21)
279#if 0
280 andi. r23,r23,MSR_PR
281 mfspr r23,SPRG3 /* if from user, fix up tss.regs */
282 beq 2f
283 addi r24,r1,STACK_FRAME_OVERHEAD
284 stw r24,PT_REGS(r23)
2852: addi r2,r23,-TSS /* set r2 to current */
286 tovirt(r2,r2,r23)
287#endif
288 mflr r23
289 andi. r24,r23,0x3f00 /* get vector offset */
290 stw r24,TRAP(r21)
291 li r22,0
292 stw r22,RESULT(r21)
293 mtspr SPRG2,r22 /* r1 is now kernel sp */
294#if 0
295 addi r24,r2,TASK_STRUCT_SIZE /* check for kernel stack overflow */
296 cmplw 0,r1,r2
297 cmplw 1,r1,r24
298 crand 1,1,4
299 bgt stack_ovf /* if r2 < r1 < r2+TASK_STRUCT_SIZE */
300#endif
301 lwz r24,0(r23) /* virtual address of handler */
302 lwz r23,4(r23) /* where to go when done */
303 mtspr SRR0,r24
304 ori r20,r20,0x30 /* enable IR, DR */
305 mtspr SRR1,r20
306 mtlr r23
307 SYNC
308 rfi /* jump to handler, enable MMU */
309
310int_return:
311 mfmsr r28 /* Disable interrupts */
312 li r4,0
313 ori r4,r4,MSR_EE
314 andc r28,r28,r4
315 SYNC /* Some chip revs need this... */
316 mtmsr r28
317 SYNC
318 lwz r2,_CTR(r1)
319 lwz r0,_LINK(r1)
320 mtctr r2
321 mtlr r0
322 lwz r2,_XER(r1)
323 lwz r0,_CCR(r1)
324 mtspr XER,r2
325 mtcrf 0xFF,r0
326 REST_10GPRS(3, r1)
327 REST_10GPRS(13, r1)
328 REST_8GPRS(23, r1)
329 REST_GPR(31, r1)
330 lwz r2,_NIP(r1) /* Restore environment */
331 lwz r0,_MSR(r1)
332 mtspr SRR0,r2
333 mtspr SRR1,r0
334 lwz r0,GPR0(r1)
335 lwz r2,GPR2(r1)
336 lwz r1,GPR1(r1)
337 SYNC
338 rfi
339
340/* Cache functions.
341*/
342 .globl icache_enable
343icache_enable:
344 mfspr r5,HID0 /* turn on the I cache. */
345 ori r5,r5,0x8800 /* Instruction cache only! */
346 addis r6,0,0xFFFF
347 ori r6,r6,0xF7FF
348 and r6,r5,r6 /* clear the invalidate bit */
349 sync
350 mtspr HID0,r5
351 mtspr HID0,r6
352 isync
353 sync
354 blr
355
356 .globl icache_disable
357icache_disable:
358 mfspr r5,HID0
359 addis r6,0,0xFFFF
360 ori r6,r6,0x7FFF
361 and r5,r5,r6
362 sync
363 mtspr HID0,r5
364 isync
365 sync
366 blr
367
368 .globl icache_status
369icache_status:
370 mfspr r3, HID0
371 srwi r3, r3, 15 /* >>15 & 1=> select bit 16 */
372 andi. r3, r3, 1
373 blr
374
375 .globl dcache_enable
376dcache_enable:
377 mfspr r5,HID0 /* turn on the D cache. */
378 ori r5,r5,0x4400 /* Data cache only! */
379 mfspr r4, PVR /* read PVR */
380 srawi r3, r4, 16 /* shift off the least 16 bits */
381 cmpi 0, 0, r3, 0xC /* Check for Max pvr */
382 bne NotMax
383 ori r5,r5,0x0040 /* setting the DCFA bit, for Max rev 1 errata */
384NotMax:
385 addis r6,0,0xFFFF
386 ori r6,r6,0xFBFF
387 and r6,r5,r6 /* clear the invalidate bit */
388 sync
389 mtspr HID0,r5
390 mtspr HID0,r6
391 isync
392 sync
393 blr
394
395 .globl dcache_disable
396dcache_disable:
397 mfspr r5,HID0
398 addis r6,0,0xFFFF
399 ori r6,r6,0xBFFF
400 and r5,r5,r6
401 sync
402 mtspr HID0,r5
403 isync
404 sync
405 blr
406
407 .globl dcache_status
408dcache_status:
409 mfspr r3, HID0
410 srwi r3, r3, 14 /* >>14 & 1=> select bit 17 */
411 andi. r3, r3, 1
412 blr
413
414 .globl dc_read
415dc_read:
416/*TODO : who uses this, what should it do?
417*/
418 blr
419
420
421 .globl get_pvr
422get_pvr:
423 mfspr r3, PVR
424 blr
425
426
427/*------------------------------------------------------------------------------*/
428
429/*
430 * void relocate_code (addr_sp, gd, addr_moni)
431 *
432 * This "function" does not return, instead it continues in RAM
433 * after relocating the monitor code.
434 *
435 * r3 = dest
436 * r4 = src
437 * r5 = length in bytes
438 * r6 = cachelinesize
439 */
440 .globl relocate_code
441relocate_code:
442
443 mr r1, r3 /* Set new stack pointer */
444 mr r9, r4 /* Save copy of Global Data pointer */
445 mr r10, r5 /* Save copy of Destination Address */
446
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100447 GET_GOT
wdenkc6097192002-11-03 00:24:07 +0000448 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200449#ifdef CONFIG_SYS_RAMBOOT
450 lis r4, CONFIG_SYS_SDRAM_BASE@h /* Source Address */
451 ori r4, r4, CONFIG_SYS_SDRAM_BASE@l
wdenkc6097192002-11-03 00:24:07 +0000452#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200453 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
454 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
wdenkc6097192002-11-03 00:24:07 +0000455#endif
wdenkb9a83a92003-05-30 12:48:29 +0000456 lwz r5, GOT(__init_end)
457 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200458 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
wdenkc6097192002-11-03 00:24:07 +0000459
460 /*
461 * Fix GOT pointer:
462 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200463 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
wdenkc6097192002-11-03 00:24:07 +0000464 *
465 * Offset:
466 */
467 sub r15, r10, r4
468
469 /* First our own GOT */
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100470 add r12, r12, r15
wdenkc6097192002-11-03 00:24:07 +0000471 /* the the one used by the C code */
472 add r30, r30, r15
473
474 /*
475 * Now relocate code
476 */
477
478 cmplw cr1,r3,r4
479 addi r0,r5,3
480 srwi. r0,r0,2
481 beq cr1,4f /* In place copy is not necessary */
482 beq 7f /* Protect against 0 count */
483 mtctr r0
484 bge cr1,2f
485
486 la r8,-4(r4)
487 la r7,-4(r3)
4881: lwzu r0,4(r8)
489 stwu r0,4(r7)
490 bdnz 1b
491 b 4f
492
4932: slwi r0,r0,2
494 add r8,r4,r0
495 add r7,r3,r0
4963: lwzu r0,-4(r8)
497 stwu r0,-4(r7)
498 bdnz 3b
499
wdenk2c9b05d2003-09-10 22:30:53 +00005004:
501#if !defined(CONFIG_BMW)
502/* Unlock the data cache and invalidate locked area */
503 xor r0, r0, r0
504 mtspr 1011, r0
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200505 lis r4, CONFIG_SYS_INIT_RAM_ADDR@h
506 ori r4, r4, CONFIG_SYS_INIT_RAM_ADDR@l
wdenk2c9b05d2003-09-10 22:30:53 +0000507 li r0, 128
508 mtctr r0
50941:
510 dcbi r0, r4
511 addi r4, r4, 32
512 bdnz 41b
513#endif
514
wdenkc6097192002-11-03 00:24:07 +0000515/*
516 * Now flush the cache: note that we must start from a cache aligned
517 * address. Otherwise we might miss one cache line.
518 */
wdenk2c9b05d2003-09-10 22:30:53 +0000519 cmpwi r6,0
wdenkc6097192002-11-03 00:24:07 +0000520 add r5,r3,r5
521 beq 7f /* Always flush prefetch queue in any case */
522 subi r0,r6,1
523 andc r3,r3,r0
524 mr r4,r3
5255: dcbst 0,r4
526 add r4,r4,r6
527 cmplw r4,r5
528 blt 5b
529 sync /* Wait for all dcbst to complete on bus */
530 mr r4,r3
5316: icbi 0,r4
532 add r4,r4,r6
533 cmplw r4,r5
534 blt 6b
5357: sync /* Wait for all icbi to complete on bus */
536 isync
537
538/*
539 * We are done. Do not return, instead branch to second part of board
540 * initialization, now running from RAM.
541 */
542
543 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
544 mtlr r0
545 blr
546
547in_ram:
548
549 /*
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100550 * Relocation Function, r12 point to got2+0x8000
wdenkc6097192002-11-03 00:24:07 +0000551 *
552 * Adjust got2 pointers, no need to check for 0, this code
553 * already puts a few entries in the table.
554 */
555 li r0,__got2_entries@sectoff@l
556 la r3,GOT(_GOT2_TABLE_)
557 lwz r11,GOT(_GOT2_TABLE_)
558 mtctr r0
559 sub r11,r3,r11
560 addi r3,r3,-4
5611: lwzu r0,4(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +0200562 cmpwi r0,0
563 beq- 2f
wdenkc6097192002-11-03 00:24:07 +0000564 add r0,r0,r11
565 stw r0,0(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02005662: bdnz 1b
wdenkc6097192002-11-03 00:24:07 +0000567
568 /*
569 * Now adjust the fixups and the pointers to the fixups
570 * in case we need to move ourselves again.
571 */
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +0200572 li r0,__fixup_entries@sectoff@l
wdenkc6097192002-11-03 00:24:07 +0000573 lwz r3,GOT(_FIXUP_TABLE_)
574 cmpwi r0,0
575 mtctr r0
576 addi r3,r3,-4
577 beq 4f
5783: lwzu r4,4(r3)
579 lwzux r0,r4,r11
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +0200580 cmpwi r0,0
wdenkc6097192002-11-03 00:24:07 +0000581 add r0,r0,r11
Joakim Tjernlund401b5922010-11-04 19:02:00 +0100582 stw r4,0(r3)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +0200583 beq- 5f
wdenkc6097192002-11-03 00:24:07 +0000584 stw r0,0(r4)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02005855: bdnz 3b
wdenkc6097192002-11-03 00:24:07 +00005864:
587clear_bss:
588 /*
589 * Now clear BSS segment
590 */
wdenkbf2f8c92003-05-22 22:52:13 +0000591 lwz r3,GOT(__bss_start)
Po-Yu Chuangcedbf4b2011-03-01 22:59:59 +0000592 lwz r4,GOT(__bss_end__)
wdenkc6097192002-11-03 00:24:07 +0000593
594 cmplw 0, r3, r4
595 beq 6f
596
597 li r0, 0
5985:
599 stw r0, 0(r3)
600 addi r3, r3, 4
601 cmplw 0, r3, r4
602 blt 5b
6036:
604
605 mr r3, r9 /* Global Data pointer */
606 mr r4, r10 /* Destination Address */
607 bl board_init_r
608
wdenkc6097192002-11-03 00:24:07 +0000609 /*
610 * Copy exception vector code to low memory
611 *
612 * r3: dest_addr
613 * r7: source address, r8: end address, r9: target address
614 */
615 .globl trap_init
616trap_init:
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100617 mflr r4 /* save link register */
618 GET_GOT
wdenkc6097192002-11-03 00:24:07 +0000619 lwz r7, GOT(_start)
620 lwz r8, GOT(_end_of_vectors)
621
wdenk4e112c12003-06-03 23:54:09 +0000622 li r9, 0x100 /* reset vector always at 0x100 */
wdenkc6097192002-11-03 00:24:07 +0000623
624 cmplw 0, r7, r8
625 bgelr /* return if r7>=r8 - just in case */
wdenkc6097192002-11-03 00:24:07 +00006261:
627 lwz r0, 0(r7)
628 stw r0, 0(r9)
629 addi r7, r7, 4
630 addi r9, r9, 4
631 cmplw 0, r7, r8
632 bne 1b
633
634 /*
635 * relocate `hdlr' and `int_return' entries
636 */
637 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
638 li r8, Alignment - _start + EXC_OFF_SYS_RESET
6392:
640 bl trap_reloc
641 addi r7, r7, 0x100 /* next exception vector */
642 cmplw 0, r7, r8
643 blt 2b
644
645 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
646 bl trap_reloc
647
648 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
649 bl trap_reloc
650
651 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
652 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
6533:
654 bl trap_reloc
655 addi r7, r7, 0x100 /* next exception vector */
656 cmplw 0, r7, r8
657 blt 3b
658
659 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
660 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
6614:
662 bl trap_reloc
663 addi r7, r7, 0x100 /* next exception vector */
664 cmplw 0, r7, r8
665 blt 4b
666
667 mtlr r4 /* restore link register */
668 blr
669
wdenkc6097192002-11-03 00:24:07 +0000670 /* Setup the BAT registers.
671 */
672setup_bats:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200673 lis r4, CONFIG_SYS_IBAT0L@h
674 ori r4, r4, CONFIG_SYS_IBAT0L@l
675 lis r3, CONFIG_SYS_IBAT0U@h
676 ori r3, r3, CONFIG_SYS_IBAT0U@l
wdenkc6097192002-11-03 00:24:07 +0000677 mtspr IBAT0L, r4
678 mtspr IBAT0U, r3
679 isync
680
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200681 lis r4, CONFIG_SYS_DBAT0L@h
682 ori r4, r4, CONFIG_SYS_DBAT0L@l
683 lis r3, CONFIG_SYS_DBAT0U@h
684 ori r3, r3, CONFIG_SYS_DBAT0U@l
wdenkc6097192002-11-03 00:24:07 +0000685 mtspr DBAT0L, r4
686 mtspr DBAT0U, r3
687 isync
688
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200689 lis r4, CONFIG_SYS_IBAT1L@h
690 ori r4, r4, CONFIG_SYS_IBAT1L@l
691 lis r3, CONFIG_SYS_IBAT1U@h
692 ori r3, r3, CONFIG_SYS_IBAT1U@l
wdenkc6097192002-11-03 00:24:07 +0000693 mtspr IBAT1L, r4
694 mtspr IBAT1U, r3
695 isync
696
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200697 lis r4, CONFIG_SYS_DBAT1L@h
698 ori r4, r4, CONFIG_SYS_DBAT1L@l
699 lis r3, CONFIG_SYS_DBAT1U@h
700 ori r3, r3, CONFIG_SYS_DBAT1U@l
wdenkc6097192002-11-03 00:24:07 +0000701 mtspr DBAT1L, r4
702 mtspr DBAT1U, r3
703 isync
704
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200705 lis r4, CONFIG_SYS_IBAT2L@h
706 ori r4, r4, CONFIG_SYS_IBAT2L@l
707 lis r3, CONFIG_SYS_IBAT2U@h
708 ori r3, r3, CONFIG_SYS_IBAT2U@l
wdenkc6097192002-11-03 00:24:07 +0000709 mtspr IBAT2L, r4
710 mtspr IBAT2U, r3
711 isync
712
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200713 lis r4, CONFIG_SYS_DBAT2L@h
714 ori r4, r4, CONFIG_SYS_DBAT2L@l
715 lis r3, CONFIG_SYS_DBAT2U@h
716 ori r3, r3, CONFIG_SYS_DBAT2U@l
wdenkc6097192002-11-03 00:24:07 +0000717 mtspr DBAT2L, r4
718 mtspr DBAT2U, r3
719 isync
720
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200721 lis r4, CONFIG_SYS_IBAT3L@h
722 ori r4, r4, CONFIG_SYS_IBAT3L@l
723 lis r3, CONFIG_SYS_IBAT3U@h
724 ori r3, r3, CONFIG_SYS_IBAT3U@l
wdenkc6097192002-11-03 00:24:07 +0000725 mtspr IBAT3L, r4
726 mtspr IBAT3U, r3
727 isync
728
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200729 lis r4, CONFIG_SYS_DBAT3L@h
730 ori r4, r4, CONFIG_SYS_DBAT3L@l
731 lis r3, CONFIG_SYS_DBAT3U@h
732 ori r3, r3, CONFIG_SYS_DBAT3U@l
wdenkc6097192002-11-03 00:24:07 +0000733 mtspr DBAT3L, r4
734 mtspr DBAT3U, r3
735 isync
736
737 /* Invalidate TLBs.
738 * -> for (val = 0; val < 0x20000; val+=0x1000)
739 * -> tlbie(val);
740 */
741 lis r3, 0
742 lis r5, 2
743
7441:
745 tlbie r3
746 addi r3, r3, 0x1000
747 cmp 0, 0, r3, r5
748 blt 1b
749
750 blr