Subversion Repositories Kolibri OS

Rev

Rev 1161 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1159 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
;driver sceletone
9
 
10
format MS COFF
11
 
12
DEBUG        equ 1
13
 
14
API_VERSION     equ 0  ;debug
15
 
16
include 'proc32.inc'
17
include 'imports.inc'
18
 
19
OS_BASE         equ 0;
20
new_app_base    equ 0x60400000
21
PROC_BASE       equ OS_BASE+0x0080000
22
 
23
struc IOCTL
24
{  .handle      dd ?
25
   .io_code     dd ?
26
   .input       dd ?
27
   .inp_size    dd ?
28
   .output      dd ?
29
   .out_size    dd ?
30
}
31
 
32
virtual at 0
33
  IOCTL IOCTL
34
end virtual
35
 
36
public START
37
public service_proc
38
public version
39
 
40
DRV_ENTRY    equ 1
41
DRV_EXIT     equ -1
42
STRIDE       equ 4      ;size of row in devices table
43
 
44
SRV_GETVERSION  equ 0
45
 
46
section '.flat' code readable align 16
47
 
48
proc START stdcall, state:dword
49
 
50
           cmp [state], 1
51
           jne .exit
52
.entry:
53
 
54
     if DEBUG
55
           mov esi, msgInit
56
           call SysMsgBoardStr
57
     end if
58
 
59
           stdcall RegService, my_service, service_proc
60
           ret
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
 
77
           mov ebx, [ioctl]
78
           mov eax, [ebx+io_code]
79
           cmp eax, SRV_GETVERSION
80
           jne @F
81
 
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
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
103
           locals
104
            last_bus dd ?
105
           endl
106
 
107
           xor eax, eax
108
           mov [bus], eax
109
           inc eax
110
           call PciApi
111
           cmp eax, -1
112
           je .err
113
 
114
           mov [last_bus], eax
115
 
116
.next_bus:
117
           and [devfn], 0
118
.next_dev:
119
           stdcall PciRead32, [bus], [devfn], dword 0
120
           test eax, eax
121
           jz .next
122
           cmp eax, -1
123
           je .next
124
 
125
           mov edi, devices
126
@@:
127
           mov ebx, [edi]
128
           test ebx, ebx
129
           jz .next
130
 
131
           cmp eax, ebx
132
           je .found
133
 
134
           add edi, STRIDE
135
           jmp @B
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
147
.found:
148
           xor eax, eax
149
           inc eax
150
           ret
151
.err:
152
           xor eax, eax
153
           ret
154
endp
155
 
156
DEVICE_ID    equ  1234;  pci device id
157
VENDOR_ID    equ  5678;  device vendor id
158
 
159
 
160
;all initialized data place here
161
 
162
align 4
163
devices      dd (DEVICE_ID shl 16)+VENDOR_ID
164
             dd 0    ;terminator
165
 
166
version      dd (5 shl 16) or (API_VERSION and 0xFFFF)
167
 
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