head.S 4.9 KB

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