relocate_kernel_64.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  32. moveli r40, hw2_last(hv_console_putc)
  33. shl16insli r40, r40, hw1(hv_console_putc)
  34. shl16insli r40, r40, hw0(hv_console_putc)
  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. /*
  67. * On TILE-GX, we need to flush all tiles' caches, since we may
  68. * have been doing hash-for-home caching there. Note that we
  69. * must do this _after_ we're completely done modifying any memory
  70. * other than our output buffer (which we know is locally cached).
  71. * We want the caches to be fully clean when we do the reexec,
  72. * because the hypervisor is going to do this flush again at that
  73. * point, and we don't want that second flush to overwrite any memory.
  74. */
  75. {
  76. move r0, zero /* cache_pa */
  77. moveli r1, hw2_last(HV_FLUSH_EVICT_L2)
  78. }
  79. {
  80. shl16insli r1, r1, hw1(HV_FLUSH_EVICT_L2)
  81. movei r2, -1 /* cache_cpumask; -1 means all client tiles */
  82. }
  83. {
  84. shl16insli r1, r1, hw0(HV_FLUSH_EVICT_L2) /* cache_control */
  85. move r3, zero /* tlb_va */
  86. }
  87. {
  88. move r4, zero /* tlb_length */
  89. move r5, zero /* tlb_pgsize */
  90. }
  91. {
  92. move r6, zero /* tlb_cpumask */
  93. move r7, zero /* asids */
  94. }
  95. {
  96. moveli r20, hw2_last(hv_flush_remote)
  97. move r8, zero /* asidcount */
  98. }
  99. shl16insli r20, r20, hw1(hv_flush_remote)
  100. shl16insli r20, r20, hw0(hv_flush_remote)
  101. jalr r20
  102. /* r33 is destination pointer, default to zero */
  103. moveli r33, 0
  104. .Lloop: ld r10, r30
  105. andi r9, r10, 0xf /* low 4 bits tell us what type it is */
  106. xor r10, r10, r9 /* r10 is now value with low 4 bits stripped */
  107. cmpeqi r0, r9, 0x1 /* IND_DESTINATION */
  108. beqzt r0, .Ltry2
  109. move r33, r10
  110. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  111. moveli r0, 'd'
  112. jalr r40
  113. #endif
  114. addi r30, r30, 8
  115. j .Lloop
  116. .Ltry2:
  117. cmpeqi r0, r9, 0x2 /* IND_INDIRECTION */
  118. beqzt r0, .Ltry4
  119. move r30, r10
  120. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  121. moveli r0, 'i'
  122. jalr r40
  123. #endif
  124. j .Lloop
  125. .Ltry4:
  126. cmpeqi r0, r9, 0x4 /* IND_DONE */
  127. beqzt r0, .Ltry8
  128. mf
  129. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  130. moveli r0, 'D'
  131. jalr r40
  132. moveli r0, '\n'
  133. jalr r40
  134. #endif
  135. move r0, r32
  136. moveli r41, hw2_last(hv_reexec)
  137. shl16insli r41, r41, hw1(hv_reexec)
  138. shl16insli r41, r41, hw0(hv_reexec)
  139. jalr r41
  140. /* we should not get here */
  141. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  142. moveli r0, '?'
  143. jalr r40
  144. moveli r0, '\n'
  145. jalr r40
  146. #endif
  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:
  192. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  193. moveli r0, 'e'
  194. jalr r40
  195. moveli r0, 'r'
  196. jalr r40
  197. moveli r0, 'r'
  198. jalr r40
  199. moveli r0, '\n'
  200. jalr r40
  201. #endif
  202. .Lhalt:
  203. moveli r41, hw2_last(hv_halt)
  204. shl16insli r41, r41, hw1(hv_halt)
  205. shl16insli r41, r41, hw0(hv_halt)
  206. jalr r41
  207. STD_ENDPROC(relocate_new_kernel)
  208. .section .rodata,"a"
  209. .globl relocate_new_kernel_size
  210. relocate_new_kernel_size:
  211. .long .Lend_relocate_new_kernel - relocate_new_kernel