Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Greg Ungerer | ece9ae6 | 2014-08-19 11:55:24 +1000 | [diff] [blame] | 2 | * entry.S -- interrupt and exception processing for ColdFire |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Greg Ungerer | 2502b667 | 2007-07-19 01:49:12 -0700 | [diff] [blame] | 4 | * Copyright (C) 1999-2007, Greg Ungerer (gerg@snapgear.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>, |
| 6 | * Kenneth Albanowski <kjahds@kjahds.com>, |
Philippe De Muyter | 623f523 | 2006-06-26 11:37:57 +1000 | [diff] [blame] | 7 | * Copyright (C) 2000 Lineo Inc. (www.lineo.com) |
| 8 | * Copyright (C) 2004-2006 Macq Electronique SA. (www.macqel.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Greg Ungerer | 1c83af5 | 2010-11-04 13:53:26 +1000 | [diff] [blame] | 38 | #ifdef CONFIG_COLDFIRE_SW_A7 |
| 39 | /* |
| 40 | * Define software copies of the supervisor and user stack pointers. |
| 41 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | .bss |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | sw_ksp: |
| 44 | .long 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | sw_usp: |
| 46 | .long 0 |
Greg Ungerer | 1c83af5 | 2010-11-04 13:53:26 +1000 | [diff] [blame] | 47 | #endif /* CONFIG_COLDFIRE_SW_A7 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | .globl inthandler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Philippe De Muyter | 623f523 | 2006-06-26 11:37:57 +1000 | [diff] [blame] | 58 | enosys: |
| 59 | mov.l #sys_ni_syscall,%d3 |
| 60 | bra 1f |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | ENTRY(system_call) |
Greg Ungerer | 61619b1 | 2011-06-22 13:50:44 +1000 | [diff] [blame] | 63 | SAVE_ALL_SYS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | move #0x2000,%sr /* enable intrs again */ |
Greg Ungerer | bbc6f1b | 2011-10-14 15:41:56 +1000 | [diff] [blame] | 65 | GET_CURRENT(%d2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Philippe De Muyter | 623f523 | 2006-06-26 11:37:57 +1000 | [diff] [blame] | 67 | cmpl #NR_syscalls,%d0 |
| 68 | jcc enosys |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | lea sys_call_table,%a0 |
Philippe De Muyter | 623f523 | 2006-06-26 11:37:57 +1000 | [diff] [blame] | 70 | lsll #2,%d0 /* movel %a0@(%d0:l:4),%d3 */ |
| 71 | movel %a0@(%d0),%d3 |
| 72 | jeq enosys |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Philippe De Muyter | 623f523 | 2006-06-26 11:37:57 +1000 | [diff] [blame] | 74 | 1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | movel %sp,%d2 /* get thread_info pointer */ |
| 76 | andl #-THREAD_SIZE,%d2 /* at start of kernel stack */ |
| 77 | movel %d2,%a0 |
Matt Waddel | 151941a | 2007-10-23 14:37:54 +1000 | [diff] [blame] | 78 | movel %a0@,%a1 /* save top of frame */ |
| 79 | movel %sp,%a1@(TASK_THREAD+THREAD_ESP0) |
Greg Ungerer | aa4d1f8 | 2011-03-29 15:55:36 +1000 | [diff] [blame] | 80 | btst #(TIF_SYSCALL_TRACE%8),%a0@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | bnes 1f |
| 82 | |
| 83 | movel %d3,%a0 |
| 84 | jbsr %a0@ |
Greg Ungerer | c84b564 | 2009-09-20 21:32:32 +1000 | [diff] [blame] | 85 | movel %d0,%sp@(PT_OFF_D0) /* save the return value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | jra ret_from_exception |
| 87 | 1: |
Greg Ungerer | c84b564 | 2009-09-20 21:32:32 +1000 | [diff] [blame] | 88 | movel #-ENOSYS,%d2 /* strace needs -ENOSYS in PT_OFF_D0 */ |
| 89 | movel %d2,PT_OFF_D0(%sp) /* on syscall entry */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | subql #4,%sp |
| 91 | SAVE_SWITCH_STACK |
Greg Ungerer | 55f411d | 2010-10-22 15:12:34 +1000 | [diff] [blame] | 92 | jbsr syscall_trace_enter |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | RESTORE_SWITCH_STACK |
| 94 | addql #4,%sp |
| 95 | movel %d3,%a0 |
| 96 | jbsr %a0@ |
Greg Ungerer | c84b564 | 2009-09-20 21:32:32 +1000 | [diff] [blame] | 97 | movel %d0,%sp@(PT_OFF_D0) /* save the return value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | subql #4,%sp /* dummy return address */ |
| 99 | SAVE_SWITCH_STACK |
Greg Ungerer | 55f411d | 2010-10-22 15:12:34 +1000 | [diff] [blame] | 100 | jbsr syscall_trace_leave |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | ret_from_signal: |
| 103 | RESTORE_SWITCH_STACK |
| 104 | addql #4,%sp |
| 105 | |
| 106 | ret_from_exception: |
Sebastian Siewior | 6c5a7d5 | 2008-05-01 12:17:49 +1000 | [diff] [blame] | 107 | move #0x2700,%sr /* disable intrs */ |
Greg Ungerer | c84b564 | 2009-09-20 21:32:32 +1000 | [diff] [blame] | 108 | btst #5,%sp@(PT_OFF_SR) /* check if returning to kernel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | jeq Luser_return /* if so, skip resched, signals */ |
| 110 | |
Sebastian Siewior | a19325a | 2008-05-01 12:16:29 +1000 | [diff] [blame] | 111 | #ifdef CONFIG_PREEMPT |
| 112 | movel %sp,%d1 /* get thread_info pointer */ |
| 113 | andl #-THREAD_SIZE,%d1 /* at base of kernel stack */ |
| 114 | movel %d1,%a0 |
Greg Ungerer | aa4d1f8 | 2011-03-29 15:55:36 +1000 | [diff] [blame] | 115 | movel %a0@(TINFO_FLAGS),%d1 /* get thread_info->flags */ |
Greg Ungerer | cddafa3 | 2010-09-13 14:10:45 +1000 | [diff] [blame] | 116 | andl #(1<<TIF_NEED_RESCHED),%d1 |
Sebastian Siewior | a19325a | 2008-05-01 12:16:29 +1000 | [diff] [blame] | 117 | jeq Lkernel_return |
| 118 | |
Greg Ungerer | aa4d1f8 | 2011-03-29 15:55:36 +1000 | [diff] [blame] | 119 | movel %a0@(TINFO_PREEMPT),%d1 |
Sebastian Siewior | a19325a | 2008-05-01 12:16:29 +1000 | [diff] [blame] | 120 | cmpl #0,%d1 |
| 121 | jne Lkernel_return |
| 122 | |
| 123 | pea Lkernel_return |
| 124 | jmp preempt_schedule_irq /* preempt the kernel */ |
| 125 | #endif |
| 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | Lkernel_return: |
| 128 | moveml %sp@,%d1-%d5/%a0-%a2 |
| 129 | lea %sp@(32),%sp /* space for 8 regs */ |
| 130 | movel %sp@+,%d0 |
| 131 | addql #4,%sp /* orig d0 */ |
| 132 | addl %sp@+,%sp /* stk adj */ |
| 133 | rte |
| 134 | |
| 135 | Luser_return: |
| 136 | movel %sp,%d1 /* get thread_info pointer */ |
| 137 | andl #-THREAD_SIZE,%d1 /* at base of kernel stack */ |
| 138 | movel %d1,%a0 |
Greg Ungerer | 8b3262c | 2012-01-16 16:46:04 +1000 | [diff] [blame] | 139 | moveb %a0@(TINFO_FLAGS+3),%d1 /* thread_info->flags (low 8 bits) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | jne Lwork_to_do /* still work to do */ |
| 141 | |
| 142 | Lreturn: |
Greg Ungerer | 1c83af5 | 2010-11-04 13:53:26 +1000 | [diff] [blame] | 143 | RESTORE_USER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | Lwork_to_do: |
Greg Ungerer | aa4d1f8 | 2011-03-29 15:55:36 +1000 | [diff] [blame] | 146 | movel %a0@(TINFO_FLAGS),%d1 /* get thread_info->flags */ |
Sebastian Siewior | 6c5a7d5 | 2008-05-01 12:17:49 +1000 | [diff] [blame] | 147 | move #0x2000,%sr /* enable intrs again */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | btst #TIF_NEED_RESCHED,%d1 |
| 149 | jne reschedule |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | Lsignal_return: |
| 152 | subql #4,%sp /* dummy return address */ |
| 153 | SAVE_SWITCH_STACK |
| 154 | pea %sp@(SWITCH_STACK_SIZE) |
Al Viro | a54f165 | 2012-04-24 01:46:23 -0400 | [diff] [blame] | 155 | jsr do_notify_resume |
Al Viro | 710e91e | 2010-10-11 17:09:20 -0400 | [diff] [blame] | 156 | addql #4,%sp |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | RESTORE_SWITCH_STACK |
| 158 | addql #4,%sp |
Al Viro | d1574df | 2010-10-11 23:29:28 -0400 | [diff] [blame] | 159 | jmp Luser_return |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * This is the generic interrupt handler (for all hardware interrupt |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 163 | * sources). Calls up to high level code to do all the work. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | */ |
| 165 | ENTRY(inthandler) |
Greg Ungerer | 61619b1 | 2011-06-22 13:50:44 +1000 | [diff] [blame] | 166 | SAVE_ALL_INT |
Greg Ungerer | bbc6f1b | 2011-10-14 15:41:56 +1000 | [diff] [blame] | 167 | GET_CURRENT(%d2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Greg Ungerer | c84b564 | 2009-09-20 21:32:32 +1000 | [diff] [blame] | 169 | movew %sp@(PT_OFF_FORMATVEC),%d0 /* put exception # in d0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | andl #0x03fc,%d0 /* mask out vector only */ |
| 171 | |
Greg Ungerer | 2502b667 | 2007-07-19 01:49:12 -0700 | [diff] [blame] | 172 | movel %sp,%sp@- /* push regs arg */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | lsrl #2,%d0 /* calculate real vector # */ |
Greg Ungerer | 2502b667 | 2007-07-19 01:49:12 -0700 | [diff] [blame] | 174 | movel %d0,%sp@- /* push vector number */ |
| 175 | jbsr do_IRQ /* call high level irq handler */ |
| 176 | lea %sp@(8),%sp /* pop args off stack */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Greg Ungerer | fb670fb | 2010-11-03 16:21:05 +1000 | [diff] [blame] | 178 | bra ret_from_exception |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | /* |
| 181 | * Beware - when entering resume, prev (the current task) is |
Greg Ungerer | f941f5c | 2011-05-05 22:32:12 +1000 | [diff] [blame] | 182 | * in a0, next (the new task) is in a1, so don't change these |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | * registers until their contents are no longer needed. |
| 184 | */ |
| 185 | ENTRY(resume) |
Greg Ungerer | f941f5c | 2011-05-05 22:32:12 +1000 | [diff] [blame] | 186 | movew %sr,%d1 /* save current status */ |
| 187 | movew %d1,%a0@(TASK_THREAD+THREAD_SR) |
| 188 | movel %a0,%d1 /* get prev thread in d1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | SAVE_SWITCH_STACK |
| 190 | movel %sp,%a0@(TASK_THREAD+THREAD_KSP) /* save kernel stack pointer */ |
Greg Ungerer | f941f5c | 2011-05-05 22:32:12 +1000 | [diff] [blame] | 191 | RDUSP /* movel %usp,%a3 */ |
| 192 | movel %a3,%a0@(TASK_THREAD+THREAD_USP) /* save thread user stack */ |
Greg Ungerer | bbc6f1b | 2011-10-14 15:41:56 +1000 | [diff] [blame] | 193 | #ifdef CONFIG_MMU |
| 194 | movel %a1,%a2 /* set new current */ |
| 195 | #endif |
Greg Ungerer | f941f5c | 2011-05-05 22:32:12 +1000 | [diff] [blame] | 196 | movel %a1@(TASK_THREAD+THREAD_USP),%a3 /* restore thread user stack */ |
| 197 | WRUSP /* movel %a3,%usp */ |
| 198 | movel %a1@(TASK_THREAD+THREAD_KSP),%sp /* restore new kernel stack */ |
| 199 | movew %a1@(TASK_THREAD+THREAD_SR),%d7 /* restore new status */ |
| 200 | movew %d7,%sr |
| 201 | RESTORE_SWITCH_STACK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | rts |
Greg Ungerer | f941f5c | 2011-05-05 22:32:12 +1000 | [diff] [blame] | 203 | |