Subversion Repositories Kolibri OS

Rev

Rev 431 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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