Subversion Repositories Kolibri OS

Rev

Rev 2288 | Rev 5054 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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