head.S 6.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
/*
 * arch/xtensa/kernel/head.S
 *
 * Xtensa Processor startup code.
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
10
 * Copyright (C) 2001 - 2008 Tensilica Inc.
11
12
13
14
15
16
17
18
19
 *
 * Chris Zankel <chris@zankel.net>
 * Marc Gauthier <marc@tensilica.com, marc@alumni.uwaterloo.ca>
 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
 * Kevin Chea
 */

#include <asm/processor.h>
#include <asm/page.h>
20
#include <asm/cacheasm.h>
Max Filippov's avatar
Max Filippov committed
21
#include <asm/initialize_mmu.h>
Max Filippov's avatar
Max Filippov committed
22
#include <asm/mxregs.h>
23

24
#include <linux/init.h>
25
26
#include <linux/linkage.h>

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * This module contains the entry code for kernel images. It performs the
 * minimal setup needed to call the generic C routines.
 *
 * Prerequisites:
 *
 * - The kernel image has been loaded to the actual address where it was
 *   compiled to.
 * - a2 contains either 0 or a pointer to a list of boot parameters.
 *   (see setup.c for more details)
 *
 */

/*
 *  _start
 *
 *  The bootloader passes a pointer to a list of boot parameters in a2.
 */

	/* The first bytes of the kernel image must be an instruction, so we
	 * manually allocate and define the literal constant we need for a jx
	 * instruction.
	 */

51
	__HEAD
Max Filippov's avatar
Max Filippov committed
52
53
	.begin	no-absolute-literals

54
55
ENTRY(_start)

Max Filippov's avatar
Max Filippov committed
56
57
	/* Preserve the pointer to the boot parameter list in EXCSAVE_1 */
	wsr     a2, excsave1
Max Filippov's avatar
Max Filippov committed
58
	_j	_SetupOCD
Max Filippov's avatar
Max Filippov committed
59
60
61

	.align	4
	.literal_position
Max Filippov's avatar
Max Filippov committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
_SetupOCD:
	/*
	 * Initialize WB, WS, and clear PS.EXCM (to allow loop instructions).
	 * Set Interrupt Level just below XCHAL_DEBUGLEVEL to allow
	 * xt-gdb to single step via DEBUG exceptions received directly
	 * by ocd.
	 */
	movi	a1, 1
	movi	a0, 0
	wsr	a1, windowstart
	wsr	a0, windowbase
	rsync

	movi	a1, LOCKLEVEL
	wsr	a1, ps
	rsync

Max Filippov's avatar
Max Filippov committed
79
80
81
82
83
84
	.global _SetupMMU
_SetupMMU:
	Offset = _SetupMMU - _start

#ifdef CONFIG_INITIALIZE_XTENSA_MMU_INSIDE_VMLINUX
	initialize_mmu
85
86
#if defined(CONFIG_MMU) && XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY
	rsr	a2, excsave1
87
88
89
90
	movi	a3, XCHAL_KSEG_PADDR
	bltu	a2, a3, 1f
	sub	a2, a2, a3
	movi	a3, XCHAL_KSEG_SIZE
91
	bgeu	a2, a3, 1f
92
	movi	a3, XCHAL_KSEG_CACHED_VADDR
93
94
95
96
	add	a2, a2, a3
	wsr	a2, excsave1
1:
#endif
Max Filippov's avatar
Max Filippov committed
97
98
#endif

99
	movi	a0, _startup
100
101
	jx	a0

102
ENDPROC(_start)
103
	.end	no-absolute-literals
104

Max Filippov's avatar
Max Filippov committed
105
	__REF
Max Filippov's avatar
Max Filippov committed
106
	.literal_position
107
108

ENTRY(_startup)
109
110
111
112
113

	/* Set a0 to 0 for the remaining initialization. */

	movi	a0, 0

114
#if XCHAL_HAVE_VECBASE
115
	movi    a2, VECBASE_VADDR
116
117
118
	wsr	a2, vecbase
#endif

119
120
121
	/* Clear debugging registers. */

#if XCHAL_HAVE_DEBUG
122
#if XCHAL_NUM_IBREAK > 0
123
	wsr	a0, ibreakenable
124
#endif
125
	wsr	a0, icount
126
	movi	a1, 15
127
	wsr	a0, icountlevel
128

129
	.set	_index, 0
130
	.rept	XCHAL_NUM_DBREAK
131
	wsr	a0, SREG_DBREAKC + _index
132
133
	.set	_index, _index + 1
	.endr
134
135
136
137
#endif

	/* Clear CCOUNT (not really necessary, but nice) */

138
	wsr	a0, ccount	# not really necessary, but nice
139
140
141
142

	/* Disable zero-loops. */

#if XCHAL_HAVE_LOOPS
143
	wsr	a0, lcount
144
145
146
147
#endif

	/* Disable all timers. */

148
	.set	_index, 0
149
	.rept	XCHAL_NUM_TIMERS
150
	wsr	a0, SREG_CCOMPARE + _index
151
152
	.set	_index, _index + 1
	.endr
153
154
155
156

	/* Interrupt initialization. */

	movi	a2, XCHAL_INTTYPE_MASK_SOFTWARE | XCHAL_INTTYPE_MASK_EXTERN_EDGE
157
158
	wsr	a0, intenable
	wsr	a2, intclear
159
160
161

	/* Disable coprocessors. */

162
#if XCHAL_HAVE_CP
163
	wsr	a0, cpenable
164
165
166
#endif

	/*  Initialize the caches.
167
	 *  a2, a3 are just working registers (clobbered).
168
169
	 */

170
171
172
173
174
175
176
177
178
179
180
181
#if XCHAL_DCACHE_LINE_LOCKABLE
	___unlock_dcache_all a2 a3
#endif

#if XCHAL_ICACHE_LINE_LOCKABLE
	___unlock_icache_all a2 a3
#endif

	___invalidate_dcache_all a2 a3
	___invalidate_icache_all a2 a3

	isync
182

183
184
	initialize_cacheattr

Max Filippov's avatar
Max Filippov committed
185
186
187
188
189
190
191
192
193
194
195
#ifdef CONFIG_HAVE_SMP
	movi	a2, CCON	# MX External Register to Configure Cache
	movi	a3, 1
	wer	a3, a2
#endif

	/* Setup stack and enable window exceptions (keep irqs disabled) */

	movi	a1, start_info
	l32i	a1, a1, 0

196
	movi	a2, PS_WOE_MASK | LOCKLEVEL
Max Filippov's avatar
Max Filippov committed
197
198
199
200
201
202
203
204
205
206
207
208
209
210
					# WOE=1, INTLEVEL=LOCKLEVEL, UM=0
	wsr	a2, ps			# (enable reg-windows; progmode stack)
	rsync

#ifdef CONFIG_SMP
	/*
	 * Notice that we assume with SMP that cores have PRID
	 * supported by the cores.
	 */
	rsr	a2, prid
	bnez	a2, .Lboot_secondary

#endif  /* CONFIG_SMP */

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
239
240
241
242
	/* Unpack data sections
	 *
	 * The linker script used to build the Linux kernel image
	 * creates a table located at __boot_reloc_table_start
	 * that contans the information what data needs to be unpacked.
	 *
	 * Uses a2-a7.
	 */

	movi	a2, __boot_reloc_table_start
	movi	a3, __boot_reloc_table_end

1:	beq	a2, a3, 3f	# no more entries?
	l32i	a4, a2, 0	# start destination (in RAM)
	l32i	a5, a2, 4	# end desination (in RAM)
	l32i	a6, a2, 8	# start source (in ROM)
	addi	a2, a2, 12	# next entry
	beq	a4, a5, 1b	# skip, empty entry
	beq	a4, a6, 1b	# skip, source and dest. are the same

2:	l32i	a7, a6, 0	# load word
	addi	a6, a6, 4
	s32i	a7, a4, 0	# store word
	addi	a4, a4, 4
	bltu	a4, a5, 2b
	j	1b

3:
	/* All code and initialized data segments have been copied.
	 * Now clear the BSS segment.
	 */

243
244
	movi	a2, __bss_start	# start of BSS
	movi	a3, __bss_stop	# end of BSS
245

246
	__loopt	a2, a3, a4, 2
247
	s32i	a0, a2, 0
248
	__endla	a2, a3, 4
249
250
251
252
253
254
255

#if XCHAL_DCACHE_IS_WRITEBACK

	/* After unpacking, flush the writeback cache to memory so the
	 * instructions/data are available.
	 */

256
	___flush_dcache_all a2 a3
257
#endif
Max Filippov's avatar
Max Filippov committed
258
259
260
261
	memw
	isync
	___invalidate_icache_all a2 a3
	isync
262

Max Filippov's avatar
Max Filippov committed
263
	movi	a6, 0
264
	xsr	a6, excsave1
265
266
267

	/* init_arch kick-starts the linux kernel */

268
269
	call4	init_arch
	call4	start_kernel
270
271
272
273

should_never_return:
	j	should_never_return

Max Filippov's avatar
Max Filippov committed
274
275
276
277
278
#ifdef CONFIG_SMP
.Lboot_secondary:

	movi	a2, cpu_start_ccount
1:
279
	memw
Max Filippov's avatar
Max Filippov committed
280
281
282
283
284
	l32i	a3, a2, 0
	beqi	a3, 0, 1b
	movi	a3, 0
	s32i	a3, a2, 0
1:
285
	memw
Max Filippov's avatar
Max Filippov committed
286
287
288
289
290
291
292
293
294
295
	l32i	a3, a2, 0
	beqi	a3, 0, 1b
	wsr	a3, ccount
	movi	a3, 0
	s32i	a3, a2, 0
	memw

	movi	a6, 0
	wsr	a6, excsave1

296
	call4	secondary_start_kernel
Max Filippov's avatar
Max Filippov committed
297
298
299
300
	j	should_never_return

#endif  /* CONFIG_SMP */

301
ENDPROC(_startup)
302

Max Filippov's avatar
Max Filippov committed
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#ifdef CONFIG_HOTPLUG_CPU

ENTRY(cpu_restart)

#if XCHAL_DCACHE_IS_WRITEBACK
	___flush_invalidate_dcache_all a2 a3
#else
	___invalidate_dcache_all a2 a3
#endif
	memw
	movi	a2, CCON	# MX External Register to Configure Cache
	movi	a3, 0
	wer	a3, a2
	extw

	rsr	a0, prid
	neg	a2, a0
	movi	a3, cpu_start_id
321
	memw
Max Filippov's avatar
Max Filippov committed
322
323
324
325
326
	s32i	a2, a3, 0
#if XCHAL_DCACHE_IS_WRITEBACK
	dhwbi	a3, 0
#endif
1:
327
	memw
Max Filippov's avatar
Max Filippov committed
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
	l32i	a2, a3, 0
	dhi	a3, 0
	bne	a2, a0, 1b

	/*
	 * Initialize WB, WS, and clear PS.EXCM (to allow loop instructions).
	 * Set Interrupt Level just below XCHAL_DEBUGLEVEL to allow
	 * xt-gdb to single step via DEBUG exceptions received directly
	 * by ocd.
	 */
	movi	a1, 1
	movi	a0, 0
	wsr	a1, windowstart
	wsr	a0, windowbase
	rsync

	movi	a1, LOCKLEVEL
	wsr	a1, ps
	rsync

	j	_startup

ENDPROC(cpu_restart)

#endif  /* CONFIG_HOTPLUG_CPU */

Max Filippov's avatar
Max Filippov committed
354
355
356
357
358
359
360
361
362
/*
 * DATA section
 */

        .section ".data.init.refok"
        .align  4
ENTRY(start_info)
        .long   init_thread_union + KERNEL_STACK_SIZE

363
364
365
366
/*
 * BSS section
 */
	
367
__PAGE_ALIGNED_BSS
Johannes Weiner's avatar
Johannes Weiner committed
368
#ifdef CONFIG_MMU
369
370
ENTRY(swapper_pg_dir)
	.fill	PAGE_SIZE, 1, 0
371
END(swapper_pg_dir)
Johannes Weiner's avatar
Johannes Weiner committed
372
#endif
373
374
ENTRY(empty_zero_page)
	.fill	PAGE_SIZE, 1, 0
375
END(empty_zero_page)