head.S 4.8 KB

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