2011-10-14 23:38:50 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2015-01-08 21:10:22 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
|
2011-10-14 23:38:50 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; queue.inc ;;
|
2011-10-14 23:38:50 +02:00
|
|
|
;; ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
2011-10-14 23:38:50 +02:00
|
|
|
;; ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
2011-10-14 23:38:50 +02:00
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-04-17 23:19:45 +02:00
|
|
|
$Revision$
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
; The Queues implemented by these macros form a ring-buffer.
|
|
|
|
; The data to these queue's always looks like this:
|
2011-10-14 23:38:50 +02:00
|
|
|
;
|
2013-05-28 19:34:26 +02:00
|
|
|
; At top, you have the queue struct, wich has the size (number of currently queued packets, read and write pointers.
|
|
|
|
; This struct is followed by a number of slots wich you can read and write to using the macros.
|
|
|
|
; How these slots look like is up to you to chose, normally they should have at least a pointer to where the real data is.
|
|
|
|
; (you can see some examples below)
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
struct queue
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
size dd ? ; number of queued packets in this queue
|
|
|
|
w_ptr dd ? ; current writing pointer in queue
|
|
|
|
r_ptr dd ? ; current reading pointer
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
ends
|
|
|
|
|
|
|
|
; The following macros share these inputs:
|
|
|
|
|
|
|
|
; ptr = pointer to where the queue data is located
|
|
|
|
; size = number of slots/entrys in the queue
|
|
|
|
; entry_size = size of one slot, in bytes
|
|
|
|
; failaddr = the address where macro will jump to when there is no data in the queue
|
|
|
|
|
|
|
|
; additionally, add_to_queue requires you to set esi to the data wich you want to queue
|
|
|
|
; get_from_queue on the other hand will return a pointer in esi, to the entry you're interessed in
|
|
|
|
; PS: macros WILL destroy ecx and edi
|
|
|
|
|
|
|
|
macro add_to_queue ptr, size, entry_size, failaddr {
|
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
local .ok, .no_wrap
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-01-22 15:08:37 +01:00
|
|
|
spin_lock_irqsave
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
cmp [ptr + queue.size], size ; Check if queue isnt full
|
|
|
|
jb .ok
|
2017-05-26 20:56:19 +02:00
|
|
|
|
2014-01-22 15:08:37 +01:00
|
|
|
spin_unlock_irqrestore
|
2013-06-24 13:39:05 +02:00
|
|
|
jmp failaddr
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
.ok:
|
|
|
|
inc [ptr + queue.size] ; if not full, queue one more
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
mov edi, [ptr + queue.w_ptr] ; Current write pointer (FIFO!)
|
|
|
|
mov ecx, entry_size/4 ; Write the queue entry
|
2013-06-27 01:35:43 +02:00
|
|
|
rep movsd ;
|
2013-06-24 13:39:05 +02:00
|
|
|
|
|
|
|
lea ecx, [size*entry_size+ptr+sizeof.queue]
|
|
|
|
cmp edi, ecx ; entry size
|
|
|
|
jb .no_wrap
|
|
|
|
|
|
|
|
sub edi, size*entry_size
|
2013-05-28 19:34:26 +02:00
|
|
|
.no_wrap:
|
2013-06-24 13:39:05 +02:00
|
|
|
mov [ptr + queue.w_ptr], edi
|
|
|
|
|
2014-01-22 15:08:37 +01:00
|
|
|
spin_unlock_irqrestore
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
macro get_from_queue ptr, size, entry_size, failaddr {
|
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
local .ok, .no_wrap
|
|
|
|
|
2014-01-22 15:08:37 +01:00
|
|
|
spin_lock_irqsave
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
cmp [ptr + queue.size], 0 ; any packets queued?
|
|
|
|
ja .ok
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-01-22 15:08:37 +01:00
|
|
|
spin_unlock_irqrestore
|
2013-06-24 13:39:05 +02:00
|
|
|
jmp failaddr
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
.ok:
|
|
|
|
dec [ptr + queue.size] ; if so, dequeue one
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
mov esi, [ptr + queue.r_ptr]
|
|
|
|
push esi
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
add esi, entry_size
|
|
|
|
|
|
|
|
lea ecx, [size*entry_size+ptr+sizeof.queue]
|
|
|
|
cmp esi, ecx ; entry size
|
|
|
|
jb .no_wrap
|
|
|
|
|
|
|
|
sub esi, size*entry_size
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
.no_wrap:
|
2013-06-24 13:39:05 +02:00
|
|
|
mov dword [ptr + queue.r_ptr], esi
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
pop esi
|
|
|
|
|
2014-01-22 15:08:37 +01:00
|
|
|
spin_unlock_irqrestore
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
}
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
macro init_queue ptr {
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2013-06-24 13:39:05 +02:00
|
|
|
mov [ptr + queue.size] , 0
|
|
|
|
lea edi, [ptr + sizeof.queue]
|
|
|
|
mov [ptr + queue.w_ptr], edi
|
|
|
|
mov [ptr + queue.r_ptr], edi
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
}
|