patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / arch / mips / kernel / entry.S
1 /*
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
20 #ifdef CONFIG_PREEMPT
21         .macro  preempt_stop reg=t0
22         .endm
23 #else
24         .macro  preempt_stop reg=t0
25         local_irq_disable \reg
26         .endm
27 #define resume_kernel   restore_all
28 #endif
29
30         .text
31         .align  5
32 FEXPORT(ret_from_exception)
33         preempt_stop
34 FEXPORT(ret_from_irq)
35         LONG_L  t0, PT_STATUS(sp)               # returning to kernel mode?
36         andi    t0, t0, KU_USER
37         beqz    t0, resume_kernel
38
39 FEXPORT(resume_userspace)
40         local_irq_disable       t0      # make sure we dont miss an
41                                         # interrupt setting need_resched
42                                         # between sampling and return
43         LONG_L  a2, TI_FLAGS($28)       # current->work
44         andi    a2, _TIF_WORK_MASK      # (ignoring syscall_trace)
45         bnez    a2, work_pending
46         j       restore_all
47
48 #ifdef CONFIG_PREEMPT
49 ENTRY(resume_kernel)
50         lw      t0, TI_PRE_COUNT($28)
51         bnez    t0, restore_all
52 need_resched:
53         LONG_L  t0, TI_FLAGS($28)
54         andi    t1, t0, _TIF_NEED_RESCHED
55         beqz    t1, restore_all
56         LONG_L  t0, PT_STATUS(sp)               # Interrupts off?
57         andi    t0, 1
58         beqz    t0, restore_all
59         li      t0, PREEMPT_ACTIVE
60         sw      t0, TI_PRE_COUNT($28)
61         local_irq_enable t0
62         jal     schedule
63         sw      zero, TI_PRE_COUNT($28)
64         local_irq_disable t0
65         b       need_resched
66 #endif
67
68 FEXPORT(ret_from_fork)
69         jal     schedule_tail           # a0 = task_t *prev
70
71 FEXPORT(syscall_exit)
72         local_irq_disable               # make sure need_resched and
73                                         # signals dont change between
74                                         # sampling and return
75         LONG_L  a2, TI_FLAGS($28)       # current->work
76         li      t0, _TIF_ALLWORK_MASK
77         and     t0, a2, t0
78         bnez    t0, syscall_exit_work
79
80 FEXPORT(restore_all)                    # restore full frame
81         .set    noat
82         RESTORE_TEMP
83         RESTORE_AT
84         RESTORE_STATIC
85 FEXPORT(restore_partial)                # restore partial frame
86         RESTORE_SOME
87         RESTORE_SP_AND_RET
88         .set    at
89
90 FEXPORT(work_pending)
91         andi    t0, a2, _TIF_NEED_RESCHED
92         beqz    t0, work_notifysig
93 work_resched:
94         jal     schedule
95
96         local_irq_disable t0            # make sure need_resched and
97                                         # signals dont change between
98                                         # sampling and return
99         LONG_L  a2, TI_FLAGS($28)
100         andi    t0, a2, _TIF_WORK_MASK  # is there any work to be done
101                                         # other than syscall tracing?
102         beqz    t0, restore_all
103         andi    t0, a2, _TIF_NEED_RESCHED
104         bnez    t0, work_resched
105
106 work_notifysig:                         # deal with pending signals and
107                                         # notify-resume requests
108         move    a0, sp
109         li      a1, 0
110         jal     do_notify_resume        # a2 already loaded
111         j       restore_all
112
113 FEXPORT(syscall_exit_work_partial)
114         SAVE_STATIC
115 FEXPORT(syscall_exit_work)
116         LONG_L  t0, TI_FLAGS($28)
117         li      t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
118         and     t0, t1
119         beqz    t0, work_pending        # trace bit is set
120         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  */
130         .text
131         .align  5
132 LEAF(spurious_interrupt)
133         /*
134          * Someone tried to fool us by sending an interrupt but we
135          * couldn't find a cause for it.
136          */
137 #ifdef CONFIG_SMP
138         lui     t1, %hi(irq_err_count)
139 1:      ll      t0, %lo(irq_err_count)(t1)
140         addiu   t0, 1
141         sc      t0, %lo(irq_err_count)(t1)
142         beqz    t0, 1b
143 #else
144         lui     t1, %hi(irq_err_count)
145         lw      t0, %lo(irq_err_count)(t1)
146         addiu   t0, 1
147         sw      t0, %lo(irq_err_count)(t1)
148 #endif
149         j       ret_from_irq
150         END(spurious_interrupt)