Subversion Repositories Kolibri OS

Rev

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

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