2 * Copyright (c) 1989, 1990 William F. Jolitz.
3 * Copyright (c) 1990 The Regents of the University of California.
6 * This code is derived from software contributed to Berkeley by
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * $FreeBSD: src/sys/i386/isa/ipl.s,v 1.32.2.3 2002/05/16 16:03:56 bde Exp $
40 * $DragonFly: src/sys/i386/isa/Attic/ipl.s,v 1.15 2003/11/21 05:29:08 dillon Exp $
46 * Vector interrupt control section
48 * *_imask - Interrupt masks for various spl*() functions
49 * ipending - Pending interrupts (set when a masked interrupt occurs)
55 /* current priority (all off) */
58 tty_imask: .long SWI_TTY_MASK
60 bio_imask: .long SWI_CLOCK_MASK | SWI_CAMBIO_MASK
62 net_imask: .long SWI_NET_MASK | SWI_CAMNET_MASK
64 cam_imask: .long SWI_CAMBIO_MASK | SWI_CAMNET_MASK
66 soft_imask: .long SWI_MASK
68 softnet_imask: .long SWI_NET_MASK
70 softtty_imask: .long SWI_TTY_MASK
76 * - fast interrupts are always called with a critical section
79 * - we release our critical section when scheduling interrupt
80 * or softinterrupt threads in order so they can preempt
81 * (unless we are called manually from a critical section, in
82 * which case there will still be a critical section and
83 * they won't preempt anyway).
85 * - TD_NEST_COUNT prevents splz from nesting too deeply within
86 * itself. It is *not* actually an interrupt nesting count.
87 * PCPU(intr_nesting_level) is an interrupt nesting count.
89 * - We have to be careful in regards to local interrupts
90 * occuring simultaniously with our doreti and splz
97 * Handle return from interrupts, traps and syscalls. This function
98 * checks the cpl for unmasked pending interrupts (fast, normal, or
99 * soft) and schedules them if appropriate, then irets.
101 * If we are in a critical section we cannot run any pending ints
102 * nor can be play with mp_lock.
106 .type doreti,@function
108 FAKE_MCOUNT(bintr) /* init "from" bintr -> doreti */
109 popl %eax /* cpl to restore */
110 movl PCPU(curthread),%ebx
111 cli /* interlock with TDPRI_CRIT */
112 cmpl $0,PCPU(reqflags) /* short cut if nothing to do */
114 movl %eax,TD_CPL(%ebx) /* save cpl being restored */
115 cmpl $TDPRI_CRIT,TD_PRI(%ebx) /* can't unpend if in critical sec */
117 addl $TDPRI_CRIT,TD_PRI(%ebx) /* force all ints to pending */
119 sti /* allow new interrupts */
120 movl %eax,%ecx /* cpl being restored */
122 cli /* disallow YYY remove */
124 testl $RQF_IPIQ,PCPU(reqflags)
127 testl PCPU(fpending),%ecx /* check for an unmasked fast int */
130 testl PCPU(ipending),%ecx
133 testl $RQF_AST_MASK,PCPU(reqflags) /* any pending ASTs? */
135 testl $PSL_VM,TF_EFLAGS(%esp)
137 cmpl $1,in_vm86call /* YYY make per 'cpu'? */
140 testb $SEL_RPL_MASK,TF_CS(%esp)
144 * Nothing left to do, finish up. Interrupts are still disabled.
145 * If our temporary cpl mask is 0 then we have processed all pending
146 * fast and normal ints including those requiring the MP lock,
147 * and we have processed as many of the reqflags as possible based
148 * on whether we came from user mode or not. So if %eax is 0 we
149 * can clear the interrupt-related reqflags.
151 subl $TDPRI_CRIT,TD_PRI(%ebx) /* interlocked with cli */
154 andl $~RQF_INTPEND,PCPU(reqflags)
157 .globl doreti_popl_fs
158 .globl doreti_popl_es
159 .globl doreti_popl_ds
161 .globl doreti_syscall_ret
175 .globl doreti_iret_fault
180 .globl doreti_popl_ds_fault
181 doreti_popl_ds_fault:
183 .globl doreti_popl_es_fault
184 doreti_popl_es_fault:
186 .globl doreti_popl_fs_fault
187 doreti_popl_fs_fault:
188 movl $0,TF_ERR(%esp) /* XXX should be the error code */
189 movl $T_PROTFLT,TF_TRAPNO(%esp)
190 jmp alltraps_with_regs_pushed
193 * FAST interrupt pending
197 andl PCPU(fpending),%ecx /* only check fast ints */
198 bsfl %ecx, %ecx /* locate the next dispatchable int */
199 btrl %ecx, PCPU(fpending) /* is it really still pending? */
201 pushl %eax /* YYY cpl (expected by frame) */
203 pushl %ecx /* save ecx */
208 /* MP lock successful */
210 incl PCPU(intr_nesting_level)
211 call *fastunpend(,%ecx,4)
212 decl PCPU(intr_nesting_level)
219 btsl %ecx, PCPU(fpending) /* oops, couldn't get the MP lock */
220 popl %eax /* add to temp. cpl mask to ignore */
221 orl PCPU(fpending),%eax
225 * INTR interrupt pending
227 * Temporarily back-out our critical section to allow an interrupt
228 * preempt us when we schedule it. Bump intr_nesting_level to
229 * prevent the switch code from recursing via splz too deeply.
233 andl PCPU(ipending),%ecx /* only check normal ints */
234 bsfl %ecx, %ecx /* locate the next dispatchable int */
235 btrl %ecx, PCPU(ipending) /* is it really still pending? */
239 incl TD_NEST_COUNT(%ebx) /* prevent doreti/splz nesting */
240 subl $TDPRI_CRIT,TD_PRI(%ebx) /* so we can preempt */
241 call sched_ithd /* YYY must pull in imasks */
242 addl $TDPRI_CRIT,TD_PRI(%ebx)
243 decl TD_NEST_COUNT(%ebx)
249 * AST pending. We clear RQF_AST_SIGNAL automatically, the others
250 * are cleared by the trap as they are processed.
252 * Temporarily back-out our critical section because trap() can be
253 * a long-winded call, and we want to be more syscall-like.
255 * YYY theoretically we can call lwkt_switch directly if all we need
256 * to do is a reschedule.
259 andl $~(RQF_AST_SIGNAL|RQF_AST_UPCALL),PCPU(reqflags)
261 movl %eax,%esi /* save cpl (can't use stack) */
262 movl $T_ASTFLT,TF_TRAPNO(%esp)
263 subl $TDPRI_CRIT,TD_PRI(%ebx)
265 addl $TDPRI_CRIT,TD_PRI(%ebx)
266 movl %esi,%eax /* restore cpl for loop */
271 * IPIQ message pending. We clear RQF_IPIQ automatically.
274 incl PCPU(intr_nesting_level)
275 andl $~RQF_IPIQ,PCPU(reqflags)
276 call lwkt_process_ipiq
277 decl PCPU(intr_nesting_level)
278 movl TD_CPL(%ebx),%eax /* retrieve cpl again for loop */
284 * SPLZ() a C callable procedure to dispatch any unmasked pending
285 * interrupts regardless of critical section nesting. ASTs
286 * are not dispatched.
288 * YYY at the moment I leave us in a critical section so as
289 * not to have to mess with the cpls which will soon be obsolete.
296 movl PCPU(curthread),%ebx
297 movl TD_CPL(%ebx),%eax
298 addl $TDPRI_CRIT,TD_PRI(%ebx)
302 movl %eax,%ecx /* ecx = ~CPL */
305 testl $RQF_IPIQ,PCPU(reqflags)
308 testl PCPU(fpending),%ecx /* check for an unmasked fast int */
311 testl PCPU(ipending),%ecx
314 subl $TDPRI_CRIT,TD_PRI(%ebx)
317 * Nothing left to do, finish up. Interrupts are still disabled.
318 * If our temporary cpl mask is 0 then we have processed everything
319 * (including any pending fast ints requiring the MP lock), and
320 * we can clear RQF_INTPEND.
324 andl $~RQF_INTPEND,PCPU(reqflags)
331 * FAST interrupt pending
335 andl PCPU(fpending),%ecx /* only check fast ints */
336 bsfl %ecx, %ecx /* locate the next dispatchable int */
337 btrl %ecx, PCPU(fpending) /* is it really still pending? */
347 incl PCPU(intr_nesting_level)
348 call *fastunpend(,%ecx,4)
349 decl PCPU(intr_nesting_level)
356 btsl %ecx, PCPU(fpending) /* oops, couldn't get the MP lock */
358 orl PCPU(fpending),%eax
362 * INTR interrupt pending
364 * Temporarily back-out our critical section to allow the interrupt
369 andl PCPU(ipending),%ecx /* only check normal ints */
370 bsfl %ecx, %ecx /* locate the next dispatchable int */
371 btrl %ecx, PCPU(ipending) /* is it really still pending? */
376 subl $TDPRI_CRIT,TD_PRI(%ebx)
377 incl TD_NEST_COUNT(%ebx) /* prevent doreti/splz nesting */
378 call sched_ithd /* YYY must pull in imasks */
379 addl $TDPRI_CRIT,TD_PRI(%ebx)
380 decl TD_NEST_COUNT(%ebx) /* prevent doreti/splz nesting */
387 andl $~RQF_IPIQ,PCPU(reqflags)
389 call lwkt_process_ipiq
395 * APIC/ICU specific ipl functions provide masking and unmasking
396 * calls for userland.
400 #include "i386/isa/apic_ipl.s"
402 #include "i386/isa/icu_ipl.s"