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