entry.S 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * entry.S -- interrupt and exception processing for ColdFire
  3. *
  4. * Copyright (C) 1999-2007, Greg Ungerer ([email protected])
  5. * Copyright (C) 1998 D. Jeff Dionne <[email protected]>,
  6. * Kenneth Albanowski <[email protected]>,
  7. * Copyright (C) 2000 Lineo Inc. (www.lineo.com)
  8. * Copyright (C) 2004-2006 Macq Electronique SA. (www.macqel.com)
  9. *
  10. * Based on:
  11. *
  12. * linux/arch/m68k/kernel/entry.S
  13. *
  14. * Copyright (C) 1991, 1992 Linus Torvalds
  15. *
  16. * This file is subject to the terms and conditions of the GNU General Public
  17. * License. See the file README.legal in the main directory of this archive
  18. * for more details.
  19. *
  20. * Linux/m68k support by Hamish Macdonald
  21. *
  22. * 68060 fixes by Jesper Skov
  23. * ColdFire support by Greg Ungerer ([email protected])
  24. * 5307 fixes by David W. Miller
  25. * linux 2.4 support David McCullough <[email protected]>
  26. * Bug, speed and maintainability fixes by Philippe De Muyter <[email protected]>
  27. */
  28. #include <linux/linkage.h>
  29. #include <asm/unistd.h>
  30. #include <asm/thread_info.h>
  31. #include <asm/errno.h>
  32. #include <asm/setup.h>
  33. #include <asm/asm-offsets.h>
  34. #include <asm/entry.h>
  35. #ifdef CONFIG_COLDFIRE_SW_A7
  36. /*
  37. * Define software copies of the supervisor and user stack pointers.
  38. */
  39. .bss
  40. sw_ksp:
  41. .long 0
  42. sw_usp:
  43. .long 0
  44. #endif /* CONFIG_COLDFIRE_SW_A7 */
  45. .text
  46. .globl system_call
  47. .globl resume
  48. .globl ret_from_exception
  49. .globl sys_call_table
  50. .globl inthandler
  51. enosys:
  52. mov.l #sys_ni_syscall,%d3
  53. bra 1f
  54. ENTRY(system_call)
  55. SAVE_ALL_SYS
  56. move #0x2000,%sr /* enable intrs again */
  57. GET_CURRENT(%d2)
  58. cmpl #NR_syscalls,%d0
  59. jcc enosys
  60. lea sys_call_table,%a0
  61. lsll #2,%d0 /* movel %a0@(%d0:l:4),%d3 */
  62. movel %a0@(%d0),%d3
  63. jeq enosys
  64. 1:
  65. movel %sp,%d2 /* get thread_info pointer */
  66. andl #-THREAD_SIZE,%d2 /* at start of kernel stack */
  67. movel %d2,%a0
  68. movel %a0@,%a1 /* save top of frame */
  69. movel %sp,%a1@(TASK_THREAD+THREAD_ESP0)
  70. btst #(TIF_SYSCALL_TRACE%8),%a0@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8)
  71. bnes 1f
  72. movel %d3,%a0
  73. jbsr %a0@
  74. movel %d0,%sp@(PT_OFF_D0) /* save the return value */
  75. jra ret_from_exception
  76. 1:
  77. movel #-ENOSYS,%d2 /* strace needs -ENOSYS in PT_OFF_D0 */
  78. movel %d2,PT_OFF_D0(%sp) /* on syscall entry */
  79. subql #4,%sp
  80. SAVE_SWITCH_STACK
  81. jbsr syscall_trace_enter
  82. RESTORE_SWITCH_STACK
  83. addql #4,%sp
  84. addql #1,%d0
  85. jeq ret_from_exception
  86. movel %d3,%a0
  87. jbsr %a0@
  88. movel %d0,%sp@(PT_OFF_D0) /* save the return value */
  89. subql #4,%sp /* dummy return address */
  90. SAVE_SWITCH_STACK
  91. jbsr syscall_trace_leave
  92. RESTORE_SWITCH_STACK
  93. addql #4,%sp
  94. ret_from_exception:
  95. move #0x2700,%sr /* disable intrs */
  96. btst #5,%sp@(PT_OFF_SR) /* check if returning to kernel */
  97. jeq Luser_return /* if so, skip resched, signals */
  98. #ifdef CONFIG_PREEMPTION
  99. movel %sp,%d1 /* get thread_info pointer */
  100. andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
  101. movel %d1,%a0
  102. movel %a0@(TINFO_FLAGS),%d1 /* get thread_info->flags */
  103. andl #(1<<TIF_NEED_RESCHED),%d1
  104. jeq Lkernel_return
  105. movel %a0@(TINFO_PREEMPT),%d1
  106. cmpl #0,%d1
  107. jne Lkernel_return
  108. pea Lkernel_return
  109. jmp preempt_schedule_irq /* preempt the kernel */
  110. #endif
  111. Lkernel_return:
  112. moveml %sp@,%d1-%d5/%a0-%a2
  113. lea %sp@(32),%sp /* space for 8 regs */
  114. movel %sp@+,%d0
  115. addql #4,%sp /* orig d0 */
  116. addl %sp@+,%sp /* stk adj */
  117. rte
  118. Luser_return:
  119. movel %sp,%d1 /* get thread_info pointer */
  120. andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
  121. movel %d1,%a0
  122. moveb %a0@(TINFO_FLAGS+3),%d1 /* thread_info->flags (low 8 bits) */
  123. jne Lwork_to_do /* still work to do */
  124. Lreturn:
  125. RESTORE_USER
  126. Lwork_to_do:
  127. movel %a0@(TINFO_FLAGS),%d1 /* get thread_info->flags */
  128. move #0x2000,%sr /* enable intrs again */
  129. btst #TIF_NEED_RESCHED,%d1
  130. jne reschedule
  131. Lsignal_return:
  132. subql #4,%sp /* dummy return address */
  133. SAVE_SWITCH_STACK
  134. pea %sp@(SWITCH_STACK_SIZE)
  135. jsr do_notify_resume
  136. addql #4,%sp
  137. RESTORE_SWITCH_STACK
  138. addql #4,%sp
  139. jmp Luser_return
  140. /*
  141. * This is the generic interrupt handler (for all hardware interrupt
  142. * sources). Calls up to high level code to do all the work.
  143. */
  144. ENTRY(inthandler)
  145. SAVE_ALL_INT
  146. GET_CURRENT(%d2)
  147. movew %sp@(PT_OFF_FORMATVEC),%d0 /* put exception # in d0 */
  148. andl #0x03fc,%d0 /* mask out vector only */
  149. movel %sp,%sp@- /* push regs arg */
  150. lsrl #2,%d0 /* calculate real vector # */
  151. movel %d0,%sp@- /* push vector number */
  152. jbsr do_IRQ /* call high level irq handler */
  153. lea %sp@(8),%sp /* pop args off stack */
  154. bra ret_from_exception
  155. /*
  156. * Beware - when entering resume, prev (the current task) is
  157. * in a0, next (the new task) is in a1, so don't change these
  158. * registers until their contents are no longer needed.
  159. */
  160. ENTRY(resume)
  161. movew %sr,%d1 /* save current status */
  162. movew %d1,%a0@(TASK_THREAD+THREAD_SR)
  163. movel %a0,%d1 /* get prev thread in d1 */
  164. SAVE_SWITCH_STACK
  165. movel %sp,%a0@(TASK_THREAD+THREAD_KSP) /* save kernel stack pointer */
  166. RDUSP /* movel %usp,%a3 */
  167. movel %a3,%a0@(TASK_THREAD+THREAD_USP) /* save thread user stack */
  168. #ifdef CONFIG_MMU
  169. movel %a1,%a2 /* set new current */
  170. #endif
  171. movel %a1@(TASK_THREAD+THREAD_USP),%a3 /* restore thread user stack */
  172. WRUSP /* movel %a3,%usp */
  173. movel %a1@(TASK_THREAD+THREAD_KSP),%sp /* restore new kernel stack */
  174. movew %a1@(TASK_THREAD+THREAD_SR),%d7 /* restore new status */
  175. movew %d7,%sr
  176. RESTORE_SWITCH_STACK
  177. rts