xref: /linux/arch/mips/kernel/entry.S (revision 7c151d3d5d7a032e08dbe86ad6088622391bf13e)
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>
131da177e4SLinus Torvalds#include <asm/regdef.h>
141da177e4SLinus Torvalds#include <asm/mipsregs.h>
151da177e4SLinus Torvalds#include <asm/stackframe.h>
161da177e4SLinus Torvalds#include <asm/isadep.h>
171da177e4SLinus Torvalds#include <asm/thread_info.h>
181da177e4SLinus Torvalds#include <asm/war.h>
191da177e4SLinus Torvalds
20f431baa5SAtsushi Nemoto#ifndef CONFIG_PREEMPT
211da177e4SLinus Torvalds#define resume_kernel	restore_all
227da8a581SFranck Bui-Huu#else
237da8a581SFranck Bui-Huu#define __ret_from_irq	ret_from_exception
241da177e4SLinus Torvalds#endif
251da177e4SLinus Torvalds
261da177e4SLinus Torvalds	.text
271da177e4SLinus Torvalds	.align	5
287da8a581SFranck Bui-Huu#ifndef CONFIG_PREEMPT
297da8a581SFranck Bui-HuuFEXPORT(ret_from_exception)
307da8a581SFranck Bui-Huu	local_irq_disable			# preempt stop
317da8a581SFranck Bui-Huu	b	__ret_from_irq
327da8a581SFranck Bui-Huu#endif
33f431baa5SAtsushi NemotoFEXPORT(ret_from_irq)
34f431baa5SAtsushi Nemoto	LONG_S	s0, TI_REGS($28)
357da8a581SFranck Bui-HuuFEXPORT(__ret_from_irq)
36c90e6fbbSDmitry Adamushko/*
37c90e6fbbSDmitry Adamushko * We can be coming here from a syscall done in the kernel space,
38c90e6fbbSDmitry Adamushko * e.g. a failed kernel_execve().
39c90e6fbbSDmitry Adamushko */
40c90e6fbbSDmitry Adamushkoresume_userspace_check:
411da177e4SLinus Torvalds	LONG_L	t0, PT_STATUS(sp)		# returning to kernel mode?
421da177e4SLinus Torvalds	andi	t0, t0, KU_USER
431da177e4SLinus Torvalds	beqz	t0, resume_kernel
441da177e4SLinus Torvalds
45c2648527SThiemo Seuferresume_userspace:
46c2648527SThiemo Seufer	local_irq_disable		# make sure we dont miss an
471da177e4SLinus Torvalds					# interrupt setting need_resched
481da177e4SLinus Torvalds					# between sampling and return
49*7c151d3dSMarkos Chandras#ifdef CONFIG_MIPSR2_TO_R6_EMULATOR
50*7c151d3dSMarkos Chandras	lw	k0, TI_R2_EMUL_RET($28)
51*7c151d3dSMarkos Chandras	bnez	k0, restore_all_from_r2_emul
52*7c151d3dSMarkos Chandras#endif
53*7c151d3dSMarkos Chandras
541da177e4SLinus Torvalds	LONG_L	a2, TI_FLAGS($28)	# current->work
55c2648527SThiemo Seufer	andi	t0, a2, _TIF_WORK_MASK	# (ignoring syscall_trace)
56c2648527SThiemo Seufer	bnez	t0, work_pending
571da177e4SLinus Torvalds	j	restore_all
581da177e4SLinus Torvalds
591da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
60c2648527SThiemo Seuferresume_kernel:
61a18815abSRalf Baechle	local_irq_disable
621da177e4SLinus Torvalds	lw	t0, TI_PRE_COUNT($28)
631da177e4SLinus Torvalds	bnez	t0, restore_all
641da177e4SLinus Torvaldsneed_resched:
651da177e4SLinus Torvalds	LONG_L	t0, TI_FLAGS($28)
661da177e4SLinus Torvalds	andi	t1, t0, _TIF_NEED_RESCHED
671da177e4SLinus Torvalds	beqz	t1, restore_all
681da177e4SLinus Torvalds	LONG_L	t0, PT_STATUS(sp)		# Interrupts off?
691da177e4SLinus Torvalds	andi	t0, 1
701da177e4SLinus Torvalds	beqz	t0, restore_all
71a18815abSRalf Baechle	jal	preempt_schedule_irq
72cdaed73aSRalf Baechle	b	need_resched
731da177e4SLinus Torvalds#endif
741da177e4SLinus Torvalds
758f54bcacSAl ViroFEXPORT(ret_from_kernel_thread)
768f54bcacSAl Viro	jal	schedule_tail		# a0 = struct task_struct *prev
778f54bcacSAl Viro	move	a0, s1
788f54bcacSAl Viro	jal	s0
799b0e5d42SAl Viro	j	syscall_exit
808f54bcacSAl Viro
811da177e4SLinus TorvaldsFEXPORT(ret_from_fork)
8236c8b586SIngo Molnar	jal	schedule_tail		# a0 = struct task_struct *prev
831da177e4SLinus Torvalds
841da177e4SLinus TorvaldsFEXPORT(syscall_exit)
851da177e4SLinus Torvalds	local_irq_disable		# make sure need_resched and
861da177e4SLinus Torvalds					# signals dont change between
871da177e4SLinus Torvalds					# sampling and return
881da177e4SLinus Torvalds	LONG_L	a2, TI_FLAGS($28)	# current->work
891da177e4SLinus Torvalds	li	t0, _TIF_ALLWORK_MASK
901da177e4SLinus Torvalds	and	t0, a2, t0
911da177e4SLinus Torvalds	bnez	t0, syscall_exit_work
921da177e4SLinus Torvalds
9302f884edSAl Virorestore_all:				# restore full frame
941da177e4SLinus Torvalds	.set	noat
951da177e4SLinus Torvalds	RESTORE_TEMP
961da177e4SLinus Torvalds	RESTORE_AT
971da177e4SLinus Torvalds	RESTORE_STATIC
9802f884edSAl Virorestore_partial:		# restore partial frame
99192ef366SRalf Baechle#ifdef CONFIG_TRACE_IRQFLAGS
100192ef366SRalf Baechle	SAVE_STATIC
101192ef366SRalf Baechle	SAVE_AT
102192ef366SRalf Baechle	SAVE_TEMP
103192ef366SRalf Baechle	LONG_L	v0, PT_STATUS(sp)
104cbde5ebcSChris Dearman#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
105cbde5ebcSChris Dearman	and	v0, ST0_IEP
106cbde5ebcSChris Dearman#else
107cbde5ebcSChris Dearman	and	v0, ST0_IE
108cbde5ebcSChris Dearman#endif
109192ef366SRalf Baechle	beqz	v0, 1f
110192ef366SRalf Baechle	jal	trace_hardirqs_on
111192ef366SRalf Baechle	b	2f
112192ef366SRalf Baechle1:	jal	trace_hardirqs_off
113192ef366SRalf Baechle2:
114192ef366SRalf Baechle	RESTORE_TEMP
115192ef366SRalf Baechle	RESTORE_AT
116192ef366SRalf Baechle	RESTORE_STATIC
117192ef366SRalf Baechle#endif
1181da177e4SLinus Torvalds	RESTORE_SOME
1191da177e4SLinus Torvalds	RESTORE_SP_AND_RET
1201da177e4SLinus Torvalds	.set	at
1211da177e4SLinus Torvalds
122*7c151d3dSMarkos Chandras#ifdef CONFIG_MIPSR2_TO_R6_EMULATOR
123*7c151d3dSMarkos Chandrasrestore_all_from_r2_emul:			# restore full frame
124*7c151d3dSMarkos Chandras	.set	noat
125*7c151d3dSMarkos Chandras	sw	zero, TI_R2_EMUL_RET($28)	# reset it
126*7c151d3dSMarkos Chandras	RESTORE_TEMP
127*7c151d3dSMarkos Chandras	RESTORE_AT
128*7c151d3dSMarkos Chandras	RESTORE_STATIC
129*7c151d3dSMarkos Chandras	RESTORE_SOME
130*7c151d3dSMarkos Chandras	LONG_L	sp, PT_R29(sp)
131*7c151d3dSMarkos Chandras	eretnc
132*7c151d3dSMarkos Chandras	.set	at
133*7c151d3dSMarkos Chandras#endif
134*7c151d3dSMarkos Chandras
135c2648527SThiemo Seuferwork_pending:
136c2648527SThiemo Seufer	andi	t0, a2, _TIF_NEED_RESCHED # a2 is preloaded with TI_FLAGS
1371da177e4SLinus Torvalds	beqz	t0, work_notifysig
1381da177e4SLinus Torvaldswork_resched:
1391da177e4SLinus Torvalds	jal	schedule
1401da177e4SLinus Torvalds
141c2648527SThiemo Seufer	local_irq_disable		# make sure need_resched and
1421da177e4SLinus Torvalds					# signals dont change between
1431da177e4SLinus Torvalds					# sampling and return
1441da177e4SLinus Torvalds	LONG_L	a2, TI_FLAGS($28)
1451da177e4SLinus Torvalds	andi	t0, a2, _TIF_WORK_MASK	# is there any work to be done
1461da177e4SLinus Torvalds					# other than syscall tracing?
1471da177e4SLinus Torvalds	beqz	t0, restore_all
1481da177e4SLinus Torvalds	andi	t0, a2, _TIF_NEED_RESCHED
1491da177e4SLinus Torvalds	bnez	t0, work_resched
1501da177e4SLinus Torvalds
1511da177e4SLinus Torvaldswork_notifysig:				# deal with pending signals and
1521da177e4SLinus Torvalds					# notify-resume requests
1531da177e4SLinus Torvalds	move	a0, sp
1541da177e4SLinus Torvalds	li	a1, 0
1551da177e4SLinus Torvalds	jal	do_notify_resume	# a2 already loaded
156c90e6fbbSDmitry Adamushko	j	resume_userspace_check
1571da177e4SLinus Torvalds
15802f884edSAl ViroFEXPORT(syscall_exit_partial)
15902f884edSAl Viro	local_irq_disable		# make sure need_resched doesn't
16002f884edSAl Viro					# change between and return
16102f884edSAl Viro	LONG_L	a2, TI_FLAGS($28)	# current->work
16202f884edSAl Viro	li	t0, _TIF_ALLWORK_MASK
16302f884edSAl Viro	and	t0, a2
16402f884edSAl Viro	beqz	t0, restore_partial
1651da177e4SLinus Torvalds	SAVE_STATIC
166c2648527SThiemo Seufersyscall_exit_work:
167f76f3308SAl Viro	LONG_L	t0, PT_STATUS(sp)		# returning to kernel mode?
168f76f3308SAl Viro	andi	t0, t0, KU_USER
169f76f3308SAl Viro	beqz	t0, resume_kernel
170c19c20acSRalf Baechle	li	t0, _TIF_WORK_SYSCALL_EXIT
171c2648527SThiemo Seufer	and	t0, a2			# a2 is preloaded with TI_FLAGS
172c2648527SThiemo Seufer	beqz	t0, work_pending	# trace bit set?
1738b659a39SRalf Baechle	local_irq_enable		# could let syscall_trace_leave()
1741da177e4SLinus Torvalds					# call schedule() instead
1751da177e4SLinus Torvalds	move	a0, sp
1768b659a39SRalf Baechle	jal	syscall_trace_leave
1771da177e4SLinus Torvalds	b	resume_userspace
178bce1a286SRalf Baechle
1796ebb496fSMarkos Chandras#if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) || \
1806ebb496fSMarkos Chandras    defined(CONFIG_MIPS_MT)
181bce1a286SRalf Baechle
182bce1a286SRalf Baechle/*
183bce1a286SRalf Baechle * MIPS32R2 Instruction Hazard Barrier - must be called
184bce1a286SRalf Baechle *
185bce1a286SRalf Baechle * For C code use the inline version named instruction_hazard().
186bce1a286SRalf Baechle */
187bce1a286SRalf BaechleLEAF(mips_ihb)
188bce1a286SRalf Baechle	.set	mips32r2
189bce1a286SRalf Baechle	jr.hb	ra
190bce1a286SRalf Baechle	nop
191bce1a286SRalf Baechle	END(mips_ihb)
192bce1a286SRalf Baechle
1936ebb496fSMarkos Chandras#endif /* CONFIG_CPU_MIPSR2 or CONFIG_CPU_MIPSR6 or CONFIG_MIPS_MT */
194