Subversion Repositories Kolibri OS

Rev

Rev 2129 | Rev 2231 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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