entry.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. local_irq_disable # make sure need_resched and
  75. # signals dont change between
  76. # sampling and return
  77. LONG_L a2, TI_FLAGS($28) # current->work
  78. li t0, _TIF_ALLWORK_MASK
  79. and t0, a2, t0
  80. bnez t0, syscall_exit_work
  81. restore_all: # restore full frame
  82. .set noat
  83. RESTORE_TEMP
  84. RESTORE_AT
  85. RESTORE_STATIC
  86. restore_partial: # restore partial frame
  87. #ifdef CONFIG_TRACE_IRQFLAGS
  88. SAVE_STATIC
  89. SAVE_AT
  90. SAVE_TEMP
  91. LONG_L v0, PT_STATUS(sp)
  92. #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  93. and v0, ST0_IEP
  94. #else
  95. and v0, ST0_IE
  96. #endif
  97. beqz v0, 1f
  98. jal trace_hardirqs_on
  99. b 2f
  100. 1: jal trace_hardirqs_off
  101. 2:
  102. RESTORE_TEMP
  103. RESTORE_AT
  104. RESTORE_STATIC
  105. #endif
  106. RESTORE_SOME
  107. RESTORE_SP_AND_RET
  108. .set at
  109. work_pending:
  110. andi t0, a2, _TIF_NEED_RESCHED # a2 is preloaded with TI_FLAGS
  111. beqz t0, work_notifysig
  112. work_resched:
  113. TRACE_IRQS_OFF
  114. jal schedule
  115. local_irq_disable # make sure need_resched and
  116. # signals dont change between
  117. # sampling and return
  118. LONG_L a2, TI_FLAGS($28)
  119. andi t0, a2, _TIF_WORK_MASK # is there any work to be done
  120. # other than syscall tracing?
  121. beqz t0, restore_all
  122. andi t0, a2, _TIF_NEED_RESCHED
  123. bnez t0, work_resched
  124. work_notifysig: # deal with pending signals and
  125. # notify-resume requests
  126. move a0, sp
  127. li a1, 0
  128. jal do_notify_resume # a2 already loaded
  129. j resume_userspace_check
  130. FEXPORT(syscall_exit_partial)
  131. local_irq_disable # make sure need_resched doesn't
  132. # change between and return
  133. LONG_L a2, TI_FLAGS($28) # current->work
  134. li t0, _TIF_ALLWORK_MASK
  135. and t0, a2
  136. beqz t0, restore_partial
  137. SAVE_STATIC
  138. syscall_exit_work:
  139. LONG_L t0, PT_STATUS(sp) # returning to kernel mode?
  140. andi t0, t0, KU_USER
  141. beqz t0, resume_kernel
  142. li t0, _TIF_WORK_SYSCALL_EXIT
  143. and t0, a2 # a2 is preloaded with TI_FLAGS
  144. beqz t0, work_pending # trace bit set?
  145. local_irq_enable # could let syscall_trace_leave()
  146. # call schedule() instead
  147. TRACE_IRQS_ON
  148. move a0, sp
  149. jal syscall_trace_leave
  150. b resume_userspace
  151. #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) || \
  152. defined(CONFIG_MIPS_MT)
  153. /*
  154. * MIPS32R2 Instruction Hazard Barrier - must be called
  155. *
  156. * For C code use the inline version named instruction_hazard().
  157. */
  158. LEAF(mips_ihb)
  159. .set MIPS_ISA_LEVEL_RAW
  160. jr.hb ra
  161. nop
  162. END(mips_ihb)
  163. #endif /* CONFIG_CPU_MIPSR2 or CONFIG_CPU_MIPSR6 or CONFIG_MIPS_MT */