head.S 5.0 KB

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