FreeBSD/Linux Kernel Cross Reference
sys/i386/spl.s
1 /*
2 * Mach Operating System
3 * Copyright (c) 1993,1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: spl.s,v $
29 * Revision 2.10 93/11/17 16:39:44 dbg
30 * Use PIC masks directly as SPL values.
31 * [93/10/29 dbg]
32 *
33 * Remove softclock checks.
34 * [93/02/18 dbg]
35 *
36 * Revision 2.9 93/02/04 07:58:11 danner
37 * Convert asm comment "/" over to "/ *" "* /"
38 * [93/01/27 rvb]
39 *
40 * Revision 2.8 91/06/06 17:04:01 jsb
41 * Added spldcm for i386ipsc.
42 * [91/05/13 16:53:38 jsb]
43 *
44 * Revision 2.7 91/05/14 16:16:41 mrt
45 * Correcting copyright
46 *
47 * Revision 2.6 91/05/08 12:42:29 dbg
48 * Put parentheses around substituted immediate expressions, so
49 * that they will pass through the GNU preprocessor.
50 *
51 * Add set_spl_noi to reset PIC masks but leave interrupts disabled
52 * (IF clear).
53 * [91/04/26 14:38:31 dbg]
54 *
55 * Revision 2.5 91/02/05 17:14:45 mrt
56 * Changed to new Mach copyright
57 * [91/02/01 17:38:06 mrt]
58 *
59 * Revision 2.4 90/12/20 16:36:50 jeffreyh
60 * Changes for __STDC__
61 * [90/12/07 jeffreyh]
62 *
63 * Revision 2.3 90/11/26 14:48:50 rvb
64 * Change Prime copyright as per Peter J. Weyman authorization.
65 * [90/11/19 rvb]
66 *
67 * Revision 2.2 90/05/03 15:37:36 dbg
68 * Stole from Prime.
69 * [90/02/14 dbg]
70 *
71 */
72
73 /*
74 Copyright (c) 1988,1989 Prime Computer, Inc. Natick, MA 01760
75 All Rights Reserved.
76
77 Permission to use, copy, modify, and distribute this
78 software and its documentation for any purpose and
79 without fee is hereby granted, provided that the above
80 copyright notice appears in all copies and that both the
81 copyright notice and this permission notice appear in
82 supporting documentation, and that the name of Prime
83 Computer, Inc. not be used in advertising or publicity
84 pertaining to distribution of the software without
85 specific, written prior permission.
86
87 THIS SOFTWARE IS PROVIDED "AS IS", AND PRIME COMPUTER,
88 INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
89 SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
90 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN
91 NO EVENT SHALL PRIME COMPUTER, INC. BE LIABLE FOR ANY
92 SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
93 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
94 PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR
95 OTHER TORTIOUS ACTION, ARISING OUR OF OR IN CONNECTION
96 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
97 */
98
99 #include <i386/asm.h>
100 #include <i386/ipl.h>
101 #include <i386/pic.h>
102
103 /* *****************************************************************************
104 SET_PIC_MASK : this routine is run to set the pic masks. It is
105 implemented as a macro for efficiency reasons.
106 ***************************************************************************** */
107
108 #define SET_PIC_MASK \
109 outb %al, $(MASTER_OCW) ; \
110 movb %ah, %al ; \
111 outb %al, $(SLAVE_OCW)
112
113
114 /* *****************************************************************************
115 SPLn : change interrupt priority level to that in %eax
116 SPLOFF : disable all interrupts, saving interrupt flag
117 SPLON: re-enable interrupt flag, undoes sploff()
118 Warning: SPLn and SPLOFF aren`t nestable. That is,
119 a = sploff();
120 ...
121 b = splmumble();
122 ...
123 splx(b);
124 ...
125 splon(a);
126 is going to do the wrong thing.
127 ***************************************************************************** */
128
129 /*
130 * The representation of the IPL is:
131 *
132 * bits 0..15 PIC mask value
133 * bit 31 nonzero if all interrupts are blocked
134 * at CPU (IF set).
135 *
136 * If interrupts are blocked at the CPU, the PIC mask may not
137 * need to be changed when the old IPL is restored.
138 */
139
140 ENTRY(spl0)
141 movw _pic_mask+2*0, %ax
142 jmp EXT(set_spl_mask)
143
144 ENTRY(spl1)
145 ENTRY(splsoftclock)
146 movw _pic_mask+2*1, %ax
147 jmp EXT(set_spl_mask)
148
149 ENTRY(spl2)
150 movw _pic_mask+2*2, %ax
151 jmp EXT(set_spl_mask)
152
153 ENTRY(spl3)
154 movw _pic_mask+2*3, %ax
155 jmp EXT(set_spl_mask)
156
157 ENTRY(splnet)
158 ENTRY(splhdw)
159 ENTRY(spl4)
160 movw _pic_mask+2*4, %ax
161 jmp EXT(set_spl_mask)
162
163 ENTRY(splbio)
164 ENTRY(spldcm)
165 ENTRY(spl5)
166 movw _pic_mask+2*5, %ax
167 jmp EXT(set_spl_mask)
168
169 ENTRY(spltty)
170 ENTRY(spl6)
171 movw _pic_mask+2*6, %ax
172 jmp EXT(set_spl_mask)
173
174
175 ENTRY(set_spl)
176 movw _pic_mask(,%eax,2),%ax /* enter with SPL number */
177
178 /*
179 * Set IPL for levels 0..6 (not blocking all interrupts).
180 * New pic mask is in %ax.
181 * Uses %edx.
182 * Returns old SPL in %eax.
183 */
184 .globl _set_spl_mask
185 _set_spl_mask:
186 andl $0xffff,%eax /* zero high bit (IF off) of new IPL */
187 cli /* disable interrupts */
188 movl _curr_ipl, %edx /* get old IPL */
189 movl %eax, _curr_ipl /* set new IPL */
190 cmpw %ax, %dx /* if new PIC mask is different, */
191 je 0f
192 SET_PIC_MASK /* set it. */
193 0:
194 sti /* enable processor interrupts */
195 movl %edx,%eax /* return old level */
196 ret
197
198 /*
199 * Block all interrupts.
200 */
201 ENTRY(splclock)
202 ENTRY(splimp)
203 ENTRY(splvm)
204 ENTRY(splsched)
205 ENTRY(splhigh)
206 ENTRY(splhi)
207 ENTRY(spl7)
208
209 cli /* 3 disable interrupts */
210 movl _curr_ipl, %eax /* return old IPL */
211 movb $0x80, _curr_ipl+3 /* 2 mark as disabled,*/
212 ret /* 10 preserve image of PIC mask */
213 /* ------ */
214 /* 19 */
215
216 ENTRY(sploff) /* 7 */
217 pushf /* 2 Flags reg NOT accessable */
218 popl %eax /* 2 push onto stk, pop it into reg */
219 cli /* 3 DISABLE ALL INTERRUPTS */
220 ret /* 7 */
221 /* ------ */
222 /* 21 */
223
224 ENTRY(splon) /* 7 */
225 pushl 4(%esp) /* 4 Flags regs not directly settable. */
226 popf /* 4 push value, pop into flags reg */
227 /* IF ints were enabled before */
228 /* then they are re-enabled now. */
229 ret /* 7 */
230 /* ------ */
231 /* 22 */
232
233 /*
234 * void splx(spl_t)
235 *
236 * Sets the IPL back to an old value that was gotten from
237 * spl<n> or pic_mask[] directly.
238 *
239 */
240 ENTRY(splx)
241 movl 4(%esp),%eax /* get new interrupt level from stack */
242 cli /* block interrupts */
243 testl %eax,%eax /* all interrupts blocked? */
244 js splx_high /* exit now if so, leaving
245 PIC mask unchanged. */
246
247 /* we now know that IF will be set */
248 movl _curr_ipl,%edx /* get current IPL */
249 movl %eax,_curr_ipl /* set new IPL (clears 'IF-set') */
250 cmpw %ax,%dx /* if PIC mask needs to be changed, */
251 je 0f
252 SET_PIC_MASK /* do so */
253 0:
254 sti /* reenable processor interrupts */
255 ret /* and return */
256
257 splx_high: /* leave interrupts disabled */
258 movb $0x80,_curr_ipl+3 /* at processor, and mark them so */
259 ret
260
261 /*
262 * Set SPL, but leave interrupts disabled. Called when returning
263 * from interrupt. Interrupts are already disabled.
264 * New interrupt level is in %ax; since this is called from
265 * an interrupt, we know that it cannot be SPLHIGH.
266 */
267 .globl EXT(set_spl_noi)
268 LEXT(set_spl_noi)
269 movl _curr_ipl,%edx /* get current IPL */
270 movl %eax,_curr_ipl /* set new IPL (clears 'IF-set') */
271 cmpw %ax,%dx /* if PIC mask needs to be changed, */
272 je 0f
273 SET_PIC_MASK /* do so */
274 0:
275 ret
Cache object: 67dd5bbddb2b9bc0785e7f7bfdd46839
|