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