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 - 2005 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>
23 * This module contains the entry code for kernel images. It performs the
24 * minimal setup needed to call the generic C routines.
28 * - The kernel image has been loaded to the actual address where it was
30 * - a2 contains either 0 or a pointer to a list of boot parameters.
31 * (see setup.c for more details)
38 * The bootloader passes a pointer to a list of boot parameters in a2.
41 /* The first bytes of the kernel image must be an instruction, so we
42 * manually allocate and define the literal constant we need for a jx
46 .section .head.text, "ax"
58 /* Disable interrupts and exceptions. */
63 /* Preserve the pointer to the boot parameter list in EXCSAVE_1 */
67 /* Start with a fresh windowbase and windowstart. */
75 /* Set a0 to 0 for the remaining initialization. */
79 /* Clear debugging registers. */
88 .rept XCHAL_NUM_DBREAK - 1
89 wsr a0, DBREAKC + _index
90 .set _index, _index + 1
94 /* Clear CCOUNT (not really necessary, but nice) */
96 wsr a0, CCOUNT # not really necessary, but nice
98 /* Disable zero-loops. */
104 /* Disable all timers. */
107 .rept XCHAL_NUM_TIMERS - 1
108 wsr a0, CCOMPARE + _index
109 .set _index, _index + 1
112 /* Interrupt initialization. */
114 movi a2, XCHAL_INTTYPE_MASK_SOFTWARE | XCHAL_INTTYPE_MASK_EXTERN_EDGE
118 /* Disable coprocessors. */
124 /* Set PS.INTLEVEL=1, PS.WOE=0, kernel stack, PS.EXCM=0
126 * Note: PS.EXCM must be cleared before using any loop
127 * instructions; otherwise, they are silently disabled, and
128 * at most one iteration of the loop is executed.
135 /* Initialize the caches.
136 * a2, a3 are just working registers (clobbered).
139 #if XCHAL_DCACHE_LINE_LOCKABLE
140 ___unlock_dcache_all a2 a3
143 #if XCHAL_ICACHE_LINE_LOCKABLE
144 ___unlock_icache_all a2 a3
147 ___invalidate_dcache_all a2 a3
148 ___invalidate_icache_all a2 a3
152 /* Unpack data sections
154 * The linker script used to build the Linux kernel image
155 * creates a table located at __boot_reloc_table_start
156 * that contans the information what data needs to be unpacked.
161 movi a2, __boot_reloc_table_start
162 movi a3, __boot_reloc_table_end
164 1: beq a2, a3, 3f # no more entries?
165 l32i a4, a2, 0 # start destination (in RAM)
166 l32i a5, a2, 4 # end desination (in RAM)
167 l32i a6, a2, 8 # start source (in ROM)
168 addi a2, a2, 12 # next entry
169 beq a4, a5, 1b # skip, empty entry
170 beq a4, a6, 1b # skip, source and dest. are the same
172 2: l32i a7, a6, 0 # load word
174 s32i a7, a4, 0 # store word
180 /* All code and initialized data segments have been copied.
181 * Now clear the BSS segment.
184 movi a2, _bss_start # start of BSS
185 movi a3, _bss_end # end of BSS
187 __loopt a2, a3, a4, 2
191 #if XCHAL_DCACHE_IS_WRITEBACK
193 /* After unpacking, flush the writeback cache to memory so the
194 * instructions/data are available.
197 ___flush_dcache_all a2 a3
200 /* Setup stack and enable window exceptions (keep irqs disabled) */
202 movi a1, init_thread_union
203 addi a1, a1, KERNEL_STACK_SIZE
205 movi a2, 0x00040001 # WOE=1, INTLEVEL=1, UM=0
206 wsr a2, PS # (enable reg-windows; progmode stack)
209 /* Set up EXCSAVE[DEBUGLEVEL] to point to the Debug Exception Handler.*/
211 movi a2, debug_exception
212 wsr a2, EXCSAVE + XCHAL_DEBUGLEVEL
214 /* Set up EXCSAVE[1] to point to the exc_table. */
219 /* init_arch kick-starts the linux kernel */
224 movi a4, start_kernel
228 j should_never_return
230 /* Define some common data structures here. We define them
231 * here in this assembly file due to their unusual alignment
235 .comm swapper_pg_dir,PAGE_SIZE,PAGE_SIZE
236 .comm empty_bad_page_table,PAGE_SIZE,PAGE_SIZE
237 .comm empty_bad_page,PAGE_SIZE,PAGE_SIZE
238 .comm empty_zero_page,PAGE_SIZE,PAGE_SIZE