blob: e5cabcac054899535389f958669d14490f42fdcc [file] [log] [blame]
wdenk9c53f402003-10-15 23:53:47 +00001/*
Andy Flemingf08233c2007-08-14 01:34:21 -05002 * Copyright 2004, 2007 Freescale Semiconductor.
wdenk9c53f402003-10-15 23:53:47 +00003 * Copyright (C) 2003 Motorola,Inc.
wdenk9c53f402003-10-15 23:53:47 +00004 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/* U-Boot Startup Code for Motorola 85xx PowerPC based Embedded Boards
25 *
26 * The processor starts at 0xfffffffc and the code is first executed in the
27 * last 4K page(0xfffff000-0xffffffff) in flash/rom.
28 *
29 */
30
31#include <config.h>
32#include <mpc85xx.h>
33#include <version.h>
34
35#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
36
37#include <ppc_asm.tmpl>
38#include <ppc_defs.h>
39
40#include <asm/cache.h>
41#include <asm/mmu.h>
42
43#ifndef CONFIG_IDENT_STRING
44#define CONFIG_IDENT_STRING ""
45#endif
46
47#undef MSR_KERNEL
Andy Flemingf08233c2007-08-14 01:34:21 -050048#define MSR_KERNEL ( MSR_ME ) /* Machine Check */
wdenk9c53f402003-10-15 23:53:47 +000049
50/*
51 * Set up GOT: Global Offset Table
52 *
53 * Use r14 to access the GOT
54 */
55 START_GOT
56 GOT_ENTRY(_GOT2_TABLE_)
57 GOT_ENTRY(_FIXUP_TABLE_)
58
59 GOT_ENTRY(_start)
60 GOT_ENTRY(_start_of_vectors)
61 GOT_ENTRY(_end_of_vectors)
62 GOT_ENTRY(transfer_to_handler)
63
64 GOT_ENTRY(__init_end)
65 GOT_ENTRY(_end)
66 GOT_ENTRY(__bss_start)
67 END_GOT
68
69/*
70 * e500 Startup -- after reset only the last 4KB of the effective
71 * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
72 * section is located at THIS LAST page and basically does three
73 * things: clear some registers, set up exception tables and
74 * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
75 * continue the boot procedure.
76
77 * Once the boot rom is mapped by TLB entries we can proceed
78 * with normal startup.
79 *
80 */
81
Andy Flemingf08233c2007-08-14 01:34:21 -050082 .section .bootpg,"ax"
83 .globl _start_e500
wdenk9c53f402003-10-15 23:53:47 +000084
85_start_e500:
wdenka445ddf2004-06-09 00:34:46 +000086
Andy Flemingf08233c2007-08-14 01:34:21 -050087/* clear registers/arrays not reset by hardware */
wdenk9c53f402003-10-15 23:53:47 +000088
Andy Flemingf08233c2007-08-14 01:34:21 -050089 /* L1 */
90 li r0,2
91 mtspr L1CSR0,r0 /* invalidate d-cache */
92 mtspr L1CSR1,r0 /* invalidate i-cache */
wdenk9c53f402003-10-15 23:53:47 +000093
94 mfspr r1,DBSR
95 mtspr DBSR,r1 /* Clear all valid bits */
96
Andy Flemingf08233c2007-08-14 01:34:21 -050097 /*
98 * Enable L1 Caches early
99 *
100 */
wdenk9c53f402003-10-15 23:53:47 +0000101
Andy Flemingf08233c2007-08-14 01:34:21 -0500102 lis r2,L1CSR0_CPE@H /* enable parity */
103 ori r2,r2,L1CSR0_DCE
104 mtspr L1CSR0,r2 /* enable L1 Dcache */
105 isync
106 mtspr L1CSR1,r2 /* enable L1 Icache */
wdenk9c53f402003-10-15 23:53:47 +0000107 isync
Andy Flemingf08233c2007-08-14 01:34:21 -0500108 msync
wdenk9c53f402003-10-15 23:53:47 +0000109
110 /* Setup interrupt vectors */
wdenkf3da7cc2005-05-13 22:49:36 +0000111 lis r1,TEXT_BASE@h
Andy Flemingf08233c2007-08-14 01:34:21 -0500112 mtspr IVPR,r1
wdenk9c53f402003-10-15 23:53:47 +0000113
wdenkf3da7cc2005-05-13 22:49:36 +0000114 li r1,0x0100
wdenk9c53f402003-10-15 23:53:47 +0000115 mtspr IVOR0,r1 /* 0: Critical input */
wdenkf3da7cc2005-05-13 22:49:36 +0000116 li r1,0x0200
wdenk9c53f402003-10-15 23:53:47 +0000117 mtspr IVOR1,r1 /* 1: Machine check */
wdenkf3da7cc2005-05-13 22:49:36 +0000118 li r1,0x0300
wdenk9c53f402003-10-15 23:53:47 +0000119 mtspr IVOR2,r1 /* 2: Data storage */
wdenkf3da7cc2005-05-13 22:49:36 +0000120 li r1,0x0400
wdenk9c53f402003-10-15 23:53:47 +0000121 mtspr IVOR3,r1 /* 3: Instruction storage */
122 li r1,0x0500
123 mtspr IVOR4,r1 /* 4: External interrupt */
124 li r1,0x0600
125 mtspr IVOR5,r1 /* 5: Alignment */
126 li r1,0x0700
127 mtspr IVOR6,r1 /* 6: Program check */
128 li r1,0x0800
129 mtspr IVOR7,r1 /* 7: floating point unavailable */
wdenkf3da7cc2005-05-13 22:49:36 +0000130 li r1,0x0900
wdenk9c53f402003-10-15 23:53:47 +0000131 mtspr IVOR8,r1 /* 8: System call */
132 /* 9: Auxiliary processor unavailable(unsupported) */
wdenkf3da7cc2005-05-13 22:49:36 +0000133 li r1,0x0a00
wdenk9c53f402003-10-15 23:53:47 +0000134 mtspr IVOR10,r1 /* 10: Decrementer */
wdenkf3da7cc2005-05-13 22:49:36 +0000135 li r1,0x0b00
136 mtspr IVOR11,r1 /* 11: Interval timer */
137 li r1,0x0c00
Wolfgang Denkc94dea22005-08-04 01:24:19 +0200138 mtspr IVOR12,r1 /* 12: Watchdog timer */
139 li r1,0x0d00
wdenk9c53f402003-10-15 23:53:47 +0000140 mtspr IVOR13,r1 /* 13: Data TLB error */
wdenkf3da7cc2005-05-13 22:49:36 +0000141 li r1,0x0e00
wdenk9c53f402003-10-15 23:53:47 +0000142 mtspr IVOR14,r1 /* 14: Instruction TLB error */
wdenkf3da7cc2005-05-13 22:49:36 +0000143 li r1,0x0f00
wdenk9c53f402003-10-15 23:53:47 +0000144 mtspr IVOR15,r1 /* 15: Debug */
145
wdenk9c53f402003-10-15 23:53:47 +0000146
wdenk492b9e72004-08-01 23:02:45 +0000147 /*
wdenk492b9e72004-08-01 23:02:45 +0000148 * After reset, CCSRBAR is located at CFG_CCSRBAR_DEFAULT, i.e.
wdenk9c53f402003-10-15 23:53:47 +0000149 * 0xff700000-0xff800000. We need add a TLB1 entry for this 1MB
150 * region before we can access any CCSR registers such as L2
151 * registers, Local Access Registers,etc. We will also re-allocate
152 * CFG_CCSRBAR_DEFAULT to CFG_CCSRBAR immediately after TLB1 setup.
153 *
154 * Please refer to board-specif directory for TLB1 entry configuration.
155 * (e.g. board/<yourboard>/init.S)
156 *
157 */
wdenkf3da7cc2005-05-13 22:49:36 +0000158 bl tlb1_entry
wdenk9c53f402003-10-15 23:53:47 +0000159 mr r5,r0
wdenk9c53f402003-10-15 23:53:47 +0000160 lwzu r4,0(r5) /* how many TLB1 entries we actually use */
Zang Roy-r61911077fb1a2006-12-20 11:01:00 +0800161 mtctr r4
wdenk9c53f402003-10-15 23:53:47 +0000162
Andy Flemingf08233c2007-08-14 01:34:21 -05001630: lwzu r6,4(r5)
164 lwzu r7,4(r5)
165 lwzu r8,4(r5)
166 lwzu r9,4(r5)
167 mtspr MAS0,r6
168 mtspr MAS1,r7
169 mtspr MAS2,r8
170 mtspr MAS3,r9
wdenk9c53f402003-10-15 23:53:47 +0000171 isync
172 msync
173 tlbwe
174 isync
wdenk9c53f402003-10-15 23:53:47 +0000175 bdnz 0b
176
1771:
178#if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
179 /* Special sequence needed to update CCSRBAR itself */
Andy Flemingf08233c2007-08-14 01:34:21 -0500180 lis r4,CFG_CCSRBAR_DEFAULT@h
181 ori r4,r4,CFG_CCSRBAR_DEFAULT@l
wdenk9c53f402003-10-15 23:53:47 +0000182
Andy Flemingf08233c2007-08-14 01:34:21 -0500183 lis r5,CFG_CCSRBAR@h
184 ori r5,r5,CFG_CCSRBAR@l
wdenk9c53f402003-10-15 23:53:47 +0000185 srwi r6,r5,12
Andy Flemingf08233c2007-08-14 01:34:21 -0500186 stw r6,0(r4)
wdenk9c53f402003-10-15 23:53:47 +0000187 isync
188
Andy Flemingf08233c2007-08-14 01:34:21 -0500189 lis r5,0xffff
wdenk9c53f402003-10-15 23:53:47 +0000190 ori r5,r5,0xf000
Andy Flemingf08233c2007-08-14 01:34:21 -0500191 lwz r5,0(r5)
wdenk9c53f402003-10-15 23:53:47 +0000192 isync
193
Andy Flemingf08233c2007-08-14 01:34:21 -0500194 lis r3,CFG_CCSRBAR@h
195 lwz r5,CFG_CCSRBAR@l(r3)
wdenk9c53f402003-10-15 23:53:47 +0000196 isync
197#endif
198
wdenk9c53f402003-10-15 23:53:47 +0000199
200 /* set up local access windows, defined at board/<boardname>/init.S */
201 lis r7,CFG_CCSRBAR@h
202 ori r7,r7,CFG_CCSRBAR@l
203
wdenkf3da7cc2005-05-13 22:49:36 +0000204 bl law_entry
wdenk9c53f402003-10-15 23:53:47 +0000205 mr r6,r0
wdenk9c53f402003-10-15 23:53:47 +0000206 lwzu r5,0(r6) /* how many windows we actually use */
Zang Roy-r61911077fb1a2006-12-20 11:01:00 +0800207 mtctr r5
wdenk9c53f402003-10-15 23:53:47 +0000208
Andy Flemingf08233c2007-08-14 01:34:21 -0500209 li r2,0x0c28 /* the first pair is reserved for */
210 li r1,0x0c30 /* boot-over-rio-or-pci */
wdenk9c53f402003-10-15 23:53:47 +0000211
Zang Roy-r61911077fb1a2006-12-20 11:01:00 +08002120: lwzu r4,4(r6)
wdenk9c53f402003-10-15 23:53:47 +0000213 lwzu r3,4(r6)
214 stwx r4,r7,r2
215 stwx r3,r7,r1
wdenk9c53f402003-10-15 23:53:47 +0000216 addi r2,r2,0x0020
217 addi r1,r1,0x0020
218 bdnz 0b
219
wdenk9c53f402003-10-15 23:53:47 +0000220 /* Clear and set up some registers. */
221 li r0,0x0000
222 lis r1,0xffff
223 mtspr DEC,r0 /* prevent dec exceptions */
224 mttbl r0 /* prevent fit & wdt exceptions */
225 mttbu r0
226 mtspr TSR,r1 /* clear all timer exception status */
227 mtspr TCR,r0 /* disable all */
228 mtspr ESR,r0 /* clear exception syndrome register */
229 mtspr MCSR,r0 /* machine check syndrome register */
230 mtxer r0 /* clear integer exception register */
231 lis r1,0x0002 /* set CE bit (Critical Exceptions) */
232 ori r1,r1,0x1200 /* set ME/DE bit */
233 mtmsr r1 /* change MSR */
234 isync
235
236 /* Enable Time Base and Select Time Base Clock */
wdenk13eb2212004-07-09 23:27:13 +0000237 lis r0,HID0_EMCP@h /* Enable machine check */
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500238#if defined(CONFIG_ENABLE_36BIT_PHYS)
Andy Flemingf08233c2007-08-14 01:34:21 -0500239 ori r0,r0,(HID0_TBEN|HID0_ENMAS7)@l /* Enable Timebase & MAS7 */
240#else
241 ori r0,r0,HID0_TBEN@l /* enable Timebase */
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500242#endif
wdenk9c53f402003-10-15 23:53:47 +0000243 mtspr HID0,r0
wdenk9c53f402003-10-15 23:53:47 +0000244
Andy Flemingf08233c2007-08-14 01:34:21 -0500245 li r0,(HID1_ASTME|HID1_ABE)@l /* Addr streaming & broadcast */
wdenk9c53f402003-10-15 23:53:47 +0000246 mtspr HID1,r0
wdenk9c53f402003-10-15 23:53:47 +0000247
248 /* Enable Branch Prediction */
249#if defined(CONFIG_BTB)
250 li r0,0x201 /* BBFI = 1, BPEN = 1 */
251 mtspr BUCSR,r0
wdenk9c53f402003-10-15 23:53:47 +0000252#endif
253
254#if defined(CFG_INIT_DBCR)
255 lis r1,0xffff
256 ori r1,r1,0xffff
wdenk13eb2212004-07-09 23:27:13 +0000257 mtspr DBSR,r1 /* Clear all status bits */
wdenk9c53f402003-10-15 23:53:47 +0000258 lis r0,CFG_INIT_DBCR@h /* DBCR0[IDM] must be set */
259 ori r0,r0,CFG_INIT_DBCR@l
wdenk13eb2212004-07-09 23:27:13 +0000260 mtspr DBCR0,r0
wdenk9c53f402003-10-15 23:53:47 +0000261#endif
262
Kumar Gala76e276b2007-08-07 18:07:27 -0500263/* L1 DCache is used for initial RAM */
264
265 /* Allocate Initial RAM in data cache.
266 */
267 lis r3,CFG_INIT_RAM_ADDR@h
268 ori r3,r3,CFG_INIT_RAM_ADDR@l
Kumar Gala91510e02007-10-02 11:12:27 -0500269 li r2,(CFG_DCACHE_SIZE / (2 * CFG_CACHELINE_SIZE))
Kumar Gala76e276b2007-08-07 18:07:27 -0500270 mtctr r2
271 li r0,0
2721:
273 dcbz r0,r3
274 dcbtls 0,r0,r3
Kumar Gala91510e02007-10-02 11:12:27 -0500275 addi r3,r3,CFG_CACHELINE_SIZE
Kumar Gala76e276b2007-08-07 18:07:27 -0500276 bdnz 1b
277
Andy Flemingf08233c2007-08-14 01:34:21 -0500278 /* Jump out the last 4K page and continue to 'normal' start */
Kumar Gala76e276b2007-08-07 18:07:27 -0500279#ifdef CFG_RAMBOOT
Andy Flemingf08233c2007-08-14 01:34:21 -0500280 bl 3f
281 b _start_cont
Kumar Gala76e276b2007-08-07 18:07:27 -0500282#else
283 /* Calculate absolute address in FLASH and jump there */
284 /*--------------------------------------------------------------*/
285 lis r3,CFG_MONITOR_BASE@h
286 ori r3,r3,CFG_MONITOR_BASE@l
287 addi r3,r3,_start_cont - _start + _START_OFFSET
288 mtlr r3
289#endif
Andy Flemingf08233c2007-08-14 01:34:21 -0500290
2913: li r0,0
292 mtspr SRR1,r0 /* Keep things disabled for now */
293 mflr r1
294 mtspr SRR0,r1
295 rfi
wdenk9c53f402003-10-15 23:53:47 +0000296 isync
297
Andy Flemingf08233c2007-08-14 01:34:21 -0500298 .text
299 .globl _start
300_start:
301 .long 0x27051956 /* U-BOOT Magic Number */
302 .globl version_string
303version_string:
304 .ascii U_BOOT_VERSION
305 .ascii " (", __DATE__, " - ", __TIME__, ")"
306 .ascii CONFIG_IDENT_STRING, "\0"
307
308 .align 4
309 .globl _start_cont
310_start_cont:
wdenk9c53f402003-10-15 23:53:47 +0000311 /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
312 lis r1,CFG_INIT_RAM_ADDR@h
313 ori r1,r1,CFG_INIT_SP_OFFSET@l
314
315 li r0,0
316 stwu r0,-4(r1)
317 stwu r0,-4(r1) /* Terminate call chain */
318
319 stwu r1,-8(r1) /* Save back chain and move SP */
320 lis r0,RESET_VECTOR@h /* Address of reset vector */
Andy Flemingf08233c2007-08-14 01:34:21 -0500321 ori r0,r0,RESET_VECTOR@l
wdenk9c53f402003-10-15 23:53:47 +0000322 stwu r1,-8(r1) /* Save back chain and move SP */
323 stw r0,+12(r1) /* Save return addr (underflow vect) */
324
325 GET_GOT
326 bl cpu_init_f
wdenk9c53f402003-10-15 23:53:47 +0000327 bl board_init_f
wdenk13eb2212004-07-09 23:27:13 +0000328 isync
wdenk9c53f402003-10-15 23:53:47 +0000329
Andy Flemingf08233c2007-08-14 01:34:21 -0500330 . = EXC_OFF_SYS_RESET
wdenk9c53f402003-10-15 23:53:47 +0000331 .globl _start_of_vectors
332_start_of_vectors:
Andy Flemingf08233c2007-08-14 01:34:21 -0500333
wdenk9c53f402003-10-15 23:53:47 +0000334/* Critical input. */
Andy Flemingf08233c2007-08-14 01:34:21 -0500335 CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException)
336
337/* Machine check */
338 MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
wdenk9c53f402003-10-15 23:53:47 +0000339
340/* Data Storage exception. */
341 STD_EXCEPTION(0x0300, DataStorage, UnknownException)
342
343/* Instruction Storage exception. */
344 STD_EXCEPTION(0x0400, InstStorage, UnknownException)
345
346/* External Interrupt exception. */
Andy Flemingf08233c2007-08-14 01:34:21 -0500347 STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException)
wdenk9c53f402003-10-15 23:53:47 +0000348
349/* Alignment exception. */
350 . = 0x0600
351Alignment:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200352 EXCEPTION_PROLOG(SRR0, SRR1)
wdenk9c53f402003-10-15 23:53:47 +0000353 mfspr r4,DAR
354 stw r4,_DAR(r21)
355 mfspr r5,DSISR
356 stw r5,_DSISR(r21)
357 addi r3,r1,STACK_FRAME_OVERHEAD
358 li r20,MSR_KERNEL
359 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
360 lwz r6,GOT(transfer_to_handler)
361 mtlr r6
362 blrl
363.L_Alignment:
Andy Flemingf08233c2007-08-14 01:34:21 -0500364 .long AlignmentException - _start + _START_OFFSET
365 .long int_return - _start + _START_OFFSET
wdenk9c53f402003-10-15 23:53:47 +0000366
367/* Program check exception */
368 . = 0x0700
369ProgramCheck:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200370 EXCEPTION_PROLOG(SRR0, SRR1)
wdenk9c53f402003-10-15 23:53:47 +0000371 addi r3,r1,STACK_FRAME_OVERHEAD
372 li r20,MSR_KERNEL
373 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
374 lwz r6,GOT(transfer_to_handler)
375 mtlr r6
376 blrl
377.L_ProgramCheck:
Andy Flemingf08233c2007-08-14 01:34:21 -0500378 .long ProgramCheckException - _start + _START_OFFSET
379 .long int_return - _start + _START_OFFSET
wdenk9c53f402003-10-15 23:53:47 +0000380
381 /* No FPU on MPC85xx. This exception is not supposed to happen.
382 */
383 STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
wdenk9c53f402003-10-15 23:53:47 +0000384
wdenkf3da7cc2005-05-13 22:49:36 +0000385 . = 0x0900
wdenk9c53f402003-10-15 23:53:47 +0000386/*
387 * r0 - SYSCALL number
388 * r3-... arguments
389 */
390SystemCall:
Andy Flemingf08233c2007-08-14 01:34:21 -0500391 addis r11,r0,0 /* get functions table addr */
392 ori r11,r11,0 /* Note: this code is patched in trap_init */
393 addis r12,r0,0 /* get number of functions */
wdenkf3da7cc2005-05-13 22:49:36 +0000394 ori r12,r12,0
wdenk9c53f402003-10-15 23:53:47 +0000395
Andy Flemingf08233c2007-08-14 01:34:21 -0500396 cmplw 0,r0,r12
wdenkf3da7cc2005-05-13 22:49:36 +0000397 bge 1f
wdenk9c53f402003-10-15 23:53:47 +0000398
Andy Flemingf08233c2007-08-14 01:34:21 -0500399 rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
wdenkf3da7cc2005-05-13 22:49:36 +0000400 add r11,r11,r0
401 lwz r11,0(r11)
wdenk9c53f402003-10-15 23:53:47 +0000402
Andy Flemingf08233c2007-08-14 01:34:21 -0500403 li r20,0xd00-4 /* Get stack pointer */
wdenkf3da7cc2005-05-13 22:49:36 +0000404 lwz r12,0(r20)
Andy Flemingf08233c2007-08-14 01:34:21 -0500405 subi r12,r12,12 /* Adjust stack pointer */
wdenkf3da7cc2005-05-13 22:49:36 +0000406 li r0,0xc00+_end_back-SystemCall
Andy Flemingf08233c2007-08-14 01:34:21 -0500407 cmplw 0,r0,r12 /* Check stack overflow */
wdenkf3da7cc2005-05-13 22:49:36 +0000408 bgt 1f
409 stw r12,0(r20)
wdenk9c53f402003-10-15 23:53:47 +0000410
wdenkf3da7cc2005-05-13 22:49:36 +0000411 mflr r0
412 stw r0,0(r12)
413 mfspr r0,SRR0
414 stw r0,4(r12)
415 mfspr r0,SRR1
416 stw r0,8(r12)
wdenk9c53f402003-10-15 23:53:47 +0000417
wdenkf3da7cc2005-05-13 22:49:36 +0000418 li r12,0xc00+_back-SystemCall
419 mtlr r12
420 mtspr SRR0,r11
wdenk9c53f402003-10-15 23:53:47 +0000421
wdenkf3da7cc2005-05-13 22:49:36 +00004221: SYNC
wdenk9c53f402003-10-15 23:53:47 +0000423 rfi
424_back:
425
wdenkf3da7cc2005-05-13 22:49:36 +0000426 mfmsr r11 /* Disable interrupts */
427 li r12,0
428 ori r12,r12,MSR_EE
429 andc r11,r11,r12
430 SYNC /* Some chip revs need this... */
431 mtmsr r11
wdenk9c53f402003-10-15 23:53:47 +0000432 SYNC
433
wdenkf3da7cc2005-05-13 22:49:36 +0000434 li r12,0xd00-4 /* restore regs */
435 lwz r12,0(r12)
wdenk9c53f402003-10-15 23:53:47 +0000436
wdenkf3da7cc2005-05-13 22:49:36 +0000437 lwz r11,0(r12)
438 mtlr r11
439 lwz r11,4(r12)
440 mtspr SRR0,r11
441 lwz r11,8(r12)
442 mtspr SRR1,r11
wdenk9c53f402003-10-15 23:53:47 +0000443
wdenkf3da7cc2005-05-13 22:49:36 +0000444 addi r12,r12,12 /* Adjust stack pointer */
445 li r20,0xd00-4
446 stw r12,0(r20)
wdenk9c53f402003-10-15 23:53:47 +0000447
448 SYNC
449 rfi
450_end_back:
451
wdenkf3da7cc2005-05-13 22:49:36 +0000452 STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
453 STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
454 STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
wdenk9c53f402003-10-15 23:53:47 +0000455
wdenkf3da7cc2005-05-13 22:49:36 +0000456 STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
457 STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
wdenk9c53f402003-10-15 23:53:47 +0000458
wdenkf3da7cc2005-05-13 22:49:36 +0000459 CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
wdenk9c53f402003-10-15 23:53:47 +0000460
wdenkf3da7cc2005-05-13 22:49:36 +0000461 .globl _end_of_vectors
wdenk9c53f402003-10-15 23:53:47 +0000462_end_of_vectors:
463
464
Andy Flemingf08233c2007-08-14 01:34:21 -0500465 . = . + (0x100 - ( . & 0xff )) /* align for debug */
wdenk9c53f402003-10-15 23:53:47 +0000466
467/*
468 * This code finishes saving the registers to the exception frame
469 * and jumps to the appropriate handler for the exception.
470 * Register r21 is pointer into trap frame, r1 has new stack pointer.
471 */
472 .globl transfer_to_handler
473transfer_to_handler:
474 stw r22,_NIP(r21)
475 lis r22,MSR_POW@h
476 andc r23,r23,r22
477 stw r23,_MSR(r21)
478 SAVE_GPR(7, r21)
479 SAVE_4GPRS(8, r21)
480 SAVE_8GPRS(12, r21)
481 SAVE_8GPRS(24, r21)
482
483 mflr r23
484 andi. r24,r23,0x3f00 /* get vector offset */
485 stw r24,TRAP(r21)
486 li r22,0
487 stw r22,RESULT(r21)
488 mtspr SPRG2,r22 /* r1 is now kernel sp */
489
490 lwz r24,0(r23) /* virtual address of handler */
491 lwz r23,4(r23) /* where to go when done */
492 mtspr SRR0,r24
493 mtspr SRR1,r20
494 mtlr r23
495 SYNC
496 rfi /* jump to handler, enable MMU */
497
498int_return:
499 mfmsr r28 /* Disable interrupts */
500 li r4,0
501 ori r4,r4,MSR_EE
502 andc r28,r28,r4
503 SYNC /* Some chip revs need this... */
504 mtmsr r28
505 SYNC
506 lwz r2,_CTR(r1)
507 lwz r0,_LINK(r1)
508 mtctr r2
509 mtlr r0
510 lwz r2,_XER(r1)
511 lwz r0,_CCR(r1)
512 mtspr XER,r2
513 mtcrf 0xFF,r0
514 REST_10GPRS(3, r1)
515 REST_10GPRS(13, r1)
516 REST_8GPRS(23, r1)
517 REST_GPR(31, r1)
518 lwz r2,_NIP(r1) /* Restore environment */
519 lwz r0,_MSR(r1)
520 mtspr SRR0,r2
521 mtspr SRR1,r0
522 lwz r0,GPR0(r1)
523 lwz r2,GPR2(r1)
524 lwz r1,GPR1(r1)
525 SYNC
526 rfi
527
528crit_return:
529 mfmsr r28 /* Disable interrupts */
530 li r4,0
531 ori r4,r4,MSR_EE
532 andc r28,r28,r4
533 SYNC /* Some chip revs need this... */
534 mtmsr r28
535 SYNC
536 lwz r2,_CTR(r1)
537 lwz r0,_LINK(r1)
538 mtctr r2
539 mtlr r0
540 lwz r2,_XER(r1)
541 lwz r0,_CCR(r1)
542 mtspr XER,r2
543 mtcrf 0xFF,r0
544 REST_10GPRS(3, r1)
545 REST_10GPRS(13, r1)
546 REST_8GPRS(23, r1)
547 REST_GPR(31, r1)
548 lwz r2,_NIP(r1) /* Restore environment */
549 lwz r0,_MSR(r1)
Andy Flemingf08233c2007-08-14 01:34:21 -0500550 mtspr SPRN_CSRR0,r2
551 mtspr SPRN_CSRR1,r0
wdenk9c53f402003-10-15 23:53:47 +0000552 lwz r0,GPR0(r1)
553 lwz r2,GPR2(r1)
554 lwz r1,GPR1(r1)
555 SYNC
556 rfci
557
Andy Flemingf08233c2007-08-14 01:34:21 -0500558mck_return:
559 mfmsr r28 /* Disable interrupts */
560 li r4,0
561 ori r4,r4,MSR_EE
562 andc r28,r28,r4
563 SYNC /* Some chip revs need this... */
564 mtmsr r28
565 SYNC
566 lwz r2,_CTR(r1)
567 lwz r0,_LINK(r1)
568 mtctr r2
569 mtlr r0
570 lwz r2,_XER(r1)
571 lwz r0,_CCR(r1)
572 mtspr XER,r2
573 mtcrf 0xFF,r0
574 REST_10GPRS(3, r1)
575 REST_10GPRS(13, r1)
576 REST_8GPRS(23, r1)
577 REST_GPR(31, r1)
578 lwz r2,_NIP(r1) /* Restore environment */
579 lwz r0,_MSR(r1)
580 mtspr SPRN_MCSRR0,r2
581 mtspr SPRN_MCSRR1,r0
582 lwz r0,GPR0(r1)
583 lwz r2,GPR2(r1)
584 lwz r1,GPR1(r1)
585 SYNC
586 rfmci
587
wdenk9c53f402003-10-15 23:53:47 +0000588/* Cache functions.
589*/
590invalidate_icache:
591 mfspr r0,L1CSR1
Andy Flemingf08233c2007-08-14 01:34:21 -0500592 ori r0,r0,L1CSR1_ICFI
593 msync
594 isync
wdenk9c53f402003-10-15 23:53:47 +0000595 mtspr L1CSR1,r0
596 isync
Andy Flemingf08233c2007-08-14 01:34:21 -0500597 blr /* entire I cache */
wdenk9c53f402003-10-15 23:53:47 +0000598
599invalidate_dcache:
600 mfspr r0,L1CSR0
Andy Flemingf08233c2007-08-14 01:34:21 -0500601 ori r0,r0,L1CSR0_DCFI
wdenk9c53f402003-10-15 23:53:47 +0000602 msync
603 isync
604 mtspr L1CSR0,r0
605 isync
606 blr
607
608 .globl icache_enable
609icache_enable:
610 mflr r8
611 bl invalidate_icache
612 mtlr r8
613 isync
614 mfspr r4,L1CSR1
615 ori r4,r4,0x0001
616 oris r4,r4,0x0001
617 mtspr L1CSR1,r4
618 isync
619 blr
620
621 .globl icache_disable
622icache_disable:
623 mfspr r0,L1CSR1
Andy Flemingf08233c2007-08-14 01:34:21 -0500624 lis r3,0
625 ori r3,r3,L1CSR1_ICE
626 andc r0,r0,r3
wdenk9c53f402003-10-15 23:53:47 +0000627 mtspr L1CSR1,r0
628 isync
629 blr
630
631 .globl icache_status
632icache_status:
633 mfspr r3,L1CSR1
Andy Flemingf08233c2007-08-14 01:34:21 -0500634 andi. r3,r3,L1CSR1_ICE
wdenk9c53f402003-10-15 23:53:47 +0000635 blr
636
637 .globl dcache_enable
638dcache_enable:
639 mflr r8
640 bl invalidate_dcache
641 mtlr r8
642 isync
643 mfspr r0,L1CSR0
644 ori r0,r0,0x0001
645 oris r0,r0,0x0001
646 msync
647 isync
648 mtspr L1CSR0,r0
649 isync
650 blr
651
652 .globl dcache_disable
653dcache_disable:
Andy Flemingf08233c2007-08-14 01:34:21 -0500654 mfspr r3,L1CSR0
655 lis r4,0
656 ori r4,r4,L1CSR0_DCE
657 andc r3,r3,r4
wdenk9c53f402003-10-15 23:53:47 +0000658 mtspr L1CSR0,r0
659 isync
660 blr
661
662 .globl dcache_status
663dcache_status:
664 mfspr r3,L1CSR0
Andy Flemingf08233c2007-08-14 01:34:21 -0500665 andi. r3,r3,L1CSR0_DCE
wdenk9c53f402003-10-15 23:53:47 +0000666 blr
667
668 .globl get_pir
669get_pir:
Andy Flemingf08233c2007-08-14 01:34:21 -0500670 mfspr r3,PIR
wdenk9c53f402003-10-15 23:53:47 +0000671 blr
672
673 .globl get_pvr
674get_pvr:
Andy Flemingf08233c2007-08-14 01:34:21 -0500675 mfspr r3,PVR
wdenk9c53f402003-10-15 23:53:47 +0000676 blr
677
wdenka445ddf2004-06-09 00:34:46 +0000678 .globl get_svr
679get_svr:
Andy Flemingf08233c2007-08-14 01:34:21 -0500680 mfspr r3,SVR
wdenka445ddf2004-06-09 00:34:46 +0000681 blr
682
wdenk9c53f402003-10-15 23:53:47 +0000683 .globl wr_tcr
684wr_tcr:
Andy Flemingf08233c2007-08-14 01:34:21 -0500685 mtspr TCR,r3
wdenk9c53f402003-10-15 23:53:47 +0000686 blr
687
688/*------------------------------------------------------------------------------- */
689/* Function: in8 */
690/* Description: Input 8 bits */
691/*------------------------------------------------------------------------------- */
692 .globl in8
693in8:
694 lbz r3,0x0000(r3)
695 blr
696
697/*------------------------------------------------------------------------------- */
698/* Function: out8 */
699/* Description: Output 8 bits */
700/*------------------------------------------------------------------------------- */
701 .globl out8
702out8:
703 stb r4,0x0000(r3)
Ed Swarthout7d6be302007-09-26 16:35:54 -0500704 sync
wdenk9c53f402003-10-15 23:53:47 +0000705 blr
706
707/*------------------------------------------------------------------------------- */
708/* Function: out16 */
709/* Description: Output 16 bits */
710/*------------------------------------------------------------------------------- */
711 .globl out16
712out16:
713 sth r4,0x0000(r3)
Ed Swarthout7d6be302007-09-26 16:35:54 -0500714 sync
wdenk9c53f402003-10-15 23:53:47 +0000715 blr
716
717/*------------------------------------------------------------------------------- */
718/* Function: out16r */
719/* Description: Byte reverse and output 16 bits */
720/*------------------------------------------------------------------------------- */
721 .globl out16r
722out16r:
723 sthbrx r4,r0,r3
Ed Swarthout7d6be302007-09-26 16:35:54 -0500724 sync
wdenk9c53f402003-10-15 23:53:47 +0000725 blr
726
727/*------------------------------------------------------------------------------- */
728/* Function: out32 */
729/* Description: Output 32 bits */
730/*------------------------------------------------------------------------------- */
731 .globl out32
732out32:
733 stw r4,0x0000(r3)
Ed Swarthout7d6be302007-09-26 16:35:54 -0500734 sync
wdenk9c53f402003-10-15 23:53:47 +0000735 blr
736
737/*------------------------------------------------------------------------------- */
738/* Function: out32r */
739/* Description: Byte reverse and output 32 bits */
740/*------------------------------------------------------------------------------- */
741 .globl out32r
742out32r:
743 stwbrx r4,r0,r3
Ed Swarthout7d6be302007-09-26 16:35:54 -0500744 sync
wdenk9c53f402003-10-15 23:53:47 +0000745 blr
746
747/*------------------------------------------------------------------------------- */
748/* Function: in16 */
749/* Description: Input 16 bits */
750/*------------------------------------------------------------------------------- */
751 .globl in16
752in16:
753 lhz r3,0x0000(r3)
754 blr
755
756/*------------------------------------------------------------------------------- */
757/* Function: in16r */
758/* Description: Input 16 bits and byte reverse */
759/*------------------------------------------------------------------------------- */
760 .globl in16r
761in16r:
762 lhbrx r3,r0,r3
763 blr
764
765/*------------------------------------------------------------------------------- */
766/* Function: in32 */
767/* Description: Input 32 bits */
768/*------------------------------------------------------------------------------- */
769 .globl in32
770in32:
771 lwz 3,0x0000(3)
772 blr
773
774/*------------------------------------------------------------------------------- */
775/* Function: in32r */
776/* Description: Input 32 bits and byte reverse */
777/*------------------------------------------------------------------------------- */
778 .globl in32r
779in32r:
780 lwbrx r3,r0,r3
781 blr
782
783/*------------------------------------------------------------------------------- */
784/* Function: ppcDcbf */
785/* Description: Data Cache block flush */
786/* Input: r3 = effective address */
787/* Output: none. */
788/*------------------------------------------------------------------------------- */
789 .globl ppcDcbf
790ppcDcbf:
791 dcbf r0,r3
792 blr
793
794/*------------------------------------------------------------------------------- */
795/* Function: ppcDcbi */
796/* Description: Data Cache block Invalidate */
797/* Input: r3 = effective address */
798/* Output: none. */
799/*------------------------------------------------------------------------------- */
800 .globl ppcDcbi
801ppcDcbi:
802 dcbi r0,r3
803 blr
804
wdenk13eb2212004-07-09 23:27:13 +0000805/*--------------------------------------------------------------------------
806 * Function: ppcDcbz
807 * Description: Data Cache block zero.
808 * Input: r3 = effective address
809 * Output: none.
810 *-------------------------------------------------------------------------- */
811
812 .globl ppcDcbz
813ppcDcbz:
814 dcbz r0,r3
815 blr
816
wdenk9c53f402003-10-15 23:53:47 +0000817/*------------------------------------------------------------------------------- */
818/* Function: ppcSync */
819/* Description: Processor Synchronize */
820/* Input: none. */
821/* Output: none. */
822/*------------------------------------------------------------------------------- */
823 .globl ppcSync
824ppcSync:
825 sync
826 blr
827
828/*------------------------------------------------------------------------------*/
829
830/*
831 * void relocate_code (addr_sp, gd, addr_moni)
832 *
833 * This "function" does not return, instead it continues in RAM
834 * after relocating the monitor code.
835 *
836 * r3 = dest
837 * r4 = src
838 * r5 = length in bytes
839 * r6 = cachelinesize
840 */
841 .globl relocate_code
842relocate_code:
Andy Flemingf08233c2007-08-14 01:34:21 -0500843 mr r1,r3 /* Set new stack pointer */
844 mr r9,r4 /* Save copy of Init Data pointer */
845 mr r10,r5 /* Save copy of Destination Address */
wdenk9c53f402003-10-15 23:53:47 +0000846
Andy Flemingf08233c2007-08-14 01:34:21 -0500847 mr r3,r5 /* Destination Address */
848 lis r4,CFG_MONITOR_BASE@h /* Source Address */
849 ori r4,r4,CFG_MONITOR_BASE@l
wdenk9c53f402003-10-15 23:53:47 +0000850 lwz r5,GOT(__init_end)
851 sub r5,r5,r4
Andy Flemingf08233c2007-08-14 01:34:21 -0500852 li r6,CFG_CACHELINE_SIZE /* Cache Line Size */
wdenk9c53f402003-10-15 23:53:47 +0000853
854 /*
855 * Fix GOT pointer:
856 *
857 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
858 *
859 * Offset:
860 */
Andy Flemingf08233c2007-08-14 01:34:21 -0500861 sub r15,r10,r4
wdenk9c53f402003-10-15 23:53:47 +0000862
863 /* First our own GOT */
Andy Flemingf08233c2007-08-14 01:34:21 -0500864 add r14,r14,r15
wdenk9c53f402003-10-15 23:53:47 +0000865 /* the the one used by the C code */
Andy Flemingf08233c2007-08-14 01:34:21 -0500866 add r30,r30,r15
wdenk9c53f402003-10-15 23:53:47 +0000867
868 /*
869 * Now relocate code
870 */
871
872 cmplw cr1,r3,r4
873 addi r0,r5,3
874 srwi. r0,r0,2
875 beq cr1,4f /* In place copy is not necessary */
876 beq 7f /* Protect against 0 count */
877 mtctr r0
878 bge cr1,2f
879
880 la r8,-4(r4)
881 la r7,-4(r3)
8821: lwzu r0,4(r8)
883 stwu r0,4(r7)
884 bdnz 1b
885 b 4f
886
8872: slwi r0,r0,2
888 add r8,r4,r0
889 add r7,r3,r0
8903: lwzu r0,-4(r8)
891 stwu r0,-4(r7)
892 bdnz 3b
893
894/*
895 * Now flush the cache: note that we must start from a cache aligned
896 * address. Otherwise we might miss one cache line.
897 */
8984: cmpwi r6,0
899 add r5,r3,r5
900 beq 7f /* Always flush prefetch queue in any case */
901 subi r0,r6,1
902 andc r3,r3,r0
903 mr r4,r3
9045: dcbst 0,r4
905 add r4,r4,r6
906 cmplw r4,r5
907 blt 5b
908 sync /* Wait for all dcbst to complete on bus */
909 mr r4,r3
9106: icbi 0,r4
911 add r4,r4,r6
912 cmplw r4,r5
913 blt 6b
9147: sync /* Wait for all icbi to complete on bus */
915 isync
916
Wolfgang Denk29dcbd42005-10-05 00:00:54 +0200917 /*
918 * Re-point the IVPR at RAM
919 */
920 mtspr IVPR,r10
Wolfgang Denk9da240c2005-10-05 00:19:34 +0200921
wdenk9c53f402003-10-15 23:53:47 +0000922/*
923 * We are done. Do not return, instead branch to second part of board
924 * initialization, now running from RAM.
925 */
926
Andy Flemingf08233c2007-08-14 01:34:21 -0500927 addi r0,r10,in_ram - _start + _START_OFFSET
wdenk9c53f402003-10-15 23:53:47 +0000928 mtlr r0
929 blr /* NEVER RETURNS! */
Andy Flemingf08233c2007-08-14 01:34:21 -0500930 .globl in_ram
wdenk9c53f402003-10-15 23:53:47 +0000931in_ram:
932
933 /*
934 * Relocation Function, r14 point to got2+0x8000
935 *
936 * Adjust got2 pointers, no need to check for 0, this code
937 * already puts a few entries in the table.
938 */
939 li r0,__got2_entries@sectoff@l
940 la r3,GOT(_GOT2_TABLE_)
941 lwz r11,GOT(_GOT2_TABLE_)
942 mtctr r0
943 sub r11,r3,r11
944 addi r3,r3,-4
9451: lwzu r0,4(r3)
946 add r0,r0,r11
947 stw r0,0(r3)
948 bdnz 1b
949
950 /*
951 * Now adjust the fixups and the pointers to the fixups
952 * in case we need to move ourselves again.
953 */
9542: li r0,__fixup_entries@sectoff@l
955 lwz r3,GOT(_FIXUP_TABLE_)
956 cmpwi r0,0
957 mtctr r0
958 addi r3,r3,-4
959 beq 4f
9603: lwzu r4,4(r3)
961 lwzux r0,r4,r11
962 add r0,r0,r11
963 stw r10,0(r3)
964 stw r0,0(r4)
965 bdnz 3b
9664:
967clear_bss:
968 /*
969 * Now clear BSS segment
970 */
971 lwz r3,GOT(__bss_start)
972 lwz r4,GOT(_end)
973
Andy Flemingf08233c2007-08-14 01:34:21 -0500974 cmplw 0,r3,r4
wdenk9c53f402003-10-15 23:53:47 +0000975 beq 6f
976
Andy Flemingf08233c2007-08-14 01:34:21 -0500977 li r0,0
wdenk9c53f402003-10-15 23:53:47 +00009785:
Andy Flemingf08233c2007-08-14 01:34:21 -0500979 stw r0,0(r3)
980 addi r3,r3,4
981 cmplw 0,r3,r4
wdenk9c53f402003-10-15 23:53:47 +0000982 bne 5b
9836:
984
Andy Flemingf08233c2007-08-14 01:34:21 -0500985 mr r3,r9 /* Init Data pointer */
986 mr r4,r10 /* Destination Address */
wdenk9c53f402003-10-15 23:53:47 +0000987 bl board_init_r
988
989 /*
990 * Copy exception vector code to low memory
991 *
992 * r3: dest_addr
993 * r7: source address, r8: end address, r9: target address
994 */
wdenkf3da7cc2005-05-13 22:49:36 +0000995 .globl trap_init
wdenk9c53f402003-10-15 23:53:47 +0000996trap_init:
Andy Flemingf08233c2007-08-14 01:34:21 -0500997 lwz r7,GOT(_start_of_vectors)
998 lwz r8,GOT(_end_of_vectors)
wdenk9c53f402003-10-15 23:53:47 +0000999
Andy Flemingf08233c2007-08-14 01:34:21 -05001000 li r9,0x100 /* reset vector always at 0x100 */
wdenk9c53f402003-10-15 23:53:47 +00001001
Andy Flemingf08233c2007-08-14 01:34:21 -05001002 cmplw 0,r7,r8
wdenkf3da7cc2005-05-13 22:49:36 +00001003 bgelr /* return if r7>=r8 - just in case */
wdenk9c53f402003-10-15 23:53:47 +00001004
wdenkf3da7cc2005-05-13 22:49:36 +00001005 mflr r4 /* save link register */
wdenk9c53f402003-10-15 23:53:47 +000010061:
Andy Flemingf08233c2007-08-14 01:34:21 -05001007 lwz r0,0(r7)
1008 stw r0,0(r9)
1009 addi r7,r7,4
1010 addi r9,r9,4
1011 cmplw 0,r7,r8
wdenkf3da7cc2005-05-13 22:49:36 +00001012 bne 1b
wdenk9c53f402003-10-15 23:53:47 +00001013
1014 /*
1015 * relocate `hdlr' and `int_return' entries
1016 */
Andy Flemingf08233c2007-08-14 01:34:21 -05001017 li r7,.L_CriticalInput - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001018 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001019 li r7,.L_MachineCheck - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001020 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001021 li r7,.L_DataStorage - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001022 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001023 li r7,.L_InstStorage - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001024 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001025 li r7,.L_ExtInterrupt - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001026 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001027 li r7,.L_Alignment - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001028 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001029 li r7,.L_ProgramCheck - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001030 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001031 li r7,.L_FPUnavailable - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001032 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001033 li r7,.L_Decrementer - _start + _START_OFFSET
1034 bl trap_reloc
1035 li r7,.L_IntervalTimer - _start + _START_OFFSET
1036 li r8,_end_of_vectors - _start + _START_OFFSET
wdenk9c53f402003-10-15 23:53:47 +000010372:
wdenkf3da7cc2005-05-13 22:49:36 +00001038 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001039 addi r7,r7,0x100 /* next exception vector */
1040 cmplw 0,r7,r8
wdenkf3da7cc2005-05-13 22:49:36 +00001041 blt 2b
wdenk9c53f402003-10-15 23:53:47 +00001042
wdenkf3da7cc2005-05-13 22:49:36 +00001043 lis r7,0x0
Andy Flemingf08233c2007-08-14 01:34:21 -05001044 mtspr IVPR,r7
wdenk9c53f402003-10-15 23:53:47 +00001045
wdenkf3da7cc2005-05-13 22:49:36 +00001046 mtlr r4 /* restore link register */
wdenk9c53f402003-10-15 23:53:47 +00001047 blr
1048
1049 /*
1050 * Function: relocate entries for one exception vector
1051 */
1052trap_reloc:
Andy Flemingf08233c2007-08-14 01:34:21 -05001053 lwz r0,0(r7) /* hdlr ... */
1054 add r0,r0,r3 /* ... += dest_addr */
1055 stw r0,0(r7)
wdenk9c53f402003-10-15 23:53:47 +00001056
Andy Flemingf08233c2007-08-14 01:34:21 -05001057 lwz r0,4(r7) /* int_return ... */
1058 add r0,r0,r3 /* ... += dest_addr */
1059 stw r0,4(r7)
wdenk9c53f402003-10-15 23:53:47 +00001060
1061 blr
1062
1063#ifdef CFG_INIT_RAM_LOCK
1064.globl unlock_ram_in_cache
1065unlock_ram_in_cache:
1066 /* invalidate the INIT_RAM section */
Andy Flemingf08233c2007-08-14 01:34:21 -05001067 lis r3,(CFG_INIT_RAM_ADDR & ~31)@h
1068 ori r3,r3,(CFG_INIT_RAM_ADDR & ~31)@l
Kumar Gala91510e02007-10-02 11:12:27 -05001069 li r4,(CFG_DCACHE_SIZE / (2 * CFG_CACHELINE_SIZE))
Andy Flemingf08233c2007-08-14 01:34:21 -05001070 mtctr r4
10711: icbi r0,r3
1072 dcbi r0,r3
Kumar Gala91510e02007-10-02 11:12:27 -05001073 addi r3,r3,CFG_CACHELINE_SIZE
wdenk9c53f402003-10-15 23:53:47 +00001074 bdnz 1b
wdenkf3da7cc2005-05-13 22:49:36 +00001075 sync /* Wait for all icbi to complete on bus */
wdenk9c53f402003-10-15 23:53:47 +00001076 isync
1077 blr
1078#endif