entry.S 5.8 KB

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