relocate_kernel.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * relocate_kernel.S for kexec
  4. * Created by <nschichan@corp.free.fr> 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. done:
  60. #ifdef CONFIG_SMP
  61. /* kexec_flag reset is signal to other CPUs what kernel
  62. was moved to its location. Note - we need relocated address
  63. of kexec_flag. */
  64. bal 1f
  65. 1: move t1,ra;
  66. PTR_LA t2,1b
  67. PTR_LA t0,kexec_flag
  68. PTR_SUB t0,t0,t2;
  69. PTR_ADD t0,t1,t0;
  70. LONG_S zero,(t0)
  71. #endif
  72. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  73. /* We need to flush I-cache before jumping to new kernel.
  74. * Unfortunately, this code is cpu-specific.
  75. */
  76. .set push
  77. .set noreorder
  78. syncw
  79. syncw
  80. synci 0($0)
  81. .set pop
  82. #else
  83. sync
  84. #endif
  85. /* jump to kexec_start_address */
  86. j s1
  87. END(relocate_new_kernel)
  88. #ifdef CONFIG_SMP
  89. /*
  90. * Other CPUs should wait until code is relocated and
  91. * then start at entry (?) point.
  92. */
  93. LEAF(kexec_smp_wait)
  94. PTR_L a0, s_arg0
  95. PTR_L a1, s_arg1
  96. PTR_L a2, s_arg2
  97. PTR_L a3, s_arg3
  98. PTR_L s1, kexec_start_address
  99. /* Non-relocated address works for args and kexec_start_address ( old
  100. * kernel is not overwritten). But we need relocated address of
  101. * kexec_flag.
  102. */
  103. bal 1f
  104. 1: move t1,ra;
  105. PTR_LA t2,1b
  106. PTR_LA t0,kexec_flag
  107. PTR_SUB t0,t0,t2;
  108. PTR_ADD t0,t1,t0;
  109. 1: LONG_L s0, (t0)
  110. bne s0, zero,1b
  111. #ifdef USE_KEXEC_SMP_WAIT_FINAL
  112. kexec_smp_wait_final
  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 used to prepare register values.
  125. */
  126. EXPORT(kexec_args)
  127. arg0: PTR_WD 0x0
  128. arg1: PTR_WD 0x0
  129. arg2: PTR_WD 0x0
  130. arg3: PTR_WD 0x0
  131. .size kexec_args,PTRSIZE*4
  132. #ifdef CONFIG_SMP
  133. /*
  134. * Secondary CPUs may have different kernel parameters in
  135. * their registers a0-a3. secondary_kexec_args[0..3] are used
  136. * to prepare register values.
  137. */
  138. EXPORT(secondary_kexec_args)
  139. s_arg0: PTR_WD 0x0
  140. s_arg1: PTR_WD 0x0
  141. s_arg2: PTR_WD 0x0
  142. s_arg3: PTR_WD 0x0
  143. .size secondary_kexec_args,PTRSIZE*4
  144. kexec_flag:
  145. LONG 0x1
  146. #endif
  147. EXPORT(kexec_start_address)
  148. PTR_WD 0x0
  149. .size kexec_start_address, PTRSIZE
  150. EXPORT(kexec_indirection_page)
  151. PTR_WD 0
  152. .size kexec_indirection_page, PTRSIZE
  153. relocate_new_kernel_end:
  154. EXPORT(relocate_new_kernel_size)
  155. PTR_WD relocate_new_kernel_end - relocate_new_kernel
  156. .size relocate_new_kernel_size, PTRSIZE