blob: f90e6173ccd4a56ce27e375b28f33cbfaf44a5a6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m68knommu/platform/5307/entry.S
3 *
Greg Ungerer2502b662007-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
Greg Ungerer1c83af52010-11-04 13:53:26 +100039#ifdef CONFIG_COLDFIRE_SW_A7
40/*
41 * Define software copies of the supervisor and user stack pointers.
42 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043.bss
Linus Torvalds1da177e2005-04-16 15:20:36 -070044sw_ksp:
45.long 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070046sw_usp:
47.long 0
Greg Ungerer1c83af52010-11-04 13:53:26 +100048#endif /* CONFIG_COLDFIRE_SW_A7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50.text
51
52.globl system_call
53.globl resume
54.globl ret_from_exception
55.globl ret_from_signal
56.globl sys_call_table
Linus Torvalds1da177e2005-04-16 15:20:36 -070057.globl inthandler
Greg Ungerer1c83af52010-11-04 13:53:26 +100058.globl fasthandler
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Philippe De Muyter623f5232006-06-26 11:37:57 +100060enosys:
61 mov.l #sys_ni_syscall,%d3
62 bra 1f
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064ENTRY(system_call)
65 SAVE_ALL
66 move #0x2000,%sr /* enable intrs again */
67
Philippe De Muyter623f5232006-06-26 11:37:57 +100068 cmpl #NR_syscalls,%d0
69 jcc enosys
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 lea sys_call_table,%a0
Philippe De Muyter623f5232006-06-26 11:37:57 +100071 lsll #2,%d0 /* movel %a0@(%d0:l:4),%d3 */
72 movel %a0@(%d0),%d3
73 jeq enosys
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Philippe De Muyter623f5232006-06-26 11:37:57 +1000751:
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 movel %sp,%d2 /* get thread_info pointer */
77 andl #-THREAD_SIZE,%d2 /* at start of kernel stack */
78 movel %d2,%a0
Matt Waddel151941a2007-10-23 14:37:54 +100079 movel %a0@,%a1 /* save top of frame */
80 movel %sp,%a1@(TASK_THREAD+THREAD_ESP0)
Philippe De Muyter623f5232006-06-26 11:37:57 +100081 btst #(TIF_SYSCALL_TRACE%8),%a0@(TI_FLAGS+(31-TIF_SYSCALL_TRACE)/8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 bnes 1f
83
84 movel %d3,%a0
85 jbsr %a0@
Greg Ungererc84b5642009-09-20 21:32:32 +100086 movel %d0,%sp@(PT_OFF_D0) /* save the return value */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 jra ret_from_exception
881:
Greg Ungererc84b5642009-09-20 21:32:32 +100089 movel #-ENOSYS,%d2 /* strace needs -ENOSYS in PT_OFF_D0 */
90 movel %d2,PT_OFF_D0(%sp) /* on syscall entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 subql #4,%sp
92 SAVE_SWITCH_STACK
Greg Ungerer55f411d2010-10-22 15:12:34 +100093 jbsr syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 RESTORE_SWITCH_STACK
95 addql #4,%sp
96 movel %d3,%a0
97 jbsr %a0@
Greg Ungererc84b5642009-09-20 21:32:32 +100098 movel %d0,%sp@(PT_OFF_D0) /* save the return value */
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 subql #4,%sp /* dummy return address */
100 SAVE_SWITCH_STACK
Greg Ungerer55f411d2010-10-22 15:12:34 +1000101 jbsr syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103ret_from_signal:
104 RESTORE_SWITCH_STACK
105 addql #4,%sp
106
107ret_from_exception:
Sebastian Siewior6c5a7d52008-05-01 12:17:49 +1000108 move #0x2700,%sr /* disable intrs */
Greg Ungererc84b5642009-09-20 21:32:32 +1000109 btst #5,%sp@(PT_OFF_SR) /* check if returning to kernel */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 jeq Luser_return /* if so, skip resched, signals */
111
Sebastian Siewiora19325a2008-05-01 12:16:29 +1000112#ifdef CONFIG_PREEMPT
113 movel %sp,%d1 /* get thread_info pointer */
114 andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
115 movel %d1,%a0
116 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
Greg Ungerercddafa32010-09-13 14:10:45 +1000117 andl #(1<<TIF_NEED_RESCHED),%d1
Sebastian Siewiora19325a2008-05-01 12:16:29 +1000118 jeq Lkernel_return
119
120 movel %a0@(TI_PREEMPTCOUNT),%d1
121 cmpl #0,%d1
122 jne Lkernel_return
123
124 pea Lkernel_return
125 jmp preempt_schedule_irq /* preempt the kernel */
126#endif
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128Lkernel_return:
129 moveml %sp@,%d1-%d5/%a0-%a2
130 lea %sp@(32),%sp /* space for 8 regs */
131 movel %sp@+,%d0
132 addql #4,%sp /* orig d0 */
133 addl %sp@+,%sp /* stk adj */
134 rte
135
136Luser_return:
137 movel %sp,%d1 /* get thread_info pointer */
138 andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
139 movel %d1,%a0
140 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
Greg Ungerercddafa32010-09-13 14:10:45 +1000141 andl #0xefff,%d1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 jne Lwork_to_do /* still work to do */
143
144Lreturn:
Greg Ungerer1c83af52010-11-04 13:53:26 +1000145 RESTORE_USER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147Lwork_to_do:
148 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
Sebastian Siewior6c5a7d52008-05-01 12:17:49 +1000149 move #0x2000,%sr /* enable intrs again */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 btst #TIF_NEED_RESCHED,%d1
151 jne reschedule
152
153 /* GERG: do we need something here for TRACEing?? */
154
155Lsignal_return:
156 subql #4,%sp /* dummy return address */
157 SAVE_SWITCH_STACK
158 pea %sp@(SWITCH_STACK_SIZE)
159 clrl %sp@-
160 jsr do_signal
161 addql #8,%sp
162 RESTORE_SWITCH_STACK
163 addql #4,%sp
164 jmp Lreturn
165
166/*
167 * This is the generic interrupt handler (for all hardware interrupt
Greg Ungerer2502b662007-07-19 01:49:12 -0700168 * sources). Calls upto high level code to do all the work.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 */
170ENTRY(inthandler)
171 SAVE_ALL
172 moveq #-1,%d0
Greg Ungererc84b5642009-09-20 21:32:32 +1000173 movel %d0,%sp@(PT_OFF_ORIG_D0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Greg Ungererc84b5642009-09-20 21:32:32 +1000175 movew %sp@(PT_OFF_FORMATVEC),%d0 /* put exception # in d0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 andl #0x03fc,%d0 /* mask out vector only */
177
Greg Ungerer2502b662007-07-19 01:49:12 -0700178 movel %sp,%sp@- /* push regs arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 lsrl #2,%d0 /* calculate real vector # */
Greg Ungerer2502b662007-07-19 01:49:12 -0700180 movel %d0,%sp@- /* push vector number */
181 jbsr do_IRQ /* call high level irq handler */
182 lea %sp@(8),%sp /* pop args off stack */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Greg Ungererfb670fb2010-11-03 16:21:05 +1000184 bra ret_from_exception
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186/*
187 * Beware - when entering resume, prev (the current task) is
188 * in a0, next (the new task) is in a1,so don't change these
189 * registers until their contents are no longer needed.
Greg Ungerer7160a672007-07-25 22:07:20 +1000190 * This is always called in supervisor mode, so don't bother to save
191 * and restore sr; user's process sr is actually in the stack.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 */
193ENTRY(resume)
194 movel %a0, %d1 /* get prev thread in d1 */
Greg Ungerer1c83af52010-11-04 13:53:26 +1000195 RDUSP
196 movel %a2,%a0@(TASK_THREAD+THREAD_USP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 SAVE_SWITCH_STACK
199 movel %sp,%a0@(TASK_THREAD+THREAD_KSP) /* save kernel stack pointer */
200 movel %a1@(TASK_THREAD+THREAD_KSP),%sp /* restore new thread stack */
201 RESTORE_SWITCH_STACK
202
203 movel %a1@(TASK_THREAD+THREAD_USP),%a0 /* restore thread user stack */
Greg Ungerer1c83af52010-11-04 13:53:26 +1000204 WRUSP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 rts