blob: e1debc8285efa648a65640e303d18d0f8434c4b9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m68knommu/platform/5307/entry.S
3 *
Greg Ungerer2502b6672007-07-19 01:49:12 -07004 * Copyright (C) 1999-2007, Greg Ungerer (gerg@snapgear.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>,
6 * Kenneth Albanowski <kjahds@kjahds.com>,
Philippe De Muyter623f5232006-06-26 11:37:57 +10007 * Copyright (C) 2000 Lineo Inc. (www.lineo.com)
8 * Copyright (C) 2004-2006 Macq Electronique SA. (www.macqel.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
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 Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/sys.h>
30#include <linux/linkage.h>
31#include <asm/unistd.h>
32#include <asm/thread_info.h>
33#include <asm/errno.h>
34#include <asm/setup.h>
35#include <asm/segment.h>
36#include <asm/asm-offsets.h>
37#include <asm/entry.h>
38
39.bss
40
41sw_ksp:
42.long 0
43
44sw_usp:
45.long 0
46
47.text
48
49.globl system_call
50.globl resume
51.globl ret_from_exception
52.globl ret_from_signal
53.globl sys_call_table
54.globl ret_from_interrupt
55.globl inthandler
56.globl fasthandler
57
Philippe De Muyter623f5232006-06-26 11:37:57 +100058enosys:
59 mov.l #sys_ni_syscall,%d3
60 bra 1f
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062ENTRY(system_call)
63 SAVE_ALL
64 move #0x2000,%sr /* enable intrs again */
65
Philippe De Muyter623f5232006-06-26 11:37:57 +100066 cmpl #NR_syscalls,%d0
67 jcc enosys
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 lea sys_call_table,%a0
Philippe De Muyter623f5232006-06-26 11:37:57 +100069 lsll #2,%d0 /* movel %a0@(%d0:l:4),%d3 */
70 movel %a0@(%d0),%d3
71 jeq enosys
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Philippe De Muyter623f5232006-06-26 11:37:57 +1000731:
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 movel %sp,%d2 /* get thread_info pointer */
75 andl #-THREAD_SIZE,%d2 /* at start of kernel stack */
76 movel %d2,%a0
Matt Waddel151941a2007-10-23 14:37:54 +100077 movel %a0@,%a1 /* save top of frame */
78 movel %sp,%a1@(TASK_THREAD+THREAD_ESP0)
Philippe De Muyter623f5232006-06-26 11:37:57 +100079 btst #(TIF_SYSCALL_TRACE%8),%a0@(TI_FLAGS+(31-TIF_SYSCALL_TRACE)/8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 bnes 1f
81
82 movel %d3,%a0
83 jbsr %a0@
Greg Ungererc84b5642009-09-20 21:32:32 +100084 movel %d0,%sp@(PT_OFF_D0) /* save the return value */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 jra ret_from_exception
861:
Greg Ungererc84b5642009-09-20 21:32:32 +100087 movel #-ENOSYS,%d2 /* strace needs -ENOSYS in PT_OFF_D0 */
88 movel %d2,PT_OFF_D0(%sp) /* on syscall entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 subql #4,%sp
90 SAVE_SWITCH_STACK
Greg Ungerer55f411d2010-10-22 15:12:34 +100091 jbsr syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 RESTORE_SWITCH_STACK
93 addql #4,%sp
94 movel %d3,%a0
95 jbsr %a0@
Greg Ungererc84b5642009-09-20 21:32:32 +100096 movel %d0,%sp@(PT_OFF_D0) /* save the return value */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 subql #4,%sp /* dummy return address */
98 SAVE_SWITCH_STACK
Greg Ungerer55f411d2010-10-22 15:12:34 +100099 jbsr syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101ret_from_signal:
102 RESTORE_SWITCH_STACK
103 addql #4,%sp
104
105ret_from_exception:
Sebastian Siewior6c5a7d52008-05-01 12:17:49 +1000106 move #0x2700,%sr /* disable intrs */
Greg Ungererc84b5642009-09-20 21:32:32 +1000107 btst #5,%sp@(PT_OFF_SR) /* check if returning to kernel */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 jeq Luser_return /* if so, skip resched, signals */
109
Sebastian Siewiora19325a2008-05-01 12:16:29 +1000110#ifdef CONFIG_PREEMPT
111 movel %sp,%d1 /* get thread_info pointer */
112 andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
113 movel %d1,%a0
114 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
Greg Ungerercddafa32010-09-13 14:10:45 +1000115 andl #(1<<TIF_NEED_RESCHED),%d1
Sebastian Siewiora19325a2008-05-01 12:16:29 +1000116 jeq Lkernel_return
117
118 movel %a0@(TI_PREEMPTCOUNT),%d1
119 cmpl #0,%d1
120 jne Lkernel_return
121
122 pea Lkernel_return
123 jmp preempt_schedule_irq /* preempt the kernel */
124#endif
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126Lkernel_return:
127 moveml %sp@,%d1-%d5/%a0-%a2
128 lea %sp@(32),%sp /* space for 8 regs */
129 movel %sp@+,%d0
130 addql #4,%sp /* orig d0 */
131 addl %sp@+,%sp /* stk adj */
132 rte
133
134Luser_return:
135 movel %sp,%d1 /* get thread_info pointer */
136 andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
137 movel %d1,%a0
138 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
Greg Ungerercddafa32010-09-13 14:10:45 +1000139 andl #0xefff,%d1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 jne Lwork_to_do /* still work to do */
141
142Lreturn:
Philippe De Muyter623f5232006-06-26 11:37:57 +1000143 move #0x2700,%sr /* disable intrs */
144 movel sw_usp,%a0 /* get usp */
Greg Ungererc84b5642009-09-20 21:32:32 +1000145 movel %sp@(PT_OFF_PC),%a0@- /* copy exception program counter */
146 movel %sp@(PT_OFF_FORMATVEC),%a0@- /* copy exception format/vector/sr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 moveml %sp@,%d1-%d5/%a0-%a2
148 lea %sp@(32),%sp /* space for 8 regs */
149 movel %sp@+,%d0
150 addql #4,%sp /* orig d0 */
151 addl %sp@+,%sp /* stk adj */
152 addql #8,%sp /* remove exception */
153 movel %sp,sw_ksp /* save ksp */
154 subql #8,sw_usp /* set exception */
155 movel sw_usp,%sp /* restore usp */
156 rte
157
158Lwork_to_do:
159 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
Sebastian Siewior6c5a7d52008-05-01 12:17:49 +1000160 move #0x2000,%sr /* enable intrs again */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 btst #TIF_NEED_RESCHED,%d1
162 jne reschedule
163
164 /* GERG: do we need something here for TRACEing?? */
165
166Lsignal_return:
167 subql #4,%sp /* dummy return address */
168 SAVE_SWITCH_STACK
169 pea %sp@(SWITCH_STACK_SIZE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 jsr do_signal
Al Viro710e91e2010-10-11 17:09:20 -0400171 addql #4,%sp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 RESTORE_SWITCH_STACK
173 addql #4,%sp
Al Virod1574df2010-10-11 23:29:28 -0400174 jmp Luser_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176/*
177 * This is the generic interrupt handler (for all hardware interrupt
Greg Ungerer2502b6672007-07-19 01:49:12 -0700178 * sources). Calls upto high level code to do all the work.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 */
180ENTRY(inthandler)
181 SAVE_ALL
182 moveq #-1,%d0
Greg Ungererc84b5642009-09-20 21:32:32 +1000183 movel %d0,%sp@(PT_OFF_ORIG_D0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Greg Ungererc84b5642009-09-20 21:32:32 +1000185 movew %sp@(PT_OFF_FORMATVEC),%d0 /* put exception # in d0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 andl #0x03fc,%d0 /* mask out vector only */
187
Greg Ungerer2502b6672007-07-19 01:49:12 -0700188 movel %sp,%sp@- /* push regs arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 lsrl #2,%d0 /* calculate real vector # */
Greg Ungerer2502b6672007-07-19 01:49:12 -0700190 movel %d0,%sp@- /* push vector number */
191 jbsr do_IRQ /* call high level irq handler */
192 lea %sp@(8),%sp /* pop args off stack */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 bra ret_from_interrupt /* this was fallthrough */
195
196/*
197 * This is the fast interrupt handler (for certain hardware interrupt
198 * sources). Unlike the normal interrupt handler it just uses the
199 * current stack (doesn't care if it is user or kernel). It also
200 * doesn't bother doing the bottom half handlers.
201 */
202ENTRY(fasthandler)
203 SAVE_LOCAL
204
Greg Ungererc84b5642009-09-20 21:32:32 +1000205 movew %sp@(PT_OFF_FORMATVEC),%d0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 andl #0x03fc,%d0 /* mask out vector only */
207
Greg Ungerer2502b6672007-07-19 01:49:12 -0700208 movel %sp,%sp@- /* push regs arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 lsrl #2,%d0 /* calculate real vector # */
Greg Ungerer2502b6672007-07-19 01:49:12 -0700210 movel %d0,%sp@- /* push vector number */
211 jbsr do_IRQ /* call high level irq handler */
212 lea %sp@(8),%sp /* pop args off stack */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 RESTORE_LOCAL
215
216ENTRY(ret_from_interrupt)
Sebastian Siewiorc7bcd0d2008-04-28 11:43:16 +0200217 /* the fasthandler is confusing me, haven't seen any user */
218 jmp ret_from_exception
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220/*
221 * Beware - when entering resume, prev (the current task) is
222 * in a0, next (the new task) is in a1,so don't change these
223 * registers until their contents are no longer needed.
Greg Ungerer7160a672007-07-25 22:07:20 +1000224 * This is always called in supervisor mode, so don't bother to save
225 * and restore sr; user's process sr is actually in the stack.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 */
227ENTRY(resume)
228 movel %a0, %d1 /* get prev thread in d1 */
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 movel sw_usp,%d0 /* save usp */
231 movel %d0,%a0@(TASK_THREAD+THREAD_USP)
232
233 SAVE_SWITCH_STACK
234 movel %sp,%a0@(TASK_THREAD+THREAD_KSP) /* save kernel stack pointer */
235 movel %a1@(TASK_THREAD+THREAD_KSP),%sp /* restore new thread stack */
236 RESTORE_SWITCH_STACK
237
238 movel %a1@(TASK_THREAD+THREAD_USP),%a0 /* restore thread user stack */
239 movel %a0, sw_usp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 rts