Rev 2138 | Rev 2229 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2106 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
2130 | serge | 8 | |
9 | IRQ_POOL_SIZE equ 48 |
||
10 | |||
2106 | serge | 11 | uglobal |
12 | |||
13 | align 16 |
||
2130 | serge | 14 | irqh_tab rd LHEAD.sizeof * IRQ_RESERVED / 4 |
2106 | serge | 15 | |
2130 | serge | 16 | irqh_pool rd IRQH.sizeof * IRQ_POOL_SIZE /4 |
2106 | serge | 17 | next_irqh rd 1 |
18 | |||
19 | irq_active_set rd 1 |
||
2130 | serge | 20 | irq_failed rd IRQ_RESERVED |
2106 | serge | 21 | |
22 | endg |
||
23 | |||
24 | align 4 |
||
25 | proc attach_int_handler stdcall, irq:dword, handler:dword, user_data:dword |
||
26 | locals |
||
27 | .irqh dd ? |
||
28 | endl |
||
29 | |||
30 | and [.irqh], 0 |
||
31 | |||
32 | push ebx |
||
33 | |||
34 | mov ebx, [irq] ;irq num |
||
35 | test ebx, ebx |
||
36 | jz .err |
||
37 | |||
2130 | serge | 38 | cmp ebx, IRQ_RESERVED |
2106 | serge | 39 | jae .err |
40 | |||
41 | mov edx, [handler] |
||
42 | test edx, edx |
||
43 | jz .err |
||
44 | |||
45 | pushfd |
||
46 | cli |
||
47 | |||
48 | ;allocate handler |
||
49 | |||
50 | mov ecx, [next_irqh] |
||
51 | test ecx, ecx |
||
52 | jz .fail |
||
53 | |||
54 | mov eax, [ecx] |
||
55 | mov [next_irqh], eax |
||
56 | mov [.irqh], ecx |
||
57 | |||
2130 | serge | 58 | mov [irq_failed+ebx*4], 0 ;clear counter |
59 | |||
2106 | serge | 60 | mov eax, [user_data] |
61 | mov [ecx+IRQH.handler], edx |
||
62 | mov [ecx+IRQH.data], eax |
||
63 | |||
64 | lea edx, [irqh_tab+ebx*8] |
||
65 | list_add_tail ecx, edx ;clobber eax |
||
2130 | serge | 66 | stdcall enable_irq, ebx |
2106 | serge | 67 | |
68 | .fail: |
||
69 | popfd |
||
70 | .err: |
||
71 | pop ebx |
||
72 | mov eax, [.irqh] |
||
73 | ret |
||
74 | |||
75 | endp |
||
76 | |||
77 | if 0 |
||
78 | align 4 |
||
79 | proc get_int_handler stdcall, irq:dword |
||
80 | |||
81 | mov eax, [irq] |
||
82 | cmp eax, 15 |
||
83 | ja .fail |
||
84 | mov eax, [irq_tab + 4 * eax] |
||
85 | ret |
||
86 | .fail: |
||
87 | xor eax, eax |
||
88 | ret |
||
89 | endp |
||
90 | end if |
||
91 | |||
92 | |||
93 | align 4 |
||
94 | proc detach_int_handler |
||
95 | |||
96 | ret |
||
97 | endp |
||
98 | |||
99 | |||
100 | macro irq_serv_h [num] { |
||
101 | forward |
||
102 | align 4 |
||
103 | .irq_#num : |
||
104 | push num |
||
105 | jmp .main |
||
106 | } |
||
107 | |||
108 | align 16 |
||
109 | irq_serv: |
||
110 | |||
111 | ; .irq_1: |
||
112 | ; push 1 |
||
113 | ; jmp .main |
||
114 | ; etc... |
||
115 | |||
116 | irq_serv_h 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15 |
||
117 | irq_serv_h 16, 17, 18, 19, 20, 21, 22, 23 |
||
118 | |||
119 | purge irq_serv_h |
||
120 | |||
121 | align 16 |
||
122 | .main: |
||
123 | save_ring3_context |
||
124 | |||
125 | mov ebp, [esp + 32] |
||
126 | mov bx, app_data ;os_data |
||
127 | mov ds, bx |
||
128 | mov es, bx |
||
129 | |||
130 | cmp [v86_irqhooks+ebp*8], 0 |
||
131 | jnz v86_irq |
||
132 | |||
133 | cmp bp, 6 |
||
134 | jnz @f |
||
135 | push ebp |
||
136 | call [fdc_irq_func] |
||
137 | pop ebp |
||
138 | @@: |
||
139 | |||
140 | cmp bp, 14 |
||
141 | jnz @f |
||
142 | push ebp |
||
143 | call [irq14_func] |
||
144 | pop ebp |
||
145 | @@: |
||
146 | cmp bp, 15 |
||
147 | jnz @f |
||
148 | push ebp |
||
149 | call [irq15_func] |
||
150 | pop ebp |
||
151 | @@: |
||
152 | bts [irq_active_set], ebp |
||
153 | |||
154 | lea esi, [irqh_tab+ebp*8] ; esi= list head |
||
155 | mov ebx, esi |
||
156 | .next: |
||
157 | mov ebx, [ebx+IRQH.list.next] ; ebx= irqh pointer |
||
158 | cmp ebx, esi |
||
159 | je .done |
||
160 | |||
161 | push ebx ; FIX THIS |
||
162 | push edi |
||
163 | push esi |
||
164 | |||
165 | push [ebx+IRQH.data] |
||
166 | call [ebx+IRQH.handler] |
||
167 | add esp, 4 |
||
168 | |||
169 | pop esi |
||
170 | pop edi |
||
171 | pop ebx |
||
172 | |||
173 | test eax, eax |
||
174 | jz .next |
||
175 | |||
176 | btr [irq_active_set], ebp |
||
177 | jmp .next |
||
178 | |||
179 | .done: |
||
180 | btr [irq_active_set], ebp |
||
181 | jnc .exit |
||
182 | |||
183 | inc [irq_failed+ebp*4] |
||
184 | .exit: |
||
185 | mov [check_idle_semaphore],5 |
||
186 | |||
2166 | serge | 187 | mov ecx, ebp |
188 | call irq_eoi |
||
189 | |||
2106 | serge | 190 | restore_ring3_context |
191 | add esp, 4 |
||
192 | iret |
||
193 | |||
2130 | serge | 194 | align 4 |
195 | irqD: |
||
196 | push eax |
||
197 | push ecx |
||
198 | xor eax,eax |
||
199 | out 0xf0,al |
||
2166 | serge | 200 | mov cl, 13 |
201 | call irq_eoi |
||
2130 | serge | 202 | pop ecx |
203 | pop eax |
||
204 | iret |
||
2106 | serge | 205 |