Subversion Repositories Kolibri OS

Rev

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

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