entry.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. #ifdef CONFIG_COLDFIRE_SW_A7
  38. /*
  39. * Define software copies of the supervisor and user stack pointers.
  40. */
  41. .bss
  42. sw_ksp:
  43. .long 0
  44. sw_usp:
  45. .long 0
  46. #endif /* CONFIG_COLDFIRE_SW_A7 */
  47. .text
  48. .globl system_call
  49. .globl resume
  50. .globl ret_from_exception
  51. .globl ret_from_signal
  52. .globl sys_call_table
  53. .globl inthandler
  54. .globl fasthandler
  55. enosys:
  56. mov.l #sys_ni_syscall,%d3
  57. bra 1f
  58. ENTRY(system_call)
  59. SAVE_ALL
  60. move #0x2000,%sr /* enable intrs again */
  61. cmpl #NR_syscalls,%d0
  62. jcc enosys
  63. lea sys_call_table,%a0
  64. lsll #2,%d0 /* movel %a0@(%d0:l:4),%d3 */
  65. movel %a0@(%d0),%d3
  66. jeq enosys
  67. 1:
  68. movel %sp,%d2 /* get thread_info pointer */
  69. andl #-THREAD_SIZE,%d2 /* at start of kernel stack */
  70. movel %d2,%a0
  71. movel %a0@,%a1 /* save top of frame */
  72. movel %sp,%a1@(TASK_THREAD+THREAD_ESP0)
  73. btst #(TIF_SYSCALL_TRACE%8),%a0@(TI_FLAGS+(31-TIF_SYSCALL_TRACE)/8)
  74. bnes 1f
  75. movel %d3,%a0
  76. jbsr %a0@
  77. movel %d0,%sp@(PT_OFF_D0) /* save the return value */
  78. jra ret_from_exception
  79. 1:
  80. movel #-ENOSYS,%d2 /* strace needs -ENOSYS in PT_OFF_D0 */
  81. movel %d2,PT_OFF_D0(%sp) /* on syscall entry */
  82. subql #4,%sp
  83. SAVE_SWITCH_STACK
  84. jbsr syscall_trace_enter
  85. RESTORE_SWITCH_STACK
  86. addql #4,%sp
  87. movel %d3,%a0
  88. jbsr %a0@
  89. movel %d0,%sp@(PT_OFF_D0) /* save the return value */
  90. subql #4,%sp /* dummy return address */
  91. SAVE_SWITCH_STACK
  92. jbsr syscall_trace_leave
  93. ret_from_signal:
  94. RESTORE_SWITCH_STACK
  95. addql #4,%sp
  96. ret_from_exception:
  97. move #0x2700,%sr /* disable intrs */
  98. btst #5,%sp@(PT_OFF_SR) /* check if returning to kernel */
  99. jeq Luser_return /* if so, skip resched, signals */
  100. #ifdef CONFIG_PREEMPT
  101. movel %sp,%d1 /* get thread_info pointer */
  102. andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
  103. movel %d1,%a0
  104. movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
  105. andl #(1<<TIF_NEED_RESCHED),%d1
  106. jeq Lkernel_return
  107. movel %a0@(TI_PREEMPTCOUNT),%d1
  108. cmpl #0,%d1
  109. jne Lkernel_return
  110. pea Lkernel_return
  111. jmp preempt_schedule_irq /* preempt the kernel */
  112. #endif
  113. Lkernel_return:
  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. rte
  120. Luser_return:
  121. movel %sp,%d1 /* get thread_info pointer */
  122. andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
  123. movel %d1,%a0
  124. movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
  125. jne Lwork_to_do /* still work to do */
  126. Lreturn:
  127. RESTORE_USER
  128. Lwork_to_do:
  129. movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
  130. move #0x2000,%sr /* enable intrs again */
  131. btst #TIF_NEED_RESCHED,%d1
  132. jne reschedule
  133. /* GERG: do we need something here for TRACEing?? */
  134. Lsignal_return:
  135. subql #4,%sp /* dummy return address */
  136. SAVE_SWITCH_STACK
  137. pea %sp@(SWITCH_STACK_SIZE)
  138. jsr do_signal
  139. addql #4,%sp
  140. RESTORE_SWITCH_STACK
  141. addql #4,%sp
  142. jmp Luser_return
  143. /*
  144. * This is the generic interrupt handler (for all hardware interrupt
  145. * sources). Calls upto high level code to do all the work.
  146. */
  147. ENTRY(inthandler)
  148. SAVE_ALL
  149. moveq #-1,%d0
  150. movel %d0,%sp@(PT_OFF_ORIG_D0)
  151. movew %sp@(PT_OFF_FORMATVEC),%d0 /* put exception # in d0 */
  152. andl #0x03fc,%d0 /* mask out vector only */
  153. movel %sp,%sp@- /* push regs arg */
  154. lsrl #2,%d0 /* calculate real vector # */
  155. movel %d0,%sp@- /* push vector number */
  156. jbsr do_IRQ /* call high level irq handler */
  157. lea %sp@(8),%sp /* pop args off stack */
  158. bra ret_from_exception
  159. /*
  160. * Beware - when entering resume, prev (the current task) is
  161. * in a0, next (the new task) is in a1,so don't change these
  162. * registers until their contents are no longer needed.
  163. * This is always called in supervisor mode, so don't bother to save
  164. * and restore sr; user's process sr is actually in the stack.
  165. */
  166. ENTRY(resume)
  167. movel %a0, %d1 /* get prev thread in d1 */
  168. RDUSP
  169. movel %a2,%a0@(TASK_THREAD+THREAD_USP)
  170. SAVE_SWITCH_STACK
  171. movel %sp,%a0@(TASK_THREAD+THREAD_KSP) /* save kernel stack pointer */
  172. movel %a1@(TASK_THREAD+THREAD_KSP),%sp /* restore new thread stack */
  173. RESTORE_SWITCH_STACK
  174. movel %a1@(TASK_THREAD+THREAD_USP),%a0 /* restore thread user stack */
  175. WRUSP
  176. rts