relocate_kernel_32.S 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * Copyright 2010 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. shri 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, lo16(hv_console_putc)
  32. auli r40, r40, ha16(hv_console_putc)
  33. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  34. moveli r0, 'r'
  35. jalr r40
  36. moveli r0, '_'
  37. jalr r40
  38. moveli r0, 'n'
  39. jalr r40
  40. moveli r0, '_'
  41. jalr r40
  42. moveli r0, 'k'
  43. jalr r40
  44. moveli r0, '\n'
  45. jalr r40
  46. #endif
  47. /*
  48. * Throughout this code r30 is pointer to the element of page
  49. * list we are working on.
  50. *
  51. * Normally we get to the next element of the page list by
  52. * incrementing r30 by four. The exception is if the element
  53. * on the page list is an IND_INDIRECTION in which case we use
  54. * the element with the low bits masked off as the new value
  55. * of r30.
  56. *
  57. * To get this started, we need the value passed to us (which
  58. * will always be an IND_INDIRECTION) in memory somewhere with
  59. * r30 pointing at it. To do that, we push the value passed
  60. * to us on the stack and make r30 point to it.
  61. */
  62. sw sp, r30
  63. move r30, sp
  64. addi sp, sp, -8
  65. /*
  66. * On TILEPro, we need to flush all tiles' caches, since we may
  67. * have been doing hash-for-home caching there. Note that we
  68. * must do this _after_ we're completely done modifying any memory
  69. * other than our output buffer (which we know is locally cached).
  70. * We want the caches to be fully clean when we do the reexec,
  71. * because the hypervisor is going to do this flush again at that
  72. * point, and we don't want that second flush to overwrite any memory.
  73. */
  74. {
  75. move r0, zero /* cache_pa */
  76. move r1, zero
  77. }
  78. {
  79. auli r2, zero, ha16(HV_FLUSH_EVICT_L2) /* cache_control */
  80. movei r3, -1 /* cache_cpumask; -1 means all client tiles */
  81. }
  82. {
  83. move r4, zero /* tlb_va */
  84. move r5, zero /* tlb_length */
  85. }
  86. {
  87. move r6, zero /* tlb_pgsize */
  88. move r7, zero /* tlb_cpumask */
  89. }
  90. {
  91. move r8, zero /* asids */
  92. moveli r20, lo16(hv_flush_remote)
  93. }
  94. {
  95. move r9, zero /* asidcount */
  96. auli r20, r20, ha16(hv_flush_remote)
  97. }
  98. jalr r20
  99. /* r33 is destination pointer, default to zero */
  100. moveli r33, 0
  101. .Lloop: lw r10, r30
  102. andi r9, r10, 0xf /* low 4 bits tell us what type it is */
  103. xor r10, r10, r9 /* r10 is now value with low 4 bits stripped */
  104. seqi r0, r9, 0x1 /* IND_DESTINATION */
  105. bzt r0, .Ltry2
  106. move r33, r10
  107. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  108. moveli r0, 'd'
  109. jalr r40
  110. #endif
  111. addi r30, r30, 4
  112. j .Lloop
  113. .Ltry2:
  114. seqi r0, r9, 0x2 /* IND_INDIRECTION */
  115. bzt r0, .Ltry4
  116. move r30, r10
  117. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  118. moveli r0, 'i'
  119. jalr r40
  120. #endif
  121. j .Lloop
  122. .Ltry4:
  123. seqi r0, r9, 0x4 /* IND_DONE */
  124. bzt r0, .Ltry8
  125. mf
  126. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  127. moveli r0, 'D'
  128. jalr r40
  129. moveli r0, '\n'
  130. jalr r40
  131. #endif
  132. move r0, r32
  133. moveli r1, 0 /* arg to hv_reexec is 64 bits */
  134. moveli r41, lo16(hv_reexec)
  135. auli r41, r41, ha16(hv_reexec)
  136. jalr r41
  137. /* we should not get here */
  138. moveli r0, '?'
  139. jalr r40
  140. moveli r0, '\n'
  141. jalr r40
  142. j .Lhalt
  143. .Ltry8: seqi r0, r9, 0x8 /* IND_SOURCE */
  144. bz r0, .Lerr /* unknown type */
  145. /* copy page at r10 to page at r33 */
  146. move r11, r33
  147. moveli r0, lo16(PAGE_SIZE)
  148. auli r0, r0, ha16(PAGE_SIZE)
  149. add r33, r33, r0
  150. /* copy word at r10 to word at r11 until r11 equals r33 */
  151. /* We know page size must be multiple of 16, so we can unroll
  152. * 16 times safely without any edge case checking.
  153. *
  154. * Issue a flush of the destination every 16 words to avoid
  155. * incoherence when starting the new kernel. (Now this is
  156. * just good paranoia because the hv_reexec call will also
  157. * take care of this.)
  158. */
  159. 1:
  160. { lw r0, r10; addi r10, r10, 4 }
  161. { sw r11, r0; addi r11, r11, 4 }
  162. { lw r0, r10; addi r10, r10, 4 }
  163. { sw r11, r0; addi r11, r11, 4 }
  164. { lw r0, r10; addi r10, r10, 4 }
  165. { sw r11, r0; addi r11, r11, 4 }
  166. { lw r0, r10; addi r10, r10, 4 }
  167. { sw r11, r0; addi r11, r11, 4 }
  168. { lw r0, r10; addi r10, r10, 4 }
  169. { sw r11, r0; addi r11, r11, 4 }
  170. { lw r0, r10; addi r10, r10, 4 }
  171. { sw r11, r0; addi r11, r11, 4 }
  172. { lw r0, r10; addi r10, r10, 4 }
  173. { sw r11, r0; addi r11, r11, 4 }
  174. { lw r0, r10; addi r10, r10, 4 }
  175. { sw r11, r0; addi r11, r11, 4 }
  176. { lw r0, r10; addi r10, r10, 4 }
  177. { sw r11, r0; addi r11, r11, 4 }
  178. { lw r0, r10; addi r10, r10, 4 }
  179. { sw r11, r0; addi r11, r11, 4 }
  180. { lw r0, r10; addi r10, r10, 4 }
  181. { sw r11, r0; addi r11, r11, 4 }
  182. { lw r0, r10; addi r10, r10, 4 }
  183. { sw r11, r0; addi r11, r11, 4 }
  184. { lw r0, r10; addi r10, r10, 4 }
  185. { sw r11, r0; addi r11, r11, 4 }
  186. { lw r0, r10; addi r10, r10, 4 }
  187. { sw r11, r0; addi r11, r11, 4 }
  188. { lw r0, r10; addi r10, r10, 4 }
  189. { sw r11, r0; addi r11, r11, 4 }
  190. { lw r0, r10; addi r10, r10, 4 }
  191. { sw r11, r0 }
  192. { flush r11 ; addi r11, r11, 4 }
  193. seq r0, r33, r11
  194. bzt r0, 1b
  195. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  196. moveli r0, 's'
  197. jalr r40
  198. #endif
  199. addi r30, r30, 4
  200. j .Lloop
  201. .Lerr: moveli r0, 'e'
  202. jalr r40
  203. moveli r0, 'r'
  204. jalr r40
  205. moveli r0, 'r'
  206. jalr r40
  207. moveli r0, '\n'
  208. jalr r40
  209. .Lhalt:
  210. moveli r41, lo16(hv_halt)
  211. auli r41, r41, ha16(hv_halt)
  212. jalr r41
  213. STD_ENDPROC(relocate_new_kernel)
  214. .section .rodata,"a"
  215. .globl relocate_new_kernel_size
  216. relocate_new_kernel_size:
  217. .long .Lend_relocate_new_kernel - relocate_new_kernel