blob: f80b4f3a52d65936d19bd5d37143574872a9e383 [file] [log] [blame]
wdenkef3386f2004-10-10 21:27:30 +00001/*
2 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkef3386f2004-10-10 21:27:30 +00006 */
7
Wolfgang Denk0191e472010-10-26 14:34:52 +02008#include <asm-offsets.h>
wdenkef3386f2004-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 Chouf144ae72010-04-20 11:01:11 +080020 wrctl status, r0 /* Disable interrupts */
wdenkef3386f2004-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-VILLARD03836942008-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 Chouf144ae72010-04-20 11:01:11 +0800300: initi r5
31 sub r5, r5, r4
32 bgt r5, r0, 0b
wdenk194b8392005-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:
wdenkef3386f2004-10-10 21:27:30 +000044
45 /* INTERRUPTS -- for now, all interrupts masked and globally
46 * disabled.
47 */
wdenkef3386f2004-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-VILLARD03836942008-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)
wdenkef3386f2004-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
Thomas Chouf2bec0e2015-09-04 16:39:16 +080076 movhi r6, %hi(CONFIG_SYS_MONITOR_LEN)
77 ori r6, r6, %lo(CONFIG_SYS_MONITOR_LEN)
78 add r6, r6, r5
wdenkef3386f2004-10-10 21:27:30 +0000792: ldwio r7, 0(r4)
80 addi r4, r4, 4
81 stwio r7, 0(r5)
82 addi r5, r5, 4
83 bne r5, r6, 2b
843:
85
wdenkef3386f2004-10-10 21:27:30 +000086 /* JUMP TO RELOC ADDR */
87 movhi r4, %hi(_reloc)
88 ori r4, r4, %lo(_reloc)
89 jmp r4
90_reloc:
91
92 /* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
wdenk194b8392005-03-30 23:28:18 +000093 * exception address. Define CONFIG_ROM_STUBS to prevent
94 * the copy (e.g. exception in flash or in other
95 * softare/firmware component).
wdenkef3386f2004-10-10 21:27:30 +000096 */
97#if !defined(CONFIG_ROM_STUBS)
98 movhi r4, %hi(_except_start)
99 ori r4, r4, %lo(_except_start)
100 movhi r5, %hi(_except_end)
101 ori r5, r5, %lo(_except_end)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200102 movhi r6, %hi(CONFIG_SYS_EXCEPTION_ADDR)
103 ori r6, r6, %lo(CONFIG_SYS_EXCEPTION_ADDR)
wdenk194b8392005-03-30 23:28:18 +0000104 beq r4, r6, 7f /* Skip if at proper addr */
wdenkef3386f2004-10-10 21:27:30 +0000105
1066: ldwio r7, 0(r4)
107 stwio r7, 0(r6)
108 addi r4, r4, 4
109 addi r6, r6, 4
110 bne r4, r5, 6b
wdenk194b8392005-03-30 23:28:18 +00001117:
wdenkef3386f2004-10-10 21:27:30 +0000112#endif
113
114 /* STACK INIT -- zero top two words for call back chain.
115 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200116 movhi sp, %hi(CONFIG_SYS_INIT_SP)
117 ori sp, sp, %lo(CONFIG_SYS_INIT_SP)
wdenkef3386f2004-10-10 21:27:30 +0000118 addi sp, sp, -8
119 stw r0, 0(sp)
120 stw r0, 4(sp)
121 mov fp, sp
122
123 /*
Thomas Choucce3e752014-08-22 11:36:47 +0800124 * Call board_init_f -- never returns
wdenkef3386f2004-10-10 21:27:30 +0000125 */
Thomas Choucce3e752014-08-22 11:36:47 +0800126 mov r4, r0
127 movhi r2, %hi(board_init_f@h)
128 ori r2, r2, %lo(board_init_f@h)
129 callr r2
wdenkef3386f2004-10-10 21:27:30 +0000130
131 /* NEVER RETURNS -- but branch to the _start just
132 * in case ;-)
133 */
134 br _start
135
wdenkef3386f2004-10-10 21:27:30 +0000136
Thomas Choucce3e752014-08-22 11:36:47 +0800137
138/*
139 * relocate_code -- Nios2 handles the relocation above. But
140 * the generic board code monkeys with the heap, stack, etc.
141 * (it makes some assumptions that may not be appropriate
142 * for Nios). Nevertheless, we capitulate here.
143 *
144 * We'll call the board_init_r from here since this isn't
145 * supposed to return.
146 *
147 * void relocate_code (ulong sp, gd_t *global_data,
148 * ulong reloc_addr)
149 * __attribute__ ((noreturn));
150 */
151 .text
152 .global relocate_code
153
154relocate_code:
155 mov sp, r4 /* Set the new sp */
156 mov r4, r5
Thomas Choufb731f22015-09-07 08:57:14 +0800157
158 /*
159 * ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
160 * and between __bss_start and __bss_end.
161 */
162 movhi r5, %hi(__bss_start)
163 ori r5, r5, %lo(__bss_start)
164 movhi r6, %hi(__bss_end)
165 ori r6, r6, %lo(__bss_end)
166 beq r5, r6, 5f
167
1684: stwio r0, 0(r5)
169 addi r5, r5, 4
170 bne r5, r6, 4b
1715:
172
Thomas Choucce3e752014-08-22 11:36:47 +0800173 movhi r8, %hi(board_init_r@h)
174 ori r8, r8, %lo(board_init_r@h)
175 callr r8
176 ret
177
wdenkef3386f2004-10-10 21:27:30 +0000178/*
179 * dly_clks -- Nios2 (like Nios1) doesn't have a timebase in
180 * the core. For simple delay loops, we do our best by counting
181 * instruction cycles.
182 *
183 * Instruction performance varies based on the core. For cores
184 * with icache and static/dynamic branch prediction (II/f, II/s):
185 *
Wolfgang Denka1be4762008-05-20 16:00:29 +0200186 * Normal ALU (e.g. add, cmp, etc): 1 cycle
187 * Branch (correctly predicted, taken): 2 cycles
wdenkef3386f2004-10-10 21:27:30 +0000188 * Negative offset is predicted (II/s).
189 *
190 * For cores without icache and no branch prediction (II/e):
191 *
Wolfgang Denka1be4762008-05-20 16:00:29 +0200192 * Normal ALU (e.g. add, cmp, etc): 6 cycles
193 * Branch (no prediction): 6 cycles
wdenkef3386f2004-10-10 21:27:30 +0000194 *
195 * For simplicity, if an instruction cache is implemented we
196 * assume II/f or II/s. Otherwise, we use the II/e.
197 *
198 */
Wolfgang Denka1be4762008-05-20 16:00:29 +0200199 .globl dly_clks
wdenkef3386f2004-10-10 21:27:30 +0000200
201dly_clks:
202
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200203#if (CONFIG_SYS_ICACHE_SIZE > 0)
wdenkef3386f2004-10-10 21:27:30 +0000204 subi r4, r4, 3 /* 3 clocks/loop */
205#else
206 subi r4, r4, 12 /* 12 clocks/loop */
207#endif
208 bge r4, r0, dly_clks
209 ret
210
wdenkef3386f2004-10-10 21:27:30 +0000211 .data
212 .globl version_string
213
214version_string:
Andreas Bießmann61d01952011-07-18 20:24:04 +0200215 .ascii U_BOOT_VERSION_STRING, "\0"