head.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. #include <asm/processor.h>
  18. #include <asm/page.h>
  19. #include <asm/cacheasm.h>
  20. #include <asm/initialize_mmu.h>
  21. #include <linux/init.h>
  22. #include <linux/linkage.h>
  23. /*
  24. * This module contains the entry code for kernel images. It performs the
  25. * minimal setup needed to call the generic C routines.
  26. *
  27. * Prerequisites:
  28. *
  29. * - The kernel image has been loaded to the actual address where it was
  30. * compiled to.
  31. * - a2 contains either 0 or a pointer to a list of boot parameters.
  32. * (see setup.c for more details)
  33. *
  34. */
  35. /*
  36. * _start
  37. *
  38. * The bootloader passes a pointer to a list of boot parameters in a2.
  39. */
  40. /* The first bytes of the kernel image must be an instruction, so we
  41. * manually allocate and define the literal constant we need for a jx
  42. * instruction.
  43. */
  44. __HEAD
  45. .begin no-absolute-literals
  46. ENTRY(_start)
  47. /* Preserve the pointer to the boot parameter list in EXCSAVE_1 */
  48. wsr a2, excsave1
  49. _j _SetupMMU
  50. .align 4
  51. .literal_position
  52. .Lstartup:
  53. .word _startup
  54. .align 4
  55. .global _SetupMMU
  56. _SetupMMU:
  57. Offset = _SetupMMU - _start
  58. #ifdef CONFIG_INITIALIZE_XTENSA_MMU_INSIDE_VMLINUX
  59. initialize_mmu
  60. #if defined(CONFIG_MMU) && XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY
  61. rsr a2, excsave1
  62. movi a3, 0x08000000
  63. bgeu a2, a3, 1f
  64. movi a3, 0xd0000000
  65. add a2, a2, a3
  66. wsr a2, excsave1
  67. 1:
  68. #endif
  69. #endif
  70. .end no-absolute-literals
  71. l32r a0, .Lstartup
  72. jx a0
  73. ENDPROC(_start)
  74. __INIT
  75. .literal_position
  76. ENTRY(_startup)
  77. /* Disable interrupts and exceptions. */
  78. movi a0, LOCKLEVEL
  79. wsr a0, ps
  80. /* Start with a fresh windowbase and windowstart. */
  81. movi a1, 1
  82. movi a0, 0
  83. wsr a1, windowstart
  84. wsr a0, windowbase
  85. rsync
  86. /* Set a0 to 0 for the remaining initialization. */
  87. movi a0, 0
  88. /* Clear debugging registers. */
  89. #if XCHAL_HAVE_DEBUG
  90. #if XCHAL_NUM_IBREAK > 0
  91. wsr a0, ibreakenable
  92. #endif
  93. wsr a0, icount
  94. movi a1, 15
  95. wsr a0, icountlevel
  96. .set _index, 0
  97. .rept XCHAL_NUM_DBREAK - 1
  98. wsr a0, SREG_DBREAKC + _index
  99. .set _index, _index + 1
  100. .endr
  101. #endif
  102. /* Clear CCOUNT (not really necessary, but nice) */
  103. wsr a0, ccount # not really necessary, but nice
  104. /* Disable zero-loops. */
  105. #if XCHAL_HAVE_LOOPS
  106. wsr a0, lcount
  107. #endif
  108. /* Disable all timers. */
  109. .set _index, 0
  110. .rept XCHAL_NUM_TIMERS
  111. wsr a0, SREG_CCOMPARE + _index
  112. .set _index, _index + 1
  113. .endr
  114. /* Interrupt initialization. */
  115. movi a2, XCHAL_INTTYPE_MASK_SOFTWARE | XCHAL_INTTYPE_MASK_EXTERN_EDGE
  116. wsr a0, intenable
  117. wsr a2, intclear
  118. /* Disable coprocessors. */
  119. #if XCHAL_HAVE_CP
  120. wsr a0, cpenable
  121. #endif
  122. /* Set PS.INTLEVEL=LOCKLEVEL, PS.WOE=0, kernel stack, PS.EXCM=0
  123. *
  124. * Note: PS.EXCM must be cleared before using any loop
  125. * instructions; otherwise, they are silently disabled, and
  126. * at most one iteration of the loop is executed.
  127. */
  128. movi a1, LOCKLEVEL
  129. wsr a1, ps
  130. rsync
  131. /* Initialize the caches.
  132. * a2, a3 are just working registers (clobbered).
  133. */
  134. #if XCHAL_DCACHE_LINE_LOCKABLE
  135. ___unlock_dcache_all a2 a3
  136. #endif
  137. #if XCHAL_ICACHE_LINE_LOCKABLE
  138. ___unlock_icache_all a2 a3
  139. #endif
  140. ___invalidate_dcache_all a2 a3
  141. ___invalidate_icache_all a2 a3
  142. isync
  143. /* Unpack data sections
  144. *
  145. * The linker script used to build the Linux kernel image
  146. * creates a table located at __boot_reloc_table_start
  147. * that contans the information what data needs to be unpacked.
  148. *
  149. * Uses a2-a7.
  150. */
  151. movi a2, __boot_reloc_table_start
  152. movi a3, __boot_reloc_table_end
  153. 1: beq a2, a3, 3f # no more entries?
  154. l32i a4, a2, 0 # start destination (in RAM)
  155. l32i a5, a2, 4 # end desination (in RAM)
  156. l32i a6, a2, 8 # start source (in ROM)
  157. addi a2, a2, 12 # next entry
  158. beq a4, a5, 1b # skip, empty entry
  159. beq a4, a6, 1b # skip, source and dest. are the same
  160. 2: l32i a7, a6, 0 # load word
  161. addi a6, a6, 4
  162. s32i a7, a4, 0 # store word
  163. addi a4, a4, 4
  164. bltu a4, a5, 2b
  165. j 1b
  166. 3:
  167. /* All code and initialized data segments have been copied.
  168. * Now clear the BSS segment.
  169. */
  170. movi a2, __bss_start # start of BSS
  171. movi a3, __bss_stop # end of BSS
  172. __loopt a2, a3, a4, 2
  173. s32i a0, a2, 0
  174. __endla a2, a4, 4
  175. #if XCHAL_DCACHE_IS_WRITEBACK
  176. /* After unpacking, flush the writeback cache to memory so the
  177. * instructions/data are available.
  178. */
  179. ___flush_dcache_all a2 a3
  180. #endif
  181. memw
  182. isync
  183. ___invalidate_icache_all a2 a3
  184. isync
  185. /* Setup stack and enable window exceptions (keep irqs disabled) */
  186. movi a1, init_thread_union
  187. addi a1, a1, KERNEL_STACK_SIZE
  188. movi a2, (1 << PS_WOE_BIT) | LOCKLEVEL
  189. # WOE=1, INTLEVEL=LOCKLEVEL, UM=0
  190. wsr a2, ps # (enable reg-windows; progmode stack)
  191. rsync
  192. /* Set up EXCSAVE[DEBUGLEVEL] to point to the Debug Exception Handler.*/
  193. movi a2, debug_exception
  194. wsr a2, SREG_EXCSAVE + XCHAL_DEBUGLEVEL
  195. /* Set up EXCSAVE[1] to point to the exc_table. */
  196. movi a6, exc_table
  197. xsr a6, excsave1
  198. /* init_arch kick-starts the linux kernel */
  199. movi a4, init_arch
  200. callx4 a4
  201. movi a4, start_kernel
  202. callx4 a4
  203. should_never_return:
  204. j should_never_return
  205. ENDPROC(_startup)
  206. /*
  207. * BSS section
  208. */
  209. __PAGE_ALIGNED_BSS
  210. #ifdef CONFIG_MMU
  211. ENTRY(swapper_pg_dir)
  212. .fill PAGE_SIZE, 1, 0
  213. END(swapper_pg_dir)
  214. #endif
  215. ENTRY(empty_zero_page)
  216. .fill PAGE_SIZE, 1, 0
  217. END(empty_zero_page)