+#include <machine/psl.h>
+
+#define _spl(s) \
+({ \
+ register int _spl_r; \
+\
+ asm __volatile ("clrl %0; movew sr,%0; movew %1,sr" : \
+ "&=d" (_spl_r) : "di" (s)); \
+ _spl_r; \
+})
+
+/* spl0 requires checking for software interrupts */
+#define spl1() _spl(PSL_S|PSL_IPL1)
+#define spl2() _spl(PSL_S|PSL_IPL2)
+#define spl3() _spl(PSL_S|PSL_IPL3)
+#define spl4() _spl(PSL_S|PSL_IPL4)
+#define spl5() _spl(PSL_S|PSL_IPL5)
+#define spl6() _spl(PSL_S|PSL_IPL6)
+#define spl7() _spl(PSL_S|PSL_IPL7)
+
+#define splsoftclock() spl1()
+#define splnet() spl1()
+#define splbio() spl5()
+#define splimp() spl5()
+#define spltty() spl5()
+#define splclock() spl6()
+#define splstatclock() spl6()
+#define splvm() spl6()
+#define splhigh() spl7()
+#define splsched() spl7()
+
+/* watch out for side effects */
+#define splx(s) (s & PSL_IPL ? _spl(s) : spl0())