2007-03-26 16:18:08 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2006-11-20 10:06:00 +03:00
|
|
|
|
|
|
|
;driver sceletone
|
|
|
|
|
|
|
|
format MS COFF
|
|
|
|
|
2008-06-09 16:12:09 +04:00
|
|
|
DEBUG equ 1
|
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
API_VERSION equ 0 ;debug
|
|
|
|
|
2006-11-20 10:06:00 +03:00
|
|
|
include 'proc32.inc'
|
2007-01-19 06:58:46 +03:00
|
|
|
include 'imports.inc'
|
2006-11-20 10:06:00 +03:00
|
|
|
|
|
|
|
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
|
2006-12-02 11:18:48 +03:00
|
|
|
public version
|
2006-11-20 10:06:00 +03:00
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
DRV_ENTRY equ 1
|
|
|
|
DRV_EXIT equ -1
|
|
|
|
STRIDE equ 4 ;size of row in devices table
|
2006-11-20 10:06:00 +03:00
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
SRV_GETVERSION equ 0
|
2006-11-20 10:06:00 +03:00
|
|
|
|
|
|
|
section '.flat' code readable align 16
|
|
|
|
|
|
|
|
proc START stdcall, state:dword
|
|
|
|
|
2006-12-02 11:18:48 +03:00
|
|
|
cmp [state], 1
|
|
|
|
jne .exit
|
2006-11-20 10:06:00 +03:00
|
|
|
.entry:
|
2006-12-02 11:18:48 +03:00
|
|
|
|
2006-11-20 10:06:00 +03:00
|
|
|
if DEBUG
|
|
|
|
mov esi, msgInit
|
|
|
|
call SysMsgBoardStr
|
|
|
|
end if
|
|
|
|
|
|
|
|
stdcall RegService, my_service, service_proc
|
2007-04-18 10:37:14 +04:00
|
|
|
ret
|
2006-11-20 10:06:00 +03:00
|
|
|
.fail:
|
|
|
|
.exit:
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
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
|
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
mov ebx, [ioctl]
|
|
|
|
mov eax, [ebx+io_code]
|
|
|
|
cmp eax, SRV_GETVERSION
|
|
|
|
jne @F
|
2006-11-20 10:06:00 +03:00
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
mov eax, [ebx+output]
|
|
|
|
cmp [ebx+out_size], 4
|
|
|
|
jne .fail
|
|
|
|
mov [eax], dword API_VERSION
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
.fail:
|
|
|
|
or eax, -1
|
|
|
|
ret
|
2006-11-20 10:06:00 +03:00
|
|
|
endp
|
|
|
|
|
|
|
|
restore handle
|
|
|
|
restore io_code
|
|
|
|
restore input
|
|
|
|
restore inp_size
|
|
|
|
restore output
|
|
|
|
restore out_size
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc detect
|
2007-04-18 10:37:14 +04:00
|
|
|
locals
|
|
|
|
last_bus dd ?
|
|
|
|
endl
|
2006-11-20 10:06:00 +03:00
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
xor eax, eax
|
|
|
|
mov [bus], eax
|
|
|
|
inc eax
|
2006-11-20 10:06:00 +03:00
|
|
|
call PciApi
|
2007-04-18 10:37:14 +04:00
|
|
|
cmp eax, -1
|
2006-11-20 10:06:00 +03:00
|
|
|
je .err
|
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
mov [last_bus], eax
|
2006-11-20 10:06:00 +03:00
|
|
|
|
|
|
|
.next_bus:
|
2007-04-18 10:37:14 +04:00
|
|
|
and [devfn], 0
|
2006-11-20 10:06:00 +03:00
|
|
|
.next_dev:
|
|
|
|
stdcall PciRead32, [bus], [devfn], dword 0
|
2007-04-18 10:37:14 +04:00
|
|
|
test eax, eax
|
|
|
|
jz .next
|
|
|
|
cmp eax, -1
|
|
|
|
je .next
|
2006-11-20 10:06:00 +03:00
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
mov edi, devices
|
2006-11-20 10:06:00 +03:00
|
|
|
@@:
|
2007-04-18 10:37:14 +04:00
|
|
|
mov ebx, [edi]
|
|
|
|
test ebx, ebx
|
|
|
|
jz .next
|
|
|
|
|
|
|
|
cmp eax, ebx
|
|
|
|
je .found
|
2006-11-20 10:06:00 +03:00
|
|
|
|
|
|
|
add edi, STRIDE
|
|
|
|
jmp @B
|
2007-04-18 10:37:14 +04:00
|
|
|
.next:
|
|
|
|
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
|
2006-11-20 10:06:00 +03:00
|
|
|
.found:
|
2007-04-18 10:37:14 +04:00
|
|
|
xor eax, eax
|
2006-11-20 10:06:00 +03:00
|
|
|
inc eax
|
2007-04-18 10:37:14 +04:00
|
|
|
ret
|
2006-11-20 10:06:00 +03:00
|
|
|
.err:
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
DEVICE_ID equ 1234; pci device id
|
|
|
|
VENDOR_ID equ 5678; device vendor id
|
2006-11-20 10:06:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
;all initialized data place here
|
|
|
|
|
|
|
|
align 4
|
2007-04-18 10:37:14 +04:00
|
|
|
devices dd (DEVICE_ID shl 16)+VENDOR_ID
|
|
|
|
dd 0 ;terminator
|
2006-11-20 10:06:00 +03:00
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
version dd (5 shl 16) or (API_VERSION and 0xFFFF)
|
2006-12-02 11:18:48 +03:00
|
|
|
|
2006-11-20 10:06:00 +03:00
|
|
|
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
|
|
|
|
|