1/* 2 * arch/xtensa/kernel/head.S 3 * 4 * Xtensa Processor startup code. 5 * 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 8 * for more details. 9 * 10 * Copyright (C) 2001 - 2008 Tensilica Inc. 11 * 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> 15 * Kevin Chea 16 */ 17 18#include <asm/processor.h> 19#include <asm/page.h> 20#include <asm/cacheasm.h> 21#include <asm/initialize_mmu.h> 22#include <asm/mxregs.h> 23 24#include <linux/init.h> 25#include <linux/linkage.h> 26 27/* 28 * This module contains the entry code for kernel images. It performs the 29 * minimal setup needed to call the generic C routines. 30 * 31 * Prerequisites: 32 * 33 * - The kernel image has been loaded to the actual address where it was 34 * compiled to. 35 * - a2 contains either 0 or a pointer to a list of boot parameters. 36 * (see setup.c for more details) 37 * 38 */ 39 40/* 41 * _start 42 * 43 * The bootloader passes a pointer to a list of boot parameters in a2. 44 */ 45 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 48 * instruction. 49 */ 50 51 __HEAD 52 .begin no-absolute-literals 53 54ENTRY(_start) 55 56 /* Preserve the pointer to the boot parameter list in EXCSAVE_1 */ 57 wsr a2, excsave1 58 _j _SetupOCD 59 60 .align 4 61 .literal_position 62.Lstartup: 63 .word _startup 64 65 .align 4 66_SetupOCD: 67 /* 68 * Initialize WB, WS, and clear PS.EXCM (to allow loop instructions). 69 * Set Interrupt Level just below XCHAL_DEBUGLEVEL to allow 70 * xt-gdb to single step via DEBUG exceptions received directly 71 * by ocd. 72 */ 73 movi a1, 1 74 movi a0, 0 75 wsr a1, windowstart 76 wsr a0, windowbase 77 rsync 78 79 movi a1, LOCKLEVEL 80 wsr a1, ps 81 rsync 82 83 .global _SetupMMU 84_SetupMMU: 85 Offset = _SetupMMU - _start 86 87#ifdef CONFIG_INITIALIZE_XTENSA_MMU_INSIDE_VMLINUX 88 initialize_mmu 89#if defined(CONFIG_MMU) && XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY 90 rsr a2, excsave1 91 movi a3, 0x08000000 92 bgeu a2, a3, 1f 93 movi a3, 0xd0000000 94 add a2, a2, a3 95 wsr a2, excsave1 961: 97#endif 98#endif 99 .end no-absolute-literals 100 101 l32r a0, .Lstartup 102 jx a0 103 104ENDPROC(_start) 105 106 __REF 107 .literal_position 108 109ENTRY(_startup) 110 111 /* Set a0 to 0 for the remaining initialization. */ 112 113 movi a0, 0 114 115#if XCHAL_HAVE_VECBASE 116 movi a2, VECBASE_VADDR 117 wsr a2, vecbase 118#endif 119 120 /* Clear debugging registers. */ 121 122#if XCHAL_HAVE_DEBUG 123#if XCHAL_NUM_IBREAK > 0 124 wsr a0, ibreakenable 125#endif 126 wsr a0, icount 127 movi a1, 15 128 wsr a0, icountlevel 129 130 .set _index, 0 131 .rept XCHAL_NUM_DBREAK 132 wsr a0, SREG_DBREAKC + _index 133 .set _index, _index + 1 134 .endr 135#endif 136 137 /* Clear CCOUNT (not really necessary, but nice) */ 138 139 wsr a0, ccount # not really necessary, but nice 140 141 /* Disable zero-loops. */ 142 143#if XCHAL_HAVE_LOOPS 144 wsr a0, lcount 145#endif 146 147 /* Disable all timers. */ 148 149 .set _index, 0 150 .rept XCHAL_NUM_TIMERS 151 wsr a0, SREG_CCOMPARE + _index 152 .set _index, _index + 1 153 .endr 154 155 /* Interrupt initialization. */ 156 157 movi a2, XCHAL_INTTYPE_MASK_SOFTWARE | XCHAL_INTTYPE_MASK_EXTERN_EDGE 158 wsr a0, intenable 159 wsr a2, intclear 160 161 /* Disable coprocessors. */ 162 163#if XCHAL_HAVE_CP 164 wsr a0, cpenable 165#endif 166 167 /* Initialize the caches. 168 * a2, a3 are just working registers (clobbered). 169 */ 170 171#if XCHAL_DCACHE_LINE_LOCKABLE 172 ___unlock_dcache_all a2 a3 173#endif 174 175#if XCHAL_ICACHE_LINE_LOCKABLE 176 ___unlock_icache_all a2 a3 177#endif 178 179 ___invalidate_dcache_all a2 a3 180 ___invalidate_icache_all a2 a3 181 182 isync 183 184 initialize_cacheattr 185 186#ifdef CONFIG_HAVE_SMP 187 movi a2, CCON # MX External Register to Configure Cache 188 movi a3, 1 189 wer a3, a2 190#endif 191 192 /* Setup stack and enable window exceptions (keep irqs disabled) */ 193 194 movi a1, start_info 195 l32i a1, a1, 0 196 197 movi a2, (1 << PS_WOE_BIT) | LOCKLEVEL 198 # WOE=1, INTLEVEL=LOCKLEVEL, UM=0 199 wsr a2, ps # (enable reg-windows; progmode stack) 200 rsync 201 202#ifdef CONFIG_SMP 203 /* 204 * Notice that we assume with SMP that cores have PRID 205 * supported by the cores. 206 */ 207 rsr a2, prid 208 bnez a2, .Lboot_secondary 209 210#endif /* CONFIG_SMP */ 211 212 /* Unpack data sections 213 * 214 * The linker script used to build the Linux kernel image 215 * creates a table located at __boot_reloc_table_start 216 * that contans the information what data needs to be unpacked. 217 * 218 * Uses a2-a7. 219 */ 220 221 movi a2, __boot_reloc_table_start 222 movi a3, __boot_reloc_table_end 223 2241: beq a2, a3, 3f # no more entries? 225 l32i a4, a2, 0 # start destination (in RAM) 226 l32i a5, a2, 4 # end desination (in RAM) 227 l32i a6, a2, 8 # start source (in ROM) 228 addi a2, a2, 12 # next entry 229 beq a4, a5, 1b # skip, empty entry 230 beq a4, a6, 1b # skip, source and dest. are the same 231 2322: l32i a7, a6, 0 # load word 233 addi a6, a6, 4 234 s32i a7, a4, 0 # store word 235 addi a4, a4, 4 236 bltu a4, a5, 2b 237 j 1b 238 2393: 240 /* All code and initialized data segments have been copied. 241 * Now clear the BSS segment. 242 */ 243 244 movi a2, __bss_start # start of BSS 245 movi a3, __bss_stop # end of BSS 246 247 __loopt a2, a3, a4, 2 248 s32i a0, a2, 0 249 __endla a2, a3, 4 250 251#if XCHAL_DCACHE_IS_WRITEBACK 252 253 /* After unpacking, flush the writeback cache to memory so the 254 * instructions/data are available. 255 */ 256 257 ___flush_dcache_all a2 a3 258#endif 259 memw 260 isync 261 ___invalidate_icache_all a2 a3 262 isync 263 264 movi a6, 0 265 xsr a6, excsave1 266 267 /* init_arch kick-starts the linux kernel */ 268 269 call4 init_arch 270 call4 start_kernel 271 272should_never_return: 273 j should_never_return 274 275#ifdef CONFIG_SMP 276.Lboot_secondary: 277 278 movi a2, cpu_start_ccount 2791: 280 l32i a3, a2, 0 281 beqi a3, 0, 1b 282 movi a3, 0 283 s32i a3, a2, 0 284 memw 2851: 286 l32i a3, a2, 0 287 beqi a3, 0, 1b 288 wsr a3, ccount 289 movi a3, 0 290 s32i a3, a2, 0 291 memw 292 293 movi a6, 0 294 wsr a6, excsave1 295 296 call4 secondary_start_kernel 297 j should_never_return 298 299#endif /* CONFIG_SMP */ 300 301ENDPROC(_startup) 302 303#ifdef CONFIG_HOTPLUG_CPU 304 305ENTRY(cpu_restart) 306 307#if XCHAL_DCACHE_IS_WRITEBACK 308 ___flush_invalidate_dcache_all a2 a3 309#else 310 ___invalidate_dcache_all a2 a3 311#endif 312 memw 313 movi a2, CCON # MX External Register to Configure Cache 314 movi a3, 0 315 wer a3, a2 316 extw 317 318 rsr a0, prid 319 neg a2, a0 320 movi a3, cpu_start_id 321 s32i a2, a3, 0 322#if XCHAL_DCACHE_IS_WRITEBACK 323 dhwbi a3, 0 324#endif 3251: 326 l32i a2, a3, 0 327 dhi a3, 0 328 bne a2, a0, 1b 329 330 /* 331 * Initialize WB, WS, and clear PS.EXCM (to allow loop instructions). 332 * Set Interrupt Level just below XCHAL_DEBUGLEVEL to allow 333 * xt-gdb to single step via DEBUG exceptions received directly 334 * by ocd. 335 */ 336 movi a1, 1 337 movi a0, 0 338 wsr a1, windowstart 339 wsr a0, windowbase 340 rsync 341 342 movi a1, LOCKLEVEL 343 wsr a1, ps 344 rsync 345 346 j _startup 347 348ENDPROC(cpu_restart) 349 350#endif /* CONFIG_HOTPLUG_CPU */ 351 352/* 353 * DATA section 354 */ 355 356 .section ".data.init.refok" 357 .align 4 358ENTRY(start_info) 359 .long init_thread_union + KERNEL_STACK_SIZE 360 361/* 362 * BSS section 363 */ 364 365__PAGE_ALIGNED_BSS 366#ifdef CONFIG_MMU 367ENTRY(swapper_pg_dir) 368 .fill PAGE_SIZE, 1, 0 369END(swapper_pg_dir) 370#endif 371ENTRY(empty_zero_page) 372 .fill PAGE_SIZE, 1, 0 373END(empty_zero_page) 374