intr.h revision 1.1
11.1Sscottr/*	$NetBSD: intr.h,v 1.1 1997/04/13 05:12:40 scottr Exp $	*/
21.1Sscottr
31.1Sscottr#ifndef _MAC68K_INTR_H_
41.1Sscottr#define _MAC68K_INTR_H_
51.1Sscottr
61.1Sscottr#ifdef _KERNEL
71.1Sscottr/*
81.1Sscottr * spl functions; all but spl0 are done in-line
91.1Sscottr */
101.1Sscottr
111.1Sscottr#define _spl(s)								\
121.1Sscottr({									\
131.1Sscottr        register int _spl_r;						\
141.1Sscottr									\
151.1Sscottr        __asm __volatile ("clrl %0; movew sr,%0; movew %1,sr" :		\
161.1Sscottr                "&=d" (_spl_r) : "di" (s));				\
171.1Sscottr        _spl_r;								\
181.1Sscottr})
191.1Sscottr
201.1Sscottr#define _splraise(s)							\
211.1Sscottr({									\
221.1Sscottr	register int _spl_r;						\
231.1Sscottr									\
241.1Sscottr	__asm __volatile ("clrl %0; movew sr,%0;" : "&=d" (_spl_r) : );	\
251.1Sscottr	if ((_spl_r & PSL_IPL) < ((s) & PSL_IPL))			\
261.1Sscottr		__asm __volatile ("movew %0,sr;" : : "di" (s));		\
271.1Sscottr	_spl_r;								\
281.1Sscottr})
291.1Sscottr
301.1Sscottr/* spl0 requires checking for software interrupts */
311.1Sscottr#define spl1()  _spl(PSL_S|PSL_IPL1)
321.1Sscottr#define spl2()  _spl(PSL_S|PSL_IPL2)
331.1Sscottr#define spl3()  _spl(PSL_S|PSL_IPL3)
341.1Sscottr#define spl4()  _spl(PSL_S|PSL_IPL4)
351.1Sscottr#define spl5()  _spl(PSL_S|PSL_IPL5)
361.1Sscottr#define spl6()  _spl(PSL_S|PSL_IPL6)
371.1Sscottr#define spl7()  _spl(PSL_S|PSL_IPL7)
381.1Sscottr
391.1Sscottr/*
401.1Sscottr * These should be used for:
411.1Sscottr * 1) ensuring mutual exclusion (why use processor level?)
421.1Sscottr * 2) allowing faster devices to take priority
431.1Sscottr *
441.1Sscottr * Note that on the Mac, most things are masked at spl1, almost
451.1Sscottr * everything at spl2, and everything but the panic switch and
461.1Sscottr * power at spl4.
471.1Sscottr */
481.1Sscottr#define	splsoftclock()	spl1()	/* disallow softclock */
491.1Sscottr#define	splsoftnet()	spl1()	/* disallow network */
501.1Sscottr#define	spltty()	spl1()	/* disallow tty (softserial & ADB) */
511.1Sscottr#define	splbio()	spl2()	/* disallow block I/O */
521.1Sscottr#define	splnet()	spl2()	/* disallow network */
531.1Sscottr#define	splimp()	spl2()	/* mutual exclusion for memory allocation */
541.1Sscottr#define	splclock()	spl2()	/* disallow clock (and other) interrupts */
551.1Sscottr#define	splstatclock()	spl2()	/* ditto */
561.1Sscottr#define	splzs()		spl4()	/* disallow serial hw interrupts */
571.1Sscottr#define	spladb()	spl7()	/* disallow adb interrupts */
581.1Sscottr#define	splhigh()	spl7()	/* disallow everything */
591.1Sscottr#define	splsched()	spl7()	/* disallow scheduling */
601.1Sscottr
611.1Sscottr/* watch out for side effects */
621.1Sscottr#define splx(s)         ((s) & PSL_IPL ? _spl(s) : spl0())
631.1Sscottr
641.1Sscottr/*
651.1Sscottr * simulated software interrupt register
661.1Sscottr */
671.1Sscottrextern volatile u_int8_t ssir;
681.1Sscottr
691.1Sscottr#define	SIR_NET		0x01
701.1Sscottr#define	SIR_CLOCK	0x02
711.1Sscottr#define	SIR_SERIAL	0x04
721.1Sscottr
731.1Sscottr#define	siron(mask)	\
741.1Sscottr	__asm __volatile ( "orb %0,_ssir" : : "i" (mask))
751.1Sscottr#define	siroff(mask)	\
761.1Sscottr	__asm __volatile ( "andb %0,_ssir" : : "ir" (~(mask)));
771.1Sscottr
781.1Sscottr#define	setsoftnet()	siron(SIR_NET)
791.1Sscottr#define	setsoftclock()	siron(SIR_CLOCK)
801.1Sscottr#define	setsoftserial()	siron(SIR_SERIAL)
811.1Sscottr
821.1Sscottr/* locore.s */
831.1Sscottrint	spl0 __P((void));
841.1Sscottr#endif /* _KERNEL */
851.1Sscottr
861.1Sscottr#endif /* _MAC68K_INTR_H_ */
87