Subversion Repositories Kolibri OS

Rev

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

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