Subversion Repositories Kolibri OS

Rev

Rev 2118 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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