2013-05-28 19:34:26 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2014-01-17 13:51:32 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; RTL8029/ne2000 driver for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; based on RTL8029.asm driver for menuetos ;;
|
|
|
|
;; and realtek8029.asm for SolarOS by Eugen Brasoveanu ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
|
|
|
;; with help from CleverMouse ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
format PE DLL native
|
|
|
|
entry START
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
CURRENT_API = 0x0200
|
|
|
|
COMPATIBLE_API = 0x0100
|
|
|
|
API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
MAX_DEVICES = 16
|
|
|
|
|
|
|
|
DEBUG = 1
|
|
|
|
__DEBUG__ = 1
|
2013-08-05 13:16:08 +02:00
|
|
|
__DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
section '.flat' readable writable executable
|
|
|
|
|
2014-01-17 13:51:32 +01:00
|
|
|
include '../struct.inc'
|
|
|
|
include '../macros.inc'
|
2013-05-28 19:34:26 +02:00
|
|
|
include '../proc32.inc'
|
|
|
|
include '../fdo.inc'
|
2014-07-18 14:23:41 +02:00
|
|
|
include '../netdrv_pe.inc'
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
struct device ETH_DEVICE
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
io_addr dd ?
|
|
|
|
irq_line db ?
|
|
|
|
pci_bus dd ?
|
|
|
|
pci_dev dd ?
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
flags db ?
|
|
|
|
vendor db ?
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
memsize db ?
|
|
|
|
rx_start db ?
|
|
|
|
tx_start db ?
|
|
|
|
bmem dd ?
|
|
|
|
rmem dd ?
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
ends
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
P0_COMMAND = 0x00
|
|
|
|
P0_PSTART = 0x01
|
|
|
|
P0_PSTOP = 0x02
|
|
|
|
P0_BOUND = 0x03
|
|
|
|
P0_TSR = 0x04
|
|
|
|
P0_TPSR = 0x04
|
|
|
|
P0_TBCR0 = 0x05
|
|
|
|
P0_TBCR1 = 0x06
|
|
|
|
P0_ISR = 0x07
|
|
|
|
P0_RSAR0 = 0x08
|
|
|
|
P0_RSAR1 = 0x09
|
|
|
|
P0_RBCR0 = 0x0A
|
|
|
|
P0_RBCR1 = 0x0B
|
|
|
|
P0_RSR = 0x0C
|
|
|
|
P0_RCR = 0x0C
|
|
|
|
P0_TCR = 0x0D
|
|
|
|
P0_DCR = 0x0E
|
|
|
|
P0_IMR = 0x0F
|
|
|
|
|
|
|
|
P1_COMMAND = 0x00
|
|
|
|
P1_PAR0 = 0x01
|
|
|
|
P1_PAR1 = 0x02
|
|
|
|
P1_PAR2 = 0x03
|
|
|
|
P1_PAR3 = 0x04
|
|
|
|
P1_PAR4 = 0x05
|
|
|
|
P1_PAR5 = 0x06
|
|
|
|
P1_CURR = 0x07
|
|
|
|
P1_MAR0 = 0x08
|
|
|
|
|
|
|
|
CMD_PS0 = 0x00 ; Page 0 select
|
|
|
|
CMD_PS1 = 0x40 ; Page 1 select
|
|
|
|
CMD_PS2 = 0x80 ; Page 2 select
|
|
|
|
CMD_RD2 = 0x20 ; Remote DMA control
|
|
|
|
CMD_RD1 = 0x10
|
|
|
|
CMD_RD0 = 0x08
|
|
|
|
CMD_TXP = 0x04 ; transmit packet
|
|
|
|
CMD_STA = 0x02 ; start
|
|
|
|
CMD_STP = 0x01 ; stop
|
|
|
|
|
|
|
|
CMD_RDMA_READ = 001b shl 3
|
|
|
|
CMD_RDMA_WRITE = 010b shl 3
|
|
|
|
CMD_RDMA_SEND_PACKET = 011b shl 3
|
|
|
|
CMD_RDMA_ABORT = 100b shl 3 ; really is 1xx, Abort/Complete Remote DMA
|
|
|
|
; RDMA_MASK = 111b shl 3 ; internal, mask
|
|
|
|
|
|
|
|
RCR_MON = 0x20 ; monitor mode
|
|
|
|
|
|
|
|
DCR_FT1 = 0x40
|
|
|
|
DCR_LS = 0x08 ; Loopback select
|
|
|
|
DCR_WTS = 0x01 ; Word transfer select
|
|
|
|
|
|
|
|
ISR_PRX = 0x01 ; successful recv
|
|
|
|
ISR_PTX = 0x02 ; successful xmit
|
|
|
|
ISR_RXE = 0x04 ; receive error
|
|
|
|
ISR_TXE = 0x08 ; transmit error
|
|
|
|
ISR_OVW = 0x10 ; Overflow
|
|
|
|
ISR_CNT = 0x20 ; Counter overflow
|
|
|
|
ISR_RDC = 0x40 ; Remote DMA complete
|
|
|
|
ISR_RST = 0x80 ; reset
|
|
|
|
|
|
|
|
IRQ_MASK = ISR_PRX ;+ ISR_PTX ;+ ISR_RDC + ISR_PTX + ISR_TXE
|
|
|
|
|
|
|
|
RSTAT_PRX = 1 shl 0 ; successful recv
|
|
|
|
RSTAT_CRC = 1 shl 1 ; CRC error
|
|
|
|
RSTAT_FAE = 1 shl 2 ; Frame alignment error
|
|
|
|
RSTAT_OVER = 1 shl 3 ; FIFO overrun
|
|
|
|
|
|
|
|
TXBUF_SIZE = 6
|
|
|
|
RXBUF_END = 32
|
|
|
|
PAGE_SIZE = 256
|
|
|
|
|
|
|
|
ETH_ZLEN = 60
|
|
|
|
ETH_FRAME_LEN = 1514
|
|
|
|
|
|
|
|
FLAG_PIO = 1 shl 0
|
|
|
|
FLAG_16BIT = 1 shl 1
|
|
|
|
|
|
|
|
VENDOR_NONE = 0
|
|
|
|
VENDOR_WD = 1
|
|
|
|
VENDOR_NOVELL = 2
|
|
|
|
VENDOR_3COM = 3
|
|
|
|
|
|
|
|
NE_ASIC = 0x10
|
|
|
|
NE_RESET = 0x0F ; Used to reset card
|
|
|
|
NE_DATA = 0x00 ; Used to read/write NIC mem
|
|
|
|
|
|
|
|
MEM_8k = 32
|
|
|
|
MEM_16k = 64
|
|
|
|
MEM_32k = 128
|
|
|
|
|
|
|
|
ISA_MAX_ADDR = 0x400
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; proc START ;;
|
|
|
|
;; ;;
|
|
|
|
;; (standard driver proc) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
proc START c, reason:dword, cmdline:dword
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
cmp [reason], DRV_ENTRY
|
|
|
|
jne .fail
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
DEBUGF 2,"Loading driver\n"
|
|
|
|
invoke RegService, my_service, service_proc
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
2014-07-18 14:23:41 +02:00
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
.fail:
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; proc SERVICE_PROC ;;
|
|
|
|
;; ;;
|
|
|
|
;; (standard driver proc) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
align 4
|
|
|
|
proc service_proc stdcall, ioctl:dword
|
|
|
|
|
|
|
|
mov edx, [ioctl]
|
2014-01-17 16:07:07 +01:00
|
|
|
mov eax, [edx + IOCTL.io_code]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
;------------------------------------------------------
|
|
|
|
;---------------
|
|
|
|
cmp eax, 0 ;SRV_GETVERSION
|
|
|
|
jne @F ;---------------
|
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
cmp [edx + IOCTL.out_size], 4
|
2013-05-28 19:34:26 +02:00
|
|
|
jb .fail
|
2014-01-17 16:07:07 +01:00
|
|
|
mov eax, [edx + IOCTL.output]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov [eax], dword API_VERSION
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
;------------------------------------------------------
|
|
|
|
@@: ;---------
|
|
|
|
cmp eax, 1 ;SRV_HOOK
|
|
|
|
jne @F ;---------
|
|
|
|
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Checking if device is already listed..\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
mov eax, [edx + IOCTL.input]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
cmp [edx + IOCTL.inp_size], 3
|
2013-05-28 19:34:26 +02:00
|
|
|
jb .fail
|
|
|
|
cmp byte [eax], 1
|
|
|
|
je .pci
|
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
cmp [edx + IOCTL.inp_size], 4
|
2013-05-28 19:34:26 +02:00
|
|
|
jb .fail
|
|
|
|
cmp byte [eax], 0
|
|
|
|
je .isa
|
|
|
|
|
|
|
|
jmp .fail
|
|
|
|
|
|
|
|
.pci:
|
|
|
|
|
|
|
|
; check if the device is already listed
|
|
|
|
|
|
|
|
mov esi, device_list
|
|
|
|
mov ecx, [devices]
|
|
|
|
test ecx, ecx
|
|
|
|
jz .firstdevice_pci
|
|
|
|
|
|
|
|
mov ax, [eax+1] ; get the pci bus and device numbers
|
|
|
|
.nextdevice:
|
|
|
|
mov ebx, [esi]
|
2014-07-18 14:23:41 +02:00
|
|
|
cmp al, byte[ebx + device.pci_bus]
|
2013-05-28 19:34:26 +02:00
|
|
|
jne @f
|
2014-07-18 14:23:41 +02:00
|
|
|
cmp ah, byte[ebx + device.pci_dev]
|
2013-05-28 19:34:26 +02:00
|
|
|
je .find_devicenum ; Device is already loaded, let's find it's device number
|
|
|
|
@@:
|
|
|
|
add esi, 4
|
|
|
|
loop .nextdevice
|
|
|
|
|
|
|
|
.firstdevice_pci:
|
|
|
|
call create_new_struct
|
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
mov eax, [edx + IOCTL.input]
|
2013-05-28 19:34:26 +02:00
|
|
|
movzx ecx, byte[eax+1]
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.pci_bus], ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
movzx ecx, byte[eax+2]
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.pci_dev], ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Now, it's time to find the base io addres of the PCI device
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev]
|
|
|
|
mov [ebx + device.io_addr], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; We've found the io address, find IRQ now
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line
|
|
|
|
mov [ebx + device.irq_line], al
|
2013-05-28 19:34:26 +02:00
|
|
|
jmp .hook
|
|
|
|
|
|
|
|
.isa:
|
|
|
|
mov esi, device_list
|
|
|
|
mov ecx, [devices]
|
|
|
|
test ecx, ecx
|
|
|
|
jz .firstdevice_isa
|
|
|
|
movzx edi, word [eax+1]
|
2014-06-14 12:34:31 +02:00
|
|
|
mov al, [eax+3]
|
2013-05-28 19:34:26 +02:00
|
|
|
.nextdevice_isa:
|
|
|
|
mov ebx, [esi]
|
2014-07-18 14:23:41 +02:00
|
|
|
cmp edi, [ebx + device.io_addr]
|
2013-05-28 19:34:26 +02:00
|
|
|
jne .maybenext
|
2014-07-18 14:23:41 +02:00
|
|
|
cmp al, [ebx + device.irq_line]
|
2013-05-28 19:34:26 +02:00
|
|
|
je find_device_num
|
|
|
|
.maybenext:
|
|
|
|
add esi, 4
|
|
|
|
loop .nextdevice_isa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.firstdevice_isa:
|
|
|
|
call create_new_struct
|
|
|
|
|
2014-01-17 16:07:07 +01:00
|
|
|
mov eax, [edx + IOCTL.input]
|
2014-06-14 12:34:31 +02:00
|
|
|
movzx ecx, word[eax+1]
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.io_addr], ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
mov cl, [eax+3]
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.irq_line], cl
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.hook:
|
2014-07-18 14:23:41 +02:00
|
|
|
DEBUGF 1,"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]:8
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
call probe ; this function will output in eax
|
|
|
|
test eax, eax
|
|
|
|
jnz .err ; If an error occured, exit
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
DEBUGF 2,"Initialised OK\n"
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
mov eax, [devices]
|
|
|
|
mov [device_list+4*eax], ebx
|
|
|
|
inc [devices]
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.type], NET_TYPE_ETH
|
|
|
|
invoke NetRegDev
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
cmp eax, -1
|
|
|
|
jz .err
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
; If the device was already loaded, find the device number and return it in eax
|
|
|
|
|
|
|
|
.find_devicenum:
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Trying to find device number of already registered device\n"
|
2014-07-18 14:23:41 +02:00
|
|
|
invoke NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
; into a device number in edi
|
|
|
|
mov eax, edi ; Application wants it in eax instead
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Kernel says: %u\n", eax
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.err:
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 2, "Failed, removing device structure\n"
|
2014-07-18 14:23:41 +02:00
|
|
|
invoke KernelFree, ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
jmp .fail
|
|
|
|
|
|
|
|
;------------------------------------------------------
|
|
|
|
@@:
|
|
|
|
.fail:
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
;------------------------------------------------------
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
create_new_struct:
|
|
|
|
|
|
|
|
cmp [devices], MAX_DEVICES
|
|
|
|
jae .fail
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
allocate_and_clear ebx, sizeof.device, .fail ; Allocate the buffer for device structure
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.reset], reset
|
|
|
|
mov [ebx + device.transmit], transmit
|
|
|
|
mov [ebx + device.unload], unload
|
|
|
|
mov [ebx + device.name], my_service
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
.fail:
|
|
|
|
add esp, 4 ; return to caller of 'hook'
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
find_device_num:
|
|
|
|
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Trying to find device number of already registered device\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ebx, eax
|
2014-07-18 14:23:41 +02:00
|
|
|
invoke NetPtrToNum ; 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
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Kernel says: %u\n", eax
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
|
|
|
|
;; ;;
|
|
|
|
;; Actual Hardware dependent code starts here ;;
|
|
|
|
;; ;;
|
|
|
|
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
|
|
|
|
|
|
|
|
|
|
|
|
unload: ; TODO
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;; probe: enables the device and clears the rx buffer
|
|
|
|
;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
probe:
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.vendor], VENDOR_NONE
|
|
|
|
mov [ebx + device.bmem], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Trying 16-bit mode\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.flags], FLAG_16BIT + FLAG_PIO
|
|
|
|
mov [ebx + device.memsize], MEM_32k
|
|
|
|
mov [ebx + device.tx_start], 64
|
|
|
|
mov [ebx + device.rx_start], TXBUF_SIZE + 64
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], P0_DCR
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, DCR_WTS + DCR_FT1 + DCR_LS ; word transfer select +
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_PSTART
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, MEM_16k
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_PSTOP
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, MEM_32k
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
mov esi, my_service
|
|
|
|
mov di, 16384
|
|
|
|
mov cx, 14
|
|
|
|
call PIO_write
|
|
|
|
|
|
|
|
mov si, 16384
|
|
|
|
mov cx, 14
|
|
|
|
sub esp, 16
|
|
|
|
mov edi, esp
|
|
|
|
call PIO_read
|
|
|
|
|
|
|
|
mov esi, esp
|
|
|
|
add esp, 16
|
|
|
|
mov edi, my_service
|
|
|
|
mov ecx, 13
|
|
|
|
repe cmpsb
|
|
|
|
je ep_set_vendor
|
|
|
|
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "16-bit mode failed\n"
|
|
|
|
DEBUGF 1, "Trying 8-bit mode\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.flags], FLAG_PIO
|
|
|
|
mov [ebx + device.memsize], MEM_16k
|
|
|
|
mov [ebx + device.tx_start], 32
|
|
|
|
mov [ebx + device.rx_start], TXBUF_SIZE + 32
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], NE_ASIC + NE_RESET
|
2013-05-28 19:34:26 +02:00
|
|
|
in al, dx
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
in al, 0x84
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_RD2 + CMD_STP
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_RCR
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, RCR_MON
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_DCR
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, DCR_FT1 + DCR_LS
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_PSTART
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, MEM_8k
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_PSTOP
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, MEM_16k
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
mov esi, my_service
|
|
|
|
mov di, 8192
|
|
|
|
mov cx, 14
|
|
|
|
call PIO_write
|
|
|
|
|
|
|
|
mov si, 8192
|
|
|
|
mov cx, 14
|
|
|
|
sub esp, 16
|
|
|
|
mov edi, esp
|
|
|
|
call PIO_read
|
|
|
|
|
|
|
|
mov esi, my_service
|
|
|
|
mov edi, esp
|
|
|
|
add esp, 16
|
|
|
|
mov ecx, 13
|
|
|
|
repe cmpsb
|
|
|
|
je ep_set_vendor
|
|
|
|
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 2, "This is not a valid ne2000 device!\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
ep_set_vendor:
|
|
|
|
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Mode ok\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
cmp [ebx + device.io_addr], ISA_MAX_ADDR
|
2013-05-28 19:34:26 +02:00
|
|
|
jbe .isa
|
|
|
|
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Card is using PCI bus\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.vendor], VENDOR_NOVELL ;;; FIXME
|
2013-05-28 19:34:26 +02:00
|
|
|
jmp ep_check_have_vendor
|
|
|
|
|
|
|
|
.isa:
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Card is using ISA bus\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.vendor], VENDOR_NOVELL
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
ep_check_have_vendor:
|
|
|
|
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
mov al, [ebx + device.vendor]
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp al, VENDOR_NONE
|
|
|
|
; je exit
|
|
|
|
|
|
|
|
cmp al, VENDOR_3COM
|
|
|
|
je reset
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
mov eax, [ebx + device.bmem]
|
|
|
|
mov [ebx + device.rmem], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;; reset: Place the chip into a virgin state
|
|
|
|
;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
reset:
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Resetting device\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; attach int handler
|
2014-07-18 14:23:41 +02:00
|
|
|
movzx eax, [ebx + device.irq_line]
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Attaching int handler to irq %x\n", eax:1
|
2014-07-18 14:23:41 +02:00
|
|
|
invoke AttachIntHandler, eax, int_handler, ebx
|
2013-08-05 13:16:08 +02:00
|
|
|
test eax, eax
|
|
|
|
jnz @f
|
|
|
|
DEBUGF 2, "Could not attach int handler!\n"
|
2014-07-18 14:23:41 +02:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2013-08-05 13:16:08 +02:00
|
|
|
@@:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Stop card + DMA
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
; set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_PS0 + CMD_RDMA_ABORT + CMD_STP
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; initialize DCR
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_DCR
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, DCR_FT1 + DCR_LS
|
2014-07-18 14:23:41 +02:00
|
|
|
test [ebx + device.flags], FLAG_16BIT
|
2013-05-28 19:34:26 +02:00
|
|
|
jz @f
|
|
|
|
or al, DCR_WTS ; word transfer select
|
|
|
|
@@:
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; clear remote bytes count
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_RBCR0
|
2013-05-28 19:34:26 +02:00
|
|
|
xor al, al
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_RBCR1
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; initialize Receive configuration register (until all init is done)
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_RCR
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, 0x20 ; monitor mode
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; transmit configuration register to monitor mode (until all ini is done)
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_TCR
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, 2 ; internal loopback
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; clear interupt status
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_ISR
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, 0xff
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; clear IRQ mask ;;;;; CHECKME ;;;;;
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_IMR
|
2013-05-28 19:34:26 +02:00
|
|
|
xor al, al
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; set transmit pointer
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_TPSR
|
|
|
|
mov al, [ebx + device.tx_start]
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; set pagestart pointer
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_PSTART
|
|
|
|
mov al, [ebx + device.rx_start]
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; set pagestop pointer
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_PSTOP
|
|
|
|
mov al, [ebx + device.memsize]
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; set boundary pointer
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_BOUND
|
|
|
|
mov al, [ebx + device.memsize]
|
2013-05-28 19:34:26 +02:00
|
|
|
dec al
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; set curr pointer
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_PS1 ;+ CMD_RD2 + CMD_STP ; page 1, stop mode
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P1_CURR
|
|
|
|
mov al, [ebx + device.rx_start]
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_PS0 ;+ CMD_RD2 + CMD_STA ; go to page 0, start mode
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; Read MAC address and set it to registers
|
|
|
|
call read_mac
|
|
|
|
push .macret
|
|
|
|
sub esp, 6
|
2014-07-18 14:23:41 +02:00
|
|
|
lea esi, [ebx + device.mac]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov edi, esp
|
|
|
|
movsd
|
|
|
|
movsw
|
|
|
|
jmp write_mac
|
|
|
|
.macret:
|
|
|
|
|
|
|
|
; set IRQ mask
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], P0_IMR
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, IRQ_MASK
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; start mode
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_STA
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; clear transmit control register
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_TCR
|
2013-05-28 19:34:26 +02:00
|
|
|
xor al, al ; no loopback
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; set receive control register ;;;;
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_RCR
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, 4 ; accept broadcast
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; clear packet/byte counters
|
|
|
|
xor eax, eax
|
2014-07-18 14:23:41 +02:00
|
|
|
lea edi, [ebx + device.bytes_tx]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ecx, 6
|
|
|
|
rep stosd
|
|
|
|
|
|
|
|
; Set the mtu, kernel will be able to send now
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.mtu], ETH_FRAME_LEN
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Set link state to unknown
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [ebx + device.state], ETH_LINK_UNKNOWN
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Indicate that we have successfully reset the card
|
|
|
|
xor eax, eax
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Done!\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;***************************************************************************
|
|
|
|
; Function
|
|
|
|
; transmit
|
|
|
|
; buffer in [esp+4], size in [esp+8], pointer to device struct in ebx
|
|
|
|
;***************************************************************************
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
proc transmit stdcall buffer_ptr, buffer_size
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
pushf
|
|
|
|
cli
|
|
|
|
|
|
|
|
mov esi, [buffer_ptr]
|
|
|
|
mov ecx, [buffer_size]
|
|
|
|
DEBUGF 1, "Transmitting packet, buffer:%x, size:%u\n", esi, ecx
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
|
2013-05-28 19:34:26 +02:00
|
|
|
[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 ecx, ETH_FRAME_LEN
|
2014-07-18 14:23:41 +02:00
|
|
|
ja .err ; packet is too long
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp ecx, ETH_ZLEN
|
2014-07-18 14:23:41 +02:00
|
|
|
jb .err ; packet is too short
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
movzx edi, [ebx + device.tx_start]
|
2013-05-28 19:34:26 +02:00
|
|
|
shl edi, 8
|
|
|
|
push cx
|
|
|
|
call PIO_write
|
|
|
|
pop cx
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
; set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_PS0 + CMD_RD2 + CMD_STA
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_TPSR
|
|
|
|
mov al, [ebx + device.tx_start]
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_TBCR0
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, cl
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_TBCR1
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, ch
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_PS0 + CMD_TXP + CMD_RD2 + CMD_STA
|
|
|
|
out dx, al
|
|
|
|
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Packet Sent!\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
inc [ebx + device.packets_tx]
|
|
|
|
mov eax, [buffer_size]
|
|
|
|
add dword[ebx + device.bytes_tx], eax
|
|
|
|
adc dword[ebx + device.bytes_tx + 4], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
invoke KernelFree, [buffer_ptr]
|
|
|
|
popf
|
2013-05-28 19:34:26 +02:00
|
|
|
xor eax, eax
|
2014-07-18 14:23:41 +02:00
|
|
|
ret
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-07 20:33:19 +02:00
|
|
|
.err:
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 2, "Transmit error!\n"
|
2014-07-18 14:23:41 +02:00
|
|
|
invoke KernelFree, [buffer_ptr]
|
|
|
|
popf
|
2013-12-08 15:34:08 +01:00
|
|
|
or eax, -1
|
2014-07-18 14:23:41 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
endp
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;
|
|
|
|
; Interrupt handler
|
|
|
|
;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
align 4
|
|
|
|
int_handler:
|
|
|
|
|
|
|
|
push ebx esi edi
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "INT\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; find pointer of device wich made INT occur
|
|
|
|
|
|
|
|
mov ecx, [devices]
|
|
|
|
test ecx, ecx
|
|
|
|
jz .nothing
|
|
|
|
mov esi, device_list
|
|
|
|
.nextdevice:
|
|
|
|
mov ebx, [esi]
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
; set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_PS0
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_ISR
|
2013-05-28 19:34:26 +02:00
|
|
|
in al, dx
|
|
|
|
test al, al
|
|
|
|
jnz .got_it
|
|
|
|
.continue:
|
|
|
|
add esi, 4
|
|
|
|
dec ecx
|
|
|
|
jnz .nextdevice
|
|
|
|
.nothing:
|
|
|
|
pop edi esi ebx
|
|
|
|
xor eax, eax
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
.got_it:
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Device=%x status=%x\n", ebx, eax:2
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
push ebx
|
2014-07-18 14:23:41 +02:00
|
|
|
.rx_loop:
|
2013-05-28 19:34:26 +02:00
|
|
|
test al, ISR_PRX ; packet received ok ?
|
|
|
|
jz .no_rx
|
2014-07-18 14:23:41 +02:00
|
|
|
test [ebx + device.flags], FLAG_PIO
|
2013-05-28 19:34:26 +02:00
|
|
|
jz .no_rx ; FIXME: Only PIO mode supported for now
|
|
|
|
|
|
|
|
; allocate a buffer
|
2014-07-18 14:23:41 +02:00
|
|
|
invoke KernelAlloc, ETH_FRAME_LEN
|
2013-05-28 19:34:26 +02:00
|
|
|
test eax, eax
|
2014-07-18 14:23:41 +02:00
|
|
|
jz .rx_fail_2
|
|
|
|
|
|
|
|
; Push return address and packet ptr to stack
|
|
|
|
pushd .no_rx
|
|
|
|
pushd 0 ; Reserve some space for the packet size
|
2013-05-28 19:34:26 +02:00
|
|
|
push eax
|
|
|
|
|
|
|
|
; read offset for current packet from device
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], P0_BOUND ; boundary ptr is offset to next packet we need to read.
|
2013-05-28 19:34:26 +02:00
|
|
|
in al, dx
|
|
|
|
inc al
|
2014-07-18 14:23:41 +02:00
|
|
|
cmp al, [ebx + device.memsize]
|
2013-05-28 19:34:26 +02:00
|
|
|
jb @f
|
2014-07-18 14:23:41 +02:00
|
|
|
mov al, [ebx + device.rx_start]
|
2013-05-28 19:34:26 +02:00
|
|
|
@@:
|
|
|
|
mov ch, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_PS1
|
|
|
|
out dx, al
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P1_CURR
|
|
|
|
in al, dx ; get current page in cl
|
2013-05-28 19:34:26 +02:00
|
|
|
mov cl, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P1_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_PS0
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
cmp cl, [ebx + device.memsize]
|
2013-05-28 19:34:26 +02:00
|
|
|
jb @f
|
2014-07-18 14:23:41 +02:00
|
|
|
mov cl, [ebx + device.rx_start]
|
2013-05-28 19:34:26 +02:00
|
|
|
@@:
|
|
|
|
|
|
|
|
cmp cl, ch
|
2014-07-18 14:23:41 +02:00
|
|
|
je .rx_fail
|
2013-05-28 19:34:26 +02:00
|
|
|
movzx esi, ch ; we are using 256 byte pages
|
|
|
|
shl esi, 8 ; esi now holds the offset for current packet
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
; Get packet header in ecx
|
|
|
|
push ecx ; reserve 4 bytes on stack to put packet header in
|
2013-05-28 19:34:26 +02:00
|
|
|
mov edi, esp
|
|
|
|
mov cx, 4
|
|
|
|
call PIO_read
|
2014-07-18 14:23:41 +02:00
|
|
|
mov ecx, [esp]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; check if packet is ok
|
|
|
|
test ecx, RSTAT_PRX
|
2014-07-18 14:23:41 +02:00
|
|
|
jz .rx_fail_3
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; calculate packet length in ecx
|
|
|
|
shr ecx, 16
|
|
|
|
sub ecx, 4 ; CRC doesnt count as data byte
|
2014-07-18 14:23:41 +02:00
|
|
|
mov [esp + 8], ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; check if packet size is ok
|
|
|
|
cmp ecx, ETH_ZLEN
|
2014-07-18 14:23:41 +02:00
|
|
|
jb .rx_fail_3
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp ecx, ETH_FRAME_LEN
|
2014-07-18 14:23:41 +02:00
|
|
|
ja .rx_fail_3
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; update stats
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Received %u bytes\n", ecx
|
2014-07-18 14:23:41 +02:00
|
|
|
add dword[ebx + device.bytes_rx], ecx
|
|
|
|
adc dword[ebx + device.bytes_rx + 4], 0
|
|
|
|
inc [ebx + device.packets_rx]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; update read and write pointers
|
|
|
|
add esi, 4
|
|
|
|
mov edi, [esp + 4]
|
|
|
|
|
|
|
|
; now check if we can read all data at once (if we cross the end boundary, we need to wrap back to the beginning)
|
|
|
|
xor eax, eax
|
2014-07-18 14:23:41 +02:00
|
|
|
mov ah, [ebx + device.memsize]
|
2013-05-28 19:34:26 +02:00
|
|
|
sub eax, esi
|
|
|
|
cmp ecx, eax ; eax = number of bytes till end of buffer, ecx = bytes we need to read
|
|
|
|
jbe .no_wrap
|
|
|
|
|
|
|
|
; Read first part
|
|
|
|
sub ecx, eax
|
|
|
|
push ecx
|
|
|
|
mov ecx, eax
|
|
|
|
call PIO_read ; Read the data
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
; update pointers for second read
|
2013-05-28 19:34:26 +02:00
|
|
|
add edi, ecx
|
|
|
|
pop ecx
|
2014-07-18 14:23:41 +02:00
|
|
|
movzx esi, [ebx + device.rx_start]
|
2013-05-28 19:34:26 +02:00
|
|
|
shl esi, 8
|
|
|
|
|
|
|
|
; now read second part (or only part)
|
|
|
|
.no_wrap:
|
|
|
|
call PIO_read ; Read the data
|
|
|
|
|
|
|
|
; update boundary pointer
|
|
|
|
pop eax
|
|
|
|
mov al, ah
|
2014-07-18 14:23:41 +02:00
|
|
|
cmp al, [ebx + device.rx_start]
|
2013-05-28 19:34:26 +02:00
|
|
|
jne @f
|
2014-07-18 14:23:41 +02:00
|
|
|
mov al, [ebx + device.memsize]
|
2013-05-28 19:34:26 +02:00
|
|
|
@@:
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], P0_BOUND
|
2013-05-28 19:34:26 +02:00
|
|
|
dec al
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; now send the data to the kernel
|
2014-07-18 14:23:41 +02:00
|
|
|
jmp [Eth_input]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
.rx_fail_3:
|
2013-05-28 19:34:26 +02:00
|
|
|
add esp, 4
|
2014-07-18 14:23:41 +02:00
|
|
|
.rx_fail:
|
|
|
|
add esp, 12
|
|
|
|
.rx_fail_2:
|
|
|
|
DEBUGF 2, "Error on receive\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
.no_rx:
|
|
|
|
pop ebx
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "done\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], P0_ISR
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, 0xff
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
pop edi esi ebx
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Write MAC address ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
align 4
|
|
|
|
write_mac: ; in: mac on stack (6 bytes)
|
|
|
|
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Writing MAC\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_PS1; + CMD_RD2 + CMD_STP
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P1_PAR0
|
2013-05-28 19:34:26 +02:00
|
|
|
mov esi, esp
|
|
|
|
mov cx, 6
|
|
|
|
@@:
|
|
|
|
lodsb
|
|
|
|
out dx, al
|
|
|
|
inc dx
|
|
|
|
loopw @r
|
|
|
|
|
|
|
|
add esp, 6
|
|
|
|
|
|
|
|
; Notice this procedure does not ret, but continues to read_mac instead.
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Read MAC address ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
read_mac:
|
|
|
|
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Reading MAC\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
xor esi, esi
|
|
|
|
mov cx, 16
|
|
|
|
sub esp, 16
|
|
|
|
mov edi, esp
|
|
|
|
call PIO_read
|
|
|
|
|
|
|
|
mov esi, esp
|
|
|
|
add esp, 16
|
2014-07-18 14:23:41 +02:00
|
|
|
lea edi, [ebx + device.mac]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ecx, 6
|
|
|
|
.loop:
|
|
|
|
movsb
|
2014-07-18 14:23:41 +02:00
|
|
|
test [ebx + device.flags], FLAG_16BIT
|
2013-05-28 19:34:26 +02:00
|
|
|
jz .8bit
|
|
|
|
inc esi
|
|
|
|
.8bit:
|
|
|
|
loop .loop
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "MAC=%x-%x-%x-%x-%x-%x\n",\
|
2014-07-18 14:23:41 +02:00
|
|
|
[ebx + device.mac]:2,[ebx + device.mac+1]:2,[ebx + device.mac+2]:2,[ebx + device.mac+3]:2,[ebx + device.mac+4]:2,[ebx + device.mac+5]:2
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
;***************************************************************************
|
|
|
|
;
|
|
|
|
; PIO_read
|
|
|
|
;
|
|
|
|
; Description
|
|
|
|
; Read a frame from the ethernet card via Programmed I/O
|
|
|
|
; src in si
|
|
|
|
; cnt in cx
|
|
|
|
; dst in edi
|
|
|
|
;***************************************************************************
|
|
|
|
PIO_read:
|
|
|
|
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "PIO Read from %x to %x, %u bytes ", si, edi, cx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
; stop DMA + start
|
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
; set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_RD2 + CMD_STA
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
; Request confirmation of end of DMA transfer
|
|
|
|
set_io [ebx + device.io_addr], P0_ISR
|
|
|
|
mov al, ISR_RDC
|
|
|
|
out dx, al
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
; set length of data we're interested in
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_RBCR0
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, cl
|
|
|
|
out dx, al
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_RBCR1
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, ch
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; set offset of what we want to read
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_RSAR0
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ax, si
|
|
|
|
out dx, al
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_RSAR1
|
2013-05-28 19:34:26 +02:00
|
|
|
shr ax, 8
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
; start DMA read
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_RD0 + CMD_STA
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], NE_ASIC
|
|
|
|
test [ebx + device.flags], FLAG_16BIT
|
2013-05-28 19:34:26 +02:00
|
|
|
jz .8bits
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "(16-bit mode)\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
shr cx, 1 ; note that if the number was odd, carry flag will be set
|
|
|
|
pushf
|
|
|
|
.16bits:
|
|
|
|
in ax, dx
|
|
|
|
stosw
|
|
|
|
loopw .16bits
|
|
|
|
popf
|
2014-07-18 14:23:41 +02:00
|
|
|
jnc wait_dma_done
|
|
|
|
in al, dx
|
|
|
|
stosb
|
|
|
|
jmp wait_dma_done
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.8bits:
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "(8-bit mode)\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
.8bits_:
|
|
|
|
in al, dx
|
|
|
|
stosb
|
|
|
|
loopw .8bits_
|
2014-07-18 14:23:41 +02:00
|
|
|
jmp wait_dma_done
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;***************************************************************************
|
|
|
|
;
|
|
|
|
; PIO_write
|
|
|
|
;
|
|
|
|
; Description
|
|
|
|
; writes a frame to the ethernet card via Programmed I/O
|
|
|
|
; dst in di
|
|
|
|
; cnt in cx
|
|
|
|
; src in esi
|
|
|
|
;***************************************************************************
|
|
|
|
PIO_write:
|
|
|
|
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "Eth PIO Write from %x to %x, %u bytes ", esi, di, cx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
; Stop DMA + start
|
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
; set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_RD2 + CMD_STA
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
; Request confirmation of end of DMA transfer
|
|
|
|
set_io [ebx + device.io_addr], P0_ISR
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, ISR_RDC
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
; Program number of bytes we want to write
|
|
|
|
set_io [ebx + device.io_addr], P0_RBCR0
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, cl
|
|
|
|
out dx, al
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_RBCR1
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, ch
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
; Program where we want to write
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ax, di
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_RSAR0
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, al
|
|
|
|
shr ax, 8
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], P0_RSAR1
|
2013-05-28 19:34:26 +02:00
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
; Set the DMA to write
|
|
|
|
set_io [ebx + device.io_addr], P0_COMMAND
|
2013-05-28 19:34:26 +02:00
|
|
|
mov al, CMD_RD1 + CMD_STA
|
|
|
|
out dx, al
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
set_io [ebx + device.io_addr], NE_ASIC
|
|
|
|
test [ebx + device.flags], FLAG_16BIT
|
2013-05-28 19:34:26 +02:00
|
|
|
jz .8_bit
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "(16-bit mode)\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
shr cx, 1 ; note that if the number was odd, carry flag will be set
|
|
|
|
pushf ; save the flags for later
|
|
|
|
.16bit:
|
|
|
|
lodsw
|
|
|
|
out dx, ax
|
|
|
|
loopw .16bit
|
|
|
|
popf
|
2014-07-18 14:23:41 +02:00
|
|
|
jnc wait_dma_done
|
|
|
|
lodsb
|
|
|
|
out dx, al
|
|
|
|
jmp wait_dma_done
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.8_bit:
|
2013-08-05 13:16:08 +02:00
|
|
|
DEBUGF 1, "(8-bit mode)\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
.8_bit_:
|
|
|
|
lodsb
|
|
|
|
out dx, al
|
|
|
|
loopw .8_bit_
|
2014-07-18 14:23:41 +02:00
|
|
|
jmp wait_dma_done
|
|
|
|
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
wait_dma_done:
|
|
|
|
|
|
|
|
set_io [ebx + device.io_addr], 0
|
|
|
|
set_io [ebx + device.io_addr], P0_ISR
|
|
|
|
.dmawait:
|
|
|
|
in al, dx
|
|
|
|
test al, ISR_RDC ; Remote DMA Complete
|
|
|
|
jz .dmawait
|
2013-05-28 19:34:26 +02:00
|
|
|
; and al, not ISR_RDC
|
|
|
|
; out dx, al ; clear the bit
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
; End of code
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
data fixups
|
|
|
|
end data
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
include '../peimport.inc'
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
my_service db 'RTL8029', 0 ; max 16 chars include zero
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-18 14:23:41 +02:00
|
|
|
;sz_8029 db 'Realtek 8029', 0
|
|
|
|
;sz_8019 db 'Realtek 8019', 0
|
|
|
|
;sz_8019as db 'Realtek 8019AS', 0
|
|
|
|
;sz_ne2k db 'ne2000', 0
|
|
|
|
;sz_dp8390 db 'DP8390', 0
|
|
|
|
|
|
|
|
include_debug_strings ; All data wich FDO uses will be included here
|
|
|
|
|
|
|
|
align 4
|
|
|
|
devices dd 0
|
|
|
|
device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|