entry.S 4.1 KB

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