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.8 2003/07/10 04:47:54 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
77 * Handle return from interrupts, traps and syscalls. This function
78 * checks the cpl for unmasked pending interrupts (fast, normal, or
79 * soft) and schedules them if appropriate, then irets.
82 .type doreti,@function
84 FAKE_MCOUNT(bintr) /* init "from" bintr -> doreti */
85 popl %eax /* cpl to restore */
86 movl PCPU(curthread),%ebx
87 cli /* interlock with TDPRI_CRIT */
88 movl %eax,TD_CPL(%ebx) /* save cpl being restored */
89 cmpl $TDPRI_CRIT,TD_PRI(%ebx) /* can't unpend if in critical sec */
91 addl $TDPRI_CRIT,TD_PRI(%ebx) /* force all ints to pending */
93 sti /* allow new interrupts */
94 movl %eax,%ecx /* cpl being restored */
96 cli /* disallow YYY remove */
98 testl $AST_IPIQ,PCPU(astpending)
101 testl PCPU(fpending),%ecx /* check for an unmasked fast int */
104 testl PCPU(ipending),%ecx
106 testl $AST_PENDING,PCPU(astpending) /* any pending ASTs? */
108 testl $PSL_VM,TF_EFLAGS(%esp)
110 cmpl $1,in_vm86call /* YYY make per 'cpu' */
113 testb $SEL_RPL_MASK,TF_CS(%esp)
117 * Nothing left to do, finish up. Interrupts are still disabled.
119 subl $TDPRI_CRIT,TD_PRI(%ebx) /* interlocked with cli */
124 decl PCPU(intr_nesting_level)
126 .globl doreti_popl_fs
127 .globl doreti_popl_es
128 .globl doreti_popl_ds
130 .globl doreti_syscall_ret
144 .globl doreti_iret_fault
149 .globl doreti_popl_ds_fault
150 doreti_popl_ds_fault:
152 .globl doreti_popl_es_fault
153 doreti_popl_es_fault:
155 .globl doreti_popl_fs_fault
156 doreti_popl_fs_fault:
157 movl $0,TF_ERR(%esp) /* XXX should be the error code */
158 movl $T_PROTFLT,TF_TRAPNO(%esp)
159 jmp alltraps_with_regs_pushed
162 * FAST interrupt pending
166 andl PCPU(fpending),%ecx /* only check fast ints */
167 bsfl %ecx, %ecx /* locate the next dispatchable int */
168 btrl %ecx, PCPU(fpending) /* is it really still pending? */
170 pushl %eax /* YYY cpl (expected by frame) */
172 pushl %ecx /* save ecx */
178 call *fastunpend(,%ecx,4) /* MP lock successful */
185 btsl %ecx, PCPU(fpending) /* oops, couldn't get the MP lock */
187 orl PCPU(fpending),%eax
191 * INTR interrupt pending
193 * Temporarily back-out our critical section to allow the interrupt
198 andl PCPU(ipending),%ecx /* only check normal ints */
199 bsfl %ecx, %ecx /* locate the next dispatchable int */
200 btrl %ecx, PCPU(ipending) /* is it really still pending? */
204 subl $TDPRI_CRIT,TD_PRI(%ebx) /* so we can preempt */
205 call sched_ithd /* YYY must pull in imasks */
206 addl $TDPRI_CRIT,TD_PRI(%ebx)
214 * Temporarily back-out our critical section because trap() can be
215 * a long-winded call, and we want to be more syscall-like.
217 * YYY If we came in from user mode (doreti_ast1) we can call
218 * lwkt_switch *RIGHT* *NOW* to deal with interrupts more quickly,
219 * but should still fall through to the trap code to properly
224 andl $~AST_PENDING,PCPU(astpending)
226 movl %eax,%esi /* save cpl (can't use stack) */
227 movl $T_ASTFLT,TF_TRAPNO(%esp)
228 decl PCPU(intr_nesting_level) /* syscall-like, not interrupt-like */
229 subl $TDPRI_CRIT,TD_PRI(%ebx)
234 andl $~AST_PENDING,PCPU(astpending)
236 movl %eax,%esi /* save cpl (can't use stack) */
237 movl $T_ASTFLT,TF_TRAPNO(%esp)
238 decl PCPU(intr_nesting_level) /* syscall-like, not interrupt-like */
239 subl $TDPRI_CRIT,TD_PRI(%ebx)
241 addl $TDPRI_CRIT,TD_PRI(%ebx)
242 incl PCPU(intr_nesting_level)
243 movl %esi,%eax /* restore cpl for loop */
248 * IPIQ message pending
251 andl $~AST_IPIQ,PCPU(astpending)
252 call lwkt_process_ipiq
253 movl TD_CPL(%ebx),%eax /* retrieve cpl again for loop */
259 * SPLZ() a C callable procedure to dispatch any unmasked pending
260 * interrupts regardless of critical section nesting. ASTs
261 * are not dispatched.
263 * YYY at the moment I leave us in a critical section so as
264 * not to have to mess with the cpls which will soon be obsolete.
271 movl PCPU(curthread),%ebx
272 movl TD_CPL(%ebx),%eax
273 addl $TDPRI_CRIT,TD_PRI(%ebx)
277 movl %eax,%ecx /* ecx = ~CPL */
280 testl $AST_IPIQ,PCPU(astpending)
283 testl PCPU(fpending),%ecx /* check for an unmasked fast int */
286 testl PCPU(ipending),%ecx
289 subl $TDPRI_CRIT,TD_PRI(%ebx)
299 * FAST interrupt pending
303 andl PCPU(fpending),%ecx /* only check fast ints */
304 bsfl %ecx, %ecx /* locate the next dispatchable int */
305 btrl %ecx, PCPU(fpending) /* is it really still pending? */
315 call *fastunpend(,%ecx,4)
322 btsl %ecx, PCPU(fpending) /* oops, couldn't get the MP lock */
324 orl PCPU(fpending),%eax
328 * INTR interrupt pending
330 * Temporarily back-out our critical section to allow the interrupt
335 andl PCPU(ipending),%ecx /* only check normal ints */
336 bsfl %ecx, %ecx /* locate the next dispatchable int */
337 btrl %ecx, PCPU(ipending) /* is it really still pending? */
342 subl $TDPRI_CRIT,TD_PRI(%ebx)
343 call sched_ithd /* YYY must pull in imasks */
344 addl $TDPRI_CRIT,TD_PRI(%ebx)
351 andl $~AST_IPIQ,PCPU(astpending)
353 call lwkt_process_ipiq
359 * APIC/ICU specific ipl functions provide masking and unmasking
360 * calls for userland.
364 #include "i386/isa/apic_ipl.s"
366 #include "i386/isa/icu_ipl.s"