blob: acb8ca686ed977911bc5dbafad404e8f14f21983 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
wdenk5c952cf2004-10-10 21:27:30 +00002/*
3 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
4 * Scott McNutt <smcnutt@psyent.com>
wdenk5c952cf2004-10-10 21:27:30 +00005 */
6
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +02007#include <asm-offsets.h>
wdenk5c952cf2004-10-10 21:27:30 +00008#include <config.h>
wdenk5c952cf2004-10-10 21:27:30 +00009
Thomas Chou55e2b4d2015-10-09 20:09:17 +080010/*
11 * icache and dcache configuration used only for start.S.
12 * the values are chosen so that it will work for all configuration.
13 */
14#define ICACHE_LINE_SIZE 32 /* fixed 32 */
15#define ICACHE_SIZE_MAX 0x10000 /* 64k max */
16#define DCACHE_LINE_SIZE_MIN 4 /* 4, 16, 32 */
17#define DCACHE_SIZE_MAX 0x10000 /* 64k max */
18
Thomas Chou4a572fa2015-10-06 10:12:59 +080019 /* RESTART */
wdenk5c952cf2004-10-10 21:27:30 +000020 .text
Thomas Choub8112092015-10-06 14:09:19 +080021 .global _start, _except_start, _except_end
wdenk5c952cf2004-10-10 21:27:30 +000022
23_start:
Thomas Choufd2712d2010-04-20 11:01:11 +080024 wrctl status, r0 /* Disable interrupts */
Thomas Chou4a572fa2015-10-06 10:12:59 +080025 /*
26 * ICACHE INIT -- only the icache line at the reset address
wdenk5c952cf2004-10-10 21:27:30 +000027 * is invalidated at reset. So the init must stay within
28 * the cache line size (8 words). If GERMS is used, we'll
29 * just be invalidating the cache a second time. If cache
30 * is not implemented initi behaves as nop.
31 */
Thomas Chou55e2b4d2015-10-09 20:09:17 +080032 ori r4, r0, %lo(ICACHE_LINE_SIZE)
33 movhi r5, %hi(ICACHE_SIZE_MAX)
34 ori r5, r5, %lo(ICACHE_SIZE_MAX)
Thomas Choufd2712d2010-04-20 11:01:11 +0800350: initi r5
36 sub r5, r5, r4
37 bgt r5, r0, 0b
wdenk0c1c117c2005-03-30 23:28:18 +000038 br _except_end /* Skip the tramp */
39
Thomas Chou4a572fa2015-10-06 10:12:59 +080040 /*
41 * EXCEPTION TRAMPOLINE -- the following gets copied
wdenk0c1c117c2005-03-30 23:28:18 +000042 * to the exception address (below), but is otherwise at the
43 * default exception vector offset (0x0020).
44 */
45_except_start:
46 movhi et, %hi(_exception)
47 ori et, et, %lo(_exception)
48 jmp et
49_except_end:
wdenk5c952cf2004-10-10 21:27:30 +000050
Thomas Chou4a572fa2015-10-06 10:12:59 +080051 /*
52 * INTERRUPTS -- for now, all interrupts masked and globally
wdenk5c952cf2004-10-10 21:27:30 +000053 * disabled.
54 */
wdenk5c952cf2004-10-10 21:27:30 +000055 wrctl ienable, r0 /* All disabled */
56
Thomas Chou4a572fa2015-10-06 10:12:59 +080057 /*
58 * DCACHE INIT -- if dcache not implemented, initd behaves as
wdenk5c952cf2004-10-10 21:27:30 +000059 * nop.
60 */
Thomas Chou55e2b4d2015-10-09 20:09:17 +080061 ori r4, r0, %lo(DCACHE_LINE_SIZE_MIN)
62 movhi r5, %hi(DCACHE_SIZE_MAX)
63 ori r5, r5, %lo(DCACHE_SIZE_MAX)
wdenk5c952cf2004-10-10 21:27:30 +000064 mov r6, r0
651: initd 0(r6)
66 add r6, r6, r4
67 bltu r6, r5, 1b
68
Thomas Chou4a572fa2015-10-06 10:12:59 +080069 /*
70 * RELOCATE CODE, DATA & COMMAND TABLE -- the following code
wdenk5c952cf2004-10-10 21:27:30 +000071 * assumes code, data and the command table are all
72 * contiguous. This lets us relocate everything as a single
73 * block. Make sure the linker script matches this ;-)
74 */
75 nextpc r4
76_cur: movhi r5, %hi(_cur - _start)
77 ori r5, r5, %lo(_cur - _start)
78 sub r4, r4, r5 /* r4 <- cur _start */
79 mov r8, r4
80 movhi r5, %hi(_start)
81 ori r5, r5, %lo(_start) /* r5 <- linked _start */
Thomas Chou65af9f62015-11-03 13:47:02 +080082 mov sp, r5 /* initial stack below u-boot code */
wdenk5c952cf2004-10-10 21:27:30 +000083 beq r4, r5, 3f
84
Thomas Choue9002982015-09-04 16:39:16 +080085 movhi r6, %hi(CONFIG_SYS_MONITOR_LEN)
86 ori r6, r6, %lo(CONFIG_SYS_MONITOR_LEN)
87 add r6, r6, r5
wdenk5c952cf2004-10-10 21:27:30 +0000882: ldwio r7, 0(r4)
89 addi r4, r4, 4
90 stwio r7, 0(r5)
91 addi r5, r5, 4
92 bne r5, r6, 2b
933:
94
wdenk5c952cf2004-10-10 21:27:30 +000095 /* JUMP TO RELOC ADDR */
96 movhi r4, %hi(_reloc)
97 ori r4, r4, %lo(_reloc)
98 jmp r4
99_reloc:
100
Thomas Chou4a572fa2015-10-06 10:12:59 +0800101 /* STACK INIT -- zero top two words for call back chain. */
wdenk5c952cf2004-10-10 21:27:30 +0000102 addi sp, sp, -8
103 stw r0, 0(sp)
104 stw r0, 4(sp)
105 mov fp, sp
106
Thomas Choue4f348b2015-12-30 20:29:18 +0800107#ifdef CONFIG_DEBUG_UART
108 /* Set up the debug UART */
109 movhi r2, %hi(debug_uart_init@h)
110 ori r2, r2, %lo(debug_uart_init@h)
111 callr r2
112#endif
113
Albert ARIBAUDecc30662015-11-25 17:56:32 +0100114 /* Allocate and initialize reserved area, update SP */
Thomas Chou3e468e62015-09-09 15:09:43 +0800115 mov r4, sp
Albert ARIBAUDecc30662015-11-25 17:56:32 +0100116 movhi r2, %hi(board_init_f_alloc_reserve@h)
117 ori r2, r2, %lo(board_init_f_alloc_reserve@h)
118 callr r2
119 mov sp, r2
120 mov r4, sp
121 movhi r2, %hi(board_init_f_init_reserve@h)
122 ori r2, r2, %lo(board_init_f_init_reserve@h)
Thomas Chou3e468e62015-09-09 15:09:43 +0800123 callr r2
124
Albert ARIBAUDecc30662015-11-25 17:56:32 +0100125 /* Update frame-pointer */
Thomas Chou3e468e62015-09-09 15:09:43 +0800126 mov fp, sp
127
Thomas Chou4a572fa2015-10-06 10:12:59 +0800128 /* Call board_init_f -- never returns */
Thomas Chou5ff10aa2014-08-22 11:36:47 +0800129 mov r4, r0
130 movhi r2, %hi(board_init_f@h)
131 ori r2, r2, %lo(board_init_f@h)
132 callr r2
wdenk5c952cf2004-10-10 21:27:30 +0000133
Thomas Chou4a572fa2015-10-06 10:12:59 +0800134 /*
135 * NEVER RETURNS -- but branch to the _start just
wdenk5c952cf2004-10-10 21:27:30 +0000136 * in case ;-)
137 */
138 br _start
139
Thomas Chou4a572fa2015-10-06 10:12:59 +0800140 /*
141 * relocate_code -- Nios2 handles the relocation above. But
142 * the generic board code monkeys with the heap, stack, etc.
143 * (it makes some assumptions that may not be appropriate
144 * for Nios). Nevertheless, we capitulate here.
145 *
146 * We'll call the board_init_r from here since this isn't
147 * supposed to return.
148 *
Simon Glass94133872019-12-28 10:44:45 -0700149 * void relocate_code(ulong sp, gd_t *global_data,
Thomas Chou4a572fa2015-10-06 10:12:59 +0800150 * ulong reloc_addr)
151 * __attribute__ ((noreturn));
152 */
Thomas Chou5ff10aa2014-08-22 11:36:47 +0800153 .text
154 .global relocate_code
155
156relocate_code:
157 mov sp, r4 /* Set the new sp */
158 mov r4, r5
Thomas Chou4192b8c2015-09-07 08:57:14 +0800159
160 /*
161 * ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
162 * and between __bss_start and __bss_end.
163 */
164 movhi r5, %hi(__bss_start)
165 ori r5, r5, %lo(__bss_start)
166 movhi r6, %hi(__bss_end)
167 ori r6, r6, %lo(__bss_end)
168 beq r5, r6, 5f
169
Thomas Chou9208d7e2015-11-03 13:52:15 +08001704: stw r0, 0(r5)
Thomas Chou4192b8c2015-09-07 08:57:14 +0800171 addi r5, r5, 4
172 bne r5, r6, 4b
1735:
174
Thomas Chou5ff10aa2014-08-22 11:36:47 +0800175 movhi r8, %hi(board_init_r@h)
176 ori r8, r8, %lo(board_init_r@h)
177 callr r8
178 ret