Fixed alignment for data in network stack. Alqo, network queue uses a mutex now.

git-svn-id: svn://kolibrios.org@3698 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-06-24 11:39:05 +00:00
parent a5c3784aca
commit 1ca5fecb5c
11 changed files with 96 additions and 42 deletions

View File

@ -55,9 +55,8 @@ struct ARP_header
ends ends
align 4
uglobal uglobal
align 4
ARP_table rb NET_DEVICES_MAX*(ARP_TABLE_SIZE * sizeof.ARP_entry) ARP_table rb NET_DEVICES_MAX*(ARP_TABLE_SIZE * sizeof.ARP_entry)

View File

@ -55,8 +55,8 @@ struct FRAGMENT_entry ; This structure will replace the ethern
ends ends
align 4
uglobal uglobal
align 4
IP_LIST rd NET_DEVICES_MAX IP_LIST rd NET_DEVICES_MAX
SUBNET_LIST rd NET_DEVICES_MAX SUBNET_LIST rd NET_DEVICES_MAX
@ -69,6 +69,7 @@ uglobal
IP_packets_dumped rd NET_DEVICES_MAX IP_packets_dumped rd NET_DEVICES_MAX
FRAGMENT_LIST rb MAX_FRAGMENTS * sizeof.FRAGMENT_slot FRAGMENT_LIST rb MAX_FRAGMENTS * sizeof.FRAGMENT_slot
endg endg

View File

@ -30,8 +30,8 @@ struct IPv6_header
ends ends
align 4
uglobal uglobal
align 4
IPv6: IPv6:
.addresses rd 4*NET_DEVICES_MAX .addresses rd 4*NET_DEVICES_MAX

View File

@ -23,8 +23,11 @@ struct PPPoE_frame
ends ends
uglobal uglobal
align 4
PPPoE_SID dw ? PPPoE_SID dw ?
PPPoE_MAC dp ? PPPoE_MAC dp ?
endg endg
;----------------------------------------------------------------- ;-----------------------------------------------------------------

View File

@ -32,8 +32,8 @@ struct ETH_DEVICE NET_DEVICE
ends ends
align 4
iglobal iglobal
align 4
ETH_BROADCAST dp 0xffffffffffff ETH_BROADCAST dp 0xffffffffffff
endg endg

View File

@ -97,10 +97,12 @@ struct ICMP_header
ends ends
align 4
uglobal uglobal
align 4
ICMP_PACKETS_TX rd NET_DEVICES_MAX ICMP_PACKETS_TX rd NET_DEVICES_MAX
ICMP_PACKETS_RX rd NET_DEVICES_MAX ICMP_PACKETS_RX rd NET_DEVICES_MAX
endg endg

View File

@ -17,6 +17,7 @@
$Revision: 2891 $ $Revision: 2891 $
iglobal iglobal
align 4
LOOPBACK_DEVICE: LOOPBACK_DEVICE:

View File

@ -23,11 +23,12 @@ $Revision: 2305 $
; (you can see some examples below) ; (you can see some examples below)
struct queue struct queue
size dd ? ; number of queued packets in this queue size dd ? ; number of queued packets in this queue
w_ptr dd ? ; current writing pointer in queue w_ptr dd ? ; current writing pointer in queue
r_ptr dd ? ; current reading pointer r_ptr dd ? ; current reading pointer
mutex MUTEX
ends ends
@ -44,23 +45,41 @@ ends
macro add_to_queue ptr, size, entry_size, failaddr { macro add_to_queue ptr, size, entry_size, failaddr {
cmp [ptr + queue.size], size ; Check if queue isnt full local .ok, .no_wrap
jae failaddr
inc [ptr + queue.size] ; if not full, queue one more pusha
lea ecx, [ptr + queue.mutex]
call mutex_lock
popa
mov edi, [ptr + queue.w_ptr] ; Current write pointer (FIFO!) cmp [ptr + queue.size], size ; Check if queue isnt full
mov ecx, entry_size/4 ; Write the queue entry jb .ok
rep movsd ;
lea ecx, [size*entry_size+ptr+sizeof.queue] pusha
cmp edi, ecx ; entry size lea ecx, [ptr + queue.mutex]
jb .no_wrap call mutex_unlock
popa
jmp failaddr
sub edi, size*entry_size .ok:
inc [ptr + queue.size] ; if not full, queue one more
mov edi, [ptr + queue.w_ptr] ; Current write pointer (FIFO!)
mov ecx, entry_size/4 ; Write the queue entry
rep movsd ;
lea ecx, [size*entry_size+ptr+sizeof.queue]
cmp edi, ecx ; entry size
jb .no_wrap
sub edi, size*entry_size
.no_wrap: .no_wrap:
mov [ptr + queue.w_ptr], edi mov [ptr + queue.w_ptr], edi
pusha
lea ecx, [ptr + queue.mutex]
call mutex_unlock
popa
} }
@ -68,33 +87,55 @@ macro add_to_queue ptr, size, entry_size, failaddr {
macro get_from_queue ptr, size, entry_size, failaddr { macro get_from_queue ptr, size, entry_size, failaddr {
cmp [ptr + queue.size], 0 ; any packets queued? local .ok, .no_wrap
je failaddr
dec [ptr + queue.size] ; if so, dequeue one pusha
lea ecx, [ptr + queue.mutex]
call mutex_lock
popa
mov esi, [ptr + queue.r_ptr] cmp [ptr + queue.size], 0 ; any packets queued?
push esi ja .ok
add esi, entry_size pusha
lea ecx, [ptr + queue.mutex]
call mutex_unlock
popa
jmp failaddr
lea ecx, [size*entry_size+ptr+sizeof.queue] .ok:
cmp esi, ecx ; entry size dec [ptr + queue.size] ; if so, dequeue one
jb .no_wrap
sub esi, size*entry_size mov esi, [ptr + queue.r_ptr]
push esi
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
.no_wrap: .no_wrap:
mov dword [ptr + queue.r_ptr], esi mov dword [ptr + queue.r_ptr], esi
pop esi pop esi
pusha
lea ecx, [ptr + queue.mutex]
call mutex_unlock
popa
} }
macro init_queue ptr { macro init_queue ptr {
mov [ptr + queue.size] , 0 mov [ptr + queue.size] , 0
lea edi, [ptr + sizeof.queue] lea edi, [ptr + sizeof.queue]
mov [ptr + queue.w_ptr], edi mov [ptr + queue.w_ptr], edi
mov [ptr + queue.r_ptr], edi mov [ptr + queue.r_ptr], edi
lea ecx, [ptr + queue.mutex]
call mutex_init
} }

View File

@ -194,11 +194,14 @@ SOCKET_QUEUE_SIZE = 10 ; maximum number of incoming packets queued f
SOCKET_QUEUE_LOCATION = (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue) SOCKET_QUEUE_LOCATION = (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue)
uglobal uglobal
align 4
net_sockets rd 4 net_sockets rd 4
last_socket_num dd ? last_socket_num dd ?
last_UDP_port dw ? ; These values give the number of the last used ephemeral port last_UDP_port dw ? ; These values give the number of the last used ephemeral port
last_TCP_port dw ? ; last_TCP_port dw ? ;
socket_mutex MUTEX socket_mutex MUTEX
endg endg
@ -614,8 +617,9 @@ align 4
.loop: .loop:
cmp [eax + TCP_SOCKET.t_state], TCPS_CLOSED cmp [eax + TCP_SOCKET.t_state], TCPS_CLOSED
je .fail je .fail
cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_SENT cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED
jne .syn_received je .established
ja .fail
call SOCKET_block call SOCKET_block
jmp .loop jmp .loop
@ -626,7 +630,7 @@ align 4
mov dword[esp+32], -1 mov dword[esp+32], -1
ret ret
.syn_received: .established:
mov dword[esp+32], 0 mov dword[esp+32], 0
ret ret

View File

@ -221,8 +221,8 @@ include "socket.inc"
align 4
uglobal uglobal
align 4
NET_RUNNING dd ? NET_RUNNING dd ?
NET_DRV_LIST rd NET_DEVICES_MAX NET_DRV_LIST rd NET_DEVICES_MAX

View File

@ -27,10 +27,12 @@ struct UDP_header
ends ends
align 4
uglobal uglobal
align 4
UDP_PACKETS_TX rd NET_DEVICES_MAX UDP_PACKETS_TX rd NET_DEVICES_MAX
UDP_PACKETS_RX rd NET_DEVICES_MAX UDP_PACKETS_RX rd NET_DEVICES_MAX
endg endg
@ -114,6 +116,7 @@ macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
diff16 "UDP packetgfgfgfgfs", 0, $
UDP_input: UDP_input:
DEBUGF DEBUG_NETWORK_VERBOSE, "UDP_input: size=%u\n", ecx DEBUGF DEBUG_NETWORK_VERBOSE, "UDP_input: size=%u\n", ecx