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