IRQH code

git-svn-id: svn://kolibrios.org@2049 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2011-08-15 20:34:55 +00:00
parent 50431b95fb
commit 416dc8b600
4 changed files with 149 additions and 6 deletions

View File

@ -771,3 +771,27 @@ end virtual
virtual at 0 virtual at 0
CSYM COFF_SYM CSYM COFF_SYM
end virtual end virtual
struc LHEAD
{
.next dd ? ;next object in list
.prev dd ? ;prev object in list
.sizeof:
}
virtual at 0
LHEAD LHEAD
end virtual
struc IRQH
{
.list LHEAD
.handler dd ? ;handler roututine
.data dd ? ;user-specific data
.sizeof:
}
virtual at 0
IRQH IRQH
end virtual

View File

@ -103,6 +103,28 @@ APIC_init:
out 0x23, al out 0x23, al
; mov dword[irq_type_to_set], IRQ_TYPE_APIC ; mov dword[irq_type_to_set], IRQ_TYPE_APIC
;init handlers table
mov ecx, IRQ_RESERVE
mov edi, irqh_tab
@@:
mov eax, edi
stosd
stosd
loop @B
mov ecx, 48
mov eax, irqh_array+IRQH.sizeof
mov [next_irqh], irqh_array
@@:
mov [eax-IRQH.sizeof], eax
add eax, IRQH.sizeof
loop @B
mov [eax-IRQH.sizeof], dword 0
.no_apic: .no_apic:
ret ret
@ -268,7 +290,7 @@ unmask_timer:
jnz @f jnz @f
stdcall enable_irq, 0 stdcall enable_irq, 0
ret ret
@@: @@:
; use PIT ; use PIT
; in some systems PIT no connected to IOAPIC ; in some systems PIT no connected to IOAPIC
; mov eax, 0x14 ; mov eax, 0x14
@ -281,7 +303,7 @@ unmask_timer:
; call IOAPIC_write ; call IOAPIC_write
; stdcall enable_irq, 2 ; stdcall enable_irq, 2
; ret ; ret
; use LAPIC timer ; use LAPIC timer
mov esi, [LAPIC_BASE] mov esi, [LAPIC_BASE]
mov eax, [esi + APIC_LVT_timer] mov eax, [esi + APIC_LVT_timer]
@ -327,11 +349,11 @@ IRQ_EOI:
out 0xa0, al out 0xa0, al
@@: out 0x20, al @@: out 0x20, al
ret ret
.APIC: .APIC:
mov eax, [LAPIC_BASE] mov eax, [LAPIC_BASE]
mov dword [eax + APIC_EOI], 0 ; EOI mov dword [eax + APIC_EOI], 0 ; EOI
ret ret
; ----------------------------------------- ; -----------------------------------------
; from dll.inc ; from dll.inc
align 4 align 4
@ -491,3 +513,94 @@ endp
; popa ; popa
; ret ; ret
; endp ; endp
macro __list_add new, prev, next
{
mov [next+LHEAD.prev], new
mov [new+LHEAD.next], next
mov [new+LHEAD.prev], prev
mov [prev+LHEAD.next], new
}
macro list_add new, head
{
mov eax, [head+LHEAD.next]
__list_add new, head, eax
}
macro list_add_tail new, head
{
mov eax, [head+LHEAD.prev]
__list_add new, eax, head
}
align 4
proc attach_int_handler_ex stdcall, irq:dword, handler:dword, user_data:dword
locals
.irqh dd ?
endl
and [.irqh], 0
push ebx
mov ebx, [irq] ;irq num
test ebx, ebx
jz .err
cmp ebx, IRQ_RESERVE
jae .err
mov edx, [handler]
test edx, edx
jz .err
pushfd
cli
;allocate handler
mov ecx, [next_irqh]
test ecx, ecx
jz .fail
mov eax, [ecx]
mov [next_irqh], eax
mov [.irqh], ecx
mov eax, [user_data]
mov [ecx+IRQH.handler], edx
mov [ecx+IRQH.data], eax
mov eax, [irqh_set]
bt [pci_irq_set], ebx ;check irq type
jc .pci_irq
.isa_irq:
bts eax, ebx ;check for installed handler
jc .fail
.set_handler:
mov [irqh_set], eax
lea edx, [irqh_tab+ebx*8]
list_add_tail ecx, edx ;clobber eax
stdcall enable_irq, [irq]
.fail:
popfd
.err:
pop ebx
mov eax, [.irqh]
ret
.pci_irq:
bts ecx, ebx ;check for installed handler
jmp .set_handler
endp

View File

@ -271,6 +271,11 @@ irq_owner rd IRQ_RESERVE ; process id
irq00read rd 16 * IRQ_RESERVE irq00read rd 16 * IRQ_RESERVE
irq_tab rd IRQ_RESERVE irq_tab rd IRQ_RESERVE
irqh_tab rd LHEAD.sizeof * IRQ_RESERVE / 4
irqh_array rd IRQH.sizeof *48 /4
next_irqh rd 1
mem_block_map rb 512 mem_block_map rb 512
mem_block_list rd 64 mem_block_list rd 64
large_block_list rd 31 large_block_list rd 31
@ -301,6 +306,8 @@ os_stack_seg rd 1
srv.fd rd 1 srv.fd rd 1
srv.bk rd 1 srv.bk rd 1
irqh_set rd 1
pci_irq_set rd 1
align 16 align 16

View File

@ -1017,8 +1017,7 @@ end if
stdcall enable_irq, 6 ; FDD stdcall enable_irq, 6 ; FDD
stdcall enable_irq, 13 ; co-processor stdcall enable_irq, 13 ; co-processor
stdcall attach_int_handler, dword 1, irq1, dword 0 ; keyboard stdcall attach_int_handler_ex, 1, irq1, 0
; mov [dma_hdd],1 ; mov [dma_hdd],1
cmp [IDEContrRegsBaseAddr], 0 cmp [IDEContrRegsBaseAddr], 0
setnz [dma_hdd] setnz [dma_hdd]