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 pea %sp@(SWITCH_STACK_SIZE)
81 movel %sp,%sp@- | switch_stack pointer
82 pea %sp@(SWITCH_STACK_SIZE+4) | pt_regs pointer
88 ENTRY(sys_rt_sigreturn)
90 movel %sp,%sp@- | switch_stack pointer
91 pea %sp@(SWITCH_STACK_SIZE+4) | pt_regs pointer
100 movel %sp,%sp@- | stack frame pointer argument
103 jra ret_from_exception
108 movel %sp,%sp@- | stack frame pointer argument
111 jra ret_from_exception
113 | After a fork we jump here directly from resume,
114 | so that %d1 contains the previous task
115 | schedule_tail now used regardless of CONFIG_SMP
120 jra ret_from_exception
122 ENTRY(ret_from_kernel_thread)
123 | a3 contains the kernel thread payload, d7 - its argument
129 jra ret_from_exception
131 #if defined(CONFIG_COLDFIRE) || !defined(CONFIG_MMU)
133 #ifdef TRAP_DBG_INTERRUPT
139 movel %sp,%sp@- /* stack frame pointer argument */
142 jra ret_from_exception
146 /* save top of frame */
150 pea ret_from_exception
153 ENTRY(ret_from_user_signal)
154 moveq #__NR_sigreturn,%d0
157 ENTRY(ret_from_user_rt_signal)
158 movel #__NR_rt_sigreturn,%d0
164 movel #-ENOSYS,%sp@(PT_OFF_D0)| needed for strace
170 movel %sp@(PT_OFF_ORIG_D0),%d0
171 cmpl #NR_syscalls,%d0
174 movel #-ENOSYS,%sp@(PT_OFF_D0)
183 jra .Lret_from_exception
185 ENTRY(ret_from_signal)
186 movel %curptr@(TASK_STACK),%a1
187 tstb %a1@(TINFO_FLAGS+2)
190 1: RESTORE_SWITCH_STACK
192 /* on 68040 complete pending writebacks if any */
194 bfextu %sp@(PT_OFF_FORMATVEC){#0,#4},%d0
195 subql #7,%d0 | bus error frame ?
202 jra .Lret_from_exception
211 movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
214 tstb %a1@(TINFO_FLAGS+2)
216 cmpl #NR_syscalls,%d0
219 jbsr @(sys_call_table,%d0:l:4)@(0)
220 movel %d0,%sp@(PT_OFF_D0) | save the return value
223 movel %curptr@(TASK_STACK),%a1
224 movew %a1@(TINFO_FLAGS+2),%d0
225 jne syscall_exit_work
229 btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
230 bnes 1b | if so, skip resched, signals
240 ENTRY(ret_from_exception)
241 .Lret_from_exception:
242 btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
243 bnes 1f | if so, skip resched, signals
244 | only allow interrupts when we are really the last one on the
245 | kernel stack, otherwise stack overflow can occur during
246 | heavy interrupt load
250 movel %curptr@(TASK_STACK),%a1
251 moveb %a1@(TINFO_FLAGS+3),%d0
257 movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
266 subql #4,%sp | dummy return address
268 pea %sp@(SWITCH_STACK_SIZE)
269 bsrl do_notify_resume
273 jbra resume_userspace
276 bclr #7,%sp@(PT_OFF_SR) | clear trace bit in SR
283 jbra resume_userspace
286 /* This is the main interrupt handler for autovector interrupts */
288 ENTRY(auto_inthandler)
291 | put exception # in d0
292 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
296 movel %d0,%sp@- | put vector # on stack
297 auto_irqhandler_fixup = . + 2
298 jsr do_IRQ | process the IRQ
299 addql #8,%sp | pop parameters off stack
300 jra ret_from_exception
302 /* Handler for user defined interrupt vectors */
304 ENTRY(user_inthandler)
307 | put exception # in d0
308 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
309 user_irqvec_fixup = . + 2
313 movel %d0,%sp@- | put vector # on stack
314 jsr do_IRQ | process the IRQ
315 addql #8,%sp | pop parameters off stack
316 jra ret_from_exception
318 /* Handler for uninitialized and spurious interrupts */
320 ENTRY(bad_inthandler)
327 jra ret_from_exception
331 * Beware - when entering resume, prev (the current task) is
332 * in a0, next (the new task) is in a1,so don't change these
333 * registers until their contents are no longer needed.
337 movew %sr,%a0@(TASK_THREAD+THREAD_SR)
339 /* save fs (sfc,%dfc) (may be pointing to kernel memory) */
341 movew %d0,%a0@(TASK_THREAD+THREAD_FS)
344 /* it is better to use a movel here instead of a movew 8*) */
346 movel %d0,%a0@(TASK_THREAD+THREAD_USP)
348 /* save non-scratch registers on stack */
351 /* save current kernel stack pointer */
352 movel %sp,%a0@(TASK_THREAD+THREAD_KSP)
354 /* save floating point context */
355 #ifndef CONFIG_M68KFPU_EMU_ONLY
356 #ifdef CONFIG_M68KFPU_EMU
360 fsave %a0@(TASK_THREAD+THREAD_FPSTATE)
362 #if defined(CONFIG_M68060)
363 #if !defined(CPU_M68060_ONLY)
364 btst #3,m68k_cputype+3
367 /* The 060 FPU keeps status in bits 15-8 of the first longword */
368 tstb %a0@(TASK_THREAD+THREAD_FPSTATE+2)
370 #if !defined(CPU_M68060_ONLY)
373 #endif /* CONFIG_M68060 */
374 #if !defined(CPU_M68060_ONLY)
375 1: tstb %a0@(TASK_THREAD+THREAD_FPSTATE)
378 2: fmovemx %fp0-%fp7,%a0@(TASK_THREAD+THREAD_FPREG)
379 fmoveml %fpcr/%fpsr/%fpiar,%a0@(TASK_THREAD+THREAD_FPCNTL)
381 #endif /* CONFIG_M68KFPU_EMU_ONLY */
382 /* Return previous task in %d1 */
385 /* switch to new task (a1 contains new task) */
388 /* restore floating point context */
389 #ifndef CONFIG_M68KFPU_EMU_ONLY
390 #ifdef CONFIG_M68KFPU_EMU
394 #if defined(CONFIG_M68060)
395 #if !defined(CPU_M68060_ONLY)
396 btst #3,m68k_cputype+3
399 /* The 060 FPU keeps status in bits 15-8 of the first longword */
400 tstb %a1@(TASK_THREAD+THREAD_FPSTATE+2)
402 #if !defined(CPU_M68060_ONLY)
405 #endif /* CONFIG_M68060 */
406 #if !defined(CPU_M68060_ONLY)
407 1: tstb %a1@(TASK_THREAD+THREAD_FPSTATE)
410 2: fmovemx %a1@(TASK_THREAD+THREAD_FPREG),%fp0-%fp7
411 fmoveml %a1@(TASK_THREAD+THREAD_FPCNTL),%fpcr/%fpsr/%fpiar
412 3: frestore %a1@(TASK_THREAD+THREAD_FPSTATE)
414 #endif /* CONFIG_M68KFPU_EMU_ONLY */
416 /* restore the kernel stack pointer */
417 movel %a1@(TASK_THREAD+THREAD_KSP),%sp
419 /* restore non-scratch registers */
422 /* restore user stack pointer */
423 movel %a1@(TASK_THREAD+THREAD_USP),%a0
426 /* restore fs (sfc,%dfc) */
427 movew %a1@(TASK_THREAD+THREAD_FS),%a0
431 /* restore status register */
432 movew %a1@(TASK_THREAD+THREAD_SR),%sr
436 #endif /* CONFIG_MMU && !CONFIG_COLDFIRE */