2 * arch/xtensa/kernel/head.S
4 * Xtensa Processor startup code.
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
10 * Copyright (C) 2001 - 2008 Tensilica Inc.
12 * Chris Zankel <chris@zankel.net>
13 * Marc Gauthier <marc@tensilica.com, marc@alumni.uwaterloo.ca>
14 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
18 #include <asm/processor.h>
20 #include <asm/cacheasm.h>
21 #include <asm/initialize_mmu.h>
22 #include <asm/mxregs.h>
24 #include <linux/init.h>
25 #include <linux/linkage.h>
28 * This module contains the entry code for kernel images. It performs the
29 * minimal setup needed to call the generic C routines.
33 * - The kernel image has been loaded to the actual address where it was
35 * - a2 contains either 0 or a pointer to a list of boot parameters.
36 * (see setup.c for more details)
43 * The bootloader passes a pointer to a list of boot parameters in a2.
46 /* The first bytes of the kernel image must be an instruction, so we
47 * manually allocate and define the literal constant we need for a jx
52 .begin no-absolute-literals
56 /* Preserve the pointer to the boot parameter list in EXCSAVE_1 */
64 * Initialize WB, WS, and clear PS.EXCM (to allow loop instructions).
65 * Set Interrupt Level just below XCHAL_DEBUGLEVEL to allow
66 * xt-gdb to single step via DEBUG exceptions received directly
81 Offset = _SetupMMU - _start
83 #ifdef CONFIG_INITIALIZE_XTENSA_MMU_INSIDE_VMLINUX
85 #if defined(CONFIG_MMU) && XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY
87 movi a3, XCHAL_KSEG_PADDR
90 movi a3, XCHAL_KSEG_SIZE
92 movi a3, XCHAL_KSEG_CACHED_VADDR
103 .end no-absolute-literals
110 /* Set a0 to 0 for the remaining initialization. */
114 #if XCHAL_HAVE_VECBASE
115 movi a2, VECBASE_VADDR
119 /* Clear debugging registers. */
122 #if XCHAL_NUM_IBREAK > 0
130 .rept XCHAL_NUM_DBREAK
131 wsr a0, SREG_DBREAKC + _index
132 .set _index, _index + 1
136 /* Clear CCOUNT (not really necessary, but nice) */
138 wsr a0, ccount # not really necessary, but nice
140 /* Disable zero-loops. */
146 /* Disable all timers. */
149 .rept XCHAL_NUM_TIMERS
150 wsr a0, SREG_CCOMPARE + _index
151 .set _index, _index + 1
154 /* Interrupt initialization. */
156 movi a2, XCHAL_INTTYPE_MASK_SOFTWARE | XCHAL_INTTYPE_MASK_EXTERN_EDGE
160 /* Disable coprocessors. */
166 /* Initialize the caches.
167 * a2, a3 are just working registers (clobbered).
170 #if XCHAL_DCACHE_LINE_LOCKABLE
171 ___unlock_dcache_all a2 a3
174 #if XCHAL_ICACHE_LINE_LOCKABLE
175 ___unlock_icache_all a2 a3
178 ___invalidate_dcache_all a2 a3
179 ___invalidate_icache_all a2 a3
185 #ifdef CONFIG_HAVE_SMP
186 movi a2, CCON # MX External Register to Configure Cache
191 /* Setup stack and enable window exceptions (keep irqs disabled) */
196 movi a2, PS_WOE_MASK | LOCKLEVEL
197 # WOE=1, INTLEVEL=LOCKLEVEL, UM=0
198 wsr a2, ps # (enable reg-windows; progmode stack)
203 * Notice that we assume with SMP that cores have PRID
204 * supported by the cores.
207 bnez a2, .Lboot_secondary
209 #endif /* CONFIG_SMP */
211 /* Unpack data sections
213 * The linker script used to build the Linux kernel image
214 * creates a table located at __boot_reloc_table_start
215 * that contans the information what data needs to be unpacked.
220 movi a2, __boot_reloc_table_start
221 movi a3, __boot_reloc_table_end
223 1: beq a2, a3, 3f # no more entries?
224 l32i a4, a2, 0 # start destination (in RAM)
225 l32i a5, a2, 4 # end desination (in RAM)
226 l32i a6, a2, 8 # start source (in ROM)
227 addi a2, a2, 12 # next entry
228 beq a4, a5, 1b # skip, empty entry
229 beq a4, a6, 1b # skip, source and dest. are the same
231 2: l32i a7, a6, 0 # load word
233 s32i a7, a4, 0 # store word
239 /* All code and initialized data segments have been copied.
240 * Now clear the BSS segment.
243 movi a2, __bss_start # start of BSS
244 movi a3, __bss_stop # end of BSS
246 __loopt a2, a3, a4, 2
250 #if XCHAL_DCACHE_IS_WRITEBACK
252 /* After unpacking, flush the writeback cache to memory so the
253 * instructions/data are available.
256 ___flush_dcache_all a2 a3
260 ___invalidate_icache_all a2 a3
263 #ifdef CONFIG_XIP_KERNEL
264 /* Setup bootstrap CPU stack in XIP kernel */
273 /* init_arch kick-starts the linux kernel */
279 j should_never_return
284 movi a2, cpu_start_ccount
303 call4 secondary_start_kernel
304 j should_never_return
306 #endif /* CONFIG_SMP */
310 #ifdef CONFIG_HOTPLUG_CPU
314 #if XCHAL_DCACHE_IS_WRITEBACK
315 ___flush_invalidate_dcache_all a2 a3
317 ___invalidate_dcache_all a2 a3
320 movi a2, CCON # MX External Register to Configure Cache
327 movi a3, cpu_start_id
330 #if XCHAL_DCACHE_IS_WRITEBACK
340 * Initialize WB, WS, and clear PS.EXCM (to allow loop instructions).
341 * Set Interrupt Level just below XCHAL_DEBUGLEVEL to allow
342 * xt-gdb to single step via DEBUG exceptions received directly
359 #endif /* CONFIG_HOTPLUG_CPU */
368 .long init_thread_union + KERNEL_STACK_SIZE
376 ENTRY(swapper_pg_dir)
377 .fill PAGE_SIZE, 1, 0
380 ENTRY(empty_zero_page)
381 .fill PAGE_SIZE, 1, 0