Subversion Repositories Kolibri OS

Rev

Rev 2106 | Rev 2138 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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