3 * linux/arch/m68k/kernel/entry.S
5 * Copyright (C) 1991, 1992 Linus Torvalds
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
11 * Linux/m68k support by Hamish Macdonald
13 * 68060 fixes by Jesper Skov
18 * entry.S contains the system-call and fault low-level handling routines.
19 * This also contains the timer-interrupt handler, as well as all interrupts
20 * and faults that can result in a task-switch.
22 * NOTE: This code handles signal-recognition, which happens every time
23 * after a timer-interrupt and after each system call.
28 * 12/03/96 Jes: Currently we only support m68k single-cpu systems, so
29 * all pointers that used to be 'current' are now entry
30 * number 0 in the 'current_set' list.
32 * 6/05/00 RZ: addedd writeback completion after return from sighandler
36 #include <linux/linkage.h>
37 #include <asm/errno.h>
38 #include <asm/setup.h>
39 #include <asm/segment.h>
40 #include <asm/traps.h>
41 #include <asm/unistd.h>
42 #include <asm/asm-offsets.h>
43 #include <asm/entry.h>
45 .globl system_call, buserr, trap, resume
47 .globl __sys_fork, __sys_clone, __sys_vfork
49 .globl auto_irqhandler_fixup
50 .globl user_irqvec_fixup
61 pea %sp@(SWITCH_STACK_SIZE)
74 movel %sp,%sp@- | switch_stack pointer
75 pea %sp@(SWITCH_STACK_SIZE+4) | pt_regs pointer
81 ENTRY(sys_rt_sigreturn)
83 movel %sp,%sp@- | switch_stack pointer
84 pea %sp@(SWITCH_STACK_SIZE+4) | pt_regs pointer
93 movel %sp,%sp@- | stack frame pointer argument
96 jra ret_from_exception
101 movel %sp,%sp@- | stack frame pointer argument
104 jra ret_from_exception
106 | After a fork we jump here directly from resume,
107 | so that %d1 contains the previous task
108 | schedule_tail now used regardless of CONFIG_SMP
113 jra ret_from_exception
115 ENTRY(ret_from_kernel_thread)
116 | a3 contains the kernel thread payload, d7 - its argument
122 jra ret_from_exception
124 #if defined(CONFIG_COLDFIRE) || !defined(CONFIG_MMU)
126 #ifdef TRAP_DBG_INTERRUPT
132 movel %sp,%sp@- /* stack frame pointer argument */
135 jra ret_from_exception
139 /* save top of frame */
143 pea ret_from_exception
146 ENTRY(ret_from_user_signal)
147 moveq #__NR_sigreturn,%d0
150 ENTRY(ret_from_user_rt_signal)
151 movel #__NR_rt_sigreturn,%d0
157 movel #-ENOSYS,%sp@(PT_OFF_D0)| needed for strace
163 movel %sp@(PT_OFF_ORIG_D0),%d0
164 cmpl #NR_syscalls,%d0
167 movel #-ENOSYS,%sp@(PT_OFF_D0)
176 jra .Lret_from_exception
178 ENTRY(ret_from_signal)
179 movel %curptr@(TASK_STACK),%a1
180 tstb %a1@(TINFO_FLAGS+2)
183 1: RESTORE_SWITCH_STACK
185 /* on 68040 complete pending writebacks if any */
187 bfextu %sp@(PT_OFF_FORMATVEC){#0,#4},%d0
188 subql #7,%d0 | bus error frame ?
195 jra .Lret_from_exception
204 movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
207 tstb %a1@(TINFO_FLAGS+2)
209 cmpl #NR_syscalls,%d0
212 jbsr @(sys_call_table,%d0:l:4)@(0)
213 movel %d0,%sp@(PT_OFF_D0) | save the return value
216 movel %curptr@(TASK_STACK),%a1
217 movew %a1@(TINFO_FLAGS+2),%d0
218 jne syscall_exit_work
222 btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
223 bnes 1b | if so, skip resched, signals
233 ENTRY(ret_from_exception)
234 .Lret_from_exception:
235 btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
236 bnes 1f | if so, skip resched, signals
237 | only allow interrupts when we are really the last one on the
238 | kernel stack, otherwise stack overflow can occur during
239 | heavy interrupt load
243 movel %curptr@(TASK_STACK),%a1
244 moveb %a1@(TINFO_FLAGS+3),%d0
250 movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
259 subql #4,%sp | dummy return address
261 pea %sp@(SWITCH_STACK_SIZE)
262 bsrl do_notify_resume
266 jbra resume_userspace
269 bclr #7,%sp@(PT_OFF_SR) | clear trace bit in SR
276 jbra resume_userspace
279 /* This is the main interrupt handler for autovector interrupts */
281 ENTRY(auto_inthandler)
284 | put exception # in d0
285 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
289 movel %d0,%sp@- | put vector # on stack
290 auto_irqhandler_fixup = . + 2
291 jsr do_IRQ | process the IRQ
292 addql #8,%sp | pop parameters off stack
293 jra ret_from_exception
295 /* Handler for user defined interrupt vectors */
297 ENTRY(user_inthandler)
300 | put exception # in d0
301 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
302 user_irqvec_fixup = . + 2
306 movel %d0,%sp@- | put vector # on stack
307 jsr do_IRQ | process the IRQ
308 addql #8,%sp | pop parameters off stack
309 jra ret_from_exception
311 /* Handler for uninitialized and spurious interrupts */
313 ENTRY(bad_inthandler)
320 jra ret_from_exception
324 * Beware - when entering resume, prev (the current task) is
325 * in a0, next (the new task) is in a1,so don't change these
326 * registers until their contents are no longer needed.
330 movew %sr,%a0@(TASK_THREAD+THREAD_SR)
332 /* save fs (sfc,%dfc) (may be pointing to kernel memory) */
334 movew %d0,%a0@(TASK_THREAD+THREAD_FS)
337 /* it is better to use a movel here instead of a movew 8*) */
339 movel %d0,%a0@(TASK_THREAD+THREAD_USP)
341 /* save non-scratch registers on stack */
344 /* save current kernel stack pointer */
345 movel %sp,%a0@(TASK_THREAD+THREAD_KSP)
347 /* save floating point context */
348 #ifndef CONFIG_M68KFPU_EMU_ONLY
349 #ifdef CONFIG_M68KFPU_EMU
353 fsave %a0@(TASK_THREAD+THREAD_FPSTATE)
355 #if defined(CONFIG_M68060)
356 #if !defined(CPU_M68060_ONLY)
357 btst #3,m68k_cputype+3
360 /* The 060 FPU keeps status in bits 15-8 of the first longword */
361 tstb %a0@(TASK_THREAD+THREAD_FPSTATE+2)
363 #if !defined(CPU_M68060_ONLY)
366 #endif /* CONFIG_M68060 */
367 #if !defined(CPU_M68060_ONLY)
368 1: tstb %a0@(TASK_THREAD+THREAD_FPSTATE)
371 2: fmovemx %fp0-%fp7,%a0@(TASK_THREAD+THREAD_FPREG)
372 fmoveml %fpcr/%fpsr/%fpiar,%a0@(TASK_THREAD+THREAD_FPCNTL)
374 #endif /* CONFIG_M68KFPU_EMU_ONLY */
375 /* Return previous task in %d1 */
378 /* switch to new task (a1 contains new task) */
381 /* restore floating point context */
382 #ifndef CONFIG_M68KFPU_EMU_ONLY
383 #ifdef CONFIG_M68KFPU_EMU
387 #if defined(CONFIG_M68060)
388 #if !defined(CPU_M68060_ONLY)
389 btst #3,m68k_cputype+3
392 /* The 060 FPU keeps status in bits 15-8 of the first longword */
393 tstb %a1@(TASK_THREAD+THREAD_FPSTATE+2)
395 #if !defined(CPU_M68060_ONLY)
398 #endif /* CONFIG_M68060 */
399 #if !defined(CPU_M68060_ONLY)
400 1: tstb %a1@(TASK_THREAD+THREAD_FPSTATE)
403 2: fmovemx %a1@(TASK_THREAD+THREAD_FPREG),%fp0-%fp7
404 fmoveml %a1@(TASK_THREAD+THREAD_FPCNTL),%fpcr/%fpsr/%fpiar
405 3: frestore %a1@(TASK_THREAD+THREAD_FPSTATE)
407 #endif /* CONFIG_M68KFPU_EMU_ONLY */
409 /* restore the kernel stack pointer */
410 movel %a1@(TASK_THREAD+THREAD_KSP),%sp
412 /* restore non-scratch registers */
415 /* restore user stack pointer */
416 movel %a1@(TASK_THREAD+THREAD_USP),%a0
419 /* restore fs (sfc,%dfc) */
420 movew %a1@(TASK_THREAD+THREAD_FS),%a0
424 /* restore status register */
425 movew %a1@(TASK_THREAD+THREAD_SR),%sr
429 #endif /* CONFIG_MMU && !CONFIG_COLDFIRE */