Subversion Repositories Kolibri OS

Rev

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

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