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
187 movel %sp@(PT_OFF_ORIG_D0),%d0
188 cmpl #NR_syscalls,%d0
191 movel #-ENOSYS,%sp@(PT_OFF_D0)
200 jra .Lret_from_exception
209 movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
212 tstb %a1@(TINFO_FLAGS+2)
214 cmpl #NR_syscalls,%d0
217 jbsr @(sys_call_table,%d0:l:4)@(0)
218 movel %d0,%sp@(PT_OFF_D0) | save the return value
221 movel %curptr@(TASK_STACK),%a1
222 movew %a1@(TINFO_FLAGS+2),%d0
223 jne syscall_exit_work
227 btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
228 bnes 1b | if so, skip resched, signals
238 ENTRY(ret_from_exception)
239 .Lret_from_exception:
240 btst #5,%sp@(PT_OFF_SR) | check if returning to kernel
241 bnes 1f | if so, skip resched, signals
242 | only allow interrupts when we are really the last one on the
243 | kernel stack, otherwise stack overflow can occur during
244 | heavy interrupt load
248 movel %curptr@(TASK_STACK),%a1
249 moveb %a1@(TINFO_FLAGS+3),%d0
255 movel %sp,%curptr@(TASK_THREAD+THREAD_ESP0)
264 subql #4,%sp | dummy return address
266 pea %sp@(SWITCH_STACK_SIZE)
267 bsrl do_notify_resume
271 jbra resume_userspace
274 bclr #7,%sp@(PT_OFF_SR) | clear trace bit in SR
281 jbra resume_userspace
284 /* This is the main interrupt handler for autovector interrupts */
286 ENTRY(auto_inthandler)
289 | put exception # in d0
290 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
294 movel %d0,%sp@- | put vector # on stack
295 auto_irqhandler_fixup = . + 2
296 jsr do_IRQ | process the IRQ
297 addql #8,%sp | pop parameters off stack
298 jra ret_from_exception
300 /* Handler for user defined interrupt vectors */
302 ENTRY(user_inthandler)
305 | put exception # in d0
306 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
307 user_irqvec_fixup = . + 2
311 movel %d0,%sp@- | put vector # on stack
312 jsr do_IRQ | process the IRQ
313 addql #8,%sp | pop parameters off stack
314 jra ret_from_exception
316 /* Handler for uninitialized and spurious interrupts */
318 ENTRY(bad_inthandler)
325 jra ret_from_exception
329 * Beware - when entering resume, prev (the current task) is
330 * in a0, next (the new task) is in a1,so don't change these
331 * registers until their contents are no longer needed.
335 movew %sr,%a0@(TASK_THREAD+THREAD_SR)
337 /* save fs (sfc,%dfc) (may be pointing to kernel memory) */
339 movew %d0,%a0@(TASK_THREAD+THREAD_FC)
342 /* it is better to use a movel here instead of a movew 8*) */
344 movel %d0,%a0@(TASK_THREAD+THREAD_USP)
346 /* save non-scratch registers on stack */
349 /* save current kernel stack pointer */
350 movel %sp,%a0@(TASK_THREAD+THREAD_KSP)
352 /* save floating point context */
353 #ifndef CONFIG_M68KFPU_EMU_ONLY
354 #ifdef CONFIG_M68KFPU_EMU
358 fsave %a0@(TASK_THREAD+THREAD_FPSTATE)
360 #if defined(CONFIG_M68060)
361 #if !defined(CPU_M68060_ONLY)
362 btst #3,m68k_cputype+3
365 /* The 060 FPU keeps status in bits 15-8 of the first longword */
366 tstb %a0@(TASK_THREAD+THREAD_FPSTATE+2)
368 #if !defined(CPU_M68060_ONLY)
371 #endif /* CONFIG_M68060 */
372 #if !defined(CPU_M68060_ONLY)
373 1: tstb %a0@(TASK_THREAD+THREAD_FPSTATE)
376 2: fmovemx %fp0-%fp7,%a0@(TASK_THREAD+THREAD_FPREG)
377 fmoveml %fpcr/%fpsr/%fpiar,%a0@(TASK_THREAD+THREAD_FPCNTL)
379 #endif /* CONFIG_M68KFPU_EMU_ONLY */
380 /* Return previous task in %d1 */
383 /* switch to new task (a1 contains new task) */
386 /* restore floating point context */
387 #ifndef CONFIG_M68KFPU_EMU_ONLY
388 #ifdef CONFIG_M68KFPU_EMU
392 #if defined(CONFIG_M68060)
393 #if !defined(CPU_M68060_ONLY)
394 btst #3,m68k_cputype+3
397 /* The 060 FPU keeps status in bits 15-8 of the first longword */
398 tstb %a1@(TASK_THREAD+THREAD_FPSTATE+2)
400 #if !defined(CPU_M68060_ONLY)
403 #endif /* CONFIG_M68060 */
404 #if !defined(CPU_M68060_ONLY)
405 1: tstb %a1@(TASK_THREAD+THREAD_FPSTATE)
408 2: fmovemx %a1@(TASK_THREAD+THREAD_FPREG),%fp0-%fp7
409 fmoveml %a1@(TASK_THREAD+THREAD_FPCNTL),%fpcr/%fpsr/%fpiar
410 3: frestore %a1@(TASK_THREAD+THREAD_FPSTATE)
412 #endif /* CONFIG_M68KFPU_EMU_ONLY */
414 /* restore the kernel stack pointer */
415 movel %a1@(TASK_THREAD+THREAD_KSP),%sp
417 /* restore non-scratch registers */
420 /* restore user stack pointer */
421 movel %a1@(TASK_THREAD+THREAD_USP),%a0
424 /* restore fs (sfc,%dfc) */
425 movew %a1@(TASK_THREAD+THREAD_FC),%a0
429 /* restore status register */
430 movew %a1@(TASK_THREAD+THREAD_SR),%sr
434 #endif /* CONFIG_MMU && !CONFIG_COLDFIRE */