entry.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. #ifndef CONFIG_PREEMPTION
  20. #define resume_kernel restore_all
  21. #else
  22. #define __ret_from_irq ret_from_exception
  23. #endif
  24. .text
  25. .align 5
  26. #ifndef CONFIG_PREEMPTION
  27. FEXPORT(ret_from_exception)
  28. local_irq_disable # preempt stop
  29. b __ret_from_irq
  30. #endif
  31. FEXPORT(ret_from_irq)
  32. LONG_S s0, TI_REGS($28)
  33. FEXPORT(__ret_from_irq)
  34. /*
  35. * We can be coming here from a syscall done in the kernel space,
  36. * e.g. a failed kernel_execve().
  37. */
  38. resume_userspace_check:
  39. LONG_L t0, PT_STATUS(sp) # returning to kernel mode?
  40. andi t0, t0, KU_USER
  41. beqz t0, resume_kernel
  42. resume_userspace:
  43. local_irq_disable # make sure we dont miss an
  44. # interrupt setting need_resched
  45. # between sampling and return
  46. LONG_L a2, TI_FLAGS($28) # current->work
  47. andi t0, a2, _TIF_WORK_MASK # (ignoring syscall_trace)
  48. bnez t0, work_pending
  49. j restore_all
  50. #ifdef CONFIG_PREEMPTION
  51. resume_kernel:
  52. local_irq_disable
  53. lw t0, TI_PRE_COUNT($28)
  54. bnez t0, restore_all
  55. LONG_L t0, TI_FLAGS($28)
  56. andi t1, t0, _TIF_NEED_RESCHED
  57. beqz t1, restore_all
  58. LONG_L t0, PT_STATUS(sp) # Interrupts off?
  59. andi t0, 1
  60. beqz t0, restore_all
  61. PTR_LA ra, restore_all
  62. j preempt_schedule_irq
  63. #endif
  64. FEXPORT(ret_from_kernel_thread)
  65. jal schedule_tail # a0 = struct task_struct *prev
  66. move a0, s1
  67. jal s0
  68. j syscall_exit
  69. FEXPORT(ret_from_fork)
  70. jal schedule_tail # a0 = struct task_struct *prev
  71. FEXPORT(syscall_exit)
  72. #ifdef CONFIG_DEBUG_RSEQ
  73. move a0, sp
  74. jal rseq_syscall
  75. #endif
  76. local_irq_disable # make sure need_resched and
  77. # signals dont change between
  78. # sampling and return
  79. LONG_L a2, TI_FLAGS($28) # current->work
  80. li t0, _TIF_ALLWORK_MASK
  81. and t0, a2, t0
  82. bnez t0, syscall_exit_work
  83. restore_all: # restore full frame
  84. .set noat
  85. RESTORE_TEMP
  86. RESTORE_AT
  87. RESTORE_STATIC
  88. restore_partial: # restore partial frame
  89. #ifdef CONFIG_TRACE_IRQFLAGS
  90. SAVE_STATIC
  91. SAVE_AT
  92. SAVE_TEMP
  93. LONG_L v0, PT_STATUS(sp)
  94. #if defined(CONFIG_CPU_R3000)
  95. and v0, ST0_IEP
  96. #else
  97. and v0, ST0_IE
  98. #endif
  99. beqz v0, 1f
  100. jal trace_hardirqs_on
  101. b 2f
  102. 1: jal trace_hardirqs_off
  103. 2:
  104. RESTORE_TEMP
  105. RESTORE_AT
  106. RESTORE_STATIC
  107. #endif
  108. RESTORE_SOME
  109. RESTORE_SP_AND_RET
  110. .set at
  111. work_pending:
  112. andi t0, a2, _TIF_NEED_RESCHED # a2 is preloaded with TI_FLAGS
  113. beqz t0, work_notifysig
  114. work_resched:
  115. TRACE_IRQS_OFF
  116. jal schedule
  117. local_irq_disable # make sure need_resched and
  118. # signals dont change between
  119. # sampling and return
  120. LONG_L a2, TI_FLAGS($28)
  121. andi t0, a2, _TIF_WORK_MASK # is there any work to be done
  122. # other than syscall tracing?
  123. beqz t0, restore_all
  124. andi t0, a2, _TIF_NEED_RESCHED
  125. bnez t0, work_resched
  126. work_notifysig: # deal with pending signals and
  127. # notify-resume requests
  128. move a0, sp
  129. li a1, 0
  130. jal do_notify_resume # a2 already loaded
  131. j resume_userspace_check
  132. FEXPORT(syscall_exit_partial)
  133. #ifdef CONFIG_DEBUG_RSEQ
  134. move a0, sp
  135. jal rseq_syscall
  136. #endif
  137. local_irq_disable # make sure need_resched doesn't
  138. # change between and return
  139. LONG_L a2, TI_FLAGS($28) # current->work
  140. li t0, _TIF_ALLWORK_MASK
  141. and t0, a2
  142. beqz t0, restore_partial
  143. SAVE_STATIC
  144. syscall_exit_work:
  145. LONG_L t0, PT_STATUS(sp) # returning to kernel mode?
  146. andi t0, t0, KU_USER
  147. beqz t0, resume_kernel
  148. li t0, _TIF_WORK_SYSCALL_EXIT
  149. and t0, a2 # a2 is preloaded with TI_FLAGS
  150. beqz t0, work_pending # trace bit set?
  151. local_irq_enable # could let syscall_trace_leave()
  152. # call schedule() instead
  153. TRACE_IRQS_ON
  154. move a0, sp
  155. jal syscall_trace_leave
  156. b resume_userspace
  157. #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR5) || \
  158. defined(CONFIG_CPU_MIPSR6) || defined(CONFIG_MIPS_MT)
  159. /*
  160. * MIPS32R2 Instruction Hazard Barrier - must be called
  161. *
  162. * For C code use the inline version named instruction_hazard().
  163. */
  164. LEAF(mips_ihb)
  165. .set MIPS_ISA_LEVEL_RAW
  166. jr.hb ra
  167. nop
  168. END(mips_ihb)
  169. #endif /* CONFIG_CPU_MIPSR2 - CONFIG_CPU_MIPSR6 or CONFIG_MIPS_MT */