entry.S 5.2 KB

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