relocate_kernel.S 3.7 KB

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