blob: be0354a14e262ba2364e11bb3c117e2cf084a966 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1994 - 2000, 2001, 2003 Ralf Baechle
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 * Copyright (C) 2001 MIPS Technologies, Inc.
9 */
10#include <linux/config.h>
11
12#include <asm/asm.h>
13#include <asm/asmmacro.h>
14#include <asm/regdef.h>
15#include <asm/mipsregs.h>
16#include <asm/stackframe.h>
17#include <asm/isadep.h>
18#include <asm/thread_info.h>
19#include <asm/war.h>
20
21#ifdef CONFIG_PREEMPT
Thiemo Seuferc2648522004-12-10 12:56:33 +000022 .macro preempt_stop
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 .endm
24#else
Thiemo Seuferc2648522004-12-10 12:56:33 +000025 .macro preempt_stop
26 local_irq_disable
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 .endm
28#define resume_kernel restore_all
29#endif
30
31 .text
32 .align 5
33FEXPORT(ret_from_exception)
34 preempt_stop
35FEXPORT(ret_from_irq)
36 LONG_L t0, PT_STATUS(sp) # returning to kernel mode?
37 andi t0, t0, KU_USER
38 beqz t0, resume_kernel
39
Thiemo Seuferc2648522004-12-10 12:56:33 +000040resume_userspace:
41 local_irq_disable # make sure we dont miss an
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 # interrupt setting need_resched
43 # between sampling and return
44 LONG_L a2, TI_FLAGS($28) # current->work
Thiemo Seuferc2648522004-12-10 12:56:33 +000045 andi t0, a2, _TIF_WORK_MASK # (ignoring syscall_trace)
46 bnez t0, work_pending
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 j restore_all
48
49#ifdef CONFIG_PREEMPT
Thiemo Seuferc2648522004-12-10 12:56:33 +000050resume_kernel:
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 lw t0, TI_PRE_COUNT($28)
52 bnez t0, restore_all
53need_resched:
54 LONG_L t0, TI_FLAGS($28)
55 andi t1, t0, _TIF_NEED_RESCHED
56 beqz t1, restore_all
57 LONG_L t0, PT_STATUS(sp) # Interrupts off?
58 andi t0, 1
59 beqz t0, restore_all
60 li t0, PREEMPT_ACTIVE
61 sw t0, TI_PRE_COUNT($28)
Thiemo Seuferc2648522004-12-10 12:56:33 +000062 local_irq_enable
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 jal schedule
64 sw zero, TI_PRE_COUNT($28)
Thiemo Seuferc2648522004-12-10 12:56:33 +000065 local_irq_disable
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 b need_resched
67#endif
68
69FEXPORT(ret_from_fork)
70 jal schedule_tail # a0 = task_t *prev
71
72FEXPORT(syscall_exit)
73 local_irq_disable # make sure need_resched and
74 # signals dont change between
75 # sampling and return
76 LONG_L a2, TI_FLAGS($28) # current->work
77 li t0, _TIF_ALLWORK_MASK
78 and t0, a2, t0
79 bnez t0, syscall_exit_work
80
81FEXPORT(restore_all) # restore full frame
82 .set noat
83 RESTORE_TEMP
84 RESTORE_AT
85 RESTORE_STATIC
86FEXPORT(restore_partial) # restore partial frame
87 RESTORE_SOME
88 RESTORE_SP_AND_RET
89 .set at
90
Thiemo Seuferc2648522004-12-10 12:56:33 +000091work_pending:
92 andi t0, a2, _TIF_NEED_RESCHED # a2 is preloaded with TI_FLAGS
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 beqz t0, work_notifysig
94work_resched:
95 jal schedule
96
Thiemo Seuferc2648522004-12-10 12:56:33 +000097 local_irq_disable # make sure need_resched and
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 # signals dont change between
99 # sampling and return
100 LONG_L a2, TI_FLAGS($28)
101 andi t0, a2, _TIF_WORK_MASK # is there any work to be done
102 # other than syscall tracing?
103 beqz t0, restore_all
104 andi t0, a2, _TIF_NEED_RESCHED
105 bnez t0, work_resched
106
107work_notifysig: # deal with pending signals and
108 # notify-resume requests
109 move a0, sp
110 li a1, 0
111 jal do_notify_resume # a2 already loaded
112 j restore_all
113
114FEXPORT(syscall_exit_work_partial)
115 SAVE_STATIC
Thiemo Seuferc2648522004-12-10 12:56:33 +0000116syscall_exit_work:
117 li t0, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
118 and t0, a2 # a2 is preloaded with TI_FLAGS
119 beqz t0, work_pending # trace bit set?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 local_irq_enable # could let do_syscall_trace()
121 # call schedule() instead
122 move a0, sp
123 li a1, 1
124 jal do_syscall_trace
125 b resume_userspace
126
127/*
128 * Common spurious interrupt handler.
129 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130LEAF(spurious_interrupt)
131 /*
132 * Someone tried to fool us by sending an interrupt but we
133 * couldn't find a cause for it.
134 */
Thiemo Seuferb59a9502004-12-04 21:35:05 +0000135 PTR_LA t1, irq_err_count
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#ifdef CONFIG_SMP
Thiemo Seuferb59a9502004-12-04 21:35:05 +00001371: ll t0, (t1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 addiu t0, 1
Thiemo Seuferb59a9502004-12-04 21:35:05 +0000139 sc t0, (t1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#if R10000_LLSC_WAR
141 beqzl t0, 1b
142#else
143 beqz t0, 1b
144#endif
145#else
Thiemo Seuferb59a9502004-12-04 21:35:05 +0000146 lw t0, (t1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 addiu t0, 1
Thiemo Seuferb59a9502004-12-04 21:35:05 +0000148 sw t0, (t1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#endif
150 j ret_from_irq
151 END(spurious_interrupt)