head.S 4.8 KB

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