relocate_kernel.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * relocate_kernel.S for kexec
  3. * Created by <nschichan@corp.free.fr> on Thu Oct 12 17:49:57 2006
  4. *
  5. * This source code is licensed under the GNU General Public License,
  6. * Version 2. See the file COPYING for more details.
  7. */
  8. #include <asm/asm.h>
  9. #include <asm/asmmacro.h>
  10. #include <asm/regdef.h>
  11. #include <asm/mipsregs.h>
  12. #include <asm/stackframe.h>
  13. #include <asm/addrspace.h>
  14. LEAF(relocate_new_kernel)
  15. PTR_L a0, arg0
  16. PTR_L a1, arg1
  17. PTR_L a2, arg2
  18. PTR_L a3, arg3
  19. PTR_L s0, kexec_indirection_page
  20. PTR_L s1, kexec_start_address
  21. process_entry:
  22. PTR_L s2, (s0)
  23. PTR_ADD s0, s0, SZREG
  24. /* destination page */
  25. and s3, s2, 0x1
  26. beq s3, zero, 1f
  27. and s4, s2, ~0x1 /* store destination addr in s4 */
  28. b process_entry
  29. 1:
  30. /* indirection page, update s0 */
  31. and s3, s2, 0x2
  32. beq s3, zero, 1f
  33. and s0, s2, ~0x2
  34. b process_entry
  35. 1:
  36. /* done page */
  37. and s3, s2, 0x4
  38. beq s3, zero, 1f
  39. b done
  40. 1:
  41. /* source page */
  42. and s3, s2, 0x8
  43. beq s3, zero, process_entry
  44. and s2, s2, ~0x8
  45. li s6, (1 << _PAGE_SHIFT) / SZREG
  46. copy_word:
  47. /* copy page word by word */
  48. REG_L s5, (s2)
  49. REG_S s5, (s4)
  50. PTR_ADD s4, s4, SZREG
  51. PTR_ADD s2, s2, SZREG
  52. LONG_SUB s6, s6, 1
  53. beq s6, zero, process_entry
  54. b copy_word
  55. b process_entry
  56. done:
  57. #ifdef CONFIG_SMP
  58. /* kexec_flag reset is signal to other CPUs what kernel
  59. was moved to it's location. Note - we need relocated address
  60. of kexec_flag. */
  61. bal 1f
  62. 1: move t1,ra;
  63. PTR_LA t2,1b
  64. PTR_LA t0,kexec_flag
  65. PTR_SUB t0,t0,t2;
  66. PTR_ADD t0,t1,t0;
  67. LONG_S zero,(t0)
  68. #endif
  69. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  70. /* We need to flush I-cache before jumping to new kernel.
  71. * Unfortunatelly, this code is cpu-specific.
  72. */
  73. .set push
  74. .set noreorder
  75. syncw
  76. syncw
  77. synci 0($0)
  78. .set pop
  79. #else
  80. sync
  81. #endif
  82. /* jump to kexec_start_address */
  83. j s1
  84. END(relocate_new_kernel)
  85. #ifdef CONFIG_SMP
  86. /*
  87. * Other CPUs should wait until code is relocated and
  88. * then start at entry (?) point.
  89. */
  90. LEAF(kexec_smp_wait)
  91. PTR_L a0, s_arg0
  92. PTR_L a1, s_arg1
  93. PTR_L a2, s_arg2
  94. PTR_L a3, s_arg3
  95. PTR_L s1, kexec_start_address
  96. /* Non-relocated address works for args and kexec_start_address ( old
  97. * kernel is not overwritten). But we need relocated address of
  98. * kexec_flag.
  99. */
  100. bal 1f
  101. 1: move t1,ra;
  102. PTR_LA t2,1b
  103. PTR_LA t0,kexec_flag
  104. PTR_SUB t0,t0,t2;
  105. PTR_ADD t0,t1,t0;
  106. 1: LONG_L s0, (t0)
  107. bne s0, zero,1b
  108. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  109. .set push
  110. .set noreorder
  111. synci 0($0)
  112. .set pop
  113. #else
  114. sync
  115. #endif
  116. j s1
  117. END(kexec_smp_wait)
  118. #endif
  119. #ifdef __mips64
  120. /* all PTR's must be aligned to 8 byte in 64-bit mode */
  121. .align 3
  122. #endif
  123. /* All parameters to new kernel are passed in registers a0-a3.
  124. * kexec_args[0..3] are uses to prepare register values.
  125. */
  126. kexec_args:
  127. EXPORT(kexec_args)
  128. arg0: PTR 0x0
  129. arg1: PTR 0x0
  130. arg2: PTR 0x0
  131. arg3: PTR 0x0
  132. .size kexec_args,PTRSIZE*4
  133. #ifdef CONFIG_SMP
  134. /*
  135. * Secondary CPUs may have different kernel parameters in
  136. * their registers a0-a3. secondary_kexec_args[0..3] are used
  137. * to prepare register values.
  138. */
  139. secondary_kexec_args:
  140. EXPORT(secondary_kexec_args)
  141. s_arg0: PTR 0x0
  142. s_arg1: PTR 0x0
  143. s_arg2: PTR 0x0
  144. s_arg3: PTR 0x0
  145. .size secondary_kexec_args,PTRSIZE*4
  146. kexec_flag:
  147. LONG 0x1
  148. #endif
  149. kexec_start_address:
  150. EXPORT(kexec_start_address)
  151. PTR 0x0
  152. .size kexec_start_address, PTRSIZE
  153. kexec_indirection_page:
  154. EXPORT(kexec_indirection_page)
  155. PTR 0
  156. .size kexec_indirection_page, PTRSIZE
  157. relocate_new_kernel_end:
  158. relocate_new_kernel_size:
  159. EXPORT(relocate_new_kernel_size)
  160. PTR relocate_new_kernel_end - relocate_new_kernel
  161. .size relocate_new_kernel_size, PTRSIZE