interrupt.s 1.79 KB
/**************************************************************************
 *									  *
 *		 Copyright (C) 1994, Silicon Graphics, Inc.		  *
 *									  *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright law.  They  may  not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *									  *
 **************************************************************************/

#include <asm.h>
#include <regdef.h>
#include <R4300.h>
#include "threadasm.h"

	.set	noreorder
/*
 * u32 __osDisableInt(void)
 *
 * Disable interrupts by flipping the interrupt enable bit off;
 * return previous state of this bit.
 */

LEAF(__osDisableInt)
	/* Load GlobalIntMask */
	la      t2, __OSGlobalIntMask
	lw      t3, 0(t2)
	andi    t3, SR_IMASK		/* t3 = old GlobalIntMask */

	/* Load SR register */
	mfc0	t0,C0_SR
	
	/* Turn off IE */
	and	t1, t0, ~SR_IE
	mtc0	t1, C0_SR

	/* Set return Value (SR_IE bit: 0 or 1) */
	and	v0, t0, SR_IE
	
	/* Check GlobalIntMask change */
	lw	t0, 0(t2)
	andi    t0, SR_IMASK		/* t0 = new GlobalIntMask */
	beq	t0, t3, No_Change_Global_Int
	
	/* Set new GlobalIntMask */
	la	t2,__osRunningThread
	lw      t1,T_CONTEXT_SR(t2)
	and	t2, t1, SR_IMASK
	and	t2, t0
	and	t1, ~SR_IMASK
	or	t1, t2
	and	t1, t1, ~SR_IE
	mtc0	t1,C0_SR
	nop
	nop

No_Change_Global_Int:	
	j	ra
	nop
END(__osDisableInt)


/*
 * void __osRestoreInt(u32 enable)
 *
 * Restore the previous state of the interrupt enable bit.
 */
LEAF(__osRestoreInt)
        mfc0    t0,C0_SR
        or      t0,a0
        mtc0    t0,C0_SR
        nop
        nop
        j       ra
        nop
END(__osRestoreInt)