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/asmmacro.h>
19 #include <asm/processor.h>
21 #include <asm/cacheasm.h>
22 #include <asm/initialize_mmu.h>
23 #include <asm/mxregs.h>
25 #include <linux/init.h>
26 #include <linux/linkage.h>
29 * This module contains the entry code for kernel images. It performs the
30 * minimal setup needed to call the generic C routines.
34 * - The kernel image has been loaded to the actual address where it was
36 * - a2 contains either 0 or a pointer to a list of boot parameters.
37 * (see setup.c for more details)
44 * The bootloader passes a pointer to a list of boot parameters in a2.
47 /* The first bytes of the kernel image must be an instruction, so we
48 * manually allocate and define the literal constant we need for a jx
53 .begin no-absolute-literals
57 /* Preserve the pointer to the boot parameter list in EXCSAVE_1 */
65 * Initialize WB, WS, and clear PS.EXCM (to allow loop instructions).
66 * Set Interrupt Level just below XCHAL_DEBUGLEVEL to allow
67 * xt-gdb to single step via DEBUG exceptions received directly
70 #if XCHAL_HAVE_WINDOWED
84 Offset = _SetupMMU - _start
86 #ifdef CONFIG_INITIALIZE_XTENSA_MMU_INSIDE_VMLINUX
88 #if defined(CONFIG_MMU) && XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY
90 movi a3, XCHAL_KSEG_PADDR
93 movi a3, XCHAL_KSEG_SIZE
95 movi a3, XCHAL_KSEG_CACHED_VADDR
106 .end no-absolute-literals
113 /* Set a0 to 0 for the remaining initialization. */
117 #if XCHAL_HAVE_VECBASE
118 movi a2, VECBASE_VADDR
122 /* Clear debugging registers. */
125 #if XCHAL_NUM_IBREAK > 0
133 .rept XCHAL_NUM_DBREAK
134 wsr a0, SREG_DBREAKC + _index
135 .set _index, _index + 1
139 /* Clear CCOUNT (not really necessary, but nice) */
141 wsr a0, ccount # not really necessary, but nice
143 /* Disable zero-loops. */
149 /* Disable all timers. */
152 .rept XCHAL_NUM_TIMERS
153 wsr a0, SREG_CCOMPARE + _index
154 .set _index, _index + 1
157 /* Interrupt initialization. */
159 movi a2, XCHAL_INTTYPE_MASK_SOFTWARE | XCHAL_INTTYPE_MASK_EXTERN_EDGE
163 /* Disable coprocessors. */
169 /* Initialize the caches.
170 * a2, a3 are just working registers (clobbered).
173 #if XCHAL_DCACHE_LINE_LOCKABLE
174 ___unlock_dcache_all a2 a3
177 #if XCHAL_ICACHE_LINE_LOCKABLE
178 ___unlock_icache_all a2 a3
181 ___invalidate_dcache_all a2 a3
182 ___invalidate_icache_all a2 a3
188 #ifdef CONFIG_HAVE_SMP
189 movi a2, CCON # MX External Register to Configure Cache
194 /* Setup stack and enable window exceptions (keep irqs disabled) */
199 /* Disable interrupts. */
200 /* Enable window exceptions if kernel is built with windowed ABI. */
201 movi a2, KERNEL_PS_WOE_MASK | LOCKLEVEL
207 * Notice that we assume with SMP that cores have PRID
208 * supported by the cores.
211 bnez a2, .Lboot_secondary
213 #endif /* CONFIG_SMP */
215 /* Unpack data sections
217 * The linker script used to build the Linux kernel image
218 * creates a table located at __boot_reloc_table_start
219 * that contains the information what data needs to be unpacked.
224 movi a2, __boot_reloc_table_start
225 movi a3, __boot_reloc_table_end
227 1: beq a2, a3, 3f # no more entries?
228 l32i a4, a2, 0 # start destination (in RAM)
229 l32i a5, a2, 4 # end destination (in RAM)
230 l32i a6, a2, 8 # start source (in ROM)
231 addi a2, a2, 12 # next entry
232 beq a4, a5, 1b # skip, empty entry
233 beq a4, a6, 1b # skip, source and dest. are the same
235 2: l32i a7, a6, 0 # load word
237 s32i a7, a4, 0 # store word
243 /* All code and initialized data segments have been copied.
244 * Now clear the BSS segment.
247 movi a2, __bss_start # start of BSS
248 movi a3, __bss_stop # end of BSS
250 __loopt a2, a3, a4, 2
254 #if XCHAL_DCACHE_IS_WRITEBACK
256 /* After unpacking, flush the writeback cache to memory so the
257 * instructions/data are available.
260 ___flush_dcache_all a2 a3
264 ___invalidate_icache_all a2 a3
267 #ifdef CONFIG_XIP_KERNEL
268 /* Setup bootstrap CPU stack in XIP kernel */
275 xsr abi_arg0, excsave1
277 /* init_arch kick-starts the linux kernel */
280 abi_call start_kernel
283 j should_never_return
288 movi a2, cpu_start_ccount
305 wsr abi_arg0, excsave1
307 abi_call secondary_start_kernel
308 j should_never_return
310 #endif /* CONFIG_SMP */
314 #ifdef CONFIG_HOTPLUG_CPU
318 #if XCHAL_DCACHE_IS_WRITEBACK
319 ___flush_invalidate_dcache_all a2 a3
321 ___invalidate_dcache_all a2 a3
324 movi a2, CCON # MX External Register to Configure Cache
331 movi a3, cpu_start_id
334 #if XCHAL_DCACHE_IS_WRITEBACK
344 * Initialize WB, WS, and clear PS.EXCM (to allow loop instructions).
345 * Set Interrupt Level just below XCHAL_DEBUGLEVEL to allow
346 * xt-gdb to single step via DEBUG exceptions received directly
363 #endif /* CONFIG_HOTPLUG_CPU */
372 .long init_thread_union + KERNEL_STACK_SIZE
380 ENTRY(swapper_pg_dir)
381 .fill PAGE_SIZE, 1, 0
384 ENTRY(empty_zero_page)
385 .fill PAGE_SIZE, 1, 0