entry.S 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994 - 2000, 2001, 2003 Ralf Baechle
  7. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  8. * Copyright (C) 2001 MIPS Technologies, Inc.
  9. */
  10. #include <asm/asm.h>
  11. #include <asm/asmmacro.h>
  12. #include <asm/compiler.h>
  13. #include <asm/irqflags.h>
  14. #include <asm/regdef.h>
  15. #include <asm/mipsregs.h>
  16. #include <asm/stackframe.h>
  17. #include <asm/isadep.h>
  18. #include <asm/thread_info.h>
  19. #include <asm/war.h>
  20. #ifndef CONFIG_PREEMPT
  21. #define resume_kernel restore_all
  22. #else
  23. #define __ret_from_irq ret_from_exception
  24. #endif
  25. .text
  26. .align 5
  27. #ifndef CONFIG_PREEMPT
  28. FEXPORT(ret_from_exception)
  29. local_irq_disable # preempt stop
  30. b __ret_from_irq
  31. #endif
  32. FEXPORT(ret_from_irq)
  33. LONG_S s0, TI_REGS($28)
  34. FEXPORT(__ret_from_irq)
  35. /*
  36. * We can be coming here from a syscall done in the kernel space,
  37. * e.g. a failed kernel_execve().
  38. */
  39. resume_userspace_check:
  40. LONG_L t0, PT_STATUS(sp) # returning to kernel mode?
  41. andi t0, t0, KU_USER
  42. beqz t0, resume_kernel
  43. resume_userspace:
  44. local_irq_disable # make sure we dont miss an
  45. # interrupt setting need_resched
  46. # between sampling and return
  47. #ifdef CONFIG_MIPSR2_TO_R6_EMULATOR
  48. lw k0, TI_R2_EMUL_RET($28)
  49. bnez k0, restore_all_from_r2_emul
  50. #endif
  51. LONG_L a2, TI_FLAGS($28) # current->work
  52. andi t0, a2, _TIF_WORK_MASK # (ignoring syscall_trace)
  53. bnez t0, work_pending
  54. j restore_all
  55. #ifdef CONFIG_PREEMPT
  56. resume_kernel:
  57. local_irq_disable
  58. lw t0, TI_PRE_COUNT($28)
  59. bnez t0, restore_all
  60. need_resched:
  61. LONG_L t0, TI_FLAGS($28)
  62. andi t1, t0, _TIF_NEED_RESCHED
  63. beqz t1, restore_all
  64. LONG_L t0, PT_STATUS(sp) # Interrupts off?
  65. andi t0, 1
  66. beqz t0, restore_all
  67. jal preempt_schedule_irq
  68. b need_resched
  69. #endif
  70. FEXPORT(ret_from_kernel_thread)
  71. jal schedule_tail # a0 = struct task_struct *prev
  72. move a0, s1
  73. jal s0
  74. j syscall_exit
  75. FEXPORT(ret_from_fork)
  76. jal schedule_tail # a0 = struct task_struct *prev
  77. FEXPORT(syscall_exit)
  78. local_irq_disable # make sure need_resched and
  79. # signals dont change between
  80. # sampling and return
  81. LONG_L a2, TI_FLAGS($28) # current->work
  82. li t0, _TIF_ALLWORK_MASK
  83. and t0, a2, t0
  84. bnez t0, syscall_exit_work
  85. restore_all: # restore full frame
  86. .set noat
  87. RESTORE_TEMP
  88. RESTORE_AT
  89. RESTORE_STATIC
  90. restore_partial: # restore partial frame
  91. #ifdef CONFIG_TRACE_IRQFLAGS
  92. SAVE_STATIC
  93. SAVE_AT
  94. SAVE_TEMP
  95. LONG_L v0, PT_STATUS(sp)
  96. #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  97. and v0, ST0_IEP
  98. #else
  99. and v0, ST0_IE
  100. #endif
  101. beqz v0, 1f
  102. jal trace_hardirqs_on
  103. b 2f
  104. 1: jal trace_hardirqs_off
  105. 2:
  106. RESTORE_TEMP
  107. RESTORE_AT
  108. RESTORE_STATIC
  109. #endif
  110. RESTORE_SOME
  111. RESTORE_SP_AND_RET
  112. .set at
  113. #ifdef CONFIG_MIPSR2_TO_R6_EMULATOR
  114. restore_all_from_r2_emul: # restore full frame
  115. .set noat
  116. sw zero, TI_R2_EMUL_RET($28) # reset it
  117. RESTORE_TEMP
  118. RESTORE_AT
  119. RESTORE_STATIC
  120. RESTORE_SOME
  121. LONG_L sp, PT_R29(sp)
  122. eretnc
  123. .set at
  124. #endif
  125. work_pending:
  126. andi t0, a2, _TIF_NEED_RESCHED # a2 is preloaded with TI_FLAGS
  127. beqz t0, work_notifysig
  128. work_resched:
  129. TRACE_IRQS_OFF
  130. jal schedule
  131. local_irq_disable # make sure need_resched and
  132. # signals dont change between
  133. # sampling and return
  134. LONG_L a2, TI_FLAGS($28)
  135. andi t0, a2, _TIF_WORK_MASK # is there any work to be done
  136. # other than syscall tracing?
  137. beqz t0, restore_all
  138. andi t0, a2, _TIF_NEED_RESCHED
  139. bnez t0, work_resched
  140. work_notifysig: # deal with pending signals and
  141. # notify-resume requests
  142. move a0, sp
  143. li a1, 0
  144. jal do_notify_resume # a2 already loaded
  145. j resume_userspace_check
  146. FEXPORT(syscall_exit_partial)
  147. local_irq_disable # make sure need_resched doesn't
  148. # change between and return
  149. LONG_L a2, TI_FLAGS($28) # current->work
  150. li t0, _TIF_ALLWORK_MASK
  151. and t0, a2
  152. beqz t0, restore_partial
  153. SAVE_STATIC
  154. syscall_exit_work:
  155. LONG_L t0, PT_STATUS(sp) # returning to kernel mode?
  156. andi t0, t0, KU_USER
  157. beqz t0, resume_kernel
  158. li t0, _TIF_WORK_SYSCALL_EXIT
  159. and t0, a2 # a2 is preloaded with TI_FLAGS
  160. beqz t0, work_pending # trace bit set?
  161. local_irq_enable # could let syscall_trace_leave()
  162. # call schedule() instead
  163. TRACE_IRQS_ON
  164. move a0, sp
  165. jal syscall_trace_leave
  166. b resume_userspace
  167. #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) || \
  168. defined(CONFIG_MIPS_MT)
  169. /*
  170. * MIPS32R2 Instruction Hazard Barrier - must be called
  171. *
  172. * For C code use the inline version named instruction_hazard().
  173. */
  174. LEAF(mips_ihb)
  175. .set MIPS_ISA_LEVEL_RAW
  176. jr.hb ra
  177. nop
  178. END(mips_ihb)
  179. #endif /* CONFIG_CPU_MIPSR2 or CONFIG_CPU_MIPSR6 or CONFIG_MIPS_MT */