blob: b9ce3196618180dcb1af3d8ebc06d2322e189802 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070054.globl inthandler
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Philippe De Muyter623f5232006-06-26 11:37:57 +100056enosys:
57 mov.l #sys_ni_syscall,%d3
58 bra 1f
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060ENTRY(system_call)
61 SAVE_ALL
62 move #0x2000,%sr /* enable intrs again */
63
Philippe De Muyter623f5232006-06-26 11:37:57 +100064 cmpl #NR_syscalls,%d0
65 jcc enosys
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 lea sys_call_table,%a0
Philippe De Muyter623f5232006-06-26 11:37:57 +100067 lsll #2,%d0 /* movel %a0@(%d0:l:4),%d3 */
68 movel %a0@(%d0),%d3
69 jeq enosys
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Philippe De Muyter623f5232006-06-26 11:37:57 +1000711:
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 movel %sp,%d2 /* get thread_info pointer */
73 andl #-THREAD_SIZE,%d2 /* at start of kernel stack */
74 movel %d2,%a0
Matt Waddel151941a2007-10-23 14:37:54 +100075 movel %a0@,%a1 /* save top of frame */
76 movel %sp,%a1@(TASK_THREAD+THREAD_ESP0)
Philippe De Muyter623f5232006-06-26 11:37:57 +100077 btst #(TIF_SYSCALL_TRACE%8),%a0@(TI_FLAGS+(31-TIF_SYSCALL_TRACE)/8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 bnes 1f
79
80 movel %d3,%a0
81 jbsr %a0@
Greg Ungererc84b5642009-09-20 21:32:32 +100082 movel %d0,%sp@(PT_OFF_D0) /* save the return value */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 jra ret_from_exception
841:
Greg Ungererc84b5642009-09-20 21:32:32 +100085 movel #-ENOSYS,%d2 /* strace needs -ENOSYS in PT_OFF_D0 */
86 movel %d2,PT_OFF_D0(%sp) /* on syscall entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 subql #4,%sp
88 SAVE_SWITCH_STACK
Greg Ungerer55f411d2010-10-22 15:12:34 +100089 jbsr syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 RESTORE_SWITCH_STACK
91 addql #4,%sp
92 movel %d3,%a0
93 jbsr %a0@
Greg Ungererc84b5642009-09-20 21:32:32 +100094 movel %d0,%sp@(PT_OFF_D0) /* save the return value */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 subql #4,%sp /* dummy return address */
96 SAVE_SWITCH_STACK
Greg Ungerer55f411d2010-10-22 15:12:34 +100097 jbsr syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99ret_from_signal:
100 RESTORE_SWITCH_STACK
101 addql #4,%sp
102
103ret_from_exception:
Sebastian Siewior6c5a7d52008-05-01 12:17:49 +1000104 move #0x2700,%sr /* disable intrs */
Greg Ungererc84b5642009-09-20 21:32:32 +1000105 btst #5,%sp@(PT_OFF_SR) /* check if returning to kernel */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 jeq Luser_return /* if so, skip resched, signals */
107
Sebastian Siewiora19325a2008-05-01 12:16:29 +1000108#ifdef CONFIG_PREEMPT
109 movel %sp,%d1 /* get thread_info pointer */
110 andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
111 movel %d1,%a0
112 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
Greg Ungerercddafa32010-09-13 14:10:45 +1000113 andl #(1<<TIF_NEED_RESCHED),%d1
Sebastian Siewiora19325a2008-05-01 12:16:29 +1000114 jeq Lkernel_return
115
116 movel %a0@(TI_PREEMPTCOUNT),%d1
117 cmpl #0,%d1
118 jne Lkernel_return
119
120 pea Lkernel_return
121 jmp preempt_schedule_irq /* preempt the kernel */
122#endif
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124Lkernel_return:
125 moveml %sp@,%d1-%d5/%a0-%a2
126 lea %sp@(32),%sp /* space for 8 regs */
127 movel %sp@+,%d0
128 addql #4,%sp /* orig d0 */
129 addl %sp@+,%sp /* stk adj */
130 rte
131
132Luser_return:
133 movel %sp,%d1 /* get thread_info pointer */
134 andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
135 movel %d1,%a0
136 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
Greg Ungerercddafa32010-09-13 14:10:45 +1000137 andl #0xefff,%d1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 jne Lwork_to_do /* still work to do */
139
140Lreturn:
Philippe De Muyter623f5232006-06-26 11:37:57 +1000141 move #0x2700,%sr /* disable intrs */
142 movel sw_usp,%a0 /* get usp */
Greg Ungererc84b5642009-09-20 21:32:32 +1000143 movel %sp@(PT_OFF_PC),%a0@- /* copy exception program counter */
144 movel %sp@(PT_OFF_FORMATVEC),%a0@- /* copy exception format/vector/sr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 moveml %sp@,%d1-%d5/%a0-%a2
146 lea %sp@(32),%sp /* space for 8 regs */
147 movel %sp@+,%d0
148 addql #4,%sp /* orig d0 */
149 addl %sp@+,%sp /* stk adj */
150 addql #8,%sp /* remove exception */
151 movel %sp,sw_ksp /* save ksp */
152 subql #8,sw_usp /* set exception */
153 movel sw_usp,%sp /* restore usp */
154 rte
155
156Lwork_to_do:
157 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
Sebastian Siewior6c5a7d52008-05-01 12:17:49 +1000158 move #0x2000,%sr /* enable intrs again */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 btst #TIF_NEED_RESCHED,%d1
160 jne reschedule
161
162 /* GERG: do we need something here for TRACEing?? */
163
164Lsignal_return:
165 subql #4,%sp /* dummy return address */
166 SAVE_SWITCH_STACK
167 pea %sp@(SWITCH_STACK_SIZE)
168 clrl %sp@-
169 jsr do_signal
170 addql #8,%sp
171 RESTORE_SWITCH_STACK
172 addql #4,%sp
173 jmp Lreturn
174
175/*
176 * This is the generic interrupt handler (for all hardware interrupt
Greg Ungerer2502b6672007-07-19 01:49:12 -0700177 * sources). Calls upto high level code to do all the work.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 */
179ENTRY(inthandler)
180 SAVE_ALL
181 moveq #-1,%d0
Greg Ungererc84b5642009-09-20 21:32:32 +1000182 movel %d0,%sp@(PT_OFF_ORIG_D0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Greg Ungererc84b5642009-09-20 21:32:32 +1000184 movew %sp@(PT_OFF_FORMATVEC),%d0 /* put exception # in d0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 andl #0x03fc,%d0 /* mask out vector only */
186
Greg Ungerer2502b6672007-07-19 01:49:12 -0700187 movel %sp,%sp@- /* push regs arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 lsrl #2,%d0 /* calculate real vector # */
Greg Ungerer2502b6672007-07-19 01:49:12 -0700189 movel %d0,%sp@- /* push vector number */
190 jbsr do_IRQ /* call high level irq handler */
191 lea %sp@(8),%sp /* pop args off stack */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Greg Ungererfb670fb2010-11-03 16:21:05 +1000193 bra ret_from_exception
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195/*
196 * Beware - when entering resume, prev (the current task) is
197 * in a0, next (the new task) is in a1,so don't change these
198 * registers until their contents are no longer needed.
Greg Ungerer7160a672007-07-25 22:07:20 +1000199 * This is always called in supervisor mode, so don't bother to save
200 * and restore sr; user's process sr is actually in the stack.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 */
202ENTRY(resume)
203 movel %a0, %d1 /* get prev thread in d1 */
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 movel sw_usp,%d0 /* save usp */
206 movel %d0,%a0@(TASK_THREAD+THREAD_USP)
207
208 SAVE_SWITCH_STACK
209 movel %sp,%a0@(TASK_THREAD+THREAD_KSP) /* save kernel stack pointer */
210 movel %a1@(TASK_THREAD+THREAD_KSP),%sp /* restore new thread stack */
211 RESTORE_SWITCH_STACK
212
213 movel %a1@(TASK_THREAD+THREAD_USP),%a0 /* restore thread user stack */
214 movel %a0, sw_usp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 rts