xref: /openbmc/u-boot/arch/powerpc/cpu/mpc85xx/start.S (revision 5344f7a258dfb74be11289367b0ffe4852ce74d3)
1a47a12beSStefan Roese/*
2a4107f86SPrabhakar Kushwaha * Copyright 2004, 2007-2012 Freescale Semiconductor, Inc.
3a47a12beSStefan Roese * Copyright (C) 2003  Motorola,Inc.
4a47a12beSStefan Roese *
5a47a12beSStefan Roese * See file CREDITS for list of people who contributed to this
6a47a12beSStefan Roese * project.
7a47a12beSStefan Roese *
8a47a12beSStefan Roese * This program is free software; you can redistribute it and/or
9a47a12beSStefan Roese * modify it under the terms of the GNU General Public License as
10a47a12beSStefan Roese * published by the Free Software Foundation; either version 2 of
11a47a12beSStefan Roese * the License, or (at your option) any later version.
12a47a12beSStefan Roese *
13a47a12beSStefan Roese * This program is distributed in the hope that it will be useful,
14a47a12beSStefan Roese * but WITHOUT ANY WARRANTY; without even the implied warranty of
15a47a12beSStefan Roese * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
16a47a12beSStefan Roese * GNU General Public License for more details.
17a47a12beSStefan Roese *
18a47a12beSStefan Roese * You should have received a copy of the GNU General Public License
19a47a12beSStefan Roese * along with this program; if not, write to the Free Software
20a47a12beSStefan Roese * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21a47a12beSStefan Roese * MA 02111-1307 USA
22a47a12beSStefan Roese */
23a47a12beSStefan Roese
24a47a12beSStefan Roese/* U-Boot Startup Code for Motorola 85xx PowerPC based Embedded Boards
25a47a12beSStefan Roese *
26a47a12beSStefan Roese * The processor starts at 0xfffffffc and the code is first executed in the
27a47a12beSStefan Roese * last 4K page(0xfffff000-0xffffffff) in flash/rom.
28a47a12beSStefan Roese *
29a47a12beSStefan Roese */
30a47a12beSStefan Roese
3125ddd1fbSWolfgang Denk#include <asm-offsets.h>
32a47a12beSStefan Roese#include <config.h>
33a47a12beSStefan Roese#include <mpc85xx.h>
34a47a12beSStefan Roese#include <version.h>
35a47a12beSStefan Roese
36a47a12beSStefan Roese#define _LINUX_CONFIG_H 1	/* avoid reading Linux autoconf.h file	*/
37a47a12beSStefan Roese
38a47a12beSStefan Roese#include <ppc_asm.tmpl>
39a47a12beSStefan Roese#include <ppc_defs.h>
40a47a12beSStefan Roese
41a47a12beSStefan Roese#include <asm/cache.h>
42a47a12beSStefan Roese#include <asm/mmu.h>
43a47a12beSStefan Roese
44a47a12beSStefan Roese#undef	MSR_KERNEL
45a47a12beSStefan Roese#define MSR_KERNEL ( MSR_ME )	/* Machine Check */
46a47a12beSStefan Roese
47a47a12beSStefan Roese/*
48a47a12beSStefan Roese * Set up GOT: Global Offset Table
49a47a12beSStefan Roese *
50a47a12beSStefan Roese * Use r12 to access the GOT
51a47a12beSStefan Roese */
52a47a12beSStefan Roese	START_GOT
53a47a12beSStefan Roese	GOT_ENTRY(_GOT2_TABLE_)
54a47a12beSStefan Roese	GOT_ENTRY(_FIXUP_TABLE_)
55a47a12beSStefan Roese
56a47a12beSStefan Roese#ifndef CONFIG_NAND_SPL
57a47a12beSStefan Roese	GOT_ENTRY(_start)
58a47a12beSStefan Roese	GOT_ENTRY(_start_of_vectors)
59a47a12beSStefan Roese	GOT_ENTRY(_end_of_vectors)
60a47a12beSStefan Roese	GOT_ENTRY(transfer_to_handler)
61a47a12beSStefan Roese#endif
62a47a12beSStefan Roese
63a47a12beSStefan Roese	GOT_ENTRY(__init_end)
6444c6e659SPo-Yu Chuang	GOT_ENTRY(__bss_end__)
65a47a12beSStefan Roese	GOT_ENTRY(__bss_start)
66a47a12beSStefan Roese	END_GOT
67a47a12beSStefan Roese
68a47a12beSStefan Roese/*
69a47a12beSStefan Roese * e500 Startup -- after reset only the last 4KB of the effective
70a47a12beSStefan Roese * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
71a47a12beSStefan Roese * section is located at THIS LAST page and basically does three
72a47a12beSStefan Roese * things: clear some registers, set up exception tables and
73a47a12beSStefan Roese * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
74a47a12beSStefan Roese * continue the boot procedure.
75a47a12beSStefan Roese
76a47a12beSStefan Roese * Once the boot rom is mapped by TLB entries we can proceed
77a47a12beSStefan Roese * with normal startup.
78a47a12beSStefan Roese *
79a47a12beSStefan Roese */
80a47a12beSStefan Roese
81a47a12beSStefan Roese	.section .bootpg,"ax"
82a47a12beSStefan Roese	.globl _start_e500
83a47a12beSStefan Roese
84a47a12beSStefan Roese_start_e500:
85*5344f7a2SPrabhakar Kushwaha/* Enable debug exception */
86*5344f7a2SPrabhakar Kushwaha	li	r1,MSR_DE
87*5344f7a2SPrabhakar Kushwaha	mtmsr 	r1
88a47a12beSStefan Roese
897065b7d4SRuchika Gupta#if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_E500MC)
907065b7d4SRuchika Gupta	/* ISBC uses L2 as stack.
917065b7d4SRuchika Gupta	 * Disable L2 cache here so that u-boot can enable it later
927065b7d4SRuchika Gupta	 * as part of it's normal flow
937065b7d4SRuchika Gupta	*/
947065b7d4SRuchika Gupta
957065b7d4SRuchika Gupta	/* Check if L2 is enabled */
967065b7d4SRuchika Gupta	mfspr	r3, SPRN_L2CSR0
977065b7d4SRuchika Gupta	lis	r2, L2CSR0_L2E@h
987065b7d4SRuchika Gupta	ori	r2, r2, L2CSR0_L2E@l
997065b7d4SRuchika Gupta	and.	r4, r3, r2
1007065b7d4SRuchika Gupta	beq	l2_disabled
1017065b7d4SRuchika Gupta
1027065b7d4SRuchika Gupta	mfspr r3, SPRN_L2CSR0
1037065b7d4SRuchika Gupta	/* Flush L2 cache */
1047065b7d4SRuchika Gupta	lis     r2,(L2CSR0_L2FL)@h
1057065b7d4SRuchika Gupta	ori     r2, r2, (L2CSR0_L2FL)@l
1067065b7d4SRuchika Gupta	or      r3, r2, r3
1077065b7d4SRuchika Gupta	sync
1087065b7d4SRuchika Gupta	isync
1097065b7d4SRuchika Gupta	mtspr   SPRN_L2CSR0,r3
1107065b7d4SRuchika Gupta	isync
1117065b7d4SRuchika Gupta1:
1127065b7d4SRuchika Gupta	mfspr r3, SPRN_L2CSR0
1137065b7d4SRuchika Gupta	and. r1, r3, r2
1147065b7d4SRuchika Gupta	bne 1b
1157065b7d4SRuchika Gupta
1167065b7d4SRuchika Gupta	mfspr r3, SPRN_L2CSR0
1177065b7d4SRuchika Gupta	lis r2, L2CSR0_L2E@h
1187065b7d4SRuchika Gupta	ori r2, r2, L2CSR0_L2E@l
1197065b7d4SRuchika Gupta	andc r4, r3, r2
1207065b7d4SRuchika Gupta	sync
1217065b7d4SRuchika Gupta	isync
1227065b7d4SRuchika Gupta	mtspr SPRN_L2CSR0,r4
1237065b7d4SRuchika Gupta	isync
1247065b7d4SRuchika Gupta
1257065b7d4SRuchika Guptal2_disabled:
1267065b7d4SRuchika Gupta#endif
1277065b7d4SRuchika Gupta
128a47a12beSStefan Roese/* clear registers/arrays not reset by hardware */
129a47a12beSStefan Roese
130a47a12beSStefan Roese	/* L1 */
131a47a12beSStefan Roese	li	r0,2
132a47a12beSStefan Roese	mtspr	L1CSR0,r0	/* invalidate d-cache */
133a47a12beSStefan Roese	mtspr	L1CSR1,r0	/* invalidate i-cache */
134a47a12beSStefan Roese
135a47a12beSStefan Roese	mfspr	r1,DBSR
136a47a12beSStefan Roese	mtspr	DBSR,r1		/* Clear all valid bits */
137a47a12beSStefan Roese
138a47a12beSStefan Roese	/*
139a47a12beSStefan Roese	 *	Enable L1 Caches early
140a47a12beSStefan Roese	 *
141a47a12beSStefan Roese	 */
142a47a12beSStefan Roese
143a47a12beSStefan Roese#if defined(CONFIG_E500MC) && defined(CONFIG_SYS_CACHE_STASHING)
144a47a12beSStefan Roese	/* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
145a47a12beSStefan Roese	li	r2,(32 + 0)
146a47a12beSStefan Roese	mtspr	L1CSR2,r2
147a47a12beSStefan Roese#endif
148a47a12beSStefan Roese
149a47a12beSStefan Roese	/* Enable/invalidate the I-Cache */
150a47a12beSStefan Roese	lis	r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
151a47a12beSStefan Roese	ori	r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
152a47a12beSStefan Roese	mtspr	SPRN_L1CSR1,r2
153a47a12beSStefan Roese1:
154a47a12beSStefan Roese	mfspr	r3,SPRN_L1CSR1
155a47a12beSStefan Roese	and.	r1,r3,r2
156a47a12beSStefan Roese	bne	1b
157a47a12beSStefan Roese
158a47a12beSStefan Roese	lis	r3,(L1CSR1_CPE|L1CSR1_ICE)@h
159a47a12beSStefan Roese	ori	r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
160a47a12beSStefan Roese	mtspr	SPRN_L1CSR1,r3
161a47a12beSStefan Roese	isync
162a47a12beSStefan Roese2:
163a47a12beSStefan Roese	mfspr	r3,SPRN_L1CSR1
164a47a12beSStefan Roese	andi.	r1,r3,L1CSR1_ICE@l
165a47a12beSStefan Roese	beq	2b
166a47a12beSStefan Roese
167a47a12beSStefan Roese	/* Enable/invalidate the D-Cache */
168a47a12beSStefan Roese	lis	r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h
169a47a12beSStefan Roese	ori	r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l
170a47a12beSStefan Roese	mtspr	SPRN_L1CSR0,r2
171a47a12beSStefan Roese1:
172a47a12beSStefan Roese	mfspr	r3,SPRN_L1CSR0
173a47a12beSStefan Roese	and.	r1,r3,r2
174a47a12beSStefan Roese	bne	1b
175a47a12beSStefan Roese
176a47a12beSStefan Roese	lis	r3,(L1CSR0_CPE|L1CSR0_DCE)@h
177a47a12beSStefan Roese	ori	r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l
178a47a12beSStefan Roese	mtspr	SPRN_L1CSR0,r3
179a47a12beSStefan Roese	isync
180a47a12beSStefan Roese2:
181a47a12beSStefan Roese	mfspr	r3,SPRN_L1CSR0
182a47a12beSStefan Roese	andi.	r1,r3,L1CSR0_DCE@l
183a47a12beSStefan Roese	beq	2b
184a47a12beSStefan Roese
185119a55f9SPrabhakar Kushwaha/*
186119a55f9SPrabhakar Kushwaha * Ne need to setup interrupt vector for NAND SPL
187119a55f9SPrabhakar Kushwaha * because NAND SPL never compiles it.
188119a55f9SPrabhakar Kushwaha */
189119a55f9SPrabhakar Kushwaha#if !defined(CONFIG_NAND_SPL)
190a47a12beSStefan Roese	/* Setup interrupt vectors */
1910635b09cSHaiying Wang	lis	r1,CONFIG_SYS_MONITOR_BASE@h
192a47a12beSStefan Roese	mtspr	IVPR,r1
193a47a12beSStefan Roese
194a4107f86SPrabhakar Kushwaha	lis	r3,(CONFIG_SYS_MONITOR_BASE & 0xffff)@h
195a4107f86SPrabhakar Kushwaha	ori	r3,r3,(CONFIG_SYS_MONITOR_BASE & 0xffff)@l
196a4107f86SPrabhakar Kushwaha
197a4107f86SPrabhakar Kushwaha	addi	r4,r3,CriticalInput - _start + _START_OFFSET
198a4107f86SPrabhakar Kushwaha	mtspr	IVOR0,r4	/* 0: Critical input */
199a4107f86SPrabhakar Kushwaha	addi	r4,r3,MachineCheck - _start + _START_OFFSET
200a4107f86SPrabhakar Kushwaha	mtspr	IVOR1,r4	/* 1: Machine check */
201a4107f86SPrabhakar Kushwaha	addi	r4,r3,DataStorage - _start + _START_OFFSET
202a4107f86SPrabhakar Kushwaha	mtspr	IVOR2,r4	/* 2: Data storage */
203a4107f86SPrabhakar Kushwaha	addi	r4,r3,InstStorage - _start + _START_OFFSET
204a4107f86SPrabhakar Kushwaha	mtspr	IVOR3,r4	/* 3: Instruction storage */
205a4107f86SPrabhakar Kushwaha	addi	r4,r3,ExtInterrupt - _start + _START_OFFSET
206a4107f86SPrabhakar Kushwaha	mtspr	IVOR4,r4	/* 4: External interrupt */
207a4107f86SPrabhakar Kushwaha	addi	r4,r3,Alignment - _start + _START_OFFSET
208a4107f86SPrabhakar Kushwaha	mtspr	IVOR5,r4	/* 5: Alignment */
209a4107f86SPrabhakar Kushwaha	addi	r4,r3,ProgramCheck - _start + _START_OFFSET
210a4107f86SPrabhakar Kushwaha	mtspr	IVOR6,r4	/* 6: Program check */
211a4107f86SPrabhakar Kushwaha	addi	r4,r3,FPUnavailable - _start + _START_OFFSET
212a4107f86SPrabhakar Kushwaha	mtspr	IVOR7,r4	/* 7: floating point unavailable */
213a4107f86SPrabhakar Kushwaha	addi	r4,r3,SystemCall - _start + _START_OFFSET
214a4107f86SPrabhakar Kushwaha	mtspr	IVOR8,r4	/* 8: System call */
215a47a12beSStefan Roese	/* 9: Auxiliary processor unavailable(unsupported) */
216a4107f86SPrabhakar Kushwaha	addi	r4,r3,Decrementer - _start + _START_OFFSET
217a4107f86SPrabhakar Kushwaha	mtspr	IVOR10,r4	/* 10: Decrementer */
218a4107f86SPrabhakar Kushwaha	addi	r4,r3,IntervalTimer - _start + _START_OFFSET
219a4107f86SPrabhakar Kushwaha	mtspr	IVOR11,r4	/* 11: Interval timer */
220a4107f86SPrabhakar Kushwaha	addi	r4,r3,WatchdogTimer - _start + _START_OFFSET
221a4107f86SPrabhakar Kushwaha	mtspr	IVOR12,r4	/* 12: Watchdog timer */
222a4107f86SPrabhakar Kushwaha	addi	r4,r3,DataTLBError - _start + _START_OFFSET
223a4107f86SPrabhakar Kushwaha	mtspr	IVOR13,r4	/* 13: Data TLB error */
224a4107f86SPrabhakar Kushwaha	addi	r4,r3,InstructionTLBError - _start + _START_OFFSET
225a4107f86SPrabhakar Kushwaha	mtspr	IVOR14,r4	/* 14: Instruction TLB error */
226a4107f86SPrabhakar Kushwaha	addi	r4,r3,DebugBreakpoint - _start + _START_OFFSET
227a4107f86SPrabhakar Kushwaha	mtspr	IVOR15,r4	/* 15: Debug */
228119a55f9SPrabhakar Kushwaha#endif
229a47a12beSStefan Roese
230a47a12beSStefan Roese	/* Clear and set up some registers. */
231a47a12beSStefan Roese	li      r0,0x0000
232a47a12beSStefan Roese	lis	r1,0xffff
233a47a12beSStefan Roese	mtspr	DEC,r0			/* prevent dec exceptions */
234a47a12beSStefan Roese	mttbl	r0			/* prevent fit & wdt exceptions */
235a47a12beSStefan Roese	mttbu	r0
236a47a12beSStefan Roese	mtspr	TSR,r1			/* clear all timer exception status */
237a47a12beSStefan Roese	mtspr	TCR,r0			/* disable all */
238a47a12beSStefan Roese	mtspr	ESR,r0			/* clear exception syndrome register */
239a47a12beSStefan Roese	mtspr	MCSR,r0			/* machine check syndrome register */
240a47a12beSStefan Roese	mtxer	r0			/* clear integer exception register */
241a47a12beSStefan Roese
242a47a12beSStefan Roese#ifdef CONFIG_SYS_BOOK3E_HV
243a47a12beSStefan Roese	mtspr	MAS8,r0			/* make sure MAS8 is clear */
244a47a12beSStefan Roese#endif
245a47a12beSStefan Roese
246a47a12beSStefan Roese	/* Enable Time Base and Select Time Base Clock */
247a47a12beSStefan Roese	lis	r0,HID0_EMCP@h		/* Enable machine check */
248a47a12beSStefan Roese#if defined(CONFIG_ENABLE_36BIT_PHYS)
249a47a12beSStefan Roese	ori	r0,r0,HID0_ENMAS7@l	/* Enable MAS7 */
250a47a12beSStefan Roese#endif
251a47a12beSStefan Roese#ifndef CONFIG_E500MC
252a47a12beSStefan Roese	ori	r0,r0,HID0_TBEN@l	/* Enable Timebase */
253a47a12beSStefan Roese#endif
254a47a12beSStefan Roese	mtspr	HID0,r0
255a47a12beSStefan Roese
256a47a12beSStefan Roese#ifndef CONFIG_E500MC
257a47a12beSStefan Roese	li	r0,(HID1_ASTME|HID1_ABE)@l	/* Addr streaming & broadcast */
258a47a12beSStefan Roese	mfspr	r3,PVR
259a47a12beSStefan Roese	andi.	r3,r3, 0xff
260a47a12beSStefan Roese	cmpwi	r3,0x50@l	/* if we are rev 5.0 or greater set MBDD */
261a47a12beSStefan Roese	blt 1f
262a47a12beSStefan Roese	/* Set MBDD bit also */
263a47a12beSStefan Roese	ori r0, r0, HID1_MBDD@l
264a47a12beSStefan Roese1:
265a47a12beSStefan Roese	mtspr	HID1,r0
266a47a12beSStefan Roese#endif
267a47a12beSStefan Roese
26843f082bbSKumar Gala#ifdef CONFIG_SYS_FSL_ERRATUM_CPU_A003999
26943f082bbSKumar Gala	mfspr	r3,977
27043f082bbSKumar Gala	oris	r3,r3,0x0100
27143f082bbSKumar Gala	mtspr	977,r3
27243f082bbSKumar Gala#endif
27343f082bbSKumar Gala
274a47a12beSStefan Roese	/* Enable Branch Prediction */
275a47a12beSStefan Roese#if defined(CONFIG_BTB)
276a47a12beSStefan Roese	lis	r0,BUCSR_ENABLE@h
277a47a12beSStefan Roese	ori	r0,r0,BUCSR_ENABLE@l
278a47a12beSStefan Roese	mtspr	SPRN_BUCSR,r0
279a47a12beSStefan Roese#endif
280a47a12beSStefan Roese
281a47a12beSStefan Roese#if defined(CONFIG_SYS_INIT_DBCR)
282a47a12beSStefan Roese	lis	r1,0xffff
283a47a12beSStefan Roese	ori	r1,r1,0xffff
284a47a12beSStefan Roese	mtspr	DBSR,r1			/* Clear all status bits */
285a47a12beSStefan Roese	lis	r0,CONFIG_SYS_INIT_DBCR@h	/* DBCR0[IDM] must be set */
286a47a12beSStefan Roese	ori	r0,r0,CONFIG_SYS_INIT_DBCR@l
287a47a12beSStefan Roese	mtspr	DBCR0,r0
288a47a12beSStefan Roese#endif
289a47a12beSStefan Roese
290a47a12beSStefan Roese#ifdef CONFIG_MPC8569
291a47a12beSStefan Roese#define CONFIG_SYS_LBC_ADDR (CONFIG_SYS_CCSRBAR_DEFAULT + 0x5000)
292a47a12beSStefan Roese#define CONFIG_SYS_LBCR_ADDR (CONFIG_SYS_LBC_ADDR + 0xd0)
293a47a12beSStefan Roese
294a47a12beSStefan Roese	/* MPC8569 Rev.0 silcon needs to set bit 13 of LBCR to allow elBC to
295a47a12beSStefan Roese	 * use address space which is more than 12bits, and it must be done in
296a47a12beSStefan Roese	 * the 4K boot page. So we set this bit here.
297a47a12beSStefan Roese	 */
298a47a12beSStefan Roese
299a47a12beSStefan Roese	/* create a temp mapping TLB0[0] for LBCR  */
300a47a12beSStefan Roese	lis     r6,FSL_BOOKE_MAS0(0, 0, 0)@h
301a47a12beSStefan Roese	ori     r6,r6,FSL_BOOKE_MAS0(0, 0, 0)@l
302a47a12beSStefan Roese
303a47a12beSStefan Roese	lis     r7,FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@h
304a47a12beSStefan Roese	ori     r7,r7,FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@l
305a47a12beSStefan Roese
306a47a12beSStefan Roese	lis     r8,FSL_BOOKE_MAS2(CONFIG_SYS_LBC_ADDR, MAS2_I|MAS2_G)@h
307a47a12beSStefan Roese	ori     r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_LBC_ADDR, MAS2_I|MAS2_G)@l
308a47a12beSStefan Roese
309a47a12beSStefan Roese	lis     r9,FSL_BOOKE_MAS3(CONFIG_SYS_LBC_ADDR, 0,
310a47a12beSStefan Roese						(MAS3_SX|MAS3_SW|MAS3_SR))@h
311a47a12beSStefan Roese	ori     r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_LBC_ADDR, 0,
312a47a12beSStefan Roese						(MAS3_SX|MAS3_SW|MAS3_SR))@l
313a47a12beSStefan Roese
314a47a12beSStefan Roese	mtspr   MAS0,r6
315a47a12beSStefan Roese	mtspr   MAS1,r7
316a47a12beSStefan Roese	mtspr   MAS2,r8
317a47a12beSStefan Roese	mtspr   MAS3,r9
318a47a12beSStefan Roese	isync
319a47a12beSStefan Roese	msync
320a47a12beSStefan Roese	tlbwe
321a47a12beSStefan Roese
322a47a12beSStefan Roese	/* Set LBCR register */
323a47a12beSStefan Roese	lis     r4,CONFIG_SYS_LBCR_ADDR@h
324a47a12beSStefan Roese	ori     r4,r4,CONFIG_SYS_LBCR_ADDR@l
325a47a12beSStefan Roese
326a47a12beSStefan Roese	lis     r5,CONFIG_SYS_LBC_LBCR@h
327a47a12beSStefan Roese	ori     r5,r5,CONFIG_SYS_LBC_LBCR@l
328a47a12beSStefan Roese	stw     r5,0(r4)
329a47a12beSStefan Roese	isync
330a47a12beSStefan Roese
331a47a12beSStefan Roese	/* invalidate this temp TLB */
332a47a12beSStefan Roese	lis	r4,CONFIG_SYS_LBC_ADDR@h
333a47a12beSStefan Roese	ori	r4,r4,CONFIG_SYS_LBC_ADDR@l
334a47a12beSStefan Roese	tlbivax	0,r4
335a47a12beSStefan Roese	isync
336a47a12beSStefan Roese
337a47a12beSStefan Roese#endif /* CONFIG_MPC8569 */
338a47a12beSStefan Roese
3396ca88b09STimur Tabi/*
34072243c01STimur Tabi * Search for the TLB that covers the code we're executing, and shrink it
34172243c01STimur Tabi * so that it covers only this 4K page.  That will ensure that any other
34272243c01STimur Tabi * TLB we create won't interfere with it.  We assume that the TLB exists,
34372243c01STimur Tabi * which is why we don't check the Valid bit of MAS1.
34472243c01STimur Tabi *
34572243c01STimur Tabi * This is necessary, for example, when booting from the on-chip ROM,
34672243c01STimur Tabi * which (oddly) creates a single 4GB TLB that covers CCSR and DDR.
34772243c01STimur Tabi * If we don't shrink this TLB now, then we'll accidentally delete it
34872243c01STimur Tabi * in "purge_old_ccsr_tlb" below.
34972243c01STimur Tabi */
35072243c01STimur Tabi	bl	nexti		/* Find our address */
35172243c01STimur Tabinexti:	mflr	r1		/* R1 = our PC */
35272243c01STimur Tabi	li	r2, 0
35372243c01STimur Tabi	mtspr	MAS6, r2	/* Assume the current PID and AS are 0 */
35472243c01STimur Tabi	isync
35572243c01STimur Tabi	msync
35672243c01STimur Tabi	tlbsx	0, r1		/* This must succeed */
35772243c01STimur Tabi
35872243c01STimur Tabi	/* Set the size of the TLB to 4KB */
35972243c01STimur Tabi	mfspr	r3, MAS1
36072243c01STimur Tabi	li	r2, 0xF00
36172243c01STimur Tabi	andc	r3, r3, r2	/* Clear the TSIZE bits */
36272243c01STimur Tabi	ori	r3, r3, MAS1_TSIZE(BOOKE_PAGESZ_4K)@l
36372243c01STimur Tabi	mtspr	MAS1, r3
36472243c01STimur Tabi
36572243c01STimur Tabi	/*
36672243c01STimur Tabi	 * Set the base address of the TLB to our PC.  We assume that
36772243c01STimur Tabi	 * virtual == physical.  We also assume that MAS2_EPN == MAS3_RPN.
36872243c01STimur Tabi	 */
36972243c01STimur Tabi	lis	r3, MAS2_EPN@h
37072243c01STimur Tabi	ori	r3, r3, MAS2_EPN@l	/* R3 = MAS2_EPN */
37172243c01STimur Tabi
37272243c01STimur Tabi	and	r1, r1, r3	/* Our PC, rounded down to the nearest page */
37372243c01STimur Tabi
37472243c01STimur Tabi	mfspr	r2, MAS2
37572243c01STimur Tabi	andc	r2, r2, r3
37672243c01STimur Tabi	or	r2, r2, r1
37772243c01STimur Tabi	mtspr	MAS2, r2	/* Set the EPN to our PC base address */
37872243c01STimur Tabi
37972243c01STimur Tabi	mfspr	r2, MAS3
38072243c01STimur Tabi	andc	r2, r2, r3
38172243c01STimur Tabi	or	r2, r2, r1
38272243c01STimur Tabi	mtspr	MAS3, r2	/* Set the RPN to our PC base address */
38372243c01STimur Tabi
38472243c01STimur Tabi	isync
38572243c01STimur Tabi	msync
38672243c01STimur Tabi	tlbwe
38772243c01STimur Tabi
38872243c01STimur Tabi/*
3896ca88b09STimur Tabi * Relocate CCSR, if necessary.  We relocate CCSR if (obviously) the default
3906ca88b09STimur Tabi * location is not where we want it.  This typically happens on a 36-bit
3916ca88b09STimur Tabi * system, where we want to move CCSR to near the top of 36-bit address space.
3926ca88b09STimur Tabi *
3936ca88b09STimur Tabi * To move CCSR, we create two temporary TLBs, one for the old location, and
3946ca88b09STimur Tabi * another for the new location.  On CoreNet systems, we also need to create
3956ca88b09STimur Tabi * a special, temporary LAW.
3966ca88b09STimur Tabi *
3976ca88b09STimur Tabi * As a general rule, TLB0 is used for short-term TLBs, and TLB1 is used for
3986ca88b09STimur Tabi * long-term TLBs, so we use TLB0 here.
3996ca88b09STimur Tabi */
4006ca88b09STimur Tabi#if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS)
4016ca88b09STimur Tabi
4026ca88b09STimur Tabi#if !defined(CONFIG_SYS_CCSRBAR_PHYS_HIGH) || !defined(CONFIG_SYS_CCSRBAR_PHYS_LOW)
4036ca88b09STimur Tabi#error "CONFIG_SYS_CCSRBAR_PHYS_HIGH and CONFIG_SYS_CCSRBAR_PHYS_LOW) must be defined."
4046ca88b09STimur Tabi#endif
4056ca88b09STimur Tabi
4066ca88b09STimur Tabipurge_old_ccsr_tlb:
4076ca88b09STimur Tabi	lis	r8, CONFIG_SYS_CCSRBAR@h
4086ca88b09STimur Tabi	ori	r8, r8, CONFIG_SYS_CCSRBAR@l
4096ca88b09STimur Tabi	lis	r9, (CONFIG_SYS_CCSRBAR + 0x1000)@h
4106ca88b09STimur Tabi	ori	r9, r9, (CONFIG_SYS_CCSRBAR + 0x1000)@l
4116ca88b09STimur Tabi
4126ca88b09STimur Tabi	/*
4136ca88b09STimur Tabi	 * In a multi-stage boot (e.g. NAND boot), a previous stage may have
4146ca88b09STimur Tabi	 * created a TLB for CCSR, which will interfere with our relocation
4156ca88b09STimur Tabi	 * code.  Since we're going to create a new TLB for CCSR anyway,
4166ca88b09STimur Tabi	 * it should be safe to delete this old TLB here.  We have to search
4176ca88b09STimur Tabi	 * for it, though.
4186ca88b09STimur Tabi	 */
4196ca88b09STimur Tabi
4206ca88b09STimur Tabi	li	r1, 0
4216ca88b09STimur Tabi	mtspr	MAS6, r1	/* Search the current address space and PID */
422452ad61cSTimur Tabi	isync
423452ad61cSTimur Tabi	msync
4246ca88b09STimur Tabi	tlbsx	0, r8
4256ca88b09STimur Tabi	mfspr	r1, MAS1
4266ca88b09STimur Tabi	andis.  r2, r1, MAS1_VALID@h	/* Check for the Valid bit */
4276ca88b09STimur Tabi	beq     1f			/* Skip if no TLB found */
4286ca88b09STimur Tabi
4296ca88b09STimur Tabi	rlwinm	r1, r1, 0, 1, 31	/* Clear Valid bit */
4306ca88b09STimur Tabi	mtspr	MAS1, r1
431452ad61cSTimur Tabi	isync
432452ad61cSTimur Tabi	msync
4336ca88b09STimur Tabi	tlbwe
4346ca88b09STimur Tabi1:
4356ca88b09STimur Tabi
4366ca88b09STimur Tabicreate_ccsr_new_tlb:
4376ca88b09STimur Tabi	/*
4386ca88b09STimur Tabi	 * Create a TLB for the new location of CCSR.  Register R8 is reserved
4396ca88b09STimur Tabi	 * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR).
4406ca88b09STimur Tabi	 */
4416ca88b09STimur Tabi	lis     r0, FSL_BOOKE_MAS0(0, 0, 0)@h
4426ca88b09STimur Tabi	ori     r0, r0, FSL_BOOKE_MAS0(0, 0, 0)@l
4436ca88b09STimur Tabi	lis     r1, FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@h
4446ca88b09STimur Tabi	ori     r1, r1, FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@l
4456ca88b09STimur Tabi	lis     r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, (MAS2_I|MAS2_G))@h
4466ca88b09STimur Tabi	ori     r2, r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, (MAS2_I|MAS2_G))@l
4476ca88b09STimur Tabi	lis     r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@h
4486ca88b09STimur Tabi	ori     r3, r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@l
449822ad60fSTimur Tabi#ifdef CONFIG_ENABLE_36BIT_PHYS
4506ca88b09STimur Tabi	lis	r7, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
4516ca88b09STimur Tabi	ori	r7, r7, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
452822ad60fSTimur Tabi	mtspr   MAS7, r7
453822ad60fSTimur Tabi#endif
4546ca88b09STimur Tabi	mtspr   MAS0, r0
4556ca88b09STimur Tabi	mtspr   MAS1, r1
4566ca88b09STimur Tabi	mtspr   MAS2, r2
4576ca88b09STimur Tabi	mtspr   MAS3, r3
4586ca88b09STimur Tabi	isync
4596ca88b09STimur Tabi	msync
4606ca88b09STimur Tabi	tlbwe
4616ca88b09STimur Tabi
4626ca88b09STimur Tabi	/*
463c2efa0aaSTimur Tabi	 * Create a TLB for the current location of CCSR.  Register R9 is reserved
4646ca88b09STimur Tabi	 * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR + 0x1000).
4656ca88b09STimur Tabi	 */
4666ca88b09STimur Tabicreate_ccsr_old_tlb:
4676ca88b09STimur Tabi	lis     r0, FSL_BOOKE_MAS0(0, 1, 0)@h
4686ca88b09STimur Tabi	ori     r0, r0, FSL_BOOKE_MAS0(0, 1, 0)@l
4696ca88b09STimur Tabi	lis     r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR + 0x1000, (MAS2_I|MAS2_G))@h
4706ca88b09STimur Tabi	ori     r2, r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR + 0x1000, (MAS2_I|MAS2_G))@l
4716ca88b09STimur Tabi	lis     r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_DEFAULT, 0, (MAS3_SW|MAS3_SR))@h
4726ca88b09STimur Tabi	ori     r3, r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_DEFAULT, 0, (MAS3_SW|MAS3_SR))@l
473822ad60fSTimur Tabi#ifdef CONFIG_ENABLE_36BIT_PHYS
4746ca88b09STimur Tabi	li	r7, 0	/* The default CCSR address is always a 32-bit number */
475822ad60fSTimur Tabi	mtspr   MAS7, r7
476822ad60fSTimur Tabi#endif
4776ca88b09STimur Tabi	mtspr   MAS0, r0
4786ca88b09STimur Tabi	/* MAS1 is the same as above */
4796ca88b09STimur Tabi	mtspr   MAS2, r2
4806ca88b09STimur Tabi	mtspr   MAS3, r3
4816ca88b09STimur Tabi	isync
4826ca88b09STimur Tabi	msync
4836ca88b09STimur Tabi	tlbwe
4846ca88b09STimur Tabi
48519e43841STimur Tabi	/*
48619e43841STimur Tabi	 * We have a TLB for what we think is the current (old) CCSR.  Let's
48719e43841STimur Tabi	 * verify that, otherwise we won't be able to move it.
48819e43841STimur Tabi	 * CONFIG_SYS_CCSRBAR_DEFAULT is always a 32-bit number, so we only
48919e43841STimur Tabi	 * need to compare the lower 32 bits of CCSRBAR on CoreNet systems.
49019e43841STimur Tabi	 */
49119e43841STimur Tabiverify_old_ccsr:
49219e43841STimur Tabi	lis     r0, CONFIG_SYS_CCSRBAR_DEFAULT@h
49319e43841STimur Tabi	ori     r0, r0, CONFIG_SYS_CCSRBAR_DEFAULT@l
49419e43841STimur Tabi#ifdef CONFIG_FSL_CORENET
49519e43841STimur Tabi	lwz	r1, 4(r9)		/* CCSRBARL */
49619e43841STimur Tabi#else
49719e43841STimur Tabi	lwz	r1, 0(r9)		/* CCSRBAR, shifted right by 12 */
49819e43841STimur Tabi	slwi	r1, r1, 12
49919e43841STimur Tabi#endif
50019e43841STimur Tabi
50119e43841STimur Tabi	cmpl	0, r0, r1
50219e43841STimur Tabi
50319e43841STimur Tabi	/*
50419e43841STimur Tabi	 * If the value we read from CCSRBARL is not what we expect, then
50519e43841STimur Tabi	 * enter an infinite loop.  This will at least allow a debugger to
50619e43841STimur Tabi	 * halt execution and examine TLBs, etc.  There's no point in going
50719e43841STimur Tabi	 * on.
50819e43841STimur Tabi	 */
50919e43841STimur Tabiinfinite_debug_loop:
51019e43841STimur Tabi	bne	infinite_debug_loop
51119e43841STimur Tabi
5126ca88b09STimur Tabi#ifdef CONFIG_FSL_CORENET
5136ca88b09STimur Tabi
5146ca88b09STimur Tabi#define CCSR_LAWBARH0	(CONFIG_SYS_CCSRBAR + 0x1000)
5156ca88b09STimur Tabi#define LAW_EN		0x80000000
5166ca88b09STimur Tabi#define LAW_SIZE_4K	0xb
5176ca88b09STimur Tabi#define CCSRBAR_LAWAR	(LAW_EN | (0x1e << 20) | LAW_SIZE_4K)
5186ca88b09STimur Tabi#define CCSRAR_C	0x80000000	/* Commit */
5196ca88b09STimur Tabi
5206ca88b09STimur Tabicreate_temp_law:
5216ca88b09STimur Tabi	/*
5226ca88b09STimur Tabi	 * On CoreNet systems, we create the temporary LAW using a special LAW
5236ca88b09STimur Tabi	 * target ID of 0x1e.  LAWBARH is at offset 0xc00 in CCSR.
5246ca88b09STimur Tabi	 */
5256ca88b09STimur Tabi	lis     r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
5266ca88b09STimur Tabi	ori     r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
5276ca88b09STimur Tabi	lis     r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
5286ca88b09STimur Tabi	ori     r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
5296ca88b09STimur Tabi	lis     r2, CCSRBAR_LAWAR@h
5306ca88b09STimur Tabi	ori     r2, r2, CCSRBAR_LAWAR@l
5316ca88b09STimur Tabi
5326ca88b09STimur Tabi	stw     r0, 0xc00(r9)	/* LAWBARH0 */
5336ca88b09STimur Tabi	stw     r1, 0xc04(r9)	/* LAWBARL0 */
5346ca88b09STimur Tabi	sync
5356ca88b09STimur Tabi	stw     r2, 0xc08(r9)	/* LAWAR0 */
5366ca88b09STimur Tabi
5376ca88b09STimur Tabi	/*
5386ca88b09STimur Tabi	 * Read back from LAWAR to ensure the update is complete.  e500mc
5396ca88b09STimur Tabi	 * cores also require an isync.
5406ca88b09STimur Tabi	 */
5416ca88b09STimur Tabi	lwz	r0, 0xc08(r9)	/* LAWAR0 */
5426ca88b09STimur Tabi	isync
5436ca88b09STimur Tabi
5446ca88b09STimur Tabi	/*
5456ca88b09STimur Tabi	 * Read the current CCSRBARH and CCSRBARL using load word instructions.
5466ca88b09STimur Tabi	 * Follow this with an isync instruction. This forces any outstanding
5476ca88b09STimur Tabi	 * accesses to configuration space to completion.
5486ca88b09STimur Tabi	 */
5496ca88b09STimur Tabiread_old_ccsrbar:
5506ca88b09STimur Tabi	lwz	r0, 0(r9)	/* CCSRBARH */
551c2efa0aaSTimur Tabi	lwz	r0, 4(r9)	/* CCSRBARL */
5526ca88b09STimur Tabi	isync
5536ca88b09STimur Tabi
5546ca88b09STimur Tabi	/*
5556ca88b09STimur Tabi	 * Write the new values for CCSRBARH and CCSRBARL to their old
5566ca88b09STimur Tabi	 * locations.  The CCSRBARH has a shadow register. When the CCSRBARH
5576ca88b09STimur Tabi	 * has a new value written it loads a CCSRBARH shadow register. When
5586ca88b09STimur Tabi	 * the CCSRBARL is written, the CCSRBARH shadow register contents
5596ca88b09STimur Tabi	 * along with the CCSRBARL value are loaded into the CCSRBARH and
5606ca88b09STimur Tabi	 * CCSRBARL registers, respectively.  Follow this with a sync
5616ca88b09STimur Tabi	 * instruction.
5626ca88b09STimur Tabi	 */
5636ca88b09STimur Tabiwrite_new_ccsrbar:
5646ca88b09STimur Tabi	lis	r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
5656ca88b09STimur Tabi	ori	r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
5666ca88b09STimur Tabi	lis	r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
5676ca88b09STimur Tabi	ori	r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
5686ca88b09STimur Tabi	lis	r2, CCSRAR_C@h
5696ca88b09STimur Tabi	ori	r2, r2, CCSRAR_C@l
5706ca88b09STimur Tabi
5716ca88b09STimur Tabi	stw	r0, 0(r9)	/* Write to CCSRBARH */
5726ca88b09STimur Tabi	sync			/* Make sure we write to CCSRBARH first */
5736ca88b09STimur Tabi	stw	r1, 4(r9)	/* Write to CCSRBARL */
5746ca88b09STimur Tabi	sync
5756ca88b09STimur Tabi
5766ca88b09STimur Tabi	/*
5776ca88b09STimur Tabi	 * Write a 1 to the commit bit (C) of CCSRAR at the old location.
5786ca88b09STimur Tabi	 * Follow this with a sync instruction.
5796ca88b09STimur Tabi	 */
5806ca88b09STimur Tabi	stw	r2, 8(r9)
5816ca88b09STimur Tabi	sync
5826ca88b09STimur Tabi
5836ca88b09STimur Tabi	/* Delete the temporary LAW */
5846ca88b09STimur Tabidelete_temp_law:
5856ca88b09STimur Tabi	li	r1, 0
5866ca88b09STimur Tabi	stw	r1, 0xc08(r8)
5876ca88b09STimur Tabi	sync
5886ca88b09STimur Tabi	stw	r1, 0xc00(r8)
5896ca88b09STimur Tabi	stw	r1, 0xc04(r8)
5906ca88b09STimur Tabi	sync
5916ca88b09STimur Tabi
5926ca88b09STimur Tabi#else /* #ifdef CONFIG_FSL_CORENET */
5936ca88b09STimur Tabi
5946ca88b09STimur Tabiwrite_new_ccsrbar:
5956ca88b09STimur Tabi	/*
5966ca88b09STimur Tabi	 * Read the current value of CCSRBAR using a load word instruction
5976ca88b09STimur Tabi	 * followed by an isync. This forces all accesses to configuration
5986ca88b09STimur Tabi	 * space to complete.
5996ca88b09STimur Tabi	 */
6006ca88b09STimur Tabi	sync
6016ca88b09STimur Tabi	lwz	r0, 0(r9)
6026ca88b09STimur Tabi	isync
6036ca88b09STimur Tabi
6046ca88b09STimur Tabi/* CONFIG_SYS_CCSRBAR_PHYS right shifted by 12 */
6056ca88b09STimur Tabi#define CCSRBAR_PHYS_RS12 ((CONFIG_SYS_CCSRBAR_PHYS_HIGH << 20) | \
6066ca88b09STimur Tabi			   (CONFIG_SYS_CCSRBAR_PHYS_LOW >> 12))
6076ca88b09STimur Tabi
6086ca88b09STimur Tabi	/* Write the new value to CCSRBAR. */
6096ca88b09STimur Tabi	lis	r0, CCSRBAR_PHYS_RS12@h
6106ca88b09STimur Tabi	ori	r0, r0, CCSRBAR_PHYS_RS12@l
6116ca88b09STimur Tabi	stw	r0, 0(r9)
6126ca88b09STimur Tabi	sync
6136ca88b09STimur Tabi
6146ca88b09STimur Tabi	/*
6156ca88b09STimur Tabi	 * The manual says to perform a load of an address that does not
6166ca88b09STimur Tabi	 * access configuration space or the on-chip SRAM using an existing TLB,
6176ca88b09STimur Tabi	 * but that doesn't appear to be necessary.  We will do the isync,
6186ca88b09STimur Tabi	 * though.
6196ca88b09STimur Tabi	 */
6206ca88b09STimur Tabi	isync
6216ca88b09STimur Tabi
6226ca88b09STimur Tabi	/*
6236ca88b09STimur Tabi	 * Read the contents of CCSRBAR from its new location, followed by
6246ca88b09STimur Tabi	 * another isync.
6256ca88b09STimur Tabi	 */
6266ca88b09STimur Tabi	lwz	r0, 0(r8)
6276ca88b09STimur Tabi	isync
6286ca88b09STimur Tabi
6296ca88b09STimur Tabi#endif  /* #ifdef CONFIG_FSL_CORENET */
6306ca88b09STimur Tabi
6316ca88b09STimur Tabi	/* Delete the temporary TLBs */
6326ca88b09STimur Tabidelete_temp_tlbs:
6336ca88b09STimur Tabi	lis     r0, FSL_BOOKE_MAS0(0, 0, 0)@h
6346ca88b09STimur Tabi	ori     r0, r0, FSL_BOOKE_MAS0(0, 0, 0)@l
6356ca88b09STimur Tabi	li	r1, 0
6366ca88b09STimur Tabi	lis     r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, (MAS2_I|MAS2_G))@h
6376ca88b09STimur Tabi	ori     r2, r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, (MAS2_I|MAS2_G))@l
6386ca88b09STimur Tabi	mtspr   MAS0, r0
6396ca88b09STimur Tabi	mtspr   MAS1, r1
6406ca88b09STimur Tabi	mtspr   MAS2, r2
6416ca88b09STimur Tabi	isync
6426ca88b09STimur Tabi	msync
6436ca88b09STimur Tabi	tlbwe
6446ca88b09STimur Tabi
6456ca88b09STimur Tabi	lis     r0, FSL_BOOKE_MAS0(0, 1, 0)@h
6466ca88b09STimur Tabi	ori     r0, r0, FSL_BOOKE_MAS0(0, 1, 0)@l
6476ca88b09STimur Tabi	lis     r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR + 0x1000, (MAS2_I|MAS2_G))@h
6486ca88b09STimur Tabi	ori     r2, r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR + 0x1000, (MAS2_I|MAS2_G))@l
6496ca88b09STimur Tabi	mtspr   MAS0, r0
6506ca88b09STimur Tabi	mtspr   MAS2, r2
6516ca88b09STimur Tabi	isync
6526ca88b09STimur Tabi	msync
6536ca88b09STimur Tabi	tlbwe
6546ca88b09STimur Tabi#endif /* #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS) */
6556ca88b09STimur Tabi
6566ca88b09STimur Tabicreate_init_ram_area:
657a47a12beSStefan Roese	lis     r6,FSL_BOOKE_MAS0(1, 15, 0)@h
658a47a12beSStefan Roese	ori     r6,r6,FSL_BOOKE_MAS0(1, 15, 0)@l
659a47a12beSStefan Roese
6607065b7d4SRuchika Gupta#if !defined(CONFIG_SYS_RAMBOOT) && !defined(CONFIG_SECURE_BOOT)
661a47a12beSStefan Roese	/* create a temp mapping in AS=1 to the 4M boot window */
662a47a12beSStefan Roese	lis     r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_4M)@h
663a47a12beSStefan Roese	ori     r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_4M)@l
664a47a12beSStefan Roese
6650635b09cSHaiying Wang	lis     r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE & 0xffc00000, (MAS2_I|MAS2_G))@h
6660635b09cSHaiying Wang	ori     r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE & 0xffc00000, (MAS2_I|MAS2_G))@l
667a47a12beSStefan Roese
668a47a12beSStefan Roese	/* The 85xx has the default boot window 0xff800000 - 0xffffffff */
669a47a12beSStefan Roese	lis     r9,FSL_BOOKE_MAS3(0xffc00000, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
670a47a12beSStefan Roese	ori     r9,r9,FSL_BOOKE_MAS3(0xffc00000, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
6717065b7d4SRuchika Gupta#elif !defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SECURE_BOOT)
6727065b7d4SRuchika Gupta	/* create a temp mapping in AS = 1 for Flash mapping
6737065b7d4SRuchika Gupta	 * created by PBL for ISBC code
6747065b7d4SRuchika Gupta	*/
6757065b7d4SRuchika Gupta	lis     r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@h
6767065b7d4SRuchika Gupta	ori     r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@l
6777065b7d4SRuchika Gupta
6787065b7d4SRuchika Gupta	lis     r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE, (MAS2_I|MAS2_G))@h
6797065b7d4SRuchika Gupta	ori     r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE, (MAS2_I|MAS2_G))@l
6807065b7d4SRuchika Gupta
6817065b7d4SRuchika Gupta	lis     r9,FSL_BOOKE_MAS3(CONFIG_SYS_PBI_FLASH_WINDOW, 0,
6827065b7d4SRuchika Gupta						(MAS3_SX|MAS3_SW|MAS3_SR))@h
6837065b7d4SRuchika Gupta	ori     r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_PBI_FLASH_WINDOW, 0,
6847065b7d4SRuchika Gupta						(MAS3_SX|MAS3_SW|MAS3_SR))@l
685a47a12beSStefan Roese#else
686a47a12beSStefan Roese	/*
6870635b09cSHaiying Wang	 * create a temp mapping in AS=1 to the 1M CONFIG_SYS_MONITOR_BASE space, the main
6880635b09cSHaiying Wang	 * image has been relocated to CONFIG_SYS_MONITOR_BASE on the second stage.
689a47a12beSStefan Roese	 */
690a47a12beSStefan Roese	lis     r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@h
691a47a12beSStefan Roese	ori     r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@l
692a47a12beSStefan Roese
6930635b09cSHaiying Wang	lis     r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE, (MAS2_I|MAS2_G))@h
6940635b09cSHaiying Wang	ori     r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE, (MAS2_I|MAS2_G))@l
695a47a12beSStefan Roese
6960635b09cSHaiying Wang	lis     r9,FSL_BOOKE_MAS3(CONFIG_SYS_MONITOR_BASE, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
6970635b09cSHaiying Wang	ori     r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_MONITOR_BASE, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
698a47a12beSStefan Roese#endif
699a47a12beSStefan Roese
700a47a12beSStefan Roese	mtspr   MAS0,r6
701a47a12beSStefan Roese	mtspr   MAS1,r7
702a47a12beSStefan Roese	mtspr   MAS2,r8
703a47a12beSStefan Roese	mtspr   MAS3,r9
704a47a12beSStefan Roese	isync
705a47a12beSStefan Roese	msync
706a47a12beSStefan Roese	tlbwe
707a47a12beSStefan Roese
708a47a12beSStefan Roese	/* create a temp mapping in AS=1 to the stack */
709a47a12beSStefan Roese	lis     r6,FSL_BOOKE_MAS0(1, 14, 0)@h
710a47a12beSStefan Roese	ori     r6,r6,FSL_BOOKE_MAS0(1, 14, 0)@l
711a47a12beSStefan Roese
712a47a12beSStefan Roese	lis     r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16K)@h
713a47a12beSStefan Roese	ori     r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16K)@l
714a47a12beSStefan Roese
715a47a12beSStefan Roese	lis     r8,FSL_BOOKE_MAS2(CONFIG_SYS_INIT_RAM_ADDR, 0)@h
716a47a12beSStefan Roese	ori     r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_INIT_RAM_ADDR, 0)@l
717a47a12beSStefan Roese
718a3f18529Syork#if defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW) && \
719a3f18529Syork    defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH)
720a3f18529Syork	lis     r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, 0,
721a3f18529Syork				(MAS3_SX|MAS3_SW|MAS3_SR))@h
722a3f18529Syork	ori     r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, 0,
723a3f18529Syork				(MAS3_SX|MAS3_SW|MAS3_SR))@l
724a3f18529Syork	li      r10,CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH
725a3f18529Syork	mtspr	MAS7,r10
726a3f18529Syork#else
727a47a12beSStefan Roese	lis     r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
728a47a12beSStefan Roese	ori     r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
729a3f18529Syork#endif
730a47a12beSStefan Roese
731a47a12beSStefan Roese	mtspr   MAS0,r6
732a47a12beSStefan Roese	mtspr   MAS1,r7
733a47a12beSStefan Roese	mtspr   MAS2,r8
734a47a12beSStefan Roese	mtspr   MAS3,r9
735a47a12beSStefan Roese	isync
736a47a12beSStefan Roese	msync
737a47a12beSStefan Roese	tlbwe
738a47a12beSStefan Roese
739*5344f7a2SPrabhakar Kushwaha	lis	r6,MSR_IS|MSR_DS|MSR_DE@h
740*5344f7a2SPrabhakar Kushwaha	ori	r6,r6,MSR_IS|MSR_DS|MSR_DE@l
741a47a12beSStefan Roese	lis	r7,switch_as@h
742a47a12beSStefan Roese	ori	r7,r7,switch_as@l
743a47a12beSStefan Roese
744a47a12beSStefan Roese	mtspr	SPRN_SRR0,r7
745a47a12beSStefan Roese	mtspr	SPRN_SRR1,r6
746a47a12beSStefan Roese	rfi
747a47a12beSStefan Roese
748a47a12beSStefan Roeseswitch_as:
749a47a12beSStefan Roese/* L1 DCache is used for initial RAM */
750a47a12beSStefan Roese
751a47a12beSStefan Roese	/* Allocate Initial RAM in data cache.
752a47a12beSStefan Roese	 */
753a47a12beSStefan Roese	lis	r3,CONFIG_SYS_INIT_RAM_ADDR@h
754a47a12beSStefan Roese	ori	r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
755a47a12beSStefan Roese	mfspr	r2, L1CFG0
756a47a12beSStefan Roese	andi.	r2, r2, 0x1ff
757a47a12beSStefan Roese	/* cache size * 1024 / (2 * L1 line size) */
758a47a12beSStefan Roese	slwi	r2, r2, (10 - 1 - L1_CACHE_SHIFT)
759a47a12beSStefan Roese	mtctr	r2
760a47a12beSStefan Roese	li	r0,0
761a47a12beSStefan Roese1:
762a47a12beSStefan Roese	dcbz	r0,r3
763a47a12beSStefan Roese	dcbtls	0,r0,r3
764a47a12beSStefan Roese	addi	r3,r3,CONFIG_SYS_CACHELINE_SIZE
765a47a12beSStefan Roese	bdnz	1b
766a47a12beSStefan Roese
767a47a12beSStefan Roese	/* Jump out the last 4K page and continue to 'normal' start */
768a47a12beSStefan Roese#ifdef CONFIG_SYS_RAMBOOT
769a47a12beSStefan Roese	b	_start_cont
770a47a12beSStefan Roese#else
771a47a12beSStefan Roese	/* Calculate absolute address in FLASH and jump there		*/
772a47a12beSStefan Roese	/*--------------------------------------------------------------*/
773a47a12beSStefan Roese	lis	r3,CONFIG_SYS_MONITOR_BASE@h
774a47a12beSStefan Roese	ori	r3,r3,CONFIG_SYS_MONITOR_BASE@l
775a47a12beSStefan Roese	addi	r3,r3,_start_cont - _start + _START_OFFSET
776a47a12beSStefan Roese	mtlr	r3
777a47a12beSStefan Roese	blr
778a47a12beSStefan Roese#endif
779a47a12beSStefan Roese
780a47a12beSStefan Roese	.text
781a47a12beSStefan Roese	.globl	_start
782a47a12beSStefan Roese_start:
783a47a12beSStefan Roese	.long	0x27051956		/* U-BOOT Magic Number */
784a47a12beSStefan Roese	.globl	version_string
785a47a12beSStefan Roeseversion_string:
78609c2e90cSAndreas Bießmann	.ascii U_BOOT_VERSION_STRING, "\0"
787a47a12beSStefan Roese
788a47a12beSStefan Roese	.align	4
789a47a12beSStefan Roese	.globl	_start_cont
790a47a12beSStefan Roese_start_cont:
791a47a12beSStefan Roese	/* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
792a47a12beSStefan Roese	lis	r1,CONFIG_SYS_INIT_RAM_ADDR@h
793a47a12beSStefan Roese	ori	r1,r1,CONFIG_SYS_INIT_SP_OFFSET@l
794a47a12beSStefan Roese
795a47a12beSStefan Roese	li	r0,0
796a47a12beSStefan Roese	stwu	r0,-4(r1)
797a47a12beSStefan Roese	stwu	r0,-4(r1)		/* Terminate call chain */
798a47a12beSStefan Roese
799a47a12beSStefan Roese	stwu	r1,-8(r1)		/* Save back chain and move SP */
800a47a12beSStefan Roese	lis	r0,RESET_VECTOR@h	/* Address of reset vector */
801a47a12beSStefan Roese	ori	r0,r0,RESET_VECTOR@l
802a47a12beSStefan Roese	stwu	r1,-8(r1)		/* Save back chain and move SP */
803a47a12beSStefan Roese	stw	r0,+12(r1)		/* Save return addr (underflow vect) */
804a47a12beSStefan Roese
805a47a12beSStefan Roese	GET_GOT
806a47a12beSStefan Roese	bl	cpu_init_early_f
807a47a12beSStefan Roese
808a47a12beSStefan Roese	/* switch back to AS = 0 */
809a47a12beSStefan Roese	lis	r3,(MSR_CE|MSR_ME|MSR_DE)@h
810a47a12beSStefan Roese	ori	r3,r3,(MSR_CE|MSR_ME|MSR_DE)@l
811a47a12beSStefan Roese	mtmsr	r3
812a47a12beSStefan Roese	isync
813a47a12beSStefan Roese
814a47a12beSStefan Roese	bl	cpu_init_f
815a47a12beSStefan Roese	bl	board_init_f
816a47a12beSStefan Roese	isync
817a47a12beSStefan Roese
81852ebd9c1SPeter Tyser	/* NOTREACHED - board_init_f() does not return */
81952ebd9c1SPeter Tyser
820a47a12beSStefan Roese#ifndef CONFIG_NAND_SPL
821a47a12beSStefan Roese	. = EXC_OFF_SYS_RESET
822a47a12beSStefan Roese	.globl	_start_of_vectors
823a47a12beSStefan Roese_start_of_vectors:
824a47a12beSStefan Roese
825a47a12beSStefan Roese/* Critical input. */
826a47a12beSStefan Roese	CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException)
827a47a12beSStefan Roese
828a47a12beSStefan Roese/* Machine check */
829a47a12beSStefan Roese	MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
830a47a12beSStefan Roese
831a47a12beSStefan Roese/* Data Storage exception. */
832a47a12beSStefan Roese	STD_EXCEPTION(0x0300, DataStorage, UnknownException)
833a47a12beSStefan Roese
834a47a12beSStefan Roese/* Instruction Storage exception. */
835a47a12beSStefan Roese	STD_EXCEPTION(0x0400, InstStorage, UnknownException)
836a47a12beSStefan Roese
837a47a12beSStefan Roese/* External Interrupt exception. */
838a47a12beSStefan Roese	STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException)
839a47a12beSStefan Roese
840a47a12beSStefan Roese/* Alignment exception. */
841a47a12beSStefan Roese	. = 0x0600
842a47a12beSStefan RoeseAlignment:
843a47a12beSStefan Roese	EXCEPTION_PROLOG(SRR0, SRR1)
844a47a12beSStefan Roese	mfspr	r4,DAR
845a47a12beSStefan Roese	stw	r4,_DAR(r21)
846a47a12beSStefan Roese	mfspr	r5,DSISR
847a47a12beSStefan Roese	stw	r5,_DSISR(r21)
848a47a12beSStefan Roese	addi	r3,r1,STACK_FRAME_OVERHEAD
849a47a12beSStefan Roese	EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
850a47a12beSStefan Roese
851a47a12beSStefan Roese/* Program check exception */
852a47a12beSStefan Roese	. = 0x0700
853a47a12beSStefan RoeseProgramCheck:
854a47a12beSStefan Roese	EXCEPTION_PROLOG(SRR0, SRR1)
855a47a12beSStefan Roese	addi	r3,r1,STACK_FRAME_OVERHEAD
856a47a12beSStefan Roese	EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
857a47a12beSStefan Roese		MSR_KERNEL, COPY_EE)
858a47a12beSStefan Roese
859a47a12beSStefan Roese	/* No FPU on MPC85xx.  This exception is not supposed to happen.
860a47a12beSStefan Roese	*/
861a47a12beSStefan Roese	STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
862a47a12beSStefan Roese
863a47a12beSStefan Roese	. = 0x0900
864a47a12beSStefan Roese/*
865a47a12beSStefan Roese * r0 - SYSCALL number
866a47a12beSStefan Roese * r3-... arguments
867a47a12beSStefan Roese */
868a47a12beSStefan RoeseSystemCall:
869a47a12beSStefan Roese	addis	r11,r0,0	/* get functions table addr */
870a47a12beSStefan Roese	ori	r11,r11,0	/* Note: this code is patched in trap_init */
871a47a12beSStefan Roese	addis	r12,r0,0	/* get number of functions */
872a47a12beSStefan Roese	ori	r12,r12,0
873a47a12beSStefan Roese
874a47a12beSStefan Roese	cmplw	0,r0,r12
875a47a12beSStefan Roese	bge	1f
876a47a12beSStefan Roese
877a47a12beSStefan Roese	rlwinm	r0,r0,2,0,31	/* fn_addr = fn_tbl[r0] */
878a47a12beSStefan Roese	add	r11,r11,r0
879a47a12beSStefan Roese	lwz	r11,0(r11)
880a47a12beSStefan Roese
881a47a12beSStefan Roese	li	r20,0xd00-4	/* Get stack pointer */
882a47a12beSStefan Roese	lwz	r12,0(r20)
883a47a12beSStefan Roese	subi	r12,r12,12	/* Adjust stack pointer */
884a47a12beSStefan Roese	li	r0,0xc00+_end_back-SystemCall
885a47a12beSStefan Roese	cmplw	0,r0,r12	/* Check stack overflow */
886a47a12beSStefan Roese	bgt	1f
887a47a12beSStefan Roese	stw	r12,0(r20)
888a47a12beSStefan Roese
889a47a12beSStefan Roese	mflr	r0
890a47a12beSStefan Roese	stw	r0,0(r12)
891a47a12beSStefan Roese	mfspr	r0,SRR0
892a47a12beSStefan Roese	stw	r0,4(r12)
893a47a12beSStefan Roese	mfspr	r0,SRR1
894a47a12beSStefan Roese	stw	r0,8(r12)
895a47a12beSStefan Roese
896a47a12beSStefan Roese	li	r12,0xc00+_back-SystemCall
897a47a12beSStefan Roese	mtlr	r12
898a47a12beSStefan Roese	mtspr	SRR0,r11
899a47a12beSStefan Roese
900a47a12beSStefan Roese1:	SYNC
901a47a12beSStefan Roese	rfi
902a47a12beSStefan Roese_back:
903a47a12beSStefan Roese
904a47a12beSStefan Roese	mfmsr	r11			/* Disable interrupts */
905a47a12beSStefan Roese	li	r12,0
906a47a12beSStefan Roese	ori	r12,r12,MSR_EE
907a47a12beSStefan Roese	andc	r11,r11,r12
908a47a12beSStefan Roese	SYNC				/* Some chip revs need this... */
909a47a12beSStefan Roese	mtmsr	r11
910a47a12beSStefan Roese	SYNC
911a47a12beSStefan Roese
912a47a12beSStefan Roese	li	r12,0xd00-4		/* restore regs */
913a47a12beSStefan Roese	lwz	r12,0(r12)
914a47a12beSStefan Roese
915a47a12beSStefan Roese	lwz	r11,0(r12)
916a47a12beSStefan Roese	mtlr	r11
917a47a12beSStefan Roese	lwz	r11,4(r12)
918a47a12beSStefan Roese	mtspr	SRR0,r11
919a47a12beSStefan Roese	lwz	r11,8(r12)
920a47a12beSStefan Roese	mtspr	SRR1,r11
921a47a12beSStefan Roese
922a47a12beSStefan Roese	addi	r12,r12,12		/* Adjust stack pointer */
923a47a12beSStefan Roese	li	r20,0xd00-4
924a47a12beSStefan Roese	stw	r12,0(r20)
925a47a12beSStefan Roese
926a47a12beSStefan Roese	SYNC
927a47a12beSStefan Roese	rfi
928a47a12beSStefan Roese_end_back:
929a47a12beSStefan Roese
930a47a12beSStefan Roese	STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
931a47a12beSStefan Roese	STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
932a47a12beSStefan Roese	STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
933a47a12beSStefan Roese
934a47a12beSStefan Roese	STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
935a47a12beSStefan Roese	STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
936a47a12beSStefan Roese
937a47a12beSStefan Roese	CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
938a47a12beSStefan Roese
939a47a12beSStefan Roese	.globl	_end_of_vectors
940a47a12beSStefan Roese_end_of_vectors:
941a47a12beSStefan Roese
942a47a12beSStefan Roese
943a47a12beSStefan Roese	. = . + (0x100 - ( . & 0xff ))	/* align for debug */
944a47a12beSStefan Roese
945a47a12beSStefan Roese/*
946a47a12beSStefan Roese * This code finishes saving the registers to the exception frame
947a47a12beSStefan Roese * and jumps to the appropriate handler for the exception.
948a47a12beSStefan Roese * Register r21 is pointer into trap frame, r1 has new stack pointer.
949a47a12beSStefan Roese */
950a47a12beSStefan Roese	.globl	transfer_to_handler
951a47a12beSStefan Roesetransfer_to_handler:
952a47a12beSStefan Roese	stw	r22,_NIP(r21)
953a47a12beSStefan Roese	lis	r22,MSR_POW@h
954a47a12beSStefan Roese	andc	r23,r23,r22
955a47a12beSStefan Roese	stw	r23,_MSR(r21)
956a47a12beSStefan Roese	SAVE_GPR(7, r21)
957a47a12beSStefan Roese	SAVE_4GPRS(8, r21)
958a47a12beSStefan Roese	SAVE_8GPRS(12, r21)
959a47a12beSStefan Roese	SAVE_8GPRS(24, r21)
960a47a12beSStefan Roese
961a47a12beSStefan Roese	mflr	r23
962a47a12beSStefan Roese	andi.	r24,r23,0x3f00		/* get vector offset */
963a47a12beSStefan Roese	stw	r24,TRAP(r21)
964a47a12beSStefan Roese	li	r22,0
965a47a12beSStefan Roese	stw	r22,RESULT(r21)
966a47a12beSStefan Roese	mtspr	SPRG2,r22		/* r1 is now kernel sp */
967a47a12beSStefan Roese
968a47a12beSStefan Roese	lwz	r24,0(r23)		/* virtual address of handler */
969a47a12beSStefan Roese	lwz	r23,4(r23)		/* where to go when done */
970a47a12beSStefan Roese	mtspr	SRR0,r24
971a47a12beSStefan Roese	mtspr	SRR1,r20
972a47a12beSStefan Roese	mtlr	r23
973a47a12beSStefan Roese	SYNC
974a47a12beSStefan Roese	rfi				/* jump to handler, enable MMU */
975a47a12beSStefan Roese
976a47a12beSStefan Roeseint_return:
977a47a12beSStefan Roese	mfmsr	r28		/* Disable interrupts */
978a47a12beSStefan Roese	li	r4,0
979a47a12beSStefan Roese	ori	r4,r4,MSR_EE
980a47a12beSStefan Roese	andc	r28,r28,r4
981a47a12beSStefan Roese	SYNC			/* Some chip revs need this... */
982a47a12beSStefan Roese	mtmsr	r28
983a47a12beSStefan Roese	SYNC
984a47a12beSStefan Roese	lwz	r2,_CTR(r1)
985a47a12beSStefan Roese	lwz	r0,_LINK(r1)
986a47a12beSStefan Roese	mtctr	r2
987a47a12beSStefan Roese	mtlr	r0
988a47a12beSStefan Roese	lwz	r2,_XER(r1)
989a47a12beSStefan Roese	lwz	r0,_CCR(r1)
990a47a12beSStefan Roese	mtspr	XER,r2
991a47a12beSStefan Roese	mtcrf	0xFF,r0
992a47a12beSStefan Roese	REST_10GPRS(3, r1)
993a47a12beSStefan Roese	REST_10GPRS(13, r1)
994a47a12beSStefan Roese	REST_8GPRS(23, r1)
995a47a12beSStefan Roese	REST_GPR(31, r1)
996a47a12beSStefan Roese	lwz	r2,_NIP(r1)	/* Restore environment */
997a47a12beSStefan Roese	lwz	r0,_MSR(r1)
998a47a12beSStefan Roese	mtspr	SRR0,r2
999a47a12beSStefan Roese	mtspr	SRR1,r0
1000a47a12beSStefan Roese	lwz	r0,GPR0(r1)
1001a47a12beSStefan Roese	lwz	r2,GPR2(r1)
1002a47a12beSStefan Roese	lwz	r1,GPR1(r1)
1003a47a12beSStefan Roese	SYNC
1004a47a12beSStefan Roese	rfi
1005a47a12beSStefan Roese
1006a47a12beSStefan Roesecrit_return:
1007a47a12beSStefan Roese	mfmsr	r28		/* Disable interrupts */
1008a47a12beSStefan Roese	li	r4,0
1009a47a12beSStefan Roese	ori	r4,r4,MSR_EE
1010a47a12beSStefan Roese	andc	r28,r28,r4
1011a47a12beSStefan Roese	SYNC			/* Some chip revs need this... */
1012a47a12beSStefan Roese	mtmsr	r28
1013a47a12beSStefan Roese	SYNC
1014a47a12beSStefan Roese	lwz	r2,_CTR(r1)
1015a47a12beSStefan Roese	lwz	r0,_LINK(r1)
1016a47a12beSStefan Roese	mtctr	r2
1017a47a12beSStefan Roese	mtlr	r0
1018a47a12beSStefan Roese	lwz	r2,_XER(r1)
1019a47a12beSStefan Roese	lwz	r0,_CCR(r1)
1020a47a12beSStefan Roese	mtspr	XER,r2
1021a47a12beSStefan Roese	mtcrf	0xFF,r0
1022a47a12beSStefan Roese	REST_10GPRS(3, r1)
1023a47a12beSStefan Roese	REST_10GPRS(13, r1)
1024a47a12beSStefan Roese	REST_8GPRS(23, r1)
1025a47a12beSStefan Roese	REST_GPR(31, r1)
1026a47a12beSStefan Roese	lwz	r2,_NIP(r1)	/* Restore environment */
1027a47a12beSStefan Roese	lwz	r0,_MSR(r1)
1028a47a12beSStefan Roese	mtspr	SPRN_CSRR0,r2
1029a47a12beSStefan Roese	mtspr	SPRN_CSRR1,r0
1030a47a12beSStefan Roese	lwz	r0,GPR0(r1)
1031a47a12beSStefan Roese	lwz	r2,GPR2(r1)
1032a47a12beSStefan Roese	lwz	r1,GPR1(r1)
1033a47a12beSStefan Roese	SYNC
1034a47a12beSStefan Roese	rfci
1035a47a12beSStefan Roese
1036a47a12beSStefan Roesemck_return:
1037a47a12beSStefan Roese	mfmsr	r28		/* Disable interrupts */
1038a47a12beSStefan Roese	li	r4,0
1039a47a12beSStefan Roese	ori	r4,r4,MSR_EE
1040a47a12beSStefan Roese	andc	r28,r28,r4
1041a47a12beSStefan Roese	SYNC			/* Some chip revs need this... */
1042a47a12beSStefan Roese	mtmsr	r28
1043a47a12beSStefan Roese	SYNC
1044a47a12beSStefan Roese	lwz	r2,_CTR(r1)
1045a47a12beSStefan Roese	lwz	r0,_LINK(r1)
1046a47a12beSStefan Roese	mtctr	r2
1047a47a12beSStefan Roese	mtlr	r0
1048a47a12beSStefan Roese	lwz	r2,_XER(r1)
1049a47a12beSStefan Roese	lwz	r0,_CCR(r1)
1050a47a12beSStefan Roese	mtspr	XER,r2
1051a47a12beSStefan Roese	mtcrf	0xFF,r0
1052a47a12beSStefan Roese	REST_10GPRS(3, r1)
1053a47a12beSStefan Roese	REST_10GPRS(13, r1)
1054a47a12beSStefan Roese	REST_8GPRS(23, r1)
1055a47a12beSStefan Roese	REST_GPR(31, r1)
1056a47a12beSStefan Roese	lwz	r2,_NIP(r1)	/* Restore environment */
1057a47a12beSStefan Roese	lwz	r0,_MSR(r1)
1058a47a12beSStefan Roese	mtspr	SPRN_MCSRR0,r2
1059a47a12beSStefan Roese	mtspr	SPRN_MCSRR1,r0
1060a47a12beSStefan Roese	lwz	r0,GPR0(r1)
1061a47a12beSStefan Roese	lwz	r2,GPR2(r1)
1062a47a12beSStefan Roese	lwz	r1,GPR1(r1)
1063a47a12beSStefan Roese	SYNC
1064a47a12beSStefan Roese	rfmci
1065a47a12beSStefan Roese
1066a47a12beSStefan Roese/* Cache functions.
1067a47a12beSStefan Roese*/
10680a9fe8eeSMatthew McClintock.globl flush_icache
10690a9fe8eeSMatthew McClintockflush_icache:
1070a47a12beSStefan Roese.globl invalidate_icache
1071a47a12beSStefan Roeseinvalidate_icache:
1072a47a12beSStefan Roese	mfspr	r0,L1CSR1
1073a47a12beSStefan Roese	ori	r0,r0,L1CSR1_ICFI
1074a47a12beSStefan Roese	msync
1075a47a12beSStefan Roese	isync
1076a47a12beSStefan Roese	mtspr	L1CSR1,r0
1077a47a12beSStefan Roese	isync
1078a47a12beSStefan Roese	blr				/* entire I cache */
1079a47a12beSStefan Roese
1080a47a12beSStefan Roese.globl invalidate_dcache
1081a47a12beSStefan Roeseinvalidate_dcache:
1082a47a12beSStefan Roese	mfspr	r0,L1CSR0
1083a47a12beSStefan Roese	ori	r0,r0,L1CSR0_DCFI
1084a47a12beSStefan Roese	msync
1085a47a12beSStefan Roese	isync
1086a47a12beSStefan Roese	mtspr	L1CSR0,r0
1087a47a12beSStefan Roese	isync
1088a47a12beSStefan Roese	blr
1089a47a12beSStefan Roese
1090a47a12beSStefan Roese	.globl	icache_enable
1091a47a12beSStefan Roeseicache_enable:
1092a47a12beSStefan Roese	mflr	r8
1093a47a12beSStefan Roese	bl	invalidate_icache
1094a47a12beSStefan Roese	mtlr	r8
1095a47a12beSStefan Roese	isync
1096a47a12beSStefan Roese	mfspr	r4,L1CSR1
1097a47a12beSStefan Roese	ori	r4,r4,0x0001
1098a47a12beSStefan Roese	oris	r4,r4,0x0001
1099a47a12beSStefan Roese	mtspr	L1CSR1,r4
1100a47a12beSStefan Roese	isync
1101a47a12beSStefan Roese	blr
1102a47a12beSStefan Roese
1103a47a12beSStefan Roese	.globl	icache_disable
1104a47a12beSStefan Roeseicache_disable:
1105a47a12beSStefan Roese	mfspr	r0,L1CSR1
1106a47a12beSStefan Roese	lis	r3,0
1107a47a12beSStefan Roese	ori	r3,r3,L1CSR1_ICE
1108a47a12beSStefan Roese	andc	r0,r0,r3
1109a47a12beSStefan Roese	mtspr	L1CSR1,r0
1110a47a12beSStefan Roese	isync
1111a47a12beSStefan Roese	blr
1112a47a12beSStefan Roese
1113a47a12beSStefan Roese	.globl	icache_status
1114a47a12beSStefan Roeseicache_status:
1115a47a12beSStefan Roese	mfspr	r3,L1CSR1
1116a47a12beSStefan Roese	andi.	r3,r3,L1CSR1_ICE
1117a47a12beSStefan Roese	blr
1118a47a12beSStefan Roese
1119a47a12beSStefan Roese	.globl	dcache_enable
1120a47a12beSStefan Roesedcache_enable:
1121a47a12beSStefan Roese	mflr	r8
1122a47a12beSStefan Roese	bl	invalidate_dcache
1123a47a12beSStefan Roese	mtlr	r8
1124a47a12beSStefan Roese	isync
1125a47a12beSStefan Roese	mfspr	r0,L1CSR0
1126a47a12beSStefan Roese	ori	r0,r0,0x0001
1127a47a12beSStefan Roese	oris	r0,r0,0x0001
1128a47a12beSStefan Roese	msync
1129a47a12beSStefan Roese	isync
1130a47a12beSStefan Roese	mtspr	L1CSR0,r0
1131a47a12beSStefan Roese	isync
1132a47a12beSStefan Roese	blr
1133a47a12beSStefan Roese
1134a47a12beSStefan Roese	.globl	dcache_disable
1135a47a12beSStefan Roesedcache_disable:
1136a47a12beSStefan Roese	mfspr	r3,L1CSR0
1137a47a12beSStefan Roese	lis	r4,0
1138a47a12beSStefan Roese	ori	r4,r4,L1CSR0_DCE
1139a47a12beSStefan Roese	andc	r3,r3,r4
114045a68135SKumar Gala	mtspr	L1CSR0,r3
1141a47a12beSStefan Roese	isync
1142a47a12beSStefan Roese	blr
1143a47a12beSStefan Roese
1144a47a12beSStefan Roese	.globl	dcache_status
1145a47a12beSStefan Roesedcache_status:
1146a47a12beSStefan Roese	mfspr	r3,L1CSR0
1147a47a12beSStefan Roese	andi.	r3,r3,L1CSR0_DCE
1148a47a12beSStefan Roese	blr
1149a47a12beSStefan Roese
1150a47a12beSStefan Roese	.globl get_pir
1151a47a12beSStefan Roeseget_pir:
1152a47a12beSStefan Roese	mfspr	r3,PIR
1153a47a12beSStefan Roese	blr
1154a47a12beSStefan Roese
1155a47a12beSStefan Roese	.globl get_pvr
1156a47a12beSStefan Roeseget_pvr:
1157a47a12beSStefan Roese	mfspr	r3,PVR
1158a47a12beSStefan Roese	blr
1159a47a12beSStefan Roese
1160a47a12beSStefan Roese	.globl get_svr
1161a47a12beSStefan Roeseget_svr:
1162a47a12beSStefan Roese	mfspr	r3,SVR
1163a47a12beSStefan Roese	blr
1164a47a12beSStefan Roese
1165a47a12beSStefan Roese	.globl wr_tcr
1166a47a12beSStefan Roesewr_tcr:
1167a47a12beSStefan Roese	mtspr	TCR,r3
1168a47a12beSStefan Roese	blr
1169a47a12beSStefan Roese
1170a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1171a47a12beSStefan Roese/* Function:	 in8 */
1172a47a12beSStefan Roese/* Description:	 Input 8 bits */
1173a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1174a47a12beSStefan Roese	.globl	in8
1175a47a12beSStefan Roesein8:
1176a47a12beSStefan Roese	lbz	r3,0x0000(r3)
1177a47a12beSStefan Roese	blr
1178a47a12beSStefan Roese
1179a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1180a47a12beSStefan Roese/* Function:	 out8 */
1181a47a12beSStefan Roese/* Description:	 Output 8 bits */
1182a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1183a47a12beSStefan Roese	.globl	out8
1184a47a12beSStefan Roeseout8:
1185a47a12beSStefan Roese	stb	r4,0x0000(r3)
1186a47a12beSStefan Roese	sync
1187a47a12beSStefan Roese	blr
1188a47a12beSStefan Roese
1189a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1190a47a12beSStefan Roese/* Function:	 out16 */
1191a47a12beSStefan Roese/* Description:	 Output 16 bits */
1192a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1193a47a12beSStefan Roese	.globl	out16
1194a47a12beSStefan Roeseout16:
1195a47a12beSStefan Roese	sth	r4,0x0000(r3)
1196a47a12beSStefan Roese	sync
1197a47a12beSStefan Roese	blr
1198a47a12beSStefan Roese
1199a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1200a47a12beSStefan Roese/* Function:	 out16r */
1201a47a12beSStefan Roese/* Description:	 Byte reverse and output 16 bits */
1202a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1203a47a12beSStefan Roese	.globl	out16r
1204a47a12beSStefan Roeseout16r:
1205a47a12beSStefan Roese	sthbrx	r4,r0,r3
1206a47a12beSStefan Roese	sync
1207a47a12beSStefan Roese	blr
1208a47a12beSStefan Roese
1209a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1210a47a12beSStefan Roese/* Function:	 out32 */
1211a47a12beSStefan Roese/* Description:	 Output 32 bits */
1212a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1213a47a12beSStefan Roese	.globl	out32
1214a47a12beSStefan Roeseout32:
1215a47a12beSStefan Roese	stw	r4,0x0000(r3)
1216a47a12beSStefan Roese	sync
1217a47a12beSStefan Roese	blr
1218a47a12beSStefan Roese
1219a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1220a47a12beSStefan Roese/* Function:	 out32r */
1221a47a12beSStefan Roese/* Description:	 Byte reverse and output 32 bits */
1222a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1223a47a12beSStefan Roese	.globl	out32r
1224a47a12beSStefan Roeseout32r:
1225a47a12beSStefan Roese	stwbrx	r4,r0,r3
1226a47a12beSStefan Roese	sync
1227a47a12beSStefan Roese	blr
1228a47a12beSStefan Roese
1229a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1230a47a12beSStefan Roese/* Function:	 in16 */
1231a47a12beSStefan Roese/* Description:	 Input 16 bits */
1232a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1233a47a12beSStefan Roese	.globl	in16
1234a47a12beSStefan Roesein16:
1235a47a12beSStefan Roese	lhz	r3,0x0000(r3)
1236a47a12beSStefan Roese	blr
1237a47a12beSStefan Roese
1238a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1239a47a12beSStefan Roese/* Function:	 in16r */
1240a47a12beSStefan Roese/* Description:	 Input 16 bits and byte reverse */
1241a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1242a47a12beSStefan Roese	.globl	in16r
1243a47a12beSStefan Roesein16r:
1244a47a12beSStefan Roese	lhbrx	r3,r0,r3
1245a47a12beSStefan Roese	blr
1246a47a12beSStefan Roese
1247a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1248a47a12beSStefan Roese/* Function:	 in32 */
1249a47a12beSStefan Roese/* Description:	 Input 32 bits */
1250a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1251a47a12beSStefan Roese	.globl	in32
1252a47a12beSStefan Roesein32:
1253a47a12beSStefan Roese	lwz	3,0x0000(3)
1254a47a12beSStefan Roese	blr
1255a47a12beSStefan Roese
1256a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1257a47a12beSStefan Roese/* Function:	 in32r */
1258a47a12beSStefan Roese/* Description:	 Input 32 bits and byte reverse */
1259a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1260a47a12beSStefan Roese	.globl	in32r
1261a47a12beSStefan Roesein32r:
1262a47a12beSStefan Roese	lwbrx	r3,r0,r3
1263a47a12beSStefan Roese	blr
1264a47a12beSStefan Roese#endif  /* !CONFIG_NAND_SPL */
1265a47a12beSStefan Roese
1266a47a12beSStefan Roese/*------------------------------------------------------------------------------*/
1267a47a12beSStefan Roese
1268a47a12beSStefan Roese/*
1269a47a12beSStefan Roese * void write_tlb(mas0, mas1, mas2, mas3, mas7)
1270a47a12beSStefan Roese */
1271a47a12beSStefan Roese	.globl	write_tlb
1272a47a12beSStefan Roesewrite_tlb:
1273a47a12beSStefan Roese	mtspr	MAS0,r3
1274a47a12beSStefan Roese	mtspr	MAS1,r4
1275a47a12beSStefan Roese	mtspr	MAS2,r5
1276a47a12beSStefan Roese	mtspr	MAS3,r6
1277a47a12beSStefan Roese#ifdef CONFIG_ENABLE_36BIT_PHYS
1278a47a12beSStefan Roese	mtspr	MAS7,r7
1279a47a12beSStefan Roese#endif
1280a47a12beSStefan Roese	li	r3,0
1281a47a12beSStefan Roese#ifdef CONFIG_SYS_BOOK3E_HV
1282a47a12beSStefan Roese	mtspr	MAS8,r3
1283a47a12beSStefan Roese#endif
1284a47a12beSStefan Roese	isync
1285a47a12beSStefan Roese	tlbwe
1286a47a12beSStefan Roese	msync
1287a47a12beSStefan Roese	isync
1288a47a12beSStefan Roese	blr
1289a47a12beSStefan Roese
1290a47a12beSStefan Roese/*
1291a47a12beSStefan Roese * void relocate_code (addr_sp, gd, addr_moni)
1292a47a12beSStefan Roese *
1293a47a12beSStefan Roese * This "function" does not return, instead it continues in RAM
1294a47a12beSStefan Roese * after relocating the monitor code.
1295a47a12beSStefan Roese *
1296a47a12beSStefan Roese * r3 = dest
1297a47a12beSStefan Roese * r4 = src
1298a47a12beSStefan Roese * r5 = length in bytes
1299a47a12beSStefan Roese * r6 = cachelinesize
1300a47a12beSStefan Roese */
1301a47a12beSStefan Roese	.globl	relocate_code
1302a47a12beSStefan Roeserelocate_code:
1303a47a12beSStefan Roese	mr	r1,r3		/* Set new stack pointer		*/
1304a47a12beSStefan Roese	mr	r9,r4		/* Save copy of Init Data pointer	*/
1305a47a12beSStefan Roese	mr	r10,r5		/* Save copy of Destination Address	*/
1306a47a12beSStefan Roese
1307a47a12beSStefan Roese	GET_GOT
1308a47a12beSStefan Roese	mr	r3,r5				/* Destination Address	*/
1309a47a12beSStefan Roese	lis	r4,CONFIG_SYS_MONITOR_BASE@h		/* Source      Address	*/
1310a47a12beSStefan Roese	ori	r4,r4,CONFIG_SYS_MONITOR_BASE@l
1311a47a12beSStefan Roese	lwz	r5,GOT(__init_end)
1312a47a12beSStefan Roese	sub	r5,r5,r4
1313a47a12beSStefan Roese	li	r6,CONFIG_SYS_CACHELINE_SIZE		/* Cache Line Size	*/
1314a47a12beSStefan Roese
1315a47a12beSStefan Roese	/*
1316a47a12beSStefan Roese	 * Fix GOT pointer:
1317a47a12beSStefan Roese	 *
1318a47a12beSStefan Roese	 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
1319a47a12beSStefan Roese	 *
1320a47a12beSStefan Roese	 * Offset:
1321a47a12beSStefan Roese	 */
1322a47a12beSStefan Roese	sub	r15,r10,r4
1323a47a12beSStefan Roese
1324a47a12beSStefan Roese	/* First our own GOT */
1325a47a12beSStefan Roese	add	r12,r12,r15
1326a47a12beSStefan Roese	/* the the one used by the C code */
1327a47a12beSStefan Roese	add	r30,r30,r15
1328a47a12beSStefan Roese
1329a47a12beSStefan Roese	/*
1330a47a12beSStefan Roese	 * Now relocate code
1331a47a12beSStefan Roese	 */
1332a47a12beSStefan Roese
1333a47a12beSStefan Roese	cmplw	cr1,r3,r4
1334a47a12beSStefan Roese	addi	r0,r5,3
1335a47a12beSStefan Roese	srwi.	r0,r0,2
1336a47a12beSStefan Roese	beq	cr1,4f		/* In place copy is not necessary	*/
1337a47a12beSStefan Roese	beq	7f		/* Protect against 0 count		*/
1338a47a12beSStefan Roese	mtctr	r0
1339a47a12beSStefan Roese	bge	cr1,2f
1340a47a12beSStefan Roese
1341a47a12beSStefan Roese	la	r8,-4(r4)
1342a47a12beSStefan Roese	la	r7,-4(r3)
1343a47a12beSStefan Roese1:	lwzu	r0,4(r8)
1344a47a12beSStefan Roese	stwu	r0,4(r7)
1345a47a12beSStefan Roese	bdnz	1b
1346a47a12beSStefan Roese	b	4f
1347a47a12beSStefan Roese
1348a47a12beSStefan Roese2:	slwi	r0,r0,2
1349a47a12beSStefan Roese	add	r8,r4,r0
1350a47a12beSStefan Roese	add	r7,r3,r0
1351a47a12beSStefan Roese3:	lwzu	r0,-4(r8)
1352a47a12beSStefan Roese	stwu	r0,-4(r7)
1353a47a12beSStefan Roese	bdnz	3b
1354a47a12beSStefan Roese
1355a47a12beSStefan Roese/*
1356a47a12beSStefan Roese * Now flush the cache: note that we must start from a cache aligned
1357a47a12beSStefan Roese * address. Otherwise we might miss one cache line.
1358a47a12beSStefan Roese */
1359a47a12beSStefan Roese4:	cmpwi	r6,0
1360a47a12beSStefan Roese	add	r5,r3,r5
1361a47a12beSStefan Roese	beq	7f		/* Always flush prefetch queue in any case */
1362a47a12beSStefan Roese	subi	r0,r6,1
1363a47a12beSStefan Roese	andc	r3,r3,r0
1364a47a12beSStefan Roese	mr	r4,r3
1365a47a12beSStefan Roese5:	dcbst	0,r4
1366a47a12beSStefan Roese	add	r4,r4,r6
1367a47a12beSStefan Roese	cmplw	r4,r5
1368a47a12beSStefan Roese	blt	5b
1369a47a12beSStefan Roese	sync			/* Wait for all dcbst to complete on bus */
1370a47a12beSStefan Roese	mr	r4,r3
1371a47a12beSStefan Roese6:	icbi	0,r4
1372a47a12beSStefan Roese	add	r4,r4,r6
1373a47a12beSStefan Roese	cmplw	r4,r5
1374a47a12beSStefan Roese	blt	6b
1375a47a12beSStefan Roese7:	sync			/* Wait for all icbi to complete on bus */
1376a47a12beSStefan Roese	isync
1377a47a12beSStefan Roese
1378a47a12beSStefan Roese	/*
1379a47a12beSStefan Roese	 * Re-point the IVPR at RAM
1380a47a12beSStefan Roese	 */
1381a47a12beSStefan Roese	mtspr	IVPR,r10
1382a47a12beSStefan Roese
1383a47a12beSStefan Roese/*
1384a47a12beSStefan Roese * We are done. Do not return, instead branch to second part of board
1385a47a12beSStefan Roese * initialization, now running from RAM.
1386a47a12beSStefan Roese */
1387a47a12beSStefan Roese
1388a47a12beSStefan Roese	addi	r0,r10,in_ram - _start + _START_OFFSET
1389a47a12beSStefan Roese	mtlr	r0
1390a47a12beSStefan Roese	blr				/* NEVER RETURNS! */
1391a47a12beSStefan Roese	.globl	in_ram
1392a47a12beSStefan Roesein_ram:
1393a47a12beSStefan Roese
1394a47a12beSStefan Roese	/*
1395a47a12beSStefan Roese	 * Relocation Function, r12 point to got2+0x8000
1396a47a12beSStefan Roese	 *
1397a47a12beSStefan Roese	 * Adjust got2 pointers, no need to check for 0, this code
1398a47a12beSStefan Roese	 * already puts a few entries in the table.
1399a47a12beSStefan Roese	 */
1400a47a12beSStefan Roese	li	r0,__got2_entries@sectoff@l
1401a47a12beSStefan Roese	la	r3,GOT(_GOT2_TABLE_)
1402a47a12beSStefan Roese	lwz	r11,GOT(_GOT2_TABLE_)
1403a47a12beSStefan Roese	mtctr	r0
1404a47a12beSStefan Roese	sub	r11,r3,r11
1405a47a12beSStefan Roese	addi	r3,r3,-4
1406a47a12beSStefan Roese1:	lwzu	r0,4(r3)
1407a47a12beSStefan Roese	cmpwi	r0,0
1408a47a12beSStefan Roese	beq-	2f
1409a47a12beSStefan Roese	add	r0,r0,r11
1410a47a12beSStefan Roese	stw	r0,0(r3)
1411a47a12beSStefan Roese2:	bdnz	1b
1412a47a12beSStefan Roese
1413a47a12beSStefan Roese	/*
1414a47a12beSStefan Roese	 * Now adjust the fixups and the pointers to the fixups
1415a47a12beSStefan Roese	 * in case we need to move ourselves again.
1416a47a12beSStefan Roese	 */
1417a47a12beSStefan Roese	li	r0,__fixup_entries@sectoff@l
1418a47a12beSStefan Roese	lwz	r3,GOT(_FIXUP_TABLE_)
1419a47a12beSStefan Roese	cmpwi	r0,0
1420a47a12beSStefan Roese	mtctr	r0
1421a47a12beSStefan Roese	addi	r3,r3,-4
1422a47a12beSStefan Roese	beq	4f
1423a47a12beSStefan Roese3:	lwzu	r4,4(r3)
1424a47a12beSStefan Roese	lwzux	r0,r4,r11
1425d1e0b10aSJoakim Tjernlund	cmpwi	r0,0
1426a47a12beSStefan Roese	add	r0,r0,r11
142734bbf618SJoakim Tjernlund	stw	r4,0(r3)
1428d1e0b10aSJoakim Tjernlund	beq-	5f
1429a47a12beSStefan Roese	stw	r0,0(r4)
1430d1e0b10aSJoakim Tjernlund5:	bdnz	3b
1431a47a12beSStefan Roese4:
1432a47a12beSStefan Roeseclear_bss:
1433a47a12beSStefan Roese	/*
1434a47a12beSStefan Roese	 * Now clear BSS segment
1435a47a12beSStefan Roese	 */
1436a47a12beSStefan Roese	lwz	r3,GOT(__bss_start)
143744c6e659SPo-Yu Chuang	lwz	r4,GOT(__bss_end__)
1438a47a12beSStefan Roese
1439a47a12beSStefan Roese	cmplw	0,r3,r4
1440a47a12beSStefan Roese	beq	6f
1441a47a12beSStefan Roese
1442a47a12beSStefan Roese	li	r0,0
1443a47a12beSStefan Roese5:
1444a47a12beSStefan Roese	stw	r0,0(r3)
1445a47a12beSStefan Roese	addi	r3,r3,4
1446a47a12beSStefan Roese	cmplw	0,r3,r4
1447a47a12beSStefan Roese	bne	5b
1448a47a12beSStefan Roese6:
1449a47a12beSStefan Roese
1450a47a12beSStefan Roese	mr	r3,r9		/* Init Data pointer		*/
1451a47a12beSStefan Roese	mr	r4,r10		/* Destination Address		*/
1452a47a12beSStefan Roese	bl	board_init_r
1453a47a12beSStefan Roese
1454a47a12beSStefan Roese#ifndef CONFIG_NAND_SPL
1455a47a12beSStefan Roese	/*
1456a47a12beSStefan Roese	 * Copy exception vector code to low memory
1457a47a12beSStefan Roese	 *
1458a47a12beSStefan Roese	 * r3: dest_addr
1459a47a12beSStefan Roese	 * r7: source address, r8: end address, r9: target address
1460a47a12beSStefan Roese	 */
1461a47a12beSStefan Roese	.globl	trap_init
1462a47a12beSStefan Roesetrap_init:
1463a47a12beSStefan Roese	mflr	r4			/* save link register		*/
1464a47a12beSStefan Roese	GET_GOT
1465a47a12beSStefan Roese	lwz	r7,GOT(_start_of_vectors)
1466a47a12beSStefan Roese	lwz	r8,GOT(_end_of_vectors)
1467a47a12beSStefan Roese
1468a47a12beSStefan Roese	li	r9,0x100		/* reset vector always at 0x100 */
1469a47a12beSStefan Roese
1470a47a12beSStefan Roese	cmplw	0,r7,r8
1471a47a12beSStefan Roese	bgelr				/* return if r7>=r8 - just in case */
1472a47a12beSStefan Roese1:
1473a47a12beSStefan Roese	lwz	r0,0(r7)
1474a47a12beSStefan Roese	stw	r0,0(r9)
1475a47a12beSStefan Roese	addi	r7,r7,4
1476a47a12beSStefan Roese	addi	r9,r9,4
1477a47a12beSStefan Roese	cmplw	0,r7,r8
1478a47a12beSStefan Roese	bne	1b
1479a47a12beSStefan Roese
1480a47a12beSStefan Roese	/*
1481a47a12beSStefan Roese	 * relocate `hdlr' and `int_return' entries
1482a47a12beSStefan Roese	 */
1483a47a12beSStefan Roese	li	r7,.L_CriticalInput - _start + _START_OFFSET
1484a47a12beSStefan Roese	bl	trap_reloc
1485a47a12beSStefan Roese	li	r7,.L_MachineCheck - _start + _START_OFFSET
1486a47a12beSStefan Roese	bl	trap_reloc
1487a47a12beSStefan Roese	li	r7,.L_DataStorage - _start + _START_OFFSET
1488a47a12beSStefan Roese	bl	trap_reloc
1489a47a12beSStefan Roese	li	r7,.L_InstStorage - _start + _START_OFFSET
1490a47a12beSStefan Roese	bl	trap_reloc
1491a47a12beSStefan Roese	li	r7,.L_ExtInterrupt - _start + _START_OFFSET
1492a47a12beSStefan Roese	bl	trap_reloc
1493a47a12beSStefan Roese	li	r7,.L_Alignment - _start + _START_OFFSET
1494a47a12beSStefan Roese	bl	trap_reloc
1495a47a12beSStefan Roese	li	r7,.L_ProgramCheck - _start + _START_OFFSET
1496a47a12beSStefan Roese	bl	trap_reloc
1497a47a12beSStefan Roese	li	r7,.L_FPUnavailable - _start + _START_OFFSET
1498a47a12beSStefan Roese	bl	trap_reloc
1499a47a12beSStefan Roese	li	r7,.L_Decrementer - _start + _START_OFFSET
1500a47a12beSStefan Roese	bl	trap_reloc
1501a47a12beSStefan Roese	li	r7,.L_IntervalTimer - _start + _START_OFFSET
1502a47a12beSStefan Roese	li	r8,_end_of_vectors - _start + _START_OFFSET
1503a47a12beSStefan Roese2:
1504a47a12beSStefan Roese	bl	trap_reloc
1505a47a12beSStefan Roese	addi	r7,r7,0x100		/* next exception vector	*/
1506a47a12beSStefan Roese	cmplw	0,r7,r8
1507a47a12beSStefan Roese	blt	2b
1508a47a12beSStefan Roese
150964829bafSPrabhakar Kushwaha	/* Update IVORs as per relocated vector table address */
151064829bafSPrabhakar Kushwaha	li	r7,0x0100
151164829bafSPrabhakar Kushwaha	mtspr	IVOR0,r7	/* 0: Critical input */
151264829bafSPrabhakar Kushwaha	li	r7,0x0200
151364829bafSPrabhakar Kushwaha	mtspr	IVOR1,r7	/* 1: Machine check */
151464829bafSPrabhakar Kushwaha	li	r7,0x0300
151564829bafSPrabhakar Kushwaha	mtspr	IVOR2,r7	/* 2: Data storage */
151664829bafSPrabhakar Kushwaha	li	r7,0x0400
151764829bafSPrabhakar Kushwaha	mtspr	IVOR3,r7	/* 3: Instruction storage */
151864829bafSPrabhakar Kushwaha	li	r7,0x0500
151964829bafSPrabhakar Kushwaha	mtspr	IVOR4,r7	/* 4: External interrupt */
152064829bafSPrabhakar Kushwaha	li	r7,0x0600
152164829bafSPrabhakar Kushwaha	mtspr	IVOR5,r7	/* 5: Alignment */
152264829bafSPrabhakar Kushwaha	li	r7,0x0700
152364829bafSPrabhakar Kushwaha	mtspr	IVOR6,r7	/* 6: Program check */
152464829bafSPrabhakar Kushwaha	li	r7,0x0800
152564829bafSPrabhakar Kushwaha	mtspr	IVOR7,r7	/* 7: floating point unavailable */
152664829bafSPrabhakar Kushwaha	li	r7,0x0900
152764829bafSPrabhakar Kushwaha	mtspr	IVOR8,r7	/* 8: System call */
152864829bafSPrabhakar Kushwaha	/* 9: Auxiliary processor unavailable(unsupported) */
152964829bafSPrabhakar Kushwaha	li	r7,0x0a00
153064829bafSPrabhakar Kushwaha	mtspr	IVOR10,r7	/* 10: Decrementer */
153164829bafSPrabhakar Kushwaha	li	r7,0x0b00
153264829bafSPrabhakar Kushwaha	mtspr	IVOR11,r7	/* 11: Interval timer */
153364829bafSPrabhakar Kushwaha	li	r7,0x0c00
153464829bafSPrabhakar Kushwaha	mtspr	IVOR12,r7	/* 12: Watchdog timer */
153564829bafSPrabhakar Kushwaha	li	r7,0x0d00
153664829bafSPrabhakar Kushwaha	mtspr	IVOR13,r7	/* 13: Data TLB error */
153764829bafSPrabhakar Kushwaha	li	r7,0x0e00
153864829bafSPrabhakar Kushwaha	mtspr	IVOR14,r7	/* 14: Instruction TLB error */
153964829bafSPrabhakar Kushwaha	li	r7,0x0f00
154064829bafSPrabhakar Kushwaha	mtspr	IVOR15,r7	/* 15: Debug */
154164829bafSPrabhakar Kushwaha
1542a47a12beSStefan Roese	lis	r7,0x0
1543a47a12beSStefan Roese	mtspr	IVPR,r7
1544a47a12beSStefan Roese
1545a47a12beSStefan Roese	mtlr	r4			/* restore link register	*/
1546a47a12beSStefan Roese	blr
1547a47a12beSStefan Roese
1548a47a12beSStefan Roese.globl unlock_ram_in_cache
1549a47a12beSStefan Roeseunlock_ram_in_cache:
1550a47a12beSStefan Roese	/* invalidate the INIT_RAM section */
1551a47a12beSStefan Roese	lis	r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@h
1552a47a12beSStefan Roese	ori	r3,r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@l
1553a47a12beSStefan Roese	mfspr	r4,L1CFG0
1554a47a12beSStefan Roese	andi.	r4,r4,0x1ff
1555a47a12beSStefan Roese	slwi	r4,r4,(10 - 1 - L1_CACHE_SHIFT)
1556a47a12beSStefan Roese	mtctr	r4
1557a47a12beSStefan Roese1:	dcbi	r0,r3
1558a47a12beSStefan Roese	addi	r3,r3,CONFIG_SYS_CACHELINE_SIZE
1559a47a12beSStefan Roese	bdnz	1b
1560a47a12beSStefan Roese	sync
1561a47a12beSStefan Roese
1562a47a12beSStefan Roese	/* Invalidate the TLB entries for the cache */
1563a47a12beSStefan Roese	lis	r3,CONFIG_SYS_INIT_RAM_ADDR@h
1564a47a12beSStefan Roese	ori	r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
1565a47a12beSStefan Roese	tlbivax	0,r3
1566a47a12beSStefan Roese	addi	r3,r3,0x1000
1567a47a12beSStefan Roese	tlbivax	0,r3
1568a47a12beSStefan Roese	addi	r3,r3,0x1000
1569a47a12beSStefan Roese	tlbivax	0,r3
1570a47a12beSStefan Roese	addi	r3,r3,0x1000
1571a47a12beSStefan Roese	tlbivax	0,r3
1572a47a12beSStefan Roese	isync
1573a47a12beSStefan Roese	blr
1574a47a12beSStefan Roese
1575a47a12beSStefan Roese.globl flush_dcache
1576a47a12beSStefan Roeseflush_dcache:
1577a47a12beSStefan Roese	mfspr	r3,SPRN_L1CFG0
1578a47a12beSStefan Roese
1579a47a12beSStefan Roese	rlwinm	r5,r3,9,3	/* Extract cache block size */
1580a47a12beSStefan Roese	twlgti	r5,1		/* Only 32 and 64 byte cache blocks
1581a47a12beSStefan Roese				 * are currently defined.
1582a47a12beSStefan Roese				 */
1583a47a12beSStefan Roese	li	r4,32
1584a47a12beSStefan Roese	subfic	r6,r5,2		/* r6 = log2(1KiB / cache block size) -
1585a47a12beSStefan Roese				 *      log2(number of ways)
1586a47a12beSStefan Roese				 */
1587a47a12beSStefan Roese	slw	r5,r4,r5	/* r5 = cache block size */
1588a47a12beSStefan Roese
1589a47a12beSStefan Roese	rlwinm	r7,r3,0,0xff	/* Extract number of KiB in the cache */
1590a47a12beSStefan Roese	mulli	r7,r7,13	/* An 8-way cache will require 13
1591a47a12beSStefan Roese				 * loads per set.
1592a47a12beSStefan Roese				 */
1593a47a12beSStefan Roese	slw	r7,r7,r6
1594a47a12beSStefan Roese
1595a47a12beSStefan Roese	/* save off HID0 and set DCFA */
1596a47a12beSStefan Roese	mfspr	r8,SPRN_HID0
1597a47a12beSStefan Roese	ori	r9,r8,HID0_DCFA@l
1598a47a12beSStefan Roese	mtspr	SPRN_HID0,r9
1599a47a12beSStefan Roese	isync
1600a47a12beSStefan Roese
1601a47a12beSStefan Roese	lis	r4,0
1602a47a12beSStefan Roese	mtctr	r7
1603a47a12beSStefan Roese
1604a47a12beSStefan Roese1:	lwz	r3,0(r4)	/* Load... */
1605a47a12beSStefan Roese	add	r4,r4,r5
1606a47a12beSStefan Roese	bdnz	1b
1607a47a12beSStefan Roese
1608a47a12beSStefan Roese	msync
1609a47a12beSStefan Roese	lis	r4,0
1610a47a12beSStefan Roese	mtctr	r7
1611a47a12beSStefan Roese
1612a47a12beSStefan Roese1:	dcbf	0,r4		/* ...and flush. */
1613a47a12beSStefan Roese	add	r4,r4,r5
1614a47a12beSStefan Roese	bdnz	1b
1615a47a12beSStefan Roese
1616a47a12beSStefan Roese	/* restore HID0 */
1617a47a12beSStefan Roese	mtspr	SPRN_HID0,r8
1618a47a12beSStefan Roese	isync
1619a47a12beSStefan Roese
1620a47a12beSStefan Roese	blr
1621a47a12beSStefan Roese
1622a47a12beSStefan Roese.globl setup_ivors
1623a47a12beSStefan Roesesetup_ivors:
1624a47a12beSStefan Roese
1625a47a12beSStefan Roese#include "fixed_ivor.S"
1626a47a12beSStefan Roese	blr
1627a47a12beSStefan Roese#endif /* !CONFIG_NAND_SPL */
1628