3e0a804c48
Updated netdrv.inc and pci.inc git-svn-id: svn://kolibrios.org@2935 a494cfbc-eb01-0410-851d-a64ba20cac60
149 lines
3.5 KiB
PHP
149 lines
3.5 KiB
PHP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; ;;
|
|
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
;; ;;
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
;; Version 2, June 1991 ;;
|
|
;; ;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
include 'bus/pci.inc'
|
|
|
|
; Kernel variables
|
|
|
|
PAGESIZE = 4096
|
|
PG_SW = 0x003
|
|
PG_NOCACHE = 0x018
|
|
|
|
|
|
; network driver types
|
|
|
|
NET_TYPE_ETH = 1
|
|
NET_TYPE_SLIP = 2
|
|
|
|
|
|
LAST_IO = 0
|
|
macro set_io addr {
|
|
|
|
if addr = 0
|
|
mov edx, [device.io_addr]
|
|
else if addr = LAST_IO
|
|
else
|
|
add edx, addr - LAST_IO
|
|
end if
|
|
|
|
LAST_IO = addr
|
|
}
|
|
|
|
macro allocate_and_clear dest, size, err {
|
|
|
|
; We need to allocate at least 8 pages, if we want a continuous memory in ram
|
|
push edx
|
|
if (size < 8*4096) & (size > 4096)
|
|
stdcall KernelAlloc, 8*4096
|
|
else
|
|
stdcall KernelAlloc, size
|
|
end if
|
|
pop edx
|
|
|
|
test eax, eax
|
|
jz err
|
|
mov dest, eax ; Save the address to it into the device struct
|
|
mov edi, eax ; look at last part of code!
|
|
|
|
; Release the unused pages (if any)
|
|
if (size < 8*4096) & (size > 4096)
|
|
add eax, (size/4096+1)*4096
|
|
mov ecx, 8-(size/4096+1)
|
|
push edx
|
|
call ReleasePages
|
|
pop edx
|
|
end if
|
|
|
|
; Clear the allocated buffer
|
|
mov ecx, size/4 ; divide by 4 because of DWORD
|
|
xor eax, eax
|
|
rep stosd
|
|
|
|
}
|
|
|
|
struc IOCTL {
|
|
.handle dd ?
|
|
.io_code dd ?
|
|
.input dd ?
|
|
.inp_size dd ?
|
|
.output dd ?
|
|
.out_size dd ?
|
|
}
|
|
|
|
virtual at edx
|
|
IOCTL IOCTL
|
|
end virtual
|
|
|
|
|
|
if used null_op
|
|
align 4
|
|
null_op:
|
|
or eax, -1
|
|
ret
|
|
|
|
end if
|
|
|
|
|
|
macro GetRealAddr { ; input and output is eax
|
|
|
|
push ax
|
|
call GetPgAddr
|
|
and word[esp], PAGESIZE - 1
|
|
or ax, word[esp]
|
|
inc esp
|
|
inc esp
|
|
|
|
}
|
|
|
|
macro NET_DEVICE {
|
|
|
|
.type dd ? ; Type field
|
|
.mtu dd ? ; Maximal Transmission Unit
|
|
.name dd ? ; Ptr to 0 terminated string
|
|
|
|
.unload dd ? ; Ptrs to driver functions
|
|
.reset dd ? ;
|
|
.transmit dd ? ;
|
|
|
|
.bytes_tx dq ? ; Statistics, updated by the driver
|
|
.bytes_rx dq ? ;
|
|
.packets_tx dd ? ;
|
|
.packets_rx dd ? ;
|
|
|
|
.end:
|
|
}
|
|
|
|
|
|
macro ETH_DEVICE {
|
|
NET_DEVICE
|
|
|
|
.set_mode dd ?
|
|
.get_mode dd ?
|
|
|
|
.set_MAC dd ?
|
|
.get_MAC dd ?
|
|
|
|
.mode dd ?
|
|
.mac dp ?
|
|
dp ? ; qword alignment
|
|
|
|
}
|
|
|
|
|
|
|
|
macro SLIP_DEVICE {
|
|
NET_DEVICE
|
|
|
|
.set_mode dd ?
|
|
.get_mode dd ?
|
|
|
|
.mode dd ?
|
|
|
|
} |