Subversion Repositories Kolibri OS

Rev

Rev 1196 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;  queue.inc                                                   ;;
  7. ;;                                                              ;;
  8. ;;    Written by hidnplayr@kolibrios.org                        ;;
  9. ;;                                                              ;;
  10. ;;          GNU GENERAL PUBLIC LICENSE                          ;;
  11. ;;             Version 2, June 1991                             ;;
  12. ;;                                                              ;;
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14.  
  15. $Revision: 1206 $
  16.  
  17. struct  queue
  18.         .size           dd ?
  19.         .w_ptr          dd ?
  20.         .r_ptr          dd ?
  21.         .data:
  22. ends
  23.  
  24. struct  queue_entry
  25.         .owner          dd ?
  26.         .data_ptr       dd ?
  27.         .data_size      dd ?
  28.         .size:
  29. ends
  30.  
  31.  
  32. macro add_to_queue ptr, size, returnaddr {
  33.  
  34.         cmp     dword [ptr + queue.size], size  ; Check if queue isnt full
  35.         jge     .fail
  36.  
  37.         DEBUGF  1,"Queuing packet for device %x\n",ebx
  38.  
  39.         inc     dword [ptr + queue.size]
  40.  
  41.         mov     edi, dword [ptr + queue.w_ptr]  ; Current write pointer (FIFO!)
  42.  
  43.         mov     eax, ebx
  44.         stosd
  45.         pop     eax
  46.         stosd
  47.         pop     eax
  48.         stosd
  49.  
  50.         cmp     edi, size*queue_entry.size+ptr+queue.data     ; entry size
  51.         jl      .no_wrap
  52.  
  53.         sub     edi, size*queue_entry.size
  54.  
  55.   .no_wrap:
  56.         mov     dword [ptr + queue.w_ptr], edi
  57.         jmp     returnaddr
  58.  
  59.   .fail:
  60.         DEBUGF  1,"queuing failed\n"
  61.  
  62.         call    kernel_free
  63.         add     esp, 4
  64.         ret
  65.  
  66. }
  67.  
  68.  
  69. macro get_from_queue ptr, size, returnaddr {
  70.  
  71.   .start_of_code:
  72.         cmp     dword [ptr + queue.size], 0             ; any packets queued?
  73.         je      returnaddr
  74.  
  75.         DEBUGF  1,"Dequeuing packet"
  76.  
  77.         dec     dword [ptr + queue.size]
  78.  
  79.         push    dword .start_of_code                    ; return address for call's
  80.  
  81.         mov     esi, [ptr + queue.r_ptr]
  82.         lodsd
  83.         mov     ebx, eax
  84.         lodsd
  85.         mov     ecx, eax
  86.         lodsd
  87.         push    eax
  88.         push    ecx
  89.         xchg    eax, ecx
  90.  
  91.         DEBUGF  1," for device %x\n", ebx
  92.  
  93.         cmp     esi, size*queue_entry.size+ptr+queue.data          ; entry size
  94.         jl      .no_wrap
  95.  
  96.         sub     esi, size*queue_entry.size
  97.  
  98.   .no_wrap:
  99.         mov     dword [ptr + queue.r_ptr], esi
  100.  
  101. }
  102.  
  103.