bootstrap.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #define _ASMLANGUAGE
  2. #include <xtensa/config/specreg.h>
  3. #include <xtensa/config/core.h>
  4. #include <xtensa/cacheasm.h>
  5. /*
  6. * RB-Data: RedBoot data/bss
  7. * P: Boot-Parameters
  8. * L: Kernel-Loader
  9. *
  10. * The Linux-Kernel image including the loader must be loaded
  11. * to a position so that the kernel and the boot parameters
  12. * can fit in the space before the load address.
  13. * ______________________________________________________
  14. * |_RB-Data_|_P_|__________|_L_|___Linux-Kernel___|______|
  15. * ^
  16. * ^ Load address
  17. * ______________________________________________________
  18. * |___Linux-Kernel___|_P_|_L_|___________________________|
  19. *
  20. * The loader copies the parameter to the position that will
  21. * be the end of the kernel and itself to the end of the
  22. * parameter list.
  23. */
  24. /* Make sure we have enough space for the 'uncompressor' */
  25. #define STACK_SIZE 32768
  26. #define HEAP_SIZE (131072*4)
  27. # a2: Parameter list
  28. # a3: Size of parameter list
  29. .section .start, "ax"
  30. .globl __start
  31. /* this must be the first byte of the loader! */
  32. __start:
  33. entry sp, 32 # we do not intend to return
  34. _call0 _start
  35. __start_a0:
  36. .align 4
  37. .section .text, "ax"
  38. .begin literal_prefix .text
  39. /* put literals in here! */
  40. .globl _start
  41. _start:
  42. /* 'reset' window registers */
  43. movi a4, 1
  44. wsr a4, PS
  45. rsync
  46. rsr a5, WINDOWBASE
  47. ssl a5
  48. sll a4, a4
  49. wsr a4, WINDOWSTART
  50. rsync
  51. movi a4, 0x00040000
  52. wsr a4, PS
  53. rsync
  54. /* copy the loader to its address
  55. * Note: The loader itself is a very small piece, so we assume we
  56. * don't partially overlap. We also assume (even more important)
  57. * that the kernel image is out of the way. Usually, when the
  58. * load address of this image is not at an arbitrary address,
  59. * but aligned to some 10K's we shouldn't overlap.
  60. */
  61. /* Note: The assembler cannot relax "addi a0, a0, ..." to an
  62. l32r, so we load to a4 first. */
  63. addi a4, a0, __start - __start_a0
  64. mov a0, a4
  65. movi a4, __start
  66. movi a5, __reloc_end
  67. # a0: address where this code has been loaded
  68. # a4: compiled address of __start
  69. # a5: compiled end address
  70. mov.n a7, a0
  71. mov.n a8, a4
  72. 1:
  73. l32i a10, a7, 0
  74. l32i a11, a7, 4
  75. s32i a10, a8, 0
  76. s32i a11, a8, 4
  77. l32i a10, a7, 8
  78. l32i a11, a7, 12
  79. s32i a10, a8, 8
  80. s32i a11, a8, 12
  81. addi a8, a8, 16
  82. addi a7, a7, 16
  83. blt a8, a5, 1b
  84. /* We have to flush and invalidate the caches here before we jump. */
  85. #if XCHAL_DCACHE_IS_WRITEBACK
  86. dcache_writeback_all a5, a6
  87. #endif
  88. icache_invalidate_all a5, a6
  89. movi a11, _reloc
  90. jx a11
  91. .globl _reloc
  92. _reloc:
  93. /* RedBoot is now at the end of the memory, so we don't have
  94. * to copy the parameter list. Keep the code around; in case
  95. * we need it again. */
  96. #if 0
  97. # a0: load address
  98. # a2: start address of parameter list
  99. # a3: length of parameter list
  100. # a4: __start
  101. /* copy the parameter list out of the way */
  102. movi a6, _param_start
  103. add a3, a2, a3
  104. 2:
  105. l32i a8, a2, 0
  106. s32i a8, a6, 0
  107. addi a2, a2, 4
  108. addi a6, a6, 4
  109. blt a2, a3, 2b
  110. #endif
  111. /* clear BSS section */
  112. movi a6, __bss_start
  113. movi a7, __bss_end
  114. movi.n a5, 0
  115. 3:
  116. s32i a5, a6, 0
  117. addi a6, a6, 4
  118. blt a6, a7, 3b
  119. movi a5, -16
  120. movi a1, _stack + STACK_SIZE
  121. and a1, a1, a5
  122. /* Uncompress the kernel */
  123. # a0: load address
  124. # a2: boot parameter
  125. # a4: __start
  126. movi a3, __image_load
  127. sub a4, a3, a4
  128. add a8, a0, a4
  129. # a1 Stack
  130. # a8(a4) Load address of the image
  131. movi a6, _image_start
  132. movi a10, _image_end
  133. movi a7, 0x1000000
  134. sub a11, a10, a6
  135. movi a9, complen
  136. s32i a11, a9, 0
  137. movi a0, 0
  138. # a6 destination
  139. # a7 maximum size of destination
  140. # a8 source
  141. # a9 ptr to length
  142. .extern gunzip
  143. movi a4, gunzip
  144. beqz a4, 1f
  145. callx4 a4
  146. j 2f
  147. # a6 destination start
  148. # a7 maximum size of destination
  149. # a8 source start
  150. # a9 ptr to length
  151. # a10 destination end
  152. 1:
  153. l32i a9, a8, 0
  154. l32i a11, a8, 4
  155. s32i a9, a6, 0
  156. s32i a11, a6, 4
  157. l32i a9, a8, 8
  158. l32i a11, a8, 12
  159. s32i a9, a6, 8
  160. s32i a11, a6, 12
  161. addi a6, a6, 16
  162. addi a8, a8, 16
  163. blt a6, a10, 1b
  164. /* jump to the kernel */
  165. 2:
  166. #if XCHAL_DCACHE_IS_WRITEBACK
  167. dcache_writeback_all a5, a6
  168. #endif
  169. icache_invalidate_all a5, a6
  170. movi a5, __start
  171. movi a3, boot_initrd_start
  172. movi a4, boot_initrd_end
  173. sub a3, a3, a5
  174. sub a4, a4, a5
  175. add a3, a0, a3
  176. add a4, a0, a4
  177. # a2 Boot parameter list
  178. # a3 initrd_start (virtual load address)
  179. # a4 initrd_end (virtual load address)
  180. movi a0, _image_start
  181. jx a0
  182. .align 16
  183. .data
  184. .globl avail_ram
  185. avail_ram:
  186. .long _heap
  187. .globl end_avail
  188. end_avail:
  189. .long _heap + HEAP_SIZE
  190. .comm _stack, STACK_SIZE
  191. .comm _heap, HEAP_SIZE
  192. .globl end_avail
  193. .comm complen, 4
  194. .end literal_prefix