entry.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. LONG_L a2, TI_FLAGS($28) # current->work
  48. andi t0, a2, _TIF_WORK_MASK # (ignoring syscall_trace)
  49. bnez t0, work_pending
  50. j restore_all
  51. #ifdef CONFIG_PREEMPT
  52. resume_kernel:
  53. local_irq_disable
  54. lw t0, TI_PRE_COUNT($28)
  55. bnez t0, restore_all
  56. need_resched:
  57. LONG_L t0, TI_FLAGS($28)
  58. andi t1, t0, _TIF_NEED_RESCHED
  59. beqz t1, restore_all
  60. LONG_L t0, PT_STATUS(sp) # Interrupts off?
  61. andi t0, 1
  62. beqz t0, restore_all
  63. jal preempt_schedule_irq
  64. b need_resched
  65. #endif
  66. FEXPORT(ret_from_kernel_thread)
  67. jal schedule_tail # a0 = struct task_struct *prev
  68. move a0, s1
  69. jal s0
  70. j syscall_exit
  71. FEXPORT(ret_from_fork)
  72. jal schedule_tail # a0 = struct task_struct *prev
  73. FEXPORT(syscall_exit)
  74. #ifdef CONFIG_DEBUG_RSEQ
  75. move a0, sp
  76. jal rseq_syscall
  77. #endif
  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. work_pending:
  114. andi t0, a2, _TIF_NEED_RESCHED # a2 is preloaded with TI_FLAGS
  115. beqz t0, work_notifysig
  116. work_resched:
  117. TRACE_IRQS_OFF
  118. jal schedule
  119. local_irq_disable # make sure need_resched and
  120. # signals dont change between
  121. # sampling and return
  122. LONG_L a2, TI_FLAGS($28)
  123. andi t0, a2, _TIF_WORK_MASK # is there any work to be done
  124. # other than syscall tracing?
  125. beqz t0, restore_all
  126. andi t0, a2, _TIF_NEED_RESCHED
  127. bnez t0, work_resched
  128. work_notifysig: # deal with pending signals and
  129. # notify-resume requests
  130. move a0, sp
  131. li a1, 0
  132. jal do_notify_resume # a2 already loaded
  133. j resume_userspace_check
  134. FEXPORT(syscall_exit_partial)
  135. #ifdef CONFIG_DEBUG_RSEQ
  136. move a0, sp
  137. jal rseq_syscall
  138. #endif
  139. local_irq_disable # make sure need_resched doesn't
  140. # change between and return
  141. LONG_L a2, TI_FLAGS($28) # current->work
  142. li t0, _TIF_ALLWORK_MASK
  143. and t0, a2
  144. beqz t0, restore_partial
  145. SAVE_STATIC
  146. syscall_exit_work:
  147. LONG_L t0, PT_STATUS(sp) # returning to kernel mode?
  148. andi t0, t0, KU_USER
  149. beqz t0, resume_kernel
  150. li t0, _TIF_WORK_SYSCALL_EXIT
  151. and t0, a2 # a2 is preloaded with TI_FLAGS
  152. beqz t0, work_pending # trace bit set?
  153. local_irq_enable # could let syscall_trace_leave()
  154. # call schedule() instead
  155. TRACE_IRQS_ON
  156. move a0, sp
  157. jal syscall_trace_leave
  158. b resume_userspace
  159. #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) || \
  160. defined(CONFIG_MIPS_MT)
  161. /*
  162. * MIPS32R2 Instruction Hazard Barrier - must be called
  163. *
  164. * For C code use the inline version named instruction_hazard().
  165. */
  166. LEAF(mips_ihb)
  167. .set MIPS_ISA_LEVEL_RAW
  168. jr.hb ra
  169. nop
  170. END(mips_ihb)
  171. #endif /* CONFIG_CPU_MIPSR2 or CONFIG_CPU_MIPSR6 or CONFIG_MIPS_MT */