Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1159 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
1196 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;;
1159 hidnplayr 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;  queue.inc                                                   ;;
7
;;                                                              ;;
8
;;    Written by hidnplayr@kolibrios.org                        ;;
9
;;                                                              ;;
10
;;          GNU GENERAL PUBLIC LICENSE                          ;;
11
;;             Version 2, June 1991                             ;;
12
;;                                                              ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
 
1206 hidnplayr 15
$Revision: 1254 $
1159 hidnplayr 16
 
17
struct	queue
1249 hidnplayr 18
	.size		dd ?	; number of queued packets in thsi queue
19
	.w_ptr		dd ?	; current writing pointer in queue
20
	.r_ptr		dd ?	; current reading pointer
1159 hidnplayr 21
	.data:
22
ends
23
 
1249 hidnplayr 24
struct	eth_queue_entry
1159 hidnplayr 25
	.owner		dd ?
26
	.data_ptr	dd ?
27
	.data_size	dd ?
28
	.size:
29
ends
30
 
1249 hidnplayr 31
struct	tcp_in_queue_entry
32
	.data_ptr	dd ?
33
	.data_size	dd ?
34
	.offset 	dd ?
35
	.size:
36
ends
1159 hidnplayr 37
 
1249 hidnplayr 38
struct	tcp_out_queue_entry
39
	.data_ptr	dd ?
40
	.data_size	dd ?
41
	.ttl		dd ?
42
	.retries	dd ?
43
	.owner		dd ?
44
	.sendproc	dd ?
1254 hidnplayr 45
	.seq_num	dd ?
1249 hidnplayr 46
	.size:
47
ends
1159 hidnplayr 48
 
1249 hidnplayr 49
struct	socket_queue_entry
50
	.data_ptr	dd ?
51
	.data_size	dd ?
52
	.offset 	dd ?
53
	.size:
54
ends
1159 hidnplayr 55
 
1249 hidnplayr 56
macro add_to_queue ptr, size, entry_size, failaddr {
1159 hidnplayr 57
 
1249 hidnplayr 58
	cmp	[ptr + queue.size], size  ; Check if queue isnt full
59
	jge	failaddr
1159 hidnplayr 60
 
1249 hidnplayr 61
	inc	[ptr + queue.size]
1159 hidnplayr 62
 
1249 hidnplayr 63
	mov	edi, [ptr + queue.w_ptr]  ; Current write pointer (FIFO!)
64
	mov	ecx, entry_size/4		; Write the queue entry
65
	rep	movsd				;
1159 hidnplayr 66
 
1249 hidnplayr 67
	lea	ecx, [size*entry_size+ptr+queue.data]
68
	cmp	edi, ecx     ; entry size
1159 hidnplayr 69
	jl	.no_wrap
70
 
1249 hidnplayr 71
	sub	edi, size*entry_size
1159 hidnplayr 72
 
73
  .no_wrap:
1249 hidnplayr 74
	mov	[ptr + queue.w_ptr], edi
1159 hidnplayr 75
 
76
}
77
 
78
 
79
 
1249 hidnplayr 80
macro get_from_queue ptr, size, entry_size,  failaddr {
1159 hidnplayr 81
 
1249 hidnplayr 82
	cmp	[ptr + queue.size], 0		  ; any packets queued?
83
	je	failaddr
1159 hidnplayr 84
 
1249 hidnplayr 85
	dec	[ptr + queue.size]
1159 hidnplayr 86
 
87
	mov	esi, [ptr + queue.r_ptr]
1249 hidnplayr 88
	push	esi
1159 hidnplayr 89
 
1249 hidnplayr 90
	add	esi, entry_size
1159 hidnplayr 91
 
1249 hidnplayr 92
	lea	ecx, [size*entry_size+ptr+queue.data]
93
	cmp	esi, ecx	  ; entry size
1159 hidnplayr 94
	jl	.no_wrap
95
 
1249 hidnplayr 96
	sub	esi, size*entry_size
1159 hidnplayr 97
 
98
  .no_wrap:
99
	mov	dword [ptr + queue.r_ptr], esi
100
 
1249 hidnplayr 101
	pop	esi
102
 
1159 hidnplayr 103
}
104
 
1249 hidnplayr 105
macro init_queue queue_ptr {
106
 
107
	mov	[queue_ptr + queue.size] , 0
108
	lea	esi, [queue_ptr + queue.data]
109
	mov	[queue_ptr + queue.w_ptr], esi
110
	mov	[queue_ptr + queue.r_ptr], esi
111
}