head.S 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 <xtensa/cacheasm.h>
  18. #include <asm/processor.h>
  19. #include <asm/page.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. .macro iterate from, to , cmd
  33. .ifeq ((\to - \from) & ~0xfff)
  34. \cmd \from
  35. iterate "(\from+1)", \to, \cmd
  36. .endif
  37. .endm
  38. /*
  39. * _start
  40. *
  41. * The bootloader passes a pointer to a list of boot parameters in a2.
  42. */
  43. /* The first bytes of the kernel image must be an instruction, so we
  44. * manually allocate and define the literal constant we need for a jx
  45. * instruction.
  46. */
  47. .section .head.text, "ax"
  48. .globl _start
  49. _start: _j 2f
  50. .align 4
  51. 1: .word _startup
  52. 2: l32r a0, 1b
  53. jx a0
  54. .text
  55. .align 4
  56. _startup:
  57. /* Disable interrupts and exceptions. */
  58. movi a0, XCHAL_PS_EXCM_MASK
  59. wsr a0, PS
  60. /* Preserve the pointer to the boot parameter list in EXCSAVE_1 */
  61. wsr a2, EXCSAVE_1
  62. /* Start with a fresh windowbase and windowstart. */
  63. movi a1, 1
  64. movi a0, 0
  65. wsr a1, WINDOWSTART
  66. wsr a0, WINDOWBASE
  67. rsync
  68. /* Set a0 to 0 for the remaining initialization. */
  69. movi a0, 0
  70. /* Clear debugging registers. */
  71. #if XCHAL_HAVE_DEBUG
  72. wsr a0, IBREAKENABLE
  73. wsr a0, ICOUNT
  74. movi a1, 15
  75. wsr a0, ICOUNTLEVEL
  76. .macro reset_dbreak num
  77. wsr a0, DBREAKC + \num
  78. .endm
  79. iterate 0, XCHAL_NUM_IBREAK-1, reset_dbreak
  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. .macro reset_timer num
  89. wsr a0, CCOMPARE_0 + \num
  90. .endm
  91. iterate 0, XCHAL_NUM_TIMERS-1, reset_timer
  92. /* Interrupt initialization. */
  93. movi a2, XCHAL_INTTYPE_MASK_SOFTWARE | XCHAL_INTTYPE_MASK_EXTERN_EDGE
  94. wsr a0, INTENABLE
  95. wsr a2, INTCLEAR
  96. /* Disable coprocessors. */
  97. #if XCHAL_CP_NUM > 0
  98. wsr a0, CPENABLE
  99. #endif
  100. /* Set PS.INTLEVEL=1, PS.WOE=0, kernel stack, PS.EXCM=0
  101. *
  102. * Note: PS.EXCM must be cleared before using any loop
  103. * instructions; otherwise, they are silently disabled, and
  104. * at most one iteration of the loop is executed.
  105. */
  106. movi a1, 1
  107. wsr a1, PS
  108. rsync
  109. /* Initialize the caches.
  110. * Does not include flushing writeback d-cache.
  111. * a6, a7 are just working registers (clobbered).
  112. */
  113. icache_reset a2, a3
  114. dcache_reset a2, a3
  115. /* Unpack data sections
  116. *
  117. * The linker script used to build the Linux kernel image
  118. * creates a table located at __boot_reloc_table_start
  119. * that contans the information what data needs to be unpacked.
  120. *
  121. * Uses a2-a7.
  122. */
  123. movi a2, __boot_reloc_table_start
  124. movi a3, __boot_reloc_table_end
  125. 1: beq a2, a3, 3f # no more entries?
  126. l32i a4, a2, 0 # start destination (in RAM)
  127. l32i a5, a2, 4 # end desination (in RAM)
  128. l32i a6, a2, 8 # start source (in ROM)
  129. addi a2, a2, 12 # next entry
  130. beq a4, a5, 1b # skip, empty entry
  131. beq a4, a6, 1b # skip, source and dest. are the same
  132. 2: l32i a7, a6, 0 # load word
  133. addi a6, a6, 4
  134. s32i a7, a4, 0 # store word
  135. addi a4, a4, 4
  136. bltu a4, a5, 2b
  137. j 1b
  138. 3:
  139. /* All code and initialized data segments have been copied.
  140. * Now clear the BSS segment.
  141. */
  142. movi a2, _bss_start # start of BSS
  143. movi a3, _bss_end # end of BSS
  144. 1: addi a2, a2, 4
  145. s32i a0, a2, 0
  146. blt a2, a3, 1b
  147. #if XCHAL_DCACHE_IS_WRITEBACK
  148. /* After unpacking, flush the writeback cache to memory so the
  149. * instructions/data are available.
  150. */
  151. dcache_writeback_all a2, a3
  152. #endif
  153. /* Setup stack and enable window exceptions (keep irqs disabled) */
  154. movi a1, init_thread_union
  155. addi a1, a1, KERNEL_STACK_SIZE
  156. movi a2, 0x00040001 # WOE=1, INTLEVEL=1, UM=0
  157. wsr a2, PS # (enable reg-windows; progmode stack)
  158. rsync
  159. /* Set up EXCSAVE[DEBUGLEVEL] to point to the Debug Exception Handler.*/
  160. movi a2, debug_exception
  161. wsr a2, EXCSAVE + XCHAL_DEBUGLEVEL
  162. /* Set up EXCSAVE[1] to point to the exc_table. */
  163. movi a6, exc_table
  164. xsr a6, EXCSAVE_1
  165. /* init_arch kick-starts the linux kernel */
  166. movi a4, init_arch
  167. callx4 a4
  168. movi a4, start_kernel
  169. callx4 a4
  170. should_never_return:
  171. j should_never_return
  172. /* Define some common data structures here. We define them
  173. * here in this assembly file due to their unusual alignment
  174. * requirements.
  175. */
  176. .comm swapper_pg_dir,PAGE_SIZE,PAGE_SIZE
  177. .comm empty_bad_page_table,PAGE_SIZE,PAGE_SIZE
  178. .comm empty_bad_page,PAGE_SIZE,PAGE_SIZE
  179. .comm empty_zero_page,PAGE_SIZE,PAGE_SIZE