Rev 2010 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2465 | Serge | 3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
431 | serge | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
214 | serge | 7 | |
8 | ;driver sceletone |
||
9 | |||
10 | format MS COFF |
||
11 | |||
802 | serge | 12 | DEBUG equ 1 |
13 | |||
465 | serge | 14 | API_VERSION equ 0 ;debug |
15 | |||
214 | serge | 16 | include 'proc32.inc' |
281 | serge | 17 | include 'imports.inc' |
214 | serge | 18 | |
19 | struc IOCTL |
||
20 | { .handle dd ? |
||
21 | .io_code dd ? |
||
22 | .input dd ? |
||
23 | .inp_size dd ? |
||
24 | .output dd ? |
||
25 | .out_size dd ? |
||
26 | } |
||
27 | |||
28 | virtual at 0 |
||
29 | IOCTL IOCTL |
||
30 | end virtual |
||
31 | |||
32 | public START |
||
33 | public service_proc |
||
227 | serge | 34 | public version |
214 | serge | 35 | |
465 | serge | 36 | DRV_ENTRY equ 1 |
37 | DRV_EXIT equ -1 |
||
38 | STRIDE equ 4 ;size of row in devices table |
||
214 | serge | 39 | |
465 | serge | 40 | SRV_GETVERSION equ 0 |
41 | |||
214 | serge | 42 | section '.flat' code readable align 16 |
43 | |||
44 | proc START stdcall, state:dword |
||
45 | |||
227 | serge | 46 | cmp [state], 1 |
47 | jne .exit |
||
214 | serge | 48 | .entry: |
227 | serge | 49 | |
214 | serge | 50 | if DEBUG |
51 | mov esi, msgInit |
||
52 | call SysMsgBoardStr |
||
53 | end if |
||
54 | |||
55 | stdcall RegService, my_service, service_proc |
||
465 | serge | 56 | ret |
214 | serge | 57 | .fail: |
58 | .exit: |
||
59 | xor eax, eax |
||
60 | ret |
||
61 | endp |
||
62 | |||
63 | handle equ IOCTL.handle |
||
64 | io_code equ IOCTL.io_code |
||
65 | input equ IOCTL.input |
||
66 | inp_size equ IOCTL.inp_size |
||
67 | output equ IOCTL.output |
||
68 | out_size equ IOCTL.out_size |
||
69 | |||
70 | align 4 |
||
71 | proc service_proc stdcall, ioctl:dword |
||
72 | |||
465 | serge | 73 | mov ebx, [ioctl] |
74 | mov eax, [ebx+io_code] |
||
75 | cmp eax, SRV_GETVERSION |
||
76 | jne @F |
||
214 | serge | 77 | |
465 | serge | 78 | mov eax, [ebx+output] |
79 | cmp [ebx+out_size], 4 |
||
80 | jne .fail |
||
81 | mov [eax], dword API_VERSION |
||
82 | xor eax, eax |
||
83 | ret |
||
84 | @@: |
||
85 | .fail: |
||
86 | or eax, -1 |
||
87 | ret |
||
214 | serge | 88 | endp |
89 | |||
90 | restore handle |
||
91 | restore io_code |
||
92 | restore input |
||
93 | restore inp_size |
||
94 | restore output |
||
95 | restore out_size |
||
96 | |||
97 | align 4 |
||
98 | proc detect |
||
465 | serge | 99 | locals |
100 | last_bus dd ? |
||
101 | endl |
||
214 | serge | 102 | |
465 | serge | 103 | xor eax, eax |
104 | mov [bus], eax |
||
105 | inc eax |
||
214 | serge | 106 | call PciApi |
465 | serge | 107 | cmp eax, -1 |
214 | serge | 108 | je .err |
109 | |||
465 | serge | 110 | mov [last_bus], eax |
214 | serge | 111 | |
112 | .next_bus: |
||
465 | serge | 113 | and [devfn], 0 |
214 | serge | 114 | .next_dev: |
115 | stdcall PciRead32, [bus], [devfn], dword 0 |
||
465 | serge | 116 | test eax, eax |
117 | jz .next |
||
118 | cmp eax, -1 |
||
119 | je .next |
||
214 | serge | 120 | |
465 | serge | 121 | mov edi, devices |
214 | serge | 122 | @@: |
465 | serge | 123 | mov ebx, [edi] |
124 | test ebx, ebx |
||
125 | jz .next |
||
214 | serge | 126 | |
465 | serge | 127 | cmp eax, ebx |
128 | je .found |
||
129 | |||
214 | serge | 130 | add edi, STRIDE |
131 | jmp @B |
||
465 | serge | 132 | .next: |
133 | inc [devfn] |
||
134 | cmp [devfn], 256 |
||
135 | jb .next_dev |
||
136 | mov eax, [bus] |
||
137 | inc eax |
||
138 | mov [bus], eax |
||
139 | cmp eax, [last_bus] |
||
140 | jna .next_bus |
||
141 | xor eax, eax |
||
142 | ret |
||
214 | serge | 143 | .found: |
465 | serge | 144 | xor eax, eax |
214 | serge | 145 | inc eax |
465 | serge | 146 | ret |
214 | serge | 147 | .err: |
148 | xor eax, eax |
||
149 | ret |
||
150 | endp |
||
151 | |||
465 | serge | 152 | DEVICE_ID equ 1234; pci device id |
153 | VENDOR_ID equ 5678; device vendor id |
||
214 | serge | 154 | |
155 | |||
156 | ;all initialized data place here |
||
157 | |||
158 | align 4 |
||
465 | serge | 159 | devices dd (DEVICE_ID shl 16)+VENDOR_ID |
160 | dd 0 ;terminator |
||
214 | serge | 161 | |
465 | serge | 162 | version dd (5 shl 16) or (API_VERSION and 0xFFFF) |
227 | serge | 163 | |
214 | serge | 164 | my_service db 'MY_SERVICE',0 ;max 16 chars include zero |
165 | |||
166 | msgInit db 'detect hardware...',13,10,0 |
||
167 | msgPCI db 'PCI accsess not supported',13,10,0 |
||
168 | msgFail db 'device not found',13,10,0 |
||
169 | |||
170 | section '.data' data readable writable align 16 |
||
171 | |||
172 | ;all uninitialized data place here |
||
173 |