Subversion Repositories Kolibri OS

Rev

Rev 914 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;                                                              ;;
  7. ;;  QUEUE.INC                                                   ;;
  8. ;;                                                              ;;
  9. ;;  Buffer queue management for Menuet OS TCP/IP Stack          ;;
  10. ;;                                                              ;;
  11. ;;  Copyright 2002 Mike Hibbett, mikeh@oceanfree.net            ;;
  12. ;;                                                              ;;
  13. ;;  See file COPYING for details                                ;;
  14. ;;                                                              ;;
  15. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16.  
  17. $Revision: 2971 $
  18.  
  19.  
  20. ;*******************************************************************
  21. ;   Interface
  22. ;
  23. ;       queueInit   Configures the queues to empty
  24. ;       dequeue     Removes a buffer pointer from a queue
  25. ;       queue       Inserts a buffer pointer into a queue
  26. ;       freeBuff    Adds the buffer pointer to the list of free buffers
  27. ;       queueSize   Returns the number of entries in a queue
  28. ;
  29. ;      The various defines for queue names can be found in stack.inc
  30. ;
  31. ;*******************************************************************
  32.  
  33.  
  34. ;***************************************************************************
  35. ;   Function
  36. ;      freeBuff
  37. ;
  38. ;   Description
  39. ;       Adds a buffer number to the beginning of the free list.
  40. ;       buffer number in eax  ( ms word zeroed )
  41. ;       all other registers preserved
  42. ;        This always works, so no error returned
  43. ;***************************************************************************
  44. ;uglobal
  45. ;  freeBuff_cnt dd ?
  46. ;endg
  47. freeBuff:
  48. ;        inc     [freeBuff_cnt]
  49. ;        DEBUGF  1, "K : freeBuff (%u)\n", [freeBuff_cnt]
  50.     push    ebx
  51.     push    ecx
  52.     mov     ebx, queues + EMPTY_QUEUE * 2
  53.     cli     ; Ensure that another process does not interfer
  54.     mov     cx, [ebx]
  55.     mov     [ebx], ax
  56.     mov     [queueList + eax * 2], cx
  57.     sti
  58.     pop     ecx
  59.     pop     ebx
  60.  
  61.     ret
  62.  
  63.  
  64. ;***************************************************************************
  65. ;   Function
  66. ;      queueSize
  67. ;
  68. ;   Description
  69. ;       Counts the number of entries in a queue
  70. ;       queue number in ebx ( ms word zeroed )
  71. ;       Queue size returned in eax
  72. ;    This always works, so no error returned
  73. ;***************************************************************************
  74. queueSize:
  75.     xor     eax, eax
  76.     shl     ebx, 1
  77.     add     ebx, queues
  78.     movzx   ecx, word [ebx]
  79.     cmp     cx, NO_BUFFER
  80.     je      qs_exit
  81.  
  82. qs_001:
  83.     inc     eax
  84.     shl     ecx, 1
  85.     add     ecx, queueList
  86.     movzx   ecx, word [ecx]
  87.     cmp     cx, NO_BUFFER
  88.     je      qs_exit
  89.     jmp     qs_001
  90.  
  91. qs_exit:
  92.     ret
  93.  
  94.  
  95. ;***************************************************************************
  96. ;   Function
  97. ;      queue
  98. ;
  99. ;   Description
  100. ;       Adds a buffer number to the *end* of a queue
  101. ;       This is quite quick because these queues will be short
  102. ;       queue number in eax ( ms word zeroed )
  103. ;       buffer number in ebx  ( ms word zeroed )
  104. ;       all other registers preserved
  105. ;        This always works, so no error returned
  106. ;***************************************************************************
  107. ;uglobal
  108. ;  queue_cnt dd ?
  109. ;endg
  110. queue:
  111. ;        inc     [queue_cnt]
  112. ;        DEBUGF  1, "K : queue (%u)\n", [queue_cnt]
  113.     push    ebx
  114.     shl     ebx, 1
  115.     add     ebx, queueList        ; eax now holds address of queue entry
  116.     mov     [ebx], word NO_BUFFER    ; This buffer will be the last
  117.  
  118.     cli
  119.     shl     eax, 1
  120.     add     eax, queues            ; eax now holds address of queue
  121.     movzx   ebx, word [eax]
  122.  
  123.     cmp     bx, NO_BUFFER
  124.     jne     qu_001
  125.  
  126.     pop     ebx
  127.     ; The list is empty, so add this to the head
  128.     mov     [eax], bx
  129.     jmp     qu_exit
  130.  
  131. qu_001:
  132.     ; Find the last entry
  133.     shl     ebx, 1
  134.     add     ebx, queueList
  135.     mov     eax, ebx
  136.     movzx   ebx, word [ebx]
  137.     cmp     bx, NO_BUFFER
  138.     jne     qu_001
  139.  
  140.     mov     ebx, eax
  141.     pop     eax
  142.     mov     [ebx], ax
  143.  
  144. qu_exit:
  145.     sti
  146.     ret
  147.  
  148.  
  149.  
  150. ;***************************************************************************
  151. ;   Function
  152. ;      dequeue
  153. ;
  154. ;   Description
  155. ;       removes a buffer number from the head of a queue
  156. ;       This is fast, as it unlinks the first entry in the list
  157. ;       queue number in eax ( ms word zeroed )
  158. ;       buffer number returned in eax ( ms word zeroed )
  159. ;       all other registers preserved
  160. ;
  161. ;***************************************************************************
  162. ;uglobal
  163. ;  dequeue_cnt dd ?
  164. ;endg
  165. dequeue:
  166.     push    ebx
  167.     shl     eax, 1
  168.     add     eax, queues            ; eax now holds address of queue
  169.     mov     ebx, eax
  170.     cli
  171.     movzx   eax, word [eax]
  172.     cmp     ax, NO_BUFFER
  173.     je      dq_exit
  174. ;        inc     [dequeue_cnt]
  175. ;        DEBUGF  1, "K : dequeue (%u)\n", [dequeue_cnt]
  176.     push    eax
  177.     shl     eax, 1
  178.     add     eax, queueList        ; eax now holds address of queue entry
  179.     mov     ax, [eax]
  180.     mov     [ebx], ax
  181.     pop     eax
  182.  
  183. dq_exit:
  184.     sti
  185.     pop     ebx
  186.     ret
  187.  
  188.  
  189. ;***************************************************************************
  190. ;   Function
  191. ;      queueInit
  192. ;
  193. ;   Description
  194. ;       Initialises the queues to empty, and creates the free queue
  195. ;       list.
  196. ;
  197. ;***************************************************************************
  198. queueInit:
  199.     mov     esi, queues
  200.     mov     ecx, NUMQUEUES
  201.     mov     ax, NO_BUFFER
  202.  
  203. qi001:
  204.     mov     [esi], ax
  205.     inc     esi
  206.     inc     esi
  207.     loop    qi001
  208.  
  209.     mov     esi, queues + ( 2 * EMPTY_QUEUE )
  210.  
  211.     ; Initialise empty queue list
  212.  
  213.     xor     ax, ax
  214.     mov     [esi], ax
  215.  
  216.     mov     ecx, NUMQUEUEENTRIES - 1
  217.     mov     esi, queueList
  218.  
  219. qi002:
  220.     inc     ax
  221.     mov     [esi], ax
  222.     inc     esi
  223.     inc     esi
  224.     loop    qi002
  225.  
  226.     mov     ax, NO_BUFFER
  227.     mov     [esi], ax
  228.  
  229.     ret
  230.