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
48 .globl ret_from_interrupt, bad_interrupt
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)
279 addqb #1,%a1@(TINFO_PREEMPT+1)
280 | put exception # in d0
281 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
285 movel %d0,%sp@- | put vector # on stack
286 auto_irqhandler_fixup = . + 2
287 jsr do_IRQ | process the IRQ
288 addql #8,%sp | pop parameters off stack
291 movel %curptr@(TASK_STACK),%a1
292 subqb #1,%a1@(TINFO_PREEMPT+1)
293 jeq ret_from_last_interrupt
297 ret_from_last_interrupt:
298 moveq #(~ALLOWINT>>8)&0xff,%d0
299 andb %sp@(PT_OFF_SR),%d0
302 /* check if we need to do software interrupts */
303 tstl irq_stat+CPUSTAT_SOFTIRQ_PENDING
304 jeq .Lret_from_exception
305 pea ret_from_exception
308 /* Handler for user defined interrupt vectors */
310 ENTRY(user_inthandler)
314 addqb #1,%a1@(TINFO_PREEMPT+1)
315 | put exception # in d0
316 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
317 user_irqvec_fixup = . + 2
321 movel %d0,%sp@- | put vector # on stack
322 jsr do_IRQ | process the IRQ
323 addql #8,%sp | pop parameters off stack
325 movel %curptr@(TASK_STACK),%a1
326 subqb #1,%a1@(TINFO_PREEMPT+1)
327 jeq ret_from_last_interrupt
330 /* Handler for uninitialized and spurious interrupts */
332 ENTRY(bad_inthandler)
336 addqb #1,%a1@(TINFO_PREEMPT+1)
342 movel %curptr@(TASK_STACK),%a1
343 subqb #1,%a1@(TINFO_PREEMPT+1)
344 jeq ret_from_last_interrupt
350 * Beware - when entering resume, prev (the current task) is
351 * in a0, next (the new task) is in a1,so don't change these
352 * registers until their contents are no longer needed.
356 movew %sr,%a0@(TASK_THREAD+THREAD_SR)
358 /* save fs (sfc,%dfc) (may be pointing to kernel memory) */
360 movew %d0,%a0@(TASK_THREAD+THREAD_FS)
363 /* it is better to use a movel here instead of a movew 8*) */
365 movel %d0,%a0@(TASK_THREAD+THREAD_USP)
367 /* save non-scratch registers on stack */
370 /* save current kernel stack pointer */
371 movel %sp,%a0@(TASK_THREAD+THREAD_KSP)
373 /* save floating point context */
374 #ifndef CONFIG_M68KFPU_EMU_ONLY
375 #ifdef CONFIG_M68KFPU_EMU
379 fsave %a0@(TASK_THREAD+THREAD_FPSTATE)
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 %a0@(TASK_THREAD+THREAD_FPSTATE+2)
389 #if !defined(CPU_M68060_ONLY)
392 #endif /* CONFIG_M68060 */
393 #if !defined(CPU_M68060_ONLY)
394 1: tstb %a0@(TASK_THREAD+THREAD_FPSTATE)
397 2: fmovemx %fp0-%fp7,%a0@(TASK_THREAD+THREAD_FPREG)
398 fmoveml %fpcr/%fpsr/%fpiar,%a0@(TASK_THREAD+THREAD_FPCNTL)
400 #endif /* CONFIG_M68KFPU_EMU_ONLY */
401 /* Return previous task in %d1 */
404 /* switch to new task (a1 contains new task) */
407 /* restore floating point context */
408 #ifndef CONFIG_M68KFPU_EMU_ONLY
409 #ifdef CONFIG_M68KFPU_EMU
413 #if defined(CONFIG_M68060)
414 #if !defined(CPU_M68060_ONLY)
415 btst #3,m68k_cputype+3
418 /* The 060 FPU keeps status in bits 15-8 of the first longword */
419 tstb %a1@(TASK_THREAD+THREAD_FPSTATE+2)
421 #if !defined(CPU_M68060_ONLY)
424 #endif /* CONFIG_M68060 */
425 #if !defined(CPU_M68060_ONLY)
426 1: tstb %a1@(TASK_THREAD+THREAD_FPSTATE)
429 2: fmovemx %a1@(TASK_THREAD+THREAD_FPREG),%fp0-%fp7
430 fmoveml %a1@(TASK_THREAD+THREAD_FPCNTL),%fpcr/%fpsr/%fpiar
431 3: frestore %a1@(TASK_THREAD+THREAD_FPSTATE)
433 #endif /* CONFIG_M68KFPU_EMU_ONLY */
435 /* restore the kernel stack pointer */
436 movel %a1@(TASK_THREAD+THREAD_KSP),%sp
438 /* restore non-scratch registers */
441 /* restore user stack pointer */
442 movel %a1@(TASK_THREAD+THREAD_USP),%a0
445 /* restore fs (sfc,%dfc) */
446 movew %a1@(TASK_THREAD+THREAD_FS),%a0
450 /* restore status register */
451 movew %a1@(TASK_THREAD+THREAD_SR),%sr
455 #endif /* CONFIG_MMU && !CONFIG_COLDFIRE */