2 * from: vector.s, 386BSD 0.1 unknown origin
3 * $FreeBSD: src/sys/i386/isa/icu_vector.s,v 1.14.2.2 2000/07/18 21:12:42 dfr Exp $
6 * WARNING! SMP builds can use the ICU now so this code must be MP safe.
9 #include "opt_auto_eoi.h"
11 #include <machine/asmacros.h>
12 #include <machine/lock.h>
13 #include <machine/psl.h>
14 #include <machine/trap.h>
15 #include <machine_base/icu/icu.h>
16 #include <machine_base/icu/icu_ipl.h>
18 #include <bus/isa/isa.h>
22 #define ICU_EOI 0x20 /* XXX - define elsewhere */
24 #define IRQ_LBIT(irq_num) (1 << (irq_num))
25 #define IRQ_BIT(irq_num) (1 << ((irq_num) % 8))
26 #define IRQ_BYTE(irq_num) ((irq_num) >> 3)
29 #define ENABLE_ICU1 /* use auto-EOI to reduce i/o */
33 movb $ICU_EOI,%al ; /* as soon as possible send EOI ... */ \
34 OUTB_ICU1 ; /* ... to clear in service bit */ \
43 * The data sheet says no auto-EOI on slave, but it sometimes works.
45 #define ENABLE_ICU1_AND_2 ENABLE_ICU1
47 #define ENABLE_ICU1_AND_2 \
48 movb $ICU_EOI,%al ; /* as above */ \
49 outb %al,$IO_ICU2 ; /* but do second icu first ... */ \
50 OUTB_ICU1 ; /* ... then first icu (if !AUTO_EOI_1) */ \
58 pushl $0 ; /* dummy error code */ \
59 pushl $0 ; /* dummy trap type */ \
60 pushl $0 ; /* dummy xflags */ \
61 pushal ; /* 8 registers */ \
75 pushfl ; /* phys int frame / flags */ \
76 pushl %cs ; /* phys int frame / cs */ \
77 pushl 12(%esp) ; /* original caller eip */ \
78 pushl $0 ; /* dummy error code */ \
79 pushl $0 ; /* dummy trap type */ \
80 pushl $0 ; /* dummy xflags */ \
81 subl $13*4,%esp ; /* pushal + 4 seg regs (dummy) + CPL */ \
84 * Warning: POP_FRAME can only be used if there is no chance of a
85 * segment register being changed (e.g. by procfs), which is why syscalls
94 addl $2*4,%esp ; /* dummy trap & error codes */ \
99 #define MASK_IRQ(icu, irq_num) \
101 movb icu_imen + IRQ_BYTE(irq_num),%al ; \
102 orb $IRQ_BIT(irq_num),%al ; \
103 movb %al,icu_imen + IRQ_BYTE(irq_num) ; \
104 outb %al,$icu+ICU_IMR_OFFSET ; \
107 #define UNMASK_IRQ(icu, irq_num) \
111 movb icu_imen + IRQ_BYTE(irq_num),%al ; \
112 andb $~IRQ_BIT(irq_num),%al ; \
113 movb %al,icu_imen + IRQ_BYTE(irq_num) ; \
114 outb %al,$icu+ICU_IMR_OFFSET ; \
119 * Interrupt call handlers run in the following sequence:
121 * - Push the trap frame required by doreti.
122 * - Mask the interrupt and reenable its source.
123 * - If we cannot take the interrupt set its ipending bit and
125 * - If we can take the interrupt clear its ipending bit,
126 * call the handler, then unmask the interrupt and doreti.
128 * YYY can cache gd base pointer instead of using hidden %fs
132 #define INTR_HANDLER(irq_num, icu, enable_icus) \
135 IDTVEC(icu_intr##irq_num) ; \
137 FAKE_MCOUNT(15*4(%esp)) ; \
138 MASK_IRQ(icu, irq_num) ; \
140 movl PCPU(curthread),%ebx ; \
141 pushl $0 ; /* DUMMY CPL FOR DORETI */ \
142 testl $-1,TD_NEST_COUNT(%ebx) ; \
144 testl $-1,TD_CRITCOUNT(%ebx) ; \
147 /* set pending bit and return, leave interrupt masked */ \
149 orl $IRQ_LBIT(irq_num),PCPU_E4(ipending,%edx) ; \
150 orl $RQF_INTPEND, PCPU(reqflags) ; \
153 /* clear pending bit, run handler */ \
155 andl $~IRQ_LBIT(irq_num),PCPU_E4(ipending,%edx) ; \
157 pushl %esp ; /* pass frame by reference */ \
158 incl TD_CRITCOUNT(%ebx) ; \
160 call ithread_fast_handler ; /* returns 0 to unmask int */ \
161 decl TD_CRITCOUNT(%ebx) ; \
163 UNMASK_IRQ(icu, irq_num) ; \
168 INTR_HANDLER(0, IO_ICU1, ENABLE_ICU1)
169 INTR_HANDLER(1, IO_ICU1, ENABLE_ICU1)
170 INTR_HANDLER(2, IO_ICU1, ENABLE_ICU1)
171 INTR_HANDLER(3, IO_ICU1, ENABLE_ICU1)
172 INTR_HANDLER(4, IO_ICU1, ENABLE_ICU1)
173 INTR_HANDLER(5, IO_ICU1, ENABLE_ICU1)
174 INTR_HANDLER(6, IO_ICU1, ENABLE_ICU1)
175 INTR_HANDLER(7, IO_ICU1, ENABLE_ICU1)
176 INTR_HANDLER(8, IO_ICU2, ENABLE_ICU1_AND_2)
177 INTR_HANDLER(9, IO_ICU2, ENABLE_ICU1_AND_2)
178 INTR_HANDLER(10, IO_ICU2, ENABLE_ICU1_AND_2)
179 INTR_HANDLER(11, IO_ICU2, ENABLE_ICU1_AND_2)
180 INTR_HANDLER(12, IO_ICU2, ENABLE_ICU1_AND_2)
181 INTR_HANDLER(13, IO_ICU2, ENABLE_ICU1_AND_2)
182 INTR_HANDLER(14, IO_ICU2, ENABLE_ICU1_AND_2)
183 INTR_HANDLER(15, IO_ICU2, ENABLE_ICU1_AND_2)