head.S 5.0 KB

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