Rev 2434 | Rev 3555 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2465 | Serge | 3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
431 | serge | 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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1 | ha | 16 | |
593 | mikedld | 17 | $Revision: 2465 $ |
1 | ha | 18 | |
593 | mikedld | 19 | |
1 | ha | 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 | ;*************************************************************************** |
||
922 | mikedld | 44 | ;uglobal |
45 | ; freeBuff_cnt dd ? |
||
46 | ;endg |
||
1 | ha | 47 | freeBuff: |
907 | mikedld | 48 | ; inc [freeBuff_cnt] |
49 | ; DEBUGF 1, "K : freeBuff (%u)\n", [freeBuff_cnt] |
||
2434 | Serge | 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 |
||
1 | ha | 60 | |
2434 | Serge | 61 | ret |
1 | ha | 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: |
||
2434 | Serge | 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 |
||
1 | ha | 81 | |
82 | qs_001: |
||
2434 | Serge | 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 |
||
1 | ha | 90 | |
91 | qs_exit: |
||
2434 | Serge | 92 | ret |
1 | ha | 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 | ;*************************************************************************** |
||
922 | mikedld | 107 | ;uglobal |
108 | ; queue_cnt dd ? |
||
109 | ;endg |
||
1 | ha | 110 | queue: |
907 | mikedld | 111 | ; inc [queue_cnt] |
112 | ; DEBUGF 1, "K : queue (%u)\n", [queue_cnt] |
||
2434 | Serge | 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 |
||
1 | ha | 117 | |
2434 | Serge | 118 | cli |
119 | shl eax, 1 |
||
120 | add eax, queues ; eax now holds address of queue |
||
121 | movzx ebx, word [eax] |
||
1 | ha | 122 | |
2434 | Serge | 123 | cmp bx, NO_BUFFER |
124 | jne qu_001 |
||
1 | ha | 125 | |
2434 | Serge | 126 | pop ebx |
1 | ha | 127 | ; The list is empty, so add this to the head |
2434 | Serge | 128 | mov [eax], bx |
129 | jmp qu_exit |
||
1 | ha | 130 | |
131 | qu_001: |
||
132 | ; Find the last entry |
||
2434 | Serge | 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 |
||
1 | ha | 139 | |
2434 | Serge | 140 | mov ebx, eax |
141 | pop eax |
||
142 | mov [ebx], ax |
||
1 | ha | 143 | |
144 | qu_exit: |
||
2434 | Serge | 145 | sti |
146 | ret |
||
1 | ha | 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 | ;*************************************************************************** |
||
922 | mikedld | 162 | ;uglobal |
163 | ; dequeue_cnt dd ? |
||
164 | ;endg |
||
1 | ha | 165 | dequeue: |
2434 | Serge | 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 |
||
907 | mikedld | 174 | ; inc [dequeue_cnt] |
175 | ; DEBUGF 1, "K : dequeue (%u)\n", [dequeue_cnt] |
||
2434 | Serge | 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 |
||
1 | ha | 182 | |
183 | dq_exit: |
||
2434 | Serge | 184 | sti |
185 | pop ebx |
||
186 | ret |
||
1 | ha | 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: |
||
2434 | Serge | 199 | mov esi, queues |
200 | mov ecx, NUMQUEUES |
||
201 | mov ax, NO_BUFFER |
||
1 | ha | 202 | |
203 | qi001: |
||
2434 | Serge | 204 | mov [esi], ax |
205 | inc esi |
||
206 | inc esi |
||
207 | loop qi001 |
||
1 | ha | 208 | |
2434 | Serge | 209 | mov esi, queues + ( 2 * EMPTY_QUEUE ) |
1 | ha | 210 | |
211 | ; Initialise empty queue list |
||
212 | |||
2434 | Serge | 213 | xor ax, ax |
214 | mov [esi], ax |
||
1 | ha | 215 | |
2434 | Serge | 216 | mov ecx, NUMQUEUEENTRIES - 1 |
217 | mov esi, queueList |
||
1 | ha | 218 | |
219 | qi002: |
||
2434 | Serge | 220 | inc ax |
221 | mov [esi], ax |
||
222 | inc esi |
||
223 | inc esi |
||
224 | loop qi002 |
||
1 | ha | 225 | |
2434 | Serge | 226 | mov ax, NO_BUFFER |
227 | mov [esi], ax |
||
1 | ha | 228 | |
2434 | Serge | 229 | ret |