Network stack: dynamic sockets list, other small fixes

git-svn-id: svn://kolibrios.org@907 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Mihail Semenyako (mike.dld) 2008-11-05 00:42:22 +00:00
parent 2d73c440b4
commit 54e9661045
10 changed files with 2033 additions and 1951 deletions

View File

@ -15,93 +15,101 @@ $Revision$
align 32
irq0:
pushad
mov ax, app_data ;
mov ds, ax
mov es, ax
pushad
mov ax, app_data ;
mov ds, ax
mov es, ax
inc dword [timer_ticks]
; cmp dword[CURRENT_TASK], 1
; jnz @f
; mov eax, [esp + 32]
; cmp eax, idle_loop + 1
; jz @f
; DEBUGF 1, "K : OOOPS! EAX = 0x%x\n", eax
; @@:
mov eax, [timer_ticks]
call playNote ; <<<--- Speaker driver
inc dword [timer_ticks]
cmp eax,[next_usage_update]
jb .nocounter
add eax,100
mov [next_usage_update],eax
call updatecputimes
mov eax, [timer_ticks]
call playNote ; <<<--- Speaker driver
cmp eax,[next_usage_update]
jb .nocounter
add eax,100
mov [next_usage_update],eax
call updatecputimes
.nocounter:
cmp [DONT_SWITCH], byte 1
jne .change_task
cmp [DONT_SWITCH], byte 1
jne .change_task
mov al,0x20 ; send End Of Interrupt signal
mov dx,0x20
out dx,al
mov al,0x20 ; send End Of Interrupt signal
mov dx,0x20
out dx,al
mov [DONT_SWITCH], byte 0
mov [DONT_SWITCH], byte 0
popad
iretd
popad
iretd
.change_task:
call update_counters
call update_counters
call find_next_task
mov ecx, eax
call find_next_task
mov ecx, eax
mov al,0x20 ; send End Of Interrupt signal
mov dx,0x20
out dx,al
mov al,0x20 ; send End Of Interrupt signal
mov dx,0x20
out dx,al
test ecx, ecx ; if there is only one running process
jnz .return
test ecx, ecx ; if there is only one running process
jnz .return
call do_change_task
call do_change_task
.return:
popad
popad
; popfd
iretd
iretd
align 4
change_task:
pushfd
cli
pushad
pushfd
cli
pushad
call update_counters
call update_counters
if 0
; \begin{Mario79}
cmp [dma_task_switched], 1
jne .find_next_task
mov [dma_task_switched], 0
mov ebx, [dma_process]
cmp [CURRENT_TASK], ebx
je .return
mov edi, [dma_slot_ptr]
mov [CURRENT_TASK], ebx
mov [TASK_BASE], edi
jmp @f
cmp [dma_task_switched], 1
jne .find_next_task
mov [dma_task_switched], 0
mov ebx, [dma_process]
cmp [CURRENT_TASK], ebx
je .return
mov edi, [dma_slot_ptr]
mov [CURRENT_TASK], ebx
mov [TASK_BASE], edi
jmp @f
.find_next_task:
; \end{Mario79}
end if
call find_next_task
test eax, eax ; the same task -> skip switch
jnz .return
call find_next_task
test eax, eax ; the same task -> skip switch
jnz .return
@@:
mov [DONT_SWITCH],byte 1
call do_change_task
mov [DONT_SWITCH],byte 1
call do_change_task
.return:
popad
popfd
ret
popad
popfd
ret
uglobal
@ -111,19 +119,19 @@ uglobal
.sel dw ?
context_counter dd ? ;noname & halyavin
next_usage_update dd ?
timer_ticks dd ?
prev_slot dd ?
event_sched dd ?
timer_ticks dd ?
prev_slot dd ?
event_sched dd ?
endg
update_counters:
mov edi, [TASK_BASE]
mov ebx, [edi+TASKDATA.counter_add] ; time stamp counter add
rdtsc
sub eax, ebx
add eax, [edi+TASKDATA.counter_sum] ; counter sum
mov [edi+TASKDATA.counter_sum], eax
mov edi, [TASK_BASE]
mov ebx, [edi+TASKDATA.counter_add] ; time stamp counter add
rdtsc
sub eax, ebx
add eax, [edi+TASKDATA.counter_sum] ; counter sum
mov [edi+TASKDATA.counter_sum], eax
ret
@ -134,65 +142,65 @@ ret
; [0x3000] = ebx and [0x3010] = edi
; corrupts other regs
find_next_task:
mov ebx, [CURRENT_TASK]
mov edi, [TASK_BASE]
mov [prev_slot], ebx
mov ebx, [CURRENT_TASK]
mov edi, [TASK_BASE]
mov [prev_slot], ebx
.waiting_for_termination:
.waiting_for_reuse:
.waiting_for_event:
.suspended:
cmp ebx, [TASK_COUNT]
jb @f
mov edi, CURRENT_TASK
xor ebx, ebx
cmp ebx, [TASK_COUNT]
jb @f
mov edi, CURRENT_TASK
xor ebx, ebx
@@:
add edi,0x20
inc ebx
add edi,0x20
inc ebx
mov al, byte [edi+TASKDATA.state]
test al, al
jz .found
mov al, byte [edi+TASKDATA.state]
test al, al
jz .found
cmp al, 1
jz .suspended
cmp al, 2
jz .suspended
cmp al, 3
je .waiting_for_termination
cmp al, 4
je .waiting_for_termination
cmp al, 9
je .waiting_for_reuse
cmp al, 3
je .waiting_for_termination
cmp al, 4
je .waiting_for_termination
cmp al, 9
je .waiting_for_reuse
mov [CURRENT_TASK],ebx
mov [TASK_BASE],edi
mov [CURRENT_TASK],ebx
mov [TASK_BASE],edi
cmp al, 5
jne .noevents
call get_event_for_app
test eax, eax
jnz @f
mov eax, ebx
shl eax, 8
mov eax, [SLOT_BASE + APPDATA.wait_timeout + eax]
cmp eax, [timer_ticks]
jae .waiting_for_event
xor eax, eax
cmp al, 5
jne .noevents
call get_event_for_app
test eax, eax
jnz @f
mov eax, ebx
shl eax, 8
mov eax, [SLOT_BASE + APPDATA.wait_timeout + eax]
cmp eax, [timer_ticks]
jae .waiting_for_event
xor eax, eax
@@:
mov [event_sched], eax
mov [edi+TASKDATA.state], byte 0
mov [event_sched], eax
mov [edi+TASKDATA.state], byte 0
.noevents:
.found:
mov [CURRENT_TASK],ebx
mov [TASK_BASE],edi
rdtsc ;call _rdtsc
mov [edi+TASKDATA.counter_add],eax
mov [CURRENT_TASK],ebx
mov [TASK_BASE],edi
rdtsc ;call _rdtsc
mov [edi+TASKDATA.counter_add],eax
mov esi, [prev_slot]
mov esi, [prev_slot]
xor eax, eax
cmp ebx, esi
sete al
cmp ebx, esi
sete al
ret
; param
@ -201,78 +209,78 @@ ret
do_change_task:
shl ebx, 8
add ebx, SLOT_BASE
mov [current_slot], ebx
shl ebx, 8
add ebx, SLOT_BASE
mov [current_slot], ebx
shl esi, 8
add esi, SLOT_BASE
shl esi, 8
add esi, SLOT_BASE
mov [esi+APPDATA.saved_esp], esp
mov esp, [ebx+APPDATA.saved_esp]
mov [esi+APPDATA.saved_esp], esp
mov esp, [ebx+APPDATA.saved_esp]
; set thread io map
mov ecx, [ebx+APPDATA.io_map]
mov edx, [ebx+APPDATA.io_map+4]
mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)], ecx
mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)], edx
mov ecx, [ebx+APPDATA.io_map]
mov edx, [ebx+APPDATA.io_map+4]
mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)], ecx
mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)], edx
mov eax, [ebx+APPDATA.dir_table]
cmp eax, [esi+APPDATA.dir_table]
je @F
mov cr3, eax
mov eax, [ebx+APPDATA.dir_table]
cmp eax, [esi+APPDATA.dir_table]
je @F
mov cr3, eax
@@:
mov eax, [ebx+APPDATA.saved_esp0]
mov [tss._esp0], eax
mov ax, graph_data
mov gs, ax
mov eax, [ebx+APPDATA.saved_esp0]
mov [tss._esp0], eax
mov ax, graph_data
mov gs, ax
mov eax, [CURRENT_TASK]
cmp eax, [fpu_owner]
clts ;clear a task switch flag
je @F
;and set it again if the owner
mov ecx, cr0 ;of a fpu has changed
or ecx, CR0_TS
mov cr0, ecx
mov eax, [CURRENT_TASK]
cmp eax, [fpu_owner]
clts ;clear a task switch flag
je @F
;and set it again if the owner
mov ecx, cr0 ;of a fpu has changed
or ecx, CR0_TS
mov cr0, ecx
@@:
inc [context_counter] ;noname & halyavin
test [ebx+APPDATA.dbg_state], 1
jnz @F
ret
inc [context_counter] ;noname & halyavin
test [ebx+APPDATA.dbg_state], 1
jnz @F
ret
@@:
mov eax, [ebx+APPDATA.dbg_regs.dr0]
mov dr0, eax
mov eax, [ebx+APPDATA.dbg_regs.dr1]
mov dr1, eax
mov eax, [ebx+APPDATA.dbg_regs.dr2]
mov dr2, eax
mov eax, [ebx+APPDATA.dbg_regs.dr3]
mov dr3, eax
xor eax, eax
mov dr6, eax
mov eax, [ebx+APPDATA.dbg_regs.dr7]
mov dr7, eax
ret
mov eax, [ebx+APPDATA.dbg_regs.dr0]
mov dr0, eax
mov eax, [ebx+APPDATA.dbg_regs.dr1]
mov dr1, eax
mov eax, [ebx+APPDATA.dbg_regs.dr2]
mov dr2, eax
mov eax, [ebx+APPDATA.dbg_regs.dr3]
mov dr3, eax
xor eax, eax
mov dr6, eax
mov eax, [ebx+APPDATA.dbg_regs.dr7]
mov dr7, eax
ret
align 4
updatecputimes:
mov eax,[idleuse]
mov [idleusesec],eax
mov [idleuse],dword 0
mov ecx, [TASK_COUNT]
mov edi, TASK_DATA
mov eax,[idleuse]
mov [idleusesec],eax
mov [idleuse],dword 0
mov ecx, [TASK_COUNT]
mov edi, TASK_DATA
.newupdate:
mov ebx,[edi+TASKDATA.counter_sum]
mov [edi+TASKDATA.cpu_usage],ebx
mov [edi+TASKDATA.counter_sum],dword 0
add edi,0x20
dec ecx
jnz .newupdate
mov ebx,[edi+TASKDATA.counter_sum]
mov [edi+TASKDATA.cpu_usage],ebx
mov [edi+TASKDATA.counter_sum],dword 0
add edi,0x20
dec ecx
jnz .newupdate
ret
ret
if 0
@ -282,7 +290,7 @@ struc TIMER
.next dd ?
.exp_time dd ?
.func dd ?
.arg dd ?
.arg dd ?
}
@ -293,12 +301,12 @@ struc TIMER
MAX_PROIRITY 0 ; highest, used for kernel tasks
MAX_USER_PRIORITY 0 ; highest priority for user processes
USER_PRIORITY 7 ; default (should correspond to nice 0)
MIN_USER_PRIORITY 14 ; minimum priority for user processes
IDLE_PRIORITY 15 ; lowest, only IDLE process goes here
NR_SCHED_QUEUES 16 ; MUST equal IDLE_PRIORYTY + 1
MAX_PROIRITY 0 ; highest, used for kernel tasks
MAX_USER_PRIORITY 0 ; highest priority for user processes
USER_PRIORITY 7 ; default (should correspond to nice 0)
MIN_USER_PRIORITY 14 ; minimum priority for user processes
IDLE_PRIORITY 15 ; lowest, only IDLE process goes here
NR_SCHED_QUEUES 16 ; MUST equal IDLE_PRIORYTY + 1
rdy_head rd 16
@ -306,21 +314,21 @@ rdy_head rd 16
align 4
pick_task:
xor eax, eax
xor eax, eax
.pick:
mov ebx, [rdy_head+eax*4]
test ebx, ebx
jz .next
mov ebx, [rdy_head+eax*4]
test ebx, ebx
jz .next
mov [next_task], ebx
test [ebx+flags.billable]
jz @F
mov [bill_task], ebx
mov [next_task], ebx
test [ebx+flags.billable]
jz @F
mov [bill_task], ebx
@@:
ret
ret
.next:
inc eax
jmp .pick
inc eax
jmp .pick
; param
@ -333,48 +341,48 @@ pick_task:
align 4
shed:
cmp [eax+.tics_left], 0 ;signed compare
mov ebx, [eax+.priority]
setg ecx
jg @F
cmp [eax+.tics_left], 0 ;signed compare
mov ebx, [eax+.priority]
setg ecx
jg @F
mov edx, [eax+.tics_quantum]
mov [eax+.ticks_left], edx
cmp ebx, (IDLE_PRIORITY-1)
je @F
inc ebx
mov edx, [eax+.tics_quantum]
mov [eax+.ticks_left], edx
cmp ebx, (IDLE_PRIORITY-1)
je @F
inc ebx
@@:
ret
ret
; param
; eax= task
align 4
enqueue:
call shed ;eax
cmp [rdy_head+ebx*4],0
jnz @F
call shed ;eax
cmp [rdy_head+ebx*4],0
jnz @F
mov [rdy_head+ebx*4], eax
mov [rdy_tail+ebx*4], eax
mov [eax+.next_ready], 0
jmp .pick
mov [rdy_head+ebx*4], eax
mov [rdy_tail+ebx*4], eax
mov [eax+.next_ready], 0
jmp .pick
@@:
test ecx, ecx
jz .back
test ecx, ecx
jz .back
mov ecx, [rdy_head+ebx*4]
mov [eax+.next_ready], ecx
mov [rdy_head+ebx*4], eax
jmp .pick
mov ecx, [rdy_head+ebx*4]
mov [eax+.next_ready], ecx
mov [rdy_head+ebx*4], eax
jmp .pick
.back:
mov ecx, [rdy_tail+ebx*4]
mov [ecx+.next_ready], eax
mov [rdy_tail+ebx*4], eax
mov [eax+.next_ready], 0
mov ecx, [rdy_tail+ebx*4]
mov [ecx+.next_ready], eax
mov [rdy_tail+ebx*4], eax
mov [eax+.next_ready], 0
.pick:
call pick_proc ;select next task
ret
call pick_proc ;select next task
ret
end if

View File

@ -90,7 +90,7 @@ szHwMouse db 'ATI2D',0
szPS2MDriver db 'PS2MOUSE',0
szCOM_MDriver db 'COM_MOUSE',0
szUSB db 'USB',0
szAtiHW db '/rd/1/drivers/ati2d.drv',0
szAtiHW db '/rd/1/drivers/ati2d.drv',0
szSTART db 'START',0
szEXPORTS db 'EXPORTS',0

View File

@ -524,20 +524,20 @@ endp
; Also adjust PCI latency timer to a reasonable value, 32.
proc adjust_pci_device
DEBUGF 1,"K : adjust_pci_device\n"
; DEBUGF 1,"K : adjust_pci_device\n"
stdcall pci_read_config_word,PCI_COMMAND
mov bx,ax
or bx,PCI_COMMAND_MASTER or PCI_COMMAND_IO
cmp ax,bx
je @f
DEBUGF 1,"K : adjust_pci_device: The PCI BIOS has not enabled this device!\nK : Updating PCI command %x->%x. pci_bus %x pci_device_fn %x\n",ax,bx,[pci_bus]:2,[pci_dev]:2
; DEBUGF 1,"K : adjust_pci_device: The PCI BIOS has not enabled this device!\nK : Updating PCI command %x->%x. pci_bus %x pci_device_fn %x\n",ax,bx,[pci_bus]:2,[pci_dev]:2
stdcall pci_write_config_word,PCI_COMMAND,ebx
@@:
stdcall pci_read_config_byte,PCI_LATENCY_TIMER
cmp al,32
jae @f
DEBUGF 1,"K : adjust_pci_device: PCI latency timer (CFLT) is unreasonably low at %d.\nK : Setting to 32 clocks.\n",al
; DEBUGF 1,"K : adjust_pci_device: PCI latency timer (CFLT) is unreasonably low at %d.\nK : Setting to 32 clocks.\n",al
stdcall pci_write_config_byte,PCI_LATENCY_TIMER,32
@@:
ret
@ -559,7 +559,7 @@ proc pci_bar_start,index:dword
stdcall pci_read_config_dword,eax
or eax,eax
jz .not64
DEBUGF 1,"K : pci_bar_start: Unhandled 64bit BAR\n"
; DEBUGF 1,"K : pci_bar_start: Unhandled 64bit BAR\n"
add esp,4
or eax,-1
ret
@ -572,7 +572,7 @@ endp
proc rtl8169_init_board
DEBUGF 1,"K : rtl8169_init_board\n"
; DEBUGF 1,"K : rtl8169_init_board\n"
call adjust_pci_device
@ -592,7 +592,7 @@ proc rtl8169_init_board
; identify config method
RTL_R32 RTL8169_REG_TxConfig
and eax,0x7c800000
DEBUGF 1,"K : rtl8169_init_board: TxConfig & 0x7c800000 = 0x%x\n",eax
; DEBUGF 1,"K : rtl8169_init_board: TxConfig & 0x7c800000 = 0x%x\n",eax
mov esi,mac_info-8
@@: add esi,8
mov ecx,eax
@ -625,9 +625,9 @@ proc rtl8169_init_board
jmp .match
@@:
; if unknown chip, assume array element #0, original RTL-8169 in this case
DEBUGF 1,"K : rtl8169_init_board: PCI device: unknown chip version, assuming RTL-8169\n"
; DEBUGF 1,"K : rtl8169_init_board: PCI device: unknown chip version, assuming RTL-8169\n"
RTL_R32 RTL8169_REG_TxConfig
DEBUGF 1,"K : rtl8169_init_board: PCI device: TxConfig = 0x%x\n",eax
; DEBUGF 1,"K : rtl8169_init_board: PCI device: TxConfig = 0x%x\n",eax
mov [rtl8169_tpc.chipset],0
@ -642,7 +642,7 @@ endp
proc rtl8169_hw_PHY_config
DEBUGF 1,"K : rtl8169_hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n",[rtl8169_tpc.mcfg],[rtl8169_tpc.pcfg]
; DEBUGF 1,"K : rtl8169_hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n",[rtl8169_tpc.mcfg],[rtl8169_tpc.pcfg]
; DBG_PRINT("priv->mcfg=%d, priv->pcfg=%d\n", tpc->mcfg, tpc->pcfg);
@ -705,7 +705,7 @@ proc rtl8169_hw_PHY_config
jmp .exit
.not_2_or_3:
; DBG_PRINT("tpc->mcfg=%d. Discard hw PHY config.\n", tpc->mcfg);
DEBUGF 1,"K : tpc.mcfg=%d, discard hw PHY config\n",[rtl8169_tpc.mcfg]
; DEBUGF 1,"K : tpc.mcfg=%d, discard hw PHY config\n",[rtl8169_tpc.mcfg]
.exit:
ret
endp
@ -716,7 +716,7 @@ endp
proc RTL8169_WRITE_GMII_REG,RegAddr:byte,value:dword
;;; DEBUGF 1,"K : RTL8169_WRITE_GMII_REG: 0x%x 0x%x\n",[RegAddr]:2,[value]
;;; DEBUGF 1,"K : RTL8169_WRITE_GMII_REG: 0x%x 0x%x\n",[RegAddr]:2,[value]
movzx eax,[RegAddr]
shl eax,16
@ -738,7 +738,7 @@ endp
proc RTL8169_READ_GMII_REG,RegAddr:byte
;;; DEBUGF 1,"K : RTL8169_READ_GMII_REG: 0x%x\n",[RegAddr]:2
;;; DEBUGF 1,"K : RTL8169_READ_GMII_REG: 0x%x\n",[RegAddr]:2
push ecx
movzx eax,[RegAddr]
@ -767,7 +767,7 @@ endp
proc rtl8169_set_rx_mode
DEBUGF 1,"K : rtl8169_set_rx_mode\n"
; DEBUGF 1,"K : rtl8169_set_rx_mode\n"
; IFF_ALLMULTI
; Too many to filter perfectly -- accept all multicasts
@ -785,7 +785,7 @@ endp
proc rtl8169_init_ring
DEBUGF 1,"K : rtl8169_init_ring\n"
; DEBUGF 1,"K : rtl8169_init_ring\n"
xor eax,eax
mov [rtl8169_tpc.cur_rx],eax
@ -834,7 +834,7 @@ endp
proc rtl8169_hw_start
DEBUGF 1,"K : rtl8169_hw_start\n"
; DEBUGF 1,"K : rtl8169_hw_start\n"
; Soft reset the chip
RTL_W8 RTL8169_REG_ChipCmd,RTL8169_CMD_Reset
@ -883,10 +883,10 @@ proc rtl8169_hw_start
push eax ; shurf 28.09.2008
mov eax, [rtl8169_tpc.TxDescArray] ; shurf 28.09.2008
sub eax, OS_BASE ; shurf 28.09.2008
RTL_W32 RTL8169_REG_TxDescStartAddr,eax ;[rtl8169_tpc.TxDescArray] ; shurf 28.09.2008
RTL_W32 RTL8169_REG_TxDescStartAddr,eax ;[rtl8169_tpc.TxDescArray] ; shurf 28.09.2008
mov eax, [rtl8169_tpc.RxDescArray] ; shurf 28.09.2008
sub eax, OS_BASE ; shurf 28.09.2008
RTL_W32 RTL8169_REG_RxDescStartAddr,eax ;[rtl8169_tpc.RxDescArray] ; shurf 28.09.2008
RTL_W32 RTL8169_REG_RxDescStartAddr,eax ;[rtl8169_tpc.RxDescArray] ; shurf 28.09.2008
pop eax ; shurf 28.09.2008
RTL_W8 RTL8169_REG_Cfg9346,RTL8169_CFG_9346_Lock
stdcall udelay,10
@ -920,7 +920,7 @@ endp
;***************************************************************************
proc rtl8169_probe
DEBUGF 1,"K : rtl8169_probe: 0x%x : 0x%x 0x%x\n",[io_addr]:8,[pci_bus]:2,[pci_dev]:2
; DEBUGF 1,"K : rtl8169_probe: 0x%x : 0x%x 0x%x\n",[io_addr]:8,[pci_bus]:2,[pci_dev]:2
call rtl8169_init_board
@ -935,7 +935,7 @@ proc rtl8169_probe
inc ebx
loop @b
DEBUGF 1,"K : rtl8169_probe: MAC = %x-%x-%x-%x-%x-%x\n",[node_addr+0]:2,[node_addr+1]:2,[node_addr+2]:2,[node_addr+3]:2,[node_addr+4]:2,[node_addr+5]:2
; DEBUGF 1,"K : rtl8169_probe: MAC = %x-%x-%x-%x-%x-%x\n",[node_addr+0]:2,[node_addr+1]:2,[node_addr+2]:2,[node_addr+3]:2,[node_addr+4]:2,[node_addr+5]:2
; Config PHY
stdcall rtl8169_hw_PHY_config
@ -995,7 +995,7 @@ endp
;***************************************************************************
proc rtl8169_reset
DEBUGF 1,"K : rtl8169_reset: 0x%x : 0x%x 0x%x\n",[io_addr]:8,[pci_bus]:2,[pci_dev]:2
; DEBUGF 1,"K : rtl8169_reset: 0x%x : 0x%x 0x%x\n",[io_addr]:8,[pci_bus]:2,[pci_dev]:2
mov [rtl8169_tpc.TxDescArrays],rtl8169_tx_ring
; Tx Desscriptor needs 256 bytes alignment
@ -1040,7 +1040,7 @@ endp
;***************************************************************************
proc rtl8169_transmit
DEBUGF 1,"K : rtl8169_transmit\n" ;: 0x%x : 0x%x 0x%x 0x%x 0x%x\n",[io_addr]:8,edi,bx,ecx,esi
; DEBUGF 1,"K : rtl8169_transmit\n" ;: 0x%x : 0x%x 0x%x 0x%x 0x%x\n",[io_addr]:8,edi,bx,ecx,esi
push ecx edx esi
mov eax,MAX_ETH_FRAME_SIZE
@ -1094,7 +1094,7 @@ proc rtl8169_transmit
add eax,[rtl8169_tpc.TxDescArray]
xchg eax,ebx
mov [ebx + rtl8169_TxDesc.buf_addr],eax
sub [ebx + rtl8169_TxDesc.buf_addr],OS_BASE ; shurf 28.09.2008
sub [ebx + rtl8169_TxDesc.buf_addr],OS_BASE ; shurf 28.09.2008
mov eax,ecx
cmp eax,ETH_ZLEN
@ -1118,7 +1118,7 @@ proc rtl8169_transmit
jnz @f
stdcall udelay,10
loop @b
DEBUGF 1,"K : rtl8169_transmit: TX Time Out\n"
; DEBUGF 1,"K : rtl8169_transmit: TX Time Out\n"
@@:
ret
@ -1176,7 +1176,7 @@ proc rtl8169_poll
add eax,-4
mov [eth_rx_data_len],ax
DEBUGF 1,"K : rtl8169_poll: data length = %u\n",ax
; DEBUGF 1,"K : rtl8169_poll: data length = %u\n",ax
push eax
mov ecx,eax
@ -1198,10 +1198,10 @@ proc rtl8169_poll
@@: mov [ebx + rtl8169_RxDesc.status],eax
mov [ebx + rtl8169_RxDesc.buf_addr],edx
sub [ebx + rtl8169_RxDesc.buf_addr],OS_BASE ; shurf 28.09.2008
sub [ebx + rtl8169_RxDesc.buf_addr],OS_BASE ; shurf 28.09.2008
jmp @f
.else:
DEBUGF 1,"K : rtl8169_poll: Rx Error\n"
; DEBUGF 1,"K : rtl8169_poll: Rx Error\n"
; FIXME: shouldn't I reset the status on an error
@@:
inc [rtl8169_tpc.cur_rx]

View File

@ -353,6 +353,9 @@ endp
; All registers may be destroyed
;
;***************************************************************************
uglobal
ether_IP_handler_cnt dd ?
endg
ether_IP_handler:
mov eax, EMPTY_QUEUE
call dequeue
@ -376,6 +379,9 @@ ether_IP_handler:
cld
rep movsd
; inc [ether_IP_handler_cnt]
; DEBUGF 1, "K : ether_IP_handler (%u)\n", [ether_IP_handler_cnt]
; And finally, place the buffer in the IPRX queue
pop ebx
mov eax, IPIN_QUEUE
@ -462,16 +468,18 @@ eth_rx:
cmp ax, ETHER_ARP
je .is_arp ; It is ARP
DEBUGF 1,"K : eth_rx - dumped (%u)\n", ax
inc [dumped_rx_count]
jmp .exit ; If not IP or ARP, ignore
.is_ip:
DEBUGF 1,"K : eth_rx - IP packet\n"
; DEBUGF 1,"K : eth_rx - IP packet\n"
inc dword [ip_rx_count]
call ether_IP_handler
jmp .exit
.is_arp:
DEBUGF 1,"K : eth_rx - ARP packet\n"
; DEBUGF 1,"K : eth_rx - ARP packet\n"
; At this point, the packet is still in the Ether_buffer
call arp_handler

View File

@ -16,22 +16,22 @@ $Revision$
; IP underlying protocols numbers
PROTOCOL_ICMP equ 1
PROTOCOL_TCP equ 6
PROTOCOL_UDP equ 17
PROTOCOL_ICMP equ 1
PROTOCOL_TCP equ 6
PROTOCOL_UDP equ 17
struc IP_PACKET
{ .VersionAndIHL db ? ;+00 - Version[0-3 bits] and IHL(header length)[4-7 bits]
.TypeOfService db ? ;+01
.TotalLength dw ? ;+02
.Identification dw ? ;+04
.FlagsAndFragmentOffset dw ? ;+06 - Flags[0-2] and FragmentOffset[3-15]
.TimeToLive db ? ;+08
.Protocol db ? ;+09
.HeaderChecksum dw ? ;+10
.SourceAddress dd ? ;+12
.DestinationAddress dd ? ;+16
.DataOrOptional dd ? ;+20
{ .VersionAndIHL db ? ;+00 - Version[0-3 bits] and IHL(header length)[4-7 bits]
.TypeOfService db ? ;+01
.TotalLength dw ? ;+02
.Identification dw ? ;+04
.FlagsAndFragmentOffset dw ? ;+06 - Flags[0-2] and FragmentOffset[3-15]
.TimeToLive db ? ;+08
.Protocol db ? ;+09
.HeaderChecksum dw ? ;+10
.SourceAddress dd ? ;+12
.DestinationAddress dd ? ;+16
.DataOrOptional dd ? ;+20
}
virtual at 0
@ -83,10 +83,14 @@ macro GET_IHL reg, header_addr
and reg, 0x0000000F
; IHL keeps number of octets, so we need to << 2 'reg'
shl reg, 2
shl reg, 2
}
include "tcp.inc"
include "udp.inc"
include "icmp.inc"
;***************************************************************************
; Function
; ip_rx
@ -104,7 +108,7 @@ local buffer_number dd ?
mov eax, IPIN_QUEUE
call dequeue
cmp ax, NO_BUFFER
je .exit ; Exit if no buffer available
je .exit ; Exit if no buffer available
mov [buffer_number], eax ;save buffer number
@ -114,12 +118,14 @@ local buffer_number dd ?
mov ebx, eax ; ebx=pointer to IP_PACKET
; DEBUGF 1, "K : ip_rx - proto: %u\n", [ebx + IP_PACKET.Protocol]:1
; Validate the IP checksum
mov dx, word[ebx + IP_PACKET.HeaderChecksum]
xchg dh,dl ; Get the checksum in intel format
xchg dh,dl ; Get the checksum in intel format
mov [ebx + IP_PACKET.HeaderChecksum], word 0 ; clear checksum field - need to when
; recalculating checksum
mov [ebx + IP_PACKET.HeaderChecksum], 0 ; clear checksum field - need to when
; recalculating checksum
; this needs two data pointers and two size #.
; 2nd pointer can be of length 0
@ -127,32 +133,51 @@ local buffer_number dd ?
stdcall checksum_jb, ebx, ecx ;buf_ptr, buf_size
cmp dx, ax
; DEBUGF 1, "K : ip_rx - checksums: %x - %x\n", dx, ax
jnz .dump.1 ;if CHECKSUM isn't valid then dump packet
mov edx, ebx ; EDX (IP-BUFFER POINTER) WILL BE USED FOR *_rx HANDLERS BELOW!!!
jnz .dump ;if CHECKSUM isn't valid then dump packet
; DEBUGF 1, "K : ip_rx - dest: %x - %x\n", [ebx + IP_PACKET.DestinationAddress], [stack_ip]
; Validate the IP address, if it isn't broadcast
mov eax, [stack_ip]
cmp dword[ebx + IP_PACKET.DestinationAddress], eax
je @f
je @f
; If the IP address is 255.255.255.255, accept it
; - it is a broadcast packet, which we need for dhcp
cmp dword[ebx + IP_PACKET.DestinationAddress], 0xffffffff
jne .dump
mov eax, [ebx + IP_PACKET.DestinationAddress]
cmp eax, 0xffffffff
;je @f
;mov ecx, [stack_ip]
;and eax, [subnet_mask]
;and ecx, [subnet_mask]
;cmp eax, ecx
;jne .dump.2
;mov eax, [ebx + IP_PACKET.DestinationAddress]
;or eax, [subnet_mask]
;cmp eax, 0xffffffff
jne .dump.2
@@:
mov al, [ebx + IP_PACKET.VersionAndIHL]
and al, 0x0f ;get IHL(header length)
cmp al, 0x05 ;if IHL!= 5*4(20 bytes)
jnz .dump ;then dump it
; DEBUGF 1, "K : ip_rx - ihl: %x - 05\n", al
jnz .dump.3 ;then dump it
cmp byte[ebx + IP_PACKET.TimeToLive], byte 0
je .dump ;if TTL==0 then dump it
; DEBUGF 1, "K : ip_rx - ttl: %x - 00\n", [ebx + IP_PACKET.TimeToLive]:2
mov ax, word[ebx + IP_PACKET.FlagsAndFragmentOffset]
and ax, 0xFFBF ;get flags
cmp ax, 0 ;if some flags was set then we dump this packet
jnz .dump ;the flags should be used for fragmented packets
cmp [ebx + IP_PACKET.TimeToLive], 0
je .dump.4 ;if TTL==0 then dump it
mov ax, [ebx + IP_PACKET.FlagsAndFragmentOffset]
and ax, 0xFFBF ;get flags
; DEBUGF 1, "K : ip_rx - flags: %x - 0000\n", ax
cmp ax, 0 ;if some flags was set then we dump this packet
jnz .dump.5 ;the flags should be used for fragmented packets
; Check the protocol, and call the appropriate handler
; Each handler will re-use or free the queue buffer as appropriate
@ -161,7 +186,7 @@ local buffer_number dd ?
cmp al , PROTOCOL_TCP
jne .not_tcp
DEBUGF 1,"K : ip_rx - TCP packet\n"
; DEBUGF 1,"K : ip_rx - TCP packet\n"
mov eax, dword[buffer_number]
call tcp_rx
jmp .exit
@ -169,29 +194,48 @@ local buffer_number dd ?
.not_tcp:
cmp al, PROTOCOL_UDP
jne .not_udp
DEBUGF 1,"K : ip_rx - UDP packet\n"
; DEBUGF 1,"K : ip_rx - UDP packet\n"
mov eax, dword[buffer_number]
call udp_rx
jmp .exit
.not_udp:
cmp al , PROTOCOL_ICMP
jne .dump ;protocol ain't supported
cmp al, PROTOCOL_ICMP
jne .dump.6 ;protocol ain't supported
DEBUGF 1,"K : ip_rx - ICMP packet\n"
; DEBUGF 1,"K : ip_rx - ICMP packet\n"
;GET_IHL ecx, ebx + IP_PACKET.VersionAndIHL ;get packet length in ecx
mov eax, dword[buffer_number]
stdcall icmp_rx,eax,ebx,ecx ;buffer_number,IPPacketBase,IPHeaderLength
jmp .exit
.dump:
; No protocol handler available, so
; silently dump the packet, freeing up the queue buffer
.dump.1:
DEBUGF 1, "K : ip_rx - dumped (checksum: 0x%x-0x%x)\n", dx, ax
jmp .dump.x
inc dword [dumped_rx_count]
.dump.2:
DEBUGF 1, "K : ip_rx - dumped (ip: %u.%u.%u.%u)\n", [ebx + IP_PACKET.DestinationAddress + 0]:1, [ebx + IP_PACKET.DestinationAddress + 1]:1, [ebx + IP_PACKET.DestinationAddress + 2]:1, [ebx + IP_PACKET.DestinationAddress + 3]:1
jmp .dump.x
mov eax, dword[buffer_number]
.dump.3:
DEBUGF 1, "K : ip_rx - dumped (ihl: %u)\n", al
jmp .dump.x
.dump.4:
DEBUGF 1, "K : ip_rx - dumped (ihl: %u)\n", [ebx + IP_PACKET.TimeToLive]
jmp .dump.x
.dump.5:
DEBUGF 1, "K : ip_rx - dumped (flags: 0x%x)\n", ax
jmp .dump.x
.dump.6:
DEBUGF 1, "K : ip_rx - dumped (proto: %u)\n", [ebx + IP_PACKET.Protocol]:1
.dump.x:
inc dword[dumped_rx_count]
mov eax, [buffer_number]
call freeBuff
.exit:

View File

@ -43,18 +43,19 @@ $Revision$
; all other registers preserved
; This always works, so no error returned
;***************************************************************************
uglobal
freeBuff_cnt dd ?
endg
freeBuff:
; inc [freeBuff_cnt]
; DEBUGF 1, "K : freeBuff (%u)\n", [freeBuff_cnt]
push ebx
push ecx
mov ebx, EMPTY_QUEUE
shl ebx, 1
add ebx, queues
mov ebx, queues + EMPTY_QUEUE * 2
cli ; Ensure that another process does not interfer
movzx ecx, word [ebx]
mov cx, [ebx]
mov [ebx], ax
shl eax, 1
add eax, queueList
mov [eax], cx
mov [queueList + eax * 2], cx
sti
pop ecx
pop ebx
@ -78,7 +79,7 @@ queueSize:
add ebx, queues
movzx ecx, word [ebx]
cmp cx, NO_BUFFER
je qs_exit
je qs_exit
qs_001:
inc eax
@ -86,7 +87,7 @@ qs_001:
add ecx, queueList
movzx ecx, word [ecx]
cmp cx, NO_BUFFER
je qs_exit
je qs_exit
jmp qs_001
qs_exit:
@ -105,15 +106,20 @@ qs_exit:
; all other registers preserved
; This always works, so no error returned
;***************************************************************************
uglobal
queue_cnt dd ?
endg
queue:
; inc [queue_cnt]
; DEBUGF 1, "K : queue (%u)\n", [queue_cnt]
push ebx
shl ebx, 1
add ebx, queueList ; eax now holds address of queue entry
add ebx, queueList ; eax now holds address of queue entry
mov [ebx], word NO_BUFFER ; This buffer will be the last
cli
shl eax, 1
add eax, queues ; eax now holds address of queue
add eax, queues ; eax now holds address of queue
movzx ebx, word [eax]
cmp bx, NO_BUFFER
@ -155,18 +161,23 @@ qu_exit:
; all other registers preserved
;
;***************************************************************************
uglobal
dequeue_cnt dd ?
endg
dequeue:
push ebx
shl eax, 1
add eax, queues ; eax now holds address of queue
add eax, queues ; eax now holds address of queue
mov ebx, eax
cli
movzx eax, word [eax]
cmp ax, NO_BUFFER
je dq_exit
je dq_exit
; inc [dequeue_cnt]
; DEBUGF 1, "K : dequeue (%u)\n", [dequeue_cnt]
push eax
shl eax, 1
add eax, queueList ; eax now holds address of queue entry
add eax, queueList ; eax now holds address of queue entry
mov ax, [eax]
mov [ebx], ax
pop eax

File diff suppressed because it is too large Load Diff

View File

@ -37,7 +37,7 @@ $Revision$
uglobal
StackCounters:
dumped_rx_count: dd 0
dumped_rx_count dd 0
arp_tx_count: dd 0
arp_rx_count: dd 0
ip_rx_count: dd 0
@ -46,9 +46,9 @@ endg
; socket buffers
SOCKETBUFFSIZE equ 4096 ; state + config + buffer.
SOCKETHEADERSIZE equ 76 ; thus 4096 - SOCKETHEADERSIZE bytes data
SOCKETHEADERSIZE equ 76+8+8 ; thus 4096 - SOCKETHEADERSIZE bytes data
NUM_SOCKETS equ 16 ; Number of open sockets supported. Was 20
;NUM_SOCKETS equ 16 ; Number of open sockets supported. Was 20
; IPBUFF status values
BUFF_EMPTY equ 0
@ -59,6 +59,7 @@ BUFF_TX_FULL equ 3
NUM_IPBUFFERS equ 20 ; buffers allocated for TX/RX
NUMQUEUES equ 4
EMPTY_QUEUE equ 0
IPIN_QUEUE equ 1
IPOUT_QUEUE equ 2
@ -94,7 +95,7 @@ ethernet_active equ stack_data + 9
; TODO :: empty memory area
; Address of selected socket
sktAddr equ stack_data + 32
;sktAddr equ stack_data + 32
; Parameter to checksum routine - data ptr
checkAdd1 equ stack_data + 36
; Parameter to checksum routine - 2nd data ptr
@ -110,8 +111,8 @@ checkResult equ stack_data + 48
pseudoHeader equ stack_data + 50
; receive and transmit IP buffer allocation
sockets equ stack_data + 62
Next_free2 equ sockets + (SOCKETBUFFSIZE * NUM_SOCKETS)
;sockets equ stack_data + 62
Next_free2 equ stack_data + 62;Next_free2 equ sockets + (SOCKETBUFFSIZE * NUM_SOCKETS)
; 1560 byte buffer for rx / tx ethernet packets
Ether_buffer equ Next_free2
Next_free3 equ Ether_buffer + 1518
@ -128,9 +129,15 @@ last_1hsTick equ queueList + ( 2 * NUMQUEUEENTRIES )
;resendQ equ 0x770000
resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP
;resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP ; XTODO: validate size
resendBuffer equ resendQ + ( 8 * NUMRESENDENTRIES ) ; for TCP
uglobal
net_sockets_mutex dd 0
net_sockets rd 2
endg
; simple macro for memory set operation
macro _memset_dw adr,value,amount
{
@ -151,9 +158,6 @@ macro _memset_dw adr,value,amount
include "queue.inc"
include "eth_drv/ethernet.inc"
include "ip.inc"
include "icmp.inc"
include "tcp.inc"
include "udp.inc"
include "socket.inc"
;***************************************************************************
@ -171,7 +175,8 @@ include "socket.inc"
stack_init:
; Init two address spaces with default values
_memset_dw stack_data_start, 0, 0x20000/4
_memset_dw resendQ, 0xFFFFFFFF, NUMRESENDENTRIES
;_memset_dw resendQ, 0xFFFFFFFF, NUMRESENDENTRIES ; XTODO: validate size
_memset_dw resendQ, 0xFFFFFFFF, NUMRESENDENTRIES * 2
; Queries initialization
call queueInit
@ -931,13 +936,11 @@ stack_get_packet:
pop edx
push eax ; save address of IP data
; Get the address of the callers data
mov edi,[TASK_BASE]
add edi,TASKDATA.mem_start
add edx,[edi]
mov edi, edx
pop eax
mov ecx, 1500 ; should get the actual number of bytes to write

File diff suppressed because it is too large Load Diff

View File

@ -47,11 +47,11 @@ $Revision$
;
struc UDP_PACKET
{ .SourcePort dw ? ;+00
{ .SourcePort dw ? ;+00
.DestinationPort dw ? ;+02
.Length dw ? ;+04 - Length of (UDP Header + Data)
.Checksum dw ? ;+06
.Data db ? ;+08
.Length dw ? ;+04 - Length of (UDP Header + Data)
.Checksum dw ? ;+06
.Data db ? ;+08
}
virtual at 0
@ -71,103 +71,93 @@ end virtual
; Free up (or re-use) IP buffer when finished
;
;***************************************************************************
udp_rx:
push eax
; First validate the header & checksum. Discard buffer if error
proc udp_rx stdcall
push eax
; Look for a socket where
; IP Packet UDP Destination Port = local Port
; IP Packet SA = Remote IP
; First validate the header & checksum. Discard buffer if error
movzx ebx, word [edx + 22] ; get the local port from
; the IP packet's UDP header
mov eax, SOCKETBUFFSIZE * NUM_SOCKETS
mov ecx, NUM_SOCKETS
; Look for a socket where
; IP Packet UDP Destination Port = local Port
; IP Packet SA = Remote IP
fs1:
sub eax, SOCKETBUFFSIZE
cmp [eax + sockets + 12], bx ; bx will hold the 'wrong' value,
; but the comparision is correct
loopnz fs1 ; Return back if no match
jz fs_done
mov ax, [edx + 20 + UDP_PACKET.DestinationPort] ; get the local port from
; the IP packet's UDP header
; No match, so exit
jmp udprx_001
mov ebx, net_sockets_mutex
call wait_mutex
mov ebx, net_sockets
fs_done:
; For dhcp, we must allow any remote server to respond.
; I will accept the first incoming response to be the one
; I bind to, if the socket is opened with a destination IP address of
; 255.255.255.255
mov ebx, [eax + sockets + 16]
cmp ebx, 0xffffffff
je udprx_002
.next_socket:
mov ebx, [ebx + SOCKET.NextPtr]
or ebx, ebx
jz .exit ; No match, so exit
cmp [ebx + SOCKET.LocalPort], ax ; ax will hold the 'wrong' value,
; but the comparision is correct
jne .next_socket ; Return back if no match
mov ebx, [edx + 12] ; get the Source address from the IP packet
cmp [eax + sockets + 16], ebx
jne udprx_001 ; Quit if the source IP is not valid
; For dhcp, we must allow any remote server to respond.
; I will accept the first incoming response to be the one
; I bind to, if the socket is opened with a destination IP address of
; 255.255.255.255
cmp [ebx + SOCKET.RemoteIP], 0xffffffff
je @f
udprx_002:
; OK - we have a valid UDP packet for this socket.
; First, update the sockets remote port number with the incoming msg
; - it will have changed
; from the original ( 69 normally ) to allow further connects
movzx ebx, word [edx + 20] ; get the UDP source port
; ( was 69, now new )
mov [eax + sockets + 20], bx
mov eax, [edx + IP_PACKET.SourceAddress] ; get the Source address from the IP packet
cmp [ebx + SOCKET.RemoteIP], ebx
jne .exit ; Quit if the source IP is not valid
; Now, copy data to socket. We have socket address as [eax + sockets].
; We have IP packet in edx
@@: ; OK - we have a valid UDP packet for this socket.
; First, update the sockets remote port number with the incoming msg
; - it will have changed
; from the original ( 69 normally ) to allow further connects
mov ax, [edx + 20 + UDP_PACKET.SourcePort] ; get the UDP source port
; ( was 69, now new )
mov [ebx + SOCKET.RemotePort], ax
; get # of bytes in ecx
movzx ecx, byte [edx + 3] ; total length of IP packet. Subtract
mov ch, byte [edx + 2] ; 20 + 8 gives data length
sub ecx, 28
; Now, copy data to socket. We have socket address as [eax + sockets].
; We have IP packet in edx
mov ebx, eax
add ebx, sockets ; ebx = address of actual socket
; get # of bytes in ecx
movzx ecx, [edx + IP_PACKET.TotalLength] ; total length of IP packet. Subtract
xchg cl, ch ; 20 + 8 gives data length
sub ecx, 28
mov eax, [ebx+ 4] ; get socket owner PID
push eax
mov eax, [ebx + SOCKET.rxDataCount] ; get # of bytes already in buffer
add [ebx + SOCKET.rxDataCount], ecx ; increment the count of bytes in buffer
mov eax, [ebx + 24] ; get # of bytes already in buffer
add [ebx + 24], ecx ; increment the count of bytes in buffer
; ecx has count, edx points to data
; point to the location to store the data
add ebx, eax
add ebx, SOCKETHEADERSIZE
add edx, 28 ; edx now points to the data
lea edi, [ebx + eax + SOCKETHEADERSIZE]
mov esi, edx
; ebx = location for first byte, ecx has count,
; edx points to data
cld
rep movsb ; copy the data across
add edx, 28 ; edx now points to the data
mov edi, ebx
mov esi, edx
; flag an event to the application
mov eax, [ebx + SOCKET.PID] ; get socket owner PID
mov ecx, 1
mov esi, TASK_DATA + TASKDATA.pid
cld
rep movsb ; copy the data across
.next_pid:
cmp [esi], eax
je .found_pid
inc ecx
add esi, 0x20
cmp ecx, [TASK_COUNT]
jbe .next_pid
; flag an event to the application
pop eax
mov ecx,1
mov esi,TASK_DATA+TASKDATA.pid
jmp .exit
newsearch:
cmp [esi],eax
je foundPID
inc ecx
add esi,0x20
cmp ecx,[TASK_COUNT]
jbe newsearch
.found_pid:
shl ecx, 8
or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK ; stack event
foundPID:
shl ecx,8
or dword [ecx+SLOT_BASE+APPDATA.event_mask],dword 10000000b ; stack event
mov [check_idle_semaphore], 200
mov [check_idle_semaphore],200
udprx_001:
pop eax
call freeBuff ; Discard the packet
ret
.exit:
pop eax
call freeBuff ; Discard the packet
ret
endp