relocate_kernel_64.S 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * Copyright 2011 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. *
  14. * copy new kernel into place and then call hv_reexec
  15. *
  16. */
  17. #include <linux/linkage.h>
  18. #include <arch/chip.h>
  19. #include <asm/page.h>
  20. #include <hv/hypervisor.h>
  21. #undef RELOCATE_NEW_KERNEL_VERBOSE
  22. STD_ENTRY(relocate_new_kernel)
  23. move r30, r0 /* page list */
  24. move r31, r1 /* address of page we are on */
  25. move r32, r2 /* start address of new kernel */
  26. shrui r1, r1, PAGE_SHIFT
  27. addi r1, r1, 1
  28. shli sp, r1, PAGE_SHIFT
  29. addi sp, sp, -8
  30. /* we now have a stack (whether we need one or not) */
  31. moveli r40, hw2_last(hv_console_putc)
  32. shl16insli r40, r40, hw1(hv_console_putc)
  33. shl16insli r40, r40, hw0(hv_console_putc)
  34. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  35. moveli r0, 'r'
  36. jalr r40
  37. moveli r0, '_'
  38. jalr r40
  39. moveli r0, 'n'
  40. jalr r40
  41. moveli r0, '_'
  42. jalr r40
  43. moveli r0, 'k'
  44. jalr r40
  45. moveli r0, '\n'
  46. jalr r40
  47. #endif
  48. /*
  49. * Throughout this code r30 is pointer to the element of page
  50. * list we are working on.
  51. *
  52. * Normally we get to the next element of the page list by
  53. * incrementing r30 by eight. The exception is if the element
  54. * on the page list is an IND_INDIRECTION in which case we use
  55. * the element with the low bits masked off as the new value
  56. * of r30.
  57. *
  58. * To get this started, we need the value passed to us (which
  59. * will always be an IND_INDIRECTION) in memory somewhere with
  60. * r30 pointing at it. To do that, we push the value passed
  61. * to us on the stack and make r30 point to it.
  62. */
  63. st sp, r30
  64. move r30, sp
  65. addi sp, sp, -16
  66. #if CHIP_HAS_CBOX_HOME_MAP()
  67. /*
  68. * On TILE-GX, we need to flush all tiles' caches, since we may
  69. * have been doing hash-for-home caching there. Note that we
  70. * must do this _after_ we're completely done modifying any memory
  71. * other than our output buffer (which we know is locally cached).
  72. * We want the caches to be fully clean when we do the reexec,
  73. * because the hypervisor is going to do this flush again at that
  74. * point, and we don't want that second flush to overwrite any memory.
  75. */
  76. {
  77. move r0, zero /* cache_pa */
  78. moveli r1, hw2_last(HV_FLUSH_EVICT_L2)
  79. }
  80. {
  81. shl16insli r1, r1, hw1(HV_FLUSH_EVICT_L2)
  82. movei r2, -1 /* cache_cpumask; -1 means all client tiles */
  83. }
  84. {
  85. shl16insli r1, r1, hw0(HV_FLUSH_EVICT_L2) /* cache_control */
  86. move r3, zero /* tlb_va */
  87. }
  88. {
  89. move r4, zero /* tlb_length */
  90. move r5, zero /* tlb_pgsize */
  91. }
  92. {
  93. move r6, zero /* tlb_cpumask */
  94. move r7, zero /* asids */
  95. }
  96. {
  97. moveli r20, hw2_last(hv_flush_remote)
  98. move r8, zero /* asidcount */
  99. }
  100. shl16insli r20, r20, hw1(hv_flush_remote)
  101. shl16insli r20, r20, hw0(hv_flush_remote)
  102. jalr r20
  103. #endif
  104. /* r33 is destination pointer, default to zero */
  105. moveli r33, 0
  106. .Lloop: ld r10, r30
  107. andi r9, r10, 0xf /* low 4 bits tell us what type it is */
  108. xor r10, r10, r9 /* r10 is now value with low 4 bits stripped */
  109. cmpeqi r0, r9, 0x1 /* IND_DESTINATION */
  110. beqzt r0, .Ltry2
  111. move r33, r10
  112. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  113. moveli r0, 'd'
  114. jalr r40
  115. #endif
  116. addi r30, r30, 8
  117. j .Lloop
  118. .Ltry2:
  119. cmpeqi r0, r9, 0x2 /* IND_INDIRECTION */
  120. beqzt r0, .Ltry4
  121. move r30, r10
  122. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  123. moveli r0, 'i'
  124. jalr r40
  125. #endif
  126. j .Lloop
  127. .Ltry4:
  128. cmpeqi r0, r9, 0x4 /* IND_DONE */
  129. beqzt r0, .Ltry8
  130. mf
  131. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  132. moveli r0, 'D'
  133. jalr r40
  134. moveli r0, '\n'
  135. jalr r40
  136. #endif
  137. move r0, r32
  138. moveli r41, hw2_last(hv_reexec)
  139. shl16insli r41, r41, hw1(hv_reexec)
  140. shl16insli r41, r41, hw0(hv_reexec)
  141. jalr r41
  142. /* we should not get here */
  143. moveli r0, '?'
  144. jalr r40
  145. moveli r0, '\n'
  146. jalr r40
  147. j .Lhalt
  148. .Ltry8: cmpeqi r0, r9, 0x8 /* IND_SOURCE */
  149. beqz r0, .Lerr /* unknown type */
  150. /* copy page at r10 to page at r33 */
  151. move r11, r33
  152. moveli r0, hw2_last(PAGE_SIZE)
  153. shl16insli r0, r0, hw1(PAGE_SIZE)
  154. shl16insli r0, r0, hw0(PAGE_SIZE)
  155. add r33, r33, r0
  156. /* copy word at r10 to word at r11 until r11 equals r33 */
  157. /* We know page size must be multiple of 8, so we can unroll
  158. * 8 times safely without any edge case checking.
  159. *
  160. * Issue a flush of the destination every 8 words to avoid
  161. * incoherence when starting the new kernel. (Now this is
  162. * just good paranoia because the hv_reexec call will also
  163. * take care of this.)
  164. */
  165. 1:
  166. { ld r0, r10; addi r10, r10, 8 }
  167. { st r11, r0; addi r11, r11, 8 }
  168. { ld r0, r10; addi r10, r10, 8 }
  169. { st r11, r0; addi r11, r11, 8 }
  170. { ld r0, r10; addi r10, r10, 8 }
  171. { st r11, r0; addi r11, r11, 8 }
  172. { ld r0, r10; addi r10, r10, 8 }
  173. { st r11, r0; addi r11, r11, 8 }
  174. { ld r0, r10; addi r10, r10, 8 }
  175. { st r11, r0; addi r11, r11, 8 }
  176. { ld r0, r10; addi r10, r10, 8 }
  177. { st r11, r0; addi r11, r11, 8 }
  178. { ld r0, r10; addi r10, r10, 8 }
  179. { st r11, r0; addi r11, r11, 8 }
  180. { ld r0, r10; addi r10, r10, 8 }
  181. { st r11, r0 }
  182. { flush r11 ; addi r11, r11, 8 }
  183. cmpeq r0, r33, r11
  184. beqzt r0, 1b
  185. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  186. moveli r0, 's'
  187. jalr r40
  188. #endif
  189. addi r30, r30, 8
  190. j .Lloop
  191. .Lerr: moveli r0, 'e'
  192. jalr r40
  193. moveli r0, 'r'
  194. jalr r40
  195. moveli r0, 'r'
  196. jalr r40
  197. moveli r0, '\n'
  198. jalr r40
  199. .Lhalt:
  200. moveli r41, hw2_last(hv_halt)
  201. shl16insli r41, r41, hw1(hv_halt)
  202. shl16insli r41, r41, hw0(hv_halt)
  203. jalr r41
  204. STD_ENDPROC(relocate_new_kernel)
  205. .section .rodata,"a"
  206. .globl relocate_new_kernel_size
  207. relocate_new_kernel_size:
  208. .long .Lend_relocate_new_kernel - relocate_new_kernel