entry.S 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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_D0) /* save the return value */
  74. jra ret_from_exception
  75. 1:
  76. movel #-ENOSYS,%d2 /* strace needs -ENOSYS in PT_D0 */
  77. movel %d2,PT_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_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. btst #5,%sp@(PT_SR) /* check if returning to kernel */
  94. jeq Luser_return /* if so, skip resched, signals */
  95. Lkernel_return:
  96. moveml %sp@,%d1-%d5/%a0-%a2
  97. lea %sp@(32),%sp /* space for 8 regs */
  98. movel %sp@+,%d0
  99. addql #4,%sp /* orig d0 */
  100. addl %sp@+,%sp /* stk adj */
  101. rte
  102. Luser_return:
  103. movel %sp,%d1 /* get thread_info pointer */
  104. andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
  105. movel %d1,%a0
  106. movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
  107. andl #_TIF_WORK_MASK,%d1
  108. jne Lwork_to_do /* still work to do */
  109. Lreturn:
  110. move #0x2700,%sr /* disable intrs */
  111. movel sw_usp,%a0 /* get usp */
  112. movel %sp@(PT_PC),%a0@- /* copy exception program counter */
  113. movel %sp@(PT_FORMATVEC),%a0@-/* copy exception format/vector/sr */
  114. moveml %sp@,%d1-%d5/%a0-%a2
  115. lea %sp@(32),%sp /* space for 8 regs */
  116. movel %sp@+,%d0
  117. addql #4,%sp /* orig d0 */
  118. addl %sp@+,%sp /* stk adj */
  119. addql #8,%sp /* remove exception */
  120. movel %sp,sw_ksp /* save ksp */
  121. subql #8,sw_usp /* set exception */
  122. movel sw_usp,%sp /* restore usp */
  123. rte
  124. Lwork_to_do:
  125. movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
  126. btst #TIF_NEED_RESCHED,%d1
  127. jne reschedule
  128. /* GERG: do we need something here for TRACEing?? */
  129. Lsignal_return:
  130. subql #4,%sp /* dummy return address */
  131. SAVE_SWITCH_STACK
  132. pea %sp@(SWITCH_STACK_SIZE)
  133. clrl %sp@-
  134. jsr do_signal
  135. addql #8,%sp
  136. RESTORE_SWITCH_STACK
  137. addql #4,%sp
  138. jmp Lreturn
  139. /*
  140. * This is the generic interrupt handler (for all hardware interrupt
  141. * sources). Calls upto high level code to do all the work.
  142. */
  143. ENTRY(inthandler)
  144. SAVE_ALL
  145. moveq #-1,%d0
  146. movel %d0,%sp@(PT_ORIG_D0)
  147. movew %sp@(PT_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_interrupt /* this was fallthrough */
  155. /*
  156. * This is the fast interrupt handler (for certain hardware interrupt
  157. * sources). Unlike the normal interrupt handler it just uses the
  158. * current stack (doesn't care if it is user or kernel). It also
  159. * doesn't bother doing the bottom half handlers.
  160. */
  161. ENTRY(fasthandler)
  162. SAVE_LOCAL
  163. movew %sp@(PT_FORMATVEC),%d0
  164. andl #0x03fc,%d0 /* mask out vector only */
  165. movel %sp,%sp@- /* push regs arg */
  166. lsrl #2,%d0 /* calculate real vector # */
  167. movel %d0,%sp@- /* push vector number */
  168. jbsr do_IRQ /* call high level irq handler */
  169. lea %sp@(8),%sp /* pop args off stack */
  170. RESTORE_LOCAL
  171. ENTRY(ret_from_interrupt)
  172. jeq 2f
  173. 1:
  174. RESTORE_ALL
  175. 2:
  176. moveb %sp@(PT_SR),%d0
  177. andl #0x7,%d0
  178. jhi 1b
  179. /* check if we need to do software interrupts */
  180. movel irq_stat+CPUSTAT_SOFTIRQ_PENDING,%d0
  181. jeq ret_from_exception
  182. pea ret_from_exception
  183. jmp do_softirq
  184. /*
  185. * Beware - when entering resume, prev (the current task) is
  186. * in a0, next (the new task) is in a1,so don't change these
  187. * registers until their contents are no longer needed.
  188. * This is always called in supervisor mode, so don't bother to save
  189. * and restore sr; user's process sr is actually in the stack.
  190. */
  191. ENTRY(resume)
  192. movel %a0, %d1 /* get prev thread in d1 */
  193. movel sw_usp,%d0 /* save usp */
  194. movel %d0,%a0@(TASK_THREAD+THREAD_USP)
  195. SAVE_SWITCH_STACK
  196. movel %sp,%a0@(TASK_THREAD+THREAD_KSP) /* save kernel stack pointer */
  197. movel %a1@(TASK_THREAD+THREAD_KSP),%sp /* restore new thread stack */
  198. RESTORE_SWITCH_STACK
  199. movel %a1@(TASK_THREAD+THREAD_USP),%a0 /* restore thread user stack */
  200. movel %a0, sw_usp
  201. rts