forked from KolibriOS/kolibrios
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:
parent
2d73c440b4
commit
54e9661045
@ -15,93 +15,101 @@ $Revision$
|
|||||||
|
|
||||||
align 32
|
align 32
|
||||||
irq0:
|
irq0:
|
||||||
pushad
|
pushad
|
||||||
mov ax, app_data ;
|
mov ax, app_data ;
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
mov es, 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]
|
inc dword [timer_ticks]
|
||||||
call playNote ; <<<--- Speaker driver
|
|
||||||
|
|
||||||
cmp eax,[next_usage_update]
|
mov eax, [timer_ticks]
|
||||||
jb .nocounter
|
call playNote ; <<<--- Speaker driver
|
||||||
add eax,100
|
|
||||||
mov [next_usage_update],eax
|
cmp eax,[next_usage_update]
|
||||||
call updatecputimes
|
jb .nocounter
|
||||||
|
add eax,100
|
||||||
|
mov [next_usage_update],eax
|
||||||
|
call updatecputimes
|
||||||
.nocounter:
|
.nocounter:
|
||||||
cmp [DONT_SWITCH], byte 1
|
cmp [DONT_SWITCH], byte 1
|
||||||
jne .change_task
|
jne .change_task
|
||||||
|
|
||||||
mov al,0x20 ; send End Of Interrupt signal
|
mov al,0x20 ; send End Of Interrupt signal
|
||||||
mov dx,0x20
|
mov dx,0x20
|
||||||
out dx,al
|
out dx,al
|
||||||
|
|
||||||
mov [DONT_SWITCH], byte 0
|
mov [DONT_SWITCH], byte 0
|
||||||
|
|
||||||
popad
|
popad
|
||||||
iretd
|
iretd
|
||||||
|
|
||||||
.change_task:
|
.change_task:
|
||||||
call update_counters
|
call update_counters
|
||||||
|
|
||||||
call find_next_task
|
call find_next_task
|
||||||
mov ecx, eax
|
mov ecx, eax
|
||||||
|
|
||||||
mov al,0x20 ; send End Of Interrupt signal
|
mov al,0x20 ; send End Of Interrupt signal
|
||||||
mov dx,0x20
|
mov dx,0x20
|
||||||
out dx,al
|
out dx,al
|
||||||
|
|
||||||
test ecx, ecx ; if there is only one running process
|
test ecx, ecx ; if there is only one running process
|
||||||
jnz .return
|
jnz .return
|
||||||
|
|
||||||
call do_change_task
|
call do_change_task
|
||||||
|
|
||||||
.return:
|
.return:
|
||||||
popad
|
popad
|
||||||
; popfd
|
; popfd
|
||||||
iretd
|
iretd
|
||||||
|
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
change_task:
|
change_task:
|
||||||
|
|
||||||
pushfd
|
pushfd
|
||||||
cli
|
cli
|
||||||
pushad
|
pushad
|
||||||
|
|
||||||
call update_counters
|
call update_counters
|
||||||
|
|
||||||
if 0
|
if 0
|
||||||
|
|
||||||
; \begin{Mario79}
|
; \begin{Mario79}
|
||||||
cmp [dma_task_switched], 1
|
cmp [dma_task_switched], 1
|
||||||
jne .find_next_task
|
jne .find_next_task
|
||||||
mov [dma_task_switched], 0
|
mov [dma_task_switched], 0
|
||||||
mov ebx, [dma_process]
|
mov ebx, [dma_process]
|
||||||
cmp [CURRENT_TASK], ebx
|
cmp [CURRENT_TASK], ebx
|
||||||
je .return
|
je .return
|
||||||
mov edi, [dma_slot_ptr]
|
mov edi, [dma_slot_ptr]
|
||||||
mov [CURRENT_TASK], ebx
|
mov [CURRENT_TASK], ebx
|
||||||
mov [TASK_BASE], edi
|
mov [TASK_BASE], edi
|
||||||
jmp @f
|
jmp @f
|
||||||
.find_next_task:
|
.find_next_task:
|
||||||
; \end{Mario79}
|
; \end{Mario79}
|
||||||
|
|
||||||
end if
|
end if
|
||||||
|
|
||||||
call find_next_task
|
call find_next_task
|
||||||
test eax, eax ; the same task -> skip switch
|
test eax, eax ; the same task -> skip switch
|
||||||
jnz .return
|
jnz .return
|
||||||
@@:
|
@@:
|
||||||
mov [DONT_SWITCH],byte 1
|
mov [DONT_SWITCH],byte 1
|
||||||
call do_change_task
|
call do_change_task
|
||||||
|
|
||||||
.return:
|
.return:
|
||||||
popad
|
popad
|
||||||
popfd
|
popfd
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
uglobal
|
uglobal
|
||||||
@ -111,19 +119,19 @@ uglobal
|
|||||||
.sel dw ?
|
.sel dw ?
|
||||||
context_counter dd ? ;noname & halyavin
|
context_counter dd ? ;noname & halyavin
|
||||||
next_usage_update dd ?
|
next_usage_update dd ?
|
||||||
timer_ticks dd ?
|
timer_ticks dd ?
|
||||||
prev_slot dd ?
|
prev_slot dd ?
|
||||||
event_sched dd ?
|
event_sched dd ?
|
||||||
endg
|
endg
|
||||||
|
|
||||||
|
|
||||||
update_counters:
|
update_counters:
|
||||||
mov edi, [TASK_BASE]
|
mov edi, [TASK_BASE]
|
||||||
mov ebx, [edi+TASKDATA.counter_add] ; time stamp counter add
|
mov ebx, [edi+TASKDATA.counter_add] ; time stamp counter add
|
||||||
rdtsc
|
rdtsc
|
||||||
sub eax, ebx
|
sub eax, ebx
|
||||||
add eax, [edi+TASKDATA.counter_sum] ; counter sum
|
add eax, [edi+TASKDATA.counter_sum] ; counter sum
|
||||||
mov [edi+TASKDATA.counter_sum], eax
|
mov [edi+TASKDATA.counter_sum], eax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
@ -134,65 +142,65 @@ ret
|
|||||||
; [0x3000] = ebx and [0x3010] = edi
|
; [0x3000] = ebx and [0x3010] = edi
|
||||||
; corrupts other regs
|
; corrupts other regs
|
||||||
find_next_task:
|
find_next_task:
|
||||||
mov ebx, [CURRENT_TASK]
|
mov ebx, [CURRENT_TASK]
|
||||||
mov edi, [TASK_BASE]
|
mov edi, [TASK_BASE]
|
||||||
mov [prev_slot], ebx
|
mov [prev_slot], ebx
|
||||||
|
|
||||||
.waiting_for_termination:
|
.waiting_for_termination:
|
||||||
.waiting_for_reuse:
|
.waiting_for_reuse:
|
||||||
.waiting_for_event:
|
.waiting_for_event:
|
||||||
.suspended:
|
.suspended:
|
||||||
cmp ebx, [TASK_COUNT]
|
cmp ebx, [TASK_COUNT]
|
||||||
jb @f
|
jb @f
|
||||||
mov edi, CURRENT_TASK
|
mov edi, CURRENT_TASK
|
||||||
xor ebx, ebx
|
xor ebx, ebx
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
add edi,0x20
|
add edi,0x20
|
||||||
inc ebx
|
inc ebx
|
||||||
|
|
||||||
mov al, byte [edi+TASKDATA.state]
|
mov al, byte [edi+TASKDATA.state]
|
||||||
test al, al
|
test al, al
|
||||||
jz .found
|
jz .found
|
||||||
cmp al, 1
|
cmp al, 1
|
||||||
jz .suspended
|
jz .suspended
|
||||||
cmp al, 2
|
cmp al, 2
|
||||||
jz .suspended
|
jz .suspended
|
||||||
cmp al, 3
|
cmp al, 3
|
||||||
je .waiting_for_termination
|
je .waiting_for_termination
|
||||||
cmp al, 4
|
cmp al, 4
|
||||||
je .waiting_for_termination
|
je .waiting_for_termination
|
||||||
cmp al, 9
|
cmp al, 9
|
||||||
je .waiting_for_reuse
|
je .waiting_for_reuse
|
||||||
|
|
||||||
mov [CURRENT_TASK],ebx
|
mov [CURRENT_TASK],ebx
|
||||||
mov [TASK_BASE],edi
|
mov [TASK_BASE],edi
|
||||||
|
|
||||||
cmp al, 5
|
cmp al, 5
|
||||||
jne .noevents
|
jne .noevents
|
||||||
call get_event_for_app
|
call get_event_for_app
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jnz @f
|
jnz @f
|
||||||
mov eax, ebx
|
mov eax, ebx
|
||||||
shl eax, 8
|
shl eax, 8
|
||||||
mov eax, [SLOT_BASE + APPDATA.wait_timeout + eax]
|
mov eax, [SLOT_BASE + APPDATA.wait_timeout + eax]
|
||||||
cmp eax, [timer_ticks]
|
cmp eax, [timer_ticks]
|
||||||
jae .waiting_for_event
|
jae .waiting_for_event
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
@@:
|
@@:
|
||||||
mov [event_sched], eax
|
mov [event_sched], eax
|
||||||
mov [edi+TASKDATA.state], byte 0
|
mov [edi+TASKDATA.state], byte 0
|
||||||
.noevents:
|
.noevents:
|
||||||
.found:
|
.found:
|
||||||
mov [CURRENT_TASK],ebx
|
mov [CURRENT_TASK],ebx
|
||||||
mov [TASK_BASE],edi
|
mov [TASK_BASE],edi
|
||||||
rdtsc ;call _rdtsc
|
rdtsc ;call _rdtsc
|
||||||
mov [edi+TASKDATA.counter_add],eax
|
mov [edi+TASKDATA.counter_add],eax
|
||||||
|
|
||||||
mov esi, [prev_slot]
|
mov esi, [prev_slot]
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
cmp ebx, esi
|
cmp ebx, esi
|
||||||
sete al
|
sete al
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; param
|
; param
|
||||||
@ -201,78 +209,78 @@ ret
|
|||||||
|
|
||||||
do_change_task:
|
do_change_task:
|
||||||
|
|
||||||
shl ebx, 8
|
shl ebx, 8
|
||||||
add ebx, SLOT_BASE
|
add ebx, SLOT_BASE
|
||||||
mov [current_slot], ebx
|
mov [current_slot], ebx
|
||||||
|
|
||||||
shl esi, 8
|
shl esi, 8
|
||||||
add esi, SLOT_BASE
|
add esi, SLOT_BASE
|
||||||
|
|
||||||
mov [esi+APPDATA.saved_esp], esp
|
mov [esi+APPDATA.saved_esp], esp
|
||||||
mov esp, [ebx+APPDATA.saved_esp]
|
mov esp, [ebx+APPDATA.saved_esp]
|
||||||
|
|
||||||
; set thread io map
|
; set thread io map
|
||||||
|
|
||||||
mov ecx, [ebx+APPDATA.io_map]
|
mov ecx, [ebx+APPDATA.io_map]
|
||||||
mov edx, [ebx+APPDATA.io_map+4]
|
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_0 and -4096) shr 10)], ecx
|
||||||
mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)], edx
|
mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)], edx
|
||||||
|
|
||||||
mov eax, [ebx+APPDATA.dir_table]
|
mov eax, [ebx+APPDATA.dir_table]
|
||||||
cmp eax, [esi+APPDATA.dir_table]
|
cmp eax, [esi+APPDATA.dir_table]
|
||||||
je @F
|
je @F
|
||||||
mov cr3, eax
|
mov cr3, eax
|
||||||
@@:
|
@@:
|
||||||
mov eax, [ebx+APPDATA.saved_esp0]
|
mov eax, [ebx+APPDATA.saved_esp0]
|
||||||
mov [tss._esp0], eax
|
mov [tss._esp0], eax
|
||||||
mov ax, graph_data
|
mov ax, graph_data
|
||||||
mov gs, ax
|
mov gs, ax
|
||||||
|
|
||||||
mov eax, [CURRENT_TASK]
|
mov eax, [CURRENT_TASK]
|
||||||
cmp eax, [fpu_owner]
|
cmp eax, [fpu_owner]
|
||||||
clts ;clear a task switch flag
|
clts ;clear a task switch flag
|
||||||
je @F
|
je @F
|
||||||
;and set it again if the owner
|
;and set it again if the owner
|
||||||
mov ecx, cr0 ;of a fpu has changed
|
mov ecx, cr0 ;of a fpu has changed
|
||||||
or ecx, CR0_TS
|
or ecx, CR0_TS
|
||||||
mov cr0, ecx
|
mov cr0, ecx
|
||||||
@@:
|
@@:
|
||||||
inc [context_counter] ;noname & halyavin
|
inc [context_counter] ;noname & halyavin
|
||||||
test [ebx+APPDATA.dbg_state], 1
|
test [ebx+APPDATA.dbg_state], 1
|
||||||
jnz @F
|
jnz @F
|
||||||
ret
|
ret
|
||||||
@@:
|
@@:
|
||||||
mov eax, [ebx+APPDATA.dbg_regs.dr0]
|
mov eax, [ebx+APPDATA.dbg_regs.dr0]
|
||||||
mov dr0, eax
|
mov dr0, eax
|
||||||
mov eax, [ebx+APPDATA.dbg_regs.dr1]
|
mov eax, [ebx+APPDATA.dbg_regs.dr1]
|
||||||
mov dr1, eax
|
mov dr1, eax
|
||||||
mov eax, [ebx+APPDATA.dbg_regs.dr2]
|
mov eax, [ebx+APPDATA.dbg_regs.dr2]
|
||||||
mov dr2, eax
|
mov dr2, eax
|
||||||
mov eax, [ebx+APPDATA.dbg_regs.dr3]
|
mov eax, [ebx+APPDATA.dbg_regs.dr3]
|
||||||
mov dr3, eax
|
mov dr3, eax
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
mov dr6, eax
|
mov dr6, eax
|
||||||
mov eax, [ebx+APPDATA.dbg_regs.dr7]
|
mov eax, [ebx+APPDATA.dbg_regs.dr7]
|
||||||
mov dr7, eax
|
mov dr7, eax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
updatecputimes:
|
updatecputimes:
|
||||||
|
|
||||||
mov eax,[idleuse]
|
mov eax,[idleuse]
|
||||||
mov [idleusesec],eax
|
mov [idleusesec],eax
|
||||||
mov [idleuse],dword 0
|
mov [idleuse],dword 0
|
||||||
mov ecx, [TASK_COUNT]
|
mov ecx, [TASK_COUNT]
|
||||||
mov edi, TASK_DATA
|
mov edi, TASK_DATA
|
||||||
.newupdate:
|
.newupdate:
|
||||||
mov ebx,[edi+TASKDATA.counter_sum]
|
mov ebx,[edi+TASKDATA.counter_sum]
|
||||||
mov [edi+TASKDATA.cpu_usage],ebx
|
mov [edi+TASKDATA.cpu_usage],ebx
|
||||||
mov [edi+TASKDATA.counter_sum],dword 0
|
mov [edi+TASKDATA.counter_sum],dword 0
|
||||||
add edi,0x20
|
add edi,0x20
|
||||||
dec ecx
|
dec ecx
|
||||||
jnz .newupdate
|
jnz .newupdate
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
if 0
|
if 0
|
||||||
|
|
||||||
@ -282,7 +290,7 @@ struc TIMER
|
|||||||
.next dd ?
|
.next dd ?
|
||||||
.exp_time dd ?
|
.exp_time dd ?
|
||||||
.func dd ?
|
.func dd ?
|
||||||
.arg dd ?
|
.arg dd ?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -293,12 +301,12 @@ struc TIMER
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
MAX_PROIRITY 0 ; highest, used for kernel tasks
|
MAX_PROIRITY 0 ; highest, used for kernel tasks
|
||||||
MAX_USER_PRIORITY 0 ; highest priority for user processes
|
MAX_USER_PRIORITY 0 ; highest priority for user processes
|
||||||
USER_PRIORITY 7 ; default (should correspond to nice 0)
|
USER_PRIORITY 7 ; default (should correspond to nice 0)
|
||||||
MIN_USER_PRIORITY 14 ; minimum priority for user processes
|
MIN_USER_PRIORITY 14 ; minimum priority for user processes
|
||||||
IDLE_PRIORITY 15 ; lowest, only IDLE process goes here
|
IDLE_PRIORITY 15 ; lowest, only IDLE process goes here
|
||||||
NR_SCHED_QUEUES 16 ; MUST equal IDLE_PRIORYTY + 1
|
NR_SCHED_QUEUES 16 ; MUST equal IDLE_PRIORYTY + 1
|
||||||
|
|
||||||
rdy_head rd 16
|
rdy_head rd 16
|
||||||
|
|
||||||
@ -306,21 +314,21 @@ rdy_head rd 16
|
|||||||
align 4
|
align 4
|
||||||
pick_task:
|
pick_task:
|
||||||
|
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
.pick:
|
.pick:
|
||||||
mov ebx, [rdy_head+eax*4]
|
mov ebx, [rdy_head+eax*4]
|
||||||
test ebx, ebx
|
test ebx, ebx
|
||||||
jz .next
|
jz .next
|
||||||
|
|
||||||
mov [next_task], ebx
|
mov [next_task], ebx
|
||||||
test [ebx+flags.billable]
|
test [ebx+flags.billable]
|
||||||
jz @F
|
jz @F
|
||||||
mov [bill_task], ebx
|
mov [bill_task], ebx
|
||||||
@@:
|
@@:
|
||||||
ret
|
ret
|
||||||
.next:
|
.next:
|
||||||
inc eax
|
inc eax
|
||||||
jmp .pick
|
jmp .pick
|
||||||
|
|
||||||
|
|
||||||
; param
|
; param
|
||||||
@ -333,48 +341,48 @@ pick_task:
|
|||||||
|
|
||||||
align 4
|
align 4
|
||||||
shed:
|
shed:
|
||||||
cmp [eax+.tics_left], 0 ;signed compare
|
cmp [eax+.tics_left], 0 ;signed compare
|
||||||
mov ebx, [eax+.priority]
|
mov ebx, [eax+.priority]
|
||||||
setg ecx
|
setg ecx
|
||||||
jg @F
|
jg @F
|
||||||
|
|
||||||
mov edx, [eax+.tics_quantum]
|
mov edx, [eax+.tics_quantum]
|
||||||
mov [eax+.ticks_left], edx
|
mov [eax+.ticks_left], edx
|
||||||
cmp ebx, (IDLE_PRIORITY-1)
|
cmp ebx, (IDLE_PRIORITY-1)
|
||||||
je @F
|
je @F
|
||||||
inc ebx
|
inc ebx
|
||||||
@@:
|
@@:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; param
|
; param
|
||||||
; eax= task
|
; eax= task
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
enqueue:
|
enqueue:
|
||||||
call shed ;eax
|
call shed ;eax
|
||||||
cmp [rdy_head+ebx*4],0
|
cmp [rdy_head+ebx*4],0
|
||||||
jnz @F
|
jnz @F
|
||||||
|
|
||||||
mov [rdy_head+ebx*4], eax
|
mov [rdy_head+ebx*4], eax
|
||||||
mov [rdy_tail+ebx*4], eax
|
mov [rdy_tail+ebx*4], eax
|
||||||
mov [eax+.next_ready], 0
|
mov [eax+.next_ready], 0
|
||||||
jmp .pick
|
jmp .pick
|
||||||
@@:
|
@@:
|
||||||
test ecx, ecx
|
test ecx, ecx
|
||||||
jz .back
|
jz .back
|
||||||
|
|
||||||
mov ecx, [rdy_head+ebx*4]
|
mov ecx, [rdy_head+ebx*4]
|
||||||
mov [eax+.next_ready], ecx
|
mov [eax+.next_ready], ecx
|
||||||
mov [rdy_head+ebx*4], eax
|
mov [rdy_head+ebx*4], eax
|
||||||
jmp .pick
|
jmp .pick
|
||||||
.back:
|
.back:
|
||||||
mov ecx, [rdy_tail+ebx*4]
|
mov ecx, [rdy_tail+ebx*4]
|
||||||
mov [ecx+.next_ready], eax
|
mov [ecx+.next_ready], eax
|
||||||
mov [rdy_tail+ebx*4], eax
|
mov [rdy_tail+ebx*4], eax
|
||||||
mov [eax+.next_ready], 0
|
mov [eax+.next_ready], 0
|
||||||
.pick:
|
.pick:
|
||||||
call pick_proc ;select next task
|
call pick_proc ;select next task
|
||||||
ret
|
ret
|
||||||
|
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ szHwMouse db 'ATI2D',0
|
|||||||
szPS2MDriver db 'PS2MOUSE',0
|
szPS2MDriver db 'PS2MOUSE',0
|
||||||
szCOM_MDriver db 'COM_MOUSE',0
|
szCOM_MDriver db 'COM_MOUSE',0
|
||||||
szUSB db 'USB',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
|
szSTART db 'START',0
|
||||||
szEXPORTS db 'EXPORTS',0
|
szEXPORTS db 'EXPORTS',0
|
||||||
|
@ -524,20 +524,20 @@ endp
|
|||||||
; Also adjust PCI latency timer to a reasonable value, 32.
|
; Also adjust PCI latency timer to a reasonable value, 32.
|
||||||
proc adjust_pci_device
|
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
|
stdcall pci_read_config_word,PCI_COMMAND
|
||||||
mov bx,ax
|
mov bx,ax
|
||||||
or bx,PCI_COMMAND_MASTER or PCI_COMMAND_IO
|
or bx,PCI_COMMAND_MASTER or PCI_COMMAND_IO
|
||||||
cmp ax,bx
|
cmp ax,bx
|
||||||
je @f
|
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_write_config_word,PCI_COMMAND,ebx
|
||||||
@@:
|
@@:
|
||||||
stdcall pci_read_config_byte,PCI_LATENCY_TIMER
|
stdcall pci_read_config_byte,PCI_LATENCY_TIMER
|
||||||
cmp al,32
|
cmp al,32
|
||||||
jae @f
|
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
|
stdcall pci_write_config_byte,PCI_LATENCY_TIMER,32
|
||||||
@@:
|
@@:
|
||||||
ret
|
ret
|
||||||
@ -559,7 +559,7 @@ proc pci_bar_start,index:dword
|
|||||||
stdcall pci_read_config_dword,eax
|
stdcall pci_read_config_dword,eax
|
||||||
or eax,eax
|
or eax,eax
|
||||||
jz .not64
|
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
|
add esp,4
|
||||||
or eax,-1
|
or eax,-1
|
||||||
ret
|
ret
|
||||||
@ -572,7 +572,7 @@ endp
|
|||||||
|
|
||||||
proc rtl8169_init_board
|
proc rtl8169_init_board
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_init_board\n"
|
; DEBUGF 1,"K : rtl8169_init_board\n"
|
||||||
|
|
||||||
call adjust_pci_device
|
call adjust_pci_device
|
||||||
|
|
||||||
@ -592,7 +592,7 @@ proc rtl8169_init_board
|
|||||||
; identify config method
|
; identify config method
|
||||||
RTL_R32 RTL8169_REG_TxConfig
|
RTL_R32 RTL8169_REG_TxConfig
|
||||||
and eax,0x7c800000
|
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
|
mov esi,mac_info-8
|
||||||
@@: add esi,8
|
@@: add esi,8
|
||||||
mov ecx,eax
|
mov ecx,eax
|
||||||
@ -625,9 +625,9 @@ proc rtl8169_init_board
|
|||||||
jmp .match
|
jmp .match
|
||||||
@@:
|
@@:
|
||||||
; if unknown chip, assume array element #0, original RTL-8169 in this case
|
; 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
|
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
|
mov [rtl8169_tpc.chipset],0
|
||||||
|
|
||||||
@ -642,7 +642,7 @@ endp
|
|||||||
|
|
||||||
proc rtl8169_hw_PHY_config
|
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);
|
; DBG_PRINT("priv->mcfg=%d, priv->pcfg=%d\n", tpc->mcfg, tpc->pcfg);
|
||||||
|
|
||||||
@ -705,7 +705,7 @@ proc rtl8169_hw_PHY_config
|
|||||||
jmp .exit
|
jmp .exit
|
||||||
.not_2_or_3:
|
.not_2_or_3:
|
||||||
; DBG_PRINT("tpc->mcfg=%d. Discard hw PHY config.\n", tpc->mcfg);
|
; 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:
|
.exit:
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
@ -716,7 +716,7 @@ endp
|
|||||||
|
|
||||||
proc RTL8169_WRITE_GMII_REG,RegAddr:byte,value:dword
|
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]
|
movzx eax,[RegAddr]
|
||||||
shl eax,16
|
shl eax,16
|
||||||
@ -738,7 +738,7 @@ endp
|
|||||||
|
|
||||||
proc RTL8169_READ_GMII_REG,RegAddr:byte
|
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
|
push ecx
|
||||||
movzx eax,[RegAddr]
|
movzx eax,[RegAddr]
|
||||||
@ -767,7 +767,7 @@ endp
|
|||||||
|
|
||||||
proc rtl8169_set_rx_mode
|
proc rtl8169_set_rx_mode
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_set_rx_mode\n"
|
; DEBUGF 1,"K : rtl8169_set_rx_mode\n"
|
||||||
|
|
||||||
; IFF_ALLMULTI
|
; IFF_ALLMULTI
|
||||||
; Too many to filter perfectly -- accept all multicasts
|
; Too many to filter perfectly -- accept all multicasts
|
||||||
@ -785,7 +785,7 @@ endp
|
|||||||
|
|
||||||
proc rtl8169_init_ring
|
proc rtl8169_init_ring
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_init_ring\n"
|
; DEBUGF 1,"K : rtl8169_init_ring\n"
|
||||||
|
|
||||||
xor eax,eax
|
xor eax,eax
|
||||||
mov [rtl8169_tpc.cur_rx],eax
|
mov [rtl8169_tpc.cur_rx],eax
|
||||||
@ -834,7 +834,7 @@ endp
|
|||||||
|
|
||||||
proc rtl8169_hw_start
|
proc rtl8169_hw_start
|
||||||
|
|
||||||
DEBUGF 1,"K : rtl8169_hw_start\n"
|
; DEBUGF 1,"K : rtl8169_hw_start\n"
|
||||||
|
|
||||||
; Soft reset the chip
|
; Soft reset the chip
|
||||||
RTL_W8 RTL8169_REG_ChipCmd,RTL8169_CMD_Reset
|
RTL_W8 RTL8169_REG_ChipCmd,RTL8169_CMD_Reset
|
||||||
@ -883,10 +883,10 @@ proc rtl8169_hw_start
|
|||||||
push eax ; shurf 28.09.2008
|
push eax ; shurf 28.09.2008
|
||||||
mov eax, [rtl8169_tpc.TxDescArray] ; shurf 28.09.2008
|
mov eax, [rtl8169_tpc.TxDescArray] ; shurf 28.09.2008
|
||||||
sub eax, OS_BASE ; 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
|
mov eax, [rtl8169_tpc.RxDescArray] ; shurf 28.09.2008
|
||||||
sub eax, OS_BASE ; 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
|
pop eax ; shurf 28.09.2008
|
||||||
RTL_W8 RTL8169_REG_Cfg9346,RTL8169_CFG_9346_Lock
|
RTL_W8 RTL8169_REG_Cfg9346,RTL8169_CFG_9346_Lock
|
||||||
stdcall udelay,10
|
stdcall udelay,10
|
||||||
@ -920,7 +920,7 @@ endp
|
|||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
proc rtl8169_probe
|
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
|
call rtl8169_init_board
|
||||||
|
|
||||||
@ -935,7 +935,7 @@ proc rtl8169_probe
|
|||||||
inc ebx
|
inc ebx
|
||||||
loop @b
|
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
|
; Config PHY
|
||||||
stdcall rtl8169_hw_PHY_config
|
stdcall rtl8169_hw_PHY_config
|
||||||
@ -995,7 +995,7 @@ endp
|
|||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
proc rtl8169_reset
|
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
|
mov [rtl8169_tpc.TxDescArrays],rtl8169_tx_ring
|
||||||
; Tx Desscriptor needs 256 bytes alignment
|
; Tx Desscriptor needs 256 bytes alignment
|
||||||
@ -1040,7 +1040,7 @@ endp
|
|||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
proc rtl8169_transmit
|
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
|
push ecx edx esi
|
||||||
mov eax,MAX_ETH_FRAME_SIZE
|
mov eax,MAX_ETH_FRAME_SIZE
|
||||||
@ -1094,7 +1094,7 @@ proc rtl8169_transmit
|
|||||||
add eax,[rtl8169_tpc.TxDescArray]
|
add eax,[rtl8169_tpc.TxDescArray]
|
||||||
xchg eax,ebx
|
xchg eax,ebx
|
||||||
mov [ebx + rtl8169_TxDesc.buf_addr],eax
|
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
|
mov eax,ecx
|
||||||
cmp eax,ETH_ZLEN
|
cmp eax,ETH_ZLEN
|
||||||
@ -1118,7 +1118,7 @@ proc rtl8169_transmit
|
|||||||
jnz @f
|
jnz @f
|
||||||
stdcall udelay,10
|
stdcall udelay,10
|
||||||
loop @b
|
loop @b
|
||||||
DEBUGF 1,"K : rtl8169_transmit: TX Time Out\n"
|
; DEBUGF 1,"K : rtl8169_transmit: TX Time Out\n"
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
ret
|
ret
|
||||||
@ -1176,7 +1176,7 @@ proc rtl8169_poll
|
|||||||
add eax,-4
|
add eax,-4
|
||||||
mov [eth_rx_data_len],ax
|
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
|
push eax
|
||||||
mov ecx,eax
|
mov ecx,eax
|
||||||
@ -1198,10 +1198,10 @@ proc rtl8169_poll
|
|||||||
@@: mov [ebx + rtl8169_RxDesc.status],eax
|
@@: mov [ebx + rtl8169_RxDesc.status],eax
|
||||||
|
|
||||||
mov [ebx + rtl8169_RxDesc.buf_addr],edx
|
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
|
jmp @f
|
||||||
.else:
|
.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
|
; FIXME: shouldn't I reset the status on an error
|
||||||
@@:
|
@@:
|
||||||
inc [rtl8169_tpc.cur_rx]
|
inc [rtl8169_tpc.cur_rx]
|
||||||
|
@ -204,7 +204,7 @@ dd 0x70161039, SIS900_probe, SIS900_reset, SIS900_poll, SIS900_transmit, 0
|
|||||||
|
|
||||||
dd 0x006610de, forcedeth_probe, forcedeth_reset, forcedeth_poll, forcedeth_transmit, forcedeth_cable ; nVidia Corporation nForce2 Ethernet Controller
|
dd 0x006610de, forcedeth_probe, forcedeth_reset, forcedeth_poll, forcedeth_transmit, forcedeth_cable ; nVidia Corporation nForce2 Ethernet Controller
|
||||||
dd 0x01c310de, forcedeth_probe, forcedeth_reset, forcedeth_poll, forcedeth_transmit, forcedeth_cable ; not tested
|
dd 0x01c310de, forcedeth_probe, forcedeth_reset, forcedeth_poll, forcedeth_transmit, forcedeth_cable ; not tested
|
||||||
dd 0x00D610de, forcedeth_probe, forcedeth_reset, forcedeth_poll, forcedeth_transmit, forcedeth_cable ; not tested
|
dd 0x00D610de, forcedeth_probe, forcedeth_reset, forcedeth_poll, forcedeth_transmit, forcedeth_cable ; not tested
|
||||||
dd 0x008610de, forcedeth_probe, forcedeth_reset, forcedeth_poll, forcedeth_transmit, forcedeth_cable ; not tested
|
dd 0x008610de, forcedeth_probe, forcedeth_reset, forcedeth_poll, forcedeth_transmit, forcedeth_cable ; not tested
|
||||||
dd 0x008c10de, forcedeth_probe, forcedeth_reset, forcedeth_poll, forcedeth_transmit, forcedeth_cable ; not tested
|
dd 0x008c10de, forcedeth_probe, forcedeth_reset, forcedeth_poll, forcedeth_transmit, forcedeth_cable ; not tested
|
||||||
dd 0x00e610de, forcedeth_probe, forcedeth_reset, forcedeth_poll, forcedeth_transmit, forcedeth_cable ; not tested
|
dd 0x00e610de, forcedeth_probe, forcedeth_reset, forcedeth_poll, forcedeth_transmit, forcedeth_cable ; not tested
|
||||||
@ -353,6 +353,9 @@ endp
|
|||||||
; All registers may be destroyed
|
; All registers may be destroyed
|
||||||
;
|
;
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
|
uglobal
|
||||||
|
ether_IP_handler_cnt dd ?
|
||||||
|
endg
|
||||||
ether_IP_handler:
|
ether_IP_handler:
|
||||||
mov eax, EMPTY_QUEUE
|
mov eax, EMPTY_QUEUE
|
||||||
call dequeue
|
call dequeue
|
||||||
@ -376,6 +379,9 @@ ether_IP_handler:
|
|||||||
cld
|
cld
|
||||||
rep movsd
|
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
|
; And finally, place the buffer in the IPRX queue
|
||||||
pop ebx
|
pop ebx
|
||||||
mov eax, IPIN_QUEUE
|
mov eax, IPIN_QUEUE
|
||||||
@ -462,16 +468,18 @@ eth_rx:
|
|||||||
cmp ax, ETHER_ARP
|
cmp ax, ETHER_ARP
|
||||||
je .is_arp ; It is 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
|
jmp .exit ; If not IP or ARP, ignore
|
||||||
|
|
||||||
.is_ip:
|
.is_ip:
|
||||||
DEBUGF 1,"K : eth_rx - IP packet\n"
|
; DEBUGF 1,"K : eth_rx - IP packet\n"
|
||||||
inc dword [ip_rx_count]
|
inc dword [ip_rx_count]
|
||||||
call ether_IP_handler
|
call ether_IP_handler
|
||||||
jmp .exit
|
jmp .exit
|
||||||
|
|
||||||
.is_arp:
|
.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
|
; At this point, the packet is still in the Ether_buffer
|
||||||
call arp_handler
|
call arp_handler
|
||||||
|
|
||||||
|
@ -16,22 +16,22 @@ $Revision$
|
|||||||
|
|
||||||
|
|
||||||
; IP underlying protocols numbers
|
; IP underlying protocols numbers
|
||||||
PROTOCOL_ICMP equ 1
|
PROTOCOL_ICMP equ 1
|
||||||
PROTOCOL_TCP equ 6
|
PROTOCOL_TCP equ 6
|
||||||
PROTOCOL_UDP equ 17
|
PROTOCOL_UDP equ 17
|
||||||
|
|
||||||
struc IP_PACKET
|
struc IP_PACKET
|
||||||
{ .VersionAndIHL db ? ;+00 - Version[0-3 bits] and IHL(header length)[4-7 bits]
|
{ .VersionAndIHL db ? ;+00 - Version[0-3 bits] and IHL(header length)[4-7 bits]
|
||||||
.TypeOfService db ? ;+01
|
.TypeOfService db ? ;+01
|
||||||
.TotalLength dw ? ;+02
|
.TotalLength dw ? ;+02
|
||||||
.Identification dw ? ;+04
|
.Identification dw ? ;+04
|
||||||
.FlagsAndFragmentOffset dw ? ;+06 - Flags[0-2] and FragmentOffset[3-15]
|
.FlagsAndFragmentOffset dw ? ;+06 - Flags[0-2] and FragmentOffset[3-15]
|
||||||
.TimeToLive db ? ;+08
|
.TimeToLive db ? ;+08
|
||||||
.Protocol db ? ;+09
|
.Protocol db ? ;+09
|
||||||
.HeaderChecksum dw ? ;+10
|
.HeaderChecksum dw ? ;+10
|
||||||
.SourceAddress dd ? ;+12
|
.SourceAddress dd ? ;+12
|
||||||
.DestinationAddress dd ? ;+16
|
.DestinationAddress dd ? ;+16
|
||||||
.DataOrOptional dd ? ;+20
|
.DataOrOptional dd ? ;+20
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual at 0
|
virtual at 0
|
||||||
@ -83,10 +83,14 @@ macro GET_IHL reg, header_addr
|
|||||||
and reg, 0x0000000F
|
and reg, 0x0000000F
|
||||||
|
|
||||||
; IHL keeps number of octets, so we need to << 2 'reg'
|
; 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
|
; Function
|
||||||
; ip_rx
|
; ip_rx
|
||||||
@ -104,7 +108,7 @@ local buffer_number dd ?
|
|||||||
mov eax, IPIN_QUEUE
|
mov eax, IPIN_QUEUE
|
||||||
call dequeue
|
call dequeue
|
||||||
cmp ax, NO_BUFFER
|
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
|
mov [buffer_number], eax ;save buffer number
|
||||||
|
|
||||||
@ -114,12 +118,14 @@ local buffer_number dd ?
|
|||||||
|
|
||||||
mov ebx, eax ; ebx=pointer to IP_PACKET
|
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
|
; Validate the IP checksum
|
||||||
mov dx, word[ebx + IP_PACKET.HeaderChecksum]
|
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
|
mov [ebx + IP_PACKET.HeaderChecksum], 0 ; clear checksum field - need to when
|
||||||
; recalculating checksum
|
; recalculating checksum
|
||||||
; this needs two data pointers and two size #.
|
; this needs two data pointers and two size #.
|
||||||
; 2nd pointer can be of length 0
|
; 2nd pointer can be of length 0
|
||||||
|
|
||||||
@ -127,32 +133,51 @@ local buffer_number dd ?
|
|||||||
stdcall checksum_jb, ebx, ecx ;buf_ptr, buf_size
|
stdcall checksum_jb, ebx, ecx ;buf_ptr, buf_size
|
||||||
cmp dx, ax
|
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!!!
|
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
|
; Validate the IP address, if it isn't broadcast
|
||||||
mov eax, [stack_ip]
|
mov eax, [stack_ip]
|
||||||
cmp dword[ebx + IP_PACKET.DestinationAddress], eax
|
cmp dword[ebx + IP_PACKET.DestinationAddress], eax
|
||||||
je @f
|
je @f
|
||||||
|
|
||||||
; If the IP address is 255.255.255.255, accept it
|
; If the IP address is 255.255.255.255, accept it
|
||||||
; - it is a broadcast packet, which we need for dhcp
|
; - 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]
|
mov al, [ebx + IP_PACKET.VersionAndIHL]
|
||||||
and al, 0x0f ;get IHL(header length)
|
and al, 0x0f ;get IHL(header length)
|
||||||
cmp al, 0x05 ;if IHL!= 5*4(20 bytes)
|
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
|
; DEBUGF 1, "K : ip_rx - ttl: %x - 00\n", [ebx + IP_PACKET.TimeToLive]:2
|
||||||
je .dump ;if TTL==0 then dump it
|
|
||||||
|
|
||||||
mov ax, word[ebx + IP_PACKET.FlagsAndFragmentOffset]
|
cmp [ebx + IP_PACKET.TimeToLive], 0
|
||||||
and ax, 0xFFBF ;get flags
|
je .dump.4 ;if TTL==0 then dump it
|
||||||
cmp ax, 0 ;if some flags was set then we dump this packet
|
|
||||||
jnz .dump ;the flags should be used for fragmented packets
|
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
|
; Check the protocol, and call the appropriate handler
|
||||||
; Each handler will re-use or free the queue buffer as appropriate
|
; Each handler will re-use or free the queue buffer as appropriate
|
||||||
@ -161,7 +186,7 @@ local buffer_number dd ?
|
|||||||
|
|
||||||
cmp al , PROTOCOL_TCP
|
cmp al , PROTOCOL_TCP
|
||||||
jne .not_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]
|
mov eax, dword[buffer_number]
|
||||||
call tcp_rx
|
call tcp_rx
|
||||||
jmp .exit
|
jmp .exit
|
||||||
@ -169,29 +194,48 @@ local buffer_number dd ?
|
|||||||
.not_tcp:
|
.not_tcp:
|
||||||
cmp al, PROTOCOL_UDP
|
cmp al, PROTOCOL_UDP
|
||||||
jne .not_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]
|
mov eax, dword[buffer_number]
|
||||||
call udp_rx
|
call udp_rx
|
||||||
jmp .exit
|
jmp .exit
|
||||||
|
|
||||||
.not_udp:
|
.not_udp:
|
||||||
cmp al , PROTOCOL_ICMP
|
cmp al, PROTOCOL_ICMP
|
||||||
jne .dump ;protocol ain't supported
|
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
|
;GET_IHL ecx, ebx + IP_PACKET.VersionAndIHL ;get packet length in ecx
|
||||||
mov eax, dword[buffer_number]
|
mov eax, dword[buffer_number]
|
||||||
stdcall icmp_rx,eax,ebx,ecx ;buffer_number,IPPacketBase,IPHeaderLength
|
stdcall icmp_rx,eax,ebx,ecx ;buffer_number,IPPacketBase,IPHeaderLength
|
||||||
jmp .exit
|
jmp .exit
|
||||||
|
|
||||||
|
|
||||||
.dump:
|
.dump.1:
|
||||||
; No protocol handler available, so
|
DEBUGF 1, "K : ip_rx - dumped (checksum: 0x%x-0x%x)\n", dx, ax
|
||||||
; silently dump the packet, freeing up the queue buffer
|
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
|
call freeBuff
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
|
@ -43,18 +43,19 @@ $Revision$
|
|||||||
; all other registers preserved
|
; all other registers preserved
|
||||||
; This always works, so no error returned
|
; This always works, so no error returned
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
|
uglobal
|
||||||
|
freeBuff_cnt dd ?
|
||||||
|
endg
|
||||||
freeBuff:
|
freeBuff:
|
||||||
|
; inc [freeBuff_cnt]
|
||||||
|
; DEBUGF 1, "K : freeBuff (%u)\n", [freeBuff_cnt]
|
||||||
push ebx
|
push ebx
|
||||||
push ecx
|
push ecx
|
||||||
mov ebx, EMPTY_QUEUE
|
mov ebx, queues + EMPTY_QUEUE * 2
|
||||||
shl ebx, 1
|
|
||||||
add ebx, queues
|
|
||||||
cli ; Ensure that another process does not interfer
|
cli ; Ensure that another process does not interfer
|
||||||
movzx ecx, word [ebx]
|
mov cx, [ebx]
|
||||||
mov [ebx], ax
|
mov [ebx], ax
|
||||||
shl eax, 1
|
mov [queueList + eax * 2], cx
|
||||||
add eax, queueList
|
|
||||||
mov [eax], cx
|
|
||||||
sti
|
sti
|
||||||
pop ecx
|
pop ecx
|
||||||
pop ebx
|
pop ebx
|
||||||
@ -78,7 +79,7 @@ queueSize:
|
|||||||
add ebx, queues
|
add ebx, queues
|
||||||
movzx ecx, word [ebx]
|
movzx ecx, word [ebx]
|
||||||
cmp cx, NO_BUFFER
|
cmp cx, NO_BUFFER
|
||||||
je qs_exit
|
je qs_exit
|
||||||
|
|
||||||
qs_001:
|
qs_001:
|
||||||
inc eax
|
inc eax
|
||||||
@ -86,7 +87,7 @@ qs_001:
|
|||||||
add ecx, queueList
|
add ecx, queueList
|
||||||
movzx ecx, word [ecx]
|
movzx ecx, word [ecx]
|
||||||
cmp cx, NO_BUFFER
|
cmp cx, NO_BUFFER
|
||||||
je qs_exit
|
je qs_exit
|
||||||
jmp qs_001
|
jmp qs_001
|
||||||
|
|
||||||
qs_exit:
|
qs_exit:
|
||||||
@ -105,15 +106,20 @@ qs_exit:
|
|||||||
; all other registers preserved
|
; all other registers preserved
|
||||||
; This always works, so no error returned
|
; This always works, so no error returned
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
|
uglobal
|
||||||
|
queue_cnt dd ?
|
||||||
|
endg
|
||||||
queue:
|
queue:
|
||||||
|
; inc [queue_cnt]
|
||||||
|
; DEBUGF 1, "K : queue (%u)\n", [queue_cnt]
|
||||||
push ebx
|
push ebx
|
||||||
shl ebx, 1
|
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
|
mov [ebx], word NO_BUFFER ; This buffer will be the last
|
||||||
|
|
||||||
cli
|
cli
|
||||||
shl eax, 1
|
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]
|
movzx ebx, word [eax]
|
||||||
|
|
||||||
cmp bx, NO_BUFFER
|
cmp bx, NO_BUFFER
|
||||||
@ -155,18 +161,23 @@ qu_exit:
|
|||||||
; all other registers preserved
|
; all other registers preserved
|
||||||
;
|
;
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
|
uglobal
|
||||||
|
dequeue_cnt dd ?
|
||||||
|
endg
|
||||||
dequeue:
|
dequeue:
|
||||||
push ebx
|
push ebx
|
||||||
shl eax, 1
|
shl eax, 1
|
||||||
add eax, queues ; eax now holds address of queue
|
add eax, queues ; eax now holds address of queue
|
||||||
mov ebx, eax
|
mov ebx, eax
|
||||||
cli
|
cli
|
||||||
movzx eax, word [eax]
|
movzx eax, word [eax]
|
||||||
cmp ax, NO_BUFFER
|
cmp ax, NO_BUFFER
|
||||||
je dq_exit
|
je dq_exit
|
||||||
|
; inc [dequeue_cnt]
|
||||||
|
; DEBUGF 1, "K : dequeue (%u)\n", [dequeue_cnt]
|
||||||
push eax
|
push eax
|
||||||
shl eax, 1
|
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 ax, [eax]
|
||||||
mov [ebx], ax
|
mov [ebx], ax
|
||||||
pop eax
|
pop eax
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -37,7 +37,7 @@ $Revision$
|
|||||||
|
|
||||||
uglobal
|
uglobal
|
||||||
StackCounters:
|
StackCounters:
|
||||||
dumped_rx_count: dd 0
|
dumped_rx_count dd 0
|
||||||
arp_tx_count: dd 0
|
arp_tx_count: dd 0
|
||||||
arp_rx_count: dd 0
|
arp_rx_count: dd 0
|
||||||
ip_rx_count: dd 0
|
ip_rx_count: dd 0
|
||||||
@ -46,9 +46,9 @@ endg
|
|||||||
|
|
||||||
; socket buffers
|
; socket buffers
|
||||||
SOCKETBUFFSIZE equ 4096 ; state + config + buffer.
|
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
|
; IPBUFF status values
|
||||||
BUFF_EMPTY equ 0
|
BUFF_EMPTY equ 0
|
||||||
@ -59,6 +59,7 @@ BUFF_TX_FULL equ 3
|
|||||||
NUM_IPBUFFERS equ 20 ; buffers allocated for TX/RX
|
NUM_IPBUFFERS equ 20 ; buffers allocated for TX/RX
|
||||||
|
|
||||||
NUMQUEUES equ 4
|
NUMQUEUES equ 4
|
||||||
|
|
||||||
EMPTY_QUEUE equ 0
|
EMPTY_QUEUE equ 0
|
||||||
IPIN_QUEUE equ 1
|
IPIN_QUEUE equ 1
|
||||||
IPOUT_QUEUE equ 2
|
IPOUT_QUEUE equ 2
|
||||||
@ -94,7 +95,7 @@ ethernet_active equ stack_data + 9
|
|||||||
; TODO :: empty memory area
|
; TODO :: empty memory area
|
||||||
|
|
||||||
; Address of selected socket
|
; Address of selected socket
|
||||||
sktAddr equ stack_data + 32
|
;sktAddr equ stack_data + 32
|
||||||
; Parameter to checksum routine - data ptr
|
; Parameter to checksum routine - data ptr
|
||||||
checkAdd1 equ stack_data + 36
|
checkAdd1 equ stack_data + 36
|
||||||
; Parameter to checksum routine - 2nd data ptr
|
; Parameter to checksum routine - 2nd data ptr
|
||||||
@ -110,8 +111,8 @@ checkResult equ stack_data + 48
|
|||||||
pseudoHeader equ stack_data + 50
|
pseudoHeader equ stack_data + 50
|
||||||
|
|
||||||
; receive and transmit IP buffer allocation
|
; receive and transmit IP buffer allocation
|
||||||
sockets equ stack_data + 62
|
;sockets equ stack_data + 62
|
||||||
Next_free2 equ sockets + (SOCKETBUFFSIZE * NUM_SOCKETS)
|
Next_free2 equ stack_data + 62;Next_free2 equ sockets + (SOCKETBUFFSIZE * NUM_SOCKETS)
|
||||||
; 1560 byte buffer for rx / tx ethernet packets
|
; 1560 byte buffer for rx / tx ethernet packets
|
||||||
Ether_buffer equ Next_free2
|
Ether_buffer equ Next_free2
|
||||||
Next_free3 equ Ether_buffer + 1518
|
Next_free3 equ Ether_buffer + 1518
|
||||||
@ -128,9 +129,15 @@ last_1hsTick equ queueList + ( 2 * NUMQUEUEENTRIES )
|
|||||||
|
|
||||||
|
|
||||||
;resendQ equ 0x770000
|
;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
|
; simple macro for memory set operation
|
||||||
macro _memset_dw adr,value,amount
|
macro _memset_dw adr,value,amount
|
||||||
{
|
{
|
||||||
@ -151,9 +158,6 @@ macro _memset_dw adr,value,amount
|
|||||||
include "queue.inc"
|
include "queue.inc"
|
||||||
include "eth_drv/ethernet.inc"
|
include "eth_drv/ethernet.inc"
|
||||||
include "ip.inc"
|
include "ip.inc"
|
||||||
include "icmp.inc"
|
|
||||||
include "tcp.inc"
|
|
||||||
include "udp.inc"
|
|
||||||
include "socket.inc"
|
include "socket.inc"
|
||||||
|
|
||||||
;***************************************************************************
|
;***************************************************************************
|
||||||
@ -171,7 +175,8 @@ include "socket.inc"
|
|||||||
stack_init:
|
stack_init:
|
||||||
; Init two address spaces with default values
|
; Init two address spaces with default values
|
||||||
_memset_dw stack_data_start, 0, 0x20000/4
|
_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
|
; Queries initialization
|
||||||
call queueInit
|
call queueInit
|
||||||
@ -931,13 +936,11 @@ stack_get_packet:
|
|||||||
pop edx
|
pop edx
|
||||||
|
|
||||||
push eax ; save address of IP data
|
push eax ; save address of IP data
|
||||||
|
|
||||||
; Get the address of the callers data
|
; Get the address of the callers data
|
||||||
mov edi,[TASK_BASE]
|
mov edi,[TASK_BASE]
|
||||||
add edi,TASKDATA.mem_start
|
add edi,TASKDATA.mem_start
|
||||||
add edx,[edi]
|
add edx,[edi]
|
||||||
mov edi, edx
|
mov edi, edx
|
||||||
|
|
||||||
pop eax
|
pop eax
|
||||||
|
|
||||||
mov ecx, 1500 ; should get the actual number of bytes to write
|
mov ecx, 1500 ; should get the actual number of bytes to write
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -47,11 +47,11 @@ $Revision$
|
|||||||
;
|
;
|
||||||
|
|
||||||
struc UDP_PACKET
|
struc UDP_PACKET
|
||||||
{ .SourcePort dw ? ;+00
|
{ .SourcePort dw ? ;+00
|
||||||
.DestinationPort dw ? ;+02
|
.DestinationPort dw ? ;+02
|
||||||
.Length dw ? ;+04 - Length of (UDP Header + Data)
|
.Length dw ? ;+04 - Length of (UDP Header + Data)
|
||||||
.Checksum dw ? ;+06
|
.Checksum dw ? ;+06
|
||||||
.Data db ? ;+08
|
.Data db ? ;+08
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual at 0
|
virtual at 0
|
||||||
@ -71,103 +71,93 @@ end virtual
|
|||||||
; Free up (or re-use) IP buffer when finished
|
; 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
|
; First validate the header & checksum. Discard buffer if error
|
||||||
; IP Packet UDP Destination Port = local Port
|
|
||||||
; IP Packet SA = Remote IP
|
|
||||||
|
|
||||||
movzx ebx, word [edx + 22] ; get the local port from
|
; Look for a socket where
|
||||||
; the IP packet's UDP header
|
; IP Packet UDP Destination Port = local Port
|
||||||
mov eax, SOCKETBUFFSIZE * NUM_SOCKETS
|
; IP Packet SA = Remote IP
|
||||||
mov ecx, NUM_SOCKETS
|
|
||||||
|
|
||||||
fs1:
|
mov ax, [edx + 20 + UDP_PACKET.DestinationPort] ; get the local port from
|
||||||
sub eax, SOCKETBUFFSIZE
|
; the IP packet's UDP header
|
||||||
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
|
|
||||||
|
|
||||||
; No match, so exit
|
mov ebx, net_sockets_mutex
|
||||||
jmp udprx_001
|
call wait_mutex
|
||||||
|
mov ebx, net_sockets
|
||||||
|
|
||||||
fs_done:
|
.next_socket:
|
||||||
; For dhcp, we must allow any remote server to respond.
|
mov ebx, [ebx + SOCKET.NextPtr]
|
||||||
; I will accept the first incoming response to be the one
|
or ebx, ebx
|
||||||
; I bind to, if the socket is opened with a destination IP address of
|
jz .exit ; No match, so exit
|
||||||
; 255.255.255.255
|
cmp [ebx + SOCKET.LocalPort], ax ; ax will hold the 'wrong' value,
|
||||||
mov ebx, [eax + sockets + 16]
|
; but the comparision is correct
|
||||||
cmp ebx, 0xffffffff
|
jne .next_socket ; Return back if no match
|
||||||
je udprx_002
|
|
||||||
|
|
||||||
mov ebx, [edx + 12] ; get the Source address from the IP packet
|
; For dhcp, we must allow any remote server to respond.
|
||||||
cmp [eax + sockets + 16], ebx
|
; I will accept the first incoming response to be the one
|
||||||
jne udprx_001 ; Quit if the source IP is not valid
|
; 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:
|
mov eax, [edx + IP_PACKET.SourceAddress] ; get the Source address from the IP packet
|
||||||
; OK - we have a valid UDP packet for this socket.
|
cmp [ebx + SOCKET.RemoteIP], ebx
|
||||||
; First, update the sockets remote port number with the incoming msg
|
jne .exit ; Quit if the source IP is not valid
|
||||||
; - 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
|
|
||||||
|
|
||||||
; Now, copy data to socket. We have socket address as [eax + sockets].
|
@@: ; OK - we have a valid UDP packet for this socket.
|
||||||
; We have IP packet in edx
|
; 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
|
; Now, copy data to socket. We have socket address as [eax + sockets].
|
||||||
movzx ecx, byte [edx + 3] ; total length of IP packet. Subtract
|
; We have IP packet in edx
|
||||||
mov ch, byte [edx + 2] ; 20 + 8 gives data length
|
|
||||||
sub ecx, 28
|
|
||||||
|
|
||||||
mov ebx, eax
|
; get # of bytes in ecx
|
||||||
add ebx, sockets ; ebx = address of actual socket
|
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
|
mov eax, [ebx + SOCKET.rxDataCount] ; get # of bytes already in buffer
|
||||||
push eax
|
add [ebx + SOCKET.rxDataCount], ecx ; increment the count of bytes in buffer
|
||||||
|
|
||||||
mov eax, [ebx + 24] ; get # of bytes already in buffer
|
; ecx has count, edx points to data
|
||||||
add [ebx + 24], ecx ; increment the count of bytes in buffer
|
|
||||||
|
|
||||||
; point to the location to store the data
|
add edx, 28 ; edx now points to the data
|
||||||
add ebx, eax
|
lea edi, [ebx + eax + SOCKETHEADERSIZE]
|
||||||
add ebx, SOCKETHEADERSIZE
|
mov esi, edx
|
||||||
|
|
||||||
; ebx = location for first byte, ecx has count,
|
cld
|
||||||
; edx points to data
|
rep movsb ; copy the data across
|
||||||
|
|
||||||
add edx, 28 ; edx now points to the data
|
; flag an event to the application
|
||||||
mov edi, ebx
|
mov eax, [ebx + SOCKET.PID] ; get socket owner PID
|
||||||
mov esi, edx
|
mov ecx, 1
|
||||||
|
mov esi, TASK_DATA + TASKDATA.pid
|
||||||
|
|
||||||
cld
|
.next_pid:
|
||||||
rep movsb ; copy the data across
|
cmp [esi], eax
|
||||||
|
je .found_pid
|
||||||
|
inc ecx
|
||||||
|
add esi, 0x20
|
||||||
|
cmp ecx, [TASK_COUNT]
|
||||||
|
jbe .next_pid
|
||||||
|
|
||||||
; flag an event to the application
|
jmp .exit
|
||||||
pop eax
|
|
||||||
mov ecx,1
|
|
||||||
mov esi,TASK_DATA+TASKDATA.pid
|
|
||||||
|
|
||||||
newsearch:
|
.found_pid:
|
||||||
cmp [esi],eax
|
shl ecx, 8
|
||||||
je foundPID
|
or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK ; stack event
|
||||||
inc ecx
|
|
||||||
add esi,0x20
|
|
||||||
cmp ecx,[TASK_COUNT]
|
|
||||||
jbe newsearch
|
|
||||||
|
|
||||||
foundPID:
|
mov [check_idle_semaphore], 200
|
||||||
shl ecx,8
|
|
||||||
or dword [ecx+SLOT_BASE+APPDATA.event_mask],dword 10000000b ; stack event
|
|
||||||
|
|
||||||
mov [check_idle_semaphore],200
|
.exit:
|
||||||
|
pop eax
|
||||||
udprx_001:
|
call freeBuff ; Discard the packet
|
||||||
pop eax
|
ret
|
||||||
call freeBuff ; Discard the packet
|
endp
|
||||||
ret
|
|
||||||
|
Loading…
Reference in New Issue
Block a user