blob: bd27242c2f431da58a0e5bebb78aa4deb803ba92 [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/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/segment.h>
35#include <asm/asm-offsets.h>
36#include <asm/entry.h>
37
Greg Ungerer1c83af52010-11-04 13:53:26 +100038#ifdef CONFIG_COLDFIRE_SW_A7
39/*
40 * Define software copies of the supervisor and user stack pointers.
41 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042.bss
Linus Torvalds1da177e2005-04-16 15:20:36 -070043sw_ksp:
44.long 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070045sw_usp:
46.long 0
Greg Ungerer1c83af52010-11-04 13:53:26 +100047#endif /* CONFIG_COLDFIRE_SW_A7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49.text
50
51.globl system_call
52.globl resume
53.globl ret_from_exception
54.globl ret_from_signal
55.globl sys_call_table
Linus Torvalds1da177e2005-04-16 15:20:36 -070056.globl inthandler
57.globl fasthandler
58
Philippe De Muyter623f5232006-06-26 11:37:57 +100059enosys:
60 mov.l #sys_ni_syscall,%d3
61 bra 1f
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063ENTRY(system_call)
64 SAVE_ALL
65 move #0x2000,%sr /* enable intrs again */
66
Philippe De Muyter623f5232006-06-26 11:37:57 +100067 cmpl #NR_syscalls,%d0
68 jcc enosys
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 lea sys_call_table,%a0
Philippe De Muyter623f5232006-06-26 11:37:57 +100070 lsll #2,%d0 /* movel %a0@(%d0:l:4),%d3 */
71 movel %a0@(%d0),%d3
72 jeq enosys
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Philippe De Muyter623f5232006-06-26 11:37:57 +1000741:
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 movel %sp,%d2 /* get thread_info pointer */
76 andl #-THREAD_SIZE,%d2 /* at start of kernel stack */
77 movel %d2,%a0
Matt Waddel151941a2007-10-23 14:37:54 +100078 movel %a0@,%a1 /* save top of frame */
79 movel %sp,%a1@(TASK_THREAD+THREAD_ESP0)
Greg Ungereraa4d1f82011-03-29 15:55:36 +100080 btst #(TIF_SYSCALL_TRACE%8),%a0@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 bnes 1f
82
83 movel %d3,%a0
84 jbsr %a0@
Greg Ungererc84b5642009-09-20 21:32:32 +100085 movel %d0,%sp@(PT_OFF_D0) /* save the return value */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 jra ret_from_exception
871:
Greg Ungererc84b5642009-09-20 21:32:32 +100088 movel #-ENOSYS,%d2 /* strace needs -ENOSYS in PT_OFF_D0 */
89 movel %d2,PT_OFF_D0(%sp) /* on syscall entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 subql #4,%sp
91 SAVE_SWITCH_STACK
Greg Ungerer55f411d2010-10-22 15:12:34 +100092 jbsr syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 RESTORE_SWITCH_STACK
94 addql #4,%sp
95 movel %d3,%a0
96 jbsr %a0@
Greg Ungererc84b5642009-09-20 21:32:32 +100097 movel %d0,%sp@(PT_OFF_D0) /* save the return value */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 subql #4,%sp /* dummy return address */
99 SAVE_SWITCH_STACK
Greg Ungerer55f411d2010-10-22 15:12:34 +1000100 jbsr syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102ret_from_signal:
103 RESTORE_SWITCH_STACK
104 addql #4,%sp
105
106ret_from_exception:
Sebastian Siewior6c5a7d52008-05-01 12:17:49 +1000107 move #0x2700,%sr /* disable intrs */
Greg Ungererc84b5642009-09-20 21:32:32 +1000108 btst #5,%sp@(PT_OFF_SR) /* check if returning to kernel */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 jeq Luser_return /* if so, skip resched, signals */
110
Sebastian Siewiora19325a2008-05-01 12:16:29 +1000111#ifdef CONFIG_PREEMPT
112 movel %sp,%d1 /* get thread_info pointer */
113 andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
114 movel %d1,%a0
Greg Ungereraa4d1f82011-03-29 15:55:36 +1000115 movel %a0@(TINFO_FLAGS),%d1 /* get thread_info->flags */
Greg Ungerercddafa32010-09-13 14:10:45 +1000116 andl #(1<<TIF_NEED_RESCHED),%d1
Sebastian Siewiora19325a2008-05-01 12:16:29 +1000117 jeq Lkernel_return
118
Greg Ungereraa4d1f82011-03-29 15:55:36 +1000119 movel %a0@(TINFO_PREEMPT),%d1
Sebastian Siewiora19325a2008-05-01 12:16:29 +1000120 cmpl #0,%d1
121 jne Lkernel_return
122
123 pea Lkernel_return
124 jmp preempt_schedule_irq /* preempt the kernel */
125#endif
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127Lkernel_return:
128 moveml %sp@,%d1-%d5/%a0-%a2
129 lea %sp@(32),%sp /* space for 8 regs */
130 movel %sp@+,%d0
131 addql #4,%sp /* orig d0 */
132 addl %sp@+,%sp /* stk adj */
133 rte
134
135Luser_return:
136 movel %sp,%d1 /* get thread_info pointer */
137 andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
138 movel %d1,%a0
Greg Ungereraa4d1f82011-03-29 15:55:36 +1000139 movel %a0@(TINFO_FLAGS),%d1 /* get thread_info->flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 jne Lwork_to_do /* still work to do */
141
142Lreturn:
Greg Ungerer1c83af52010-11-04 13:53:26 +1000143 RESTORE_USER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145Lwork_to_do:
Greg Ungereraa4d1f82011-03-29 15:55:36 +1000146 movel %a0@(TINFO_FLAGS),%d1 /* get thread_info->flags */
Sebastian Siewior6c5a7d52008-05-01 12:17:49 +1000147 move #0x2000,%sr /* enable intrs again */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 btst #TIF_NEED_RESCHED,%d1
149 jne reschedule
150
151 /* GERG: do we need something here for TRACEing?? */
152
153Lsignal_return:
154 subql #4,%sp /* dummy return address */
155 SAVE_SWITCH_STACK
156 pea %sp@(SWITCH_STACK_SIZE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 jsr do_signal
Al Viro710e91e2010-10-11 17:09:20 -0400158 addql #4,%sp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 RESTORE_SWITCH_STACK
160 addql #4,%sp
Al Virod1574df2010-10-11 23:29:28 -0400161 jmp Luser_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163/*
164 * This is the generic interrupt handler (for all hardware interrupt
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300165 * sources). Calls up to high level code to do all the work.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 */
167ENTRY(inthandler)
168 SAVE_ALL
169 moveq #-1,%d0
Greg Ungererc84b5642009-09-20 21:32:32 +1000170 movel %d0,%sp@(PT_OFF_ORIG_D0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Greg Ungererc84b5642009-09-20 21:32:32 +1000172 movew %sp@(PT_OFF_FORMATVEC),%d0 /* put exception # in d0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 andl #0x03fc,%d0 /* mask out vector only */
174
Greg Ungerer2502b6672007-07-19 01:49:12 -0700175 movel %sp,%sp@- /* push regs arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 lsrl #2,%d0 /* calculate real vector # */
Greg Ungerer2502b6672007-07-19 01:49:12 -0700177 movel %d0,%sp@- /* push vector number */
178 jbsr do_IRQ /* call high level irq handler */
179 lea %sp@(8),%sp /* pop args off stack */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Greg Ungererfb670fb2010-11-03 16:21:05 +1000181 bra ret_from_exception
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183/*
184 * Beware - when entering resume, prev (the current task) is
Greg Ungererf941f5c2011-05-05 22:32:12 +1000185 * in a0, next (the new task) is in a1, so don't change these
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 * registers until their contents are no longer needed.
187 */
188ENTRY(resume)
Greg Ungererf941f5c2011-05-05 22:32:12 +1000189 movew %sr,%d1 /* save current status */
190 movew %d1,%a0@(TASK_THREAD+THREAD_SR)
191 movel %a0,%d1 /* get prev thread in d1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 SAVE_SWITCH_STACK
193 movel %sp,%a0@(TASK_THREAD+THREAD_KSP) /* save kernel stack pointer */
Greg Ungererf941f5c2011-05-05 22:32:12 +1000194 RDUSP /* movel %usp,%a3 */
195 movel %a3,%a0@(TASK_THREAD+THREAD_USP) /* save thread user stack */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Greg Ungererf941f5c2011-05-05 22:32:12 +1000197 movel %a1@(TASK_THREAD+THREAD_USP),%a3 /* restore thread user stack */
198 WRUSP /* movel %a3,%usp */
199 movel %a1@(TASK_THREAD+THREAD_KSP),%sp /* restore new kernel stack */
200 movew %a1@(TASK_THREAD+THREAD_SR),%d7 /* restore new status */
201 movew %d7,%sr
202 RESTORE_SWITCH_STACK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 rts
Greg Ungererf941f5c2011-05-05 22:32:12 +1000204