Subversion Repositories Kolibri OS

Rev

Rev 837 | 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: 914 $
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
;***************************************************************************
914 serge 46
uglobal
47
  freeBuff_cnt dd ?
48
endg
1 ha 49
freeBuff:
914 serge 50
;        inc     [freeBuff_cnt]
51
;        DEBUGF  1, "K : freeBuff (%u)\n", [freeBuff_cnt]
1 ha 52
    push    ebx
53
    push    ecx
914 serge 54
    mov     ebx, queues + EMPTY_QUEUE * 2
1 ha 55
    cli     ; Ensure that another process does not interfer
914 serge 56
    mov     cx, [ebx]
1 ha 57
    mov     [ebx], ax
914 serge 58
    mov     [queueList + eax * 2], cx
1 ha 59
    sti
60
    pop     ecx
61
    pop     ebx
62
 
63
    ret
64
 
65
 
66
;***************************************************************************
67
;   Function
68
;      queueSize
69
;
70
;   Description
71
;       Counts the number of entries in a queue
72
;       queue number in ebx ( ms word zeroed )
73
;       Queue size returned in eax
74
;    This always works, so no error returned
75
;***************************************************************************
76
queueSize:
77
    xor     eax, eax
78
    shl     ebx, 1
79
    add     ebx, queues
80
    movzx   ecx, word [ebx]
81
    cmp     cx, NO_BUFFER
82
    je      qs_exit
83
 
84
qs_001:
85
    inc     eax
86
    shl     ecx, 1
87
    add     ecx, queueList
88
    movzx   ecx, word [ecx]
89
    cmp     cx, NO_BUFFER
90
    je      qs_exit
91
    jmp     qs_001
92
 
93
qs_exit:
94
    ret
95
 
96
 
97
;***************************************************************************
98
;   Function
99
;      queue
100
;
101
;   Description
102
;       Adds a buffer number to the *end* of a queue
103
;       This is quite quick because these queues will be short
104
;       queue number in eax ( ms word zeroed )
105
;       buffer number in ebx  ( ms word zeroed )
106
;       all other registers preserved
107
;        This always works, so no error returned
108
;***************************************************************************
914 serge 109
uglobal
110
  queue_cnt dd ?
111
endg
1 ha 112
queue:
914 serge 113
;        inc     [queue_cnt]
114
;        DEBUGF  1, "K : queue (%u)\n", [queue_cnt]
1 ha 115
    push    ebx
116
    shl     ebx, 1
117
    add     ebx, queueList        ; eax now holds address of queue entry
118
    mov     [ebx], word NO_BUFFER    ; This buffer will be the last
119
 
120
    cli
121
    shl     eax, 1
122
    add     eax, queues            ; eax now holds address of queue
123
    movzx   ebx, word [eax]
124
 
125
    cmp     bx, NO_BUFFER
126
    jne     qu_001
127
 
128
    pop     ebx
129
    ; The list is empty, so add this to the head
130
    mov     [eax], bx
131
    jmp     qu_exit
132
 
133
qu_001:
134
    ; Find the last entry
135
    shl     ebx, 1
136
    add     ebx, queueList
137
    mov     eax, ebx
138
    movzx   ebx, word [ebx]
139
    cmp     bx, NO_BUFFER
140
    jne     qu_001
141
 
142
    mov     ebx, eax
143
    pop     eax
144
    mov     [ebx], ax
145
 
146
qu_exit:
147
    sti
148
    ret
149
 
150
 
151
 
152
;***************************************************************************
153
;   Function
154
;      dequeue
155
;
156
;   Description
157
;       removes a buffer number from the head of a queue
158
;       This is fast, as it unlinks the first entry in the list
159
;       queue number in eax ( ms word zeroed )
160
;       buffer number returned in eax ( ms word zeroed )
161
;       all other registers preserved
162
;
163
;***************************************************************************
914 serge 164
uglobal
165
  dequeue_cnt dd ?
166
endg
1 ha 167
dequeue:
168
    push    ebx
169
    shl     eax, 1
170
    add     eax, queues            ; eax now holds address of queue
171
    mov     ebx, eax
172
    cli
173
    movzx   eax, word [eax]
174
    cmp     ax, NO_BUFFER
175
    je      dq_exit
914 serge 176
;        inc     [dequeue_cnt]
177
;        DEBUGF  1, "K : dequeue (%u)\n", [dequeue_cnt]
1 ha 178
    push    eax
179
    shl     eax, 1
180
    add     eax, queueList        ; eax now holds address of queue entry
181
    mov     ax, [eax]
182
    mov     [ebx], ax
183
    pop     eax
184
 
185
dq_exit:
186
    sti
187
    pop     ebx
188
    ret
189
 
190
 
191
;***************************************************************************
192
;   Function
193
;      queueInit
194
;
195
;   Description
196
;       Initialises the queues to empty, and creates the free queue
197
;       list.
198
;
199
;***************************************************************************
200
queueInit:
201
    mov     esi, queues
202
    mov     ecx, NUMQUEUES
203
    mov     ax, NO_BUFFER
204
 
205
qi001:
206
    mov     [esi], ax
207
    inc     esi
208
    inc     esi
209
    loop    qi001
210
 
211
    mov     esi, queues + ( 2 * EMPTY_QUEUE )
212
 
213
    ; Initialise empty queue list
214
 
215
    xor     ax, ax
216
    mov     [esi], ax
217
 
218
    mov     ecx, NUMQUEUEENTRIES - 1
219
    mov     esi, queueList
220
 
221
qi002:
222
    inc     ax
223
    mov     [esi], ax
224
    inc     esi
225
    inc     esi
226
    loop    qi002
227
 
228
    mov     ax, NO_BUFFER
229
    mov     [esi], ax
230
 
231
    ret