From 416dc8b6002d2e887f0b68a2cf7723dcd739026f Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Mon, 15 Aug 2011 20:34:55 +0000 Subject: [PATCH] IRQH code git-svn-id: svn://kolibrios.org@2049 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/Kolibri-acpi/const.inc | 24 ++++ kernel/branches/Kolibri-acpi/core/apic.inc | 121 ++++++++++++++++++++- kernel/branches/Kolibri-acpi/data32.inc | 7 ++ kernel/branches/Kolibri-acpi/kernel.asm | 3 +- 4 files changed, 149 insertions(+), 6 deletions(-) diff --git a/kernel/branches/Kolibri-acpi/const.inc b/kernel/branches/Kolibri-acpi/const.inc index 731bea00ff..4fda41ed53 100644 --- a/kernel/branches/Kolibri-acpi/const.inc +++ b/kernel/branches/Kolibri-acpi/const.inc @@ -771,3 +771,27 @@ end virtual virtual at 0 CSYM COFF_SYM 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 + diff --git a/kernel/branches/Kolibri-acpi/core/apic.inc b/kernel/branches/Kolibri-acpi/core/apic.inc index 996bb84cf0..c3c056153b 100644 --- a/kernel/branches/Kolibri-acpi/core/apic.inc +++ b/kernel/branches/Kolibri-acpi/core/apic.inc @@ -103,6 +103,28 @@ APIC_init: out 0x23, al ; 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: ret @@ -268,7 +290,7 @@ unmask_timer: jnz @f stdcall enable_irq, 0 ret -@@: +@@: ; use PIT ; in some systems PIT no connected to IOAPIC ; mov eax, 0x14 @@ -281,7 +303,7 @@ unmask_timer: ; call IOAPIC_write ; stdcall enable_irq, 2 ; ret - + ; use LAPIC timer mov esi, [LAPIC_BASE] mov eax, [esi + APIC_LVT_timer] @@ -327,11 +349,11 @@ IRQ_EOI: out 0xa0, al @@: out 0x20, al ret -.APIC: +.APIC: mov eax, [LAPIC_BASE] mov dword [eax + APIC_EOI], 0 ; EOI ret - + ; ----------------------------------------- ; from dll.inc align 4 @@ -491,3 +513,94 @@ endp ; popa ; ret ; 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 + diff --git a/kernel/branches/Kolibri-acpi/data32.inc b/kernel/branches/Kolibri-acpi/data32.inc index 530acda14d..8db3689016 100644 --- a/kernel/branches/Kolibri-acpi/data32.inc +++ b/kernel/branches/Kolibri-acpi/data32.inc @@ -271,6 +271,11 @@ irq_owner rd IRQ_RESERVE ; process id irq00read rd 16 * 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_list rd 64 large_block_list rd 31 @@ -301,6 +306,8 @@ os_stack_seg rd 1 srv.fd rd 1 srv.bk rd 1 +irqh_set rd 1 +pci_irq_set rd 1 align 16 diff --git a/kernel/branches/Kolibri-acpi/kernel.asm b/kernel/branches/Kolibri-acpi/kernel.asm index 66a913c769..2bd52bbfa7 100644 --- a/kernel/branches/Kolibri-acpi/kernel.asm +++ b/kernel/branches/Kolibri-acpi/kernel.asm @@ -1017,8 +1017,7 @@ end if stdcall enable_irq, 6 ; FDD 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 cmp [IDEContrRegsBaseAddr], 0 setnz [dma_hdd]