relocate_kernel_32.S 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. #if CHIP_HAS_CBOX_HOME_MAP()
  66. /*
  67. * On TILEPro, 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. move r1, zero
  78. }
  79. {
  80. auli r2, zero, ha16(HV_FLUSH_EVICT_L2) /* cache_control */
  81. movei r3, -1 /* cache_cpumask; -1 means all client tiles */
  82. }
  83. {
  84. move r4, zero /* tlb_va */
  85. move r5, zero /* tlb_length */
  86. }
  87. {
  88. move r6, zero /* tlb_pgsize */
  89. move r7, zero /* tlb_cpumask */
  90. }
  91. {
  92. move r8, zero /* asids */
  93. moveli r20, lo16(hv_flush_remote)
  94. }
  95. {
  96. move r9, zero /* asidcount */
  97. auli r20, r20, ha16(hv_flush_remote)
  98. }
  99. jalr r20
  100. #endif
  101. /* r33 is destination pointer, default to zero */
  102. moveli r33, 0
  103. .Lloop: lw r10, r30
  104. andi r9, r10, 0xf /* low 4 bits tell us what type it is */
  105. xor r10, r10, r9 /* r10 is now value with low 4 bits stripped */
  106. seqi r0, r9, 0x1 /* IND_DESTINATION */
  107. bzt r0, .Ltry2
  108. move r33, r10
  109. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  110. moveli r0, 'd'
  111. jalr r40
  112. #endif
  113. addi r30, r30, 4
  114. j .Lloop
  115. .Ltry2:
  116. seqi r0, r9, 0x2 /* IND_INDIRECTION */
  117. bzt r0, .Ltry4
  118. move r30, r10
  119. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  120. moveli r0, 'i'
  121. jalr r40
  122. #endif
  123. j .Lloop
  124. .Ltry4:
  125. seqi r0, r9, 0x4 /* IND_DONE */
  126. bzt r0, .Ltry8
  127. mf
  128. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  129. moveli r0, 'D'
  130. jalr r40
  131. moveli r0, '\n'
  132. jalr r40
  133. #endif
  134. move r0, r32
  135. moveli r1, 0 /* arg to hv_reexec is 64 bits */
  136. moveli r41, lo16(hv_reexec)
  137. auli r41, r41, ha16(hv_reexec)
  138. jalr r41
  139. /* we should not get here */
  140. moveli r0, '?'
  141. jalr r40
  142. moveli r0, '\n'
  143. jalr r40
  144. j .Lhalt
  145. .Ltry8: seqi r0, r9, 0x8 /* IND_SOURCE */
  146. bz r0, .Lerr /* unknown type */
  147. /* copy page at r10 to page at r33 */
  148. move r11, r33
  149. moveli r0, lo16(PAGE_SIZE)
  150. auli r0, r0, ha16(PAGE_SIZE)
  151. add r33, r33, r0
  152. /* copy word at r10 to word at r11 until r11 equals r33 */
  153. /* We know page size must be multiple of 16, so we can unroll
  154. * 16 times safely without any edge case checking.
  155. *
  156. * Issue a flush of the destination every 16 words to avoid
  157. * incoherence when starting the new kernel. (Now this is
  158. * just good paranoia because the hv_reexec call will also
  159. * take care of this.)
  160. */
  161. 1:
  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; addi r11, r11, 4 }
  192. { lw r0, r10; addi r10, r10, 4 }
  193. { sw r11, r0 }
  194. { flush r11 ; addi r11, r11, 4 }
  195. seq r0, r33, r11
  196. bzt r0, 1b
  197. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  198. moveli r0, 's'
  199. jalr r40
  200. #endif
  201. addi r30, r30, 4
  202. j .Lloop
  203. .Lerr: moveli r0, 'e'
  204. jalr r40
  205. moveli r0, 'r'
  206. jalr r40
  207. moveli r0, 'r'
  208. jalr r40
  209. moveli r0, '\n'
  210. jalr r40
  211. .Lhalt:
  212. moveli r41, lo16(hv_halt)
  213. auli r41, r41, ha16(hv_halt)
  214. jalr r41
  215. STD_ENDPROC(relocate_new_kernel)
  216. .section .rodata,"a"
  217. .globl relocate_new_kernel_size
  218. relocate_new_kernel_size:
  219. .long .Lend_relocate_new_kernel - relocate_new_kernel