Subversion Repositories Kolibri OS

Rev

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