blob: 7ce0d34d7fadd61b2705eba5e3f0cfdd30fed5b5 [file] [log] [blame]
wdenk5c952cf2004-10-10 21:27:30 +00001/*
2 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk5c952cf2004-10-10 21:27:30 +00006 */
7
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +02008#include <asm-offsets.h>
wdenk5c952cf2004-10-10 21:27:30 +00009#include <config.h>
10#include <version.h>
11
12/*************************************************************************
13 * RESTART
14 ************************************************************************/
15
16 .text
17 .global _start
18
19_start:
Thomas Choufd2712d2010-04-20 11:01:11 +080020 wrctl status, r0 /* Disable interrupts */
wdenk5c952cf2004-10-10 21:27:30 +000021 /* ICACHE INIT -- only the icache line at the reset address
22 * is invalidated at reset. So the init must stay within
23 * the cache line size (8 words). If GERMS is used, we'll
24 * just be invalidating the cache a second time. If cache
25 * is not implemented initi behaves as nop.
26 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020027 ori r4, r0, %lo(CONFIG_SYS_ICACHELINE_SIZE)
28 movhi r5, %hi(CONFIG_SYS_ICACHE_SIZE)
29 ori r5, r5, %lo(CONFIG_SYS_ICACHE_SIZE)
Thomas Choufd2712d2010-04-20 11:01:11 +0800300: initi r5
31 sub r5, r5, r4
32 bgt r5, r0, 0b
wdenk0c1c117c2005-03-30 23:28:18 +000033 br _except_end /* Skip the tramp */
34
35 /* EXCEPTION TRAMPOLINE -- the following gets copied
36 * to the exception address (below), but is otherwise at the
37 * default exception vector offset (0x0020).
38 */
39_except_start:
40 movhi et, %hi(_exception)
41 ori et, et, %lo(_exception)
42 jmp et
43_except_end:
wdenk5c952cf2004-10-10 21:27:30 +000044
45 /* INTERRUPTS -- for now, all interrupts masked and globally
46 * disabled.
47 */
wdenk5c952cf2004-10-10 21:27:30 +000048 wrctl ienable, r0 /* All disabled */
49
50 /* DCACHE INIT -- if dcache not implemented, initd behaves as
51 * nop.
52 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020053 movhi r4, %hi(CONFIG_SYS_DCACHELINE_SIZE)
54 ori r4, r4, %lo(CONFIG_SYS_DCACHELINE_SIZE)
55 movhi r5, %hi(CONFIG_SYS_DCACHE_SIZE)
56 ori r5, r5, %lo(CONFIG_SYS_DCACHE_SIZE)
wdenk5c952cf2004-10-10 21:27:30 +000057 mov r6, r0
581: initd 0(r6)
59 add r6, r6, r4
60 bltu r6, r5, 1b
61
62 /* RELOCATE CODE, DATA & COMMAND TABLE -- the following code
63 * assumes code, data and the command table are all
64 * contiguous. This lets us relocate everything as a single
65 * block. Make sure the linker script matches this ;-)
66 */
67 nextpc r4
68_cur: movhi r5, %hi(_cur - _start)
69 ori r5, r5, %lo(_cur - _start)
70 sub r4, r4, r5 /* r4 <- cur _start */
71 mov r8, r4
72 movhi r5, %hi(_start)
73 ori r5, r5, %lo(_start) /* r5 <- linked _start */
74 beq r4, r5, 3f
75
76 movhi r6, %hi(_edata)
77 ori r6, r6, %lo(_edata)
782: ldwio r7, 0(r4)
79 addi r4, r4, 4
80 stwio r7, 0(r5)
81 addi r5, r5, 4
82 bne r5, r6, 2b
833:
84
85 /* ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
Simon Glass3929fb02013-03-14 06:54:53 +000086 * and between __bss_start and __bss_end.
wdenk5c952cf2004-10-10 21:27:30 +000087 */
88 movhi r5, %hi(__bss_start)
89 ori r5, r5, %lo(__bss_start)
Simon Glass3929fb02013-03-14 06:54:53 +000090 movhi r6, %hi(__bss_end)
91 ori r6, r6, %lo(__bss_end)
wdenk5c952cf2004-10-10 21:27:30 +000092 beq r5, r6, 5f
93
944: stwio r0, 0(r5)
95 addi r5, r5, 4
96 bne r5, r6, 4b
975:
98
wdenk5c952cf2004-10-10 21:27:30 +000099 /* JUMP TO RELOC ADDR */
100 movhi r4, %hi(_reloc)
101 ori r4, r4, %lo(_reloc)
102 jmp r4
103_reloc:
104
105 /* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
wdenk0c1c117c2005-03-30 23:28:18 +0000106 * exception address. Define CONFIG_ROM_STUBS to prevent
107 * the copy (e.g. exception in flash or in other
108 * softare/firmware component).
wdenk5c952cf2004-10-10 21:27:30 +0000109 */
110#if !defined(CONFIG_ROM_STUBS)
111 movhi r4, %hi(_except_start)
112 ori r4, r4, %lo(_except_start)
113 movhi r5, %hi(_except_end)
114 ori r5, r5, %lo(_except_end)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200115 movhi r6, %hi(CONFIG_SYS_EXCEPTION_ADDR)
116 ori r6, r6, %lo(CONFIG_SYS_EXCEPTION_ADDR)
wdenk0c1c117c2005-03-30 23:28:18 +0000117 beq r4, r6, 7f /* Skip if at proper addr */
wdenk5c952cf2004-10-10 21:27:30 +0000118
1196: ldwio r7, 0(r4)
120 stwio r7, 0(r6)
121 addi r4, r4, 4
122 addi r6, r6, 4
123 bne r4, r5, 6b
wdenk0c1c117c2005-03-30 23:28:18 +00001247:
wdenk5c952cf2004-10-10 21:27:30 +0000125#endif
126
127 /* STACK INIT -- zero top two words for call back chain.
128 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200129 movhi sp, %hi(CONFIG_SYS_INIT_SP)
130 ori sp, sp, %lo(CONFIG_SYS_INIT_SP)
wdenk5c952cf2004-10-10 21:27:30 +0000131 addi sp, sp, -8
132 stw r0, 0(sp)
133 stw r0, 4(sp)
134 mov fp, sp
135
136 /*
137 * Call board_init -- never returns
138 */
139 movhi r4, %hi(board_init@h)
140 ori r4, r4, %lo(board_init@h)
141 callr r4
142
143 /* NEVER RETURNS -- but branch to the _start just
144 * in case ;-)
145 */
146 br _start
147
wdenk5c952cf2004-10-10 21:27:30 +0000148
149/*
150 * dly_clks -- Nios2 (like Nios1) doesn't have a timebase in
151 * the core. For simple delay loops, we do our best by counting
152 * instruction cycles.
153 *
154 * Instruction performance varies based on the core. For cores
155 * with icache and static/dynamic branch prediction (II/f, II/s):
156 *
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200157 * Normal ALU (e.g. add, cmp, etc): 1 cycle
158 * Branch (correctly predicted, taken): 2 cycles
wdenk5c952cf2004-10-10 21:27:30 +0000159 * Negative offset is predicted (II/s).
160 *
161 * For cores without icache and no branch prediction (II/e):
162 *
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200163 * Normal ALU (e.g. add, cmp, etc): 6 cycles
164 * Branch (no prediction): 6 cycles
wdenk5c952cf2004-10-10 21:27:30 +0000165 *
166 * For simplicity, if an instruction cache is implemented we
167 * assume II/f or II/s. Otherwise, we use the II/e.
168 *
169 */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200170 .globl dly_clks
wdenk5c952cf2004-10-10 21:27:30 +0000171
172dly_clks:
173
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200174#if (CONFIG_SYS_ICACHE_SIZE > 0)
wdenk5c952cf2004-10-10 21:27:30 +0000175 subi r4, r4, 3 /* 3 clocks/loop */
176#else
177 subi r4, r4, 12 /* 12 clocks/loop */
178#endif
179 bge r4, r0, dly_clks
180 ret
181
wdenk5c952cf2004-10-10 21:27:30 +0000182 .data
183 .globl version_string
184
185version_string:
Andreas Bießmann09c2e902011-07-18 20:24:04 +0200186 .ascii U_BOOT_VERSION_STRING, "\0"