2010-10-01 11:21:55 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2012-03-15 13:41:29 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
|
2010-10-01 11:21:55 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
;driver sceletone
|
|
|
|
|
|
|
|
format MS COFF
|
|
|
|
|
|
|
|
DEBUG equ 1
|
|
|
|
|
|
|
|
API_VERSION equ 0 ;debug
|
|
|
|
|
|
|
|
include 'proc32.inc'
|
|
|
|
include 'imports.inc'
|
|
|
|
|
|
|
|
struc IOCTL
|
|
|
|
{ .handle dd ?
|
|
|
|
.io_code dd ?
|
|
|
|
.input dd ?
|
|
|
|
.inp_size dd ?
|
|
|
|
.output dd ?
|
|
|
|
.out_size dd ?
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual at 0
|
|
|
|
IOCTL IOCTL
|
|
|
|
end virtual
|
|
|
|
|
|
|
|
public START
|
|
|
|
public service_proc
|
|
|
|
public version
|
|
|
|
|
|
|
|
DRV_ENTRY equ 1
|
|
|
|
DRV_EXIT equ -1
|
|
|
|
STRIDE equ 4 ;size of row in devices table
|
|
|
|
|
|
|
|
SRV_GETVERSION equ 0
|
|
|
|
|
|
|
|
section '.flat' code readable align 16
|
|
|
|
|
|
|
|
proc START stdcall, state:dword
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
cmp [state], 1
|
|
|
|
jne .exit
|
2010-10-01 11:21:55 +02:00
|
|
|
.entry:
|
|
|
|
|
|
|
|
if DEBUG
|
2013-05-11 14:38:27 +02:00
|
|
|
mov esi, msgInit
|
|
|
|
call SysMsgBoardStr
|
2010-10-01 11:21:55 +02:00
|
|
|
end if
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
stdcall RegService, my_service, service_proc
|
|
|
|
ret
|
2010-10-01 11:21:55 +02:00
|
|
|
.fail:
|
|
|
|
.exit:
|
2013-05-11 14:38:27 +02:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-10-01 11:21:55 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
handle equ IOCTL.handle
|
|
|
|
io_code equ IOCTL.io_code
|
|
|
|
input equ IOCTL.input
|
|
|
|
inp_size equ IOCTL.inp_size
|
|
|
|
output equ IOCTL.output
|
|
|
|
out_size equ IOCTL.out_size
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc service_proc stdcall, ioctl:dword
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
mov ebx, [ioctl]
|
|
|
|
mov eax, [ebx+io_code]
|
|
|
|
cmp eax, SRV_GETVERSION
|
|
|
|
jne @F
|
|
|
|
|
|
|
|
mov eax, [ebx+output]
|
|
|
|
cmp [ebx+out_size], 4
|
|
|
|
jne .fail
|
|
|
|
mov [eax], dword API_VERSION
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-10-01 11:21:55 +02:00
|
|
|
@@:
|
|
|
|
.fail:
|
2013-05-11 14:38:27 +02:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2010-10-01 11:21:55 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
restore handle
|
|
|
|
restore io_code
|
|
|
|
restore input
|
|
|
|
restore inp_size
|
|
|
|
restore output
|
|
|
|
restore out_size
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc detect
|
|
|
|
locals
|
|
|
|
last_bus dd ?
|
|
|
|
endl
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
xor eax, eax
|
|
|
|
mov [bus], eax
|
|
|
|
inc eax
|
|
|
|
call PciApi
|
|
|
|
cmp eax, -1
|
|
|
|
je .err
|
2010-10-01 11:21:55 +02:00
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
mov [last_bus], eax
|
2010-10-01 11:21:55 +02:00
|
|
|
|
|
|
|
.next_bus:
|
2013-05-11 14:38:27 +02:00
|
|
|
and [devfn], 0
|
2010-10-01 11:21:55 +02:00
|
|
|
.next_dev:
|
2013-05-11 14:38:27 +02:00
|
|
|
stdcall PciRead32, [bus], [devfn], dword 0
|
|
|
|
test eax, eax
|
|
|
|
jz .next
|
|
|
|
cmp eax, -1
|
|
|
|
je .next
|
2010-10-01 11:21:55 +02:00
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
mov edi, devices
|
2010-10-01 11:21:55 +02:00
|
|
|
@@:
|
2013-05-11 14:38:27 +02:00
|
|
|
mov ebx, [edi]
|
|
|
|
test ebx, ebx
|
|
|
|
jz .next
|
2010-10-01 11:21:55 +02:00
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
cmp eax, ebx
|
|
|
|
je .found
|
2010-10-01 11:21:55 +02:00
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
add edi, STRIDE
|
|
|
|
jmp @B
|
2010-10-01 11:21:55 +02:00
|
|
|
.next:
|
2013-05-11 14:38:27 +02:00
|
|
|
inc [devfn]
|
|
|
|
cmp [devfn], 256
|
|
|
|
jb .next_dev
|
|
|
|
mov eax, [bus]
|
|
|
|
inc eax
|
|
|
|
mov [bus], eax
|
|
|
|
cmp eax, [last_bus]
|
|
|
|
jna .next_bus
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-10-01 11:21:55 +02:00
|
|
|
.found:
|
2013-05-11 14:38:27 +02:00
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
ret
|
2010-10-01 11:21:55 +02:00
|
|
|
.err:
|
2013-05-11 14:38:27 +02:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-10-01 11:21:55 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
DEVICE_ID equ 1234; pci device id
|
|
|
|
VENDOR_ID equ 5678; device vendor id
|
|
|
|
|
|
|
|
|
|
|
|
;all initialized data place here
|
|
|
|
|
|
|
|
align 4
|
|
|
|
devices dd (DEVICE_ID shl 16)+VENDOR_ID
|
|
|
|
dd 0 ;terminator
|
|
|
|
|
|
|
|
version dd (5 shl 16) or (API_VERSION and 0xFFFF)
|
|
|
|
|
|
|
|
my_service db 'MY_SERVICE',0 ;max 16 chars include zero
|
|
|
|
|
|
|
|
msgInit db 'detect hardware...',13,10,0
|
|
|
|
msgPCI db 'PCI accsess not supported',13,10,0
|
|
|
|
msgFail db 'device not found',13,10,0
|
|
|
|
|
|
|
|
section '.data' data readable writable align 16
|
|
|
|
|
|
|
|
;all uninitialized data place here
|
|
|
|
|