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/traps.h>
40 #include <asm/unistd.h>
41 #include <asm/asm-offsets.h>
42 #include <asm/entry.h>
44 .globl system_call, buserr, trap, resume
46 .globl __sys_fork, __sys_clone, __sys_vfork
48 .globl auto_irqhandler_fixup
49 .globl user_irqvec_fixup
60 pea %sp@(SWITCH_STACK_SIZE)
73 pea %sp@(SWITCH_STACK_SIZE)
80 movel %sp,%a1 | switch_stack pointer
81 lea %sp@(SWITCH_STACK_SIZE),%a0 | pt_regs pointer
82 lea %sp@(-84),%sp | leave a gap
86 jra 1f | shared with rt_sigreturn()
88 ENTRY(sys_rt_sigreturn)
90 movel %sp,%a1 | switch_stack pointer
91 lea %sp@(SWITCH_STACK_SIZE),%a0 | pt_regs pointer
92 lea %sp@(-84),%sp | leave a gap
96 | [original pt_regs address] [original switch_stack address]
97 | [gap] [switch_stack] [pt_regs] [exception frame]
101 | stack contents now:
102 | [original pt_regs address] [original switch_stack address]
103 | [unused part of the gap] [moved switch_stack] [moved pt_regs]
104 | [replacement exception frame]
105 | return value of do_{rt_,}sigreturn() points to moved switch_stack.
107 movel %d0,%sp | discard the leftover junk
109 | stack contents now is just [syscall return address] [pt_regs] [frame]
111 movel %sp@(PT_OFF_D0+4),%d0
117 movel %sp,%sp@- | stack frame pointer argument
120 jra ret_from_exception
125 movel %sp,%sp@- | stack frame pointer argument
128 jra ret_from_exception
130 | After a fork we jump here directly from resume,
131 | so that %d1 contains the previous task
132 | schedule_tail now used regardless of CONFIG_SMP
137 jra ret_from_exception
139 ENTRY(ret_from_kernel_thread)
140 | a3 contains the kernel thread payload, d7 - its argument
146 jra ret_from_exception
148 #if defined(CONFIG_COLDFIRE) || !defined(CONFIG_MMU)
150 #ifdef TRAP_DBG_INTERRUPT
156 movel %sp,%sp@- /* stack frame pointer argument */
159 jra ret_from_exception
163 /* save top of frame */
167 pea ret_from_exception
170 ENTRY(ret_from_user_signal)
171 moveq #__NR_sigreturn,%d0
174 ENTRY(ret_from_user_rt_signal)
175 movel #__NR_rt_sigreturn,%d0
181 movel #-ENOSYS,%sp@(PT_OFF_D0)| needed for strace
184 jbsr syscall_trace_enter
187 addql #1,%d0 | optimization for cmpil #-1,%d0
189 movel %sp@(PT_OFF_ORIG_D0),%d0
190 cmpl #NR_syscalls,%d0
194 movel #-ENOSYS,%sp@(PT_OFF_D0)
200 jbsr syscall_trace_leave
203 jra .Lret_from_exception
212 movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
215 tstb %a1@(TINFO_FLAGS+2)
217 cmpl #NR_syscalls,%d0
220 jbsr @(sys_call_table,%d0:l:4)@(0)
221 movel %d0,%sp@(PT_OFF_D0) | save the return value
224 movel %curptr@(TASK_STACK),%a1
225 movew %a1@(TINFO_FLAGS+2),%d0
226 jne syscall_exit_work
230 btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
231 bnes 1b | if so, skip resched, signals
241 ENTRY(ret_from_exception)
242 .Lret_from_exception:
243 btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
244 bnes 1f | if so, skip resched, signals
245 | only allow interrupts when we are really the last one on the
246 | kernel stack, otherwise stack overflow can occur during
247 | heavy interrupt load
251 movel %curptr@(TASK_STACK),%a1
252 moveb %a1@(TINFO_FLAGS+3),%d0
258 movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
267 subql #4,%sp | dummy return address
269 pea %sp@(SWITCH_STACK_SIZE)
270 bsrl do_notify_resume
274 jbra resume_userspace
277 bclr #7,%sp@(PT_OFF_SR) | clear trace bit in SR
284 jbra resume_userspace
287 /* This is the main interrupt handler for autovector interrupts */
289 ENTRY(auto_inthandler)
292 | put exception # in d0
293 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
297 movel %d0,%sp@- | put vector # on stack
298 auto_irqhandler_fixup = . + 2
299 jsr do_IRQ | process the IRQ
300 addql #8,%sp | pop parameters off stack
301 jra ret_from_exception
303 /* Handler for user defined interrupt vectors */
305 ENTRY(user_inthandler)
308 | put exception # in d0
309 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
310 user_irqvec_fixup = . + 2
314 movel %d0,%sp@- | put vector # on stack
315 jsr do_IRQ | process the IRQ
316 addql #8,%sp | pop parameters off stack
317 jra ret_from_exception
319 /* Handler for uninitialized and spurious interrupts */
321 ENTRY(bad_inthandler)
328 jra ret_from_exception
332 * Beware - when entering resume, prev (the current task) is
333 * in a0, next (the new task) is in a1,so don't change these
334 * registers until their contents are no longer needed.
338 movew %sr,%a0@(TASK_THREAD+THREAD_SR)
340 /* save fs (sfc,%dfc) (may be pointing to kernel memory) */
342 movew %d0,%a0@(TASK_THREAD+THREAD_FC)
345 /* it is better to use a movel here instead of a movew 8*) */
347 movel %d0,%a0@(TASK_THREAD+THREAD_USP)
349 /* save non-scratch registers on stack */
352 /* save current kernel stack pointer */
353 movel %sp,%a0@(TASK_THREAD+THREAD_KSP)
355 /* save floating point context */
356 #ifndef CONFIG_M68KFPU_EMU_ONLY
357 #ifdef CONFIG_M68KFPU_EMU
361 fsave %a0@(TASK_THREAD+THREAD_FPSTATE)
363 #if defined(CONFIG_M68060)
364 #if !defined(CPU_M68060_ONLY)
365 btst #3,m68k_cputype+3
368 /* The 060 FPU keeps status in bits 15-8 of the first longword */
369 tstb %a0@(TASK_THREAD+THREAD_FPSTATE+2)
371 #if !defined(CPU_M68060_ONLY)
374 #endif /* CONFIG_M68060 */
375 #if !defined(CPU_M68060_ONLY)
376 1: tstb %a0@(TASK_THREAD+THREAD_FPSTATE)
379 2: fmovemx %fp0-%fp7,%a0@(TASK_THREAD+THREAD_FPREG)
380 fmoveml %fpcr/%fpsr/%fpiar,%a0@(TASK_THREAD+THREAD_FPCNTL)
382 #endif /* CONFIG_M68KFPU_EMU_ONLY */
383 /* Return previous task in %d1 */
386 /* switch to new task (a1 contains new task) */
389 /* restore floating point context */
390 #ifndef CONFIG_M68KFPU_EMU_ONLY
391 #ifdef CONFIG_M68KFPU_EMU
395 #if defined(CONFIG_M68060)
396 #if !defined(CPU_M68060_ONLY)
397 btst #3,m68k_cputype+3
400 /* The 060 FPU keeps status in bits 15-8 of the first longword */
401 tstb %a1@(TASK_THREAD+THREAD_FPSTATE+2)
403 #if !defined(CPU_M68060_ONLY)
406 #endif /* CONFIG_M68060 */
407 #if !defined(CPU_M68060_ONLY)
408 1: tstb %a1@(TASK_THREAD+THREAD_FPSTATE)
411 2: fmovemx %a1@(TASK_THREAD+THREAD_FPREG),%fp0-%fp7
412 fmoveml %a1@(TASK_THREAD+THREAD_FPCNTL),%fpcr/%fpsr/%fpiar
413 3: frestore %a1@(TASK_THREAD+THREAD_FPSTATE)
415 #endif /* CONFIG_M68KFPU_EMU_ONLY */
417 /* restore the kernel stack pointer */
418 movel %a1@(TASK_THREAD+THREAD_KSP),%sp
420 /* restore non-scratch registers */
423 /* restore user stack pointer */
424 movel %a1@(TASK_THREAD+THREAD_USP),%a0
427 /* restore fs (sfc,%dfc) */
428 movew %a1@(TASK_THREAD+THREAD_FC),%a0
432 /* restore status register */
433 movew %a1@(TASK_THREAD+THREAD_SR),%sr
437 #endif /* CONFIG_MMU && !CONFIG_COLDFIRE */