blob: 8758e7e847a27112c02dd8fe86225913daad4b7c [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
Thomas Chou39826172015-10-09 20:09:17 +080012/*
13 * icache and dcache configuration used only for start.S.
14 * the values are chosen so that it will work for all configuration.
15 */
16#define ICACHE_LINE_SIZE 32 /* fixed 32 */
17#define ICACHE_SIZE_MAX 0x10000 /* 64k max */
18#define DCACHE_LINE_SIZE_MIN 4 /* 4, 16, 32 */
19#define DCACHE_SIZE_MAX 0x10000 /* 64k max */
20
Thomas Chouf8efd772015-10-06 10:12:59 +080021 /* RESTART */
wdenkef3386f2004-10-10 21:27:30 +000022 .text
Thomas Chou93f96462015-10-06 14:09:19 +080023 .global _start, _except_start, _except_end
wdenkef3386f2004-10-10 21:27:30 +000024
25_start:
Thomas Chouf144ae72010-04-20 11:01:11 +080026 wrctl status, r0 /* Disable interrupts */
Thomas Chouf8efd772015-10-06 10:12:59 +080027 /*
28 * ICACHE INIT -- only the icache line at the reset address
wdenkef3386f2004-10-10 21:27:30 +000029 * is invalidated at reset. So the init must stay within
30 * the cache line size (8 words). If GERMS is used, we'll
31 * just be invalidating the cache a second time. If cache
32 * is not implemented initi behaves as nop.
33 */
Thomas Chou39826172015-10-09 20:09:17 +080034 ori r4, r0, %lo(ICACHE_LINE_SIZE)
35 movhi r5, %hi(ICACHE_SIZE_MAX)
36 ori r5, r5, %lo(ICACHE_SIZE_MAX)
Thomas Chouf144ae72010-04-20 11:01:11 +0800370: initi r5
38 sub r5, r5, r4
39 bgt r5, r0, 0b
wdenk194b8392005-03-30 23:28:18 +000040 br _except_end /* Skip the tramp */
41
Thomas Chouf8efd772015-10-06 10:12:59 +080042 /*
43 * EXCEPTION TRAMPOLINE -- the following gets copied
wdenk194b8392005-03-30 23:28:18 +000044 * to the exception address (below), but is otherwise at the
45 * default exception vector offset (0x0020).
46 */
47_except_start:
48 movhi et, %hi(_exception)
49 ori et, et, %lo(_exception)
50 jmp et
51_except_end:
wdenkef3386f2004-10-10 21:27:30 +000052
Thomas Chouf8efd772015-10-06 10:12:59 +080053 /*
54 * INTERRUPTS -- for now, all interrupts masked and globally
wdenkef3386f2004-10-10 21:27:30 +000055 * disabled.
56 */
wdenkef3386f2004-10-10 21:27:30 +000057 wrctl ienable, r0 /* All disabled */
58
Thomas Chouf8efd772015-10-06 10:12:59 +080059 /*
60 * DCACHE INIT -- if dcache not implemented, initd behaves as
wdenkef3386f2004-10-10 21:27:30 +000061 * nop.
62 */
Thomas Chou39826172015-10-09 20:09:17 +080063 ori r4, r0, %lo(DCACHE_LINE_SIZE_MIN)
64 movhi r5, %hi(DCACHE_SIZE_MAX)
65 ori r5, r5, %lo(DCACHE_SIZE_MAX)
wdenkef3386f2004-10-10 21:27:30 +000066 mov r6, r0
671: initd 0(r6)
68 add r6, r6, r4
69 bltu r6, r5, 1b
70
Thomas Chouf8efd772015-10-06 10:12:59 +080071 /*
72 * RELOCATE CODE, DATA & COMMAND TABLE -- the following code
wdenkef3386f2004-10-10 21:27:30 +000073 * assumes code, data and the command table are all
74 * contiguous. This lets us relocate everything as a single
75 * block. Make sure the linker script matches this ;-)
76 */
77 nextpc r4
78_cur: movhi r5, %hi(_cur - _start)
79 ori r5, r5, %lo(_cur - _start)
80 sub r4, r4, r5 /* r4 <- cur _start */
81 mov r8, r4
82 movhi r5, %hi(_start)
83 ori r5, r5, %lo(_start) /* r5 <- linked _start */
84 beq r4, r5, 3f
85
Thomas Chouf2bec0e2015-09-04 16:39:16 +080086 movhi r6, %hi(CONFIG_SYS_MONITOR_LEN)
87 ori r6, r6, %lo(CONFIG_SYS_MONITOR_LEN)
88 add r6, r6, r5
wdenkef3386f2004-10-10 21:27:30 +0000892: ldwio r7, 0(r4)
90 addi r4, r4, 4
91 stwio r7, 0(r5)
92 addi r5, r5, 4
93 bne r5, r6, 2b
943:
95
wdenkef3386f2004-10-10 21:27:30 +000096 /* JUMP TO RELOC ADDR */
97 movhi r4, %hi(_reloc)
98 ori r4, r4, %lo(_reloc)
99 jmp r4
100_reloc:
101
Thomas Chouf8efd772015-10-06 10:12:59 +0800102 /* STACK INIT -- zero top two words for call back chain. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200103 movhi sp, %hi(CONFIG_SYS_INIT_SP)
104 ori sp, sp, %lo(CONFIG_SYS_INIT_SP)
wdenkef3386f2004-10-10 21:27:30 +0000105 addi sp, sp, -8
106 stw r0, 0(sp)
107 stw r0, 4(sp)
108 mov fp, sp
109
Thomas Chouc3c6ab12015-09-09 15:09:43 +0800110 /* Allocate and zero GD, update SP */
111 mov r4, sp
112 movhi r2, %hi(board_init_f_mem@h)
113 ori r2, r2, %lo(board_init_f_mem@h)
114 callr r2
115
116 /* Update stack- and frame-pointers */
117 mov sp, r2
118 mov fp, sp
119
Thomas Chouf8efd772015-10-06 10:12:59 +0800120 /* Call board_init_f -- never returns */
Thomas Choucce3e752014-08-22 11:36:47 +0800121 mov r4, r0
122 movhi r2, %hi(board_init_f@h)
123 ori r2, r2, %lo(board_init_f@h)
124 callr r2
wdenkef3386f2004-10-10 21:27:30 +0000125
Thomas Chouf8efd772015-10-06 10:12:59 +0800126 /*
127 * NEVER RETURNS -- but branch to the _start just
wdenkef3386f2004-10-10 21:27:30 +0000128 * in case ;-)
129 */
130 br _start
131
Thomas Chouf8efd772015-10-06 10:12:59 +0800132 /*
133 * relocate_code -- Nios2 handles the relocation above. But
134 * the generic board code monkeys with the heap, stack, etc.
135 * (it makes some assumptions that may not be appropriate
136 * for Nios). Nevertheless, we capitulate here.
137 *
138 * We'll call the board_init_r from here since this isn't
139 * supposed to return.
140 *
141 * void relocate_code (ulong sp, gd_t *global_data,
142 * ulong reloc_addr)
143 * __attribute__ ((noreturn));
144 */
Thomas Choucce3e752014-08-22 11:36:47 +0800145 .text
146 .global relocate_code
147
148relocate_code:
149 mov sp, r4 /* Set the new sp */
150 mov r4, r5
Thomas Choufb731f22015-09-07 08:57:14 +0800151
152 /*
153 * ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
154 * and between __bss_start and __bss_end.
155 */
156 movhi r5, %hi(__bss_start)
157 ori r5, r5, %lo(__bss_start)
158 movhi r6, %hi(__bss_end)
159 ori r6, r6, %lo(__bss_end)
160 beq r5, r6, 5f
161
1624: stwio r0, 0(r5)
163 addi r5, r5, 4
164 bne r5, r6, 4b
1655:
166
Thomas Choucce3e752014-08-22 11:36:47 +0800167 movhi r8, %hi(board_init_r@h)
168 ori r8, r8, %lo(board_init_r@h)
169 callr r8
170 ret