2011-08-23 16:25:29 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2012-03-15 16:41:29 +04:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
2011-08-23 16:25:29 +04:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2011-09-22 16:21:49 +04:00
|
|
|
IRQ_RESERVED equ 24
|
2011-08-27 15:24:26 +04:00
|
|
|
|
|
|
|
IRQ_POOL_SIZE equ 48
|
|
|
|
|
2011-08-23 16:25:29 +04:00
|
|
|
uglobal
|
|
|
|
|
|
|
|
align 16
|
2012-03-08 12:33:38 +04:00
|
|
|
irqh_tab rd sizeof.LHEAD * IRQ_RESERVED / 4
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
irqh_pool rd sizeof.IRQH * IRQ_POOL_SIZE /4
|
2011-08-23 16:25:29 +04:00
|
|
|
next_irqh rd 1
|
|
|
|
|
|
|
|
irq_active_set rd 1
|
2011-08-27 15:24:26 +04:00
|
|
|
irq_failed rd IRQ_RESERVED
|
2011-08-23 16:25:29 +04:00
|
|
|
|
|
|
|
endg
|
|
|
|
|
2011-09-22 16:21:49 +04:00
|
|
|
align 4
|
|
|
|
init_irqs:
|
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
mov ecx, IRQ_RESERVED
|
|
|
|
mov edi, irqh_tab
|
2011-09-22 16:21:49 +04:00
|
|
|
@@:
|
2013-09-14 22:55:13 +04:00
|
|
|
mov eax, edi
|
|
|
|
stosd
|
|
|
|
stosd
|
|
|
|
loop @B
|
2011-09-22 16:21:49 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
mov ecx, IRQ_POOL_SIZE-1
|
2012-03-08 12:33:38 +04:00
|
|
|
mov eax, irqh_pool+sizeof.IRQH
|
2013-09-14 22:55:13 +04:00
|
|
|
mov [next_irqh], irqh_pool
|
2011-09-22 16:21:49 +04:00
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [eax-sizeof.IRQH], eax
|
|
|
|
add eax, sizeof.IRQH
|
2013-09-14 22:55:13 +04:00
|
|
|
loop @B
|
2011-09-22 16:21:49 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [eax-sizeof.IRQH], dword 0
|
2013-09-14 22:55:13 +04:00
|
|
|
ret
|
2011-09-22 16:21:49 +04:00
|
|
|
|
|
|
|
|
2011-08-23 16:25:29 +04:00
|
|
|
align 4
|
|
|
|
proc attach_int_handler stdcall, irq:dword, handler:dword, user_data:dword
|
|
|
|
locals
|
|
|
|
.irqh dd ?
|
|
|
|
endl
|
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
DEBUGF 1, "K : Attach Interrupt %d Handler %x\n", [irq], [handler]
|
|
|
|
|
|
|
|
and [.irqh], 0
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
push ebx
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
mov ebx, [irq] ;irq num
|
|
|
|
test ebx, ebx
|
|
|
|
jz .err
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
cmp ebx, IRQ_RESERVED
|
|
|
|
jae .err
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
mov edx, [handler]
|
|
|
|
test edx, edx
|
|
|
|
jz .err
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
spin_lock_irqsave IrqsList
|
2011-08-23 16:25:29 +04:00
|
|
|
|
|
|
|
;allocate handler
|
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
mov ecx, [next_irqh]
|
|
|
|
test ecx, ecx
|
|
|
|
jz .fail
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
mov eax, [ecx]
|
|
|
|
mov [next_irqh], eax
|
|
|
|
mov [.irqh], ecx
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [irq_failed+ebx*4], 0;clear counter
|
2011-08-27 15:24:26 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
mov eax, [user_data]
|
|
|
|
mov [ecx+IRQH.handler], edx
|
|
|
|
mov [ecx+IRQH.data], eax
|
2013-05-28 23:09:31 +04:00
|
|
|
and [ecx+IRQH.num_ints], 0
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
lea edx, [irqh_tab+ebx*8]
|
|
|
|
list_add_tail ecx, edx ;clobber eax
|
|
|
|
stdcall enable_irq, ebx
|
2011-08-23 16:25:29 +04:00
|
|
|
|
|
|
|
.fail:
|
2013-05-28 23:09:31 +04:00
|
|
|
spin_unlock_irqrestore IrqsList
|
2011-08-23 16:25:29 +04:00
|
|
|
.err:
|
2013-09-14 22:55:13 +04:00
|
|
|
pop ebx
|
|
|
|
mov eax, [.irqh]
|
|
|
|
ret
|
2011-08-23 16:25:29 +04:00
|
|
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
if 0
|
|
|
|
align 4
|
|
|
|
proc get_int_handler stdcall, irq:dword
|
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
mov eax, [irq]
|
|
|
|
cmp eax, 15
|
|
|
|
ja .fail
|
|
|
|
mov eax, [irq_tab + 4 * eax]
|
2011-08-23 16:25:29 +04:00
|
|
|
ret
|
|
|
|
.fail:
|
2013-09-14 22:55:13 +04:00
|
|
|
xor eax, eax
|
2011-08-23 16:25:29 +04:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc detach_int_handler
|
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
ret
|
2011-08-23 16:25:29 +04:00
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
macro irq_serv_h [num] {
|
|
|
|
forward
|
|
|
|
align 4
|
|
|
|
.irq_#num :
|
2013-09-14 22:55:13 +04:00
|
|
|
push num
|
|
|
|
jmp .main
|
2011-08-23 16:25:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
align 16
|
|
|
|
irq_serv:
|
|
|
|
|
|
|
|
; .irq_1:
|
|
|
|
; push 1
|
|
|
|
; jmp .main
|
|
|
|
; etc...
|
|
|
|
|
|
|
|
irq_serv_h 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15
|
|
|
|
irq_serv_h 16, 17, 18, 19, 20, 21, 22, 23
|
|
|
|
|
|
|
|
purge irq_serv_h
|
|
|
|
|
|
|
|
align 16
|
|
|
|
.main:
|
2013-09-14 22:55:13 +04:00
|
|
|
save_ring3_context
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
mov ebp, [esp + 32]
|
2012-03-08 12:33:38 +04:00
|
|
|
mov bx, app_data;os_data
|
2013-09-14 22:55:13 +04:00
|
|
|
mov ds, bx
|
|
|
|
mov es, bx
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
cmp [v86_irqhooks+ebp*8], 0
|
|
|
|
jnz v86_irq
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
bts [irq_active_set], ebp
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
lea esi, [irqh_tab+ebp*8] ; esi= list head
|
|
|
|
mov ebx, esi
|
2011-08-23 16:25:29 +04:00
|
|
|
.next:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov ebx, [ebx+IRQH.list.next]; ebx= irqh pointer
|
2013-09-14 22:55:13 +04:00
|
|
|
cmp ebx, esi
|
|
|
|
je .done
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
push ebx ; FIX THIS
|
|
|
|
push edi
|
|
|
|
push esi
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
push [ebx+IRQH.data]
|
|
|
|
call [ebx+IRQH.handler]
|
2013-05-28 23:09:31 +04:00
|
|
|
pop ecx
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
pop esi
|
|
|
|
pop edi
|
|
|
|
pop ebx
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
test eax, eax
|
|
|
|
jz .next
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
inc [ebx+IRQH.num_ints]
|
2013-09-14 22:55:13 +04:00
|
|
|
btr [irq_active_set], ebp
|
|
|
|
jmp .next
|
2011-08-23 16:25:29 +04:00
|
|
|
|
|
|
|
.done:
|
2013-09-14 22:55:13 +04:00
|
|
|
btr [irq_active_set], ebp
|
|
|
|
jnc .exit
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
; There is at least one configuration with one device which generates IRQ
|
|
|
|
; that is not the same as it should be according to PCI config space.
|
|
|
|
; For that device, the handler is registered at wrong IRQ.
|
|
|
|
; As a workaround, when nobody acknowledges the generated IRQ,
|
|
|
|
; try to ask all other registered handlers; if some handler acknowledges
|
|
|
|
; the IRQ this time, relink it to the current IRQ list.
|
|
|
|
; To make this more reliable, for every handler keep number of times
|
|
|
|
; that it has acknowledged an IRQ, and assume that handlers with at least one
|
|
|
|
; acknowledged IRQ are registered properly.
|
|
|
|
; Note: this still isn't 100% correct, because two IRQs can fire simultaneously,
|
|
|
|
; the better way would be to find the correct IRQ, but I don't know how to do
|
|
|
|
; this in that case.
|
|
|
|
push ebp
|
|
|
|
xor ebp, ebp
|
|
|
|
.try_other_irqs:
|
|
|
|
cmp ebp, [esp]
|
|
|
|
jz .try_next_irq
|
|
|
|
cmp ebp, 1
|
|
|
|
jz .try_next_irq
|
2013-09-14 22:55:13 +04:00
|
|
|
cmp ebp, 6
|
|
|
|
jz .try_next_irq
|
2013-05-28 23:09:31 +04:00
|
|
|
cmp ebp, 12
|
|
|
|
jz .try_next_irq
|
2013-09-14 22:55:13 +04:00
|
|
|
cmp ebp, 14
|
|
|
|
jz .try_next_irq
|
|
|
|
cmp ebp, 15
|
|
|
|
jz .try_next_irq
|
2013-05-28 23:09:31 +04:00
|
|
|
lea esi, [irqh_tab+ebp*8]
|
|
|
|
mov ebx, esi
|
|
|
|
.try_next_handler:
|
|
|
|
mov ebx, [ebx+IRQH.list.next]
|
|
|
|
cmp ebx, esi
|
|
|
|
je .try_next_irq
|
|
|
|
cmp [ebx+IRQH.num_ints], 0
|
|
|
|
jne .try_next_handler
|
|
|
|
; keyboard handler acknowledges everything
|
|
|
|
push [ebx+IRQH.data]
|
|
|
|
call [ebx+IRQH.handler]
|
|
|
|
pop ecx
|
|
|
|
test eax, eax
|
|
|
|
jz .try_next_handler
|
|
|
|
|
|
|
|
.found_in_wrong_list:
|
|
|
|
DEBUGF 1,'K : warning: relinking handler from IRQ%d to IRQ%d\n',\
|
|
|
|
ebp, [esp]
|
|
|
|
pop ebp
|
|
|
|
spin_lock_irqsave IrqsList
|
|
|
|
list_del ebx
|
|
|
|
lea edx, [irqh_tab+ebp*8]
|
|
|
|
list_add_tail ebx, edx
|
|
|
|
spin_unlock_irqrestore IrqsList
|
|
|
|
jmp .exit
|
|
|
|
|
|
|
|
.try_next_irq:
|
|
|
|
inc ebp
|
|
|
|
cmp ebp, 16
|
|
|
|
jb .try_other_irqs
|
|
|
|
pop ebp
|
|
|
|
|
|
|
|
.fail:
|
2013-09-14 22:55:13 +04:00
|
|
|
inc [irq_failed+ebp*4]
|
2011-08-23 16:25:29 +04:00
|
|
|
.exit:
|
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
mov ecx, ebp
|
|
|
|
call irq_eoi
|
2011-09-10 14:52:59 +04:00
|
|
|
|
2013-06-08 17:00:38 +04:00
|
|
|
; IRQ handler could make some kernel thread ready; reschedule
|
|
|
|
mov bl, SCHEDULE_HIGHER_PRIORITY
|
|
|
|
call find_next_task
|
|
|
|
jz .return ; if there is only one running process
|
|
|
|
call do_change_task
|
|
|
|
.return:
|
2013-09-14 22:55:13 +04:00
|
|
|
restore_ring3_context
|
|
|
|
add esp, 4
|
|
|
|
iret
|
2011-08-23 16:25:29 +04:00
|
|
|
|
2011-08-27 15:24:26 +04:00
|
|
|
align 4
|
|
|
|
irqD:
|
2013-09-14 22:55:13 +04:00
|
|
|
push eax
|
|
|
|
push ecx
|
2012-03-08 12:33:38 +04:00
|
|
|
xor eax, eax
|
|
|
|
out 0xf0, al
|
2013-09-14 22:55:13 +04:00
|
|
|
mov cl, 13
|
|
|
|
call irq_eoi
|
|
|
|
pop ecx
|
|
|
|
pop eax
|
2011-08-27 15:24:26 +04:00
|
|
|
iret
|
2011-08-23 16:25:29 +04:00
|
|
|
|