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