This commit represents a major revamping of the clock interrupt and timebase
[dragonfly.git] / sys / platform / pc32 / isa / ipl.s
CommitLineData
984263bc
MD
1/*-
2 * Copyright (c) 1989, 1990 William F. Jolitz.
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * William Jolitz.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
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.
24 *
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
35 * SUCH DAMAGE.
36 *
37 * @(#)ipl.s
38 *
39 * $FreeBSD: src/sys/i386/isa/ipl.s,v 1.32.2.3 2002/05/16 16:03:56 bde Exp $
88c4d2f6 40 * $DragonFly: src/sys/platform/pc32/isa/ipl.s,v 1.16 2004/01/30 05:42:16 dillon Exp $
984263bc
MD
41 */
42
43
44/*
45 * AT/386
46 * Vector interrupt control section
47 *
984263bc
MD
48 * *_imask - Interrupt masks for various spl*() functions
49 * ipending - Pending interrupts (set when a masked interrupt occurs)
50 */
51
52 .data
53 ALIGN_DATA
54
55/* current priority (all off) */
984263bc 56
2954c92f
MD
57 .globl tty_imask
58tty_imask: .long SWI_TTY_MASK
59 .globl bio_imask
60bio_imask: .long SWI_CLOCK_MASK | SWI_CAMBIO_MASK
61 .globl net_imask
62net_imask: .long SWI_NET_MASK | SWI_CAMNET_MASK
63 .globl cam_imask
64cam_imask: .long SWI_CAMBIO_MASK | SWI_CAMNET_MASK
65 .globl soft_imask
66soft_imask: .long SWI_MASK
67 .globl softnet_imask
68softnet_imask: .long SWI_NET_MASK
69 .globl softtty_imask
70softtty_imask: .long SWI_TTY_MASK
984263bc 71
984263bc 72 .text
46a3f46d
MD
73 /*
74 * GENERAL NOTES
75 *
76 * - fast interrupts are always called with a critical section
77 * held
78 *
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).
84 *
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.
88 *
89 * - We have to be careful in regards to local interrupts
90 * occuring simultaniously with our doreti and splz
91 * processing.
92 */
984263bc 93
ef0fdad1
MD
94 /*
95 * DORETI
96 *
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.
71ef2f5c
MD
100 *
101 * If we are in a critical section we cannot run any pending ints
102 * nor can be play with mp_lock.
46a3f46d 103 *
ef0fdad1 104 */
984263bc 105 SUPERALIGN_TEXT
2954c92f
MD
106 .type doreti,@function
107doreti:
108 FAKE_MCOUNT(bintr) /* init "from" bintr -> doreti */
ef0fdad1 109 popl %eax /* cpl to restore */
2954c92f 110 movl PCPU(curthread),%ebx
ef0fdad1 111 cli /* interlock with TDPRI_CRIT */
235957ed
MD
112 cmpl $0,PCPU(reqflags) /* short cut if nothing to do */
113 je 5f
ef0fdad1
MD
114 movl %eax,TD_CPL(%ebx) /* save cpl being restored */
115 cmpl $TDPRI_CRIT,TD_PRI(%ebx) /* can't unpend if in critical sec */
116 jge 5f
117 addl $TDPRI_CRIT,TD_PRI(%ebx) /* force all ints to pending */
984263bc 118doreti_next:
ef0fdad1
MD
119 sti /* allow new interrupts */
120 movl %eax,%ecx /* cpl being restored */
121 notl %ecx
122 cli /* disallow YYY remove */
96728c05 123#ifdef SMP
235957ed 124 testl $RQF_IPIQ,PCPU(reqflags)
96728c05
MD
125 jnz doreti_ipiq
126#endif
a2a5ad0d
MD
127 testl PCPU(fpending),%ecx /* check for an unmasked fast int */
128 jnz doreti_fast
129
130 testl PCPU(ipending),%ecx
131 jnz doreti_intr
235957ed
MD
132
133 testl $RQF_AST_MASK,PCPU(reqflags) /* any pending ASTs? */
26a0694b 134 jz 2f
984263bc 135 testl $PSL_VM,TF_EFLAGS(%esp)
ef0fdad1 136 jz 1f
235957ed
MD
137 cmpl $1,in_vm86call /* YYY make per 'cpu'? */
138 jnz doreti_ast
ef0fdad1 1391:
984263bc 140 testb $SEL_RPL_MASK,TF_CS(%esp)
235957ed 141 jnz doreti_ast
96728c05 1422:
984263bc 143 /*
ef0fdad1 144 * Nothing left to do, finish up. Interrupts are still disabled.
5c323556
MD
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.
984263bc 150 */
ef0fdad1 151 subl $TDPRI_CRIT,TD_PRI(%ebx) /* interlocked with cli */
a2a5ad0d
MD
152 testl %eax,%eax
153 jnz 5f
5c323556 154 andl $~RQF_INTPEND,PCPU(reqflags)
ef0fdad1 1555:
984263bc 156 MEXITCOUNT
984263bc 157 .globl doreti_popl_fs
ef0fdad1
MD
158 .globl doreti_popl_es
159 .globl doreti_popl_ds
160 .globl doreti_iret
984263bc
MD
161 .globl doreti_syscall_ret
162doreti_syscall_ret:
163doreti_popl_fs:
164 popl %fs
984263bc
MD
165doreti_popl_es:
166 popl %es
984263bc
MD
167doreti_popl_ds:
168 popl %ds
169 popal
170 addl $8,%esp
984263bc
MD
171doreti_iret:
172 iret
173
174 ALIGN_TEXT
175 .globl doreti_iret_fault
176doreti_iret_fault:
177 subl $8,%esp
178 pushal
179 pushl %ds
180 .globl doreti_popl_ds_fault
181doreti_popl_ds_fault:
182 pushl %es
183 .globl doreti_popl_es_fault
184doreti_popl_es_fault:
185 pushl %fs
186 .globl doreti_popl_fs_fault
187doreti_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
191
984263bc 192 /*
ef0fdad1 193 * FAST interrupt pending
984263bc 194 */
ef0fdad1
MD
195 ALIGN_TEXT
196doreti_fast:
2954c92f 197 andl PCPU(fpending),%ecx /* only check fast ints */
984263bc 198 bsfl %ecx, %ecx /* locate the next dispatchable int */
2954c92f 199 btrl %ecx, PCPU(fpending) /* is it really still pending? */
ef0fdad1 200 jnc doreti_next
96728c05
MD
201 pushl %eax /* YYY cpl (expected by frame) */
202#ifdef SMP
203 pushl %ecx /* save ecx */
204 call try_mplock
205 popl %ecx
206 testl %eax,%eax
207 jz 1f
03aa8d99 208 /* MP lock successful */
96728c05 209#endif
03aa8d99
MD
210 incl PCPU(intr_nesting_level)
211 call *fastunpend(,%ecx,4)
212 decl PCPU(intr_nesting_level)
96728c05
MD
213#ifdef SMP
214 call rel_mplock
215#endif
216 popl %eax
217 jmp doreti_next
2181:
219 btsl %ecx, PCPU(fpending) /* oops, couldn't get the MP lock */
3c23a41a 220 popl %eax /* add to temp. cpl mask to ignore */
96728c05 221 orl PCPU(fpending),%eax
ef0fdad1
MD
222 jmp doreti_next
223
984263bc 224 /*
ef0fdad1 225 * INTR interrupt pending
96728c05 226 *
46a3f46d
MD
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.
984263bc 230 */
ef0fdad1
MD
231 ALIGN_TEXT
232doreti_intr:
2954c92f 233 andl PCPU(ipending),%ecx /* only check normal ints */
ef0fdad1 234 bsfl %ecx, %ecx /* locate the next dispatchable int */
2954c92f 235 btrl %ecx, PCPU(ipending) /* is it really still pending? */
ef0fdad1 236 jnc doreti_next
984263bc
MD
237 pushl %eax
238 pushl %ecx
46a3f46d 239 incl TD_NEST_COUNT(%ebx) /* prevent doreti/splz nesting */
a2a5ad0d 240 subl $TDPRI_CRIT,TD_PRI(%ebx) /* so we can preempt */
2954c92f 241 call sched_ithd /* YYY must pull in imasks */
96728c05 242 addl $TDPRI_CRIT,TD_PRI(%ebx)
46a3f46d 243 decl TD_NEST_COUNT(%ebx)
984263bc 244 addl $4,%esp
984263bc 245 popl %eax
ef0fdad1 246 jmp doreti_next
984263bc 247
984263bc 248 /*
235957ed
MD
249 * AST pending. We clear RQF_AST_SIGNAL automatically, the others
250 * are cleared by the trap as they are processed.
a2a5ad0d
MD
251 *
252 * Temporarily back-out our critical section because trap() can be
253 * a long-winded call, and we want to be more syscall-like.
254 *
235957ed
MD
255 * YYY theoretically we can call lwkt_switch directly if all we need
256 * to do is a reschedule.
984263bc 257 */
235957ed 258doreti_ast:
a722be49 259 andl $~(RQF_AST_SIGNAL|RQF_AST_UPCALL),PCPU(reqflags)
a2a5ad0d
MD
260 sti
261 movl %eax,%esi /* save cpl (can't use stack) */
262 movl $T_ASTFLT,TF_TRAPNO(%esp)
a2a5ad0d
MD
263 subl $TDPRI_CRIT,TD_PRI(%ebx)
2641: call trap
265 addl $TDPRI_CRIT,TD_PRI(%ebx)
96728c05
MD
266 movl %esi,%eax /* restore cpl for loop */
267 jmp doreti_next
268
269#ifdef SMP
270 /*
235957ed 271 * IPIQ message pending. We clear RQF_IPIQ automatically.
96728c05
MD
272 */
273doreti_ipiq:
03aa8d99 274 incl PCPU(intr_nesting_level)
235957ed 275 andl $~RQF_IPIQ,PCPU(reqflags)
88c4d2f6
MD
276 subl $8,%esp /* add dummy vec and ppl */
277 call lwkt_process_ipiq_frame
278 addl $8,%esp
03aa8d99 279 decl PCPU(intr_nesting_level)
ef0fdad1 280 movl TD_CPL(%ebx),%eax /* retrieve cpl again for loop */
984263bc
MD
281 jmp doreti_next
282
96728c05 283#endif
ef0fdad1
MD
284
285 /*
286 * SPLZ() a C callable procedure to dispatch any unmasked pending
287 * interrupts regardless of critical section nesting. ASTs
288 * are not dispatched.
26a0694b
MD
289 *
290 * YYY at the moment I leave us in a critical section so as
291 * not to have to mess with the cpls which will soon be obsolete.
ef0fdad1
MD
292 */
293 SUPERALIGN_TEXT
294
295ENTRY(splz)
26a0694b 296 pushfl
ef0fdad1 297 pushl %ebx
2954c92f 298 movl PCPU(curthread),%ebx
ef0fdad1 299 movl TD_CPL(%ebx),%eax
26a0694b 300 addl $TDPRI_CRIT,TD_PRI(%ebx)
ef0fdad1
MD
301
302splz_next:
26a0694b 303 cli
ef0fdad1
MD
304 movl %eax,%ecx /* ecx = ~CPL */
305 notl %ecx
96728c05 306#ifdef SMP
235957ed 307 testl $RQF_IPIQ,PCPU(reqflags)
96728c05
MD
308 jnz splz_ipiq
309#endif
a2a5ad0d
MD
310 testl PCPU(fpending),%ecx /* check for an unmasked fast int */
311 jnz splz_fast
312
313 testl PCPU(ipending),%ecx
314 jnz splz_intr
96728c05 315
26a0694b 316 subl $TDPRI_CRIT,TD_PRI(%ebx)
235957ed 317
3c23a41a
MD
318 /*
319 * Nothing left to do, finish up. Interrupts are still disabled.
320 * If our temporary cpl mask is 0 then we have processed everything
321 * (including any pending fast ints requiring the MP lock), and
235957ed 322 * we can clear RQF_INTPEND.
3c23a41a 323 */
a2a5ad0d
MD
324 testl %eax,%eax
325 jnz 5f
235957ed 326 andl $~RQF_INTPEND,PCPU(reqflags)
a2a5ad0d 3275:
ef0fdad1 328 popl %ebx
26a0694b 329 popfl
984263bc
MD
330 ret
331
ef0fdad1
MD
332 /*
333 * FAST interrupt pending
334 */
984263bc 335 ALIGN_TEXT
ef0fdad1 336splz_fast:
2954c92f 337 andl PCPU(fpending),%ecx /* only check fast ints */
ef0fdad1 338 bsfl %ecx, %ecx /* locate the next dispatchable int */
2954c92f 339 btrl %ecx, PCPU(fpending) /* is it really still pending? */
ef0fdad1
MD
340 jnc splz_next
341 pushl %eax
96728c05
MD
342#ifdef SMP
343 pushl %ecx
344 call try_mplock
345 popl %ecx
346 testl %eax,%eax
347 jz 1f
348#endif
46a3f46d 349 incl PCPU(intr_nesting_level)
2954c92f 350 call *fastunpend(,%ecx,4)
46a3f46d 351 decl PCPU(intr_nesting_level)
96728c05
MD
352#ifdef SMP
353 call rel_mplock
354#endif
355 popl %eax
356 jmp splz_next
3571:
358 btsl %ecx, PCPU(fpending) /* oops, couldn't get the MP lock */
ef0fdad1 359 popl %eax
96728c05 360 orl PCPU(fpending),%eax
ef0fdad1 361 jmp splz_next
984263bc 362
ef0fdad1
MD
363 /*
364 * INTR interrupt pending
96728c05
MD
365 *
366 * Temporarily back-out our critical section to allow the interrupt
367 * preempt us.
ef0fdad1 368 */
984263bc 369 ALIGN_TEXT
ef0fdad1 370splz_intr:
2954c92f 371 andl PCPU(ipending),%ecx /* only check normal ints */
ef0fdad1 372 bsfl %ecx, %ecx /* locate the next dispatchable int */
2954c92f 373 btrl %ecx, PCPU(ipending) /* is it really still pending? */
ef0fdad1 374 jnc splz_next
26a0694b 375 sti
ef0fdad1 376 pushl %eax
984263bc 377 pushl %ecx
96728c05 378 subl $TDPRI_CRIT,TD_PRI(%ebx)
46a3f46d 379 incl TD_NEST_COUNT(%ebx) /* prevent doreti/splz nesting */
2954c92f 380 call sched_ithd /* YYY must pull in imasks */
96728c05 381 addl $TDPRI_CRIT,TD_PRI(%ebx)
46a3f46d 382 decl TD_NEST_COUNT(%ebx) /* prevent doreti/splz nesting */
ef0fdad1
MD
383 addl $4,%esp
384 popl %eax
385 jmp splz_next
984263bc 386
96728c05
MD
387#ifdef SMP
388splz_ipiq:
235957ed 389 andl $~RQF_IPIQ,PCPU(reqflags)
96728c05
MD
390 pushl %eax
391 call lwkt_process_ipiq
392 popl %eax
393 jmp splz_next
394#endif
395
ef0fdad1
MD
396 /*
397 * APIC/ICU specific ipl functions provide masking and unmasking
398 * calls for userland.
399 */
984263bc
MD
400
401#ifdef APIC_IO
402#include "i386/isa/apic_ipl.s"
403#else
404#include "i386/isa/icu_ipl.s"
405#endif /* APIC_IO */