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