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)
78 ENTRY(sys_rt_sigreturn)
87 movel %sp,%sp@- | stack frame pointer argument
90 jra ret_from_exception
95 movel %sp,%sp@- | stack frame pointer argument
98 jra ret_from_exception
100 | After a fork we jump here directly from resume,
101 | so that %d1 contains the previous task
102 | schedule_tail now used regardless of CONFIG_SMP
107 jra ret_from_exception
109 ENTRY(ret_from_kernel_thread)
110 | a3 contains the kernel thread payload, d7 - its argument
116 jra ret_from_exception
118 #if defined(CONFIG_COLDFIRE) || !defined(CONFIG_MMU)
120 #ifdef TRAP_DBG_INTERRUPT
126 movel %sp,%sp@- /* stack frame pointer argument */
129 jra ret_from_exception
133 /* save top of frame */
137 pea ret_from_exception
140 ENTRY(ret_from_user_signal)
141 moveq #__NR_sigreturn,%d0
144 ENTRY(ret_from_user_rt_signal)
145 movel #__NR_rt_sigreturn,%d0
151 movel #-ENOSYS,%sp@(PT_OFF_D0)| needed for strace
157 movel %sp@(PT_OFF_ORIG_D0),%d0
158 cmpl #NR_syscalls,%d0
161 movel #-ENOSYS,%sp@(PT_OFF_D0)
170 jra .Lret_from_exception
172 ENTRY(ret_from_signal)
173 movel %curptr@(TASK_STACK),%a1
174 tstb %a1@(TINFO_FLAGS+2)
177 1: RESTORE_SWITCH_STACK
179 /* on 68040 complete pending writebacks if any */
181 bfextu %sp@(PT_OFF_FORMATVEC){#0,#4},%d0
182 subql #7,%d0 | bus error frame ?
189 jra .Lret_from_exception
198 movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
201 tstb %a1@(TINFO_FLAGS+2)
203 cmpl #NR_syscalls,%d0
206 jbsr @(sys_call_table,%d0:l:4)@(0)
207 movel %d0,%sp@(PT_OFF_D0) | save the return value
210 movel %curptr@(TASK_STACK),%a1
211 movew %a1@(TINFO_FLAGS+2),%d0
212 jne syscall_exit_work
216 btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
217 bnes 1b | if so, skip resched, signals
227 ENTRY(ret_from_exception)
228 .Lret_from_exception:
229 btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
230 bnes 1f | if so, skip resched, signals
231 | only allow interrupts when we are really the last one on the
232 | kernel stack, otherwise stack overflow can occur during
233 | heavy interrupt load
237 movel %curptr@(TASK_STACK),%a1
238 moveb %a1@(TINFO_FLAGS+3),%d0
244 movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
253 subql #4,%sp | dummy return address
255 pea %sp@(SWITCH_STACK_SIZE)
256 bsrl do_notify_resume
260 jbra resume_userspace
263 bclr #7,%sp@(PT_OFF_SR) | clear trace bit in SR
270 jbra resume_userspace
273 /* This is the main interrupt handler for autovector interrupts */
275 ENTRY(auto_inthandler)
278 | put exception # in d0
279 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
283 movel %d0,%sp@- | put vector # on stack
284 auto_irqhandler_fixup = . + 2
285 jsr do_IRQ | process the IRQ
286 addql #8,%sp | pop parameters off stack
287 jra ret_from_exception
289 /* Handler for user defined interrupt vectors */
291 ENTRY(user_inthandler)
294 | put exception # in d0
295 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
296 user_irqvec_fixup = . + 2
300 movel %d0,%sp@- | put vector # on stack
301 jsr do_IRQ | process the IRQ
302 addql #8,%sp | pop parameters off stack
303 jra ret_from_exception
305 /* Handler for uninitialized and spurious interrupts */
307 ENTRY(bad_inthandler)
314 jra ret_from_exception
318 * Beware - when entering resume, prev (the current task) is
319 * in a0, next (the new task) is in a1,so don't change these
320 * registers until their contents are no longer needed.
324 movew %sr,%a0@(TASK_THREAD+THREAD_SR)
326 /* save fs (sfc,%dfc) (may be pointing to kernel memory) */
328 movew %d0,%a0@(TASK_THREAD+THREAD_FS)
331 /* it is better to use a movel here instead of a movew 8*) */
333 movel %d0,%a0@(TASK_THREAD+THREAD_USP)
335 /* save non-scratch registers on stack */
338 /* save current kernel stack pointer */
339 movel %sp,%a0@(TASK_THREAD+THREAD_KSP)
341 /* save floating point context */
342 #ifndef CONFIG_M68KFPU_EMU_ONLY
343 #ifdef CONFIG_M68KFPU_EMU
347 fsave %a0@(TASK_THREAD+THREAD_FPSTATE)
349 #if defined(CONFIG_M68060)
350 #if !defined(CPU_M68060_ONLY)
351 btst #3,m68k_cputype+3
354 /* The 060 FPU keeps status in bits 15-8 of the first longword */
355 tstb %a0@(TASK_THREAD+THREAD_FPSTATE+2)
357 #if !defined(CPU_M68060_ONLY)
360 #endif /* CONFIG_M68060 */
361 #if !defined(CPU_M68060_ONLY)
362 1: tstb %a0@(TASK_THREAD+THREAD_FPSTATE)
365 2: fmovemx %fp0-%fp7,%a0@(TASK_THREAD+THREAD_FPREG)
366 fmoveml %fpcr/%fpsr/%fpiar,%a0@(TASK_THREAD+THREAD_FPCNTL)
368 #endif /* CONFIG_M68KFPU_EMU_ONLY */
369 /* Return previous task in %d1 */
372 /* switch to new task (a1 contains new task) */
375 /* restore floating point context */
376 #ifndef CONFIG_M68KFPU_EMU_ONLY
377 #ifdef CONFIG_M68KFPU_EMU
381 #if defined(CONFIG_M68060)
382 #if !defined(CPU_M68060_ONLY)
383 btst #3,m68k_cputype+3
386 /* The 060 FPU keeps status in bits 15-8 of the first longword */
387 tstb %a1@(TASK_THREAD+THREAD_FPSTATE+2)
389 #if !defined(CPU_M68060_ONLY)
392 #endif /* CONFIG_M68060 */
393 #if !defined(CPU_M68060_ONLY)
394 1: tstb %a1@(TASK_THREAD+THREAD_FPSTATE)
397 2: fmovemx %a1@(TASK_THREAD+THREAD_FPREG),%fp0-%fp7
398 fmoveml %a1@(TASK_THREAD+THREAD_FPCNTL),%fpcr/%fpsr/%fpiar
399 3: frestore %a1@(TASK_THREAD+THREAD_FPSTATE)
401 #endif /* CONFIG_M68KFPU_EMU_ONLY */
403 /* restore the kernel stack pointer */
404 movel %a1@(TASK_THREAD+THREAD_KSP),%sp
406 /* restore non-scratch registers */
409 /* restore user stack pointer */
410 movel %a1@(TASK_THREAD+THREAD_USP),%a0
413 /* restore fs (sfc,%dfc) */
414 movew %a1@(TASK_THREAD+THREAD_FS),%a0
418 /* restore status register */
419 movew %a1@(TASK_THREAD+THREAD_SR),%sr
423 #endif /* CONFIG_MMU && !CONFIG_COLDFIRE */