summaryrefslogtreecommitdiff
path: root/arch/nios/cpu/start.S
blob: 3578a04d51e88d01b4d059edb2a63bd12a878b2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
 * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
 * Scott McNutt <smcnutt@psyent.com>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */


#include <config.h>
#include <timestamp.h>
#include <version.h>

#if !defined(CONFIG_IDENT_STRING)
#define CONFIG_IDENT_STRING ""
#endif

#define STATUS_INIT	0x8600		/* IE=1, IPRI=2 */

/*************************************************************************
 * RESTART
 ************************************************************************/

	.text
	.global _start

_start:
	bsr	0f
	nop
	.long	_start

	/* GERMS -- The "standard-32" configuration GERMS monitor looks
	 * for the string "Nios" at flash_base + 0xc (actually it only
	 * tests for 'N', 'i'). You can leave support for this in place
	 * as it's only a few words.
	 */
	. = _start + 0x000c
	.string "Nios"

	.align 4
0:
	/*
	 * Early setup -- set cwp = HI_LIMIT, IPRI = 2, IE = 1 to
	 * enable underflow exceptions. Disable cache.
	 * NOTE: %o7 has return addr -- save in %g7 use later.
	 */
	mov	%g7, %o7

	pfx	2			/* WVALID */
	rdctl	%g0
	lsri	%g0, 1
	pfx	%hi(STATUS_INIT)
	or	%g0, %lo(STATUS_INIT)
	wrctl	%g0			/* update status */
	nop

	/*
	 * STACK
	 */
	pfx	%hi(CONFIG_SYS_INIT_SP)
	movi	%sp, %lo(CONFIG_SYS_INIT_SP)
	pfx	%xhi(CONFIG_SYS_INIT_SP)
	movhi	%sp, %xlo(CONFIG_SYS_INIT_SP)
	mov	%fp, %sp

	pfx	%hi(4*16)
	subi	%sp, %lo(4*16)		/* Space for reg window mgmt */

	/*
	 * RELOCATE -- %g7 has return addr from bsr at _start.
	 */
	pfx	%hi(__u_boot_cmd_end)
	movi	%g5, %lo(__u_boot_cmd_end)
	pfx	%xhi(__u_boot_cmd_end)
	movhi	%g5, %xlo(__u_boot_cmd_end) /* %g5 <- end address */

	lsli	%g7, 1			/* mem = retaddr << 1 */
	mov	%g6, %g7
	subi	%g6, 4			/* %g6 <- src addr */
	ld	%g7, [%g7]		/* %g7 <- dst addr */

	/* No need to move text sections if we're already located
	 * at the proper address.
	 */
	cmp	%g7, %g6
	ifs	cc_z
	br	reloc
	nop				/* delay slot */

1:	cmp	%g7, %g5
	skps	cc_nz
	br	2f
	nop				/* delay slot */

	ld	%g0, [%g6]
	addi	%g6, 4			/* src++ */
	st	[%g7], %g0
	addi	%g7, 4			/* dst++ */
	br	1b
	nop				/* delay slot */
2:

	/*
	 * Jump to relocation address
	 */
	 pfx	%hi(reloc@h)
	 movi	%g0, %lo(reloc@h)
	 pfx	%xhi(reloc@h)
	 movhi	%g0, %xlo(reloc@h)
	 jmp	%g0
	 nop				/* delay slot */
reloc:

	/*
	 * CLEAR BSS
	 */
	pfx	%hi(__bss_end)
	movi	%g5, %lo(__bss_end)
	pfx	%xhi(__bss_end)
	movhi	%g5, %xlo(__bss_end)	/* %g5 <- end address */
	pfx	%hi(__bss_start)
	movi	%g7, %lo(__bss_start)
	pfx	%xhi(__bss_start)
	movhi	%g7, %xlo(__bss_start)	/* %g7 <- end address */

	movi	%g0, 0
3:	cmp	%g7, %g5
	skps	cc_nz
	br	4f
	nop				/* delay slot */

	st	[%g7], %g0
	addi	%g7, 4			/* (delay slot) dst++ */
	br	3b
	nop				/* delay slot */
4:

	/*
	 * INIT VECTOR TABLE
	 */
	pfx	%hi(CONFIG_SYS_VECT_BASE)
	movi	%g0, %lo(CONFIG_SYS_VECT_BASE)
	pfx	%xhi(CONFIG_SYS_VECT_BASE)
	movhi	%g0, %xlo(CONFIG_SYS_VECT_BASE)	/* dst */
	mov	%l0, %g0

	pfx	%hi(_vectors)
	movi	%g1, %lo(_vectors)
	pfx	%xhi(_vectors)
	movhi	%g1, %xlo(_vectors)	/* src */
	bgen	%g2, 6			/* cnt = 64 */

	ldp	%g3, [%l0, 3]		/* bkpt vector */
	ldp	%g4, [%l0, 4]		/* single step vector */

5:	ld	%g7, [%g1]
	addi	%g1, 4			/* src++ */
	st	[%g0], %g7
	addi	%g0, 4			/* dst++ */

	subi	%g2, 1			/* cnt-- */
	ifrnz	%g2
	br	5b
	nop				/* delay slot */

#if defined(CONFIG_ROM_STUBS)
	/* Restore the breakpoint and single step exception
	 * vectors to their original values.
	 */
	stp	[%l0,3], %g3		/* breakpoint */
	stp	[%l0,4], %g4		/* single step */
#endif

	/* For debug startup convenience ... software breakpoints
	 * set prior to this point may not succeed ;-)
	 */
	.global __start
__start:

	/*
	 * Call board_init -- never returns
	 */
	pfx	%hi(board_init@h)
	movi	%g1, %lo(board_init@h)
	pfx	%xhi(board_init@h)
	movhi	%g1, %xlo(board_init@h)
	call	%g1
	nop				/* Delaly slot */
	/* NEVER RETURNS */

/*
 * dly_clks -- Nios doesn't have a time/clk reference for simple
 * delay loops, so we do our best by counting instruction cycles.
 * A control register that counts system clock cycles would be
 * a handy feature -- hint for Altera ;-)
 */
	.globl dly_clks
	/* Each loop is 4 instructions as delay slot is always
	 * executed. Each instruction is approximately 4 clocks
	 * (according to some lame info from Altera). So ...
	 * ... each loop is about 16 clocks.
	 */

dly_clks:
	lsri	%o0, 4			/* cnt/16 */

8:	skprnz	%o0
	br	9f
	subi	%o0, 1			/* cnt--, Delay slot */
	br	8b
	nop

9:	lret
	nop				/* Delay slot */


	.data
	.globl	version_string

version_string:
	.ascii U_BOOT_VERSION
	.ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
	.ascii CONFIG_IDENT_STRING, "\0"