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