head.S 5.0 KB

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