Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1253 hidnplayr 1
;
2
; Netcfg v1.02
3
;
4
; Application to load network drivers in KolibriOS
5
;
6
; By hidnplayr
7
;
1164 hidnplayr 8
 
1253 hidnplayr 9
use32
10
	       org    0x0
11
 
12
	       db     'MENUET01'	    ; 8 byte id
13
	       dd     0x01		    ; header version
14
	       dd     START		    ; start of code
15
	       dd     IM_END		    ; size of image
16
	       dd     (I_END+0x100)	    ; memory for app
17
	       dd     (I_END+0x100)	    ; esp
18
	       dd     param, 0x0	   ; I_Param , I_Icon
19
 
1164 hidnplayr 20
type_ethernet equ 1
21
 
1253 hidnplayr 22
include '../macros.inc'
23
include 'proc32.inc'
24
include 'struct.inc'
25
 
26
START:
27
	; first, check boot parameters
28
 
29
	cmp	byte[param], 0
30
	je	.noparams
31
 
32
	mcall 40, 0
33
 
34
 
35
	push	exit
36
	cmp	byte[param], 'A'	; A for All
37
	je	Get_PCI_Info
38
 
39
	cmp	byte[param], 'F'	; F for First
40
	je	Get_PCI_Info
41
 
42
	ret
43
 
44
.noparams:
1164 hidnplayr 45
	call draw_window
46
 
47
still:	mcall	10			; wait here for event
48
	dec	eax			; redraw request ?
49
	jz	red
50
	dec	eax			; key in buffer ?
51
	jz	key
52
	dec	eax			; button in buffer ?
53
	jz	button
54
	jmp	still
55
 
56
red:					; redraw
57
	mcall	9, Proc_Info, -1	; window redraw requested so get new window coordinates and size
58
	mov	eax, [Proc_Info.box.left]; store the window coordinates into the Form Structure
59
	mov	[Form + 2], ax		; x start position
60
	mov	eax, [Proc_Info.box.top];
61
	mov	[Form + 6], ax		; ystart position
62
	mov	eax, [Proc_Info.box.width]	;
63
	mov	[Form], ax		; window width
64
	mov	eax, [Proc_Info.box.height]	;
65
	mov	[Form + 4] ,ax		; window height
66
	call	draw_window		; go redraw window now
67
	jmp	still
68
 
69
key:					; key
70
	mcall	2			; just read it and ignore
71
	jmp	still
72
button: 				; button
73
	mcall	17			; get id
74
 
75
	cmp	ah, 1			; button id = 1 ?
76
	jne	@f
1253 hidnplayr 77
exit:	mcall	-1			; close this program
1164 hidnplayr 78
       @@:
1196 hidnplayr 79
	cmp	eax,0x0000ff00
80
	jg	load_drv
1164 hidnplayr 81
 
82
	cmp	ah, 4
83
	je	hook
84
 
1192 hidnplayr 85
	cmp	ah, 5
86
	je	reset
87
 
88
	cmp	ah, 6
89
	je	unload
90
 
1164 hidnplayr 91
	jmp	still
92
 
93
 
94
load_drv:
1196 hidnplayr 95
	shr	eax, 16
96
	mov	word [selected], ax
1164 hidnplayr 97
 
98
	mov	bl , 6			; get a dword
1196 hidnplayr 99
	mov	bh , ah 		; bus
100
	mov	ch , al 		; dev
1164 hidnplayr 101
	mov	cl , 0			; offset to device/vendor id
1196 hidnplayr 102
	mcall	62			; get ID's
1164 hidnplayr 103
 
104
	mov	word [PCI_Vendor], ax
105
	shr	eax, 16
106
	mov	word [PCI_Device], ax
107
	call	get_drv_ptr
108
 
109
	mov	ecx, eax
1196 hidnplayr 110
	mcall	68, 16
1164 hidnplayr 111
 
112
	mov	[IOCTL.handle], eax
113
 
1196 hidnplayr 114
	call	draw_window
1164 hidnplayr 115
 
1196 hidnplayr 116
	cmp	[IOCTL.handle], 0
117
	jne	still
118
 
119
	mcall	4, 20 shl 16 + 30, 1 shl 31 + 0x00ff0000 , load_error
120
 
121
	jmp	still
122
 
123
 
1164 hidnplayr 124
hook:
125
	mov	ax , [selected]
126
	test	ax , ax
127
	jz	still
128
 
129
	mov	[hardwareinfo.pci_dev], al
130
	mov	[hardwareinfo.pci_bus], ah
131
 
132
	mov	[IOCTL.io_code], 1 ; SRV_HOOK
133
	mov	[IOCTL.inp_size], 3
134
	mov	[IOCTL.input], hardwareinfo
135
	mov	[IOCTL.out_size], 0
136
	mov	[IOCTL.output], 0
137
 
1196 hidnplayr 138
	mcall	68, 17, IOCTL
1164 hidnplayr 139
 
140
	mov	byte[drivernumber], al
141
 
1196 hidnplayr 142
	jmp	still
143
 
1192 hidnplayr 144
reset:
145
	movzx	ebx, byte[drivernumber]
146
	mcall	73,,2
1164 hidnplayr 147
 
1196 hidnplayr 148
	jmp	still
1164 hidnplayr 149
 
1192 hidnplayr 150
unload:
151
	movzx	ebx, byte[drivernumber]
152
	mcall	73,,3
1164 hidnplayr 153
 
1196 hidnplayr 154
	jmp	still
1192 hidnplayr 155
 
1164 hidnplayr 156
draw_window:
157
	mcall	12, 1			; start of draw
158
	mcall	0, dword [Form], dword [Form + 4], 0x13ffffff, 0x805080d0, title
159
 
160
	call	Get_PCI_Info		; get pci version and last bus, scan for and draw each pci device
161
 
162
	cmp	edx, 20 shl 16 + 110
163
	je	.nonefound
164
 
165
	mcall	4, 20 shl 16 + 100, 1 shl 31 + 0x00000000 , caption
166
 
1196 hidnplayr 167
	cmp	[selected], 0
1192 hidnplayr 168
	jz	.done
1196 hidnplayr 169
	cmp	[IOCTL.handle] ,0
170
	jz	.done
1164 hidnplayr 171
 
1192 hidnplayr 172
	mcall	8, 18 shl 16 + 100, 35 shl 16 + 18, 4, 0x00007f00
173
	mcall	,, 55 shl 16 + 18, 5, 0x0000007f
174
	mcall	,, 75 shl 16 + 18, 6, 0x007f0000
1164 hidnplayr 175
 
1192 hidnplayr 176
	mcall	4, 33 shl 16 + 42, 1 shl 31 + 0x00ffffff , btn_start
177
	mcall	, 33 shl 16 + 62, , btn_reset
178
	mcall	, 36 shl 16 + 82, , btn_stop
1164 hidnplayr 179
 
1192 hidnplayr 180
;        mcall   , 140 shl 16 + 62, 1 shl 31 + 0x00000000 , devicename
1164 hidnplayr 181
 
182
	jmp	.done
183
 
1196 hidnplayr 184
.nonefound:
1164 hidnplayr 185
	mcall	4, 20 shl 16 + 30, 1 shl 31 + 0x00ff0000 , nonefound
186
.done:
187
	mcall	12, 2			; end of draw
188
	ret
189
 
190
 
1253 hidnplayr 191
 
192
 
193
 
1164 hidnplayr 194
;------------------------------------------------------------------
195
;* Gets the PCI Version and Last Bus
196
Get_PCI_Info:
197
	mcall	62, 0
198
	mov	word [PCI_Version], ax
199
	mcall	62, 1
200
	mov	byte [PCI_LastBus], al
201
	;----------------------------------------------------------
202
	;* Get all devices on PCI Bus
203
	mov	edx, 20 shl 16 + 110  ; set start write position
204
	cmp	al , 0xff		 ; 0xFF means no pci bus found
205
	jne	Pci_Exists		;
206
	ret				; if no bus then leave
207
Pci_Exists:
208
	mov	byte [V_Bus], 0 	; reset varibles
209
	mov	byte [V_Dev], 0 	;
210
Start_Enum:
211
	mov	bl , 6			 ; get a dword
212
	mov	bh , byte [V_Bus]	 ; bus of pci device
213
	mov	ch , byte [V_Dev]	 ; device number/function
214
	mov	cl , 0			 ; offset to device/vendor id
215
	mcall	62			; get ID's
216
 
217
	cmp	ax, 0			; Vendor ID should not be 0 or 0xFFFF
218
	je	nextDev 		; check next device if nothing exists here
219
	cmp	ax, 0xffff		;
220
	je	nextDev 		;
221
 
222
	mov	word [PCI_Vendor], ax	; There is a device here, save the ID's
223
	shr	eax, 16 		;
224
	mov	word [PCI_Device], ax	;
225
	mov	bl , 4			 ; Read config byte
226
	mov	bh , byte [V_Bus]	 ; Bus #
227
	mov	ch , byte [V_Dev]	 ; Device # on bus
228
	mov	cl , 0x08		 ; Register to read (Get Revision)
229
	mcall	62			; Read it
230
	mov	byte [PCI_Rev], al	; Save it
231
	mov	cl , 0x0b		 ; Register to read (Get class)
232
	mcall	62			; Read it
233
 
234
	mov	byte [PCI_Class], al	; Save it
235
	mov	cl , 0x0a		 ; Register to read (Get Subclass)
236
	mcall	62			; Read it
237
	mov	byte [PCI_SubClass], al ; Save it
238
	mov	cl , 0x09		 ; Register to read (Get Interface)
239
	mcall	62			; Read it
240
	mov	[PCI_Interface], al	; Save it
241
	mov	cl , 0x3c		 ; Register to read (Get IRQ)
242
@@:	mcall	62			; Read it
243
	mov	[PCI_IRQ], al		; Save it
244
;
245
;        inc     byte [total]            ; one more device found
246
 
247
	cmp	byte [PCI_Class],2
248
	jne	nextDev
249
 
1253 hidnplayr 250
	cmp	byte[param], 0
251
	jne	load_and_start
252
 
1164 hidnplayr 253
	call	Print_New_Device	; print device info to screen
1253 hidnplayr 254
 
1164 hidnplayr 255
nextDev:
256
	add	byte [V_Dev], 8 	; lower 3 bits are the function number
257
 
258
	jnz	Start_Enum		; jump until we reach zero
259
	mov	byte [V_Dev], 0 	; reset device number
260
	inc	byte [V_Bus]		; next bus
261
	mov	al , byte [PCI_LastBus]  ; get last bus
262
	cmp	byte [V_Bus], al	; was it last bus
263
	jbe	Start_Enum		; if not jump to keep searching
264
	ret
265
 
1253 hidnplayr 266
 
267
 
268
load_and_start:
269
 
270
	call	get_drv_ptr
271
	cmp	eax, lbl_none
272
	je	.next
273
 
274
	mov	ecx, eax
275
	mcall	68, 16
276
	test	eax, eax
277
	jz	.next
278
	mov	[IOCTL.handle], eax
279
 
280
	mov	al, [V_Dev]
281
	mov	[hardwareinfo.pci_dev], al
282
	mov	al, [V_Bus]
283
	mov	[hardwareinfo.pci_bus], al
284
 
285
	mov	[IOCTL.io_code], 1 ; SRV_HOOK
286
	mov	[IOCTL.inp_size], 3
287
	mov	[IOCTL.input], hardwareinfo
288
	mov	[IOCTL.out_size], 0
289
	mov	[IOCTL.output], 0
290
 
291
	mcall	68, 17, IOCTL
292
 
293
       .next:
294
	cmp	byte[param], 'A'
295
	je	nextDev
296
	jmp	exit
297
 
298
 
299
 
1164 hidnplayr 300
;------------------------------------------------------------------
301
;* Print device info to screen
302
Print_New_Device:
303
 
304
	push	edx			; Magic ! (to print a button...)
305
 
306
	mov	ebx, 18 shl 16
307
	mov	bx , [Form]
308
	sub	bx , 36
309
 
310
	mov	cx , dx
311
	dec	cx
312
	shl	ecx, 16
313
	add	ecx, 9
314
 
315
	movzx	edx, byte [V_Bus]
316
	shl	dx , 8
317
	mov	dl , byte [V_Dev]
318
 
319
	mov	esi, 0x0000c0ff        ; color: yellow if selected, blue otherwise
320
	cmp	word [selected], dx
321
	jne	@f
322
	mov	esi, 0x00c0c000
323
       @@:
324
 
325
	shl	edx, 8
326
	or	dl , 0xff
327
 
328
	mcall	8
329
	pop	edx
330
 
331
	xor	esi, esi		; Color of text
332
	movzx	ecx, word [PCI_Vendor]	; number to be written
333
	mcall	47, 0x00040100		; Write Vendor ID
334
 
335
	add	edx, (4*6+18) shl 16
336
	movzx	ecx, word [PCI_Device]	; get Vendor ID
337
	mcall				; Draw Vendor ID to Window
338
 
339
	add	edx, (4*6+18) shl 16
340
	movzx	ecx, byte [V_Bus]	; get bus number
341
	mcall	,0x00020100		; draw bus number to screen
342
 
343
	add	edx, (2*6+18) shl 16
344
	movzx	ecx, byte [V_Dev]	; get device number
345
	shr	ecx, 3			; device number is bits 3-7
346
	mcall				; Draw device Number To Window
347
 
348
	add	edx, (2*6+18) shl 16
349
	movzx	ecx, byte [PCI_Rev]	; get revision number
350
	mcall				; Draw Revision to screen
351
 
352
	add	edx, (2*6+18) shl 16
353
	movzx	ecx, [PCI_IRQ]
354
	cmp	cl , 0x0f		; IRQ must be between 0 and 15
355
	ja	@f
356
	mcall
357
@@:
358
;
359
	;Write Names
360
	movzx	ebx, dx 		; Set y position
361
	or	ebx, 230 shl 16 	; set Xposition
362
 
363
;------------------------------------------------------------------
364
; Prints the Vendor's Name based on Vendor ID
365
;------------------------------------------------------------------
366
	mov	edx, VendorsTab
367
	mov	cx , word[PCI_Vendor]
368
 
369
.fn:	mov	ax , [edx]
370
	add	edx, 6
371
	test	ax , ax
372
	jz	.find
373
	cmp	ax , cx
374
	jne	.fn
375
.find:	mov	edx, [edx - 4]
376
	mcall	4,, 0x80000000		; lets print the vendor Name
377
 
378
;------------------------------------------------------------------
379
; Get description based on Class/Subclass
380
;------------------------------------------------------------------
381
	mov	eax, dword [PCI_Class]
382
	and	eax, 0xffffff
383
	xor	edx, edx
384
	xor	esi, esi
385
.fnc:	inc	esi
386
	mov	ecx, [Classes + esi * 8 - 8]
387
	cmp	cx , 0xffff
388
	je	.endfc
389
	cmp	cx , ax
390
	jne	.fnc
391
	test	ecx, 0xff000000
392
	jz	@f
393
	mov	edx, [Classes + esi * 8 - 4]
394
	jmp	.fnc
395
@@:	cmp	eax, ecx
396
	jne	.fnc
397
	xor	edx, edx
398
.endfc: test	edx, edx
399
	jnz	@f
400
	mov	edx, [Classes + esi * 8 - 4]
401
@@:
402
	add	ebx, 288 shl 16
403
	mcall	4,, 0x80000000,, 32	; draw the text
404
	movzx	edx, bx 		; get y coordinate
405
	add	edx, 0x0014000A 	; add 10 to y coordinate and set x coordinate to 20
406
 
407
;------------------------------------------------------------------
408
; Print Driver Name
409
;------------------------------------------------------------------
410
	push	edx
411
	add	ebx, 120 shl 16
412
	push	ebx
413
 
414
	call	get_drv_ptr
415
	mov	edx, eax
416
	pop	ebx
417
	mcall	4,,0x80000000	       ; lets print the vendor Name
418
	pop	edx
419
	ret
420
 
421
get_drv_ptr:
422
	mov	eax, driverlist        ; eax will be the pointer to latest driver title
423
	mov	ebx, driverlist        ; ebx is the current pointer
424
	mov	ecx, dword[PCI_Vendor] ; the device/vendor id of we want to find
425
 
426
       driverloop:
427
	inc	ebx
428
 
429
	cmp	byte[ebx],0
430
	jne	driverloop
431
 
432
	inc	ebx		       ; the device/vendor id list for the driver eax is pointing to starts here.
433
 
434
       deviceloop:
435
	cmp	dword[ebx],0
436
	je	nextdriver
437
 
438
	cmp	dword[ebx],ecx
439
	je	driverfound
440
 
441
	add	ebx,4
442
	jmp	deviceloop
443
 
444
       nextdriver:
445
	add	ebx,4
446
 
447
	cmp	dword[ebx],0
448
	je	nodriver
449
 
450
	mov	eax,ebx
451
	jmp	driverloop
452
 
453
       nodriver:
454
	mov	eax, lbl_none	       ; lets print the vendor Name
455
	ret
456
 
457
       driverfound:
458
	ret
459
 
1196 hidnplayr 460
include 'vendors.inc'
461
include 'drivers.inc'
1253 hidnplayr 462
 
463
 
1164 hidnplayr 464
;------------------------------------------------------------------
465
; DATA AREA
1253 hidnplayr 466
 
467
 
1164 hidnplayr 468
DATA
469
 
470
 
471
Form:	dw 800 ; window width (no more, special for 800x600)
472
	dw 100 ; window x start
473
	dw 220 ; window height
474
	dw 100 ; window y start
475
 
476
title	db 'Network Driver Control Center', 0
477
 
478
caption db 'Vendor Device Bus  Dev  Rev  IRQ   Company                                         Description         DRIVER',0
479
nonefound db 'No compatible devices were found!',0
1192 hidnplayr 480
btn_start db 'Start device',0
481
btn_reset db 'Reset device',0
482
btn_stop db 'Stop device',0
1164 hidnplayr 483
lbl_none db 'none',0
1196 hidnplayr 484
load_error db 'Could not load driver!',0
1164 hidnplayr 485
 
1192 hidnplayr 486
devicename     db 'test'
487
rb 64
488
		db 0
1164 hidnplayr 489
 
1253 hidnplayr 490
hardwareinfo:
491
   .type	db 1 ; pci
492
   .pci_bus	db ?
493
   .pci_dev	db ?
1192 hidnplayr 494
 
1253 hidnplayr 495
 
496
IM_END:
497
 
498
;------------------------------------------------------------------
499
; UNINITIALIZED DATA AREA
500
 
501
 
1164 hidnplayr 502
IOCTL:
503
   .handle	dd ?
504
   .io_code	dd ?
505
   .input	dd ?
506
   .inp_size	dd ?
507
   .output	dd ?
508
   .out_size	dd ?
509
 
510
drivernumber	db ?
511
MAC		dp ?
512
 
513
 
514
type		db ?
515
selected	dw ?
516
V_Bus		db ?
517
V_Dev		db ?
518
PCI_Version	dw ?
519
PCI_LastBus	db ?
520
PCI_Vendor	dw ?
521
PCI_Device	dw ?
522
PCI_Bus 	db ?
523
PCI_Dev 	db ?
524
PCI_Rev 	db ?
525
; don`t change order!!!
526
PCI_Class	db ?
527
PCI_SubClass	db ?
528
PCI_Interface	db ?
529
PCI_IRQ 	db ?
530
 
531
Proc_Info	process_information
532
 
1253 hidnplayr 533
param		rb 1024
1164 hidnplayr 534
 
1253 hidnplayr 535
 
536
I_END: