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