psl.h revision 1.14 1 /* $NetBSD: psl.h,v 1.14 1998/11/24 17:07:54 kleink Exp $ */
2
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef PSL_C
40 #include <m68k/psl.h>
41
42 /* Could define this in the common <m68k/psl.h> instead. */
43
44 #if defined(_KERNEL) && !defined(_LOCORE)
45
46 #ifndef __GNUC__
47 /* No inline, use the real functions in locore.s */
48 extern int _getsr __P((void));
49 extern int _spl __P((int new));
50 extern int _splraise __P((int new));
51 #else /* GNUC */
52 /*
53 * Define inline functions for PSL manipulation.
54 * These are as close to macros as one can get.
55 * When not optimizing gcc will call the locore.s
56 * functions by the same names, so breakpoints on
57 * these functions will work normally, etc.
58 * (See the GCC extensions info document.)
59 */
60
61 static __inline int _getsr __P((void));
62 static __inline int _spl __P((int));
63 static __inline int _splraise __P((int));
64
65 /* Get current sr value. */
66 static __inline int
67 _getsr(void)
68 {
69 register int rv;
70
71 __asm __volatile ("clrl %0; movew sr,%0" : "&=d" (rv));
72 return (rv);
73 }
74
75 /* Set the current sr and return the old value. */
76 static __inline int
77 _spl(int new)
78 {
79 register int old;
80
81 __asm __volatile (
82 "clrl %0; movew sr,%0; movew %1,sr" :
83 "&=d" (old) : "di" (new));
84 return (old);
85 }
86
87 /*
88 * Like _spl() but can be used in places where the
89 * interrupt priority may already have been raised,
90 * without risk of enabling interrupts by accident.
91 * The comparison includes the "S" bit (always on)
92 * because that generates more efficient code.
93 */
94 static __inline int
95 _splraise(int new)
96 {
97 register int old;
98
99 __asm __volatile ("clrl %0; movew sr,%0" : "&=d" (old));
100 if ((old & PSL_HIGHIPL) < new) {
101 __asm __volatile ("movew %0,sr;" : : "di" (new));
102 }
103 return (old);
104 }
105 #endif /* GNUC */
106
107 /*
108 * The rest of this is sun3 specific, because other ports may
109 * need to do special things in spl0() (i.e. simulate SIR).
110 * Suns have a REAL interrupt register, so spl0() and splx(s)
111 * have no need to check for any simulated interrupts, etc.
112 */
113
114 #define spl0() _spl(PSL_S|PSL_IPL0)
115 #define spl1() _spl(PSL_S|PSL_IPL1)
116 #define spl2() _spl(PSL_S|PSL_IPL2)
117 #define spl3() _spl(PSL_S|PSL_IPL3)
118 #define spl4() _spl(PSL_S|PSL_IPL4)
119 #define spl5() _spl(PSL_S|PSL_IPL5)
120 #define spl6() _spl(PSL_S|PSL_IPL6)
121 #define spl7() _spl(PSL_S|PSL_IPL7)
122 #define splx(x) _spl(x)
123
124 /* IPL used by soft interrupts: netintr(), softclock() */
125 #define splsoftclock() spl1()
126 #define splsoftnet() spl1()
127
128 /* Highest block device (strategy) IPL. */
129 #define splbio() spl2()
130
131 /* Highest network interface IPL. */
132 #define splnet() spl3()
133
134 /* Highest tty device IPL. */
135 #define spltty() spl4()
136
137 /*
138 * Requirement: imp >= (highest network, tty, or disk IPL)
139 * This is used mostly in the VM code. (Why not splvm?)
140 * Note that the VM code runs at spl7 during kernel
141 * initialization, and later at spl0, so we have to
142 * use splraise to avoid enabling interrupts early.
143 */
144 #define splimp() _splraise(PSL_S|PSL_IPL4)
145
146 /* Intersil clock hardware interrupts (hard-wired at 5) */
147 #define splclock() spl5()
148 #define splstatclock() splclock()
149
150 /* Block out all interrupts (except NMI of course). */
151 #define splhigh() spl7()
152 #define splsched() spl7()
153
154 #endif /* KERNEL && !_LOCORE */
155 #endif /* PSL_C */
156