entry.S 4.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 1994 - 2000, 2001, 2003 Ralf Baechle
 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
 * Copyright (C) 2001 MIPS Technologies, Inc.
 */

#include <asm/asm.h>
#include <asm/asmmacro.h>
#include <asm/regdef.h>
#include <asm/mipsregs.h>
#include <asm/stackframe.h>
#include <asm/isadep.h>
#include <asm/thread_info.h>
#include <asm/war.h>

A
Atsushi Nemoto 已提交
20
#ifndef CONFIG_PREEMPT
L
Linus Torvalds 已提交
21
#define resume_kernel	restore_all
22 23
#else
#define __ret_from_irq	ret_from_exception
L
Linus Torvalds 已提交
24 25 26 27
#endif

	.text
	.align	5
28
#ifndef CONFIG_PREEMPT
L
Linus Torvalds 已提交
29
FEXPORT(ret_from_exception)
30 31
	local_irq_disable			# preempt stop
	b	__ret_from_irq
A
Atsushi Nemoto 已提交
32
#endif
33 34 35
FEXPORT(ret_from_irq)
	LONG_S	s0, TI_REGS($28)
FEXPORT(__ret_from_irq)
36 37 38 39 40
/*
 * We can be coming here from a syscall done in the kernel space,
 * e.g. a failed kernel_execve().
 */
resume_userspace_check:
L
Linus Torvalds 已提交
41 42 43 44
	LONG_L	t0, PT_STATUS(sp)		# returning to kernel mode?
	andi	t0, t0, KU_USER
	beqz	t0, resume_kernel

45 46
resume_userspace:
	local_irq_disable		# make sure we dont miss an
L
Linus Torvalds 已提交
47 48 49
					# interrupt setting need_resched
					# between sampling and return
	LONG_L	a2, TI_FLAGS($28)	# current->work
50 51
	andi	t0, a2, _TIF_WORK_MASK	# (ignoring syscall_trace)
	bnez	t0, work_pending
L
Linus Torvalds 已提交
52 53 54
	j	restore_all

#ifdef CONFIG_PREEMPT
55
resume_kernel:
R
Ralf Baechle 已提交
56
	local_irq_disable
L
Linus Torvalds 已提交
57 58 59 60 61 62 63 64 65
	lw	t0, TI_PRE_COUNT($28)
	bnez	t0, restore_all
need_resched:
	LONG_L	t0, TI_FLAGS($28)
	andi	t1, t0, _TIF_NEED_RESCHED
	beqz	t1, restore_all
	LONG_L	t0, PT_STATUS(sp)		# Interrupts off?
	andi	t0, 1
	beqz	t0, restore_all
R
Ralf Baechle 已提交
66
	jal	preempt_schedule_irq
R
Ralf Baechle 已提交
67
	b	need_resched
L
Linus Torvalds 已提交
68 69
#endif

A
Al Viro 已提交
70 71 72 73
FEXPORT(ret_from_kernel_thread)
	jal	schedule_tail		# a0 = struct task_struct *prev
	move	a0, s1
	jal	s0
74
	j	syscall_exit
A
Al Viro 已提交
75

L
Linus Torvalds 已提交
76
FEXPORT(ret_from_fork)
77
	jal	schedule_tail		# a0 = struct task_struct *prev
L
Linus Torvalds 已提交
78 79 80 81 82 83 84 85 86 87

FEXPORT(syscall_exit)
	local_irq_disable		# make sure need_resched and
					# signals dont change between
					# sampling and return
	LONG_L	a2, TI_FLAGS($28)	# current->work
	li	t0, _TIF_ALLWORK_MASK
	and	t0, a2, t0
	bnez	t0, syscall_exit_work

88
restore_all:				# restore full frame
L
Linus Torvalds 已提交
89 90 91 92
	.set	noat
	RESTORE_TEMP
	RESTORE_AT
	RESTORE_STATIC
93
restore_partial:		# restore partial frame
94 95 96 97 98
#ifdef CONFIG_TRACE_IRQFLAGS
	SAVE_STATIC
	SAVE_AT
	SAVE_TEMP
	LONG_L	v0, PT_STATUS(sp)
99 100 101 102 103
#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
	and	v0, ST0_IEP
#else
	and	v0, ST0_IE
#endif
104 105 106 107 108 109 110 111 112
	beqz	v0, 1f
	jal	trace_hardirqs_on
	b	2f
1:	jal	trace_hardirqs_off
2:
	RESTORE_TEMP
	RESTORE_AT
	RESTORE_STATIC
#endif
L
Linus Torvalds 已提交
113 114 115 116
	RESTORE_SOME
	RESTORE_SP_AND_RET
	.set	at

117 118
work_pending:
	andi	t0, a2, _TIF_NEED_RESCHED # a2 is preloaded with TI_FLAGS
L
Linus Torvalds 已提交
119 120 121 122
	beqz	t0, work_notifysig
work_resched:
	jal	schedule

123
	local_irq_disable		# make sure need_resched and
L
Linus Torvalds 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136 137
					# signals dont change between
					# sampling and return
	LONG_L	a2, TI_FLAGS($28)
	andi	t0, a2, _TIF_WORK_MASK	# is there any work to be done
					# other than syscall tracing?
	beqz	t0, restore_all
	andi	t0, a2, _TIF_NEED_RESCHED
	bnez	t0, work_resched

work_notifysig:				# deal with pending signals and
					# notify-resume requests
	move	a0, sp
	li	a1, 0
	jal	do_notify_resume	# a2 already loaded
138
	j	resume_userspace_check
L
Linus Torvalds 已提交
139

140 141 142 143 144 145 146
FEXPORT(syscall_exit_partial)
	local_irq_disable		# make sure need_resched doesn't
					# change between and return
	LONG_L	a2, TI_FLAGS($28)	# current->work
	li	t0, _TIF_ALLWORK_MASK
	and	t0, a2
	beqz	t0, restore_partial
L
Linus Torvalds 已提交
147
	SAVE_STATIC
148
syscall_exit_work:
149 150 151
	LONG_L	t0, PT_STATUS(sp)		# returning to kernel mode?
	andi	t0, t0, KU_USER
	beqz	t0, resume_kernel
152
	li	t0, _TIF_WORK_SYSCALL_EXIT
153 154
	and	t0, a2			# a2 is preloaded with TI_FLAGS
	beqz	t0, work_pending	# trace bit set?
155
	local_irq_enable		# could let syscall_trace_leave()
L
Linus Torvalds 已提交
156 157
					# call schedule() instead
	move	a0, sp
158
	jal	syscall_trace_leave
L
Linus Torvalds 已提交
159
	b	resume_userspace
160

161 162
#if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) || \
    defined(CONFIG_MIPS_MT)
163 164 165 166 167 168 169 170 171 172 173 174

/*
 * MIPS32R2 Instruction Hazard Barrier - must be called
 *
 * For C code use the inline version named instruction_hazard().
 */
LEAF(mips_ihb)
	.set	mips32r2
	jr.hb	ra
	nop
	END(mips_ihb)

175
#endif /* CONFIG_CPU_MIPSR2 or CONFIG_CPU_MIPSR6 or CONFIG_MIPS_MT */