relocate_kernel.S 3.5 KB

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