]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i386/isa/atpic_vector.s
Use the MI ithread helper functions in the x86 interrupt code.
[FreeBSD/FreeBSD.git] / sys / i386 / isa / atpic_vector.s
1 /*
2  *      from: vector.s, 386BSD 0.1 unknown origin
3  * $FreeBSD$
4  */
5
6 /*
7  * modified for PC98 by Kakefuda
8  */
9
10 #ifdef PC98
11 #define ICU_IMR_OFFSET          2       /* IO_ICU{1,2} + 2 */
12 #else
13 #define ICU_IMR_OFFSET          1       /* IO_ICU{1,2} + 1 */
14 #endif
15
16 #define ICU_EOI                 0x20    /* XXX - define elsewhere */
17
18 #define IRQ_BIT(irq_num)        (1 << ((irq_num) % 8))
19 #define IRQ_BYTE(irq_num)       ((irq_num) >> 3)
20
21 #ifdef AUTO_EOI_1
22 #define ENABLE_ICU1             /* use auto-EOI to reduce i/o */
23 #define OUTB_ICU1
24 #else
25 #define ENABLE_ICU1 \
26         movb    $ICU_EOI,%al ;  /* as soon as possible send EOI ... */ \
27         OUTB_ICU1               /* ... to clear in service bit */
28 #define OUTB_ICU1 \
29         outb    %al,$IO_ICU1
30 #endif
31
32 #ifdef AUTO_EOI_2
33 /*
34  * The data sheet says no auto-EOI on slave, but it sometimes works.
35  */
36 #define ENABLE_ICU1_AND_2       ENABLE_ICU1
37 #else
38 #define ENABLE_ICU1_AND_2 \
39         movb    $ICU_EOI,%al ;  /* as above */ \
40         outb    %al,$IO_ICU2 ;  /* but do second icu first ... */ \
41         OUTB_ICU1               /* ... then first icu (if !AUTO_EOI_1) */
42 #endif
43
44 /*
45  * Macros for interrupt interrupt entry, call to handler, and exit.
46  */
47
48 #define FAST_INTR(irq_num, vec_name, enable_icus) \
49         .text ; \
50         SUPERALIGN_TEXT ; \
51 IDTVEC(vec_name) ; \
52         pushl   $0 ;            /* dummy error code */ \
53         pushl   $0 ;            /* dummy trap type */ \
54         pushal ; \
55         pushl   %ds ; \
56         pushl   %es ; \
57         pushl   %fs ; \
58         mov     $KDSEL,%ax ; \
59         mov     %ax,%ds ; \
60         mov     %ax,%es ; \
61         mov     $KPSEL,%ax ; \
62         mov     %ax,%fs ; \
63         FAKE_MCOUNT((12+ACTUALLY_PUSHED)*4(%esp)) ; \
64         movl    PCPU(CURPROC),%ebx ; \
65         incl    P_INTR_NESTING_LEVEL(%ebx) ; \
66         pushl   _intr_unit + (irq_num) * 4 ; \
67         call    *_intr_handler + (irq_num) * 4 ; /* do the work ASAP */ \
68         enable_icus ;           /* (re)enable ASAP (helps edge trigger?) */ \
69         addl    $4,%esp ; \
70         incl    _cnt+V_INTR ;   /* book-keeping can wait */ \
71         movl    _intr_countp + (irq_num) * 4,%eax ; \
72         incl    (%eax) ; \
73         decl    P_INTR_NESTING_LEVEL(%ebx) ; \
74         MEXITCOUNT ; \
75         jmp     _doreti
76
77 /* 
78  * Slow, threaded interrupts.
79  *
80  * XXX Most of the parameters here are obsolete.  Fix this when we're
81  * done.
82  * XXX we really shouldn't return via doreti if we just schedule the
83  * interrupt handler and don't run anything.  We could just do an
84  * iret.  FIXME.
85  */
86 #define INTR(irq_num, vec_name, icu, enable_icus, reg, maybe_extra_ipending) \
87         .text ; \
88         SUPERALIGN_TEXT ; \
89 IDTVEC(vec_name) ; \
90         pushl   $0 ;            /* dummy error code */ \
91         pushl   $0 ;            /* dummy trap type */ \
92         pushal ; \
93         pushl   %ds ;           /* save our data and extra segments ... */ \
94         pushl   %es ; \
95         pushl   %fs ; \
96         mov     $KDSEL,%ax ;    /* load kernel ds, es and fs */ \
97         mov     %ax,%ds ; \
98         mov     %ax,%es ; \
99         mov     $KPSEL,%ax ; \
100         mov     %ax,%fs ; \
101         maybe_extra_ipending ; \
102         movb    _imen + IRQ_BYTE(irq_num),%al ; \
103         orb     $IRQ_BIT(irq_num),%al ; \
104         movb    %al,_imen + IRQ_BYTE(irq_num) ; \
105         outb    %al,$icu+ICU_IMR_OFFSET ; \
106         enable_icus ; \
107         movl    PCPU(CURPROC),%ebx ; \
108         incl    P_INTR_NESTING_LEVEL(%ebx) ; \
109 __CONCAT(Xresume,irq_num): ; \
110         FAKE_MCOUNT(13*4(%esp)) ;       /* XXX late to avoid double count */ \
111         pushl   $irq_num;       /* pass the IRQ */ \
112         sti ; \
113         call    _sched_ithd ; \
114         addl    $4, %esp ;      /* discard the parameter */ \
115         decl    P_INTR_NESTING_LEVEL(%ebx) ; \
116         MEXITCOUNT ; \
117         /* We could usually avoid the following jmp by inlining some of */ \
118         /* _doreti, but it's probably better to use less cache. */ \
119         jmp     _doreti         /* and catch up inside doreti */
120
121 MCOUNT_LABEL(bintr)
122         FAST_INTR(0,fastintr0, ENABLE_ICU1)
123         FAST_INTR(1,fastintr1, ENABLE_ICU1)
124         FAST_INTR(2,fastintr2, ENABLE_ICU1)
125         FAST_INTR(3,fastintr3, ENABLE_ICU1)
126         FAST_INTR(4,fastintr4, ENABLE_ICU1)
127         FAST_INTR(5,fastintr5, ENABLE_ICU1)
128         FAST_INTR(6,fastintr6, ENABLE_ICU1)
129         FAST_INTR(7,fastintr7, ENABLE_ICU1)
130         FAST_INTR(8,fastintr8, ENABLE_ICU1_AND_2)
131         FAST_INTR(9,fastintr9, ENABLE_ICU1_AND_2)
132         FAST_INTR(10,fastintr10, ENABLE_ICU1_AND_2)
133         FAST_INTR(11,fastintr11, ENABLE_ICU1_AND_2)
134         FAST_INTR(12,fastintr12, ENABLE_ICU1_AND_2)
135         FAST_INTR(13,fastintr13, ENABLE_ICU1_AND_2)
136         FAST_INTR(14,fastintr14, ENABLE_ICU1_AND_2)
137         FAST_INTR(15,fastintr15, ENABLE_ICU1_AND_2)
138
139 #define CLKINTR_PENDING movl $1,CNAME(clkintr_pending)
140 /* Threaded interrupts */
141         INTR(0,intr0, IO_ICU1, ENABLE_ICU1, al, CLKINTR_PENDING)
142         INTR(1,intr1, IO_ICU1, ENABLE_ICU1, al,)
143         INTR(2,intr2, IO_ICU1, ENABLE_ICU1, al,)
144         INTR(3,intr3, IO_ICU1, ENABLE_ICU1, al,)
145         INTR(4,intr4, IO_ICU1, ENABLE_ICU1, al,)
146         INTR(5,intr5, IO_ICU1, ENABLE_ICU1, al,)
147         INTR(6,intr6, IO_ICU1, ENABLE_ICU1, al,)
148         INTR(7,intr7, IO_ICU1, ENABLE_ICU1, al,)
149         INTR(8,intr8, IO_ICU2, ENABLE_ICU1_AND_2, ah,)
150         INTR(9,intr9, IO_ICU2, ENABLE_ICU1_AND_2, ah,)
151         INTR(10,intr10, IO_ICU2, ENABLE_ICU1_AND_2, ah,)
152         INTR(11,intr11, IO_ICU2, ENABLE_ICU1_AND_2, ah,)
153         INTR(12,intr12, IO_ICU2, ENABLE_ICU1_AND_2, ah,)
154         INTR(13,intr13, IO_ICU2, ENABLE_ICU1_AND_2, ah,)
155         INTR(14,intr14, IO_ICU2, ENABLE_ICU1_AND_2, ah,)
156         INTR(15,intr15, IO_ICU2, ENABLE_ICU1_AND_2, ah,)
157
158 MCOUNT_LABEL(eintr)