entry.S 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /* -*- mode: asm -*-
  2. *
  3. * linux/arch/m68k/kernel/entry.S
  4. *
  5. * Copyright (C) 1991, 1992 Linus Torvalds
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file README.legal in the main directory of this archive
  9. * for more details.
  10. *
  11. * Linux/m68k support by Hamish Macdonald
  12. *
  13. * 68060 fixes by Jesper Skov
  14. *
  15. */
  16. /*
  17. * entry.S contains the system-call and fault low-level handling routines.
  18. * This also contains the timer-interrupt handler, as well as all interrupts
  19. * and faults that can result in a task-switch.
  20. *
  21. * NOTE: This code handles signal-recognition, which happens every time
  22. * after a timer-interrupt and after each system call.
  23. *
  24. */
  25. /*
  26. * 12/03/96 Jes: Currently we only support m68k single-cpu systems, so
  27. * all pointers that used to be 'current' are now entry
  28. * number 0 in the 'current_set' list.
  29. *
  30. * 6/05/00 RZ: addedd writeback completion after return from sighandler
  31. * for 68040
  32. */
  33. #include <linux/linkage.h>
  34. #include <asm/errno.h>
  35. #include <asm/setup.h>
  36. #include <asm/segment.h>
  37. #include <asm/traps.h>
  38. #include <asm/unistd.h>
  39. #include <asm/asm-offsets.h>
  40. #include <asm/entry.h>
  41. .globl system_call, buserr, trap, resume
  42. .globl sys_call_table
  43. .globl __sys_fork, __sys_clone, __sys_vfork
  44. .globl bad_interrupt
  45. .globl auto_irqhandler_fixup
  46. .globl user_irqvec_fixup
  47. .text
  48. ENTRY(__sys_fork)
  49. SAVE_SWITCH_STACK
  50. jbsr sys_fork
  51. lea %sp@(24),%sp
  52. rts
  53. ENTRY(__sys_clone)
  54. SAVE_SWITCH_STACK
  55. pea %sp@(SWITCH_STACK_SIZE)
  56. jbsr m68k_clone
  57. lea %sp@(28),%sp
  58. rts
  59. ENTRY(__sys_vfork)
  60. SAVE_SWITCH_STACK
  61. jbsr sys_vfork
  62. lea %sp@(24),%sp
  63. rts
  64. ENTRY(sys_sigreturn)
  65. SAVE_SWITCH_STACK
  66. movel %sp,%sp@- | switch_stack pointer
  67. pea %sp@(SWITCH_STACK_SIZE+4) | pt_regs pointer
  68. jbsr do_sigreturn
  69. addql #8,%sp
  70. RESTORE_SWITCH_STACK
  71. rts
  72. ENTRY(sys_rt_sigreturn)
  73. SAVE_SWITCH_STACK
  74. movel %sp,%sp@- | switch_stack pointer
  75. pea %sp@(SWITCH_STACK_SIZE+4) | pt_regs pointer
  76. jbsr do_rt_sigreturn
  77. addql #8,%sp
  78. RESTORE_SWITCH_STACK
  79. rts
  80. ENTRY(buserr)
  81. SAVE_ALL_INT
  82. GET_CURRENT(%d0)
  83. movel %sp,%sp@- | stack frame pointer argument
  84. jbsr buserr_c
  85. addql #4,%sp
  86. jra ret_from_exception
  87. ENTRY(trap)
  88. SAVE_ALL_INT
  89. GET_CURRENT(%d0)
  90. movel %sp,%sp@- | stack frame pointer argument
  91. jbsr trap_c
  92. addql #4,%sp
  93. jra ret_from_exception
  94. | After a fork we jump here directly from resume,
  95. | so that %d1 contains the previous task
  96. | schedule_tail now used regardless of CONFIG_SMP
  97. ENTRY(ret_from_fork)
  98. movel %d1,%sp@-
  99. jsr schedule_tail
  100. addql #4,%sp
  101. jra ret_from_exception
  102. ENTRY(ret_from_kernel_thread)
  103. | a3 contains the kernel thread payload, d7 - its argument
  104. movel %d1,%sp@-
  105. jsr schedule_tail
  106. movel %d7,(%sp)
  107. jsr %a3@
  108. addql #4,%sp
  109. jra ret_from_exception
  110. #if defined(CONFIG_COLDFIRE) || !defined(CONFIG_MMU)
  111. #ifdef TRAP_DBG_INTERRUPT
  112. .globl dbginterrupt
  113. ENTRY(dbginterrupt)
  114. SAVE_ALL_INT
  115. GET_CURRENT(%d0)
  116. movel %sp,%sp@- /* stack frame pointer argument */
  117. jsr dbginterrupt_c
  118. addql #4,%sp
  119. jra ret_from_exception
  120. #endif
  121. ENTRY(reschedule)
  122. /* save top of frame */
  123. pea %sp@
  124. jbsr set_esp0
  125. addql #4,%sp
  126. pea ret_from_exception
  127. jmp schedule
  128. ENTRY(ret_from_user_signal)
  129. moveq #__NR_sigreturn,%d0
  130. trap #0
  131. ENTRY(ret_from_user_rt_signal)
  132. movel #__NR_rt_sigreturn,%d0
  133. trap #0
  134. #else
  135. do_trace_entry:
  136. movel #-ENOSYS,%sp@(PT_OFF_D0)| needed for strace
  137. subql #4,%sp
  138. SAVE_SWITCH_STACK
  139. jbsr syscall_trace
  140. RESTORE_SWITCH_STACK
  141. addql #4,%sp
  142. movel %sp@(PT_OFF_ORIG_D0),%d0
  143. cmpl #NR_syscalls,%d0
  144. jcs syscall
  145. badsys:
  146. movel #-ENOSYS,%sp@(PT_OFF_D0)
  147. jra ret_from_syscall
  148. do_trace_exit:
  149. subql #4,%sp
  150. SAVE_SWITCH_STACK
  151. jbsr syscall_trace
  152. RESTORE_SWITCH_STACK
  153. addql #4,%sp
  154. jra .Lret_from_exception
  155. ENTRY(ret_from_signal)
  156. movel %curptr@(TASK_STACK),%a1
  157. tstb %a1@(TINFO_FLAGS+2)
  158. jge 1f
  159. jbsr syscall_trace
  160. 1: RESTORE_SWITCH_STACK
  161. addql #4,%sp
  162. /* on 68040 complete pending writebacks if any */
  163. #ifdef CONFIG_M68040
  164. bfextu %sp@(PT_OFF_FORMATVEC){#0,#4},%d0
  165. subql #7,%d0 | bus error frame ?
  166. jbne 1f
  167. movel %sp,%sp@-
  168. jbsr berr_040cleanup
  169. addql #4,%sp
  170. 1:
  171. #endif
  172. jra .Lret_from_exception
  173. ENTRY(system_call)
  174. SAVE_ALL_SYS
  175. GET_CURRENT(%d1)
  176. movel %d1,%a1
  177. | save top of frame
  178. movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
  179. | syscall trace?
  180. tstb %a1@(TINFO_FLAGS+2)
  181. jmi do_trace_entry
  182. cmpl #NR_syscalls,%d0
  183. jcc badsys
  184. syscall:
  185. jbsr @(sys_call_table,%d0:l:4)@(0)
  186. movel %d0,%sp@(PT_OFF_D0) | save the return value
  187. ret_from_syscall:
  188. |oriw #0x0700,%sr
  189. movel %curptr@(TASK_STACK),%a1
  190. movew %a1@(TINFO_FLAGS+2),%d0
  191. jne syscall_exit_work
  192. 1: RESTORE_ALL
  193. syscall_exit_work:
  194. btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
  195. bnes 1b | if so, skip resched, signals
  196. lslw #1,%d0
  197. jcs do_trace_exit
  198. jmi do_delayed_trace
  199. lslw #8,%d0
  200. jne do_signal_return
  201. pea resume_userspace
  202. jra schedule
  203. ENTRY(ret_from_exception)
  204. .Lret_from_exception:
  205. btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
  206. bnes 1f | if so, skip resched, signals
  207. | only allow interrupts when we are really the last one on the
  208. | kernel stack, otherwise stack overflow can occur during
  209. | heavy interrupt load
  210. andw #ALLOWINT,%sr
  211. resume_userspace:
  212. movel %curptr@(TASK_STACK),%a1
  213. moveb %a1@(TINFO_FLAGS+3),%d0
  214. jne exit_work
  215. 1: RESTORE_ALL
  216. exit_work:
  217. | save top of frame
  218. movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
  219. lslb #1,%d0
  220. jne do_signal_return
  221. pea resume_userspace
  222. jra schedule
  223. do_signal_return:
  224. |andw #ALLOWINT,%sr
  225. subql #4,%sp | dummy return address
  226. SAVE_SWITCH_STACK
  227. pea %sp@(SWITCH_STACK_SIZE)
  228. bsrl do_notify_resume
  229. addql #4,%sp
  230. RESTORE_SWITCH_STACK
  231. addql #4,%sp
  232. jbra resume_userspace
  233. do_delayed_trace:
  234. bclr #7,%sp@(PT_OFF_SR) | clear trace bit in SR
  235. pea 1 | send SIGTRAP
  236. movel %curptr,%sp@-
  237. pea LSIGTRAP
  238. jbsr send_sig
  239. addql #8,%sp
  240. addql #4,%sp
  241. jbra resume_userspace
  242. /* This is the main interrupt handler for autovector interrupts */
  243. ENTRY(auto_inthandler)
  244. SAVE_ALL_INT
  245. GET_CURRENT(%d0)
  246. | put exception # in d0
  247. bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
  248. subw #VEC_SPUR,%d0
  249. movel %sp,%sp@-
  250. movel %d0,%sp@- | put vector # on stack
  251. auto_irqhandler_fixup = . + 2
  252. jsr do_IRQ | process the IRQ
  253. addql #8,%sp | pop parameters off stack
  254. jra ret_from_exception
  255. /* Handler for user defined interrupt vectors */
  256. ENTRY(user_inthandler)
  257. SAVE_ALL_INT
  258. GET_CURRENT(%d0)
  259. | put exception # in d0
  260. bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
  261. user_irqvec_fixup = . + 2
  262. subw #VEC_USER,%d0
  263. movel %sp,%sp@-
  264. movel %d0,%sp@- | put vector # on stack
  265. jsr do_IRQ | process the IRQ
  266. addql #8,%sp | pop parameters off stack
  267. jra ret_from_exception
  268. /* Handler for uninitialized and spurious interrupts */
  269. ENTRY(bad_inthandler)
  270. SAVE_ALL_INT
  271. GET_CURRENT(%d0)
  272. movel %sp,%sp@-
  273. jsr handle_badint
  274. addql #4,%sp
  275. jra ret_from_exception
  276. resume:
  277. /*
  278. * Beware - when entering resume, prev (the current task) is
  279. * in a0, next (the new task) is in a1,so don't change these
  280. * registers until their contents are no longer needed.
  281. */
  282. /* save sr */
  283. movew %sr,%a0@(TASK_THREAD+THREAD_SR)
  284. /* save fs (sfc,%dfc) (may be pointing to kernel memory) */
  285. movec %sfc,%d0
  286. movew %d0,%a0@(TASK_THREAD+THREAD_FS)
  287. /* save usp */
  288. /* it is better to use a movel here instead of a movew 8*) */
  289. movec %usp,%d0
  290. movel %d0,%a0@(TASK_THREAD+THREAD_USP)
  291. /* save non-scratch registers on stack */
  292. SAVE_SWITCH_STACK
  293. /* save current kernel stack pointer */
  294. movel %sp,%a0@(TASK_THREAD+THREAD_KSP)
  295. /* save floating point context */
  296. #ifndef CONFIG_M68KFPU_EMU_ONLY
  297. #ifdef CONFIG_M68KFPU_EMU
  298. tstl m68k_fputype
  299. jeq 3f
  300. #endif
  301. fsave %a0@(TASK_THREAD+THREAD_FPSTATE)
  302. #if defined(CONFIG_M68060)
  303. #if !defined(CPU_M68060_ONLY)
  304. btst #3,m68k_cputype+3
  305. beqs 1f
  306. #endif
  307. /* The 060 FPU keeps status in bits 15-8 of the first longword */
  308. tstb %a0@(TASK_THREAD+THREAD_FPSTATE+2)
  309. jeq 3f
  310. #if !defined(CPU_M68060_ONLY)
  311. jra 2f
  312. #endif
  313. #endif /* CONFIG_M68060 */
  314. #if !defined(CPU_M68060_ONLY)
  315. 1: tstb %a0@(TASK_THREAD+THREAD_FPSTATE)
  316. jeq 3f
  317. #endif
  318. 2: fmovemx %fp0-%fp7,%a0@(TASK_THREAD+THREAD_FPREG)
  319. fmoveml %fpcr/%fpsr/%fpiar,%a0@(TASK_THREAD+THREAD_FPCNTL)
  320. 3:
  321. #endif /* CONFIG_M68KFPU_EMU_ONLY */
  322. /* Return previous task in %d1 */
  323. movel %curptr,%d1
  324. /* switch to new task (a1 contains new task) */
  325. movel %a1,%curptr
  326. /* restore floating point context */
  327. #ifndef CONFIG_M68KFPU_EMU_ONLY
  328. #ifdef CONFIG_M68KFPU_EMU
  329. tstl m68k_fputype
  330. jeq 4f
  331. #endif
  332. #if defined(CONFIG_M68060)
  333. #if !defined(CPU_M68060_ONLY)
  334. btst #3,m68k_cputype+3
  335. beqs 1f
  336. #endif
  337. /* The 060 FPU keeps status in bits 15-8 of the first longword */
  338. tstb %a1@(TASK_THREAD+THREAD_FPSTATE+2)
  339. jeq 3f
  340. #if !defined(CPU_M68060_ONLY)
  341. jra 2f
  342. #endif
  343. #endif /* CONFIG_M68060 */
  344. #if !defined(CPU_M68060_ONLY)
  345. 1: tstb %a1@(TASK_THREAD+THREAD_FPSTATE)
  346. jeq 3f
  347. #endif
  348. 2: fmovemx %a1@(TASK_THREAD+THREAD_FPREG),%fp0-%fp7
  349. fmoveml %a1@(TASK_THREAD+THREAD_FPCNTL),%fpcr/%fpsr/%fpiar
  350. 3: frestore %a1@(TASK_THREAD+THREAD_FPSTATE)
  351. 4:
  352. #endif /* CONFIG_M68KFPU_EMU_ONLY */
  353. /* restore the kernel stack pointer */
  354. movel %a1@(TASK_THREAD+THREAD_KSP),%sp
  355. /* restore non-scratch registers */
  356. RESTORE_SWITCH_STACK
  357. /* restore user stack pointer */
  358. movel %a1@(TASK_THREAD+THREAD_USP),%a0
  359. movel %a0,%usp
  360. /* restore fs (sfc,%dfc) */
  361. movew %a1@(TASK_THREAD+THREAD_FS),%a0
  362. movec %a0,%sfc
  363. movec %a0,%dfc
  364. /* restore status register */
  365. movew %a1@(TASK_THREAD+THREAD_SR),%sr
  366. rts
  367. #endif /* CONFIG_MMU && !CONFIG_COLDFIRE */