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> 1941c594abSRalf Baechle#ifdef CONFIG_MIPS_MT_SMTC 2041c594abSRalf Baechle#include <asm/mipsmtregs.h> 2141c594abSRalf Baechle#endif 221da177e4SLinus Torvalds 23f431baa5SAtsushi Nemoto#ifndef CONFIG_PREEMPT 241da177e4SLinus Torvalds#define resume_kernel restore_all 257da8a581SFranck Bui-Huu#else 267da8a581SFranck Bui-Huu#define __ret_from_irq ret_from_exception 271da177e4SLinus Torvalds#endif 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds .text 301da177e4SLinus Torvalds .align 5 317da8a581SFranck Bui-Huu#ifndef CONFIG_PREEMPT 327da8a581SFranck Bui-HuuFEXPORT(ret_from_exception) 337da8a581SFranck Bui-Huu local_irq_disable # preempt stop 347da8a581SFranck Bui-Huu b __ret_from_irq 357da8a581SFranck Bui-Huu#endif 36f431baa5SAtsushi NemotoFEXPORT(ret_from_irq) 37f431baa5SAtsushi Nemoto LONG_S s0, TI_REGS($28) 387da8a581SFranck Bui-HuuFEXPORT(__ret_from_irq) 391da177e4SLinus Torvalds LONG_L t0, PT_STATUS(sp) # returning to kernel mode? 401da177e4SLinus Torvalds andi t0, t0, KU_USER 411da177e4SLinus Torvalds beqz t0, resume_kernel 421da177e4SLinus Torvalds 43c2648527SThiemo Seuferresume_userspace: 44c2648527SThiemo Seufer local_irq_disable # make sure we dont miss an 451da177e4SLinus Torvalds # interrupt setting need_resched 461da177e4SLinus Torvalds # between sampling and return 471da177e4SLinus Torvalds LONG_L a2, TI_FLAGS($28) # current->work 48c2648527SThiemo Seufer andi t0, a2, _TIF_WORK_MASK # (ignoring syscall_trace) 49c2648527SThiemo Seufer bnez t0, work_pending 501da177e4SLinus Torvalds j restore_all 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 53c2648527SThiemo Seuferresume_kernel: 54a18815abSRalf Baechle local_irq_disable 551da177e4SLinus Torvalds lw t0, TI_PRE_COUNT($28) 561da177e4SLinus Torvalds bnez t0, restore_all 571da177e4SLinus Torvaldsneed_resched: 581da177e4SLinus Torvalds LONG_L t0, TI_FLAGS($28) 591da177e4SLinus Torvalds andi t1, t0, _TIF_NEED_RESCHED 601da177e4SLinus Torvalds beqz t1, restore_all 611da177e4SLinus Torvalds LONG_L t0, PT_STATUS(sp) # Interrupts off? 621da177e4SLinus Torvalds andi t0, 1 631da177e4SLinus Torvalds beqz t0, restore_all 64a18815abSRalf Baechle jal preempt_schedule_irq 65cdaed73aSRalf Baechle b need_resched 661da177e4SLinus Torvalds#endif 671da177e4SLinus Torvalds 68*8f54bcacSAl ViroFEXPORT(ret_from_kernel_thread) 69*8f54bcacSAl Viro jal schedule_tail # a0 = struct task_struct *prev 70*8f54bcacSAl Viro move a0, s1 71*8f54bcacSAl Viro jal s0 72*8f54bcacSAl Viro li a0, 0 73*8f54bcacSAl Viro j sys_exit 74*8f54bcacSAl Viro 751da177e4SLinus TorvaldsFEXPORT(ret_from_fork) 7636c8b586SIngo Molnar jal schedule_tail # a0 = struct task_struct *prev 771da177e4SLinus Torvalds 781da177e4SLinus TorvaldsFEXPORT(syscall_exit) 791da177e4SLinus Torvalds local_irq_disable # make sure need_resched and 801da177e4SLinus Torvalds # signals dont change between 811da177e4SLinus Torvalds # sampling and return 821da177e4SLinus Torvalds LONG_L a2, TI_FLAGS($28) # current->work 831da177e4SLinus Torvalds li t0, _TIF_ALLWORK_MASK 841da177e4SLinus Torvalds and t0, a2, t0 851da177e4SLinus Torvalds bnez t0, syscall_exit_work 861da177e4SLinus Torvalds 8702f884edSAl Virorestore_all: # restore full frame 8841c594abSRalf Baechle#ifdef CONFIG_MIPS_MT_SMTC 890db34215SKevin D. Kissell#ifdef CONFIG_MIPS_MT_SMTC_IM_BACKSTOP 9041c594abSRalf Baechle/* Re-arm any temporarily masked interrupts not explicitly "acked" */ 9141c594abSRalf Baechle mfc0 v0, CP0_TCSTATUS 9241c594abSRalf Baechle ori v1, v0, TCSTATUS_IXMT 9341c594abSRalf Baechle mtc0 v1, CP0_TCSTATUS 9441c594abSRalf Baechle andi v0, TCSTATUS_IXMT 954277ff5eSRalf Baechle _ehb 9641c594abSRalf Baechle mfc0 t0, CP0_TCCONTEXT 9741c594abSRalf Baechle DMT 9 # dmt t1 9841c594abSRalf Baechle jal mips_ihb 9941c594abSRalf Baechle mfc0 t2, CP0_STATUS 10041c594abSRalf Baechle andi t3, t0, 0xff00 10141c594abSRalf Baechle or t2, t2, t3 10241c594abSRalf Baechle mtc0 t2, CP0_STATUS 1034277ff5eSRalf Baechle _ehb 10441c594abSRalf Baechle andi t1, t1, VPECONTROL_TE 10541c594abSRalf Baechle beqz t1, 1f 10641c594abSRalf Baechle EMT 10741c594abSRalf Baechle1: 10841c594abSRalf Baechle mfc0 v1, CP0_TCSTATUS 109477654fcSRalf Baechle /* We set IXMT above, XOR should clear it here */ 11041c594abSRalf Baechle xori v1, v1, TCSTATUS_IXMT 11141c594abSRalf Baechle or v1, v0, v1 11241c594abSRalf Baechle mtc0 v1, CP0_TCSTATUS 1134277ff5eSRalf Baechle _ehb 11441c594abSRalf Baechle xor t0, t0, t3 11541c594abSRalf Baechle mtc0 t0, CP0_TCCONTEXT 1160db34215SKevin D. Kissell#endif /* CONFIG_MIPS_MT_SMTC_IM_BACKSTOP */ 117d2bb01b0SKevin D. Kissell/* Detect and execute deferred IPI "interrupts" */ 118d2bb01b0SKevin D. Kissell LONG_L s0, TI_REGS($28) 119d2bb01b0SKevin D. Kissell LONG_S sp, TI_REGS($28) 120d2bb01b0SKevin D. Kissell jal deferred_smtc_ipi 121d2bb01b0SKevin D. Kissell LONG_S s0, TI_REGS($28) 12241c594abSRalf Baechle#endif /* CONFIG_MIPS_MT_SMTC */ 1231da177e4SLinus Torvalds .set noat 1241da177e4SLinus Torvalds RESTORE_TEMP 1251da177e4SLinus Torvalds RESTORE_AT 1261da177e4SLinus Torvalds RESTORE_STATIC 12702f884edSAl Virorestore_partial: # restore partial frame 128192ef366SRalf Baechle#ifdef CONFIG_TRACE_IRQFLAGS 129192ef366SRalf Baechle SAVE_STATIC 130192ef366SRalf Baechle SAVE_AT 131192ef366SRalf Baechle SAVE_TEMP 132192ef366SRalf Baechle LONG_L v0, PT_STATUS(sp) 133cbde5ebcSChris Dearman#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX) 134cbde5ebcSChris Dearman and v0, ST0_IEP 135cbde5ebcSChris Dearman#else 136cbde5ebcSChris Dearman and v0, ST0_IE 137cbde5ebcSChris Dearman#endif 138192ef366SRalf Baechle beqz v0, 1f 139192ef366SRalf Baechle jal trace_hardirqs_on 140192ef366SRalf Baechle b 2f 141192ef366SRalf Baechle1: jal trace_hardirqs_off 142192ef366SRalf Baechle2: 143192ef366SRalf Baechle RESTORE_TEMP 144192ef366SRalf Baechle RESTORE_AT 145192ef366SRalf Baechle RESTORE_STATIC 146192ef366SRalf Baechle#endif 1471da177e4SLinus Torvalds RESTORE_SOME 1481da177e4SLinus Torvalds RESTORE_SP_AND_RET 1491da177e4SLinus Torvalds .set at 1501da177e4SLinus Torvalds 151c2648527SThiemo Seuferwork_pending: 152c2648527SThiemo Seufer andi t0, a2, _TIF_NEED_RESCHED # a2 is preloaded with TI_FLAGS 1531da177e4SLinus Torvalds beqz t0, work_notifysig 1541da177e4SLinus Torvaldswork_resched: 1551da177e4SLinus Torvalds jal schedule 1561da177e4SLinus Torvalds 157c2648527SThiemo Seufer local_irq_disable # make sure need_resched and 1581da177e4SLinus Torvalds # signals dont change between 1591da177e4SLinus Torvalds # sampling and return 1601da177e4SLinus Torvalds LONG_L a2, TI_FLAGS($28) 1611da177e4SLinus Torvalds andi t0, a2, _TIF_WORK_MASK # is there any work to be done 1621da177e4SLinus Torvalds # other than syscall tracing? 1631da177e4SLinus Torvalds beqz t0, restore_all 1641da177e4SLinus Torvalds andi t0, a2, _TIF_NEED_RESCHED 1651da177e4SLinus Torvalds bnez t0, work_resched 1661da177e4SLinus Torvalds 1671da177e4SLinus Torvaldswork_notifysig: # deal with pending signals and 1681da177e4SLinus Torvalds # notify-resume requests 1691da177e4SLinus Torvalds move a0, sp 1701da177e4SLinus Torvalds li a1, 0 1711da177e4SLinus Torvalds jal do_notify_resume # a2 already loaded 1720bf0e3e2SRalf Baechle j resume_userspace 1731da177e4SLinus Torvalds 17402f884edSAl ViroFEXPORT(syscall_exit_partial) 17502f884edSAl Viro local_irq_disable # make sure need_resched doesn't 17602f884edSAl Viro # change between and return 17702f884edSAl Viro LONG_L a2, TI_FLAGS($28) # current->work 17802f884edSAl Viro li t0, _TIF_ALLWORK_MASK 17902f884edSAl Viro and t0, a2 18002f884edSAl Viro beqz t0, restore_partial 1811da177e4SLinus Torvalds SAVE_STATIC 182c2648527SThiemo Seufersyscall_exit_work: 183f76f3308SAl Viro LONG_L t0, PT_STATUS(sp) # returning to kernel mode? 184f76f3308SAl Viro andi t0, t0, KU_USER 185f76f3308SAl Viro beqz t0, resume_kernel 186c19c20acSRalf Baechle li t0, _TIF_WORK_SYSCALL_EXIT 187c2648527SThiemo Seufer and t0, a2 # a2 is preloaded with TI_FLAGS 188c2648527SThiemo Seufer beqz t0, work_pending # trace bit set? 1898b659a39SRalf Baechle local_irq_enable # could let syscall_trace_leave() 1901da177e4SLinus Torvalds # call schedule() instead 1911da177e4SLinus Torvalds move a0, sp 1928b659a39SRalf Baechle jal syscall_trace_leave 1931da177e4SLinus Torvalds b resume_userspace 194bce1a286SRalf Baechle 195bce1a286SRalf Baechle#if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_MIPS_MT) 196bce1a286SRalf Baechle 197bce1a286SRalf Baechle/* 198bce1a286SRalf Baechle * MIPS32R2 Instruction Hazard Barrier - must be called 199bce1a286SRalf Baechle * 200bce1a286SRalf Baechle * For C code use the inline version named instruction_hazard(). 201bce1a286SRalf Baechle */ 202bce1a286SRalf BaechleLEAF(mips_ihb) 203bce1a286SRalf Baechle .set mips32r2 204bce1a286SRalf Baechle jr.hb ra 205bce1a286SRalf Baechle nop 206bce1a286SRalf Baechle END(mips_ihb) 207bce1a286SRalf Baechle 208bce1a286SRalf Baechle#endif /* CONFIG_CPU_MIPSR2 or CONFIG_MIPS_MT */ 209