blob: ada6ea505fbf12f297023bae71772bf448aab0fe [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
Andy Fleming61a21e92007-08-14 01:34:21 -05002 * Copyright 2004, 2007 Freescale Semiconductor.
wdenk42d1f032003-10-15 23:53:47 +00003 * Copyright (C) 2003 Motorola,Inc.
wdenk42d1f032003-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 Fleming61a21e92007-08-14 01:34:21 -050048#define MSR_KERNEL ( MSR_ME ) /* Machine Check */
wdenk42d1f032003-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 Fleming61a21e92007-08-14 01:34:21 -050082 .section .bootpg,"ax"
83 .globl _start_e500
wdenk42d1f032003-10-15 23:53:47 +000084
85_start_e500:
wdenk97d80fc2004-06-09 00:34:46 +000086
Andy Fleming61a21e92007-08-14 01:34:21 -050087/* clear registers/arrays not reset by hardware */
wdenk42d1f032003-10-15 23:53:47 +000088
Andy Fleming61a21e92007-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 */
wdenk42d1f032003-10-15 23:53:47 +000093
94 mfspr r1,DBSR
95 mtspr DBSR,r1 /* Clear all valid bits */
96
Andy Fleming61a21e92007-08-14 01:34:21 -050097 /*
98 * Enable L1 Caches early
99 *
100 */
wdenk42d1f032003-10-15 23:53:47 +0000101
Andy Fleming61a21e92007-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 */
wdenk42d1f032003-10-15 23:53:47 +0000105 isync
Andy Fleming61a21e92007-08-14 01:34:21 -0500106 mtspr L1CSR1,r2 /* enable L1 Icache */
107 isync
108 msync
wdenk42d1f032003-10-15 23:53:47 +0000109
110 /* Setup interrupt vectors */
wdenk343117b2005-05-13 22:49:36 +0000111 lis r1,TEXT_BASE@h
Andy Fleming61a21e92007-08-14 01:34:21 -0500112 mtspr IVPR,r1
wdenk42d1f032003-10-15 23:53:47 +0000113
wdenk343117b2005-05-13 22:49:36 +0000114 li r1,0x0100
wdenk42d1f032003-10-15 23:53:47 +0000115 mtspr IVOR0,r1 /* 0: Critical input */
wdenk343117b2005-05-13 22:49:36 +0000116 li r1,0x0200
wdenk42d1f032003-10-15 23:53:47 +0000117 mtspr IVOR1,r1 /* 1: Machine check */
wdenk343117b2005-05-13 22:49:36 +0000118 li r1,0x0300
wdenk42d1f032003-10-15 23:53:47 +0000119 mtspr IVOR2,r1 /* 2: Data storage */
wdenk343117b2005-05-13 22:49:36 +0000120 li r1,0x0400
wdenk42d1f032003-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 */
wdenk343117b2005-05-13 22:49:36 +0000130 li r1,0x0900
wdenk42d1f032003-10-15 23:53:47 +0000131 mtspr IVOR8,r1 /* 8: System call */
132 /* 9: Auxiliary processor unavailable(unsupported) */
wdenk343117b2005-05-13 22:49:36 +0000133 li r1,0x0a00
wdenk42d1f032003-10-15 23:53:47 +0000134 mtspr IVOR10,r1 /* 10: Decrementer */
wdenk343117b2005-05-13 22:49:36 +0000135 li r1,0x0b00
136 mtspr IVOR11,r1 /* 11: Interval timer */
137 li r1,0x0c00
Wolfgang Denk3e0bc442005-08-04 01:24:19 +0200138 mtspr IVOR12,r1 /* 12: Watchdog timer */
139 li r1,0x0d00
wdenk42d1f032003-10-15 23:53:47 +0000140 mtspr IVOR13,r1 /* 13: Data TLB error */
wdenk343117b2005-05-13 22:49:36 +0000141 li r1,0x0e00
wdenk42d1f032003-10-15 23:53:47 +0000142 mtspr IVOR14,r1 /* 14: Instruction TLB error */
wdenk343117b2005-05-13 22:49:36 +0000143 li r1,0x0f00
wdenk42d1f032003-10-15 23:53:47 +0000144 mtspr IVOR15,r1 /* 15: Debug */
145
wdenk9aea9532004-08-01 23:02:45 +0000146
147 /*
148 * After reset, CCSRBAR is located at CFG_CCSRBAR_DEFAULT, i.e.
wdenk42d1f032003-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 */
wdenk343117b2005-05-13 22:49:36 +0000158 bl tlb1_entry
wdenk42d1f032003-10-15 23:53:47 +0000159 mr r5,r0
wdenk42d1f032003-10-15 23:53:47 +0000160 lwzu r4,0(r5) /* how many TLB1 entries we actually use */
Zang Roy-r6191163247a52006-12-20 11:01:00 +0800161 mtctr r4
wdenk42d1f032003-10-15 23:53:47 +0000162
Andy Fleming61a21e92007-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
wdenk42d1f032003-10-15 23:53:47 +0000171 isync
172 msync
173 tlbwe
174 isync
wdenk42d1f032003-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 Fleming61a21e92007-08-14 01:34:21 -0500180 lis r4,CFG_CCSRBAR_DEFAULT@h
181 ori r4,r4,CFG_CCSRBAR_DEFAULT@l
wdenk42d1f032003-10-15 23:53:47 +0000182
Andy Fleming61a21e92007-08-14 01:34:21 -0500183 lis r5,CFG_CCSRBAR@h
184 ori r5,r5,CFG_CCSRBAR@l
wdenk42d1f032003-10-15 23:53:47 +0000185 srwi r6,r5,12
Andy Fleming61a21e92007-08-14 01:34:21 -0500186 stw r6,0(r4)
wdenk42d1f032003-10-15 23:53:47 +0000187 isync
188
Andy Fleming61a21e92007-08-14 01:34:21 -0500189 lis r5,0xffff
wdenk42d1f032003-10-15 23:53:47 +0000190 ori r5,r5,0xf000
Andy Fleming61a21e92007-08-14 01:34:21 -0500191 lwz r5,0(r5)
wdenk42d1f032003-10-15 23:53:47 +0000192 isync
193
Andy Fleming61a21e92007-08-14 01:34:21 -0500194 lis r3,CFG_CCSRBAR@h
195 lwz r5,CFG_CCSRBAR@l(r3)
wdenk42d1f032003-10-15 23:53:47 +0000196 isync
197#endif
198
wdenk42d1f032003-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
wdenk343117b2005-05-13 22:49:36 +0000204 bl law_entry
wdenk42d1f032003-10-15 23:53:47 +0000205 mr r6,r0
wdenk42d1f032003-10-15 23:53:47 +0000206 lwzu r5,0(r6) /* how many windows we actually use */
Zang Roy-r6191163247a52006-12-20 11:01:00 +0800207 mtctr r5
wdenk42d1f032003-10-15 23:53:47 +0000208
Andy Fleming61a21e92007-08-14 01:34:21 -0500209 li r2,0x0c28 /* the first pair is reserved for */
210 li r1,0x0c30 /* boot-over-rio-or-pci */
wdenk42d1f032003-10-15 23:53:47 +0000211
Zang Roy-r6191163247a52006-12-20 11:01:00 +08002120: lwzu r4,4(r6)
wdenk42d1f032003-10-15 23:53:47 +0000213 lwzu r3,4(r6)
214 stwx r4,r7,r2
215 stwx r3,r7,r1
wdenk42d1f032003-10-15 23:53:47 +0000216 addi r2,r2,0x0020
217 addi r1,r1,0x0020
218 bdnz 0b
219
wdenk42d1f032003-10-15 23:53:47 +0000220 /* Clear and set up some registers. */
urwithsughosh@gmail.com1e701e72007-09-24 13:36:01 -0400221 li r0,0
222 mtmsr r0
wdenk42d1f032003-10-15 23:53:47 +0000223 li r0,0x0000
224 lis r1,0xffff
225 mtspr DEC,r0 /* prevent dec exceptions */
226 mttbl r0 /* prevent fit & wdt exceptions */
227 mttbu r0
228 mtspr TSR,r1 /* clear all timer exception status */
229 mtspr TCR,r0 /* disable all */
230 mtspr ESR,r0 /* clear exception syndrome register */
231 mtspr MCSR,r0 /* machine check syndrome register */
232 mtxer r0 /* clear integer exception register */
233 lis r1,0x0002 /* set CE bit (Critical Exceptions) */
234 ori r1,r1,0x1200 /* set ME/DE bit */
235 mtmsr r1 /* change MSR */
236 isync
237
238 /* Enable Time Base and Select Time Base Clock */
wdenk0ac6f8b2004-07-09 23:27:13 +0000239 lis r0,HID0_EMCP@h /* Enable machine check */
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500240#if defined(CONFIG_ENABLE_36BIT_PHYS)
Andy Fleming61a21e92007-08-14 01:34:21 -0500241 ori r0,r0,(HID0_TBEN|HID0_ENMAS7)@l /* Enable Timebase & MAS7 */
242#else
243 ori r0,r0,HID0_TBEN@l /* enable Timebase */
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500244#endif
wdenk42d1f032003-10-15 23:53:47 +0000245 mtspr HID0,r0
wdenk42d1f032003-10-15 23:53:47 +0000246
Andy Fleming61a21e92007-08-14 01:34:21 -0500247 li r0,(HID1_ASTME|HID1_ABE)@l /* Addr streaming & broadcast */
wdenk42d1f032003-10-15 23:53:47 +0000248 mtspr HID1,r0
wdenk42d1f032003-10-15 23:53:47 +0000249
250 /* Enable Branch Prediction */
251#if defined(CONFIG_BTB)
252 li r0,0x201 /* BBFI = 1, BPEN = 1 */
253 mtspr BUCSR,r0
wdenk42d1f032003-10-15 23:53:47 +0000254#endif
255
256#if defined(CFG_INIT_DBCR)
257 lis r1,0xffff
258 ori r1,r1,0xffff
wdenk0ac6f8b2004-07-09 23:27:13 +0000259 mtspr DBSR,r1 /* Clear all status bits */
wdenk42d1f032003-10-15 23:53:47 +0000260 lis r0,CFG_INIT_DBCR@h /* DBCR0[IDM] must be set */
261 ori r0,r0,CFG_INIT_DBCR@l
wdenk0ac6f8b2004-07-09 23:27:13 +0000262 mtspr DBCR0,r0
wdenk42d1f032003-10-15 23:53:47 +0000263#endif
264
Andy Fleming61a21e92007-08-14 01:34:21 -0500265/* L1 DCache is used for initial RAM */
266
wdenk42d1f032003-10-15 23:53:47 +0000267 /* Allocate Initial RAM in data cache.
268 */
Andy Fleming61a21e92007-08-14 01:34:21 -0500269 lis r3,CFG_INIT_RAM_ADDR@h
270 ori r3,r3,CFG_INIT_RAM_ADDR@l
Kumar Galae1ce3cb2007-10-02 11:12:27 -0500271 li r2,(CFG_DCACHE_SIZE / (2 * CFG_CACHELINE_SIZE))
wdenk343117b2005-05-13 22:49:36 +0000272 mtctr r2
Andy Fleming61a21e92007-08-14 01:34:21 -0500273 li r0,0
wdenk42d1f032003-10-15 23:53:47 +00002741:
Andy Fleming61a21e92007-08-14 01:34:21 -0500275 dcbz r0,r3
276 dcbtls 0,r0,r3
Kumar Galae1ce3cb2007-10-02 11:12:27 -0500277 addi r3,r3,CFG_CACHELINE_SIZE
wdenk343117b2005-05-13 22:49:36 +0000278 bdnz 1b
wdenk42d1f032003-10-15 23:53:47 +0000279
Kumar Gala3db0bef2007-08-07 18:07:27 -0500280 /* Jump out the last 4K page and continue to 'normal' start */
281#ifdef CFG_RAMBOOT
Kumar Gala3db0bef2007-08-07 18:07:27 -0500282 b _start_cont
283#else
wdenk343117b2005-05-13 22:49:36 +0000284 /* Calculate absolute address in FLASH and jump there */
wdenk42d1f032003-10-15 23:53:47 +0000285 /*--------------------------------------------------------------*/
Andy Fleming61a21e92007-08-14 01:34:21 -0500286 lis r3,CFG_MONITOR_BASE@h
287 ori r3,r3,CFG_MONITOR_BASE@l
Kumar Gala3db0bef2007-08-07 18:07:27 -0500288 addi r3,r3,_start_cont - _start + _START_OFFSET
wdenk343117b2005-05-13 22:49:36 +0000289 mtlr r3
urwithsughosh@gmail.com1e701e72007-09-24 13:36:01 -0400290 blr
Kumar Gala3db0bef2007-08-07 18:07:27 -0500291#endif
wdenk42d1f032003-10-15 23:53:47 +0000292
Kumar Gala3db0bef2007-08-07 18:07:27 -0500293 .text
294 .globl _start
295_start:
296 .long 0x27051956 /* U-BOOT Magic Number */
297 .globl version_string
298version_string:
299 .ascii U_BOOT_VERSION
300 .ascii " (", __DATE__, " - ", __TIME__, ")"
301 .ascii CONFIG_IDENT_STRING, "\0"
302
303 .align 4
304 .globl _start_cont
305_start_cont:
wdenk42d1f032003-10-15 23:53:47 +0000306 /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
307 lis r1,CFG_INIT_RAM_ADDR@h
308 ori r1,r1,CFG_INIT_SP_OFFSET@l
309
310 li r0,0
311 stwu r0,-4(r1)
312 stwu r0,-4(r1) /* Terminate call chain */
313
314 stwu r1,-8(r1) /* Save back chain and move SP */
315 lis r0,RESET_VECTOR@h /* Address of reset vector */
Andy Fleming61a21e92007-08-14 01:34:21 -0500316 ori r0,r0,RESET_VECTOR@l
wdenk42d1f032003-10-15 23:53:47 +0000317 stwu r1,-8(r1) /* Save back chain and move SP */
318 stw r0,+12(r1) /* Save return addr (underflow vect) */
319
320 GET_GOT
321 bl cpu_init_f
wdenk42d1f032003-10-15 23:53:47 +0000322 bl board_init_f
wdenk0ac6f8b2004-07-09 23:27:13 +0000323 isync
wdenk42d1f032003-10-15 23:53:47 +0000324
Andy Fleming61a21e92007-08-14 01:34:21 -0500325 . = EXC_OFF_SYS_RESET
wdenk42d1f032003-10-15 23:53:47 +0000326 .globl _start_of_vectors
327_start_of_vectors:
Andy Fleming61a21e92007-08-14 01:34:21 -0500328
wdenk42d1f032003-10-15 23:53:47 +0000329/* Critical input. */
Andy Fleming61a21e92007-08-14 01:34:21 -0500330 CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException)
331
332/* Machine check */
333 MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
wdenk42d1f032003-10-15 23:53:47 +0000334
335/* Data Storage exception. */
336 STD_EXCEPTION(0x0300, DataStorage, UnknownException)
337
338/* Instruction Storage exception. */
339 STD_EXCEPTION(0x0400, InstStorage, UnknownException)
340
341/* External Interrupt exception. */
Andy Fleming61a21e92007-08-14 01:34:21 -0500342 STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException)
wdenk42d1f032003-10-15 23:53:47 +0000343
344/* Alignment exception. */
345 . = 0x0600
346Alignment:
Rafal Jaworowski02032e82007-06-22 14:58:04 +0200347 EXCEPTION_PROLOG(SRR0, SRR1)
wdenk42d1f032003-10-15 23:53:47 +0000348 mfspr r4,DAR
349 stw r4,_DAR(r21)
350 mfspr r5,DSISR
351 stw r5,_DSISR(r21)
352 addi r3,r1,STACK_FRAME_OVERHEAD
353 li r20,MSR_KERNEL
354 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
355 lwz r6,GOT(transfer_to_handler)
356 mtlr r6
357 blrl
358.L_Alignment:
Andy Fleming61a21e92007-08-14 01:34:21 -0500359 .long AlignmentException - _start + _START_OFFSET
360 .long int_return - _start + _START_OFFSET
wdenk42d1f032003-10-15 23:53:47 +0000361
362/* Program check exception */
363 . = 0x0700
364ProgramCheck:
Rafal Jaworowski02032e82007-06-22 14:58:04 +0200365 EXCEPTION_PROLOG(SRR0, SRR1)
wdenk42d1f032003-10-15 23:53:47 +0000366 addi r3,r1,STACK_FRAME_OVERHEAD
367 li r20,MSR_KERNEL
368 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
369 lwz r6,GOT(transfer_to_handler)
370 mtlr r6
371 blrl
372.L_ProgramCheck:
Andy Fleming61a21e92007-08-14 01:34:21 -0500373 .long ProgramCheckException - _start + _START_OFFSET
374 .long int_return - _start + _START_OFFSET
wdenk42d1f032003-10-15 23:53:47 +0000375
376 /* No FPU on MPC85xx. This exception is not supposed to happen.
377 */
378 STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
wdenk42d1f032003-10-15 23:53:47 +0000379
wdenk343117b2005-05-13 22:49:36 +0000380 . = 0x0900
wdenk42d1f032003-10-15 23:53:47 +0000381/*
382 * r0 - SYSCALL number
383 * r3-... arguments
384 */
385SystemCall:
Andy Fleming61a21e92007-08-14 01:34:21 -0500386 addis r11,r0,0 /* get functions table addr */
387 ori r11,r11,0 /* Note: this code is patched in trap_init */
388 addis r12,r0,0 /* get number of functions */
wdenk343117b2005-05-13 22:49:36 +0000389 ori r12,r12,0
wdenk42d1f032003-10-15 23:53:47 +0000390
Andy Fleming61a21e92007-08-14 01:34:21 -0500391 cmplw 0,r0,r12
wdenk343117b2005-05-13 22:49:36 +0000392 bge 1f
wdenk42d1f032003-10-15 23:53:47 +0000393
Andy Fleming61a21e92007-08-14 01:34:21 -0500394 rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
wdenk343117b2005-05-13 22:49:36 +0000395 add r11,r11,r0
396 lwz r11,0(r11)
wdenk42d1f032003-10-15 23:53:47 +0000397
Andy Fleming61a21e92007-08-14 01:34:21 -0500398 li r20,0xd00-4 /* Get stack pointer */
wdenk343117b2005-05-13 22:49:36 +0000399 lwz r12,0(r20)
Andy Fleming61a21e92007-08-14 01:34:21 -0500400 subi r12,r12,12 /* Adjust stack pointer */
wdenk343117b2005-05-13 22:49:36 +0000401 li r0,0xc00+_end_back-SystemCall
Andy Fleming61a21e92007-08-14 01:34:21 -0500402 cmplw 0,r0,r12 /* Check stack overflow */
wdenk343117b2005-05-13 22:49:36 +0000403 bgt 1f
404 stw r12,0(r20)
wdenk42d1f032003-10-15 23:53:47 +0000405
wdenk343117b2005-05-13 22:49:36 +0000406 mflr r0
407 stw r0,0(r12)
408 mfspr r0,SRR0
409 stw r0,4(r12)
410 mfspr r0,SRR1
411 stw r0,8(r12)
wdenk42d1f032003-10-15 23:53:47 +0000412
wdenk343117b2005-05-13 22:49:36 +0000413 li r12,0xc00+_back-SystemCall
414 mtlr r12
415 mtspr SRR0,r11
wdenk42d1f032003-10-15 23:53:47 +0000416
wdenk343117b2005-05-13 22:49:36 +00004171: SYNC
wdenk42d1f032003-10-15 23:53:47 +0000418 rfi
419_back:
420
wdenk343117b2005-05-13 22:49:36 +0000421 mfmsr r11 /* Disable interrupts */
422 li r12,0
423 ori r12,r12,MSR_EE
424 andc r11,r11,r12
425 SYNC /* Some chip revs need this... */
426 mtmsr r11
wdenk42d1f032003-10-15 23:53:47 +0000427 SYNC
428
wdenk343117b2005-05-13 22:49:36 +0000429 li r12,0xd00-4 /* restore regs */
430 lwz r12,0(r12)
wdenk42d1f032003-10-15 23:53:47 +0000431
wdenk343117b2005-05-13 22:49:36 +0000432 lwz r11,0(r12)
433 mtlr r11
434 lwz r11,4(r12)
435 mtspr SRR0,r11
436 lwz r11,8(r12)
437 mtspr SRR1,r11
wdenk42d1f032003-10-15 23:53:47 +0000438
wdenk343117b2005-05-13 22:49:36 +0000439 addi r12,r12,12 /* Adjust stack pointer */
440 li r20,0xd00-4
441 stw r12,0(r20)
wdenk42d1f032003-10-15 23:53:47 +0000442
443 SYNC
444 rfi
445_end_back:
446
wdenk343117b2005-05-13 22:49:36 +0000447 STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
448 STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
449 STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
wdenk42d1f032003-10-15 23:53:47 +0000450
wdenk343117b2005-05-13 22:49:36 +0000451 STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
452 STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
wdenk42d1f032003-10-15 23:53:47 +0000453
wdenk343117b2005-05-13 22:49:36 +0000454 CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
wdenk42d1f032003-10-15 23:53:47 +0000455
wdenk343117b2005-05-13 22:49:36 +0000456 .globl _end_of_vectors
wdenk42d1f032003-10-15 23:53:47 +0000457_end_of_vectors:
458
459
Andy Fleming61a21e92007-08-14 01:34:21 -0500460 . = . + (0x100 - ( . & 0xff )) /* align for debug */
wdenk42d1f032003-10-15 23:53:47 +0000461
462/*
463 * This code finishes saving the registers to the exception frame
464 * and jumps to the appropriate handler for the exception.
465 * Register r21 is pointer into trap frame, r1 has new stack pointer.
466 */
467 .globl transfer_to_handler
468transfer_to_handler:
469 stw r22,_NIP(r21)
470 lis r22,MSR_POW@h
471 andc r23,r23,r22
472 stw r23,_MSR(r21)
473 SAVE_GPR(7, r21)
474 SAVE_4GPRS(8, r21)
475 SAVE_8GPRS(12, r21)
476 SAVE_8GPRS(24, r21)
477
478 mflr r23
479 andi. r24,r23,0x3f00 /* get vector offset */
480 stw r24,TRAP(r21)
481 li r22,0
482 stw r22,RESULT(r21)
483 mtspr SPRG2,r22 /* r1 is now kernel sp */
484
485 lwz r24,0(r23) /* virtual address of handler */
486 lwz r23,4(r23) /* where to go when done */
487 mtspr SRR0,r24
488 mtspr SRR1,r20
489 mtlr r23
490 SYNC
491 rfi /* jump to handler, enable MMU */
492
493int_return:
494 mfmsr r28 /* Disable interrupts */
495 li r4,0
496 ori r4,r4,MSR_EE
497 andc r28,r28,r4
498 SYNC /* Some chip revs need this... */
499 mtmsr r28
500 SYNC
501 lwz r2,_CTR(r1)
502 lwz r0,_LINK(r1)
503 mtctr r2
504 mtlr r0
505 lwz r2,_XER(r1)
506 lwz r0,_CCR(r1)
507 mtspr XER,r2
508 mtcrf 0xFF,r0
509 REST_10GPRS(3, r1)
510 REST_10GPRS(13, r1)
511 REST_8GPRS(23, r1)
512 REST_GPR(31, r1)
513 lwz r2,_NIP(r1) /* Restore environment */
514 lwz r0,_MSR(r1)
515 mtspr SRR0,r2
516 mtspr SRR1,r0
517 lwz r0,GPR0(r1)
518 lwz r2,GPR2(r1)
519 lwz r1,GPR1(r1)
520 SYNC
521 rfi
522
523crit_return:
524 mfmsr r28 /* Disable interrupts */
525 li r4,0
526 ori r4,r4,MSR_EE
527 andc r28,r28,r4
528 SYNC /* Some chip revs need this... */
529 mtmsr r28
530 SYNC
531 lwz r2,_CTR(r1)
532 lwz r0,_LINK(r1)
533 mtctr r2
534 mtlr r0
535 lwz r2,_XER(r1)
536 lwz r0,_CCR(r1)
537 mtspr XER,r2
538 mtcrf 0xFF,r0
539 REST_10GPRS(3, r1)
540 REST_10GPRS(13, r1)
541 REST_8GPRS(23, r1)
542 REST_GPR(31, r1)
543 lwz r2,_NIP(r1) /* Restore environment */
544 lwz r0,_MSR(r1)
Andy Fleming61a21e92007-08-14 01:34:21 -0500545 mtspr SPRN_CSRR0,r2
546 mtspr SPRN_CSRR1,r0
wdenk42d1f032003-10-15 23:53:47 +0000547 lwz r0,GPR0(r1)
548 lwz r2,GPR2(r1)
549 lwz r1,GPR1(r1)
550 SYNC
551 rfci
552
Andy Fleming61a21e92007-08-14 01:34:21 -0500553mck_return:
554 mfmsr r28 /* Disable interrupts */
555 li r4,0
556 ori r4,r4,MSR_EE
557 andc r28,r28,r4
558 SYNC /* Some chip revs need this... */
559 mtmsr r28
560 SYNC
561 lwz r2,_CTR(r1)
562 lwz r0,_LINK(r1)
563 mtctr r2
564 mtlr r0
565 lwz r2,_XER(r1)
566 lwz r0,_CCR(r1)
567 mtspr XER,r2
568 mtcrf 0xFF,r0
569 REST_10GPRS(3, r1)
570 REST_10GPRS(13, r1)
571 REST_8GPRS(23, r1)
572 REST_GPR(31, r1)
573 lwz r2,_NIP(r1) /* Restore environment */
574 lwz r0,_MSR(r1)
575 mtspr SPRN_MCSRR0,r2
576 mtspr SPRN_MCSRR1,r0
577 lwz r0,GPR0(r1)
578 lwz r2,GPR2(r1)
579 lwz r1,GPR1(r1)
580 SYNC
581 rfmci
582
wdenk42d1f032003-10-15 23:53:47 +0000583/* Cache functions.
584*/
585invalidate_icache:
586 mfspr r0,L1CSR1
Andy Fleming61a21e92007-08-14 01:34:21 -0500587 ori r0,r0,L1CSR1_ICFI
588 msync
589 isync
wdenk42d1f032003-10-15 23:53:47 +0000590 mtspr L1CSR1,r0
591 isync
Andy Fleming61a21e92007-08-14 01:34:21 -0500592 blr /* entire I cache */
wdenk42d1f032003-10-15 23:53:47 +0000593
594invalidate_dcache:
595 mfspr r0,L1CSR0
Andy Fleming61a21e92007-08-14 01:34:21 -0500596 ori r0,r0,L1CSR0_DCFI
wdenk42d1f032003-10-15 23:53:47 +0000597 msync
598 isync
599 mtspr L1CSR0,r0
600 isync
601 blr
602
603 .globl icache_enable
604icache_enable:
605 mflr r8
606 bl invalidate_icache
607 mtlr r8
608 isync
609 mfspr r4,L1CSR1
610 ori r4,r4,0x0001
611 oris r4,r4,0x0001
612 mtspr L1CSR1,r4
613 isync
614 blr
615
616 .globl icache_disable
617icache_disable:
618 mfspr r0,L1CSR1
Andy Fleming61a21e92007-08-14 01:34:21 -0500619 lis r3,0
620 ori r3,r3,L1CSR1_ICE
621 andc r0,r0,r3
wdenk42d1f032003-10-15 23:53:47 +0000622 mtspr L1CSR1,r0
623 isync
624 blr
625
626 .globl icache_status
627icache_status:
628 mfspr r3,L1CSR1
Andy Fleming61a21e92007-08-14 01:34:21 -0500629 andi. r3,r3,L1CSR1_ICE
wdenk42d1f032003-10-15 23:53:47 +0000630 blr
631
632 .globl dcache_enable
633dcache_enable:
634 mflr r8
635 bl invalidate_dcache
636 mtlr r8
637 isync
638 mfspr r0,L1CSR0
639 ori r0,r0,0x0001
640 oris r0,r0,0x0001
641 msync
642 isync
643 mtspr L1CSR0,r0
644 isync
645 blr
646
647 .globl dcache_disable
648dcache_disable:
Andy Fleming61a21e92007-08-14 01:34:21 -0500649 mfspr r3,L1CSR0
650 lis r4,0
651 ori r4,r4,L1CSR0_DCE
652 andc r3,r3,r4
wdenk42d1f032003-10-15 23:53:47 +0000653 mtspr L1CSR0,r0
654 isync
655 blr
656
657 .globl dcache_status
658dcache_status:
659 mfspr r3,L1CSR0
Andy Fleming61a21e92007-08-14 01:34:21 -0500660 andi. r3,r3,L1CSR0_DCE
wdenk42d1f032003-10-15 23:53:47 +0000661 blr
662
663 .globl get_pir
664get_pir:
Andy Fleming61a21e92007-08-14 01:34:21 -0500665 mfspr r3,PIR
wdenk42d1f032003-10-15 23:53:47 +0000666 blr
667
668 .globl get_pvr
669get_pvr:
Andy Fleming61a21e92007-08-14 01:34:21 -0500670 mfspr r3,PVR
wdenk42d1f032003-10-15 23:53:47 +0000671 blr
672
wdenk97d80fc2004-06-09 00:34:46 +0000673 .globl get_svr
674get_svr:
Andy Fleming61a21e92007-08-14 01:34:21 -0500675 mfspr r3,SVR
wdenk97d80fc2004-06-09 00:34:46 +0000676 blr
677
wdenk42d1f032003-10-15 23:53:47 +0000678 .globl wr_tcr
679wr_tcr:
Andy Fleming61a21e92007-08-14 01:34:21 -0500680 mtspr TCR,r3
wdenk42d1f032003-10-15 23:53:47 +0000681 blr
682
683/*------------------------------------------------------------------------------- */
684/* Function: in8 */
685/* Description: Input 8 bits */
686/*------------------------------------------------------------------------------- */
687 .globl in8
688in8:
689 lbz r3,0x0000(r3)
690 blr
691
692/*------------------------------------------------------------------------------- */
693/* Function: out8 */
694/* Description: Output 8 bits */
695/*------------------------------------------------------------------------------- */
696 .globl out8
697out8:
698 stb r4,0x0000(r3)
Ed Swarthout1487adb2007-09-26 16:35:54 -0500699 sync
wdenk42d1f032003-10-15 23:53:47 +0000700 blr
701
702/*------------------------------------------------------------------------------- */
703/* Function: out16 */
704/* Description: Output 16 bits */
705/*------------------------------------------------------------------------------- */
706 .globl out16
707out16:
708 sth r4,0x0000(r3)
Ed Swarthout1487adb2007-09-26 16:35:54 -0500709 sync
wdenk42d1f032003-10-15 23:53:47 +0000710 blr
711
712/*------------------------------------------------------------------------------- */
713/* Function: out16r */
714/* Description: Byte reverse and output 16 bits */
715/*------------------------------------------------------------------------------- */
716 .globl out16r
717out16r:
718 sthbrx r4,r0,r3
Ed Swarthout1487adb2007-09-26 16:35:54 -0500719 sync
wdenk42d1f032003-10-15 23:53:47 +0000720 blr
721
722/*------------------------------------------------------------------------------- */
723/* Function: out32 */
724/* Description: Output 32 bits */
725/*------------------------------------------------------------------------------- */
726 .globl out32
727out32:
728 stw r4,0x0000(r3)
Ed Swarthout1487adb2007-09-26 16:35:54 -0500729 sync
wdenk42d1f032003-10-15 23:53:47 +0000730 blr
731
732/*------------------------------------------------------------------------------- */
733/* Function: out32r */
734/* Description: Byte reverse and output 32 bits */
735/*------------------------------------------------------------------------------- */
736 .globl out32r
737out32r:
738 stwbrx r4,r0,r3
Ed Swarthout1487adb2007-09-26 16:35:54 -0500739 sync
wdenk42d1f032003-10-15 23:53:47 +0000740 blr
741
742/*------------------------------------------------------------------------------- */
743/* Function: in16 */
744/* Description: Input 16 bits */
745/*------------------------------------------------------------------------------- */
746 .globl in16
747in16:
748 lhz r3,0x0000(r3)
749 blr
750
751/*------------------------------------------------------------------------------- */
752/* Function: in16r */
753/* Description: Input 16 bits and byte reverse */
754/*------------------------------------------------------------------------------- */
755 .globl in16r
756in16r:
757 lhbrx r3,r0,r3
758 blr
759
760/*------------------------------------------------------------------------------- */
761/* Function: in32 */
762/* Description: Input 32 bits */
763/*------------------------------------------------------------------------------- */
764 .globl in32
765in32:
766 lwz 3,0x0000(3)
767 blr
768
769/*------------------------------------------------------------------------------- */
770/* Function: in32r */
771/* Description: Input 32 bits and byte reverse */
772/*------------------------------------------------------------------------------- */
773 .globl in32r
774in32r:
775 lwbrx r3,r0,r3
776 blr
777
778/*------------------------------------------------------------------------------- */
779/* Function: ppcDcbf */
780/* Description: Data Cache block flush */
781/* Input: r3 = effective address */
782/* Output: none. */
783/*------------------------------------------------------------------------------- */
784 .globl ppcDcbf
785ppcDcbf:
786 dcbf r0,r3
787 blr
788
789/*------------------------------------------------------------------------------- */
790/* Function: ppcDcbi */
791/* Description: Data Cache block Invalidate */
792/* Input: r3 = effective address */
793/* Output: none. */
794/*------------------------------------------------------------------------------- */
795 .globl ppcDcbi
796ppcDcbi:
797 dcbi r0,r3
798 blr
799
wdenk0ac6f8b2004-07-09 23:27:13 +0000800/*--------------------------------------------------------------------------
801 * Function: ppcDcbz
802 * Description: Data Cache block zero.
803 * Input: r3 = effective address
804 * Output: none.
805 *-------------------------------------------------------------------------- */
806
807 .globl ppcDcbz
808ppcDcbz:
809 dcbz r0,r3
810 blr
811
wdenk42d1f032003-10-15 23:53:47 +0000812/*------------------------------------------------------------------------------- */
813/* Function: ppcSync */
814/* Description: Processor Synchronize */
815/* Input: none. */
816/* Output: none. */
817/*------------------------------------------------------------------------------- */
818 .globl ppcSync
819ppcSync:
820 sync
821 blr
822
823/*------------------------------------------------------------------------------*/
824
825/*
826 * void relocate_code (addr_sp, gd, addr_moni)
827 *
828 * This "function" does not return, instead it continues in RAM
829 * after relocating the monitor code.
830 *
831 * r3 = dest
832 * r4 = src
833 * r5 = length in bytes
834 * r6 = cachelinesize
835 */
836 .globl relocate_code
837relocate_code:
Andy Fleming61a21e92007-08-14 01:34:21 -0500838 mr r1,r3 /* Set new stack pointer */
839 mr r9,r4 /* Save copy of Init Data pointer */
840 mr r10,r5 /* Save copy of Destination Address */
wdenk42d1f032003-10-15 23:53:47 +0000841
Andy Fleming61a21e92007-08-14 01:34:21 -0500842 mr r3,r5 /* Destination Address */
843 lis r4,CFG_MONITOR_BASE@h /* Source Address */
844 ori r4,r4,CFG_MONITOR_BASE@l
wdenk42d1f032003-10-15 23:53:47 +0000845 lwz r5,GOT(__init_end)
846 sub r5,r5,r4
Andy Fleming61a21e92007-08-14 01:34:21 -0500847 li r6,CFG_CACHELINE_SIZE /* Cache Line Size */
wdenk42d1f032003-10-15 23:53:47 +0000848
849 /*
850 * Fix GOT pointer:
851 *
852 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
853 *
854 * Offset:
855 */
Andy Fleming61a21e92007-08-14 01:34:21 -0500856 sub r15,r10,r4
wdenk42d1f032003-10-15 23:53:47 +0000857
858 /* First our own GOT */
Andy Fleming61a21e92007-08-14 01:34:21 -0500859 add r14,r14,r15
wdenk42d1f032003-10-15 23:53:47 +0000860 /* the the one used by the C code */
Andy Fleming61a21e92007-08-14 01:34:21 -0500861 add r30,r30,r15
wdenk42d1f032003-10-15 23:53:47 +0000862
863 /*
864 * Now relocate code
865 */
866
867 cmplw cr1,r3,r4
868 addi r0,r5,3
869 srwi. r0,r0,2
870 beq cr1,4f /* In place copy is not necessary */
871 beq 7f /* Protect against 0 count */
872 mtctr r0
873 bge cr1,2f
874
875 la r8,-4(r4)
876 la r7,-4(r3)
8771: lwzu r0,4(r8)
878 stwu r0,4(r7)
879 bdnz 1b
880 b 4f
881
8822: slwi r0,r0,2
883 add r8,r4,r0
884 add r7,r3,r0
8853: lwzu r0,-4(r8)
886 stwu r0,-4(r7)
887 bdnz 3b
888
889/*
890 * Now flush the cache: note that we must start from a cache aligned
891 * address. Otherwise we might miss one cache line.
892 */
8934: cmpwi r6,0
894 add r5,r3,r5
895 beq 7f /* Always flush prefetch queue in any case */
896 subi r0,r6,1
897 andc r3,r3,r0
898 mr r4,r3
8995: dcbst 0,r4
900 add r4,r4,r6
901 cmplw r4,r5
902 blt 5b
903 sync /* Wait for all dcbst to complete on bus */
904 mr r4,r3
9056: icbi 0,r4
906 add r4,r4,r6
907 cmplw r4,r5
908 blt 6b
9097: sync /* Wait for all icbi to complete on bus */
910 isync
911
Wolfgang Denk7d314992005-10-05 00:00:54 +0200912 /*
913 * Re-point the IVPR at RAM
914 */
915 mtspr IVPR,r10
Wolfgang Denk99b0d282005-10-05 00:19:34 +0200916
wdenk42d1f032003-10-15 23:53:47 +0000917/*
918 * We are done. Do not return, instead branch to second part of board
919 * initialization, now running from RAM.
920 */
921
Andy Fleming61a21e92007-08-14 01:34:21 -0500922 addi r0,r10,in_ram - _start + _START_OFFSET
wdenk42d1f032003-10-15 23:53:47 +0000923 mtlr r0
924 blr /* NEVER RETURNS! */
Andy Fleming61a21e92007-08-14 01:34:21 -0500925 .globl in_ram
wdenk42d1f032003-10-15 23:53:47 +0000926in_ram:
927
928 /*
929 * Relocation Function, r14 point to got2+0x8000
930 *
931 * Adjust got2 pointers, no need to check for 0, this code
932 * already puts a few entries in the table.
933 */
934 li r0,__got2_entries@sectoff@l
935 la r3,GOT(_GOT2_TABLE_)
936 lwz r11,GOT(_GOT2_TABLE_)
937 mtctr r0
938 sub r11,r3,r11
939 addi r3,r3,-4
9401: lwzu r0,4(r3)
941 add r0,r0,r11
942 stw r0,0(r3)
943 bdnz 1b
944
945 /*
946 * Now adjust the fixups and the pointers to the fixups
947 * in case we need to move ourselves again.
948 */
9492: li r0,__fixup_entries@sectoff@l
950 lwz r3,GOT(_FIXUP_TABLE_)
951 cmpwi r0,0
952 mtctr r0
953 addi r3,r3,-4
954 beq 4f
9553: lwzu r4,4(r3)
956 lwzux r0,r4,r11
957 add r0,r0,r11
958 stw r10,0(r3)
959 stw r0,0(r4)
960 bdnz 3b
9614:
962clear_bss:
963 /*
964 * Now clear BSS segment
965 */
966 lwz r3,GOT(__bss_start)
967 lwz r4,GOT(_end)
968
Andy Fleming61a21e92007-08-14 01:34:21 -0500969 cmplw 0,r3,r4
wdenk42d1f032003-10-15 23:53:47 +0000970 beq 6f
971
Andy Fleming61a21e92007-08-14 01:34:21 -0500972 li r0,0
wdenk42d1f032003-10-15 23:53:47 +00009735:
Andy Fleming61a21e92007-08-14 01:34:21 -0500974 stw r0,0(r3)
975 addi r3,r3,4
976 cmplw 0,r3,r4
wdenk42d1f032003-10-15 23:53:47 +0000977 bne 5b
9786:
979
Andy Fleming61a21e92007-08-14 01:34:21 -0500980 mr r3,r9 /* Init Data pointer */
981 mr r4,r10 /* Destination Address */
wdenk42d1f032003-10-15 23:53:47 +0000982 bl board_init_r
983
984 /*
985 * Copy exception vector code to low memory
986 *
987 * r3: dest_addr
988 * r7: source address, r8: end address, r9: target address
989 */
wdenk343117b2005-05-13 22:49:36 +0000990 .globl trap_init
wdenk42d1f032003-10-15 23:53:47 +0000991trap_init:
Andy Fleming61a21e92007-08-14 01:34:21 -0500992 lwz r7,GOT(_start_of_vectors)
993 lwz r8,GOT(_end_of_vectors)
wdenk42d1f032003-10-15 23:53:47 +0000994
Andy Fleming61a21e92007-08-14 01:34:21 -0500995 li r9,0x100 /* reset vector always at 0x100 */
wdenk42d1f032003-10-15 23:53:47 +0000996
Andy Fleming61a21e92007-08-14 01:34:21 -0500997 cmplw 0,r7,r8
wdenk343117b2005-05-13 22:49:36 +0000998 bgelr /* return if r7>=r8 - just in case */
wdenk42d1f032003-10-15 23:53:47 +0000999
wdenk343117b2005-05-13 22:49:36 +00001000 mflr r4 /* save link register */
wdenk42d1f032003-10-15 23:53:47 +000010011:
Andy Fleming61a21e92007-08-14 01:34:21 -05001002 lwz r0,0(r7)
1003 stw r0,0(r9)
1004 addi r7,r7,4
1005 addi r9,r9,4
1006 cmplw 0,r7,r8
wdenk343117b2005-05-13 22:49:36 +00001007 bne 1b
wdenk42d1f032003-10-15 23:53:47 +00001008
1009 /*
1010 * relocate `hdlr' and `int_return' entries
1011 */
Andy Fleming61a21e92007-08-14 01:34:21 -05001012 li r7,.L_CriticalInput - _start + _START_OFFSET
wdenk343117b2005-05-13 22:49:36 +00001013 bl trap_reloc
Andy Fleming61a21e92007-08-14 01:34:21 -05001014 li r7,.L_MachineCheck - _start + _START_OFFSET
wdenk343117b2005-05-13 22:49:36 +00001015 bl trap_reloc
Andy Fleming61a21e92007-08-14 01:34:21 -05001016 li r7,.L_DataStorage - _start + _START_OFFSET
wdenk343117b2005-05-13 22:49:36 +00001017 bl trap_reloc
Andy Fleming61a21e92007-08-14 01:34:21 -05001018 li r7,.L_InstStorage - _start + _START_OFFSET
wdenk343117b2005-05-13 22:49:36 +00001019 bl trap_reloc
Andy Fleming61a21e92007-08-14 01:34:21 -05001020 li r7,.L_ExtInterrupt - _start + _START_OFFSET
wdenk343117b2005-05-13 22:49:36 +00001021 bl trap_reloc
Andy Fleming61a21e92007-08-14 01:34:21 -05001022 li r7,.L_Alignment - _start + _START_OFFSET
wdenk343117b2005-05-13 22:49:36 +00001023 bl trap_reloc
Andy Fleming61a21e92007-08-14 01:34:21 -05001024 li r7,.L_ProgramCheck - _start + _START_OFFSET
wdenk343117b2005-05-13 22:49:36 +00001025 bl trap_reloc
Andy Fleming61a21e92007-08-14 01:34:21 -05001026 li r7,.L_FPUnavailable - _start + _START_OFFSET
wdenk343117b2005-05-13 22:49:36 +00001027 bl trap_reloc
Andy Fleming61a21e92007-08-14 01:34:21 -05001028 li r7,.L_Decrementer - _start + _START_OFFSET
1029 bl trap_reloc
1030 li r7,.L_IntervalTimer - _start + _START_OFFSET
1031 li r8,_end_of_vectors - _start + _START_OFFSET
wdenk42d1f032003-10-15 23:53:47 +000010322:
wdenk343117b2005-05-13 22:49:36 +00001033 bl trap_reloc
Andy Fleming61a21e92007-08-14 01:34:21 -05001034 addi r7,r7,0x100 /* next exception vector */
1035 cmplw 0,r7,r8
wdenk343117b2005-05-13 22:49:36 +00001036 blt 2b
wdenk42d1f032003-10-15 23:53:47 +00001037
wdenk343117b2005-05-13 22:49:36 +00001038 lis r7,0x0
Andy Fleming61a21e92007-08-14 01:34:21 -05001039 mtspr IVPR,r7
wdenk42d1f032003-10-15 23:53:47 +00001040
wdenk343117b2005-05-13 22:49:36 +00001041 mtlr r4 /* restore link register */
wdenk42d1f032003-10-15 23:53:47 +00001042 blr
1043
1044 /*
1045 * Function: relocate entries for one exception vector
1046 */
1047trap_reloc:
Andy Fleming61a21e92007-08-14 01:34:21 -05001048 lwz r0,0(r7) /* hdlr ... */
1049 add r0,r0,r3 /* ... += dest_addr */
1050 stw r0,0(r7)
wdenk42d1f032003-10-15 23:53:47 +00001051
Andy Fleming61a21e92007-08-14 01:34:21 -05001052 lwz r0,4(r7) /* int_return ... */
1053 add r0,r0,r3 /* ... += dest_addr */
1054 stw r0,4(r7)
wdenk42d1f032003-10-15 23:53:47 +00001055
1056 blr
1057
1058#ifdef CFG_INIT_RAM_LOCK
1059.globl unlock_ram_in_cache
1060unlock_ram_in_cache:
1061 /* invalidate the INIT_RAM section */
Andy Fleming61a21e92007-08-14 01:34:21 -05001062 lis r3,(CFG_INIT_RAM_ADDR & ~31)@h
1063 ori r3,r3,(CFG_INIT_RAM_ADDR & ~31)@l
Kumar Galae1ce3cb2007-10-02 11:12:27 -05001064 li r4,(CFG_DCACHE_SIZE / (2 * CFG_CACHELINE_SIZE))
Andy Fleming61a21e92007-08-14 01:34:21 -05001065 mtctr r4
10661: icbi r0,r3
1067 dcbi r0,r3
Kumar Galae1ce3cb2007-10-02 11:12:27 -05001068 addi r3,r3,CFG_CACHELINE_SIZE
wdenk42d1f032003-10-15 23:53:47 +00001069 bdnz 1b
wdenk343117b2005-05-13 22:49:36 +00001070 sync /* Wait for all icbi to complete on bus */
wdenk42d1f032003-10-15 23:53:47 +00001071 isync
1072 blr
1073#endif