Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2455 mario79 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
2288 clevermous 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
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
34
public version
35
 
36
DRV_ENTRY    equ 1
37
DRV_EXIT     equ -1
38
STRIDE       equ 4      ;size of row in devices table
39
 
40
SRV_GETVERSION  equ 0
41
 
42
section '.flat' code readable align 16
43
 
44
proc START stdcall, state:dword
45
 
46
        cmp     [state], 1
47
        jne     .exit
48
.entry:
49
 
50
     if DEBUG
51
        mov     esi, msgInit
52
        call    SysMsgBoardStr
53
     end if
54
 
55
        stdcall RegService, my_service, service_proc
56
        ret
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
 
73
        mov     ebx, [ioctl]
74
        mov     eax, [ebx+io_code]
75
        cmp     eax, SRV_GETVERSION
76
        jne     @F
77
 
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
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
99
           locals
100
            last_bus dd ?
101
           endl
102
 
103
        xor     eax, eax
104
        mov     [bus], eax
105
        inc     eax
106
        call    PciApi
107
        cmp     eax, -1
108
        je      .err
109
 
110
        mov     [last_bus], eax
111
 
112
.next_bus:
113
        and     [devfn], 0
114
.next_dev:
115
        stdcall PciRead32, [bus], [devfn], dword 0
116
        test    eax, eax
117
        jz      .next
118
        cmp     eax, -1
119
        je      .next
120
 
121
        mov     edi, devices
122
@@:
123
        mov     ebx, [edi]
124
        test    ebx, ebx
125
        jz      .next
126
 
127
        cmp     eax, ebx
128
        je      .found
129
 
130
        add     edi, STRIDE
131
        jmp     @B
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
143
.found:
144
        xor     eax, eax
145
        inc     eax
146
        ret
147
.err:
148
        xor     eax, eax
149
        ret
150
endp
151
 
152
DEVICE_ID    equ  1234;  pci device id
153
VENDOR_ID    equ  5678;  device vendor id
154
 
155
 
156
;all initialized data place here
157
 
158
align 4
159
devices      dd (DEVICE_ID shl 16)+VENDOR_ID
160
             dd 0    ;terminator
161
 
162
version      dd (5 shl 16) or (API_VERSION and 0xFFFF)
163
 
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