blob: f0dba84d91019cb6798a985d1d27ab63ad4ad415 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m68knommu/platform/5307/entry.S
3 *
4 * Copyright (C) 1999-2002, Greg Ungerer (gerg@snapgear.com)
5 * 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
Philippe De Muyter623f5232006-06-26 11:37:57 +100077 movel %sp,%a0@(THREAD_ESP0) /* save top of frame */
78 btst #(TIF_SYSCALL_TRACE%8),%a0@(TI_FLAGS+(31-TIF_SYSCALL_TRACE)/8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 bnes 1f
80
81 movel %d3,%a0
82 jbsr %a0@
83 movel %d0,%sp@(PT_D0) /* save the return value */
84 jra ret_from_exception
851:
86 subql #4,%sp
87 SAVE_SWITCH_STACK
88 jbsr syscall_trace
89 RESTORE_SWITCH_STACK
90 addql #4,%sp
91 movel %d3,%a0
92 jbsr %a0@
93 movel %d0,%sp@(PT_D0) /* save the return value */
94 subql #4,%sp /* dummy return address */
95 SAVE_SWITCH_STACK
96 jbsr syscall_trace
97
98ret_from_signal:
99 RESTORE_SWITCH_STACK
100 addql #4,%sp
101
102ret_from_exception:
103 btst #5,%sp@(PT_SR) /* check if returning to kernel */
104 jeq Luser_return /* if so, skip resched, signals */
105
106Lkernel_return:
107 moveml %sp@,%d1-%d5/%a0-%a2
108 lea %sp@(32),%sp /* space for 8 regs */
109 movel %sp@+,%d0
110 addql #4,%sp /* orig d0 */
111 addl %sp@+,%sp /* stk adj */
112 rte
113
114Luser_return:
115 movel %sp,%d1 /* get thread_info pointer */
116 andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
117 movel %d1,%a0
118 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
119 andl #_TIF_WORK_MASK,%d1
120 jne Lwork_to_do /* still work to do */
121
122Lreturn:
Philippe De Muyter623f5232006-06-26 11:37:57 +1000123 move #0x2700,%sr /* disable intrs */
124 movel sw_usp,%a0 /* get usp */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 movel %sp@(PT_PC),%a0@- /* copy exception program counter */
126 movel %sp@(PT_FORMATVEC),%a0@-/* copy exception format/vector/sr */
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 addql #8,%sp /* remove exception */
133 movel %sp,sw_ksp /* save ksp */
134 subql #8,sw_usp /* set exception */
135 movel sw_usp,%sp /* restore usp */
136 rte
137
138Lwork_to_do:
139 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
140 btst #TIF_NEED_RESCHED,%d1
141 jne reschedule
142
143 /* GERG: do we need something here for TRACEing?? */
144
145Lsignal_return:
146 subql #4,%sp /* dummy return address */
147 SAVE_SWITCH_STACK
148 pea %sp@(SWITCH_STACK_SIZE)
149 clrl %sp@-
150 jsr do_signal
151 addql #8,%sp
152 RESTORE_SWITCH_STACK
153 addql #4,%sp
154 jmp Lreturn
155
156/*
157 * This is the generic interrupt handler (for all hardware interrupt
158 * sources). It figures out the vector number and calls the appropriate
159 * interrupt service routine directly.
160 */
161ENTRY(inthandler)
162 SAVE_ALL
163 moveq #-1,%d0
164 movel %d0,%sp@(PT_ORIG_D0)
165 addql #1,local_irq_count
166
Philippe De Muyter623f5232006-06-26 11:37:57 +1000167 movew %sp@(PT_FORMATVEC),%d0 /* put exception # in d0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 andl #0x03fc,%d0 /* mask out vector only */
169
170 leal per_cpu__kstat+STAT_IRQ,%a0
171 addql #1,%a0@(%d0)
172
173 lsrl #2,%d0 /* calculate real vector # */
174 movel %d0,%d1 /* calculate array offset */
175 lsll #4,%d1
176 lea irq_list,%a0
177 addl %d1,%a0 /* pointer to array struct */
178
179 movel %sp,%sp@- /* push regs arg onto stack */
180 movel %a0@(8),%sp@- /* push devid arg */
Philippe De Muyter623f5232006-06-26 11:37:57 +1000181 movel %d0,%sp@- /* push vector # on stack */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 movel %a0@,%a0 /* get function to call */
184 jbsr %a0@ /* call vector handler */
185 lea %sp@(12),%sp /* pop parameters off stack */
186
187 bra ret_from_interrupt /* this was fallthrough */
188
189/*
190 * This is the fast interrupt handler (for certain hardware interrupt
191 * sources). Unlike the normal interrupt handler it just uses the
192 * current stack (doesn't care if it is user or kernel). It also
193 * doesn't bother doing the bottom half handlers.
194 */
195ENTRY(fasthandler)
196 SAVE_LOCAL
197
Philippe De Muyter623f5232006-06-26 11:37:57 +1000198 movew %sp@(PT_FORMATVEC),%d0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 andl #0x03fc,%d0 /* mask out vector only */
200
201 leal per_cpu__kstat+STAT_IRQ,%a0
202 addql #1,%a0@(%d0)
203
204 movel %sp,%sp@- /* push regs arg onto stack */
205 clrl %sp@- /* push devid arg */
206 lsrl #2,%d0 /* calculate real vector # */
Philippe De Muyter623f5232006-06-26 11:37:57 +1000207 movel %d0,%sp@- /* push vector # on stack */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209 lsll #4,%d0 /* adjust for array offset */
210 lea irq_list,%a0
211 movel %a0@(%d0),%a0 /* get function to call */
212 jbsr %a0@ /* call vector handler */
213 lea %sp@(12),%sp /* pop parameters off stack */
214
215 RESTORE_LOCAL
216
217ENTRY(ret_from_interrupt)
218 subql #1,local_irq_count
219 jeq 2f
2201:
221 RESTORE_ALL
2222:
223 moveb %sp@(PT_SR),%d0
224 andl #0x7,%d0
225 jhi 1b
226
227 /* check if we need to do software interrupts */
228 movel irq_stat+CPUSTAT_SOFTIRQ_PENDING,%d0
229 jeq ret_from_exception
230
231 pea ret_from_exception
232 jmp do_softirq
233
234/*
235 * Beware - when entering resume, prev (the current task) is
236 * in a0, next (the new task) is in a1,so don't change these
237 * registers until their contents are no longer needed.
238 */
239ENTRY(resume)
240 movel %a0, %d1 /* get prev thread in d1 */
241
242 movew %sr,%d0 /* save thread status reg */
243 movew %d0,%a0@(TASK_THREAD+THREAD_SR)
244
245 oril #0x700,%d0 /* disable interrupts */
246 move %d0,%sr
247
248 movel sw_usp,%d0 /* save usp */
249 movel %d0,%a0@(TASK_THREAD+THREAD_USP)
250
251 SAVE_SWITCH_STACK
252 movel %sp,%a0@(TASK_THREAD+THREAD_KSP) /* save kernel stack pointer */
253 movel %a1@(TASK_THREAD+THREAD_KSP),%sp /* restore new thread stack */
254 RESTORE_SWITCH_STACK
255
256 movel %a1@(TASK_THREAD+THREAD_USP),%a0 /* restore thread user stack */
257 movel %a0, sw_usp
258
259 movew %a1@(TASK_THREAD+THREAD_SR),%d0 /* restore thread status reg */
260 movew %d0, %sr
261 rts