Updates in RTL8029 and PCNET32 driver.

Moved public data structure for network drivers to netdrv.inc

git-svn-id: svn://kolibrios.org@1492 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2010-06-11 16:44:47 +00:00
parent 04bf87db30
commit 34efef1da5
5 changed files with 538 additions and 760 deletions

View File

@ -102,7 +102,7 @@ include 'fdo.inc'
include 'netdrv.inc' include 'netdrv.inc'
OS_BASE equ 0; OS_BASE equ 0
new_app_base equ 0x60400000 new_app_base equ 0x60400000
PROC_BASE equ OS_BASE+0x0080000 PROC_BASE equ OS_BASE+0x0080000
@ -111,24 +111,11 @@ public service_proc
public version public version
struc ETH_DEVICE { virtual at ebx
; pointers to procedures
.unload dd ? device:
.reset dd ?
.transmit dd ? ETH_DEVICE
.set_MAC dd ?
.get_MAC dd ?
.set_mode dd ?
.get_mode dd ?
; status & variables
.bytes_tx dq ?
.bytes_rx dq ?
.packets_tx dd ?
.packets_rx dd ?
.mode dd ? ; This dword contains cable status (10mbit/100mbit, full/half duplex, auto negotiation or not,..)
.name dd ?
.mac dp ?
; device specific
.rx_buffer dd ? .rx_buffer dd ?
.tx_buffer dd ? .tx_buffer dd ?
@ -152,10 +139,6 @@ struc ETH_DEVICE {
.size = $ - device .size = $ - device
}
virtual at ebx
device ETH_DEVICE
end virtual end virtual
@ -530,17 +513,12 @@ proc service_proc stdcall, ioctl:dword
mov [device.pci_dev], cl mov [device.pci_dev], cl
; Now, it's time to find the base io addres of the PCI device ; Now, it's time to find the base io addres of the PCI device
; TODO: implement check if bus and dev exist on this machine
find_io [device.pci_bus], [device.pci_dev], [device.io_addr] find_io [device.pci_bus], [device.pci_dev], [device.io_addr]
; We've found the io address, find IRQ now ; We've found the io address, find IRQ now
movzx ecx, [device.pci_bus] find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
movzx edx, [device.pci_dev]
stdcall PciRead8, ecx ,edx ,0x3c ; 0x3c is the offset where irq can be found
mov [device.irq_line], al
DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
[device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4

View File

@ -18,7 +18,7 @@
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Revision$ ;$Revision$
format MS COFF format MS COFF
@ -31,51 +31,20 @@ __DEBUG_LEVEL__ equ 1
include 'proc32.inc' include 'proc32.inc'
include 'imports.inc' include 'imports.inc'
include 'fdo.inc' include 'fdo.inc'
include 'netdrv.inc'
OS_BASE equ 0x80000000 OS_BASE equ 0
new_app_base equ 0x0 new_app_base equ 0x60400000
PROC_BASE equ OS_BASE+0x0080000 PROC_BASE equ OS_BASE+0x0080000
; PCI Bus defines
PCI_HEADER_TYPE equ 0x0e ;8 bit
PCI_BASE_ADDRESS_0 equ 0x10 ;32 bit
PCI_BASE_ADDRESS_5 equ 0x24 ;32 bits
PCI_BASE_ADDRESS_SPACE_IO equ 0x01
PCI_VENDOR_ID equ 0x00 ;16 bit
PCI_BASE_ADDRESS_IO_MASK equ 0xFFFFFFFC
struc IOCTL { virtual at ebx
.handle dd ?
.io_code dd ?
.input dd ?
.inp_size dd ?
.output dd ?
.out_size dd ?
}
virtual at 0 device:
IOCTL IOCTL
end virtual
struc ETH_DEVICE { ETH_DEVICE
; pointers to procedures
.unload dd ? .io_addr dd ?
.reset dd ?
.transmit dd ?
.set_MAC dd ?
.get_MAC dd ?
.set_mode dd ?
.get_mode dd ?
; status
.bytes_tx dq ?
.bytes_rx dq ?
.packets_tx dd ?
.packets_rx dd ?
.mode dd ? ; This dword contains cable status (10mbit/100mbit, full/half duplex, auto negotiation or not,..)
.name dd ?
.mac dp ?
; device specific
.io_addr dw ?
.irq_line db ? .irq_line db ?
.pci_bus db ? .pci_bus db ?
.pci_dev db ? .pci_dev db ?
@ -89,19 +58,17 @@ struc ETH_DEVICE {
.bmem dd ? .bmem dd ?
.rmem dd ? .rmem dd ?
.romdata rb 16 .romdata rb 16
.size:
} .size = $ - device
virtual at 0
device ETH_DEVICE
end virtual end virtual
public START public START
public service_proc public service_proc
public version public version
MAX_ne2000 equ 16 ; Max number of devices this driver may handle MAX_DEVICES equ 16 ; Max number of devices this driver may handle
P0_PSTART equ 0x01 P0_PSTART equ 0x01
P0_PSTOP equ 0x02 P0_PSTOP equ 0x02
@ -190,24 +157,6 @@ public version
ISA_MAX_ADDR equ 0x400 ISA_MAX_ADDR equ 0x400
;------------------------------------------------
LAST_IO = 0
macro set_io addr {
if addr = 0
mov dx, [ebp + device.io_addr]
else
add edx, addr - LAST_IO
end if
LAST_IO = addr
}
;-------------------------------------------------
section '.flat' code readable align 16 section '.flat' code readable align 16
@ -218,6 +167,7 @@ section '.flat' code readable align 16
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 4
proc START stdcall, state:dword proc START stdcall, state:dword
cmp [state], 1 cmp [state], 1
@ -239,25 +189,24 @@ endp
;; proc SERVICE_PROC ;; proc SERVICE_PROC
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 4
proc service_proc ;stdcall, ioctl:dword
push ebp
mov edx, [esp+8];[ioctl] align 4
mov eax, [edx+IOCTL.io_code] proc service_proc stdcall, ioctl:dword
mov edx, [ioctl]
mov eax, [IOCTL.io_code]
;------------------------------------------------------ ;------------------------------------------------------
;--------------- ;---------------
cmp eax, 0 ;SRV_GETVERSION cmp eax, 0 ;SRV_GETVERSION
jne @F ;--------------- jne @F ;---------------
cmp [edx+IOCTL.out_size], 4 cmp [IOCTL.out_size], 4
jl .fail jl .fail
mov eax, [edx+IOCTL.output] mov eax, [IOCTL.output]
mov [eax], dword API_VERSION mov [eax], dword API_VERSION
xor eax, eax xor eax, eax
pop ebp
ret 4 ret 4
;------------------------------------------------------ ;------------------------------------------------------
@ -267,14 +216,14 @@ proc service_proc ;stdcall, ioctl:dword
DEBUGF 2,"Checking if device is already listed..\n" DEBUGF 2,"Checking if device is already listed..\n"
mov eax, [edx+IOCTL.input] mov eax, [IOCTL.input]
cmp [edx+IOCTL.inp_size], 3 cmp [IOCTL.inp_size], 3
jl .fail jl .fail
cmp byte [eax], 1 cmp byte [eax], 1
je .pci je .pci
cmp [edx+IOCTL.inp_size], 4 cmp [IOCTL.inp_size], 4
jl .fail jl .fail
cmp byte [eax], 0 cmp byte [eax], 0
je .isa je .isa
@ -283,80 +232,57 @@ proc service_proc ;stdcall, ioctl:dword
.pci: .pci:
mov esi, ne2000_LIST ; check if the device is already listed
mov ecx, [ne2000_DEV]
mov esi, DEVICE_LIST
mov ecx, [DEVICES]
test ecx, ecx test ecx, ecx
jz .firstdevice_pci jz .firstdevice_pci
mov bx , [eax+1]
; mov eax, [IOCTL.input] ; get the pci bus and device numbers
mov ax , [eax+1] ;
.nextdevice: .nextdevice:
lodsd mov ebx, [esi]
cmp bx , word [eax + device.pci_bus] ; compare with pci and device num in ne2000 list cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte)
je find_device_num je .find_devicenum ; Device is already loaded, let's find it's device number
add esi, 4
loop .nextdevice loop .nextdevice
.firstdevice_pci: .firstdevice_pci:
call create_new_struct call create_new_struct
mov eax, [edx+IOCTL.input] ; save the pci bus and device numbers mov eax, [IOCTL.input]
mov cx , [eax+1] ; mov cl , [eax+1]
mov [ebx+device.pci_bus], cl ; mov [device.pci_bus], cl
mov [ebx+device.pci_dev], ch ; mov cl , [eax+2]
mov [device.pci_dev], cl
mov edx, PCI_BASE_ADDRESS_0 ; find the base io address ; Now, it's time to find the base io addres of the PCI device
.sb_reg_check:
movzx eax, byte [ebx+device.pci_bus] ; find_io [device.pci_bus], [device.pci_dev], [device.io_addr]
movzx ecx, byte [ebx+device.pci_dev] ;
;
push edx ecx
stdcall PciRead16, eax ,ecx ,edx ;
pop ecx edx
;
mov [ebx+device.io_addr], ax ;
and eax, PCI_BASE_ADDRESS_IO_MASK ;
test eax, eax ;
jz .sb_inc_reg ;
movzx eax, [ebx+device.io_addr] ;
and eax, PCI_BASE_ADDRESS_SPACE_IO ;
test eax, eax ;
jz .sb_inc_reg ;
;
movzx eax, [ebx+device.io_addr] ;
and eax, PCI_BASE_ADDRESS_IO_MASK ;
mov [ebx+device.io_addr], ax ;
;
jmp .got_io ;
;
.sb_inc_reg: ;
add edx, 4 ;
cmp edx, PCI_BASE_ADDRESS_5 ;
jbe .sb_reg_check ;
.got_io: ; We've found the io address, find IRQ now
movzx eax, byte [ebx+device.pci_bus] ; find IRQ line
movzx ecx, byte [ebx+device.pci_dev] ; find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
push ebx
stdcall PciRead8, eax ,ecx ,0x3c ; 0x3c is the offset where irq can be found
pop ebx
mov byte [ebx+device.irq_line], al ;
jmp .hook jmp .hook
.isa: .isa:
mov esi, ne2000_LIST mov esi, DEVICE_LIST
mov ecx, [ne2000_DEV] mov ecx, [DEVICES]
test ecx, ecx test ecx, ecx
jz .firstdevice_isa jz .firstdevice_isa
mov bx , [eax+1] mov al , [eax+3]
mov dl , [eax+3] movzx edi, word [eax+1]
.nextdevice_isa: .nextdevice_isa:
lodsd mov ebx, [esi]
cmp bx , [eax + device.io_addr] cmp edi, [device.io_addr]
jne .maybenext jne .maybenext
cmp dl , [eax + device.irq_line] cmp al , [device.irq_line]
je find_device_num je find_device_num
.maybenext: .maybenext:
add esi, 4
loop .nextdevice_isa loop .nextdevice_isa
@ -364,31 +290,44 @@ proc service_proc ;stdcall, ioctl:dword
.firstdevice_isa: .firstdevice_isa:
call create_new_struct call create_new_struct
mov eax, [edx+IOCTL.input] mov eax, [IOCTL.input]
mov cx , [eax+1] movzx ecx , word [eax+1]
mov [ebx+device.io_addr], cx mov [device.io_addr], ecx
mov cl, [eax+3] mov cl, [eax+3]
mov [ebx+device.irq_line], cl mov [device.irq_line], cl
.hook: .hook:
DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",[ebx+device.pci_dev]:1,[ebx+device.pci_bus]:1,[ebx+device.irq_line]:1,[ebx+device.io_addr]:4 DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
[device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
call probe ; this function will output in eax call probe ; this function will output in eax
test eax, eax test eax, eax
jnz .err ; If an error occured, exit jnz .err ; If an error occured, exit
mov eax, [ne2000_DEV] mov eax, [DEVICES]
mov [ne2000_LIST+4*eax], ebx mov [DEVICE_LIST+4*eax], ebx
inc [ne2000_DEV] inc [DEVICES]
call EthRegDev ; Register the device to kernel (ebx points to device struct) call EthRegDev ; Register the device to kernel (ebx points to device struct)
cmp eax, -1 cmp eax, -1
jz .err jz .err
pop ebp
ret 4 ret 4
; If the device was already loaded, find the device number and return it in eax
.find_devicenum:
DEBUGF 1,"Trying to find device number of already registered device\n"
mov ebx, eax
call EthStruc2Dev ; This kernel procedure converts a pointer to device struct in ebx
; into a device number in edi
mov eax, edi ; Application wants it in eax instead
DEBUGF 1,"Kernel says: %u\n", eax
ret
.err: .err:
DEBUGF 1,"Failed, removing device structure\n"
stdcall KernelFree, ebx stdcall KernelFree, ebx
jmp .fail jmp .fail
@ -397,7 +336,6 @@ proc service_proc ;stdcall, ioctl:dword
@@: @@:
.fail: .fail:
or eax, -1 or eax, -1
pop ebp
ret 4 ret 4
;------------------------------------------------------ ;------------------------------------------------------
@ -406,7 +344,7 @@ endp
create_new_struct: create_new_struct:
cmp [ne2000_DEV], MAX_ne2000 cmp [DEVICES], MAX_DEVICES
jge .fail jge .fail
push edx push edx
@ -416,12 +354,12 @@ create_new_struct:
jz .fail jz .fail
mov ebx, eax mov ebx, eax
mov dword [ebx+device.reset], reset mov [device.reset], reset
mov dword [ebx+device.transmit], transmit mov [device.transmit], transmit
mov dword [ebx+device.get_MAC], read_mac mov [device.get_MAC], read_mac
mov dword [ebx+device.set_MAC], write_mac mov [device.set_MAC], write_mac
mov dword [ebx+device.unload], unload mov [device.unload], unload
mov dword [ebx+device.name], my_service mov [device.name], my_service
ret ret
@ -458,25 +396,21 @@ unload: ; TODO
;; ;;
;; probe: enables the device and clears the rx buffer ;; probe: enables the device and clears the rx buffer
;; ;;
;; Destroys: eax, ebx, ecx, edx
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
probe: probe:
mov ebp, ebx ;--- mov [device.vendor], VENDOR_NONE
mov [device.bmem], 0
mov [ebp + device.vendor], VENDOR_NONE mov eax,[device.io_addr]
mov [ebp + device.bmem], 0 add eax, NE_ASIC_OFFSET
mov ax, [ebp + device.io_addr] mov [device.asic_base], ax
add ax, NE_ASIC_OFFSET
mov [ebp + device.asic_base], ax
DEBUGF 2,"Trying 16-bit mode\n" DEBUGF 2,"Trying 16-bit mode\n"
or [ebp + device.flags], FLAG_16BIT or FLAG_PIO or [device.flags], FLAG_16BIT or FLAG_PIO
mov [ebp + device.memsize], MEM_32768 mov [device.memsize], MEM_32768
mov [ebp + device.tx_start], 64 mov [device.tx_start], 64
mov [ebp + device.rx_start], TXBUF_SIZE + 64 mov [device.rx_start], TXBUF_SIZE + 64
set_io 0 set_io 0
set_io P0_DCR set_io P0_DCR
@ -492,16 +426,16 @@ probe:
out dx, al out dx, al
mov esi, test_data mov esi, test_data
mov bx, 16384 mov di, 16384
mov cx, 14 mov cx, 14
call eth_pio_write call eth_pio_write
mov bx, 16384 mov si, 16384
mov cx, 14 mov cx, 14
lea edi, [ebp + device.romdata] lea edi, [device.romdata]
call eth_pio_read call eth_pio_read
lea esi, [ebp + device.romdata] lea esi, [device.romdata]
mov edi, test_data mov edi, test_data
mov ecx, 13 mov ecx, 13
@ -511,12 +445,12 @@ probe:
DEBUGF 2,"Trying 8-bit mode\n" DEBUGF 2,"Trying 8-bit mode\n"
mov [ebp + device.flags], FLAG_PIO mov [device.flags], FLAG_PIO
mov [ebp + device.memsize], MEM_16384 mov [device.memsize], MEM_16384
mov [ebp + device.tx_start], 32 mov [device.tx_start], 32
mov [ebp + device.rx_start], TXBUF_SIZE + 32 mov [device.rx_start], TXBUF_SIZE + 32
mov dx, [ebp + device.asic_base] mov dx, [device.asic_base]
add dx, NE_RESET add dx, NE_RESET
in al, dx in al, dx
@ -545,17 +479,17 @@ probe:
out dx, al out dx, al
mov esi, test_data mov esi, test_data
mov bx, 8192 mov di, 8192
mov cx, 14 mov cx, 14
call eth_pio_write call eth_pio_write
mov bx, 8192 mov si, 8192
mov cx, 14 mov cx, 14
lea edi, [ebp + device.romdata] lea edi, [device.romdata]
call eth_pio_read call eth_pio_read
mov esi, test_data mov esi, test_data
lea edi, [ebp + device.romdata] lea edi, [device.romdata]
mov ecx, 13 mov ecx, 13
repz cmpsb repz cmpsb
@ -568,60 +502,52 @@ probe:
ep_set_vendor: ep_set_vendor:
cmp [ebp + device.io_addr], ISA_MAX_ADDR cmp [device.io_addr], ISA_MAX_ADDR
jbe ep_001 jbe ep_001
DEBUGF 2,"Card is using PCI bus\n" DEBUGF 2,"Card is using PCI bus\n"
;;; or [ebp + device.flags], FLAG_16BIT ; or [flags], FLAG_16BIT
ep_001: ep_001:
mov [ebp + device.vendor], VENDOR_NOVELL mov [device.vendor], VENDOR_NOVELL
ep_check_have_vendor: ep_check_have_vendor:
mov ebx, ebp ;----
mov al, [ebp + device.vendor] mov al, [device.vendor]
cmp al, VENDOR_NONE cmp al, VENDOR_NONE
;;;; je rtl8029_exit ; je rtl8029_exit
cmp al, VENDOR_3COM cmp al, VENDOR_3COM
je reset je reset
mov eax, [ebp + device.bmem] mov eax, [device.bmem]
mov [ebp + device.rmem], eax mov [device.rmem], eax
;-- hack (read mac from eeprom ant write it to hardware's register)
mov ebx, ebp
call read_mac call read_mac
push .hack push .hack
sub esp, 6 sub esp, 6
mov edi, esp mov edi, esp
lea esi, [ebp + device.mac] lea esi, [device.mac]
movsd movsd
movsw movsw
jmp write_mac jmp write_mac
.hack: .hack:
;--- hack
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; reset: Place the chip into a virgin state ;; reset: Place the chip into a virgin state
;; ;;
;; Destroys: eax, ebx, ecx, edx
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
reset: reset:
mov ebp, ebx ;---
DEBUGF 2,"Resetting device\n" DEBUGF 2,"Resetting device\n"
; attach int handler ; attach int handler
movzx eax, [ebp+device.irq_line] movzx eax, [device.irq_line]
DEBUGF 1,"Attaching int handler to irq %x\n",eax:1 DEBUGF 1,"Attaching int handler to irq %x\n",eax:1
stdcall AttachIntHandler, eax, int_handler, dword 0 stdcall AttachIntHandler, eax, int_handler, dword 0
@ -632,7 +558,7 @@ reset:
out dx, al out dx, al
set_io P0_DCR set_io P0_DCR
test [ebp + device.flags], FLAG_16BIT test [device.flags], FLAG_16BIT
jz nsr_001 jz nsr_001
mov al, 0x49 mov al, 0x49
@ -644,7 +570,6 @@ nsr_001:
nsr_002: nsr_002:
out dx, al out dx, al
;clear remote bytes count ;clear remote bytes count
set_io 0 set_io 0
@ -671,7 +596,7 @@ nsr_002:
; transmit page stuff ; transmit page stuff
set_io P0_TPSR set_io P0_TPSR
mov al, [ebp + device.tx_start] mov al, [device.tx_start]
out dx, al out dx, al
; set receive control register ;;;; ; set receive control register ;;;;
@ -681,17 +606,17 @@ nsr_002:
; pagestart ; pagestart
set_io P0_PSTART set_io P0_PSTART
mov al, [ebp + device.rx_start] mov al, [device.rx_start]
out dx, al out dx, al
; pagestop ; pagestop
set_io P0_PSTOP set_io P0_PSTOP
mov al, [ebp + device.memsize] mov al, [device.memsize]
out dx, al out dx, al
; page boundary ; page boundary
set_io P0_BOUND set_io P0_BOUND
mov al, [ebp + device.memsize] mov al, [device.memsize]
dec al dec al
out dx, al out dx, al
@ -706,7 +631,7 @@ nsr_002:
out dx, al out dx, al
set_io P1_CURR set_io P1_CURR
mov al, [ebp + device.rx_start] mov al, [device.rx_start]
out dx, al out dx, al
set_io 0 set_io 0
@ -714,7 +639,6 @@ nsr_002:
out dx, al out dx, al
; Read MAC address ; Read MAC address
mov ebx, ebp ;----
call read_mac call read_mac
; clear interupt status ; clear interupt status
@ -739,17 +663,13 @@ nsr_002:
out dx, al out dx, al
; clear packet/byte counters ; clear packet/byte counters
xor eax, eax
lea edi, [ebp+device.bytes_tx] lea edi, [device.bytes_tx]
mov ecx, 6 mov ecx, 6
rep stosd rep stosd
; Indicate that we have successfully reset the card ; Indicate that we have successfully reset the card
DEBUGF 2,"Done!\n" DEBUGF 2,"Done!\n"
xor eax, eax
mov ebx, ebp ;------
ret ret
@ -761,22 +681,23 @@ nsr_002:
; buffer in [esp+4], size in [esp+8], pointer to device struct in ebx ; buffer in [esp+4], size in [esp+8], pointer to device struct in ebx
;*************************************************************************** ;***************************************************************************
; TODO: use a RING-buffer
align 4 align 4
transmit: transmit:
mov ebp, ebx
mov esi, [esp + 4] mov esi, [esp + 4]
mov ecx, [esp + 8] mov ecx, [esp + 8]
DEBUGF 2,"Transmitting packet, buffer:%x, size:%u\n",esi, ecx DEBUGF 2,"Transmitting packet, buffer:%x, size:%u\n",esi, ecx
DEBUGF 2,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",[esi+0]:2,[esi+1]:2,[esi+2]:2,[esi+3]:2,[esi+4]:2,[esi+5]:2,[esi+6]:2,[esi+7]:2,[esi+8]:2,[esi+9]:2,[esi+10]:2,[esi+11]:2,[esi+13]:2,[esi+12]:2 DEBUGF 2,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",[esi+0]:2,[esi+1]:2,[esi+2]:2,[esi+3]:2,[esi+4]:2,[esi+5]:2,[esi+6]:2,[esi+7]:2,[esi+8]:2,[esi+9]:2,[esi+10]:2,[esi+11]:2,[esi+13]:2,[esi+12]:2
cmp dword [esp + 8], ETH_FRAME_LEN cmp ecx, ETH_FRAME_LEN
jg .finish ; packet is too long jg .err ; packet is too long
cmp dword [esp + 8], 60 cmp ecx, 60
jl .finish ; packet is too short jl .err ; packet is too short
xor bl, bl movzx edi, [device.tx_start]
mov bh, [ebp + device.tx_start] shl edi, 8
push cx push cx
call eth_pio_write call eth_pio_write
pop cx pop cx
@ -786,7 +707,7 @@ transmit:
out dx, al out dx, al
set_io P0_TPSR set_io P0_TPSR
mov al, [ebp + device.tx_start] mov al, [device.tx_start]
out dx, al out dx, al
set_io P0_TBCR0 set_io P0_TBCR0
@ -803,15 +724,18 @@ transmit:
DEBUGF 2," - Packet Sent!\n" DEBUGF 2," - Packet Sent!\n"
inc [ebp+device.packets_tx] ; inc [device.packets_tx]
mov eax, [esp + 8] ; Get packet size in eax mov eax, [esp + 8] ; Get packet size in eax
add dword [ebp + device.bytes_tx], eax add dword [device.bytes_tx], eax
adc dword [ebp + device.bytes_tx + 4], 0 adc dword [device.bytes_tx + 4], 0
.finish:
mov ebx, ebp
xor eax, eax
.finish:
xor eax, eax
ret
.err:
or eax, -1
ret ret
@ -826,10 +750,10 @@ int_handler:
DEBUGF 2,"IRQ %x ",eax:2 DEBUGF 2,"IRQ %x ",eax:2
; find pointer of device wich made INT occur ; find pointer of device wich made INT occur
mov esi, ne2000_LIST mov esi, DEVICE_LIST
mov ecx, [ne2000_DEV] mov ecx, [DEVICES]
.nextdevice: .nextdevice:
mov ebp, dword [esi] mov ebx, [esi]
set_io 0 set_io 0
set_io P0_ISR set_io P0_ISR
@ -878,10 +802,10 @@ int_handler:
in al, dx in al, dx
inc al inc al
cmp al, [ebp + device.memsize] cmp al, [device.memsize]
jb .nsp_001 jb .nsp_001
mov al, [ebp + device.rx_start] mov al, [device.rx_start]
.nsp_001: .nsp_001:
mov ch, al mov ch, al
@ -898,10 +822,10 @@ int_handler:
mov al, CMD_PS0 mov al, CMD_PS0
out dx, al out dx, al
cmp cl, [ebp + device.memsize] cmp cl, [device.memsize]
jb .nsp_002 jb .nsp_002
mov cl, [ebp + device.rx_start] mov cl, [device.rx_start]
.nsp_002: .nsp_002:
cmp cl, ch cmp cl, ch
@ -912,18 +836,18 @@ int_handler:
mov [pktoff], ax mov [pktoff], ax
mov al, [ebp + device.flags] mov al, [device.flags]
test al, FLAG_PIO test al, FLAG_PIO
jz .nsp_003 jz .nsp_003
mov bx, word [pktoff] mov si, word [pktoff]
lea edi, [pkthdr] lea edi, [pkthdr]
mov cx, 4 mov cx, 4
call eth_pio_read call eth_pio_read
jmp .nsp_004 jmp .nsp_004
.nsp_003: .nsp_003:
mov edi, [ebp + device.rmem] mov edi, [device.rmem]
movzx eax, word [pktoff] movzx eax, word [pktoff]
add edi, eax add edi, eax
mov eax, [edi] mov eax, [edi]
@ -938,9 +862,9 @@ int_handler:
DEBUGF 2,"Received %u bytes\n",eax DEBUGF 2,"Received %u bytes\n",eax
add dword [ebp + device.bytes_rx], eax ; Update stats add dword [device.bytes_rx], eax ; Update stats
adc dword [ebp + device.bytes_rx + 4], 0 adc dword [device.bytes_rx + 4], 0
inc dword [ebp + device.packets_rx] ; inc dword [device.packets_rx] ;
mov [eth_tmp_len], ax mov [eth_tmp_len], ax
mov dword[size], eax mov dword[size], eax
@ -957,25 +881,24 @@ int_handler:
; Right, we can now get the data ; Right, we can now get the data
xor ebx, ebx movzx esi, [device.memsize]
mov bh , [ebp + device.memsize] sub si , [pktoff]
sub bx , [pktoff]
cmp [eth_tmp_len], bx cmp [eth_tmp_len], si
jbe .nsp_005 jbe .nsp_005
DEBUGF 2,"WRAP!\n" DEBUGF 2,"WRAP!\n"
mov al , [ebp + device.flags] mov al , [device.flags]
test al , FLAG_PIO test al , FLAG_PIO
jz .nsp_006 jz .nsp_006
push ebx push esi
mov cx , bx mov cx , si
mov bx , [pktoff+4] mov si , [pktoff+4]
mov edi, [eth_rx_data_ptr+4] mov edi, [eth_rx_data_ptr+4]
call eth_pio_read call eth_pio_read
pop ebx pop esi
jmp .nsp_007 jmp .nsp_007
.nsp_006: .nsp_006:
@ -984,20 +907,18 @@ int_handler:
.nsp_007: .nsp_007:
xor al, al xor al, al
mov ah, [ebp + device.rx_start] mov ah, [device.rx_start]
mov [pktoff], ax mov [pktoff], ax
add [eth_rx_data_ptr], ebx add [eth_rx_data_ptr], esi
sub [eth_tmp_len], bx sub [eth_tmp_len], si
.nsp_005: .nsp_005:
test [ebp + device.flags], FLAG_PIO test [device.flags], FLAG_PIO
jz .nsp_008 jz .nsp_008
xor ebx, ebx movzx esi, word [pktoff]
mov bx, [pktoff] movzx ecx, word [eth_tmp_len]
xor ecx, ecx
mov cx, [eth_tmp_len]
mov edi, [eth_rx_data_ptr] mov edi, [eth_rx_data_ptr]
call eth_pio_read call eth_pio_read
jmp .nsp_009 jmp .nsp_009
@ -1008,10 +929,10 @@ int_handler:
.nsp_009: .nsp_009:
mov al, [pkthdr+1] mov al, [pkthdr+1]
cmp al, [ebp + device.rx_start] cmp al, [device.rx_start]
jne .nsp_010 jne .nsp_010
mov al, [ebp + device.memsize] mov al, [device.memsize]
.nsp_010: .nsp_010:
set_io 0 set_io 0
@ -1019,10 +940,7 @@ int_handler:
dec al dec al
out dx, al out dx, al
mov ebx, ebp
add esp, 14 add esp, 14
mov ebx, ebp
jmp EthReceiver ; send it to the kernel jmp EthReceiver ; send it to the kernel
.fail: .fail:
@ -1044,8 +962,6 @@ ret
align 4 align 4
write_mac: ; in: mac on stack (6 bytes) write_mac: ; in: mac on stack (6 bytes)
mov ebp, ebx ;---
DEBUGF 1,"Writing MAC: " DEBUGF 1,"Writing MAC: "
set_io 0 set_io 0
@ -1063,8 +979,6 @@ write_mac: ; in: mac on stack (6 bytes)
add esp, 6 add esp, 6
mov ebx, ebp ;---
; Notice this procedure does not ret, but continues to read_mac instead. ; Notice this procedure does not ret, but continues to read_mac instead.
;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;
@ -1075,8 +989,6 @@ write_mac: ; in: mac on stack (6 bytes)
read_mac: read_mac:
mov ebp, ebx ;-----
DEBUGF 1,"Reading MAC: " DEBUGF 1,"Reading MAC: "
; set_io 0 ; set_io 0
@ -1084,7 +996,7 @@ read_mac:
; out dx, al ; out dx, al
; ;
; set_io P1_PAR0 ; set_io P1_PAR0
; lea edi, [ebp + device.mac] ; lea edi, [mac]
; ;
; mov cx, 6 ; mov cx, 6
; .loop: ; .loop:
@ -1097,19 +1009,18 @@ read_mac:
; mov al, CMD_PS0; + CMD_RD2 + CMD_STA ; set page back to 0 ; mov al, CMD_PS0; + CMD_RD2 + CMD_STA ; set page back to 0
; out dx, al ; out dx, al
mov si, 0
mov bx, 0
mov cx, 16 mov cx, 16
lea edi, [ebp + device.romdata] lea edi, [device.romdata]
call eth_pio_read call eth_pio_read
lea esi, [ebp + device.romdata] lea esi, [device.romdata]
lea edi, [ebp + device.mac] lea edi, [device.mac]
mov ecx, 6 mov ecx, 6
.loop: .loop:
movsb movsb
test [ebp + device.flags], FLAG_16BIT test [device.flags], FLAG_16BIT
jz .8bit jz .8bit
inc esi inc esi
.8bit: .8bit:
@ -1117,8 +1028,6 @@ read_mac:
DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",[edi-6]:2,[edi-5]:2,[edi-4]:2,[edi-3]:2,[edi-2]:2,[edi-1]:2 DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",[edi-6]:2,[edi-5]:2,[edi-4]:2,[edi-3]:2,[edi-2]:2,[edi-1]:2
mov ebx, ebp ;---
ret ret
@ -1128,13 +1037,13 @@ read_mac:
; ;
; Description ; Description
; Read a frame from the ethernet card via Programmed I/O ; Read a frame from the ethernet card via Programmed I/O
; src in bx ; src in si
; cnt in cx ; cnt in cx
; dst in edi ; dst in edi
;*************************************************************************** ;***************************************************************************
eth_pio_read: eth_pio_read:
DEBUGF 1,"Eth PIO Read from %x to %x, %u bytes ",bx,edi,cx DEBUGF 1,"Eth PIO Read from %x to %x, %u bytes ",si,edi,cx
set_io 0 set_io 0
mov al, CMD_RD2 + CMD_STA mov al, CMD_RD2 + CMD_STA
@ -1148,11 +1057,10 @@ eth_pio_read:
set_io P0_RBCR1 set_io P0_RBCR1
out dx, al out dx, al
mov al, bl mov ax, si
set_io P0_RSAR0 set_io P0_RSAR0
out dx, al out dx, al
shr ax, 8
mov al, bh
set_io P0_RSAR1 set_io P0_RSAR1
out dx, al out dx, al
@ -1160,9 +1068,9 @@ eth_pio_read:
set_io 0 set_io 0
out dx, al out dx, al
mov dx, [ebp + device.asic_base] mov dx, [device.asic_base]
test [ebp+device.flags], FLAG_16BIT test [device.flags], FLAG_16BIT
jz epr_003 jz epr_003
DEBUGF 1,"in 16-bits mode" DEBUGF 1,"in 16-bits mode"
@ -1209,13 +1117,13 @@ epr_005: ; Wait for Remote DMA Complete
; ;
; Description ; Description
; writes a frame to the ethernet card via Programmed I/O ; writes a frame to the ethernet card via Programmed I/O
; dst in bx ; dst in di
; cnt in cx ; cnt in cx
; src in esi ; src in esi
;*************************************************************************** ;***************************************************************************
eth_pio_write: eth_pio_write:
DEBUGF 1,"Eth PIO Write from %x to %x, %u bytes ",esi,bx,cx DEBUGF 1,"Eth PIO Write from %x to %x, %u bytes ",esi,di,cx
set_io 0 set_io 0
mov al, CMD_RD2 + CMD_STA mov al, CMD_RD2 + CMD_STA
@ -1233,20 +1141,19 @@ eth_pio_write:
mov al, ch mov al, ch
out dx, al out dx, al
mov ax, di
set_io P0_RSAR0 set_io P0_RSAR0
mov al, bl
out dx, al out dx, al
shr ax, 8
set_io P0_RSAR1 set_io P0_RSAR1
mov al, bh
out dx, al out dx, al
set_io 0 set_io 0
mov al, CMD_RD1 + CMD_STA mov al, CMD_RD1 + CMD_STA
out dx, al out dx, al
mov dx, [ebp + device.asic_base] mov dx, [device.asic_base]
test [ebp + device.flags], FLAG_16BIT test [device.flags], FLAG_16BIT
jz epw_003 jz epw_003
DEBUGF 1,"in 16-bits mode" DEBUGF 1,"in 16-bits mode"
@ -1288,7 +1195,7 @@ epw_005: ; Wait for Remote DMA Complete
;all initialized data place here ;all initialized data place here
align 4 align 4
ne2000_DEV dd 0 DEVICES dd 0
version dd (5 shl 16) or (API_VERSION and 0xFFFF) version dd (5 shl 16) or (API_VERSION and 0xFFFF)
my_service db 'RTL8029/ne2000',0 ;max 16 chars include zero my_service db 'RTL8029/ne2000',0 ;max 16 chars include zero
@ -1304,7 +1211,7 @@ include_debug_strings
section '.data' data readable writable align 16 ;place all uninitialized data place here section '.data' data readable writable align 16 ;place all uninitialized data place here
ne2000_LIST rd MAX_ne2000 DEVICE_LIST rd MAX_DEVICES

View File

@ -29,7 +29,7 @@ include 'imports.inc'
include 'fdo.inc' include 'fdo.inc'
include 'netdrv.inc' include 'netdrv.inc'
OS_BASE equ 0; OS_BASE equ 0
new_app_base equ 0x60400000 new_app_base equ 0x60400000
PROC_BASE equ OS_BASE+0x0080000 PROC_BASE equ OS_BASE+0x0080000
@ -38,24 +38,12 @@ public service_proc
public version public version
struc ETH_DEVICE { virtual at ebx
; pointers to procedures
.unload dd ? device:
.reset dd ?
.transmit dd ? ETH_DEVICE
.set_MAC dd ?
.get_MAC dd ?
.set_mode dd ?
.get_mode dd ?
; status & variables
.bytes_tx dq ?
.bytes_rx dq ?
.packets_tx dd ?
.packets_rx dd ?
.mode dd ? ; This dword contains cable status (10mbit/100mbit, full/half duplex, auto negotiation or not,..)
.name dd ?
.mac dp ?
; device specific
.rx_buffer dd ? .rx_buffer dd ?
.tx_buffer dd ? .tx_buffer dd ?
.rx_data_offset dd ? .rx_data_offset dd ?
@ -68,12 +56,9 @@ struc ETH_DEVICE {
.size = $ - device .size = $ - device
}
virtual at ebx
device ETH_DEVICE
end virtual end virtual
; RTL8139 specific defines ; RTL8139 specific defines
MAX_RTL8139 equ 16 ; Max number of devices this driver may handle MAX_RTL8139 equ 16 ; Max number of devices this driver may handle
@ -334,7 +319,7 @@ proc service_proc stdcall, ioctl:dword
jge .fail jge .fail
push edx push edx
stdcall KernelAlloc, dword device.size ; Allocate the buffer for eth_device structure stdcall KernelAlloc, device.size ; Allocate the buffer for eth_device structure
pop edx pop edx
test eax, eax test eax, eax
jz .fail jz .fail
@ -358,18 +343,12 @@ proc service_proc stdcall, ioctl:dword
mov [device.pci_dev], cl mov [device.pci_dev], cl
; Now, it's time to find the base io addres of the PCI device ; Now, it's time to find the base io addres of the PCI device
; TODO: implement check if bus and dev exist on this machine
find_io [device.pci_bus], [device.pci_dev], [device.io_addr] find_io [device.pci_bus], [device.pci_dev], [device.io_addr]
; We've found the io address, find IRQ now ; We've found the io address, find IRQ now
movzx eax, byte [device.pci_bus] find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
movzx ecx, byte [device.pci_dev]
push ebx
stdcall PciRead8, eax ,ecx ,0x3c ; 0x3c is the offset where irq can be found
pop ebx
mov byte [device.irq_line], al
DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
[device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4

View File

@ -112,6 +112,17 @@ macro find_io bus, dev, io {
} }
macro find_irq bus, dev, irq {
push eax edx ecx
movzx ecx, bus
movzx edx, dev
stdcall PciRead8, ecx ,edx ,0x3c ; 0x3c is the offset where irq can be found
mov irq, al
pop ecx edx eax
}
macro make_bus_master bus, dev { macro make_bus_master bus, dev {
@ -164,3 +175,25 @@ macro virt_to_dma { ; input is eax
inc esp inc esp
} }
;struc ETH_DEVICE {
macro ETH_DEVICE {
; pointers to procedures
.unload dd ?
.reset dd ?
.transmit dd ?
.set_MAC dd ?
.get_MAC dd ?
.set_mode dd ?
.get_mode dd ?
; status
.bytes_tx dq ?
.bytes_rx dq ?
.packets_tx dd ?
.packets_rx dd ?
.mode dd ?
.name dd ?
.mac dp ?
}

File diff suppressed because it is too large Load Diff