blob: 7d80af5acd32a77b09e2e10e9bfc1e856454de06 [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
2 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
4 * Copyright (C) 2000, 2001,2002 Wolfgang Denk <wd@denx.de>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25/*
26 * U-Boot - Startup Code for MPC8260 PowerPC based Embedded Boards
27 */
28#include <config.h>
29#include <mpc8260.h>
Peter Tyser561858e2008-11-03 09:30:59 -060030#include <timestamp.h>
wdenk47d1a6e2002-11-03 00:01:44 +000031#include <version.h>
32
33#define CONFIG_8260 1 /* needed for Linux kernel header files */
34#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
35
36#include <ppc_asm.tmpl>
37#include <ppc_defs.h>
38
39#include <asm/cache.h>
40#include <asm/mmu.h>
41
42#ifndef CONFIG_IDENT_STRING
43#define CONFIG_IDENT_STRING ""
44#endif
45
46/* We don't want the MMU yet.
47*/
48#undef MSR_KERNEL
49/* Floating Point enable, Machine Check and Recoverable Interr. */
50#ifdef DEBUG
51#define MSR_KERNEL (MSR_FP|MSR_RI)
52#else
53#define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
54#endif
55
56/*
57 * Set up GOT: Global Offset Table
58 *
59 * Use r14 to access the GOT
60 */
61 START_GOT
62 GOT_ENTRY(_GOT2_TABLE_)
63 GOT_ENTRY(_FIXUP_TABLE_)
64
65 GOT_ENTRY(_start)
66 GOT_ENTRY(_start_of_vectors)
67 GOT_ENTRY(_end_of_vectors)
68 GOT_ENTRY(transfer_to_handler)
69
wdenk3b57fe02003-05-30 12:48:29 +000070 GOT_ENTRY(__init_end)
wdenk47d1a6e2002-11-03 00:01:44 +000071 GOT_ENTRY(_end)
wdenk5d232d02003-05-22 22:52:13 +000072 GOT_ENTRY(__bss_start)
wdenk47d1a6e2002-11-03 00:01:44 +000073#if defined(CONFIG_HYMOD)
74 GOT_ENTRY(environment)
75#endif
76 END_GOT
77
78/*
79 * Version string - must be in data segment because MPC8260 uses the first
80 * 256 bytes for the Hard Reset Configuration Word table (see below).
81 * Similarly, can't have the U-Boot Magic Number as the first thing in
82 * the image - don't know how this will affect the image tools, but I guess
83 * I'll find out soon
84 */
85 .data
86 .globl version_string
87version_string:
88 .ascii U_BOOT_VERSION
Peter Tyser561858e2008-11-03 09:30:59 -060089 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
wdenk47d1a6e2002-11-03 00:01:44 +000090 .ascii CONFIG_IDENT_STRING, "\0"
91
92/*
93 * Hard Reset Configuration Word (HRCW) table
94 *
95 * The Hard Reset Configuration Word (HRCW) sets a number of useful things
96 * such as whether there is an external memory controller, whether the
97 * PowerPC core is disabled (i.e. only the communications processor is
98 * active, accessed by another CPU on the bus), whether using external
99 * arbitration, external bus mode, boot port size, core initial prefix,
100 * internal space base, boot memory space, etc.
101 *
102 * These things dictate where the processor begins execution, where the
103 * boot ROM appears in memory, the memory controller setup when access
104 * boot ROM, etc. The HRCW is *extremely* important.
105 *
106 * The HRCW is read from the bus during reset. One CPU on the bus will
107 * be a hard reset configuration master, any others will be hard reset
108 * configuration slaves. The master reads eight HRCWs from flash during
109 * reset - the first it uses for itself, the other 7 it communicates to
110 * up to 7 configuration slaves by some complicated mechanism, which is
111 * not really important here.
112 *
113 * The configuration master performs 32 successive reads starting at address
114 * 0 and incrementing by 8 each read (i.e. on 64 bit boundaries) but only 8
115 * bits is read, and always from byte lane D[0-7] (so that port size of the
116 * boot device does not matter). The first four reads form the 32 bit HRCW
117 * for the master itself. The second four reads form the HRCW for the first
118 * slave, and so on, up to seven slaves. The 32 bit HRCW is formed by
119 * concatenating the four bytes, with the first read placed in byte 0 (the
120 * most significant byte), and so on with the fourth read placed in byte 3
121 * (the least significant byte).
122 */
123#define _HRCW_TABLE_ENTRY(w) \
124 .fill 8,1,(((w)>>24)&0xff); \
125 .fill 8,1,(((w)>>16)&0xff); \
126 .fill 8,1,(((w)>> 8)&0xff); \
127 .fill 8,1,(((w) )&0xff)
128 .text
129 .globl _hrcw_table
130_hrcw_table:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200131 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_MASTER)
132 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE1)
133 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE2)
134 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE3)
135 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE4)
136 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE5)
137 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE6)
138 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE7)
wdenk47d1a6e2002-11-03 00:01:44 +0000139/*
140 * After configuration, a system reset exception is executed using the
141 * vector at offset 0x100 relative to the base set by MSR[IP]. If MSR[IP]
142 * is 0, the base address is 0x00000000. If MSR[IP] is 1, the base address
143 * is 0xfff00000. In the case of a Power On Reset or Hard Reset, the value
144 * of MSR[IP] is determined by the CIP field in the HRCW.
145 *
146 * Other bits in the HRCW set up the Base Address and Port Size in BR0.
147 * This determines the location of the boot ROM (flash or EPROM) in the
148 * processor's address space at boot time. As long as the HRCW is set up
149 * so that we eventually end up executing the code below when the processor
150 * executes the reset exception, the actual values used should not matter.
151 *
152 * Once we have got here, the address mask in OR0 is cleared so that the
153 * bottom 32K of the boot ROM is effectively repeated all throughout the
154 * processor's address space, after which we can jump to the absolute
155 * address at which the boot ROM was linked at compile time, and proceed
156 * to initialise the memory controller without worrying if the rug will be
157 * pulled out from under us, so to speak (it will be fine as long as we
158 * configure BR0 with the same boot ROM link address).
159 */
160 . = EXC_OFF_SYS_RESET
161
162 .globl _start
163_start:
164 li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH*/
wdenk48b42612003-06-19 23:01:32 +0000165 nop
wdenk47d1a6e2002-11-03 00:01:44 +0000166 b boot_cold
167
168 . = EXC_OFF_SYS_RESET + 0x10
169
170 .globl _start_warm
171_start_warm:
172 li r21, BOOTFLAG_WARM /* Software reboot */
173 b boot_warm
174
175boot_cold:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200176#if defined(CONFIG_MPC8260ADS) && defined(CONFIG_SYS_DEFAULT_IMMR)
177 lis r3, CONFIG_SYS_DEFAULT_IMMR@h
wdenk48b42612003-06-19 23:01:32 +0000178 nop
179 lwz r4, 0(r3)
180 nop
181 rlwinm r4, r4, 0, 8, 5
182 nop
183 oris r4, r4, 0x0200
184 nop
185 stw r4, 0(r3)
186 nop
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200187#endif /* CONFIG_MPC8260ADS && CONFIG_SYS_DEFAULT_IMMR */
wdenk47d1a6e2002-11-03 00:01:44 +0000188boot_warm:
189 mfmsr r5 /* save msr contents */
190
191#if defined(CONFIG_COGENT)
192 /* this is what the cogent EPROM does */
193 li r0, 0
194 mtmsr r0
195 isync
196 bl cogent_init_8260
197#endif /* CONFIG_COGENT */
198
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200199#if defined(CONFIG_SYS_DEFAULT_IMMR)
200 lis r3, CONFIG_SYS_IMMR@h
201 ori r3, r3, CONFIG_SYS_IMMR@l
202 lis r4, CONFIG_SYS_DEFAULT_IMMR@h
wdenk47d1a6e2002-11-03 00:01:44 +0000203 stw r3, 0x1A8(r4)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200204#endif /* CONFIG_SYS_DEFAULT_IMMR */
wdenk47d1a6e2002-11-03 00:01:44 +0000205
206 /* Initialise the MPC8260 processor core */
207 /*--------------------------------------------------------------*/
208
209 bl init_8260_core
210
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200211#ifndef CONFIG_SYS_RAMBOOT
wdenk47d1a6e2002-11-03 00:01:44 +0000212 /* When booting from ROM (Flash or EPROM), clear the */
213 /* Address Mask in OR0 so ROM appears everywhere */
214 /*--------------------------------------------------------------*/
215
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200216 lis r3, (CONFIG_SYS_IMMR+IM_REGBASE)@h
wdenk47d1a6e2002-11-03 00:01:44 +0000217 lwz r4, IM_OR0@l(r3)
218 li r5, 0x7fff
219 and r4, r4, r5
220 stw r4, IM_OR0@l(r3)
221
222 /* Calculate absolute address in FLASH and jump there */
223 /*--------------------------------------------------------------*/
224
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200225 lis r3, CONFIG_SYS_MONITOR_BASE@h
226 ori r3, r3, CONFIG_SYS_MONITOR_BASE@l
wdenk47d1a6e2002-11-03 00:01:44 +0000227 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
228 mtlr r3
229 blr
230
231in_flash:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200232#endif /* CONFIG_SYS_RAMBOOT */
wdenk47d1a6e2002-11-03 00:01:44 +0000233
234 /* initialize some things that are hard to access from C */
235 /*--------------------------------------------------------------*/
236
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200237 lis r3, CONFIG_SYS_IMMR@h /* set up stack in internal DPRAM */
238 ori r1, r3, CONFIG_SYS_INIT_SP_OFFSET
wdenk47d1a6e2002-11-03 00:01:44 +0000239 li r0, 0 /* Make room for stack frame header and */
240 stwu r0, -4(r1) /* clear final stack frame so that */
241 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
242
243 /* let the C-code set up the rest */
244 /* */
245 /* Be careful to keep code relocatable ! */
246 /*--------------------------------------------------------------*/
247
248 GET_GOT /* initialize GOT access */
249
250 /* r3: IMMR */
251 bl cpu_init_f /* run low-level CPU init code (in Flash)*/
252
253#ifdef DEBUG
254 bl init_debug /* set up debugging stuff */
255#endif
256
257 mr r3, r21
258 /* r3: BOOTFLAG */
259 bl board_init_f /* run 1st part of board init code (in Flash)*/
260
261/*
262 * Vector Table
263 */
264
265 .globl _start_of_vectors
266_start_of_vectors:
267
268/* Machine check */
269 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
270
271/* Data Storage exception. */
272 STD_EXCEPTION(0x300, DataStorage, UnknownException)
273
274/* Instruction Storage exception. */
275 STD_EXCEPTION(0x400, InstStorage, UnknownException)
276
277/* External Interrupt exception. */
278 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
279
280/* Alignment exception. */
281 . = 0x600
282Alignment:
Rafal Jaworowski02032e82007-06-22 14:58:04 +0200283 EXCEPTION_PROLOG(SRR0, SRR1)
wdenk47d1a6e2002-11-03 00:01:44 +0000284 mfspr r4,DAR
285 stw r4,_DAR(r21)
286 mfspr r5,DSISR
287 stw r5,_DSISR(r21)
288 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlundfc4e1882010-01-19 14:41:55 +0100289 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
wdenk47d1a6e2002-11-03 00:01:44 +0000290
291/* Program check exception */
292 . = 0x700
293ProgramCheck:
Rafal Jaworowski02032e82007-06-22 14:58:04 +0200294 EXCEPTION_PROLOG(SRR0, SRR1)
wdenk47d1a6e2002-11-03 00:01:44 +0000295 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlundfc4e1882010-01-19 14:41:55 +0100296 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
297 MSR_KERNEL, COPY_EE)
wdenk47d1a6e2002-11-03 00:01:44 +0000298
299 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
300
301 /* I guess we could implement decrementer, and may have
302 * to someday for timekeeping.
303 */
304 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
305
306 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
307 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
wdenk27b207f2003-07-24 23:38:38 +0000308 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
wdenk47d1a6e2002-11-03 00:01:44 +0000309 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
310
311 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
312 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
313
314 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
315 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
316 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
317#ifdef DEBUG
318 . = 0x1300
319 /*
320 * This exception occurs when the program counter matches the
321 * Instruction Address Breakpoint Register (IABR).
322 *
323 * I want the cpu to halt if this occurs so I can hunt around
324 * with the debugger and look at things.
325 *
326 * When DEBUG is defined, both machine check enable (in the MSR)
327 * and checkstop reset enable (in the reset mode register) are
328 * turned off and so a checkstop condition will result in the cpu
329 * halting.
330 *
331 * I force the cpu into a checkstop condition by putting an illegal
332 * instruction here (at least this is the theory).
333 *
334 * well - that didnt work, so just do an infinite loop!
335 */
3361: b 1b
337#else
338 STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
339#endif
340 STD_EXCEPTION(0x1400, SMI, UnknownException)
341
342 STD_EXCEPTION(0x1500, Trap_15, UnknownException)
343 STD_EXCEPTION(0x1600, Trap_16, UnknownException)
344 STD_EXCEPTION(0x1700, Trap_17, UnknownException)
345 STD_EXCEPTION(0x1800, Trap_18, UnknownException)
346 STD_EXCEPTION(0x1900, Trap_19, UnknownException)
347 STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
348 STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
349 STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
350 STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
351 STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
352 STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
353 STD_EXCEPTION(0x2000, Trap_20, UnknownException)
354 STD_EXCEPTION(0x2100, Trap_21, UnknownException)
355 STD_EXCEPTION(0x2200, Trap_22, UnknownException)
356 STD_EXCEPTION(0x2300, Trap_23, UnknownException)
357 STD_EXCEPTION(0x2400, Trap_24, UnknownException)
358 STD_EXCEPTION(0x2500, Trap_25, UnknownException)
359 STD_EXCEPTION(0x2600, Trap_26, UnknownException)
360 STD_EXCEPTION(0x2700, Trap_27, UnknownException)
361 STD_EXCEPTION(0x2800, Trap_28, UnknownException)
362 STD_EXCEPTION(0x2900, Trap_29, UnknownException)
363 STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
364 STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
365 STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
366 STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
367 STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
368 STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
369
370
371 .globl _end_of_vectors
372_end_of_vectors:
373
374 . = 0x3000
375
376/*
377 * This code finishes saving the registers to the exception frame
378 * and jumps to the appropriate handler for the exception.
379 * Register r21 is pointer into trap frame, r1 has new stack pointer.
380 */
381 .globl transfer_to_handler
382transfer_to_handler:
383 stw r22,_NIP(r21)
384 lis r22,MSR_POW@h
385 andc r23,r23,r22
386 stw r23,_MSR(r21)
387 SAVE_GPR(7, r21)
388 SAVE_4GPRS(8, r21)
389 SAVE_8GPRS(12, r21)
390 SAVE_8GPRS(24, r21)
391 mflr r23
392 andi. r24,r23,0x3f00 /* get vector offset */
393 stw r24,TRAP(r21)
394 li r22,0
395 stw r22,RESULT(r21)
396 lwz r24,0(r23) /* virtual address of handler */
397 lwz r23,4(r23) /* where to go when done */
398 mtspr SRR0,r24
399 mtspr SRR1,r20
400 mtlr r23
401 SYNC
402 rfi /* jump to handler, enable MMU */
403
404int_return:
405 mfmsr r28 /* Disable interrupts */
406 li r4,0
407 ori r4,r4,MSR_EE
408 andc r28,r28,r4
409 SYNC /* Some chip revs need this... */
410 mtmsr r28
411 SYNC
412 lwz r2,_CTR(r1)
413 lwz r0,_LINK(r1)
414 mtctr r2
415 mtlr r0
416 lwz r2,_XER(r1)
417 lwz r0,_CCR(r1)
418 mtspr XER,r2
419 mtcrf 0xFF,r0
420 REST_10GPRS(3, r1)
421 REST_10GPRS(13, r1)
422 REST_8GPRS(23, r1)
423 REST_GPR(31, r1)
424 lwz r2,_NIP(r1) /* Restore environment */
425 lwz r0,_MSR(r1)
426 mtspr SRR0,r2
427 mtspr SRR1,r0
428 lwz r0,GPR0(r1)
429 lwz r2,GPR2(r1)
430 lwz r1,GPR1(r1)
431 SYNC
432 rfi
433
434#if defined(CONFIG_COGENT)
435
436/*
437 * This code initialises the MPC8260 processor core
438 * (conforms to PowerPC 603e spec)
439 */
440
441 .globl cogent_init_8260
442cogent_init_8260:
443
444 /* Taken from page 14 of CMA282 manual */
445 /*--------------------------------------------------------------*/
446
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200447 lis r4, (CONFIG_SYS_IMMR+IM_REGBASE)@h
448 lis r3, CONFIG_SYS_IMMR@h
wdenk47d1a6e2002-11-03 00:01:44 +0000449 stw r3, IM_IMMR@l(r4)
450 lwz r3, IM_IMMR@l(r4)
451 stw r3, 0(r0)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200452 lis r3, CONFIG_SYS_SYPCR@h
453 ori r3, r3, CONFIG_SYS_SYPCR@l
wdenk47d1a6e2002-11-03 00:01:44 +0000454 stw r3, IM_SYPCR@l(r4)
455 lwz r3, IM_SYPCR@l(r4)
456 stw r3, 4(r0)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200457 lis r3, CONFIG_SYS_SCCR@h
458 ori r3, r3, CONFIG_SYS_SCCR@l
wdenk47d1a6e2002-11-03 00:01:44 +0000459 stw r3, IM_SCCR@l(r4)
460 lwz r3, IM_SCCR@l(r4)
461 stw r3, 8(r0)
462
463 /* the rest of this was disassembled from the */
464 /* EPROM code that came with my CMA282 CPU module */
465 /*--------------------------------------------------------------*/
466
467 lis r1, 0x1234
468 ori r1, r1, 0x5678
469 stw r1, 0x20(r0)
470 lwz r1, 0x20(r0)
471 stw r1, 0x24(r0)
472 lwz r1, 0x24(r0)
473 lis r3, 0x0e80
474 ori r3, r3, 0
475 stw r1, 4(r3)
476 lwz r1, 4(r3)
477
478 /* Done! */
479 /*--------------------------------------------------------------*/
480
481 blr
482
483#endif /* CONFIG_COGENT */
484
485/*
486 * This code initialises the MPC8260 processor core
487 * (conforms to PowerPC 603e spec)
488 * Note: expects original MSR contents to be in r5.
489 */
490
491 .globl init_8260_core
492init_8260_core:
493
494 /* Initialize machine status; enable machine check interrupt */
495 /*--------------------------------------------------------------*/
496
497 li r3, MSR_KERNEL /* Set ME and RI flags */
498 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
499#ifdef DEBUG
500 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
501#endif
502 SYNC /* Some chip revs need this... */
503 mtmsr r3
504 SYNC
505 mtspr SRR1, r3 /* Make SRR1 match MSR */
506
507 /* Initialise the SYPCR early, and reset the watchdog (if req) */
508 /*--------------------------------------------------------------*/
509
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200510 lis r3, (CONFIG_SYS_IMMR+IM_REGBASE)@h
wdenk47d1a6e2002-11-03 00:01:44 +0000511#if !defined(CONFIG_COGENT)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200512 lis r4, CONFIG_SYS_SYPCR@h
513 ori r4, r4, CONFIG_SYS_SYPCR@l
wdenk47d1a6e2002-11-03 00:01:44 +0000514 stw r4, IM_SYPCR@l(r3)
515#endif /* !CONFIG_COGENT */
516#if defined(CONFIG_WATCHDOG)
517 li r4, 21868 /* = 0x556c */
518 sth r4, IM_SWSR@l(r3)
519 li r4, -21959 /* = 0xaa39 */
520 sth r4, IM_SWSR@l(r3)
521#endif /* CONFIG_WATCHDOG */
522
523 /* Initialize the Hardware Implementation-dependent Registers */
524 /* HID0 also contains cache control */
525 /*--------------------------------------------------------------*/
526
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200527 lis r3, CONFIG_SYS_HID0_INIT@h
528 ori r3, r3, CONFIG_SYS_HID0_INIT@l
wdenk47d1a6e2002-11-03 00:01:44 +0000529 SYNC
530 mtspr HID0, r3
531
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200532 lis r3, CONFIG_SYS_HID0_FINAL@h
533 ori r3, r3, CONFIG_SYS_HID0_FINAL@l
wdenk47d1a6e2002-11-03 00:01:44 +0000534 SYNC
535 mtspr HID0, r3
536
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200537 lis r3, CONFIG_SYS_HID2@h
538 ori r3, r3, CONFIG_SYS_HID2@l
wdenk47d1a6e2002-11-03 00:01:44 +0000539 mtspr HID2, r3
540
541 /* clear all BAT's */
542 /*--------------------------------------------------------------*/
543
544 li r0, 0
545 mtspr DBAT0U, r0
546 mtspr DBAT0L, r0
547 mtspr DBAT1U, r0
548 mtspr DBAT1L, r0
549 mtspr DBAT2U, r0
550 mtspr DBAT2L, r0
551 mtspr DBAT3U, r0
552 mtspr DBAT3L, r0
553 mtspr IBAT0U, r0
554 mtspr IBAT0L, r0
555 mtspr IBAT1U, r0
556 mtspr IBAT1L, r0
557 mtspr IBAT2U, r0
558 mtspr IBAT2L, r0
559 mtspr IBAT3U, r0
560 mtspr IBAT3L, r0
561 SYNC
562
563 /* invalidate all tlb's */
564 /* */
565 /* From the 603e User Manual: "The 603e provides the ability to */
566 /* invalidate a TLB entry. The TLB Invalidate Entry (tlbie) */
567 /* instruction invalidates the TLB entry indexed by the EA, and */
568 /* operates on both the instruction and data TLBs simultaneously*/
569 /* invalidating four TLB entries (both sets in each TLB). The */
570 /* index corresponds to bits 15-19 of the EA. To invalidate all */
571 /* entries within both TLBs, 32 tlbie instructions should be */
572 /* issued, incrementing this field by one each time." */
573 /* */
574 /* "Note that the tlbia instruction is not implemented on the */
575 /* 603e." */
576 /* */
577 /* bits 15-19 correspond to addresses 0x00000000 to 0x0001F000 */
578 /* incrementing by 0x1000 each time. The code below is sort of */
579 /* based on code in "flush_tlbs" from arch/ppc/kernel/head.S */
580 /* */
581 /*--------------------------------------------------------------*/
582
583 li r3, 32
584 mtctr r3
585 li r3, 0
5861: tlbie r3
587 addi r3, r3, 0x1000
588 bdnz 1b
589 SYNC
590
591 /* Done! */
592 /*--------------------------------------------------------------*/
593
594 blr
595
596#ifdef DEBUG
597
598/*
599 * initialise things related to debugging.
600 *
601 * must be called after the global offset table (GOT) is initialised
602 * (GET_GOT) and after cpu_init_f() has executed.
603 */
604
605 .globl init_debug
606init_debug:
607
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200608 lis r3, (CONFIG_SYS_IMMR+IM_REGBASE)@h
wdenk47d1a6e2002-11-03 00:01:44 +0000609
610 /* Quick and dirty hack to enable the RAM and copy the */
611 /* vectors so that we can take exceptions. */
612 /*--------------------------------------------------------------*/
613 /* write Memory Refresh Prescaler */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200614 li r4, CONFIG_SYS_MPTPR
wdenk47d1a6e2002-11-03 00:01:44 +0000615 sth r4, IM_MPTPR@l(r3)
616 /* write 60x Refresh Timer */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200617 li r4, CONFIG_SYS_PSRT
wdenk47d1a6e2002-11-03 00:01:44 +0000618 stb r4, IM_PSRT@l(r3)
619 /* init the 60x SDRAM Mode Register */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200620 lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_NORM)@h
621 ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_NORM)@l
wdenk47d1a6e2002-11-03 00:01:44 +0000622 stw r4, IM_PSDMR@l(r3)
623 /* write Precharge All Banks command */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200624 lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_PREA)@h
625 ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_PREA)@l
wdenk47d1a6e2002-11-03 00:01:44 +0000626 stw r4, IM_PSDMR@l(r3)
627 stb r0, 0(0)
628 /* write eight CBR Refresh commands */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200629 lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_CBRR)@h
630 ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_CBRR)@l
wdenk47d1a6e2002-11-03 00:01:44 +0000631 stw r4, IM_PSDMR@l(r3)
632 stb r0, 0(0)
633 stb r0, 0(0)
634 stb r0, 0(0)
635 stb r0, 0(0)
636 stb r0, 0(0)
637 stb r0, 0(0)
638 stb r0, 0(0)
639 stb r0, 0(0)
640 /* write Mode Register Write command */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200641 lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_MRW)@h
642 ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_MRW)@l
wdenk47d1a6e2002-11-03 00:01:44 +0000643 stw r4, IM_PSDMR@l(r3)
644 stb r0, 0(0)
645 /* write Normal Operation command and enable Refresh */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200646 lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_NORM|PSDMR_RFEN)@h
647 ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_NORM|PSDMR_RFEN)@l
wdenk47d1a6e2002-11-03 00:01:44 +0000648 stw r4, IM_PSDMR@l(r3)
649 stb r0, 0(0)
650 /* RAM should now be operational */
651
652#define VEC_WRD_CNT ((_end_of_vectors - _start + EXC_OFF_SYS_RESET) / 4)
653
654 lwz r3, GOT(_end_of_vectors)
655 rlwinm r4, r3, 0, 18, 31 /* _end_of_vectors & 0x3FFF */
656 lis r5, VEC_WRD_CNT@h
657 ori r5, r5, VEC_WRD_CNT@l
658 mtctr r5
6591:
660 lwzu r5, -4(r3)
661 stwu r5, -4(r4)
662 bdnz 1b
663
664 /* Load the Instruction Address Breakpoint Register (IABR). */
Wolfgang Denk1636d1c2007-06-22 23:59:00 +0200665 /* */
wdenk47d1a6e2002-11-03 00:01:44 +0000666 /* The address to load is stored in the first word of dual port */
667 /* ram and should be preserved while the power is on, so you */
668 /* can plug addresses into that location then reset the cpu and */
669 /* this code will load that address into the IABR after the */
670 /* reset. */
Wolfgang Denk1636d1c2007-06-22 23:59:00 +0200671 /* */
wdenk47d1a6e2002-11-03 00:01:44 +0000672 /* When the program counter matches the contents of the IABR, */
673 /* an exception is generated (before the instruction at that */
674 /* location completes). The vector for this exception is 0x1300 */
675 /*--------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200676 lis r3, CONFIG_SYS_IMMR@h
wdenk47d1a6e2002-11-03 00:01:44 +0000677 lwz r3, 0(r3)
678 mtspr IABR, r3
679
680 /* Set the entire dual port RAM (where the initial stack */
681 /* resides) to a known value - makes it easier to see where */
682 /* the stack has been written */
683 /*--------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200684 lis r3, (CONFIG_SYS_IMMR + CONFIG_SYS_INIT_SP_OFFSET)@h
685 ori r3, r3, (CONFIG_SYS_IMMR + CONFIG_SYS_INIT_SP_OFFSET)@l
686 li r4, ((CONFIG_SYS_INIT_SP_OFFSET - 4) / 4)
wdenk47d1a6e2002-11-03 00:01:44 +0000687 mtctr r4
688 lis r4, 0xdeadbeaf@h
689 ori r4, r4, 0xdeadbeaf@l
6901:
691 stwu r4, -4(r3)
692 bdnz 1b
693
694 /* Done! */
695 /*--------------------------------------------------------------*/
696
697 blr
698#endif
699
700/* Cache functions.
701 *
702 * Note: requires that all cache bits in
703 * HID0 are in the low half word.
704 */
705 .globl icache_enable
706icache_enable:
707 mfspr r3, HID0
708 ori r3, r3, HID0_ICE
709 lis r4, 0
710 ori r4, r4, HID0_ILOCK
711 andc r3, r3, r4
712 ori r4, r3, HID0_ICFI
713 isync
714 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
715 isync
716 mtspr HID0, r3 /* clears invalidate */
717 blr
718
719 .globl icache_disable
720icache_disable:
721 mfspr r3, HID0
722 lis r4, 0
723 ori r4, r4, HID0_ICE|HID0_ILOCK
724 andc r3, r3, r4
725 ori r4, r3, HID0_ICFI
726 isync
727 mtspr HID0, r4 /* sets invalidate, clears enable and lock */
728 isync
729 mtspr HID0, r3 /* clears invalidate */
730 blr
731
732 .globl icache_status
733icache_status:
734 mfspr r3, HID0
735 rlwinm r3, r3, HID0_ICE_BITPOS + 1, 31, 31
736 blr
737
738 .globl dcache_enable
739dcache_enable:
740 mfspr r3, HID0
741 ori r3, r3, HID0_DCE
742 lis r4, 0
743 ori r4, r4, HID0_DLOCK
744 andc r3, r3, r4
745 ori r4, r3, HID0_DCI
746 sync
747 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
748 sync
749 mtspr HID0, r3 /* clears invalidate */
750 blr
751
752 .globl dcache_disable
753dcache_disable:
754 mfspr r3, HID0
755 lis r4, 0
756 ori r4, r4, HID0_DCE|HID0_DLOCK
757 andc r3, r3, r4
758 ori r4, r3, HID0_DCI
759 sync
760 mtspr HID0, r4 /* sets invalidate, clears enable and lock */
761 sync
762 mtspr HID0, r3 /* clears invalidate */
763 blr
764
765 .globl dcache_status
766dcache_status:
767 mfspr r3, HID0
768 rlwinm r3, r3, HID0_DCE_BITPOS + 1, 31, 31
769 blr
770
771 .globl get_pvr
772get_pvr:
773 mfspr r3, PVR
774 blr
775
776/*------------------------------------------------------------------------------*/
777
778/*
779 * void relocate_code (addr_sp, gd, addr_moni)
780 *
781 * This "function" does not return, instead it continues in RAM
782 * after relocating the monitor code.
783 *
784 * r3 = dest
785 * r4 = src
786 * r5 = length in bytes
787 * r6 = cachelinesize
788 */
789 .globl relocate_code
790relocate_code:
791 mr r1, r3 /* Set new stack pointer */
792 mr r9, r4 /* Save copy of Global Data pointer */
793 mr r10, r5 /* Save copy of Destination Address */
794
795 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200796 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
797 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
wdenk3b57fe02003-05-30 12:48:29 +0000798 lwz r5, GOT(__init_end)
799 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200800 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
wdenk47d1a6e2002-11-03 00:01:44 +0000801
802 /*
803 * Fix GOT pointer:
804 *
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200805 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
wdenk47d1a6e2002-11-03 00:01:44 +0000806 *
807 * Offset:
808 */
809 sub r15, r10, r4
810
811 /* First our own GOT */
812 add r14, r14, r15
813 /* then the one used by the C code */
814 add r30, r30, r15
815
816 /*
817 * Now relocate code
818 */
819
820 cmplw cr1,r3,r4
821 addi r0,r5,3
822 srwi. r0,r0,2
823 beq cr1,4f /* In place copy is not necessary */
824 beq 7f /* Protect against 0 count */
825 mtctr r0
826 bge cr1,2f
827
828 la r8,-4(r4)
829 la r7,-4(r3)
8301: lwzu r0,4(r8)
831 stwu r0,4(r7)
832 bdnz 1b
833 b 4f
834
8352: slwi r0,r0,2
836 add r8,r4,r0
837 add r7,r3,r0
8383: lwzu r0,-4(r8)
839 stwu r0,-4(r7)
840 bdnz 3b
841
842/*
843 * Now flush the cache: note that we must start from a cache aligned
844 * address. Otherwise we might miss one cache line.
845 */
8464: cmpwi r6,0
847 add r5,r3,r5
848 beq 7f /* Always flush prefetch queue in any case */
849 subi r0,r6,1
850 andc r3,r3,r0
851 mfspr r7,HID0 /* don't do dcbst if dcache is disabled */
852 rlwinm r7,r7,HID0_DCE_BITPOS+1,31,31
853 cmpwi r7,0
854 beq 9f
855 mr r4,r3
8565: dcbst 0,r4
857 add r4,r4,r6
858 cmplw r4,r5
859 blt 5b
860 sync /* Wait for all dcbst to complete on bus */
8619: mfspr r7,HID0 /* don't do icbi if icache is disabled */
862 rlwinm r7,r7,HID0_ICE_BITPOS+1,31,31
863 cmpwi r7,0
864 beq 7f
865 mr r4,r3
8666: icbi 0,r4
867 add r4,r4,r6
868 cmplw r4,r5
869 blt 6b
8707: sync /* Wait for all icbi to complete on bus */
871 isync
872
873/*
874 * We are done. Do not return, instead branch to second part of board
875 * initialization, now running from RAM.
876 */
877
878 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
879 mtlr r0
880 blr
881
882in_ram:
883
884 /*
885 * Relocation Function, r14 point to got2+0x8000
886 *
wdenk8bde7f72003-06-27 21:31:46 +0000887 * Adjust got2 pointers, no need to check for 0, this code
888 * already puts a few entries in the table.
wdenk47d1a6e2002-11-03 00:01:44 +0000889 */
890 li r0,__got2_entries@sectoff@l
891 la r3,GOT(_GOT2_TABLE_)
892 lwz r11,GOT(_GOT2_TABLE_)
893 mtctr r0
894 sub r11,r3,r11
895 addi r3,r3,-4
8961: lwzu r0,4(r3)
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +0200897 cmpwi r0,0
898 beq- 2f
wdenk47d1a6e2002-11-03 00:01:44 +0000899 add r0,r0,r11
900 stw r0,0(r3)
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +02009012: bdnz 1b
wdenk47d1a6e2002-11-03 00:01:44 +0000902
903 /*
wdenk8bde7f72003-06-27 21:31:46 +0000904 * Now adjust the fixups and the pointers to the fixups
wdenk47d1a6e2002-11-03 00:01:44 +0000905 * in case we need to move ourselves again.
906 */
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +0200907 li r0,__fixup_entries@sectoff@l
wdenk47d1a6e2002-11-03 00:01:44 +0000908 lwz r3,GOT(_FIXUP_TABLE_)
909 cmpwi r0,0
910 mtctr r0
911 addi r3,r3,-4
912 beq 4f
9133: lwzu r4,4(r3)
914 lwzux r0,r4,r11
915 add r0,r0,r11
916 stw r10,0(r3)
917 stw r0,0(r4)
918 bdnz 3b
9194:
920clear_bss:
921 /*
922 * Now clear BSS segment
923 */
wdenk5d232d02003-05-22 22:52:13 +0000924 lwz r3,GOT(__bss_start)
wdenk47d1a6e2002-11-03 00:01:44 +0000925#if defined(CONFIG_HYMOD)
926 /*
927 * For HYMOD - the environment is the very last item in flash.
928 * The real .bss stops just before environment starts, so only
929 * clear up to that point.
930 *
931 * taken from mods for FADS board
932 */
933 lwz r4,GOT(environment)
934#else
935 lwz r4,GOT(_end)
936#endif
937
938 cmplw 0, r3, r4
939 beq 6f
940
941 li r0, 0
9425:
943 stw r0, 0(r3)
944 addi r3, r3, 4
945 cmplw 0, r3, r4
946 bne 5b
9476:
948
949 mr r3, r9 /* Global Data pointer */
950 mr r4, r10 /* Destination Address */
951 bl board_init_r
952
wdenk47d1a6e2002-11-03 00:01:44 +0000953 /*
954 * Copy exception vector code to low memory
955 *
956 * r3: dest_addr
957 * r7: source address, r8: end address, r9: target address
958 */
959 .globl trap_init
960trap_init:
961 lwz r7, GOT(_start)
962 lwz r8, GOT(_end_of_vectors)
963
wdenk682011f2003-06-03 23:54:09 +0000964 li r9, 0x100 /* reset vector always at 0x100 */
wdenk47d1a6e2002-11-03 00:01:44 +0000965
966 cmplw 0, r7, r8
967 bgelr /* return if r7>=r8 - just in case */
968
969 mflr r4 /* save link register */
9701:
971 lwz r0, 0(r7)
972 stw r0, 0(r9)
973 addi r7, r7, 4
974 addi r9, r9, 4
975 cmplw 0, r7, r8
976 bne 1b
977
978 /*
979 * relocate `hdlr' and `int_return' entries
980 */
981 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
982 li r8, Alignment - _start + EXC_OFF_SYS_RESET
9832:
984 bl trap_reloc
985 addi r7, r7, 0x100 /* next exception vector */
986 cmplw 0, r7, r8
987 blt 2b
988
989 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
990 bl trap_reloc
991
992 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
993 bl trap_reloc
994
995 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
996 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
9973:
998 bl trap_reloc
999 addi r7, r7, 0x100 /* next exception vector */
1000 cmplw 0, r7, r8
1001 blt 3b
1002
1003 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
1004 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
10054:
1006 bl trap_reloc
1007 addi r7, r7, 0x100 /* next exception vector */
1008 cmplw 0, r7, r8
1009 blt 4b
1010
1011 mfmsr r3 /* now that the vectors have */
1012 lis r7, MSR_IP@h /* relocated into low memory */
1013 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
1014 andc r3, r3, r7 /* (if it was on) */
1015 SYNC /* Some chip revs need this... */
1016 mtmsr r3
1017 SYNC
1018
1019 mtlr r4 /* restore link register */
1020 blr