Fasm: Fixed a bug when building programs with the length of the included file name...
[kolibrios.git] / drivers / sceletone.asm
blobeb67ec83daac3b8a037f0d51065c27f898994786
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; ;;
3 ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
4 ;; Distributed under terms of the GNU General Public License ;;
5 ;; ;;
6 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;driver sceletone
10 format PE DLL native 0.05
11 entry START
13 DEBUG equ 1
15 API_VERSION equ 0 ;debug
17 STRIDE equ 4 ;size of row in devices table
19 SRV_GETVERSION equ 0
21 section '.flat' code readable writable executable
22 include 'proc32.inc'
23 include 'struct.inc'
24 include 'macros.inc'
25 include 'peimport.inc'
27 proc START c, state:dword, cmdline:dword
29 cmp [state], 1
30 jne .exit
31 .entry:
33 push esi
34 if DEBUG
35 mov esi, msgInit
36 invoke SysMsgBoardStr
37 end if
38 call detect
39 pop esi
40 test eax, eax
41 jz .fail
43 invoke RegService, my_service, service_proc
44 ret
45 .fail:
46 .exit:
47 xor eax, eax
48 ret
49 endp
51 proc service_proc stdcall, ioctl:dword
53 mov ebx, [ioctl]
54 mov eax, [ebx+IOCTL.io_code]
55 cmp eax, SRV_GETVERSION
56 jne @F
58 mov eax, [ebx+IOCTL.output]
59 cmp [ebx+IOCTL.out_size], 4
60 jne .fail
61 mov dword [eax], API_VERSION
62 xor eax, eax
63 ret
64 @@:
65 .fail:
66 or eax, -1
67 ret
68 endp
70 proc detect
71 push ebx
72 invoke GetPCIList
73 mov ebx, eax
74 .next_dev:
75 mov eax, [eax+PCIDEV.fd]
76 cmp eax, ebx
77 jz .err
78 mov edx, [eax+PCIDEV.vendor_device_id]
80 mov esi, devices
81 @@:
82 cmp dword [esi], 0
83 jz .next_dev
84 cmp edx, [esi]
85 jz .found
87 add esi, STRIDE
88 jmp @B
90 .found:
91 xor eax, eax
92 inc eax
93 pop ebx
94 ret
95 .err:
96 mov esi, msgFail
97 invoke SysMsgBoardStr
98 xor eax, eax
99 pop ebx
101 endp
103 DEVICE_ID equ 1234; pci device id
104 VENDOR_ID equ 5678; device vendor id
107 ;all initialized data place here
109 align 4
110 devices dd (DEVICE_ID shl 16)+VENDOR_ID
111 dd 0 ;terminator
113 my_service db 'MY_SERVICE',0 ;max 16 chars include zero
115 msgInit db 'detect hardware...',13,10,0
116 msgFail db 'device not found',13,10,0
118 align 4
119 data fixups
120 end data