Subversion Repositories Kolibri OS

Rev

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