xref: /linux/arch/mips/kernel/entry.S (revision 455481fc9a807798eca05f6fb0918ab88109d845)
11da177e4SLinus Torvalds/*
21da177e4SLinus Torvalds * This file is subject to the terms and conditions of the GNU General Public
31da177e4SLinus Torvalds * License.  See the file "COPYING" in the main directory of this archive
41da177e4SLinus Torvalds * for more details.
51da177e4SLinus Torvalds *
61da177e4SLinus Torvalds * Copyright (C) 1994 - 2000, 2001, 2003 Ralf Baechle
71da177e4SLinus Torvalds * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
81da177e4SLinus Torvalds * Copyright (C) 2001 MIPS Technologies, Inc.
91da177e4SLinus Torvalds */
101da177e4SLinus Torvalds
111da177e4SLinus Torvalds#include <asm/asm.h>
121da177e4SLinus Torvalds#include <asm/asmmacro.h>
13aebac993SMarkos Chandras#include <asm/compiler.h>
14d8550860SPaul Burton#include <asm/irqflags.h>
151da177e4SLinus Torvalds#include <asm/regdef.h>
161da177e4SLinus Torvalds#include <asm/mipsregs.h>
171da177e4SLinus Torvalds#include <asm/stackframe.h>
181da177e4SLinus Torvalds#include <asm/isadep.h>
191da177e4SLinus Torvalds#include <asm/thread_info.h>
201da177e4SLinus Torvalds
21098fa51bSThomas Gleixner#ifndef CONFIG_PREEMPTION
221da177e4SLinus Torvalds#define resume_kernel	restore_all
237da8a581SFranck Bui-Huu#else
247da8a581SFranck Bui-Huu#define __ret_from_irq	ret_from_exception
251da177e4SLinus Torvalds#endif
261da177e4SLinus Torvalds
271da177e4SLinus Torvalds	.text
281da177e4SLinus Torvalds	.align	5
29098fa51bSThomas Gleixner#ifndef CONFIG_PREEMPTION
307da8a581SFranck Bui-HuuFEXPORT(ret_from_exception)
317da8a581SFranck Bui-Huu	local_irq_disable			# preempt stop
327da8a581SFranck Bui-Huu	b	__ret_from_irq
337da8a581SFranck Bui-Huu#endif
34f431baa5SAtsushi NemotoFEXPORT(ret_from_irq)
35f431baa5SAtsushi Nemoto	LONG_S	s0, TI_REGS($28)
367da8a581SFranck Bui-HuuFEXPORT(__ret_from_irq)
37c90e6fbbSDmitry Adamushko/*
38c90e6fbbSDmitry Adamushko * We can be coming here from a syscall done in the kernel space,
39c90e6fbbSDmitry Adamushko * e.g. a failed kernel_execve().
40c90e6fbbSDmitry Adamushko */
41c90e6fbbSDmitry Adamushkoresume_userspace_check:
421da177e4SLinus Torvalds	LONG_L	t0, PT_STATUS(sp)		# returning to kernel mode?
431da177e4SLinus Torvalds	andi	t0, t0, KU_USER
441da177e4SLinus Torvalds	beqz	t0, resume_kernel
451da177e4SLinus Torvalds
46c2648527SThiemo Seuferresume_userspace:
47c2648527SThiemo Seufer	local_irq_disable		# make sure we dont miss an
481da177e4SLinus Torvalds					# interrupt setting need_resched
491da177e4SLinus Torvalds					# between sampling and return
501da177e4SLinus Torvalds	LONG_L	a2, TI_FLAGS($28)	# current->work
51c2648527SThiemo Seufer	andi	t0, a2, _TIF_WORK_MASK	# (ignoring syscall_trace)
52c2648527SThiemo Seufer	bnez	t0, work_pending
531da177e4SLinus Torvalds	j	restore_all
541da177e4SLinus Torvalds
55098fa51bSThomas Gleixner#ifdef CONFIG_PREEMPTION
56c2648527SThiemo Seuferresume_kernel:
57a18815abSRalf Baechle	local_irq_disable
581da177e4SLinus Torvalds	lw	t0, TI_PRE_COUNT($28)
591da177e4SLinus Torvalds	bnez	t0, restore_all
601da177e4SLinus Torvalds	LONG_L	t0, TI_FLAGS($28)
611da177e4SLinus Torvalds	andi	t1, t0, _TIF_NEED_RESCHED
621da177e4SLinus Torvalds	beqz	t1, restore_all
631da177e4SLinus Torvalds	LONG_L	t0, PT_STATUS(sp)		# Interrupts off?
641da177e4SLinus Torvalds	andi	t0, 1
651da177e4SLinus Torvalds	beqz	t0, restore_all
66b8f3b15aSValentin Schneider	PTR_LA	ra, restore_all
67b8f3b15aSValentin Schneider	j	preempt_schedule_irq
681da177e4SLinus Torvalds#endif
691da177e4SLinus Torvalds
708f54bcacSAl ViroFEXPORT(ret_from_kernel_thread)
718f54bcacSAl Viro	jal	schedule_tail		# a0 = struct task_struct *prev
728f54bcacSAl Viro	move	a0, s1
738f54bcacSAl Viro	jal	s0
749b0e5d42SAl Viro	j	syscall_exit
758f54bcacSAl Viro
761da177e4SLinus TorvaldsFEXPORT(ret_from_fork)
7736c8b586SIngo Molnar	jal	schedule_tail		# a0 = struct task_struct *prev
781da177e4SLinus Torvalds
791da177e4SLinus TorvaldsFEXPORT(syscall_exit)
809bcf5359SPaul Burton#ifdef CONFIG_DEBUG_RSEQ
819bcf5359SPaul Burton	move	a0, sp
829bcf5359SPaul Burton	jal	rseq_syscall
839bcf5359SPaul Burton#endif
841da177e4SLinus Torvalds	local_irq_disable		# make sure need_resched and
851da177e4SLinus Torvalds					# signals dont change between
861da177e4SLinus Torvalds					# sampling and return
871da177e4SLinus Torvalds	LONG_L	a2, TI_FLAGS($28)	# current->work
881da177e4SLinus Torvalds	li	t0, _TIF_ALLWORK_MASK
891da177e4SLinus Torvalds	and	t0, a2, t0
901da177e4SLinus Torvalds	bnez	t0, syscall_exit_work
911da177e4SLinus Torvalds
9202f884edSAl Virorestore_all:				# restore full frame
931da177e4SLinus Torvalds	.set	noat
941da177e4SLinus Torvalds	RESTORE_TEMP
951da177e4SLinus Torvalds	RESTORE_AT
961da177e4SLinus Torvalds	RESTORE_STATIC
9702f884edSAl Virorestore_partial:		# restore partial frame
98192ef366SRalf Baechle#ifdef CONFIG_TRACE_IRQFLAGS
99192ef366SRalf Baechle	SAVE_STATIC
100192ef366SRalf Baechle	SAVE_AT
101192ef366SRalf Baechle	SAVE_TEMP
102192ef366SRalf Baechle	LONG_L	v0, PT_STATUS(sp)
103*455481fcSThomas Bogendoerfer#if defined(CONFIG_CPU_R3000)
104cbde5ebcSChris Dearman	and	v0, ST0_IEP
105cbde5ebcSChris Dearman#else
106cbde5ebcSChris Dearman	and	v0, ST0_IE
107cbde5ebcSChris Dearman#endif
108192ef366SRalf Baechle	beqz	v0, 1f
109192ef366SRalf Baechle	jal	trace_hardirqs_on
110192ef366SRalf Baechle	b	2f
111192ef366SRalf Baechle1:	jal	trace_hardirqs_off
112192ef366SRalf Baechle2:
113192ef366SRalf Baechle	RESTORE_TEMP
114192ef366SRalf Baechle	RESTORE_AT
115192ef366SRalf Baechle	RESTORE_STATIC
116192ef366SRalf Baechle#endif
1171da177e4SLinus Torvalds	RESTORE_SOME
1181da177e4SLinus Torvalds	RESTORE_SP_AND_RET
1191da177e4SLinus Torvalds	.set	at
1201da177e4SLinus Torvalds
121c2648527SThiemo Seuferwork_pending:
122c2648527SThiemo Seufer	andi	t0, a2, _TIF_NEED_RESCHED # a2 is preloaded with TI_FLAGS
1231da177e4SLinus Torvalds	beqz	t0, work_notifysig
1241da177e4SLinus Torvaldswork_resched:
125d8550860SPaul Burton	TRACE_IRQS_OFF
1261da177e4SLinus Torvalds	jal	schedule
1271da177e4SLinus Torvalds
128c2648527SThiemo Seufer	local_irq_disable		# make sure need_resched and
1291da177e4SLinus Torvalds					# signals dont change between
1301da177e4SLinus Torvalds					# sampling and return
1311da177e4SLinus Torvalds	LONG_L	a2, TI_FLAGS($28)
1321da177e4SLinus Torvalds	andi	t0, a2, _TIF_WORK_MASK	# is there any work to be done
1331da177e4SLinus Torvalds					# other than syscall tracing?
1341da177e4SLinus Torvalds	beqz	t0, restore_all
1351da177e4SLinus Torvalds	andi	t0, a2, _TIF_NEED_RESCHED
1361da177e4SLinus Torvalds	bnez	t0, work_resched
1371da177e4SLinus Torvalds
1381da177e4SLinus Torvaldswork_notifysig:				# deal with pending signals and
1391da177e4SLinus Torvalds					# notify-resume requests
1401da177e4SLinus Torvalds	move	a0, sp
1411da177e4SLinus Torvalds	li	a1, 0
1421da177e4SLinus Torvalds	jal	do_notify_resume	# a2 already loaded
143c90e6fbbSDmitry Adamushko	j	resume_userspace_check
1441da177e4SLinus Torvalds
14502f884edSAl ViroFEXPORT(syscall_exit_partial)
1469bcf5359SPaul Burton#ifdef CONFIG_DEBUG_RSEQ
1479bcf5359SPaul Burton	move	a0, sp
1489bcf5359SPaul Burton	jal	rseq_syscall
1499bcf5359SPaul Burton#endif
15002f884edSAl Viro	local_irq_disable		# make sure need_resched doesn't
15102f884edSAl Viro					# change between and return
15202f884edSAl Viro	LONG_L	a2, TI_FLAGS($28)	# current->work
15302f884edSAl Viro	li	t0, _TIF_ALLWORK_MASK
15402f884edSAl Viro	and	t0, a2
15502f884edSAl Viro	beqz	t0, restore_partial
1561da177e4SLinus Torvalds	SAVE_STATIC
157c2648527SThiemo Seufersyscall_exit_work:
158f76f3308SAl Viro	LONG_L	t0, PT_STATUS(sp)		# returning to kernel mode?
159f76f3308SAl Viro	andi	t0, t0, KU_USER
160f76f3308SAl Viro	beqz	t0, resume_kernel
161c19c20acSRalf Baechle	li	t0, _TIF_WORK_SYSCALL_EXIT
162c2648527SThiemo Seufer	and	t0, a2			# a2 is preloaded with TI_FLAGS
163c2648527SThiemo Seufer	beqz	t0, work_pending	# trace bit set?
1648b659a39SRalf Baechle	local_irq_enable		# could let syscall_trace_leave()
1651da177e4SLinus Torvalds					# call schedule() instead
166d8550860SPaul Burton	TRACE_IRQS_ON
1671da177e4SLinus Torvalds	move	a0, sp
1688b659a39SRalf Baechle	jal	syscall_trace_leave
1691da177e4SLinus Torvalds	b	resume_userspace
170bce1a286SRalf Baechle
171ab7c01fdSSerge Semin#if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR5) || \
172ab7c01fdSSerge Semin    defined(CONFIG_CPU_MIPSR6) || defined(CONFIG_MIPS_MT)
173bce1a286SRalf Baechle
174bce1a286SRalf Baechle/*
175bce1a286SRalf Baechle * MIPS32R2 Instruction Hazard Barrier - must be called
176bce1a286SRalf Baechle *
177bce1a286SRalf Baechle * For C code use the inline version named instruction_hazard().
178bce1a286SRalf Baechle */
179bce1a286SRalf BaechleLEAF(mips_ihb)
180aebac993SMarkos Chandras	.set	MIPS_ISA_LEVEL_RAW
181bce1a286SRalf Baechle	jr.hb	ra
182bce1a286SRalf Baechle	nop
183bce1a286SRalf Baechle	END(mips_ihb)
184bce1a286SRalf Baechle
185ab7c01fdSSerge Semin#endif /* CONFIG_CPU_MIPSR2 - CONFIG_CPU_MIPSR6 or CONFIG_MIPS_MT */
186