blob: 882ef219a53359826a498c6b5f9aeea5eb3e7433 [file] [log] [blame]
wdenk0442ed82002-11-03 10:24:00 +00001/*
2 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
4 * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de>
Stefan Roese3cb86f32007-03-24 15:45:34 +01005 * Copyright (C) 2007 Stefan Roese <sr@denx.de>, DENX Software Engineering
Grant Ericksonc821b5f2008-05-22 14:44:14 -07006 * Copyright (c) 2008 Nuovation System Designs, LLC
7 * Grant Erickson <gerickson@nuovations.com>
wdenk0442ed82002-11-03 10:24:00 +00008 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +020027/*------------------------------------------------------------------------------+
28 *
29 * This source code has been made available to you by IBM on an AS-IS
30 * basis. Anyone receiving this source is licensed under IBM
31 * copyrights to use it in any way he or she deems fit, including
32 * copying it, modifying it, compiling it, and redistributing it either
33 * with or without modifications. No license under IBM patents or
34 * patent applications is to be implied by the copyright license.
35 *
36 * Any user of this software should understand that IBM cannot provide
37 * technical support for this software and will not be responsible for
38 * any consequences resulting from the use of this software.
39 *
40 * Any person who transfers this source code or any derivative work
41 * must include the IBM copyright notice, this paragraph, and the
42 * preceding two paragraphs in the transferred software.
43 *
44 * COPYRIGHT I B M CORPORATION 1995
45 * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
46 *-------------------------------------------------------------------------------
47 */
wdenk0442ed82002-11-03 10:24:00 +000048
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020049/* U-Boot - Startup Code for AMCC 4xx PowerPC based Embedded Boards
wdenk0442ed82002-11-03 10:24:00 +000050 *
51 *
52 * The processor starts at 0xfffffffc and the code is executed
53 * from flash/rom.
54 * in memory, but as long we don't jump around before relocating.
55 * board_init lies at a quite high address and when the cpu has
56 * jumped there, everything is ok.
57 * This works because the cpu gives the FLASH (CS0) the whole
58 * address space at startup, and board_init lies as a echo of
59 * the flash somewhere up there in the memorymap.
60 *
61 * board_init will change CS0 to be positioned at the correct
62 * address and (s)dram will be positioned at address 0
63 */
64#include <config.h>
wdenk0442ed82002-11-03 10:24:00 +000065#include <ppc4xx.h>
66#include <version.h>
67
68#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
69
70#include <ppc_asm.tmpl>
71#include <ppc_defs.h>
72
73#include <asm/cache.h>
74#include <asm/mmu.h>
75
76#ifndef CONFIG_IDENT_STRING
77#define CONFIG_IDENT_STRING ""
78#endif
79
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020080#ifdef CONFIG_SYS_INIT_DCACHE_CS
81# if (CONFIG_SYS_INIT_DCACHE_CS == 0)
wdenk0442ed82002-11-03 10:24:00 +000082# define PBxAP pb0ap
83# define PBxCR pb0cr
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020084# if (defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))
85# define PBxAP_VAL CONFIG_SYS_EBC_PB0AP
86# define PBxCR_VAL CONFIG_SYS_EBC_PB0CR
Grant Ericksonc821b5f2008-05-22 14:44:14 -070087# endif
wdenk0442ed82002-11-03 10:24:00 +000088# endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020089# if (CONFIG_SYS_INIT_DCACHE_CS == 1)
wdenk0442ed82002-11-03 10:24:00 +000090# define PBxAP pb1ap
91# define PBxCR pb1cr
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020092# if (defined(CONFIG_SYS_EBC_PB1AP) && defined(CONFIG_SYS_EBC_PB1CR))
93# define PBxAP_VAL CONFIG_SYS_EBC_PB1AP
94# define PBxCR_VAL CONFIG_SYS_EBC_PB1CR
Grant Ericksonc821b5f2008-05-22 14:44:14 -070095# endif
wdenk0442ed82002-11-03 10:24:00 +000096# endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020097# if (CONFIG_SYS_INIT_DCACHE_CS == 2)
wdenk0442ed82002-11-03 10:24:00 +000098# define PBxAP pb2ap
99# define PBxCR pb2cr
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200100# if (defined(CONFIG_SYS_EBC_PB2AP) && defined(CONFIG_SYS_EBC_PB2CR))
101# define PBxAP_VAL CONFIG_SYS_EBC_PB2AP
102# define PBxCR_VAL CONFIG_SYS_EBC_PB2CR
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700103# endif
wdenk0442ed82002-11-03 10:24:00 +0000104# endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200105# if (CONFIG_SYS_INIT_DCACHE_CS == 3)
wdenk0442ed82002-11-03 10:24:00 +0000106# define PBxAP pb3ap
107# define PBxCR pb3cr
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200108# if (defined(CONFIG_SYS_EBC_PB3AP) && defined(CONFIG_SYS_EBC_PB3CR))
109# define PBxAP_VAL CONFIG_SYS_EBC_PB3AP
110# define PBxCR_VAL CONFIG_SYS_EBC_PB3CR
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700111# endif
wdenk0442ed82002-11-03 10:24:00 +0000112# endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200113# if (CONFIG_SYS_INIT_DCACHE_CS == 4)
wdenk0442ed82002-11-03 10:24:00 +0000114# define PBxAP pb4ap
115# define PBxCR pb4cr
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200116# if (defined(CONFIG_SYS_EBC_PB4AP) && defined(CONFIG_SYS_EBC_PB4CR))
117# define PBxAP_VAL CONFIG_SYS_EBC_PB4AP
118# define PBxCR_VAL CONFIG_SYS_EBC_PB4CR
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700119# endif
wdenk0442ed82002-11-03 10:24:00 +0000120# endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200121# if (CONFIG_SYS_INIT_DCACHE_CS == 5)
wdenk0442ed82002-11-03 10:24:00 +0000122# define PBxAP pb5ap
123# define PBxCR pb5cr
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200124# if (defined(CONFIG_SYS_EBC_PB5AP) && defined(CONFIG_SYS_EBC_PB5CR))
125# define PBxAP_VAL CONFIG_SYS_EBC_PB5AP
126# define PBxCR_VAL CONFIG_SYS_EBC_PB5CR
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700127# endif
wdenk0442ed82002-11-03 10:24:00 +0000128# endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200129# if (CONFIG_SYS_INIT_DCACHE_CS == 6)
wdenk0442ed82002-11-03 10:24:00 +0000130# define PBxAP pb6ap
131# define PBxCR pb6cr
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200132# if (defined(CONFIG_SYS_EBC_PB6AP) && defined(CONFIG_SYS_EBC_PB6CR))
133# define PBxAP_VAL CONFIG_SYS_EBC_PB6AP
134# define PBxCR_VAL CONFIG_SYS_EBC_PB6CR
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700135# endif
wdenk0442ed82002-11-03 10:24:00 +0000136# endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200137# if (CONFIG_SYS_INIT_DCACHE_CS == 7)
wdenk0442ed82002-11-03 10:24:00 +0000138# define PBxAP pb7ap
139# define PBxCR pb7cr
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200140# if (defined(CONFIG_SYS_EBC_PB7AP) && defined(CONFIG_SYS_EBC_PB7CR))
141# define PBxAP_VAL CONFIG_SYS_EBC_PB7AP
142# define PBxCR_VAL CONFIG_SYS_EBC_PB7CR
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700143# endif
144# endif
145# ifndef PBxAP_VAL
146# define PBxAP_VAL 0
147# endif
148# ifndef PBxCR_VAL
149# define PBxCR_VAL 0
150# endif
151/*
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200152 * Memory Bank x (nothingness) initialization CONFIG_SYS_INIT_RAM_ADDR + 64 MiB
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700153 * used as temporary stack pointer for the primordial stack
154 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200155# ifndef CONFIG_SYS_INIT_DCACHE_PBxAR
156# define CONFIG_SYS_INIT_DCACHE_PBxAR (EBC_BXAP_BME_DISABLED | \
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700157 EBC_BXAP_TWT_ENCODE(7) | \
158 EBC_BXAP_BCE_DISABLE | \
159 EBC_BXAP_BCT_2TRANS | \
160 EBC_BXAP_CSN_ENCODE(0) | \
161 EBC_BXAP_OEN_ENCODE(0) | \
162 EBC_BXAP_WBN_ENCODE(0) | \
163 EBC_BXAP_WBF_ENCODE(0) | \
164 EBC_BXAP_TH_ENCODE(2) | \
165 EBC_BXAP_RE_DISABLED | \
166 EBC_BXAP_SOR_NONDELAYED | \
167 EBC_BXAP_BEM_WRITEONLY | \
168 EBC_BXAP_PEN_DISABLED)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200169# endif /* CONFIG_SYS_INIT_DCACHE_PBxAR */
170# ifndef CONFIG_SYS_INIT_DCACHE_PBxCR
171# define CONFIG_SYS_INIT_DCACHE_PBxCR (EBC_BXCR_BAS_ENCODE(CONFIG_SYS_INIT_RAM_ADDR) | \
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700172 EBC_BXCR_BS_64MB | \
173 EBC_BXCR_BU_RW | \
174 EBC_BXCR_BW_16BIT)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200175# endif /* CONFIG_SYS_INIT_DCACHE_PBxCR */
176# ifndef CONFIG_SYS_INIT_RAM_PATTERN
177# define CONFIG_SYS_INIT_RAM_PATTERN 0xDEADDEAD
wdenk0442ed82002-11-03 10:24:00 +0000178# endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200179#endif /* CONFIG_SYS_INIT_DCACHE_CS */
wdenk0442ed82002-11-03 10:24:00 +0000180
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200181#if (defined(CONFIG_SYS_INIT_RAM_DCACHE) && (CONFIG_SYS_INIT_RAM_END > (4 << 10)))
182#error Only 4k of init-ram is supported - please adjust CONFIG_SYS_INIT_RAM_END!
Stefan Roese28d77d92008-01-30 14:48:28 +0100183#endif
184
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700185/*
186 * Unless otherwise overriden, enable two 128MB cachable instruction regions
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200187 * at CONFIG_SYS_SDRAM_BASE and another 128MB cacheable instruction region covering
188 * NOR flash at CONFIG_SYS_FLASH_BASE. Disable all cacheable data regions.
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700189 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200190#if !defined(CONFIG_SYS_FLASH_BASE)
Stefan Roese64852d02008-06-02 14:35:44 +0200191/* If not already defined, set it to the "last" 128MByte region */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200192# define CONFIG_SYS_FLASH_BASE 0xf8000000
Stefan Roese64852d02008-06-02 14:35:44 +0200193#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200194#if !defined(CONFIG_SYS_ICACHE_SACR_VALUE)
195# define CONFIG_SYS_ICACHE_SACR_VALUE \
196 (PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + ( 0 << 20)) | \
197 PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + (128 << 20)) | \
198 PPC_128MB_SACR_VALUE(CONFIG_SYS_FLASH_BASE))
199#endif /* !defined(CONFIG_SYS_ICACHE_SACR_VALUE) */
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700200
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200201#if !defined(CONFIG_SYS_DCACHE_SACR_VALUE)
202# define CONFIG_SYS_DCACHE_SACR_VALUE \
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700203 (0x00000000)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200204#endif /* !defined(CONFIG_SYS_DCACHE_SACR_VALUE) */
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700205
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200206#define function_prolog(func_name) .text; \
Stefan Roesecf959c72007-06-01 15:27:11 +0200207 .align 2; \
208 .globl func_name; \
209 func_name:
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200210#define function_epilog(func_name) .type func_name,@function; \
Stefan Roesecf959c72007-06-01 15:27:11 +0200211 .size func_name,.-func_name
212
wdenk0442ed82002-11-03 10:24:00 +0000213/* We don't want the MMU yet.
214*/
215#undef MSR_KERNEL
216#define MSR_KERNEL ( MSR_ME ) /* Machine Check */
217
218
219 .extern ext_bus_cntlr_init
Stefan Roese887e2ec2006-09-07 11:51:23 +0200220#ifdef CONFIG_NAND_U_BOOT
221 .extern reconfig_tlb0
222#endif
wdenk0442ed82002-11-03 10:24:00 +0000223
224/*
225 * Set up GOT: Global Offset Table
226 *
227 * Use r14 to access the GOT
228 */
Stefan Roese887e2ec2006-09-07 11:51:23 +0200229#if !defined(CONFIG_NAND_SPL)
wdenk0442ed82002-11-03 10:24:00 +0000230 START_GOT
231 GOT_ENTRY(_GOT2_TABLE_)
232 GOT_ENTRY(_FIXUP_TABLE_)
233
234 GOT_ENTRY(_start)
235 GOT_ENTRY(_start_of_vectors)
236 GOT_ENTRY(_end_of_vectors)
237 GOT_ENTRY(transfer_to_handler)
238
wdenk3b57fe02003-05-30 12:48:29 +0000239 GOT_ENTRY(__init_end)
wdenk0442ed82002-11-03 10:24:00 +0000240 GOT_ENTRY(_end)
wdenk5d232d02003-05-22 22:52:13 +0000241 GOT_ENTRY(__bss_start)
wdenk0442ed82002-11-03 10:24:00 +0000242 END_GOT
Stefan Roese887e2ec2006-09-07 11:51:23 +0200243#endif /* CONFIG_NAND_SPL */
244
245#if defined(CONFIG_NAND_U_BOOT) && !defined(CONFIG_NAND_SPL)
246 /*
247 * NAND U-Boot image is started from offset 0
248 */
249 .text
Stefan Roesec440bfe2007-06-06 11:42:13 +0200250#if defined(CONFIG_440)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200251 bl reconfig_tlb0
Stefan Roesec440bfe2007-06-06 11:42:13 +0200252#endif
Stefan Roese887e2ec2006-09-07 11:51:23 +0200253 GET_GOT
254 bl cpu_init_f /* run low-level CPU init code (from Flash) */
255 bl board_init_f
256#endif
wdenk0442ed82002-11-03 10:24:00 +0000257
258/*
259 * 440 Startup -- on reset only the top 4k of the effective
260 * address space is mapped in by an entry in the instruction
261 * and data shadow TLB. The .bootpg section is located in the
262 * top 4k & does only what's necessary to map in the the rest
263 * of the boot rom. Once the boot rom is mapped in we can
264 * proceed with normal startup.
265 *
266 * NOTE: CS0 only covers the top 2MB of the effective address
267 * space after reset.
268 */
269
270#if defined(CONFIG_440)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200271#if !defined(CONFIG_NAND_SPL)
wdenk0442ed82002-11-03 10:24:00 +0000272 .section .bootpg,"ax"
Stefan Roese887e2ec2006-09-07 11:51:23 +0200273#endif
wdenk0442ed82002-11-03 10:24:00 +0000274 .globl _start_440
275
276/**************************************************************************/
277_start_440:
Wolfgang Denk511d0c72006-10-09 00:42:01 +0200278 /*--------------------------------------------------------------------+
279 | 440EPX BUP Change - Hardware team request
280 +--------------------------------------------------------------------*/
Stefan Roese887e2ec2006-09-07 11:51:23 +0200281#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
282 sync
283 nop
284 nop
285#endif
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200286 /*----------------------------------------------------------------+
287 | Core bug fix. Clear the esr
288 +-----------------------------------------------------------------*/
Marian Balakowiczedd6cf22006-07-06 21:17:24 +0200289 li r0,0
Wolfgang Denkb87dfd22006-07-19 13:50:38 +0200290 mtspr esr,r0
wdenk0442ed82002-11-03 10:24:00 +0000291 /*----------------------------------------------------------------*/
292 /* Clear and set up some registers. */
293 /*----------------------------------------------------------------*/
Wolfgang Denkf901a832005-08-06 01:42:58 +0200294 iccci r0,r0 /* NOTE: operands not used for 440 */
295 dccci r0,r0 /* NOTE: operands not used for 440 */
wdenk0442ed82002-11-03 10:24:00 +0000296 sync
297 li r0,0
298 mtspr srr0,r0
299 mtspr srr1,r0
300 mtspr csrr0,r0
301 mtspr csrr1,r0
Stefan Roese887e2ec2006-09-07 11:51:23 +0200302 /* NOTE: 440GX adds machine check status regs */
303#if defined(CONFIG_440) && !defined(CONFIG_440GP)
Wolfgang Denkf901a832005-08-06 01:42:58 +0200304 mtspr mcsrr0,r0
305 mtspr mcsrr1,r0
Stefan Roese887e2ec2006-09-07 11:51:23 +0200306 mfspr r1,mcsr
Wolfgang Denkf901a832005-08-06 01:42:58 +0200307 mtspr mcsr,r1
wdenkba56f622004-02-06 23:19:44 +0000308#endif
Stefan Roese20532832006-11-22 13:20:50 +0100309
310 /*----------------------------------------------------------------*/
311 /* CCR0 init */
312 /*----------------------------------------------------------------*/
313 /* Disable store gathering & broadcast, guarantee inst/data
314 * cache block touch, force load/store alignment
315 * (see errata 1.12: 440_33)
316 */
317 lis r1,0x0030 /* store gathering & broadcast disable */
318 ori r1,r1,0x6000 /* cache touch */
319 mtspr ccr0,r1
320
wdenk0442ed82002-11-03 10:24:00 +0000321 /*----------------------------------------------------------------*/
322 /* Initialize debug */
323 /*----------------------------------------------------------------*/
Stefan Roese887e2ec2006-09-07 11:51:23 +0200324 mfspr r1,dbcr0
325 andis. r1, r1, 0x8000 /* test DBCR0[EDM] bit */
326 bne skip_debug_init /* if set, don't clear debug register */
wdenk0442ed82002-11-03 10:24:00 +0000327 mtspr dbcr0,r0
328 mtspr dbcr1,r0
329 mtspr dbcr2,r0
330 mtspr iac1,r0
331 mtspr iac2,r0
332 mtspr iac3,r0
333 mtspr dac1,r0
334 mtspr dac2,r0
335 mtspr dvc1,r0
336 mtspr dvc2,r0
337
338 mfspr r1,dbsr
339 mtspr dbsr,r1 /* Clear all valid bits */
Stefan Roese887e2ec2006-09-07 11:51:23 +0200340skip_debug_init:
wdenk0442ed82002-11-03 10:24:00 +0000341
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200342#if defined (CONFIG_440SPE)
343 /*----------------------------------------------------------------+
344 | Initialize Core Configuration Reg1.
345 | a. ICDPEI: Record even parity. Normal operation.
346 | b. ICTPEI: Record even parity. Normal operation.
347 | c. DCTPEI: Record even parity. Normal operation.
348 | d. DCDPEI: Record even parity. Normal operation.
349 | e. DCUPEI: Record even parity. Normal operation.
350 | f. DCMPEI: Record even parity. Normal operation.
351 | g. FCOM: Normal operation
352 | h. MMUPEI: Record even parity. Normal operation.
353 | i. FFF: Flush only as much data as necessary.
Marian Balakowiczedd6cf22006-07-06 21:17:24 +0200354 | j. TCS: Timebase increments from CPU clock.
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200355 +-----------------------------------------------------------------*/
Marian Balakowiczedd6cf22006-07-06 21:17:24 +0200356 li r0,0
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200357 mtspr ccr1, r0
358
359 /*----------------------------------------------------------------+
360 | Reset the timebase.
361 | The previous write to CCR1 sets the timebase source.
362 +-----------------------------------------------------------------*/
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200363 mtspr tbl, r0
364 mtspr tbu, r0
365#endif
366
wdenk0442ed82002-11-03 10:24:00 +0000367 /*----------------------------------------------------------------*/
368 /* Setup interrupt vectors */
369 /*----------------------------------------------------------------*/
370 mtspr ivpr,r0 /* Vectors start at 0x0000_0000 */
Wolfgang Denkf901a832005-08-06 01:42:58 +0200371 li r1,0x0100
wdenk0442ed82002-11-03 10:24:00 +0000372 mtspr ivor0,r1 /* Critical input */
Wolfgang Denkf901a832005-08-06 01:42:58 +0200373 li r1,0x0200
wdenk0442ed82002-11-03 10:24:00 +0000374 mtspr ivor1,r1 /* Machine check */
Wolfgang Denkf901a832005-08-06 01:42:58 +0200375 li r1,0x0300
wdenk0442ed82002-11-03 10:24:00 +0000376 mtspr ivor2,r1 /* Data storage */
Wolfgang Denkf901a832005-08-06 01:42:58 +0200377 li r1,0x0400
wdenk0442ed82002-11-03 10:24:00 +0000378 mtspr ivor3,r1 /* Instruction storage */
379 li r1,0x0500
380 mtspr ivor4,r1 /* External interrupt */
381 li r1,0x0600
382 mtspr ivor5,r1 /* Alignment */
383 li r1,0x0700
384 mtspr ivor6,r1 /* Program check */
385 li r1,0x0800
386 mtspr ivor7,r1 /* Floating point unavailable */
387 li r1,0x0c00
388 mtspr ivor8,r1 /* System call */
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200389 li r1,0x0a00
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200390 mtspr ivor9,r1 /* Auxiliary Processor unavailable */
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200391 li r1,0x0900
392 mtspr ivor10,r1 /* Decrementer */
wdenk0442ed82002-11-03 10:24:00 +0000393 li r1,0x1300
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200394 mtspr ivor13,r1 /* Data TLB error */
395 li r1,0x1400
wdenk0442ed82002-11-03 10:24:00 +0000396 mtspr ivor14,r1 /* Instr TLB error */
397 li r1,0x2000
398 mtspr ivor15,r1 /* Debug */
399
400 /*----------------------------------------------------------------*/
401 /* Configure cache regions */
402 /*----------------------------------------------------------------*/
403 mtspr inv0,r0
404 mtspr inv1,r0
405 mtspr inv2,r0
406 mtspr inv3,r0
407 mtspr dnv0,r0
408 mtspr dnv1,r0
409 mtspr dnv2,r0
410 mtspr dnv3,r0
411 mtspr itv0,r0
412 mtspr itv1,r0
413 mtspr itv2,r0
414 mtspr itv3,r0
415 mtspr dtv0,r0
416 mtspr dtv1,r0
417 mtspr dtv2,r0
418 mtspr dtv3,r0
419
420 /*----------------------------------------------------------------*/
421 /* Cache victim limits */
422 /*----------------------------------------------------------------*/
423 /* floors 0, ceiling max to use the entire cache -- nothing locked
424 */
425 lis r1,0x0001
426 ori r1,r1,0xf800
427 mtspr ivlim,r1
428 mtspr dvlim,r1
429
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200430 /*----------------------------------------------------------------+
431 |Initialize MMUCR[STID] = 0.
432 +-----------------------------------------------------------------*/
433 mfspr r0,mmucr
434 addis r1,0,0xFFFF
435 ori r1,r1,0xFF00
436 and r0,r0,r1
437 mtspr mmucr,r0
438
wdenk0442ed82002-11-03 10:24:00 +0000439 /*----------------------------------------------------------------*/
440 /* Clear all TLB entries -- TID = 0, TS = 0 */
441 /*----------------------------------------------------------------*/
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200442 addis r0,0,0x0000
wdenk0442ed82002-11-03 10:24:00 +0000443 li r1,0x003f /* 64 TLB entries */
444 mtctr r1
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200445rsttlb: tlbwe r0,r1,0x0000 /* Invalidate all entries (V=0)*/
446 tlbwe r0,r1,0x0001
447 tlbwe r0,r1,0x0002
wdenk0442ed82002-11-03 10:24:00 +0000448 subi r1,r1,0x0001
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200449 bdnz rsttlb
wdenk0442ed82002-11-03 10:24:00 +0000450
451 /*----------------------------------------------------------------*/
452 /* TLB entry setup -- step thru tlbtab */
453 /*----------------------------------------------------------------*/
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200454#if defined(CONFIG_440SPE)
455 /*----------------------------------------------------------------*/
456 /* We have different TLB tables for revA and rev B of 440SPe */
457 /*----------------------------------------------------------------*/
458 mfspr r1, PVR
459 lis r0,0x5342
460 ori r0,r0,0x1891
461 cmpw r7,r1,r0
462 bne r7,..revA
463 bl tlbtabB
464 b ..goon
465..revA:
466 bl tlbtabA
467..goon:
468#else
wdenk0442ed82002-11-03 10:24:00 +0000469 bl tlbtab /* Get tlbtab pointer */
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200470#endif
wdenk0442ed82002-11-03 10:24:00 +0000471 mr r5,r0
472 li r1,0x003f /* 64 TLB entries max */
473 mtctr r1
474 li r4,0 /* TLB # */
475
476 addi r5,r5,-4
4771: lwzu r0,4(r5)
478 cmpwi r0,0
479 beq 2f /* 0 marks end */
480 lwzu r1,4(r5)
481 lwzu r2,4(r5)
482 tlbwe r0,r4,0 /* TLB Word 0 */
483 tlbwe r1,r4,1 /* TLB Word 1 */
484 tlbwe r2,r4,2 /* TLB Word 2 */
485 addi r4,r4,1 /* Next TLB */
486 bdnz 1b
487
488 /*----------------------------------------------------------------*/
489 /* Continue from 'normal' start */
490 /*----------------------------------------------------------------*/
Stefan Roese887e2ec2006-09-07 11:51:23 +02004912:
Stefan Roese887e2ec2006-09-07 11:51:23 +0200492 bl 3f
wdenk0442ed82002-11-03 10:24:00 +0000493 b _start
494
4953: li r0,0
496 mtspr srr1,r0 /* Keep things disabled for now */
497 mflr r1
498 mtspr srr0,r1
499 rfi
stroeseb867d702003-05-23 11:18:02 +0000500#endif /* CONFIG_440 */
wdenk0442ed82002-11-03 10:24:00 +0000501
502/*
503 * r3 - 1st arg to board_init(): IMMP pointer
504 * r4 - 2nd arg to board_init(): boot flag
505 */
Stefan Roese887e2ec2006-09-07 11:51:23 +0200506#ifndef CONFIG_NAND_SPL
wdenk0442ed82002-11-03 10:24:00 +0000507 .text
508 .long 0x27051956 /* U-Boot Magic Number */
509 .globl version_string
510version_string:
511 .ascii U_BOOT_VERSION
512 .ascii " (", __DATE__, " - ", __TIME__, ")"
513 .ascii CONFIG_IDENT_STRING, "\0"
514
wdenk0442ed82002-11-03 10:24:00 +0000515 . = EXC_OFF_SYS_RESET
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200516 .globl _start_of_vectors
517_start_of_vectors:
518
519/* Critical input. */
520 CRIT_EXCEPTION(0x100, CritcalInput, UnknownException)
521
522#ifdef CONFIG_440
523/* Machine check */
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200524 MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200525#else
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200526 CRIT_EXCEPTION(0x200, MachineCheck, MachineCheckException)
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200527#endif /* CONFIG_440 */
528
529/* Data Storage exception. */
530 STD_EXCEPTION(0x300, DataStorage, UnknownException)
531
532/* Instruction Storage exception. */
533 STD_EXCEPTION(0x400, InstStorage, UnknownException)
534
535/* External Interrupt exception. */
536 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
537
538/* Alignment exception. */
539 . = 0x600
540Alignment:
541 EXCEPTION_PROLOG(SRR0, SRR1)
542 mfspr r4,DAR
543 stw r4,_DAR(r21)
544 mfspr r5,DSISR
545 stw r5,_DSISR(r21)
546 addi r3,r1,STACK_FRAME_OVERHEAD
547 li r20,MSR_KERNEL
548 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
549 lwz r6,GOT(transfer_to_handler)
550 mtlr r6
551 blrl
552.L_Alignment:
553 .long AlignmentException - _start + _START_OFFSET
554 .long int_return - _start + _START_OFFSET
555
556/* Program check exception */
557 . = 0x700
558ProgramCheck:
559 EXCEPTION_PROLOG(SRR0, SRR1)
560 addi r3,r1,STACK_FRAME_OVERHEAD
561 li r20,MSR_KERNEL
562 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
563 lwz r6,GOT(transfer_to_handler)
564 mtlr r6
565 blrl
566.L_ProgramCheck:
567 .long ProgramCheckException - _start + _START_OFFSET
568 .long int_return - _start + _START_OFFSET
569
570#ifdef CONFIG_440
571 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
572 STD_EXCEPTION(0x900, Decrementer, DecrementerPITException)
573 STD_EXCEPTION(0xa00, APU, UnknownException)
Stefan Roesedf8a24c2007-06-19 16:42:31 +0200574#endif
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200575 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
576
577#ifdef CONFIG_440
578 STD_EXCEPTION(0x1300, DataTLBError, UnknownException)
579 STD_EXCEPTION(0x1400, InstructionTLBError, UnknownException)
580#else
581 STD_EXCEPTION(0x1000, PIT, DecrementerPITException)
582 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
583 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
584#endif
585 CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
586
587 .globl _end_of_vectors
588_end_of_vectors:
589 . = _START_OFFSET
Stefan Roese887e2ec2006-09-07 11:51:23 +0200590#endif
wdenk0442ed82002-11-03 10:24:00 +0000591 .globl _start
592_start:
593
594/*****************************************************************************/
595#if defined(CONFIG_440)
596
597 /*----------------------------------------------------------------*/
598 /* Clear and set up some registers. */
599 /*----------------------------------------------------------------*/
600 li r0,0x0000
601 lis r1,0xffff
602 mtspr dec,r0 /* prevent dec exceptions */
603 mtspr tbl,r0 /* prevent fit & wdt exceptions */
604 mtspr tbu,r0
605 mtspr tsr,r1 /* clear all timer exception status */
606 mtspr tcr,r0 /* disable all */
607 mtspr esr,r0 /* clear exception syndrome register */
608 mtxer r0 /* clear integer exception register */
wdenk0442ed82002-11-03 10:24:00 +0000609
610 /*----------------------------------------------------------------*/
611 /* Debug setup -- some (not very good) ice's need an event*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200612 /* to establish control :-( Define CONFIG_SYS_INIT_DBCR to the dbsr */
wdenk0442ed82002-11-03 10:24:00 +0000613 /* value you need in this case 0x8cff 0000 should do the trick */
614 /*----------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200615#if defined(CONFIG_SYS_INIT_DBCR)
wdenk0442ed82002-11-03 10:24:00 +0000616 lis r1,0xffff
617 ori r1,r1,0xffff
618 mtspr dbsr,r1 /* Clear all status bits */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200619 lis r0,CONFIG_SYS_INIT_DBCR@h
620 ori r0,r0,CONFIG_SYS_INIT_DBCR@l
wdenk0442ed82002-11-03 10:24:00 +0000621 mtspr dbcr0,r0
622 isync
623#endif
624
625 /*----------------------------------------------------------------*/
626 /* Setup the internal SRAM */
627 /*----------------------------------------------------------------*/
628 li r0,0
Stefan Roese887e2ec2006-09-07 11:51:23 +0200629
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200630#ifdef CONFIG_SYS_INIT_RAM_DCACHE
Stefan Roesec157d8e2005-08-01 16:41:48 +0200631 /* Clear Dcache to use as RAM */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200632 addis r3,r0,CONFIG_SYS_INIT_RAM_ADDR@h
633 ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
634 addis r4,r0,CONFIG_SYS_INIT_RAM_END@h
635 ori r4,r4,CONFIG_SYS_INIT_RAM_END@l
Stefan Roesec157d8e2005-08-01 16:41:48 +0200636 rlwinm. r5,r4,0,27,31
Wolfgang Denkf901a832005-08-06 01:42:58 +0200637 rlwinm r5,r4,27,5,31
638 beq ..d_ran
639 addi r5,r5,0x0001
Stefan Roesec157d8e2005-08-01 16:41:48 +0200640..d_ran:
Wolfgang Denkf901a832005-08-06 01:42:58 +0200641 mtctr r5
Stefan Roesec157d8e2005-08-01 16:41:48 +0200642..d_ag:
Wolfgang Denkf901a832005-08-06 01:42:58 +0200643 dcbz r0,r3
644 addi r3,r3,32
645 bdnz ..d_ag
Stefan Roesee02c5212008-01-09 10:23:16 +0100646
647 /*
648 * Lock the init-ram/stack in d-cache, so that other regions
649 * may use d-cache as well
650 * Note, that this current implementation locks exactly 4k
651 * of d-cache, so please make sure that you don't define a
652 * bigger init-ram area. Take a look at the lwmon5 440EPx
653 * implementation as a reference.
654 */
655 msync
656 isync
657 /* 8. set TFLOOR/NFLOOR to 8 (-> 8*16*32 bytes locked -> 4k) */
658 lis r1,0x0201
659 ori r1,r1,0xf808
660 mtspr dvlim,r1
661 lis r1,0x0808
662 ori r1,r1,0x0808
663 mtspr dnv0,r1
664 mtspr dnv1,r1
665 mtspr dnv2,r1
666 mtspr dnv3,r1
667 mtspr dtv0,r1
668 mtspr dtv1,r1
669 mtspr dtv2,r1
670 mtspr dtv3,r1
671 msync
672 isync
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200673#endif /* CONFIG_SYS_INIT_RAM_DCACHE */
Stefan Roese887e2ec2006-09-07 11:51:23 +0200674
675 /* 440EP & 440GR are only 440er PPC's without internal SRAM */
676#if !defined(CONFIG_440EP) && !defined(CONFIG_440GR)
677 /* not all PPC's have internal SRAM usable as L2-cache */
Stefan Roese2801b2d2008-03-11 15:05:50 +0100678#if defined(CONFIG_440GX) || \
679 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Feng Kan7d307932008-07-08 22:47:31 -0700680 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
681 defined(CONFIG_460SX)
Wolfgang Denkf901a832005-08-06 01:42:58 +0200682 mtdcr l2_cache_cfg,r0 /* Ensure L2 Cache is off */
wdenkba56f622004-02-06 23:19:44 +0000683#endif
wdenk0442ed82002-11-03 10:24:00 +0000684
Stefan Roese887e2ec2006-09-07 11:51:23 +0200685 lis r2,0x7fff
wdenk0442ed82002-11-03 10:24:00 +0000686 ori r2,r2,0xffff
687 mfdcr r1,isram0_dpc
688 and r1,r1,r2 /* Disable parity check */
689 mtdcr isram0_dpc,r1
690 mfdcr r1,isram0_pmeg
Stefan Roese887e2ec2006-09-07 11:51:23 +0200691 and r1,r1,r2 /* Disable pwr mgmt */
wdenk0442ed82002-11-03 10:24:00 +0000692 mtdcr isram0_pmeg,r1
693
694 lis r1,0x8000 /* BAS = 8000_0000 */
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100695#if defined(CONFIG_440GX) || defined(CONFIG_440SP)
wdenkba56f622004-02-06 23:19:44 +0000696 ori r1,r1,0x0980 /* first 64k */
Wolfgang Denkf901a832005-08-06 01:42:58 +0200697 mtdcr isram0_sb0cr,r1
wdenkba56f622004-02-06 23:19:44 +0000698 lis r1,0x8001
699 ori r1,r1,0x0980 /* second 64k */
Wolfgang Denkf901a832005-08-06 01:42:58 +0200700 mtdcr isram0_sb1cr,r1
wdenkba56f622004-02-06 23:19:44 +0000701 lis r1, 0x8002
702 ori r1,r1, 0x0980 /* third 64k */
Wolfgang Denkf901a832005-08-06 01:42:58 +0200703 mtdcr isram0_sb2cr,r1
wdenkba56f622004-02-06 23:19:44 +0000704 lis r1, 0x8003
705 ori r1,r1, 0x0980 /* fourth 64k */
Wolfgang Denkf901a832005-08-06 01:42:58 +0200706 mtdcr isram0_sb3cr,r1
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200707#elif defined(CONFIG_440SPE)
708 lis r1,0x0000 /* BAS = 0000_0000 */
709 ori r1,r1,0x0984 /* first 64k */
710 mtdcr isram0_sb0cr,r1
711 lis r1,0x0001
712 ori r1,r1,0x0984 /* second 64k */
713 mtdcr isram0_sb1cr,r1
714 lis r1, 0x0002
715 ori r1,r1, 0x0984 /* third 64k */
716 mtdcr isram0_sb2cr,r1
717 lis r1, 0x0003
718 ori r1,r1, 0x0984 /* fourth 64k */
719 mtdcr isram0_sb3cr,r1
Stefan Roese2801b2d2008-03-11 15:05:50 +0100720#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
721 lis r1,0x4000 /* BAS = 8000_0000 */
722 ori r1,r1,0x4580 /* 16k */
723 mtdcr isram0_sb0cr,r1
Feng Kan7d307932008-07-08 22:47:31 -0700724#elif defined(CONFIG_460SX)
725 lis r1,0x0000 /* BAS = 0000_0000 */
726 ori r1,r1,0x0B84 /* first 128k */
727 mtdcr isram0_sb0cr,r1
728 lis r1,0x0001
729 ori r1,r1,0x0B84 /* second 128k */
730 mtdcr isram0_sb1cr,r1
731 lis r1, 0x0002
732 ori r1,r1, 0x0B84 /* third 128k */
733 mtdcr isram0_sb2cr,r1
734 lis r1, 0x0003
735 ori r1,r1, 0x0B84 /* fourth 128k */
736 mtdcr isram0_sb3cr,r1
Stefan Roese887e2ec2006-09-07 11:51:23 +0200737#elif defined(CONFIG_440GP)
wdenk0442ed82002-11-03 10:24:00 +0000738 ori r1,r1,0x0380 /* 8k rw */
739 mtdcr isram0_sb0cr,r1
Stefan Roese887e2ec2006-09-07 11:51:23 +0200740 mtdcr isram0_sb1cr,r0 /* Disable bank 1 */
wdenkba56f622004-02-06 23:19:44 +0000741#endif
Stefan Roese887e2ec2006-09-07 11:51:23 +0200742#endif /* #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) */
wdenk0442ed82002-11-03 10:24:00 +0000743
744 /*----------------------------------------------------------------*/
745 /* Setup the stack in internal SRAM */
746 /*----------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200747 lis r1,CONFIG_SYS_INIT_RAM_ADDR@h
748 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET@l
wdenk0442ed82002-11-03 10:24:00 +0000749 li r0,0
750 stwu r0,-4(r1)
751 stwu r0,-4(r1) /* Terminate call chain */
752
753 stwu r1,-8(r1) /* Save back chain and move SP */
754 lis r0,RESET_VECTOR@h /* Address of reset vector */
755 ori r0,r0, RESET_VECTOR@l
756 stwu r1,-8(r1) /* Save back chain and move SP */
757 stw r0,+12(r1) /* Save return addr (underflow vect) */
758
Stefan Roese887e2ec2006-09-07 11:51:23 +0200759#ifdef CONFIG_NAND_SPL
Stefan Roese64852d02008-06-02 14:35:44 +0200760 bl nand_boot_common /* will not return */
Stefan Roese887e2ec2006-09-07 11:51:23 +0200761#else
wdenk0442ed82002-11-03 10:24:00 +0000762 GET_GOT
Stefan Roese5568e612005-11-22 13:20:42 +0100763
764 bl cpu_init_f /* run low-level CPU init code (from Flash) */
wdenk0442ed82002-11-03 10:24:00 +0000765 bl board_init_f
Stefan Roese887e2ec2006-09-07 11:51:23 +0200766#endif
wdenk0442ed82002-11-03 10:24:00 +0000767
768#endif /* CONFIG_440 */
769
770/*****************************************************************************/
771#ifdef CONFIG_IOP480
772 /*----------------------------------------------------------------------- */
773 /* Set up some machine state registers. */
774 /*----------------------------------------------------------------------- */
775 addi r0,r0,0x0000 /* initialize r0 to zero */
776 mtspr esr,r0 /* clear Exception Syndrome Reg */
777 mttcr r0 /* timer control register */
778 mtexier r0 /* disable all interrupts */
wdenk0442ed82002-11-03 10:24:00 +0000779 addis r4,r0,0xFFFF /* set r4 to 0xFFFFFFFF (status in the */
780 ori r4,r4,0xFFFF /* dbsr is cleared by setting bits to 1) */
781 mtdbsr r4 /* clear/reset the dbsr */
782 mtexisr r4 /* clear all pending interrupts */
783 addis r4,r0,0x8000
784 mtexier r4 /* enable critical exceptions */
785 addis r4,r0,0x0000 /* assume 403GCX - enable core clk */
786 ori r4,r4,0x4020 /* dbling (no harm done on GA and GC */
787 mtiocr r4 /* since bit not used) & DRC to latch */
788 /* data bus on rising edge of CAS */
789 /*----------------------------------------------------------------------- */
790 /* Clear XER. */
791 /*----------------------------------------------------------------------- */
792 mtxer r0
793 /*----------------------------------------------------------------------- */
794 /* Invalidate i-cache and d-cache TAG arrays. */
795 /*----------------------------------------------------------------------- */
796 addi r3,0,1024 /* 1/4 of I-cache size, half of D-cache */
797 addi r4,0,1024 /* 1/4 of I-cache */
798..cloop:
799 iccci 0,r3
800 iccci r4,r3
801 dccci 0,r3
802 addic. r3,r3,-16 /* move back one cache line */
803 bne ..cloop /* loop back to do rest until r3 = 0 */
804
805 /* */
806 /* initialize IOP480 so it can read 1 MB code area for SRAM spaces */
807 /* this requires enabling MA[17..0], by default only MA[12..0] are enabled. */
808 /* */
809
810 /* first copy IOP480 register base address into r3 */
811 addis r3,0,0x5000 /* IOP480 register base address hi */
812/* ori r3,r3,0x0000 / IOP480 register base address lo */
813
814#ifdef CONFIG_ADCIOP
815 /* use r4 as the working variable */
816 /* turn on CS3 (LOCCTL.7) */
817 lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */
818 andi. r4,r4,0xff7f /* make bit 7 = 0 -- CS3 mode */
819 stw r4,0x84(r3) /* LOCTL is at offset 0x84 */
820#endif
821
822#ifdef CONFIG_DASA_SIM
823 /* use r4 as the working variable */
824 /* turn on MA17 (LOCCTL.7) */
825 lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */
826 ori r4,r4,0x80 /* make bit 7 = 1 -- MA17 mode */
827 stw r4,0x84(r3) /* LOCTL is at offset 0x84 */
828#endif
829
830 /* turn on MA16..13 (LCS0BRD.12 = 0) */
831 lwz r4,0x100(r3) /* LCS0BRD is at offset 0x100 */
832 andi. r4,r4,0xefff /* make bit 12 = 0 */
833 stw r4,0x100(r3) /* LCS0BRD is at offset 0x100 */
834
835 /* make sure above stores all comlete before going on */
836 sync
837
838 /* last thing, set local init status done bit (DEVINIT.31) */
839 lwz r4,0x80(r3) /* DEVINIT is at offset 0x80 */
840 oris r4,r4,0x8000 /* make bit 31 = 1 */
841 stw r4,0x80(r3) /* DEVINIT is at offset 0x80 */
842
843 /* clear all pending interrupts and disable all interrupts */
844 li r4,-1 /* set p1 to 0xffffffff */
845 stw r4,0x1b0(r3) /* clear all pending interrupts */
846 stw r4,0x1b8(r3) /* clear all pending interrupts */
847 li r4,0 /* set r4 to 0 */
848 stw r4,0x1b4(r3) /* disable all interrupts */
849 stw r4,0x1bc(r3) /* disable all interrupts */
850
851 /* make sure above stores all comlete before going on */
852 sync
853
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700854 /* Set-up icache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200855 lis r1, CONFIG_SYS_ICACHE_SACR_VALUE@h
856 ori r1, r1, CONFIG_SYS_ICACHE_SACR_VALUE@l
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700857 mticcr r1
858 isync
wdenk0442ed82002-11-03 10:24:00 +0000859
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700860 /* Set-up dcache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200861 lis r1, CONFIG_SYS_DCACHE_SACR_VALUE@h
862 ori r1, r1, CONFIG_SYS_DCACHE_SACR_VALUE@l
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700863 mtdccr r1
wdenk0442ed82002-11-03 10:24:00 +0000864
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200865 addis r1,r0,CONFIG_SYS_INIT_RAM_ADDR@h
866 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET /* set up the stack to SDRAM */
wdenk0442ed82002-11-03 10:24:00 +0000867 li r0, 0 /* Make room for stack frame header and */
868 stwu r0, -4(r1) /* clear final stack frame so that */
869 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
870
871 GET_GOT /* initialize GOT access */
872
873 bl board_init_f /* run first part of init code (from Flash) */
874
875#endif /* CONFIG_IOP480 */
876
877/*****************************************************************************/
Stefan Roesee01bd212007-03-21 13:38:59 +0100878#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
879 defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
Stefan Roesedbbd1252007-10-05 17:10:59 +0200880 defined(CONFIG_405EX) || defined(CONFIG_405)
wdenk0442ed82002-11-03 10:24:00 +0000881 /*----------------------------------------------------------------------- */
882 /* Clear and set up some registers. */
883 /*----------------------------------------------------------------------- */
884 addi r4,r0,0x0000
Stefan Roesedbbd1252007-10-05 17:10:59 +0200885#if !defined(CONFIG_405EX)
wdenk0442ed82002-11-03 10:24:00 +0000886 mtspr sgr,r4
Stefan Roesedbbd1252007-10-05 17:10:59 +0200887#else
888 /*
889 * On 405EX, completely clearing the SGR leads to PPC hangup
890 * upon PCIe configuration access. The PCIe memory regions
891 * need to be guarded!
892 */
893 lis r3,0x0000
894 ori r3,r3,0x7FFC
895 mtspr sgr,r3
896#endif
wdenk0442ed82002-11-03 10:24:00 +0000897 mtspr dcwr,r4
898 mtesr r4 /* clear Exception Syndrome Reg */
899 mttcr r4 /* clear Timer Control Reg */
900 mtxer r4 /* clear Fixed-Point Exception Reg */
901 mtevpr r4 /* clear Exception Vector Prefix Reg */
wdenk0442ed82002-11-03 10:24:00 +0000902 addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */
903 /* dbsr is cleared by setting bits to 1) */
904 mtdbsr r4 /* clear/reset the dbsr */
905
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700906 /* Invalidate the i- and d-caches. */
wdenk0442ed82002-11-03 10:24:00 +0000907 bl invalidate_icache
908 bl invalidate_dcache
909
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700910 /* Set-up icache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200911 lis r4, CONFIG_SYS_ICACHE_SACR_VALUE@h
912 ori r4, r4, CONFIG_SYS_ICACHE_SACR_VALUE@l
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700913 mticcr r4
wdenk0442ed82002-11-03 10:24:00 +0000914 isync
915
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700916 /* Set-up dcache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200917 lis r4, CONFIG_SYS_DCACHE_SACR_VALUE@h
918 ori r4, r4, CONFIG_SYS_DCACHE_SACR_VALUE@l
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700919 mtdccr r4
wdenk0442ed82002-11-03 10:24:00 +0000920
Ricardo Ribalda Delgado1f4d5322008-10-21 18:29:46 +0200921#if !(defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))\
922 && !defined (CONFIG_XILINX_405)
wdenk0442ed82002-11-03 10:24:00 +0000923 /*----------------------------------------------------------------------- */
924 /* Tune the speed and size for flash CS0 */
925 /*----------------------------------------------------------------------- */
926 bl ext_bus_cntlr_init
927#endif
Stefan Roese64852d02008-06-02 14:35:44 +0200928
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200929#if !(defined(CONFIG_SYS_INIT_DCACHE_CS) || defined(CONFIG_SYS_TEMP_STACK_OCM))
Stefan Roesedbbd1252007-10-05 17:10:59 +0200930 /*
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700931 * For boards that don't have OCM and can't use the data cache
932 * for their primordial stack, setup stack here directly after the
933 * SDRAM is initialized in ext_bus_cntlr_init.
Stefan Roesedbbd1252007-10-05 17:10:59 +0200934 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200935 lis r1, CONFIG_SYS_INIT_RAM_ADDR@h
936 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET /* set up the stack in SDRAM */
Stefan Roesedbbd1252007-10-05 17:10:59 +0200937
938 li r0, 0 /* Make room for stack frame header and */
939 stwu r0, -4(r1) /* clear final stack frame so that */
940 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
941 /*
942 * Set up a dummy frame to store reset vector as return address.
943 * this causes stack underflow to reset board.
944 */
945 stwu r1, -8(r1) /* Save back chain and move SP */
946 lis r0, RESET_VECTOR@h /* Address of reset vector */
947 ori r0, r0, RESET_VECTOR@l
948 stwu r1, -8(r1) /* Save back chain and move SP */
949 stw r0, +12(r1) /* Save return addr (underflow vect) */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200950#endif /* !(CONFIG_SYS_INIT_DCACHE_CS || !CONFIG_SYS_TEM_STACK_OCM) */
wdenk0442ed82002-11-03 10:24:00 +0000951
stroeseb867d702003-05-23 11:18:02 +0000952#if defined(CONFIG_405EP)
953 /*----------------------------------------------------------------------- */
954 /* DMA Status, clear to come up clean */
955 /*----------------------------------------------------------------------- */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200956 addis r3,r0, 0xFFFF /* Clear all existing DMA status */
Wolfgang Denkf901a832005-08-06 01:42:58 +0200957 ori r3,r3, 0xFFFF
958 mtdcr dmasr, r3
stroeseb867d702003-05-23 11:18:02 +0000959
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200960 bl ppc405ep_init /* do ppc405ep specific init */
stroeseb867d702003-05-23 11:18:02 +0000961#endif /* CONFIG_405EP */
962
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200963#if defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE)
Stefan Roesee01bd212007-03-21 13:38:59 +0100964#if defined(CONFIG_405EZ)
965 /********************************************************************
966 * Setup OCM - On Chip Memory - PPC405EZ uses OCM Controller V2
967 *******************************************************************/
968 /*
969 * We can map the OCM on the PLB3, so map it at
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200970 * CONFIG_SYS_OCM_DATA_ADDR + 0x8000
Stefan Roesee01bd212007-03-21 13:38:59 +0100971 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200972 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
973 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Stefan Roesedf8a24c2007-06-19 16:42:31 +0200974 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
Stefan Roesee01bd212007-03-21 13:38:59 +0100975 mtdcr ocmplb3cr1,r3 /* Set PLB Access */
976 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
977 mtdcr ocmplb3cr2,r3 /* Set PLB Access */
978 isync
979
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200980 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
981 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200982 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
983 mtdcr ocmdscr1, r3 /* Set Data Side */
984 mtdcr ocmiscr1, r3 /* Set Instruction Side */
Stefan Roesee01bd212007-03-21 13:38:59 +0100985 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200986 mtdcr ocmdscr2, r3 /* Set Data Side */
987 mtdcr ocmiscr2, r3 /* Set Instruction Side */
988 addis r3,0,0x0800 /* OCM Data Parity Disable - 1 Wait State */
Stefan Roesed7568942007-05-24 09:49:00 +0200989 mtdcr ocmdsisdpc,r3
Stefan Roesee01bd212007-03-21 13:38:59 +0100990
991 isync
Stefan Roese3cb86f32007-03-24 15:45:34 +0100992#else /* CONFIG_405EZ */
wdenk0442ed82002-11-03 10:24:00 +0000993 /********************************************************************
994 * Setup OCM - On Chip Memory
995 *******************************************************************/
996 /* Setup OCM */
wdenk8bde7f72003-06-27 21:31:46 +0000997 lis r0, 0x7FFF
998 ori r0, r0, 0xFFFF
Wolfgang Denkf901a832005-08-06 01:42:58 +0200999 mfdcr r3, ocmiscntl /* get instr-side IRAM config */
Stefan Roese3cb86f32007-03-24 15:45:34 +01001000 mfdcr r4, ocmdscntl /* get data-side IRAM config */
1001 and r3, r3, r0 /* disable data-side IRAM */
1002 and r4, r4, r0 /* disable data-side IRAM */
1003 mtdcr ocmiscntl, r3 /* set instr-side IRAM config */
1004 mtdcr ocmdscntl, r4 /* set data-side IRAM config */
wdenk8bde7f72003-06-27 21:31:46 +00001005 isync
wdenk0442ed82002-11-03 10:24:00 +00001006
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001007 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
1008 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
wdenk0442ed82002-11-03 10:24:00 +00001009 mtdcr ocmdsarc, r3
1010 addis r4, 0, 0xC000 /* OCM data area enabled */
1011 mtdcr ocmdscntl, r4
wdenk8bde7f72003-06-27 21:31:46 +00001012 isync
Stefan Roesee01bd212007-03-21 13:38:59 +01001013#endif /* CONFIG_405EZ */
wdenk0442ed82002-11-03 10:24:00 +00001014#endif
1015
1016 /*----------------------------------------------------------------------- */
1017 /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
1018 /*----------------------------------------------------------------------- */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001019#ifdef CONFIG_SYS_INIT_DCACHE_CS
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001020 li r4, PBxAP
1021 mtdcr ebccfga, r4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001022 lis r4, CONFIG_SYS_INIT_DCACHE_PBxAR@h
1023 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxAR@l
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001024 mtdcr ebccfgd, r4
wdenk0442ed82002-11-03 10:24:00 +00001025
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001026 addi r4, 0, PBxCR
1027 mtdcr ebccfga, r4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001028 lis r4, CONFIG_SYS_INIT_DCACHE_PBxCR@h
1029 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxCR@l
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001030 mtdcr ebccfgd, r4
wdenk0442ed82002-11-03 10:24:00 +00001031
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001032 /*
1033 * Enable the data cache for the 128MB storage access control region
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001034 * at CONFIG_SYS_INIT_RAM_ADDR.
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001035 */
1036 mfdccr r4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001037 oris r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
1038 ori r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
wdenk0442ed82002-11-03 10:24:00 +00001039 mtdccr r4
1040
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001041 /*
1042 * Preallocate data cache lines to be used to avoid a subsequent
1043 * cache miss and an ensuing machine check exception when exceptions
1044 * are enabled.
1045 */
1046 li r0, 0
wdenk0442ed82002-11-03 10:24:00 +00001047
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001048 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
1049 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
wdenk0442ed82002-11-03 10:24:00 +00001050
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001051 lis r4, CONFIG_SYS_INIT_RAM_END@h
1052 ori r4, r4, CONFIG_SYS_INIT_RAM_END@l
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001053
1054 /*
1055 * Convert the size, in bytes, to the number of cache lines/blocks
1056 * to preallocate.
1057 */
1058 clrlwi. r5, r4, (32 - L1_CACHE_SHIFT)
1059 srwi r5, r4, L1_CACHE_SHIFT
1060 beq ..load_counter
1061 addi r5, r5, 0x0001
1062..load_counter:
1063 mtctr r5
1064
1065 /* Preallocate the computed number of cache blocks. */
1066..alloc_dcache_block:
1067 dcba r0, r3
1068 addi r3, r3, L1_CACHE_BYTES
1069 bdnz ..alloc_dcache_block
1070 sync
1071
1072 /*
1073 * Load the initial stack pointer and data area and convert the size,
1074 * in bytes, to the number of words to initialize to a known value.
1075 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001076 lis r1, CONFIG_SYS_INIT_RAM_ADDR@h
1077 ori r1, r1, CONFIG_SYS_INIT_SP_OFFSET@l
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001078
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001079 lis r4, (CONFIG_SYS_INIT_RAM_END >> 2)@h
1080 ori r4, r4, (CONFIG_SYS_INIT_RAM_END >> 2)@l
wdenk0442ed82002-11-03 10:24:00 +00001081 mtctr r4
1082
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001083 lis r2, CONFIG_SYS_INIT_RAM_ADDR@h
1084 ori r2, r2, CONFIG_SYS_INIT_RAM_END@l
wdenk0442ed82002-11-03 10:24:00 +00001085
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001086 lis r4, CONFIG_SYS_INIT_RAM_PATTERN@h
1087 ori r4, r4, CONFIG_SYS_INIT_RAM_PATTERN@l
wdenk0442ed82002-11-03 10:24:00 +00001088
1089..stackloop:
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001090 stwu r4, -4(r2)
wdenk0442ed82002-11-03 10:24:00 +00001091 bdnz ..stackloop
1092
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001093 /*
1094 * Make room for stack frame header and clear final stack frame so
1095 * that stack backtraces terminate cleanly.
1096 */
1097 stwu r0, -4(r1)
1098 stwu r0, -4(r1)
1099
wdenk0442ed82002-11-03 10:24:00 +00001100 /*
1101 * Set up a dummy frame to store reset vector as return address.
1102 * this causes stack underflow to reset board.
1103 */
1104 stwu r1, -8(r1) /* Save back chain and move SP */
1105 addis r0, 0, RESET_VECTOR@h /* Address of reset vector */
1106 ori r0, r0, RESET_VECTOR@l
1107 stwu r1, -8(r1) /* Save back chain and move SP */
1108 stw r0, +12(r1) /* Save return addr (underflow vect) */
1109
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001110#elif defined(CONFIG_SYS_TEMP_STACK_OCM) && \
1111 (defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE))
wdenk0442ed82002-11-03 10:24:00 +00001112 /*
1113 * Stack in OCM.
1114 */
1115
1116 /* Set up Stack at top of OCM */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001117 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)@h
1118 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)@l
wdenk0442ed82002-11-03 10:24:00 +00001119
1120 /* Set up a zeroized stack frame so that backtrace works right */
1121 li r0, 0
1122 stwu r0, -4(r1)
1123 stwu r0, -4(r1)
1124
1125 /*
1126 * Set up a dummy frame to store reset vector as return address.
1127 * this causes stack underflow to reset board.
1128 */
1129 stwu r1, -8(r1) /* Save back chain and move SP */
1130 lis r0, RESET_VECTOR@h /* Address of reset vector */
1131 ori r0, r0, RESET_VECTOR@l
1132 stwu r1, -8(r1) /* Save back chain and move SP */
1133 stw r0, +12(r1) /* Save return addr (underflow vect) */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001134#endif /* CONFIG_SYS_INIT_DCACHE_CS */
wdenk0442ed82002-11-03 10:24:00 +00001135
Stefan Roesec440bfe2007-06-06 11:42:13 +02001136#ifdef CONFIG_NAND_SPL
Stefan Roese64852d02008-06-02 14:35:44 +02001137 bl nand_boot_common /* will not return */
Stefan Roesec440bfe2007-06-06 11:42:13 +02001138#else
wdenk0442ed82002-11-03 10:24:00 +00001139 GET_GOT /* initialize GOT access */
1140
Wolfgang Denkf901a832005-08-06 01:42:58 +02001141 bl cpu_init_f /* run low-level CPU init code (from Flash) */
wdenk0442ed82002-11-03 10:24:00 +00001142
1143 /* NEVER RETURNS! */
1144 bl board_init_f /* run first part of init code (from Flash) */
Stefan Roesec440bfe2007-06-06 11:42:13 +02001145#endif /* CONFIG_NAND_SPL */
wdenk0442ed82002-11-03 10:24:00 +00001146
wdenk12f34242003-09-02 22:48:03 +00001147#endif /* CONFIG_405GP || CONFIG_405CR || CONFIG_405 || CONFIG_405EP */
1148 /*----------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001149
1150
Stefan Roese887e2ec2006-09-07 11:51:23 +02001151#ifndef CONFIG_NAND_SPL
wdenk0442ed82002-11-03 10:24:00 +00001152/*
1153 * This code finishes saving the registers to the exception frame
1154 * and jumps to the appropriate handler for the exception.
1155 * Register r21 is pointer into trap frame, r1 has new stack pointer.
1156 */
1157 .globl transfer_to_handler
1158transfer_to_handler:
1159 stw r22,_NIP(r21)
1160 lis r22,MSR_POW@h
1161 andc r23,r23,r22
1162 stw r23,_MSR(r21)
1163 SAVE_GPR(7, r21)
1164 SAVE_4GPRS(8, r21)
1165 SAVE_8GPRS(12, r21)
1166 SAVE_8GPRS(24, r21)
wdenk0442ed82002-11-03 10:24:00 +00001167 mflr r23
1168 andi. r24,r23,0x3f00 /* get vector offset */
1169 stw r24,TRAP(r21)
1170 li r22,0
1171 stw r22,RESULT(r21)
1172 mtspr SPRG2,r22 /* r1 is now kernel sp */
wdenk0442ed82002-11-03 10:24:00 +00001173 lwz r24,0(r23) /* virtual address of handler */
1174 lwz r23,4(r23) /* where to go when done */
1175 mtspr SRR0,r24
1176 mtspr SRR1,r20
1177 mtlr r23
1178 SYNC
1179 rfi /* jump to handler, enable MMU */
1180
1181int_return:
1182 mfmsr r28 /* Disable interrupts */
1183 li r4,0
1184 ori r4,r4,MSR_EE
1185 andc r28,r28,r4
1186 SYNC /* Some chip revs need this... */
1187 mtmsr r28
1188 SYNC
1189 lwz r2,_CTR(r1)
1190 lwz r0,_LINK(r1)
1191 mtctr r2
1192 mtlr r0
1193 lwz r2,_XER(r1)
1194 lwz r0,_CCR(r1)
1195 mtspr XER,r2
1196 mtcrf 0xFF,r0
1197 REST_10GPRS(3, r1)
1198 REST_10GPRS(13, r1)
1199 REST_8GPRS(23, r1)
1200 REST_GPR(31, r1)
1201 lwz r2,_NIP(r1) /* Restore environment */
1202 lwz r0,_MSR(r1)
1203 mtspr SRR0,r2
1204 mtspr SRR1,r0
1205 lwz r0,GPR0(r1)
1206 lwz r2,GPR2(r1)
1207 lwz r1,GPR1(r1)
1208 SYNC
1209 rfi
1210
1211crit_return:
1212 mfmsr r28 /* Disable interrupts */
1213 li r4,0
1214 ori r4,r4,MSR_EE
1215 andc r28,r28,r4
1216 SYNC /* Some chip revs need this... */
1217 mtmsr r28
1218 SYNC
1219 lwz r2,_CTR(r1)
1220 lwz r0,_LINK(r1)
1221 mtctr r2
1222 mtlr r0
1223 lwz r2,_XER(r1)
1224 lwz r0,_CCR(r1)
1225 mtspr XER,r2
1226 mtcrf 0xFF,r0
1227 REST_10GPRS(3, r1)
1228 REST_10GPRS(13, r1)
1229 REST_8GPRS(23, r1)
1230 REST_GPR(31, r1)
1231 lwz r2,_NIP(r1) /* Restore environment */
1232 lwz r0,_MSR(r1)
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +02001233 mtspr csrr0,r2
1234 mtspr csrr1,r0
wdenk0442ed82002-11-03 10:24:00 +00001235 lwz r0,GPR0(r1)
1236 lwz r2,GPR2(r1)
1237 lwz r1,GPR1(r1)
1238 SYNC
1239 rfci
1240
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001241#ifdef CONFIG_440
1242mck_return:
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +02001243 mfmsr r28 /* Disable interrupts */
1244 li r4,0
1245 ori r4,r4,MSR_EE
1246 andc r28,r28,r4
1247 SYNC /* Some chip revs need this... */
1248 mtmsr r28
1249 SYNC
1250 lwz r2,_CTR(r1)
1251 lwz r0,_LINK(r1)
1252 mtctr r2
1253 mtlr r0
1254 lwz r2,_XER(r1)
1255 lwz r0,_CCR(r1)
1256 mtspr XER,r2
1257 mtcrf 0xFF,r0
1258 REST_10GPRS(3, r1)
1259 REST_10GPRS(13, r1)
1260 REST_8GPRS(23, r1)
1261 REST_GPR(31, r1)
1262 lwz r2,_NIP(r1) /* Restore environment */
1263 lwz r0,_MSR(r1)
1264 mtspr mcsrr0,r2
1265 mtspr mcsrr1,r0
1266 lwz r0,GPR0(r1)
1267 lwz r2,GPR2(r1)
1268 lwz r1,GPR1(r1)
1269 SYNC
1270 rfmci
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001271#endif /* CONFIG_440 */
1272
1273
wdenk0442ed82002-11-03 10:24:00 +00001274 .globl get_pvr
1275get_pvr:
1276 mfspr r3, PVR
1277 blr
1278
wdenk0442ed82002-11-03 10:24:00 +00001279/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001280/* Function: out16 */
1281/* Description: Output 16 bits */
1282/*------------------------------------------------------------------------------- */
1283 .globl out16
1284out16:
1285 sth r4,0x0000(r3)
1286 blr
1287
1288/*------------------------------------------------------------------------------- */
1289/* Function: out16r */
1290/* Description: Byte reverse and output 16 bits */
1291/*------------------------------------------------------------------------------- */
1292 .globl out16r
1293out16r:
1294 sthbrx r4,r0,r3
1295 blr
1296
1297/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001298/* Function: out32r */
1299/* Description: Byte reverse and output 32 bits */
1300/*------------------------------------------------------------------------------- */
1301 .globl out32r
1302out32r:
1303 stwbrx r4,r0,r3
1304 blr
1305
1306/*------------------------------------------------------------------------------- */
1307/* Function: in16 */
1308/* Description: Input 16 bits */
1309/*------------------------------------------------------------------------------- */
1310 .globl in16
1311in16:
1312 lhz r3,0x0000(r3)
1313 blr
1314
1315/*------------------------------------------------------------------------------- */
1316/* Function: in16r */
1317/* Description: Input 16 bits and byte reverse */
1318/*------------------------------------------------------------------------------- */
1319 .globl in16r
1320in16r:
1321 lhbrx r3,r0,r3
1322 blr
1323
1324/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001325/* Function: in32r */
1326/* Description: Input 32 bits and byte reverse */
1327/*------------------------------------------------------------------------------- */
1328 .globl in32r
1329in32r:
1330 lwbrx r3,r0,r3
1331 blr
1332
wdenk0442ed82002-11-03 10:24:00 +00001333/*
1334 * void relocate_code (addr_sp, gd, addr_moni)
1335 *
1336 * This "function" does not return, instead it continues in RAM
1337 * after relocating the monitor code.
1338 *
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001339 * r3 = Relocated stack pointer
1340 * r4 = Relocated global data pointer
1341 * r5 = Relocated text pointer
wdenk0442ed82002-11-03 10:24:00 +00001342 */
1343 .globl relocate_code
1344relocate_code:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001345#if defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS)
Stefan Roese9b94ac62007-10-31 17:55:58 +01001346 /*
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001347 * We need to flush the initial global data (gd_t) before the dcache
1348 * will be invalidated.
Stefan Roese9b94ac62007-10-31 17:55:58 +01001349 */
1350
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001351 /* Save registers */
1352 mr r9, r3
1353 mr r10, r4
1354 mr r11, r5
Stefan Roese9b94ac62007-10-31 17:55:58 +01001355
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001356 /* Flush initial global data range */
1357 mr r3, r4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001358 addi r4, r4, CONFIG_SYS_GBL_DATA_SIZE@l
Stefan Roese9b94ac62007-10-31 17:55:58 +01001359 bl flush_dcache_range
1360
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001361#if defined(CONFIG_SYS_INIT_DCACHE_CS)
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001362 /*
1363 * Undo the earlier data cache set-up for the primordial stack and
1364 * data area. First, invalidate the data cache and then disable data
1365 * cacheability for that area. Finally, restore the EBC values, if
1366 * any.
1367 */
1368
1369 /* Invalidate the primordial stack and data area in cache */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001370 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
1371 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001372
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001373 lis r4, CONFIG_SYS_INIT_RAM_END@h
1374 ori r4, r4, CONFIG_SYS_INIT_RAM_END@l
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001375 add r4, r4, r3
1376
1377 bl invalidate_dcache_range
1378
1379 /* Disable cacheability for the region */
1380 mfdccr r3
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001381 lis r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
1382 ori r4, r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001383 and r3, r3, r4
1384 mtdccr r3
1385
1386 /* Restore the EBC parameters */
1387 li r3, PBxAP
1388 mtdcr ebccfga, r3
1389 lis r3, PBxAP_VAL@h
1390 ori r3, r3, PBxAP_VAL@l
1391 mtdcr ebccfgd, r3
1392
1393 li r3, PBxCR
1394 mtdcr ebccfga, r3
1395 lis r3, PBxCR_VAL@h
1396 ori r3, r3, PBxCR_VAL@l
1397 mtdcr ebccfgd, r3
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001398#endif /* defined(CONFIG_SYS_INIT_DCACHE_CS) */
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001399
1400 /* Restore registers */
1401 mr r3, r9
1402 mr r4, r10
1403 mr r5, r11
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001404#endif /* defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS) */
Stefan Roesee02c5212008-01-09 10:23:16 +01001405
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001406#ifdef CONFIG_SYS_INIT_RAM_DCACHE
Stefan Roesee02c5212008-01-09 10:23:16 +01001407 /*
1408 * Unlock the previously locked d-cache
1409 */
1410 msync
1411 isync
1412 /* set TFLOOR/NFLOOR to 0 again */
1413 lis r6,0x0001
1414 ori r6,r6,0xf800
1415 mtspr dvlim,r6
1416 lis r6,0x0000
1417 ori r6,r6,0x0000
1418 mtspr dnv0,r6
1419 mtspr dnv1,r6
1420 mtspr dnv2,r6
1421 mtspr dnv3,r6
1422 mtspr dtv0,r6
1423 mtspr dtv1,r6
1424 mtspr dtv2,r6
1425 mtspr dtv3,r6
1426 msync
1427 isync
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001428#endif /* CONFIG_SYS_INIT_RAM_DCACHE */
Stefan Roesee02c5212008-01-09 10:23:16 +01001429
Stefan Roese887e2ec2006-09-07 11:51:23 +02001430#if defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
1431 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roese2801b2d2008-03-11 15:05:50 +01001432 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Feng Kan7d307932008-07-08 22:47:31 -07001433 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1434 defined(CONFIG_460SX)
Stefan Roesea4c8d132006-06-02 16:18:04 +02001435 /*
1436 * On some 440er platforms the cache is enabled in the first TLB (Boot-CS)
1437 * to speed up the boot process. Now this cache needs to be disabled.
1438 */
1439 iccci 0,0 /* Invalidate inst cache */
1440 dccci 0,0 /* Invalidate data cache, now no longer our stack */
Stefan Roesec157d8e2005-08-01 16:41:48 +02001441 sync
Stefan Roesea4c8d132006-06-02 16:18:04 +02001442 isync
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001443#ifdef CONFIG_SYS_TLB_FOR_BOOT_FLASH
1444 addi r1,r0,CONFIG_SYS_TLB_FOR_BOOT_FLASH /* Use defined TLB */
Niklaus Giger85dc2a72007-11-30 18:35:11 +01001445#else
1446 addi r1,r0,0x0000 /* Default TLB entry is #0 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001447#endif /* CONFIG_SYS_TLB_FOR_BOOT_FLASH */
Stefan Roesec157d8e2005-08-01 16:41:48 +02001448 tlbre r0,r1,0x0002 /* Read contents */
Stefan Roese6e7fb6e2005-11-29 18:18:21 +01001449 ori r0,r0,0x0c00 /* Or in the inhibit, write through bit */
Wolfgang Denkf901a832005-08-06 01:42:58 +02001450 tlbwe r0,r1,0x0002 /* Save it out */
Stefan Roesea4c8d132006-06-02 16:18:04 +02001451 sync
Stefan Roesec157d8e2005-08-01 16:41:48 +02001452 isync
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001453#endif /* defined(CONFIG_440EP) || ... || defined(CONFIG_460GT) */
wdenk0442ed82002-11-03 10:24:00 +00001454 mr r1, r3 /* Set new stack pointer */
1455 mr r9, r4 /* Save copy of Init Data pointer */
1456 mr r10, r5 /* Save copy of Destination Address */
1457
1458 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001459 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
1460 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
wdenk3b57fe02003-05-30 12:48:29 +00001461 lwz r5, GOT(__init_end)
1462 sub r5, r5, r4
Stefan Roese9b94ac62007-10-31 17:55:58 +01001463 li r6, L1_CACHE_BYTES /* Cache Line Size */
wdenk0442ed82002-11-03 10:24:00 +00001464
1465 /*
1466 * Fix GOT pointer:
1467 *
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001468 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
wdenk0442ed82002-11-03 10:24:00 +00001469 *
1470 * Offset:
1471 */
1472 sub r15, r10, r4
1473
1474 /* First our own GOT */
1475 add r14, r14, r15
Grant Ericksonc821b5f2008-05-22 14:44:14 -07001476 /* then the one used by the C code */
wdenk0442ed82002-11-03 10:24:00 +00001477 add r30, r30, r15
1478
1479 /*
1480 * Now relocate code
1481 */
1482
1483 cmplw cr1,r3,r4
1484 addi r0,r5,3
1485 srwi. r0,r0,2
1486 beq cr1,4f /* In place copy is not necessary */
1487 beq 7f /* Protect against 0 count */
1488 mtctr r0
1489 bge cr1,2f
1490
1491 la r8,-4(r4)
1492 la r7,-4(r3)
14931: lwzu r0,4(r8)
1494 stwu r0,4(r7)
1495 bdnz 1b
1496 b 4f
1497
14982: slwi r0,r0,2
1499 add r8,r4,r0
1500 add r7,r3,r0
15013: lwzu r0,-4(r8)
1502 stwu r0,-4(r7)
1503 bdnz 3b
1504
1505/*
1506 * Now flush the cache: note that we must start from a cache aligned
1507 * address. Otherwise we might miss one cache line.
1508 */
15094: cmpwi r6,0
1510 add r5,r3,r5
1511 beq 7f /* Always flush prefetch queue in any case */
1512 subi r0,r6,1
1513 andc r3,r3,r0
1514 mr r4,r3
15155: dcbst 0,r4
1516 add r4,r4,r6
1517 cmplw r4,r5
1518 blt 5b
1519 sync /* Wait for all dcbst to complete on bus */
1520 mr r4,r3
15216: icbi 0,r4
1522 add r4,r4,r6
1523 cmplw r4,r5
1524 blt 6b
15257: sync /* Wait for all icbi to complete on bus */
1526 isync
1527
1528/*
1529 * We are done. Do not return, instead branch to second part of board
1530 * initialization, now running from RAM.
1531 */
1532
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001533 addi r0, r10, in_ram - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001534 mtlr r0
1535 blr /* NEVER RETURNS! */
1536
1537in_ram:
1538
1539 /*
1540 * Relocation Function, r14 point to got2+0x8000
1541 *
1542 * Adjust got2 pointers, no need to check for 0, this code
1543 * already puts a few entries in the table.
1544 */
1545 li r0,__got2_entries@sectoff@l
1546 la r3,GOT(_GOT2_TABLE_)
1547 lwz r11,GOT(_GOT2_TABLE_)
1548 mtctr r0
1549 sub r11,r3,r11
1550 addi r3,r3,-4
15511: lwzu r0,4(r3)
1552 add r0,r0,r11
1553 stw r0,0(r3)
1554 bdnz 1b
1555
1556 /*
1557 * Now adjust the fixups and the pointers to the fixups
1558 * in case we need to move ourselves again.
1559 */
15602: li r0,__fixup_entries@sectoff@l
1561 lwz r3,GOT(_FIXUP_TABLE_)
1562 cmpwi r0,0
1563 mtctr r0
1564 addi r3,r3,-4
1565 beq 4f
15663: lwzu r4,4(r3)
1567 lwzux r0,r4,r11
1568 add r0,r0,r11
1569 stw r10,0(r3)
1570 stw r0,0(r4)
1571 bdnz 3b
15724:
1573clear_bss:
1574 /*
1575 * Now clear BSS segment
1576 */
wdenk5d232d02003-05-22 22:52:13 +00001577 lwz r3,GOT(__bss_start)
wdenk0442ed82002-11-03 10:24:00 +00001578 lwz r4,GOT(_end)
1579
1580 cmplw 0, r3, r4
Anatolij Gustschin42ed33f2007-12-05 17:43:20 +01001581 beq 7f
wdenk0442ed82002-11-03 10:24:00 +00001582
1583 li r0, 0
Anatolij Gustschin42ed33f2007-12-05 17:43:20 +01001584
1585 andi. r5, r4, 3
1586 beq 6f
1587 sub r4, r4, r5
1588 mtctr r5
1589 mr r5, r4
15905: stb r0, 0(r5)
1591 addi r5, r5, 1
1592 bdnz 5b
15936:
wdenk0442ed82002-11-03 10:24:00 +00001594 stw r0, 0(r3)
1595 addi r3, r3, 4
1596 cmplw 0, r3, r4
Anatolij Gustschin42ed33f2007-12-05 17:43:20 +01001597 bne 6b
wdenk0442ed82002-11-03 10:24:00 +00001598
Anatolij Gustschin42ed33f2007-12-05 17:43:20 +010015997:
wdenk0442ed82002-11-03 10:24:00 +00001600 mr r3, r9 /* Init Data pointer */
1601 mr r4, r10 /* Destination Address */
1602 bl board_init_r
1603
wdenk0442ed82002-11-03 10:24:00 +00001604 /*
1605 * Copy exception vector code to low memory
1606 *
1607 * r3: dest_addr
1608 * r7: source address, r8: end address, r9: target address
1609 */
1610 .globl trap_init
1611trap_init:
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001612 lwz r7, GOT(_start_of_vectors)
wdenk0442ed82002-11-03 10:24:00 +00001613 lwz r8, GOT(_end_of_vectors)
1614
wdenk682011f2003-06-03 23:54:09 +00001615 li r9, 0x100 /* reset vector always at 0x100 */
wdenk0442ed82002-11-03 10:24:00 +00001616
1617 cmplw 0, r7, r8
1618 bgelr /* return if r7>=r8 - just in case */
1619
1620 mflr r4 /* save link register */
16211:
1622 lwz r0, 0(r7)
1623 stw r0, 0(r9)
1624 addi r7, r7, 4
1625 addi r9, r9, 4
1626 cmplw 0, r7, r8
1627 bne 1b
1628
1629 /*
1630 * relocate `hdlr' and `int_return' entries
1631 */
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001632 li r7, .L_MachineCheck - _start + _START_OFFSET
1633 li r8, Alignment - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +000016342:
1635 bl trap_reloc
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001636 addi r7, r7, 0x100 /* next exception vector */
wdenk0442ed82002-11-03 10:24:00 +00001637 cmplw 0, r7, r8
1638 blt 2b
1639
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001640 li r7, .L_Alignment - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001641 bl trap_reloc
1642
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001643 li r7, .L_ProgramCheck - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001644 bl trap_reloc
1645
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001646#ifdef CONFIG_440
1647 li r7, .L_FPUnavailable - _start + _START_OFFSET
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +02001648 bl trap_reloc
wdenk0442ed82002-11-03 10:24:00 +00001649
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001650 li r7, .L_Decrementer - _start + _START_OFFSET
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +02001651 bl trap_reloc
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001652
1653 li r7, .L_APU - _start + _START_OFFSET
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +02001654 bl trap_reloc
Stefan Roesedf8a24c2007-06-19 16:42:31 +02001655
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +02001656 li r7, .L_InstructionTLBError - _start + _START_OFFSET
1657 bl trap_reloc
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001658
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +02001659 li r7, .L_DataTLBError - _start + _START_OFFSET
1660 bl trap_reloc
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001661#else /* CONFIG_440 */
1662 li r7, .L_PIT - _start + _START_OFFSET
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +02001663 bl trap_reloc
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001664
1665 li r7, .L_InstructionTLBMiss - _start + _START_OFFSET
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +02001666 bl trap_reloc
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001667
1668 li r7, .L_DataTLBMiss - _start + _START_OFFSET
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +02001669 bl trap_reloc
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +02001670#endif /* CONFIG_440 */
1671
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +02001672 li r7, .L_DebugBreakpoint - _start + _START_OFFSET
1673 bl trap_reloc
wdenk0442ed82002-11-03 10:24:00 +00001674
Stefan Roese887e2ec2006-09-07 11:51:23 +02001675#if !defined(CONFIG_440)
Stefan Roese9a7b4082006-03-13 09:42:28 +01001676 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1677 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
1678 mtmsr r7 /* change MSR */
1679#else
Stefan Roese887e2ec2006-09-07 11:51:23 +02001680 bl __440_msr_set
1681 b __440_msr_continue
Stefan Roese9a7b4082006-03-13 09:42:28 +01001682
Stefan Roese887e2ec2006-09-07 11:51:23 +02001683__440_msr_set:
Stefan Roese9a7b4082006-03-13 09:42:28 +01001684 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1685 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
1686 mtspr srr1,r7
1687 mflr r7
1688 mtspr srr0,r7
1689 rfi
Stefan Roese887e2ec2006-09-07 11:51:23 +02001690__440_msr_continue:
Stefan Roese9a7b4082006-03-13 09:42:28 +01001691#endif
1692
wdenk0442ed82002-11-03 10:24:00 +00001693 mtlr r4 /* restore link register */
1694 blr
1695
1696 /*
1697 * Function: relocate entries for one exception vector
1698 */
1699trap_reloc:
1700 lwz r0, 0(r7) /* hdlr ... */
1701 add r0, r0, r3 /* ... += dest_addr */
1702 stw r0, 0(r7)
1703
1704 lwz r0, 4(r7) /* int_return ... */
1705 add r0, r0, r3 /* ... += dest_addr */
1706 stw r0, 4(r7)
1707
1708 blr
Stefan Roesecf959c72007-06-01 15:27:11 +02001709
1710#if defined(CONFIG_440)
1711/*----------------------------------------------------------------------------+
1712| dcbz_area.
1713+----------------------------------------------------------------------------*/
1714 function_prolog(dcbz_area)
1715 rlwinm. r5,r4,0,27,31
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +02001716 rlwinm r5,r4,27,5,31
1717 beq ..d_ra2
1718 addi r5,r5,0x0001
1719..d_ra2:mtctr r5
1720..d_ag2:dcbz r0,r3
1721 addi r3,r3,32
1722 bdnz ..d_ag2
Stefan Roesecf959c72007-06-01 15:27:11 +02001723 sync
1724 blr
1725 function_epilog(dcbz_area)
Stefan Roesecf959c72007-06-01 15:27:11 +02001726#endif /* CONFIG_440 */
Stefan Roese887e2ec2006-09-07 11:51:23 +02001727#endif /* CONFIG_NAND_SPL */
stroeseb867d702003-05-23 11:18:02 +00001728
Stefan Roesecf959c72007-06-01 15:27:11 +02001729/*------------------------------------------------------------------------------- */
1730/* Function: in8 */
1731/* Description: Input 8 bits */
1732/*------------------------------------------------------------------------------- */
1733 .globl in8
1734in8:
1735 lbz r3,0x0000(r3)
1736 blr
1737
1738/*------------------------------------------------------------------------------- */
1739/* Function: out8 */
1740/* Description: Output 8 bits */
1741/*------------------------------------------------------------------------------- */
1742 .globl out8
1743out8:
1744 stb r4,0x0000(r3)
1745 blr
1746
1747/*------------------------------------------------------------------------------- */
1748/* Function: out32 */
1749/* Description: Output 32 bits */
1750/*------------------------------------------------------------------------------- */
1751 .globl out32
1752out32:
1753 stw r4,0x0000(r3)
1754 blr
1755
1756/*------------------------------------------------------------------------------- */
1757/* Function: in32 */
1758/* Description: Input 32 bits */
1759/*------------------------------------------------------------------------------- */
1760 .globl in32
1761in32:
1762 lwz 3,0x0000(3)
1763 blr
stroeseb867d702003-05-23 11:18:02 +00001764
1765/**************************************************************************/
Wolfgang Denkf901a832005-08-06 01:42:58 +02001766/* PPC405EP specific stuff */
stroeseb867d702003-05-23 11:18:02 +00001767/**************************************************************************/
1768#ifdef CONFIG_405EP
1769ppc405ep_init:
stroeseb828dda2003-12-09 14:54:43 +00001770
Stefan Roesec157d8e2005-08-01 16:41:48 +02001771#ifdef CONFIG_BUBINGA
stroeseb828dda2003-12-09 14:54:43 +00001772 /*
1773 * Initialize EBC chip selects 1 & 4 and GPIO pins (for alternate
1774 * function) to support FPGA and NVRAM accesses below.
1775 */
1776
1777 lis r3,GPIO0_OSRH@h /* config GPIO output select */
1778 ori r3,r3,GPIO0_OSRH@l
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001779 lis r4,CONFIG_SYS_GPIO0_OSRH@h
1780 ori r4,r4,CONFIG_SYS_GPIO0_OSRH@l
stroeseb828dda2003-12-09 14:54:43 +00001781 stw r4,0(r3)
1782 lis r3,GPIO0_OSRL@h
1783 ori r3,r3,GPIO0_OSRL@l
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001784 lis r4,CONFIG_SYS_GPIO0_OSRL@h
1785 ori r4,r4,CONFIG_SYS_GPIO0_OSRL@l
stroeseb828dda2003-12-09 14:54:43 +00001786 stw r4,0(r3)
1787
1788 lis r3,GPIO0_ISR1H@h /* config GPIO input select */
1789 ori r3,r3,GPIO0_ISR1H@l
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001790 lis r4,CONFIG_SYS_GPIO0_ISR1H@h
1791 ori r4,r4,CONFIG_SYS_GPIO0_ISR1H@l
stroeseb828dda2003-12-09 14:54:43 +00001792 stw r4,0(r3)
1793 lis r3,GPIO0_ISR1L@h
1794 ori r3,r3,GPIO0_ISR1L@l
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001795 lis r4,CONFIG_SYS_GPIO0_ISR1L@h
1796 ori r4,r4,CONFIG_SYS_GPIO0_ISR1L@l
stroeseb828dda2003-12-09 14:54:43 +00001797 stw r4,0(r3)
1798
1799 lis r3,GPIO0_TSRH@h /* config GPIO three-state select */
1800 ori r3,r3,GPIO0_TSRH@l
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001801 lis r4,CONFIG_SYS_GPIO0_TSRH@h
1802 ori r4,r4,CONFIG_SYS_GPIO0_TSRH@l
stroeseb828dda2003-12-09 14:54:43 +00001803 stw r4,0(r3)
1804 lis r3,GPIO0_TSRL@h
1805 ori r3,r3,GPIO0_TSRL@l
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001806 lis r4,CONFIG_SYS_GPIO0_TSRL@h
1807 ori r4,r4,CONFIG_SYS_GPIO0_TSRL@l
stroeseb828dda2003-12-09 14:54:43 +00001808 stw r4,0(r3)
1809
1810 lis r3,GPIO0_TCR@h /* config GPIO driver output enables */
1811 ori r3,r3,GPIO0_TCR@l
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001812 lis r4,CONFIG_SYS_GPIO0_TCR@h
1813 ori r4,r4,CONFIG_SYS_GPIO0_TCR@l
stroeseb828dda2003-12-09 14:54:43 +00001814 stw r4,0(r3)
1815
1816 li r3,pb1ap /* program EBC bank 1 for RTC access */
1817 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001818 lis r3,CONFIG_SYS_EBC_PB1AP@h
1819 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
stroeseb828dda2003-12-09 14:54:43 +00001820 mtdcr ebccfgd,r3
1821 li r3,pb1cr
1822 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001823 lis r3,CONFIG_SYS_EBC_PB1CR@h
1824 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
stroeseb828dda2003-12-09 14:54:43 +00001825 mtdcr ebccfgd,r3
1826
1827 li r3,pb1ap /* program EBC bank 1 for RTC access */
1828 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001829 lis r3,CONFIG_SYS_EBC_PB1AP@h
1830 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
stroeseb828dda2003-12-09 14:54:43 +00001831 mtdcr ebccfgd,r3
1832 li r3,pb1cr
1833 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001834 lis r3,CONFIG_SYS_EBC_PB1CR@h
1835 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
stroeseb828dda2003-12-09 14:54:43 +00001836 mtdcr ebccfgd,r3
1837
1838 li r3,pb4ap /* program EBC bank 4 for FPGA access */
1839 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001840 lis r3,CONFIG_SYS_EBC_PB4AP@h
1841 ori r3,r3,CONFIG_SYS_EBC_PB4AP@l
stroeseb828dda2003-12-09 14:54:43 +00001842 mtdcr ebccfgd,r3
1843 li r3,pb4cr
1844 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001845 lis r3,CONFIG_SYS_EBC_PB4CR@h
1846 ori r3,r3,CONFIG_SYS_EBC_PB4CR@l
stroeseb828dda2003-12-09 14:54:43 +00001847 mtdcr ebccfgd,r3
1848#endif
1849
wdenk8bde7f72003-06-27 21:31:46 +00001850 /*
1851 !-----------------------------------------------------------------------
1852 ! Check to see if chip is in bypass mode.
1853 ! If so, write stored CPC0_PLLMR0 and CPC0_PLLMR1 values and perform a
1854 ! CPU reset Otherwise, skip this step and keep going.
Wolfgang Denkf901a832005-08-06 01:42:58 +02001855 ! Note: Running BIOS in bypass mode is not supported since PLB speed
1856 ! will not be fast enough for the SDRAM (min 66MHz)
wdenk8bde7f72003-06-27 21:31:46 +00001857 !-----------------------------------------------------------------------
stroeseb867d702003-05-23 11:18:02 +00001858 */
Wolfgang Denkf901a832005-08-06 01:42:58 +02001859 mfdcr r5, CPC0_PLLMR1
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001860 rlwinm r4,r5,1,0x1 /* get system clock source (SSCS) */
Wolfgang Denkf901a832005-08-06 01:42:58 +02001861 cmpi cr0,0,r4,0x1
stroeseb867d702003-05-23 11:18:02 +00001862
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001863 beq pll_done /* if SSCS =b'1' then PLL has */
1864 /* already been set */
1865 /* and CPU has been reset */
1866 /* so skip to next section */
stroeseb867d702003-05-23 11:18:02 +00001867
Stefan Roesec157d8e2005-08-01 16:41:48 +02001868#ifdef CONFIG_BUBINGA
stroeseb867d702003-05-23 11:18:02 +00001869 /*
wdenk8bde7f72003-06-27 21:31:46 +00001870 !-----------------------------------------------------------------------
1871 ! Read NVRAM to get value to write in PLLMR.
1872 ! If value has not been correctly saved, write default value
1873 ! Default config values (assuming on-board 33MHz SYS_CLK) are above.
1874 ! See CPU_DEFAULT_200 and CPU_DEFAULT_266 above.
1875 !
1876 ! WARNING: This code assumes the first three words in the nvram_t
Wolfgang Denkf901a832005-08-06 01:42:58 +02001877 ! structure in openbios.h. Changing the beginning of
1878 ! the structure will break this code.
wdenk8bde7f72003-06-27 21:31:46 +00001879 !
1880 !-----------------------------------------------------------------------
stroeseb867d702003-05-23 11:18:02 +00001881 */
Wolfgang Denkf901a832005-08-06 01:42:58 +02001882 addis r3,0,NVRAM_BASE@h
1883 addi r3,r3,NVRAM_BASE@l
stroeseb867d702003-05-23 11:18:02 +00001884
Wolfgang Denkf901a832005-08-06 01:42:58 +02001885 lwz r4, 0(r3)
1886 addis r5,0,NVRVFY1@h
1887 addi r5,r5,NVRVFY1@l
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001888 cmp cr0,0,r4,r5 /* Compare 1st NVRAM Magic number*/
Wolfgang Denkf901a832005-08-06 01:42:58 +02001889 bne ..no_pllset
1890 addi r3,r3,4
1891 lwz r4, 0(r3)
1892 addis r5,0,NVRVFY2@h
1893 addi r5,r5,NVRVFY2@l
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001894 cmp cr0,0,r4,r5 /* Compare 2 NVRAM Magic number */
Wolfgang Denkf901a832005-08-06 01:42:58 +02001895 bne ..no_pllset
1896 addi r3,r3,8 /* Skip over conf_size */
1897 lwz r4, 4(r3) /* Load PLLMR1 value from NVRAM */
1898 lwz r3, 0(r3) /* Load PLLMR0 value from NVRAM */
1899 rlwinm r5,r4,1,0x1 /* get system clock source (SSCS) */
1900 cmpi cr0,0,r5,1 /* See if PLL is locked */
1901 beq pll_write
stroeseb867d702003-05-23 11:18:02 +00001902..no_pllset:
Stefan Roesec157d8e2005-08-01 16:41:48 +02001903#endif /* CONFIG_BUBINGA */
stroeseb867d702003-05-23 11:18:02 +00001904
John Otkend4024bb2007-07-26 17:49:11 +02001905#ifdef CONFIG_TAIHU
1906 mfdcr r4, CPC0_BOOT
1907 andi. r5, r4, CPC0_BOOT_SEP@l
1908 bne strap_1 /* serial eeprom present */
1909 addis r5,0,CPLD_REG0_ADDR@h
1910 ori r5,r5,CPLD_REG0_ADDR@l
1911 andi. r5, r5, 0x10
1912 bne _pci_66mhz
1913#endif /* CONFIG_TAIHU */
1914
Stefan Roese779e9752007-08-14 14:44:41 +02001915#if defined(CONFIG_ZEUS)
1916 mfdcr r4, CPC0_BOOT
1917 andi. r5, r4, CPC0_BOOT_SEP@l
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001918 bne strap_1 /* serial eeprom present */
Stefan Roese779e9752007-08-14 14:44:41 +02001919 lis r3,0x0000
1920 addi r3,r3,0x3030
1921 lis r4,0x8042
1922 addi r4,r4,0x223e
1923 b 1f
1924strap_1:
1925 mfdcr r3, CPC0_PLLMR0
1926 mfdcr r4, CPC0_PLLMR1
1927 b 1f
1928#endif
1929
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001930 addis r3,0,PLLMR0_DEFAULT@h /* PLLMR0 default value */
1931 ori r3,r3,PLLMR0_DEFAULT@l /* */
1932 addis r4,0,PLLMR1_DEFAULT@h /* PLLMR1 default value */
1933 ori r4,r4,PLLMR1_DEFAULT@l /* */
stroeseb867d702003-05-23 11:18:02 +00001934
John Otkend4024bb2007-07-26 17:49:11 +02001935#ifdef CONFIG_TAIHU
1936 b 1f
1937_pci_66mhz:
1938 addis r3,0,PLLMR0_DEFAULT_PCI66@h
1939 ori r3,r3,PLLMR0_DEFAULT_PCI66@l
1940 addis r4,0,PLLMR1_DEFAULT_PCI66@h
1941 ori r4,r4,PLLMR1_DEFAULT_PCI66@l
1942 b 1f
1943strap_1:
1944 mfdcr r3, CPC0_PLLMR0
1945 mfdcr r4, CPC0_PLLMR1
John Otkend4024bb2007-07-26 17:49:11 +02001946#endif /* CONFIG_TAIHU */
1947
Stefan Roese779e9752007-08-14 14:44:41 +020019481:
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001949 b pll_write /* Write the CPC0_PLLMR with new value */
stroeseb867d702003-05-23 11:18:02 +00001950
1951pll_done:
wdenk8bde7f72003-06-27 21:31:46 +00001952 /*
1953 !-----------------------------------------------------------------------
1954 ! Clear Soft Reset Register
1955 ! This is needed to enable PCI if not booting from serial EPROM
1956 !-----------------------------------------------------------------------
stroeseb867d702003-05-23 11:18:02 +00001957 */
Wolfgang Denkf901a832005-08-06 01:42:58 +02001958 addi r3, 0, 0x0
1959 mtdcr CPC0_SRR, r3
stroeseb867d702003-05-23 11:18:02 +00001960
Wolfgang Denkf901a832005-08-06 01:42:58 +02001961 addis r3,0,0x0010
1962 mtctr r3
stroeseb867d702003-05-23 11:18:02 +00001963pci_wait:
Wolfgang Denkf901a832005-08-06 01:42:58 +02001964 bdnz pci_wait
stroeseb867d702003-05-23 11:18:02 +00001965
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001966 blr /* return to main code */
stroeseb867d702003-05-23 11:18:02 +00001967
1968/*
1969!-----------------------------------------------------------------------------
Wolfgang Denkf901a832005-08-06 01:42:58 +02001970! Function: pll_write
1971! Description: Updates the value of the CPC0_PLLMR according to CMOS27E documentation
1972! That is:
1973! 1. Pll is first disabled (de-activated by putting in bypass mode)
1974! 2. PLL is reset
1975! 3. Clock dividers are set while PLL is held in reset and bypassed
1976! 4. PLL Reset is cleared
1977! 5. Wait 100us for PLL to lock
1978! 6. A core reset is performed
stroeseb867d702003-05-23 11:18:02 +00001979! Input: r3 = Value to write to CPC0_PLLMR0
1980! Input: r4 = Value to write to CPC0_PLLMR1
1981! Output r3 = none
1982!-----------------------------------------------------------------------------
1983*/
1984pll_write:
wdenk8bde7f72003-06-27 21:31:46 +00001985 mfdcr r5, CPC0_UCR
1986 andis. r5,r5,0xFFFF
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001987 ori r5,r5,0x0101 /* Stop the UART clocks */
1988 mtdcr CPC0_UCR,r5 /* Before changing PLL */
stroeseb867d702003-05-23 11:18:02 +00001989
wdenk8bde7f72003-06-27 21:31:46 +00001990 mfdcr r5, CPC0_PLLMR1
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001991 rlwinm r5,r5,0,0x7FFFFFFF /* Disable PLL */
Wolfgang Denkf901a832005-08-06 01:42:58 +02001992 mtdcr CPC0_PLLMR1,r5
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001993 oris r5,r5,0x4000 /* Set PLL Reset */
Wolfgang Denkf901a832005-08-06 01:42:58 +02001994 mtdcr CPC0_PLLMR1,r5
stroeseb867d702003-05-23 11:18:02 +00001995
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001996 mtdcr CPC0_PLLMR0,r3 /* Set clock dividers */
1997 rlwinm r5,r4,0,0x3FFFFFFF /* Reset & Bypass new PLL dividers */
1998 oris r5,r5,0x4000 /* Set PLL Reset */
1999 mtdcr CPC0_PLLMR1,r5 /* Set clock dividers */
2000 rlwinm r5,r5,0,0xBFFFFFFF /* Clear PLL Reset */
Wolfgang Denkf901a832005-08-06 01:42:58 +02002001 mtdcr CPC0_PLLMR1,r5
stroeseb867d702003-05-23 11:18:02 +00002002
2003 /*
wdenk8bde7f72003-06-27 21:31:46 +00002004 ! Wait min of 100us for PLL to lock.
2005 ! See CMOS 27E databook for more info.
2006 ! At 200MHz, that means waiting 20,000 instructions
stroeseb867d702003-05-23 11:18:02 +00002007 */
Wolfgang Denkf901a832005-08-06 01:42:58 +02002008 addi r3,0,20000 /* 2000 = 0x4e20 */
2009 mtctr r3
stroeseb867d702003-05-23 11:18:02 +00002010pll_wait:
Wolfgang Denkf901a832005-08-06 01:42:58 +02002011 bdnz pll_wait
stroeseb867d702003-05-23 11:18:02 +00002012
Wolfgang Denkf901a832005-08-06 01:42:58 +02002013 oris r5,r5,0x8000 /* Enable PLL */
2014 mtdcr CPC0_PLLMR1,r5 /* Engage */
stroeseb867d702003-05-23 11:18:02 +00002015
wdenk8bde7f72003-06-27 21:31:46 +00002016 /*
2017 * Reset CPU to guarantee timings are OK
2018 * Not sure if this is needed...
2019 */
2020 addis r3,0,0x1000
Wolfgang Denk53677ef2008-05-20 16:00:29 +02002021 mtspr dbcr0,r3 /* This will cause a CPU core reset, and */
2022 /* execution will continue from the poweron */
2023 /* vector of 0xfffffffc */
stroeseb867d702003-05-23 11:18:02 +00002024#endif /* CONFIG_405EP */
Stefan Roese4745aca2007-02-20 10:57:08 +01002025
2026#if defined(CONFIG_440)
Stefan Roese4745aca2007-02-20 10:57:08 +01002027/*----------------------------------------------------------------------------+
2028| mttlb3.
2029+----------------------------------------------------------------------------*/
2030 function_prolog(mttlb3)
2031 TLBWE(4,3,2)
2032 blr
2033 function_epilog(mttlb3)
2034
2035/*----------------------------------------------------------------------------+
2036| mftlb3.
2037+----------------------------------------------------------------------------*/
2038 function_prolog(mftlb3)
Wolfgang Denk74357112007-02-27 14:26:04 +01002039 TLBRE(3,3,2)
Stefan Roese4745aca2007-02-20 10:57:08 +01002040 blr
2041 function_epilog(mftlb3)
2042
2043/*----------------------------------------------------------------------------+
2044| mttlb2.
2045+----------------------------------------------------------------------------*/
2046 function_prolog(mttlb2)
2047 TLBWE(4,3,1)
2048 blr
2049 function_epilog(mttlb2)
2050
2051/*----------------------------------------------------------------------------+
2052| mftlb2.
2053+----------------------------------------------------------------------------*/
2054 function_prolog(mftlb2)
Wolfgang Denk74357112007-02-27 14:26:04 +01002055 TLBRE(3,3,1)
Stefan Roese4745aca2007-02-20 10:57:08 +01002056 blr
2057 function_epilog(mftlb2)
2058
2059/*----------------------------------------------------------------------------+
2060| mttlb1.
2061+----------------------------------------------------------------------------*/
2062 function_prolog(mttlb1)
2063 TLBWE(4,3,0)
2064 blr
2065 function_epilog(mttlb1)
2066
2067/*----------------------------------------------------------------------------+
2068| mftlb1.
2069+----------------------------------------------------------------------------*/
2070 function_prolog(mftlb1)
Wolfgang Denk74357112007-02-27 14:26:04 +01002071 TLBRE(3,3,0)
Stefan Roese4745aca2007-02-20 10:57:08 +01002072 blr
2073 function_epilog(mftlb1)
2074#endif /* CONFIG_440 */
Stefan Roese64852d02008-06-02 14:35:44 +02002075
2076#if defined(CONFIG_NAND_SPL)
2077/*
2078 * void nand_boot_relocate(dst, src, bytes)
2079 *
2080 * r3 = Destination address to copy code to (in SDRAM)
2081 * r4 = Source address to copy code from
2082 * r5 = size to copy in bytes
2083 */
2084nand_boot_relocate:
2085 mr r6,r3
2086 mr r7,r4
2087 mflr r8
2088
2089 /*
2090 * Copy SPL from icache into SDRAM
2091 */
2092 subi r3,r3,4
2093 subi r4,r4,4
2094 srwi r5,r5,2
2095 mtctr r5
2096..spl_loop:
2097 lwzu r0,4(r4)
2098 stwu r0,4(r3)
2099 bdnz ..spl_loop
2100
2101 /*
2102 * Calculate "corrected" link register, so that we "continue"
2103 * in execution in destination range
2104 */
2105 sub r3,r7,r6 /* r3 = src - dst */
2106 sub r8,r8,r3 /* r8 = link-reg - (src - dst) */
2107 mtlr r8
2108 blr
2109
2110nand_boot_common:
2111 /*
2112 * First initialize SDRAM. It has to be available *before* calling
2113 * nand_boot().
2114 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02002115 lis r3,CONFIG_SYS_SDRAM_BASE@h
2116 ori r3,r3,CONFIG_SYS_SDRAM_BASE@l
Stefan Roese64852d02008-06-02 14:35:44 +02002117 bl initdram
2118
2119 /*
2120 * Now copy the 4k SPL code into SDRAM and continue execution
2121 * from there.
2122 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02002123 lis r3,CONFIG_SYS_NAND_BOOT_SPL_DST@h
2124 ori r3,r3,CONFIG_SYS_NAND_BOOT_SPL_DST@l
2125 lis r4,CONFIG_SYS_NAND_BOOT_SPL_SRC@h
2126 ori r4,r4,CONFIG_SYS_NAND_BOOT_SPL_SRC@l
2127 lis r5,CONFIG_SYS_NAND_BOOT_SPL_SIZE@h
2128 ori r5,r5,CONFIG_SYS_NAND_BOOT_SPL_SIZE@l
Stefan Roese64852d02008-06-02 14:35:44 +02002129 bl nand_boot_relocate
2130
2131 /*
2132 * We're running from SDRAM now!!!
2133 *
2134 * It is necessary for 4xx systems to relocate from running at
2135 * the original location (0xfffffxxx) to somewhere else (SDRAM
2136 * preferably). This is because CS0 needs to be reconfigured for
2137 * NAND access. And we can't reconfigure this CS when currently
2138 * "running" from it.
2139 */
2140
2141 /*
2142 * Finally call nand_boot() to load main NAND U-Boot image from
2143 * NAND and jump to it.
2144 */
2145 bl nand_boot /* will not return */
2146#endif /* CONFIG_NAND_SPL */