2012-07-22 21:47:29 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; 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'
|
2010-05-28 17:40:36 +02:00
|
|
|
|
2010-08-05 16:03:47 +02:00
|
|
|
; Kernel variables
|
|
|
|
|
2012-07-22 22:07:20 +02:00
|
|
|
PAGESIZE = 4096
|
|
|
|
PG_SW = 0x003
|
2010-05-28 17:40:36 +02:00
|
|
|
|
|
|
|
|
2010-07-12 01:13:12 +02:00
|
|
|
; network driver types
|
|
|
|
|
2012-07-22 22:07:20 +02:00
|
|
|
NET_TYPE_ETH = 1
|
|
|
|
NET_TYPE_SLIP = 2
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2010-05-28 17:40:36 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
LAST_IO = 0
|
2012-07-22 22:07:20 +02:00
|
|
|
macro set_io addr {
|
2010-05-28 17:40:36 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
if addr = 0
|
|
|
|
mov edx, [device.io_addr]
|
|
|
|
else if addr = LAST_IO
|
|
|
|
else
|
|
|
|
add edx, addr - LAST_IO
|
|
|
|
end if
|
2010-05-28 17:40:36 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
LAST_IO = addr
|
2010-05-28 17:40:36 +02:00
|
|
|
}
|
|
|
|
|
2012-07-22 22:07:20 +02:00
|
|
|
macro allocate_and_clear dest, size, err {
|
2010-05-28 17:40:36 +02:00
|
|
|
|
|
|
|
; We need to allocate at least 8 pages, if we want a continuous memory in ram
|
2012-07-22 21:47:29 +02:00
|
|
|
push edx
|
2010-05-28 17:40:36 +02:00
|
|
|
if (size < 8*4096) & (size > 4096)
|
2012-07-22 21:47:29 +02:00
|
|
|
stdcall KernelAlloc, 8*4096
|
2010-05-28 17:40:36 +02:00
|
|
|
else
|
2012-07-22 21:47:29 +02:00
|
|
|
stdcall KernelAlloc, size
|
2010-05-28 17:40:36 +02:00
|
|
|
end if
|
2012-07-22 21:47:29 +02:00
|
|
|
pop edx
|
2010-07-16 17:37:50 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
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!
|
2010-05-28 17:40:36 +02:00
|
|
|
|
|
|
|
; Release the unused pages (if any)
|
|
|
|
if (size < 8*4096) & (size > 4096)
|
2012-07-22 21:47:29 +02:00
|
|
|
add eax, (size/4096+1)*4096
|
|
|
|
mov ecx, 8-(size/4096+1)
|
|
|
|
push edx
|
|
|
|
call ReleasePages
|
|
|
|
pop edx
|
2010-05-28 17:40:36 +02:00
|
|
|
end if
|
|
|
|
|
|
|
|
; Clear the allocated buffer
|
2012-07-22 21:47:29 +02:00
|
|
|
mov ecx, size/4 ; divide by 4 because of DWORD
|
|
|
|
xor eax, eax
|
|
|
|
rep stosd
|
2010-07-12 01:13:12 +02:00
|
|
|
|
2010-05-28 17:40:36 +02:00
|
|
|
}
|
|
|
|
|
2012-07-22 22:07:20 +02:00
|
|
|
struc IOCTL {
|
|
|
|
.handle dd ?
|
|
|
|
.io_code dd ?
|
|
|
|
.input dd ?
|
|
|
|
.inp_size dd ?
|
|
|
|
.output dd ?
|
|
|
|
.out_size dd ?
|
2010-05-28 17:40:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual at edx
|
|
|
|
IOCTL IOCTL
|
|
|
|
end virtual
|
|
|
|
|
|
|
|
|
|
|
|
if used null_op
|
|
|
|
align 4
|
|
|
|
null_op:
|
2012-07-22 21:47:29 +02:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2010-05-28 17:40:36 +02:00
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
2012-07-22 22:07:20 +02:00
|
|
|
macro GetRealAddr { ; input and output is eax
|
2010-05-28 17:40:36 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
push ax
|
|
|
|
call GetPgAddr
|
|
|
|
and word[esp], PAGESIZE - 1
|
|
|
|
or ax, word[esp]
|
|
|
|
inc esp
|
|
|
|
inc esp
|
2010-05-28 17:40:36 +02:00
|
|
|
|
2010-06-11 18:44:47 +02:00
|
|
|
}
|
|
|
|
|
2012-07-22 22:07:20 +02:00
|
|
|
macro NET_DEVICE {
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
.type dd ? ; Type field
|
|
|
|
.mtu dd ? ; Maximal Transmission Unit
|
|
|
|
.name dd ? ; Ptr to 0 terminated string
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
.unload dd ? ; Ptrs to driver functions
|
|
|
|
.reset dd ? ;
|
|
|
|
.transmit dd ? ;
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
.bytes_tx dq ? ; Statistics, updated by the driver
|
|
|
|
.bytes_rx dq ? ;
|
|
|
|
.packets_tx dd ? ;
|
|
|
|
.packets_rx dd ? ;
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
.end:
|
2010-07-12 01:13:12 +02:00
|
|
|
}
|
2010-06-11 18:44:47 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
|
2012-07-22 22:07:20 +02:00
|
|
|
macro ETH_DEVICE {
|
|
|
|
NET_DEVICE
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
.set_mode dd ?
|
|
|
|
.get_mode dd ?
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
.set_MAC dd ?
|
|
|
|
.get_MAC dd ?
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
.mode dd ?
|
|
|
|
.mac dp ?
|
|
|
|
dp ? ; qword alignment
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2010-06-11 18:44:47 +02:00
|
|
|
}
|
|
|
|
|
2010-06-21 00:36:52 +02:00
|
|
|
|
|
|
|
|
2012-07-22 22:07:20 +02:00
|
|
|
macro SLIP_DEVICE {
|
2012-07-22 21:47:29 +02:00
|
|
|
NET_DEVICE
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
.set_mode dd ?
|
|
|
|
.get_mode dd ?
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2012-07-22 21:47:29 +02:00
|
|
|
.mode dd ?
|
2010-07-15 20:54:19 +02:00
|
|
|
|
2010-07-27 20:53:38 +02:00
|
|
|
}
|