head.S 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. #endif
  61. .end no-absolute-literals
  62. l32r a0, .Lstartup
  63. jx a0
  64. ENDPROC(_start)
  65. __INIT
  66. .literal_position
  67. ENTRY(_startup)
  68. /* Disable interrupts and exceptions. */
  69. movi a0, LOCKLEVEL
  70. wsr a0, ps
  71. /* Start with a fresh windowbase and windowstart. */
  72. movi a1, 1
  73. movi a0, 0
  74. wsr a1, windowstart
  75. wsr a0, windowbase
  76. rsync
  77. /* Set a0 to 0 for the remaining initialization. */
  78. movi a0, 0
  79. /* Clear debugging registers. */
  80. #if XCHAL_HAVE_DEBUG
  81. #if XCHAL_NUM_IBREAK > 0
  82. wsr a0, ibreakenable
  83. #endif
  84. wsr a0, icount
  85. movi a1, 15
  86. wsr a0, icountlevel
  87. .set _index, 0
  88. .rept XCHAL_NUM_DBREAK - 1
  89. wsr a0, SREG_DBREAKC + _index
  90. .set _index, _index + 1
  91. .endr
  92. #endif
  93. /* Clear CCOUNT (not really necessary, but nice) */
  94. wsr a0, ccount # not really necessary, but nice
  95. /* Disable zero-loops. */
  96. #if XCHAL_HAVE_LOOPS
  97. wsr a0, lcount
  98. #endif
  99. /* Disable all timers. */
  100. .set _index, 0
  101. .rept XCHAL_NUM_TIMERS
  102. wsr a0, SREG_CCOMPARE + _index
  103. .set _index, _index + 1
  104. .endr
  105. /* Interrupt initialization. */
  106. movi a2, XCHAL_INTTYPE_MASK_SOFTWARE | XCHAL_INTTYPE_MASK_EXTERN_EDGE
  107. wsr a0, intenable
  108. wsr a2, intclear
  109. /* Disable coprocessors. */
  110. #if XCHAL_HAVE_CP
  111. wsr a0, cpenable
  112. #endif
  113. /* Set PS.INTLEVEL=LOCKLEVEL, PS.WOE=0, kernel stack, PS.EXCM=0
  114. *
  115. * Note: PS.EXCM must be cleared before using any loop
  116. * instructions; otherwise, they are silently disabled, and
  117. * at most one iteration of the loop is executed.
  118. */
  119. movi a1, LOCKLEVEL
  120. wsr a1, ps
  121. rsync
  122. /* Initialize the caches.
  123. * a2, a3 are just working registers (clobbered).
  124. */
  125. #if XCHAL_DCACHE_LINE_LOCKABLE
  126. ___unlock_dcache_all a2 a3
  127. #endif
  128. #if XCHAL_ICACHE_LINE_LOCKABLE
  129. ___unlock_icache_all a2 a3
  130. #endif
  131. ___invalidate_dcache_all a2 a3
  132. ___invalidate_icache_all a2 a3
  133. isync
  134. /* Unpack data sections
  135. *
  136. * The linker script used to build the Linux kernel image
  137. * creates a table located at __boot_reloc_table_start
  138. * that contans the information what data needs to be unpacked.
  139. *
  140. * Uses a2-a7.
  141. */
  142. movi a2, __boot_reloc_table_start
  143. movi a3, __boot_reloc_table_end
  144. 1: beq a2, a3, 3f # no more entries?
  145. l32i a4, a2, 0 # start destination (in RAM)
  146. l32i a5, a2, 4 # end desination (in RAM)
  147. l32i a6, a2, 8 # start source (in ROM)
  148. addi a2, a2, 12 # next entry
  149. beq a4, a5, 1b # skip, empty entry
  150. beq a4, a6, 1b # skip, source and dest. are the same
  151. 2: l32i a7, a6, 0 # load word
  152. addi a6, a6, 4
  153. s32i a7, a4, 0 # store word
  154. addi a4, a4, 4
  155. bltu a4, a5, 2b
  156. j 1b
  157. 3:
  158. /* All code and initialized data segments have been copied.
  159. * Now clear the BSS segment.
  160. */
  161. movi a2, __bss_start # start of BSS
  162. movi a3, __bss_stop # end of BSS
  163. __loopt a2, a3, a4, 2
  164. s32i a0, a2, 0
  165. __endla a2, a4, 4
  166. #if XCHAL_DCACHE_IS_WRITEBACK
  167. /* After unpacking, flush the writeback cache to memory so the
  168. * instructions/data are available.
  169. */
  170. ___flush_dcache_all a2 a3
  171. #endif
  172. memw
  173. isync
  174. ___invalidate_icache_all a2 a3
  175. isync
  176. /* Setup stack and enable window exceptions (keep irqs disabled) */
  177. movi a1, init_thread_union
  178. addi a1, a1, KERNEL_STACK_SIZE
  179. movi a2, (1 << PS_WOE_BIT) | LOCKLEVEL
  180. # WOE=1, INTLEVEL=LOCKLEVEL, UM=0
  181. wsr a2, ps # (enable reg-windows; progmode stack)
  182. rsync
  183. /* Set up EXCSAVE[DEBUGLEVEL] to point to the Debug Exception Handler.*/
  184. movi a2, debug_exception
  185. wsr a2, SREG_EXCSAVE + XCHAL_DEBUGLEVEL
  186. /* Set up EXCSAVE[1] to point to the exc_table. */
  187. movi a6, exc_table
  188. xsr a6, excsave1
  189. /* init_arch kick-starts the linux kernel */
  190. movi a4, init_arch
  191. callx4 a4
  192. movi a4, start_kernel
  193. callx4 a4
  194. should_never_return:
  195. j should_never_return
  196. ENDPROC(_startup)
  197. /*
  198. * BSS section
  199. */
  200. __PAGE_ALIGNED_BSS
  201. #ifdef CONFIG_MMU
  202. ENTRY(swapper_pg_dir)
  203. .fill PAGE_SIZE, 1, 0
  204. END(swapper_pg_dir)
  205. #endif
  206. ENTRY(empty_zero_page)
  207. .fill PAGE_SIZE, 1, 0
  208. END(empty_zero_page)