1/* 2 * entry.S -- interrupt and exception processing for ColdFire 3 * 4 * Copyright (C) 1999-2007, Greg Ungerer (gerg@snapgear.com) 5 * Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>, 6 * Kenneth Albanowski <kjahds@kjahds.com>, 7 * Copyright (C) 2000 Lineo Inc. (www.lineo.com) 8 * Copyright (C) 2004-2006 Macq Electronique SA. (www.macqel.com) 9 * 10 * Based on: 11 * 12 * linux/arch/m68k/kernel/entry.S 13 * 14 * Copyright (C) 1991, 1992 Linus Torvalds 15 * 16 * This file is subject to the terms and conditions of the GNU General Public 17 * License. See the file README.legal in the main directory of this archive 18 * for more details. 19 * 20 * Linux/m68k support by Hamish Macdonald 21 * 22 * 68060 fixes by Jesper Skov 23 * ColdFire support by Greg Ungerer (gerg@snapgear.com) 24 * 5307 fixes by David W. Miller 25 * linux 2.4 support David McCullough <davidm@snapgear.com> 26 * Bug, speed and maintainability fixes by Philippe De Muyter <phdm@macqel.be> 27 */ 28 29#include <linux/linkage.h> 30#include <asm/unistd.h> 31#include <asm/thread_info.h> 32#include <asm/errno.h> 33#include <asm/setup.h> 34#include <asm/segment.h> 35#include <asm/asm-offsets.h> 36#include <asm/entry.h> 37 38#ifdef CONFIG_COLDFIRE_SW_A7 39/* 40 * Define software copies of the supervisor and user stack pointers. 41 */ 42.bss 43sw_ksp: 44.long 0 45sw_usp: 46.long 0 47#endif /* CONFIG_COLDFIRE_SW_A7 */ 48 49.text 50 51.globl system_call 52.globl resume 53.globl ret_from_exception 54.globl ret_from_signal 55.globl sys_call_table 56.globl inthandler 57 58enosys: 59 mov.l #sys_ni_syscall,%d3 60 bra 1f 61 62ENTRY(system_call) 63 SAVE_ALL_SYS 64 move #0x2000,%sr /* enable intrs again */ 65 GET_CURRENT(%d2) 66 67 cmpl #NR_syscalls,%d0 68 jcc enosys 69 lea sys_call_table,%a0 70 lsll #2,%d0 /* movel %a0@(%d0:l:4),%d3 */ 71 movel %a0@(%d0),%d3 72 jeq enosys 73 741: 75 movel %sp,%d2 /* get thread_info pointer */ 76 andl #-THREAD_SIZE,%d2 /* at start of kernel stack */ 77 movel %d2,%a0 78 movel %a0@,%a1 /* save top of frame */ 79 movel %sp,%a1@(TASK_THREAD+THREAD_ESP0) 80 btst #(TIF_SYSCALL_TRACE%8),%a0@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8) 81 bnes 1f 82 83 movel %d3,%a0 84 jbsr %a0@ 85 movel %d0,%sp@(PT_OFF_D0) /* save the return value */ 86 jra ret_from_exception 871: 88 movel #-ENOSYS,%d2 /* strace needs -ENOSYS in PT_OFF_D0 */ 89 movel %d2,PT_OFF_D0(%sp) /* on syscall entry */ 90 subql #4,%sp 91 SAVE_SWITCH_STACK 92 jbsr syscall_trace_enter 93 RESTORE_SWITCH_STACK 94 addql #4,%sp 95 addql #1,%d0 96 jeq ret_from_exception 97 movel %d3,%a0 98 jbsr %a0@ 99 movel %d0,%sp@(PT_OFF_D0) /* save the return value */ 100 subql #4,%sp /* dummy return address */ 101 SAVE_SWITCH_STACK 102 jbsr syscall_trace_leave 103 104ret_from_signal: 105 RESTORE_SWITCH_STACK 106 addql #4,%sp 107 108ret_from_exception: 109 move #0x2700,%sr /* disable intrs */ 110 btst #5,%sp@(PT_OFF_SR) /* check if returning to kernel */ 111 jeq Luser_return /* if so, skip resched, signals */ 112 113#ifdef CONFIG_PREEMPT 114 movel %sp,%d1 /* get thread_info pointer */ 115 andl #-THREAD_SIZE,%d1 /* at base of kernel stack */ 116 movel %d1,%a0 117 movel %a0@(TINFO_FLAGS),%d1 /* get thread_info->flags */ 118 andl #(1<<TIF_NEED_RESCHED),%d1 119 jeq Lkernel_return 120 121 movel %a0@(TINFO_PREEMPT),%d1 122 cmpl #0,%d1 123 jne Lkernel_return 124 125 pea Lkernel_return 126 jmp preempt_schedule_irq /* preempt the kernel */ 127#endif 128 129Lkernel_return: 130 moveml %sp@,%d1-%d5/%a0-%a2 131 lea %sp@(32),%sp /* space for 8 regs */ 132 movel %sp@+,%d0 133 addql #4,%sp /* orig d0 */ 134 addl %sp@+,%sp /* stk adj */ 135 rte 136 137Luser_return: 138 movel %sp,%d1 /* get thread_info pointer */ 139 andl #-THREAD_SIZE,%d1 /* at base of kernel stack */ 140 movel %d1,%a0 141 moveb %a0@(TINFO_FLAGS+3),%d1 /* thread_info->flags (low 8 bits) */ 142 jne Lwork_to_do /* still work to do */ 143 144Lreturn: 145 RESTORE_USER 146 147Lwork_to_do: 148 movel %a0@(TINFO_FLAGS),%d1 /* get thread_info->flags */ 149 move #0x2000,%sr /* enable intrs again */ 150 btst #TIF_NEED_RESCHED,%d1 151 jne reschedule 152 153Lsignal_return: 154 subql #4,%sp /* dummy return address */ 155 SAVE_SWITCH_STACK 156 pea %sp@(SWITCH_STACK_SIZE) 157 jsr do_notify_resume 158 addql #4,%sp 159 RESTORE_SWITCH_STACK 160 addql #4,%sp 161 jmp Luser_return 162 163/* 164 * This is the generic interrupt handler (for all hardware interrupt 165 * sources). Calls up to high level code to do all the work. 166 */ 167ENTRY(inthandler) 168 SAVE_ALL_INT 169 GET_CURRENT(%d2) 170 171 movew %sp@(PT_OFF_FORMATVEC),%d0 /* put exception # in d0 */ 172 andl #0x03fc,%d0 /* mask out vector only */ 173 174 movel %sp,%sp@- /* push regs arg */ 175 lsrl #2,%d0 /* calculate real vector # */ 176 movel %d0,%sp@- /* push vector number */ 177 jbsr do_IRQ /* call high level irq handler */ 178 lea %sp@(8),%sp /* pop args off stack */ 179 180 bra ret_from_exception 181 182/* 183 * Beware - when entering resume, prev (the current task) is 184 * in a0, next (the new task) is in a1, so don't change these 185 * registers until their contents are no longer needed. 186 */ 187ENTRY(resume) 188 movew %sr,%d1 /* save current status */ 189 movew %d1,%a0@(TASK_THREAD+THREAD_SR) 190 movel %a0,%d1 /* get prev thread in d1 */ 191 SAVE_SWITCH_STACK 192 movel %sp,%a0@(TASK_THREAD+THREAD_KSP) /* save kernel stack pointer */ 193 RDUSP /* movel %usp,%a3 */ 194 movel %a3,%a0@(TASK_THREAD+THREAD_USP) /* save thread user stack */ 195#ifdef CONFIG_MMU 196 movel %a1,%a2 /* set new current */ 197#endif 198 movel %a1@(TASK_THREAD+THREAD_USP),%a3 /* restore thread user stack */ 199 WRUSP /* movel %a3,%usp */ 200 movel %a1@(TASK_THREAD+THREAD_KSP),%sp /* restore new kernel stack */ 201 movew %a1@(TASK_THREAD+THREAD_SR),%d7 /* restore new status */ 202 movew %d7,%sr 203 RESTORE_SWITCH_STACK 204 rts 205 206