Subversion Repositories Kolibri OS

Rev

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

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