Subversion Repositories Kolibri OS

Rev

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

  1. $Revision: 431 $
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;                                                              ;;
  4. ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
  5. ;; Distributed under terms of the GNU General Public License    ;;
  6. ;;                                                              ;;
  7. ;;                                                              ;;
  8. ;;  QUEUE.INC                                                   ;;
  9. ;;                                                              ;;
  10. ;;  Buffer queue management for Menuet OS TCP/IP Stack          ;;
  11. ;;                                                              ;;
  12. ;;  Version 0.3  29 August 2002                                 ;;
  13. ;;                                                              ;;
  14. ;;  Copyright 2002 Mike Hibbett, mikeh@oceanfree.net            ;;
  15. ;;                                                              ;;
  16. ;;  See file COPYING for details                                ;;
  17. ;;                                                              ;;
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19.  
  20.  
  21. ;*******************************************************************
  22. ;   Interface
  23. ;
  24. ;       queueInit   Configures the queues to empty
  25. ;       dequeue     Removes a buffer pointer from a queue
  26. ;       queue       Inserts a buffer pointer into a queue
  27. ;       freeBuff    Adds the buffer pointer to the list of free buffers
  28. ;       queueSize   Returns the number of entries in a queue
  29. ;
  30. ;      The various defines for queue names can be found in stack.inc
  31. ;
  32. ;*******************************************************************
  33.  
  34.  
  35. ;***************************************************************************
  36. ;   Function
  37. ;      freeBuff
  38. ;
  39. ;   Description
  40. ;       Adds a buffer number to the beginning of the free list.
  41. ;       buffer number in eax  ( ms word zeroed )
  42. ;       all other registers preserved
  43. ;        This always works, so no error returned
  44. ;***************************************************************************
  45. freeBuff:
  46.     push    ebx
  47.     push    ecx
  48.     mov     ebx, EMPTY_QUEUE
  49.     shl     ebx, 1
  50.     add     ebx, queues
  51.     cli     ; Ensure that another process does not interfer
  52.     movzx   ecx, word [ebx]
  53.     mov     [ebx], ax
  54.     shl     eax, 1
  55.     add     eax, queueList
  56.     mov     [eax], 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. queue:
  108.     push    ebx
  109.     shl     ebx, 1
  110.     add     ebx, queueList        ; eax now holds address of queue entry
  111.     mov     [ebx], word NO_BUFFER    ; This buffer will be the last
  112.  
  113.     cli
  114.     shl     eax, 1
  115.     add     eax, queues            ; eax now holds address of queue
  116.     movzx   ebx, word [eax]
  117.  
  118.     cmp     bx, NO_BUFFER
  119.     jne     qu_001
  120.  
  121.     pop     ebx
  122.     ; The list is empty, so add this to the head
  123.     mov     [eax], bx
  124.     jmp     qu_exit
  125.  
  126. qu_001:
  127.     ; Find the last entry
  128.     shl     ebx, 1
  129.     add     ebx, queueList
  130.     mov     eax, ebx
  131.     movzx   ebx, word [ebx]
  132.     cmp     bx, NO_BUFFER
  133.     jne     qu_001
  134.  
  135.     mov     ebx, eax
  136.     pop     eax
  137.     mov     [ebx], ax
  138.  
  139. qu_exit:
  140.     sti
  141.     ret
  142.  
  143.  
  144.  
  145. ;***************************************************************************
  146. ;   Function
  147. ;      dequeue
  148. ;
  149. ;   Description
  150. ;       removes a buffer number from the head of a queue
  151. ;       This is fast, as it unlinks the first entry in the list
  152. ;       queue number in eax ( ms word zeroed )
  153. ;       buffer number returned in eax ( ms word zeroed )
  154. ;       all other registers preserved
  155. ;
  156. ;***************************************************************************
  157. dequeue:
  158.     push    ebx
  159.     shl     eax, 1
  160.     add     eax, queues            ; eax now holds address of queue
  161.     mov     ebx, eax
  162.     cli
  163.     movzx   eax, word [eax]
  164.     cmp     ax, NO_BUFFER
  165.     je      dq_exit
  166.     push    eax
  167.     shl     eax, 1
  168.     add     eax, queueList        ; eax now holds address of queue entry
  169.     mov     ax, [eax]
  170.     mov     [ebx], ax
  171.     pop     eax
  172.  
  173. dq_exit:
  174.     sti
  175.     pop     ebx
  176.     ret
  177.  
  178.  
  179. ;***************************************************************************
  180. ;   Function
  181. ;      queueInit
  182. ;
  183. ;   Description
  184. ;       Initialises the queues to empty, and creates the free queue
  185. ;       list.
  186. ;
  187. ;***************************************************************************
  188. queueInit:
  189.     mov     esi, queues
  190.     mov     ecx, NUMQUEUES
  191.     mov     ax, NO_BUFFER
  192.  
  193. qi001:
  194.     mov     [esi], ax
  195.     inc     esi
  196.     inc     esi
  197.     loop    qi001
  198.  
  199.     mov     esi, queues + ( 2 * EMPTY_QUEUE )
  200.  
  201.     ; Initialise empty queue list
  202.  
  203.     xor     ax, ax
  204.     mov     [esi], ax
  205.  
  206.     mov     ecx, NUMQUEUEENTRIES - 1
  207.     mov     esi, queueList
  208.  
  209. qi002:
  210.     inc     ax
  211.     mov     [esi], ax
  212.     inc     esi
  213.     inc     esi
  214.     loop    qi002
  215.  
  216.     mov     ax, NO_BUFFER
  217.     mov     [esi], ax
  218.  
  219.     ret
  220.