NET branch:

- cleanup in stack.inc + re-organisation of device pointers
- i8255x driver stub
- fix in sis900 driver (still untested)


git-svn-id: svn://kolibrios.org@2220 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2011-09-22 04:08:56 +00:00
parent 71ef7e28cd
commit d17706e476
4 changed files with 1212 additions and 66 deletions

File diff suppressed because it is too large Load Diff

View File

@ -436,7 +436,7 @@ probe:
; Get Card Revision ; Get Card Revision
stdcall PciRead8, dword [device.pci_bus], dword [device.pci_dev], 0x08 stdcall PciRead8, dword [device.pci_bus], dword [device.pci_dev], 0x08
mov [pci_revision], al ; save the revision for later use mov [device.pci_revision], al ; save the revision for later use
; Look up through the specific_table ; Look up through the specific_table
mov esi, specific_table mov esi, specific_table
@ -1255,7 +1255,8 @@ transmit:
jl transmit_finish jl transmit_finish
movzx ecx, [device.cur_tx] movzx ecx, [device.cur_tx]
mov ecx, [device.txd+ecx*16] shl ecx, 4
mov ecx, [device.txd+ecx]
;; TODO: check if desc is empty (for example: check for eax, 0x6200000 at [ecx+4] ;; TODO: check if desc is empty (for example: check for eax, 0x6200000 at [ecx+4]
;;; or: count number of available descriptors ;;; or: count number of available descriptors

View File

@ -44,26 +44,6 @@ iglobal
ETH_BROADCAST dp 0xffffffffffff ETH_BROADCAST dp 0xffffffffffff
endg endg
align 4
uglobal
ETH_RUNNING dd ?
endg
;-----------------------------------------------------------------
;
; ETH_init
;
; This function resets all ethernet variables
;
;-----------------------------------------------------------------
macro ETH_init {
mov [ETH_RUNNING], 0
}
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; ETH_input ; ETH_input

View File

@ -176,7 +176,7 @@ align 4
uglobal uglobal
NET_RUNNING dd ? NET_RUNNING dd ?
NET_DRV_LIST rd MAX_NET_DEVICES NET_DRV_LIST rd (MAX_NET_DEVICES + 1) ; device 0 is a link to the default device
endg endg
@ -197,10 +197,9 @@ stack_init:
; Init the network drivers list ; Init the network drivers list
xor eax, eax xor eax, eax
mov edi, NET_RUNNING mov edi, NET_RUNNING
mov ecx, MAX_NET_DEVICES + 1 mov ecx, (MAX_NET_DEVICES + 2)
rep stosd rep stosd
ETH_init
; SLIP_init ; SLIP_init
; PPPOE_init ; PPPOE_init
@ -259,7 +258,7 @@ stack_handler:
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; NET_add_Device: ; NET_add_device:
; ;
; This function is called by the network drivers, ; This function is called by the network drivers,
; to register each running NIC to the kernel ; to register each running NIC to the kernel
@ -271,7 +270,7 @@ stack_handler:
align 4 align 4
NET_add_device: NET_add_device:
DEBUGF 1,"NET_Add_Device: %x\n", ebx DEBUGF 1,"NET_Add_Device: %x\n", ebx ;;; TODO: use mutex to lock net device list
mov eax, [NET_RUNNING] mov eax, [NET_RUNNING]
cmp eax, MAX_NET_DEVICES cmp eax, MAX_NET_DEVICES
@ -280,57 +279,41 @@ NET_add_device:
;---------------------------------- ;----------------------------------
; Check if device is already listed ; Check if device is already listed
mov eax, ebx mov eax, ebx
mov ecx, MAX_NET_DEVICES ; We need to check whole list because a device may be removed without re-organizing list mov ecx, MAX_NET_DEVICES ; We need to check whole list because a device may be removed without re-organizing list
mov edi, NET_DRV_LIST mov edi, NET_DRV_LIST+4
repne scasd ; See if device is already in the list repne scasd ; See if device is already in the list
jz .error jz .error
;---------------------------- ;----------------------------
; Find empty slot in the list ; Find empty slot in the list
xor eax, eax xor eax, eax
mov ecx, MAX_NET_DEVICES mov ecx, MAX_NET_DEVICES
mov edi, NET_DRV_LIST mov edi, NET_DRV_LIST+4
repne scasd repne scasd
jnz .error jnz .error
sub edi, 4 sub edi, 4
cmp [ebx + NET_DEVICE.type], NET_TYPE_ETH
je .ethernet
cmp [ebx + NET_DEVICE.type], NET_TYPE_SLIP
je .slip
DEBUGF 1,"Unknown network device type: %u\n", [ebx + NET_DEVICE.type]
jmp .error
.ethernet:
DEBUGF 1,"Trying to add an ethernet device\n"
inc [ETH_RUNNING] ; Indicate that one more ethernet device is up and running
jmp .add_it
.slip:
DEBUGF 1,"Trying to add a slip device\n"
;;;;
jmp .error
.add_it:
;----------------------------- ;-----------------------------
; Add device to the found slot ; Add device to the found slot
mov [edi], ebx ; add device to list mov [edi], ebx ; add device to list
sub edi, NET_DRV_LIST ; Calculate device number in eax mov eax, edi ; Calculate device number in eax
mov eax, edi ; sub eax, NET_DRV_LIST
shr eax, 2 shr eax, 2
inc [NET_RUNNING] ; Indicate that one more network device is up and running inc [NET_RUNNING] ; Indicate that one more network device is up and running
DEBUGF 1,"Device number: %u\n",eax cmp eax, 1 ; If it's the first network device, try to set it as default
jne @f
push eax
call NET_set_default
pop eax
@@:
DEBUGF 1,"Device number: %u\n", eax
ret ret
.error: .error:
@ -340,13 +323,46 @@ NET_add_device:
;-----------------------------------------------------------------
;
; NET_set_default
;
; API to set the default interface
;
; IN: Device num in eax
; OUT: Device num in eax, -1 on error
;
;-----------------------------------------------------------------
align 4
NET_set_default:
DEBUGF 1,"NET_set_default %x\n", eax
cmp eax, MAX_NET_DEVICES
jge .error
cmp [NET_DRV_LIST+eax*4], 0
je .error
push [NET_DRV_LIST+eax*4]
pop [NET_DRV_LIST]
DEBUGF 1,"Device number %u is now default!\n", eax
ret
.error:
or eax, -1
DEBUGF 2,"Setting default network device failed\n"
ret
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; NET_Remove_Device: ; NET_Remove_Device:
; ;
; This function is called by etwork drivers, ; This function is called by etwork drivers,
; to unregister network devices from the kernel ; to unregister network devices from the kernel
; ; d
; IN: Pointer to device structure in ebx ; IN: Pointer to device structure in ebx
; OUT: eax: -1 on error ; OUT: eax: -1 on error
; ;
@ -357,12 +373,27 @@ NET_remove_device:
cmp [NET_RUNNING], 0 cmp [NET_RUNNING], 0
je .error je .error
cmp [NET_DRV_LIST], ebx
jne @f
mov [NET_DRV_LIST], 0
cmp [NET_RUNNING], 1
je @f
; there are still active devices, find one and make it default
xor eax, eax
mov ecx, MAX_NET_DEVICES
mov edi, NET_DRV_LIST+4
repe scasd
jz @f
push dword [edi-4]
pop [NET_DRV_LIST]
@@:
;---------------------------- ;----------------------------
; Find the driver in the list ; Find the driver in the list
mov eax, ebx mov eax, ebx
mov ecx, MAX_NET_DEVICES mov ecx, MAX_NET_DEVICES
mov edi, NET_DRV_LIST mov edi, NET_DRV_LIST+4
repne scasd repne scasd
jnz .error jnz .error
@ -395,7 +426,7 @@ NET_ptr_to_num:
push ecx push ecx
mov ecx, MAX_NET_DEVICES mov ecx, MAX_NET_DEVICES
mov edi, NET_DRV_LIST mov edi, NET_DRV_LIST+4
.loop: .loop:
cmp ebx, [edi] cmp ebx, [edi]
@ -551,17 +582,19 @@ sys_network:
jmp .return jmp .return
@@: @@:
cmp bh, MAX_NET_DEVICES ; Check if device number exists cmp bh, MAX_NET_DEVICES ; Check if device number exists
jge .doesnt_exist jge .doesnt_exist
mov esi, ebx mov esi, ebx
and esi, 0x0000ff00 and esi, 0x0000ff00
shr esi, 6 shr esi, 6
cmp dword [esi + NET_DRV_LIST], 0 ; check if driver is running cmp dword [esi + NET_DRV_LIST], 0 ; check if driver is running
je .doesnt_exist je .doesnt_exist
test bl, bl ; 0 = Get device type (ethernet/token ring/...)
test bl, bl ; 0 = Get device type (ethernet/token ring/...)
jnz @f jnz @f
xor eax, eax xor eax, eax
@ -605,10 +638,29 @@ sys_network:
jnz @f jnz @f
; ..; ; ..;
xor eax, eax
jmp .return
@@:
dec bl ; 5 = Get driver name
jnz @f
; ..;
xor eax, eax
jmp .return
@@:
dec bl ; 6 = Set default device
jnz @f
mov eax, esi
call NET_set_default
jmp .return
@@: @@:
; ... ; 5 Get driver name
.doesnt_exist: .doesnt_exist:
DEBUGF 1,"sys_network: invalid device/function specified!\n" DEBUGF 1,"sys_network: invalid device/function specified!\n"