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/entry.h>
38 #include <asm/errno.h>
39 #include <asm/setup.h>
40 #include <asm/segment.h>
41 #include <asm/traps.h>
42 #include <asm/unistd.h>
44 #include <asm/asm-offsets.h>
46 .globl system_call, buserr, trap, resume
48 .globl sys_fork, sys_clone, sys_vfork
49 .globl ret_from_interrupt, bad_interrupt
50 .globl auto_irqhandler_fixup
51 .globl user_irqvec_fixup
57 movel %sp,%sp@- | stack frame pointer argument
60 jra .Lret_from_exception
65 movel %sp,%sp@- | stack frame pointer argument
68 jra .Lret_from_exception
70 | After a fork we jump here directly from resume,
71 | so that %d1 contains the previous task
72 | schedule_tail now used regardless of CONFIG_SMP
77 jra .Lret_from_exception
80 movel #-ENOSYS,%sp@(PT_OFF_D0)| needed for strace
86 movel %sp@(PT_OFF_ORIG_D0),%d0
90 movel #-ENOSYS,%sp@(PT_OFF_D0)
99 jra .Lret_from_exception
101 ENTRY(ret_from_signal)
102 movel %curptr@(TASK_STACK),%a1
103 tstb %a1@(TINFO_FLAGS+2)
106 1: RESTORE_SWITCH_STACK
108 /* on 68040 complete pending writebacks if any */
110 bfextu %sp@(PT_OFF_FORMATVEC){#0,#4},%d0
111 subql #7,%d0 | bus error frame ?
118 jra .Lret_from_exception
127 movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
130 tstb %a1@(TINFO_FLAGS+2)
132 cmpl #NR_syscalls,%d0
135 jbsr @(sys_call_table,%d0:l:4)@(0)
136 movel %d0,%sp@(PT_OFF_D0) | save the return value
139 movel %curptr@(TASK_STACK),%a1
140 movew %a1@(TINFO_FLAGS+2),%d0
141 jne syscall_exit_work
145 btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
146 bnes 1b | if so, skip resched, signals
156 ENTRY(ret_from_exception)
157 .Lret_from_exception:
158 btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
159 bnes 1f | if so, skip resched, signals
160 | only allow interrupts when we are really the last one on the
161 | kernel stack, otherwise stack overflow can occur during
162 | heavy interrupt load
166 movel %curptr@(TASK_STACK),%a1
167 moveb %a1@(TINFO_FLAGS+3),%d0
173 movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
182 subql #4,%sp | dummy return address
184 pea %sp@(SWITCH_STACK_SIZE)
189 jbra resume_userspace
192 bclr #7,%sp@(PT_OFF_SR) | clear trace bit in SR
199 jbra resume_userspace
202 /* This is the main interrupt handler for autovector interrupts */
204 ENTRY(auto_inthandler)
208 addqb #1,%a1@(TINFO_PREEMPT+1)
209 | put exception # in d0
210 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
214 movel %d0,%sp@- | put vector # on stack
215 auto_irqhandler_fixup = . + 2
216 jsr do_IRQ | process the IRQ
217 addql #8,%sp | pop parameters off stack
220 movel %curptr@(TASK_STACK),%a1
221 subqb #1,%a1@(TINFO_PREEMPT+1)
222 jeq ret_from_last_interrupt
226 ret_from_last_interrupt:
227 moveq #(~ALLOWINT>>8)&0xff,%d0
228 andb %sp@(PT_OFF_SR),%d0
231 /* check if we need to do software interrupts */
232 tstl irq_stat+CPUSTAT_SOFTIRQ_PENDING
233 jeq .Lret_from_exception
234 pea ret_from_exception
237 /* Handler for user defined interrupt vectors */
239 ENTRY(user_inthandler)
243 addqb #1,%a1@(TINFO_PREEMPT+1)
244 | put exception # in d0
245 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
246 user_irqvec_fixup = . + 2
250 movel %d0,%sp@- | put vector # on stack
251 jsr do_IRQ | process the IRQ
252 addql #8,%sp | pop parameters off stack
254 movel %curptr@(TASK_STACK),%a1
255 subqb #1,%a1@(TINFO_PREEMPT+1)
256 jeq ret_from_last_interrupt
259 /* Handler for uninitialized and spurious interrupts */
261 ENTRY(bad_inthandler)
265 addqb #1,%a1@(TINFO_PREEMPT+1)
271 movel %curptr@(TASK_STACK),%a1
272 subqb #1,%a1@(TINFO_PREEMPT+1)
273 jeq ret_from_last_interrupt
279 pea %sp@(SWITCH_STACK_SIZE)
287 pea %sp@(SWITCH_STACK_SIZE)
295 pea %sp@(SWITCH_STACK_SIZE)
307 ENTRY(sys_rt_sigreturn)
315 * Beware - when entering resume, prev (the current task) is
316 * in a0, next (the new task) is in a1,so don't change these
317 * registers until their contents are no longer needed.
321 movew %sr,%a0@(TASK_THREAD+THREAD_SR)
323 /* save fs (sfc,%dfc) (may be pointing to kernel memory) */
325 movew %d0,%a0@(TASK_THREAD+THREAD_FS)
328 /* it is better to use a movel here instead of a movew 8*) */
330 movel %d0,%a0@(TASK_THREAD+THREAD_USP)
332 /* save non-scratch registers on stack */
335 /* save current kernel stack pointer */
336 movel %sp,%a0@(TASK_THREAD+THREAD_KSP)
338 /* save floating point context */
339 #ifndef CONFIG_M68KFPU_EMU_ONLY
340 #ifdef CONFIG_M68KFPU_EMU
344 fsave %a0@(TASK_THREAD+THREAD_FPSTATE)
346 #if defined(CONFIG_M68060)
347 #if !defined(CPU_M68060_ONLY)
348 btst #3,m68k_cputype+3
351 /* The 060 FPU keeps status in bits 15-8 of the first longword */
352 tstb %a0@(TASK_THREAD+THREAD_FPSTATE+2)
354 #if !defined(CPU_M68060_ONLY)
357 #endif /* CONFIG_M68060 */
358 #if !defined(CPU_M68060_ONLY)
359 1: tstb %a0@(TASK_THREAD+THREAD_FPSTATE)
362 2: fmovemx %fp0-%fp7,%a0@(TASK_THREAD+THREAD_FPREG)
363 fmoveml %fpcr/%fpsr/%fpiar,%a0@(TASK_THREAD+THREAD_FPCNTL)
365 #endif /* CONFIG_M68KFPU_EMU_ONLY */
366 /* Return previous task in %d1 */
369 /* switch to new task (a1 contains new task) */
372 /* restore floating point context */
373 #ifndef CONFIG_M68KFPU_EMU_ONLY
374 #ifdef CONFIG_M68KFPU_EMU
378 #if defined(CONFIG_M68060)
379 #if !defined(CPU_M68060_ONLY)
380 btst #3,m68k_cputype+3
383 /* The 060 FPU keeps status in bits 15-8 of the first longword */
384 tstb %a1@(TASK_THREAD+THREAD_FPSTATE+2)
386 #if !defined(CPU_M68060_ONLY)
389 #endif /* CONFIG_M68060 */
390 #if !defined(CPU_M68060_ONLY)
391 1: tstb %a1@(TASK_THREAD+THREAD_FPSTATE)
394 2: fmovemx %a1@(TASK_THREAD+THREAD_FPREG),%fp0-%fp7
395 fmoveml %a1@(TASK_THREAD+THREAD_FPCNTL),%fpcr/%fpsr/%fpiar
396 3: frestore %a1@(TASK_THREAD+THREAD_FPSTATE)
398 #endif /* CONFIG_M68KFPU_EMU_ONLY */
400 /* restore the kernel stack pointer */
401 movel %a1@(TASK_THREAD+THREAD_KSP),%sp
403 /* restore non-scratch registers */
406 /* restore user stack pointer */
407 movel %a1@(TASK_THREAD+THREAD_USP),%a0
410 /* restore fs (sfc,%dfc) */
411 movew %a1@(TASK_THREAD+THREAD_FS),%a0
415 /* restore status register */
416 movew %a1@(TASK_THREAD+THREAD_SR),%sr