entry.S 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * linux/arch/m68knommu/platform/5307/entry.S
  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/sys.h>
  29. #include <linux/linkage.h>
  30. #include <asm/unistd.h>
  31. #include <asm/thread_info.h>
  32. #include <asm/errno.h>
  33. #include <asm/setup.h>
  34. #include <asm/segment.h>
  35. #include <asm/asm-offsets.h>
  36. #include <asm/entry.h>
  37. .bss
  38. sw_ksp:
  39. .long 0
  40. sw_usp:
  41. .long 0
  42. .text
  43. .globl system_call
  44. .globl resume
  45. .globl ret_from_exception
  46. .globl ret_from_signal
  47. .globl sys_call_table
  48. .globl ret_from_interrupt
  49. .globl inthandler
  50. .globl fasthandler
  51. enosys:
  52. mov.l #sys_ni_syscall,%d3
  53. bra 1f
  54. ENTRY(system_call)
  55. SAVE_ALL
  56. move #0x2000,%sr /* enable intrs again */
  57. cmpl #NR_syscalls,%d0
  58. jcc enosys
  59. lea sys_call_table,%a0
  60. lsll #2,%d0 /* movel %a0@(%d0:l:4),%d3 */
  61. movel %a0@(%d0),%d3
  62. jeq enosys
  63. 1:
  64. movel %sp,%d2 /* get thread_info pointer */
  65. andl #-THREAD_SIZE,%d2 /* at start of kernel stack */
  66. movel %d2,%a0
  67. movel %a0@,%a1 /* save top of frame */
  68. movel %sp,%a1@(TASK_THREAD+THREAD_ESP0)
  69. btst #(TIF_SYSCALL_TRACE%8),%a0@(TI_FLAGS+(31-TIF_SYSCALL_TRACE)/8)
  70. bnes 1f
  71. movel %d3,%a0
  72. jbsr %a0@
  73. movel %d0,%sp@(PT_OFF_D0) /* save the return value */
  74. jra ret_from_exception
  75. 1:
  76. movel #-ENOSYS,%d2 /* strace needs -ENOSYS in PT_OFF_D0 */
  77. movel %d2,PT_OFF_D0(%sp) /* on syscall entry */
  78. subql #4,%sp
  79. SAVE_SWITCH_STACK
  80. jbsr syscall_trace
  81. RESTORE_SWITCH_STACK
  82. addql #4,%sp
  83. movel %d3,%a0
  84. jbsr %a0@
  85. movel %d0,%sp@(PT_OFF_D0) /* save the return value */
  86. subql #4,%sp /* dummy return address */
  87. SAVE_SWITCH_STACK
  88. jbsr syscall_trace
  89. ret_from_signal:
  90. RESTORE_SWITCH_STACK
  91. addql #4,%sp
  92. ret_from_exception:
  93. move #0x2700,%sr /* disable intrs */
  94. btst #5,%sp@(PT_OFF_SR) /* check if returning to kernel */
  95. jeq Luser_return /* if so, skip resched, signals */
  96. #ifdef CONFIG_PREEMPT
  97. movel %sp,%d1 /* get thread_info pointer */
  98. andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
  99. movel %d1,%a0
  100. movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
  101. andl #_TIF_NEED_RESCHED,%d1
  102. jeq Lkernel_return
  103. movel %a0@(TI_PREEMPTCOUNT),%d1
  104. cmpl #0,%d1
  105. jne Lkernel_return
  106. pea Lkernel_return
  107. jmp preempt_schedule_irq /* preempt the kernel */
  108. #endif
  109. Lkernel_return:
  110. moveml %sp@,%d1-%d5/%a0-%a2
  111. lea %sp@(32),%sp /* space for 8 regs */
  112. movel %sp@+,%d0
  113. addql #4,%sp /* orig d0 */
  114. addl %sp@+,%sp /* stk adj */
  115. rte
  116. Luser_return:
  117. movel %sp,%d1 /* get thread_info pointer */
  118. andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
  119. movel %d1,%a0
  120. movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
  121. andl #_TIF_WORK_MASK,%d1
  122. jne Lwork_to_do /* still work to do */
  123. Lreturn:
  124. move #0x2700,%sr /* disable intrs */
  125. movel sw_usp,%a0 /* get usp */
  126. movel %sp@(PT_OFF_PC),%a0@- /* copy exception program counter */
  127. movel %sp@(PT_OFF_FORMATVEC),%a0@- /* copy exception format/vector/sr */
  128. moveml %sp@,%d1-%d5/%a0-%a2
  129. lea %sp@(32),%sp /* space for 8 regs */
  130. movel %sp@+,%d0
  131. addql #4,%sp /* orig d0 */
  132. addl %sp@+,%sp /* stk adj */
  133. addql #8,%sp /* remove exception */
  134. movel %sp,sw_ksp /* save ksp */
  135. subql #8,sw_usp /* set exception */
  136. movel sw_usp,%sp /* restore usp */
  137. rte
  138. Lwork_to_do:
  139. movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
  140. move #0x2000,%sr /* enable intrs again */
  141. btst #TIF_NEED_RESCHED,%d1
  142. jne reschedule
  143. /* GERG: do we need something here for TRACEing?? */
  144. Lsignal_return:
  145. subql #4,%sp /* dummy return address */
  146. SAVE_SWITCH_STACK
  147. pea %sp@(SWITCH_STACK_SIZE)
  148. clrl %sp@-
  149. jsr do_signal
  150. addql #8,%sp
  151. RESTORE_SWITCH_STACK
  152. addql #4,%sp
  153. jmp Lreturn
  154. /*
  155. * This is the generic interrupt handler (for all hardware interrupt
  156. * sources). Calls upto high level code to do all the work.
  157. */
  158. ENTRY(inthandler)
  159. SAVE_ALL
  160. moveq #-1,%d0
  161. movel %d0,%sp@(PT_OFF_ORIG_D0)
  162. movew %sp@(PT_OFF_FORMATVEC),%d0 /* put exception # in d0 */
  163. andl #0x03fc,%d0 /* mask out vector only */
  164. movel %sp,%sp@- /* push regs arg */
  165. lsrl #2,%d0 /* calculate real vector # */
  166. movel %d0,%sp@- /* push vector number */
  167. jbsr do_IRQ /* call high level irq handler */
  168. lea %sp@(8),%sp /* pop args off stack */
  169. bra ret_from_interrupt /* this was fallthrough */
  170. /*
  171. * This is the fast interrupt handler (for certain hardware interrupt
  172. * sources). Unlike the normal interrupt handler it just uses the
  173. * current stack (doesn't care if it is user or kernel). It also
  174. * doesn't bother doing the bottom half handlers.
  175. */
  176. ENTRY(fasthandler)
  177. SAVE_LOCAL
  178. movew %sp@(PT_OFF_FORMATVEC),%d0
  179. andl #0x03fc,%d0 /* mask out vector only */
  180. movel %sp,%sp@- /* push regs arg */
  181. lsrl #2,%d0 /* calculate real vector # */
  182. movel %d0,%sp@- /* push vector number */
  183. jbsr do_IRQ /* call high level irq handler */
  184. lea %sp@(8),%sp /* pop args off stack */
  185. RESTORE_LOCAL
  186. ENTRY(ret_from_interrupt)
  187. /* the fasthandler is confusing me, haven't seen any user */
  188. jmp ret_from_exception
  189. /*
  190. * Beware - when entering resume, prev (the current task) is
  191. * in a0, next (the new task) is in a1,so don't change these
  192. * registers until their contents are no longer needed.
  193. * This is always called in supervisor mode, so don't bother to save
  194. * and restore sr; user's process sr is actually in the stack.
  195. */
  196. ENTRY(resume)
  197. movel %a0, %d1 /* get prev thread in d1 */
  198. movel sw_usp,%d0 /* save usp */
  199. movel %d0,%a0@(TASK_THREAD+THREAD_USP)
  200. SAVE_SWITCH_STACK
  201. movel %sp,%a0@(TASK_THREAD+THREAD_KSP) /* save kernel stack pointer */
  202. movel %a1@(TASK_THREAD+THREAD_KSP),%sp /* restore new thread stack */
  203. RESTORE_SWITCH_STACK
  204. movel %a1@(TASK_THREAD+THREAD_USP),%a0 /* restore thread user stack */
  205. movel %a0, sw_usp
  206. rts