Subversion Repositories Kolibri OS

Rev

Rev 2113 | Rev 2129 | Go to most recent revision | Details | Compare with Previous | 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
 
147
macro irq_serv_h [num] {
148
    forward
149
align 4
150
  .irq_#num :
151
    push num
152
       jmp .main
153
}
154
 
155
align 16
156
irq_serv:
157
 
158
; .irq_1:
159
;      push 1
160
;      jmp .main
161
; etc...
162
 
163
irq_serv_h 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15
164
irq_serv_h 16, 17, 18, 19, 20, 21, 22, 23
165
 
166
purge irq_serv_h
167
 
168
align 16
169
.main:
170
       save_ring3_context
171
 
172
       mov   ebp, [esp + 32]
173
       mov   bx, app_data  ;os_data
174
       mov   ds, bx
175
       mov   es, bx
176
 
177
       cmp   [v86_irqhooks+ebp*8], 0
178
       jnz   v86_irq
179
 
180
       cmp   bp, 6
181
       jnz   @f
182
       push  ebp
183
       call  [fdc_irq_func]
184
       pop   ebp
185
@@:
186
 
187
       cmp   bp, 14
188
       jnz   @f
189
       push  ebp
190
       call  [irq14_func]
191
       pop   ebp
192
@@:
193
       cmp   bp, 15
194
       jnz   @f
195
       push  ebp
196
       call  [irq15_func]
197
       pop   ebp
198
@@:
199
       bts [irq_active_set], ebp
200
 
201
       lea esi, [irqh_tab+ebp*8]        ; esi= list head
202
       mov ebx, esi
203
.next:
204
       mov ebx, [ebx+IRQH.list.next]    ; ebx= irqh pointer
205
       cmp ebx, esi
206
       je .done
207
 
208
       push ebx                         ; FIX THIS
209
       push edi
210
       push esi
211
 
212
       push [ebx+IRQH.data]
213
       call [ebx+IRQH.handler]
214
       add esp, 4
215
 
216
       pop esi
217
       pop edi
218
       pop ebx
219
 
220
       test eax, eax
221
       jz .next
222
 
223
       btr [irq_active_set], ebp
224
       jmp .next
225
 
226
.done:
227
       btr [irq_active_set], ebp
228
       jnc .exit
229
 
230
       inc [irq_failed+ebp*4]
231
.exit:
232
       mov  [check_idle_semaphore],5
233
 
2118 serge 234
       mov ecx, ebp
235
       call irq_eoi
2113 serge 236
 
237
       restore_ring3_context
238
       add   esp, 4
239
       iret
240
 
2118 serge 241
align 4
242
irqD:
243
        push  eax
244
        push  ecx
245
        xor   eax,eax
246
        out   0xf0,al
247
        mov   cl, 13
248
        call  irq_eoi
249
        pop   ecx
250
        pop   eax
251
        iret
2113 serge 252