Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
3618 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
4515 hidnplayr 3
;; Copyright (C) KolibriOS team 2010-2014. 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
 
17
use32
18
               org    0x0
19
 
4788 hidnplayr 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
3545 hidnplayr 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:
4788 hidnplayr 53
        call    draw_window
3545 hidnplayr 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
4788 hidnplayr 86
exit:
87
        mcall   -1                      ; close this program
3545 hidnplayr 88
       @@:
4788 hidnplayr 89
        cmp     eax, 0x0000ff00
3545 hidnplayr 90
        jg      load_drv
91
 
92
        cmp     ah, 4
93
        je      hook
94
 
95
        cmp     ah, 5
96
        je      reset
97
 
98
        cmp     ah, 6
99
        je      unload
100
 
101
        jmp     still
102
 
103
 
104
load_drv:
105
        shr     eax, 16
4788 hidnplayr 106
        mov     [selected], ax
3545 hidnplayr 107
 
4788 hidnplayr 108
        mov     bl, 6                   ; get a dword
109
        mov     bh, ah                  ; bus
110
        mov     ch, al                  ; dev
111
        mov     cl, 0                   ; offset to device/vendor id
3545 hidnplayr 112
        mcall   62                      ; get ID's
113
 
4788 hidnplayr 114
        mov     [PCI_Vendor], ax
3545 hidnplayr 115
        shr     eax, 16
4788 hidnplayr 116
        mov     [PCI_Device], ax
3545 hidnplayr 117
        call    get_drv_ptr
118
 
119
        mov     ecx, eax
120
        mcall   68, 16
121
 
122
        mov     [IOCTL.handle], eax
123
 
124
        call    draw_window
125
 
126
        cmp     [IOCTL.handle], 0
127
        jne     still
128
 
129
        mcall   4, 20 shl 16 + 30, 1 shl 31 + 0x00ff0000 , load_error
130
 
131
        jmp     still
132
 
133
 
134
hook:
4788 hidnplayr 135
        mov     ax, [selected]
136
        test    ax, ax
3545 hidnplayr 137
        jz      still
138
 
139
        mov     [hardwareinfo.pci_dev], al
140
        mov     [hardwareinfo.pci_bus], ah
141
 
142
        mov     [IOCTL.io_code], 1 ; SRV_HOOK
143
        mov     [IOCTL.inp_size], 3
144
        mov     [IOCTL.input], hardwareinfo
145
        mov     [IOCTL.out_size], 0
146
        mov     [IOCTL.output], 0
147
 
148
        mcall   68, 17, IOCTL
4788 hidnplayr 149
        mov     [drivernumber], al
3545 hidnplayr 150
 
151
        jmp     still
152
 
153
reset:
4788 hidnplayr 154
        movzx   ebx, [drivernumber]
3545 hidnplayr 155
        mcall   74,,2
156
 
157
        jmp     still
158
 
159
unload:
4788 hidnplayr 160
        movzx   ebx, [drivernumber]
3545 hidnplayr 161
        mcall   74,,3
162
 
163
        jmp     still
164
 
165
draw_window:
166
        mcall   12, 1                   ; start of draw
4788 hidnplayr 167
        mcall   0, dword[Form], dword[Form + 4], 0x13ffffff, 0x805080d0, title
3545 hidnplayr 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
 
4788 hidnplayr 174
        mcall   4, 20 shl 16 + 100, 1 shl 31 + 0x00000000, caption
3545 hidnplayr 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
 
4788 hidnplayr 185
        mcall   4, 33 shl 16 + 42, 1 shl 31 + 0x00ffffff, btn_start
3545 hidnplayr 186
        mcall   , 33 shl 16 + 62, , btn_reset
187
        mcall   , 36 shl 16 + 82, , btn_stop
188
 
189
        jmp     .done
190
 
191
  .nonefound:
4788 hidnplayr 192
        mcall   4, 20 shl 16 + 30, 1 shl 31 + 0x00ff0000, nonefound
3545 hidnplayr 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
4788 hidnplayr 205
        mov     [PCI_Version], ax
3545 hidnplayr 206
        mcall   62, 1
4788 hidnplayr 207
        mov     [PCI_LastBus], al
3545 hidnplayr 208
        ;----------------------------------------------------------
209
        ;* Get all devices on PCI Bus
4788 hidnplayr 210
        cmp     al, 0xff                ; 0xFF means no pci bus found
3545 hidnplayr 211
        jne     Pci_Exists              ;
212
        ret                             ; if no bus then leave
4788 hidnplayr 213
 
3545 hidnplayr 214
Pci_Exists:
4788 hidnplayr 215
        mov     [V_Bus], 0
216
        mov     [V_Dev], 0
217
        mov     edx, 20 shl 16 + 110    ; set start write position
218
 
3545 hidnplayr 219
Start_Enum:
4788 hidnplayr 220
        mov     bl, 6                   ; read dword
221
        mov     bh, [V_Bus]
222
        mov     ch, [V_Dev]
223
        mov     cl, 0                   ; offset to device/vendor id
3545 hidnplayr 224
        mcall   62                      ; get ID's
225
 
226
        cmp     ax, 0                   ; Vendor ID should not be 0 or 0xFFFF
5166 hidnplayr 227
        je      .nextDev                ; check next device if nothing exists here
3545 hidnplayr 228
        cmp     ax, 0xffff              ;
5166 hidnplayr 229
        je      .nextDev                ;
3545 hidnplayr 230
 
4788 hidnplayr 231
        mov     [PCI_Vendor], ax        ; There is a device here, save the ID's
3545 hidnplayr 232
        shr     eax, 16                 ;
4788 hidnplayr 233
        mov     [PCI_Device], ax        ;
234
        mov     bl, 4                   ; Read config byte
235
        mov     bh, [V_Bus]             ; Bus #
236
        mov     ch, [V_Dev]             ; Device # on bus
237
        mov     cl, 0x08                ; Register to read (Get Revision)
3545 hidnplayr 238
        mcall   62                      ; Read it
4788 hidnplayr 239
        mov     [PCI_Rev], al           ; Save it
5166 hidnplayr 240
 
4788 hidnplayr 241
        mov     cl, 0x0b                ; Register to read (Get class)
3545 hidnplayr 242
        mcall   62                      ; Read it
4788 hidnplayr 243
        mov     [PCI_Class], al         ; Save it
5166 hidnplayr 244
 
4788 hidnplayr 245
        mov     cl, 0x0a                ; Register to read (Get Subclass)
3545 hidnplayr 246
        mcall   62                      ; Read it
4788 hidnplayr 247
        mov     [PCI_SubClass], al      ; Save it
5166 hidnplayr 248
 
4788 hidnplayr 249
        mov     cl, 0x09                ; Register to read (Get Interface)
3545 hidnplayr 250
        mcall   62                      ; Read it
251
        mov     [PCI_Interface], al     ; Save it
5166 hidnplayr 252
 
4788 hidnplayr 253
        mov     cl, 0x3c                ; Register to read (Get IRQ)
5166 hidnplayr 254
        mcall   62                      ; Read it
3545 hidnplayr 255
        mov     [PCI_IRQ], al           ; Save it
256
 
5166 hidnplayr 257
; Could it be a network card?
4515 hidnplayr 258
        cmp     [PCI_Class], 2          ; network controller
5166 hidnplayr 259
        je      .found
3545 hidnplayr 260
 
4515 hidnplayr 261
        cmp     [PCI_Class], 6          ; bridge type device
5166 hidnplayr 262
        jne     .nextDev
4515 hidnplayr 263
        cmp     [PCI_SubClass], 0x80    ; PCI-other bridge (for nvidia chipset)
5166 hidnplayr 264
        jne     .nextDev
4515 hidnplayr 265
        cmp     [PCI_Vendor], 0x10DE    ; nvidia
5166 hidnplayr 266
        jne     .nextDev
3618 hidnplayr 267
 
5166 hidnplayr 268
  .found:
269
        cmp     byte[param], 0          ; Load network driver immediately?
3545 hidnplayr 270
        jne     load_and_start
271
 
5166 hidnplayr 272
        call    Print_New_Device        ; print device info to screen
273
 
274
  .nextDev:
275
        test    [V_Dev], 7
276
        jnz     .nextFn
277
 
278
; Is this a multifunction device?
279
        mov     bl, 4                   ; Read config byte
280
        mov     bh, [V_Bus]             ; Bus #
281
        mov     ch, [V_Dev]             ; Device # on bus
3545 hidnplayr 282
        mov     cl, 0x0e
283
        mcall   62
284
        test    al, al
5166 hidnplayr 285
        js      .nextFn
3545 hidnplayr 286
 
5166 hidnplayr 287
; Not a multifunction device, go to the next device
4788 hidnplayr 288
        or      [V_Dev], 7
3545 hidnplayr 289
 
5166 hidnplayr 290
  .nextFn:
3545 hidnplayr 291
        inc     [V_Dev]                 ; lower 3 bits are the function number
4788 hidnplayr 292
        jnz     Start_Enum              ; jump until we reach zero
3545 hidnplayr 293
 
4788 hidnplayr 294
        mov     [V_Dev], 0              ; reset device number
295
        inc     [V_Bus]                 ; next bus
296
        mov     al, [PCI_LastBus]       ; get last bus
297
        cmp     [V_Bus], al             ; was it last bus
3545 hidnplayr 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'
5166 hidnplayr 330
        je      Start_Enum.nextDev
3545 hidnplayr 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
4788 hidnplayr 342
        mov     bx, [Form]
343
        sub     bx, 36
3545 hidnplayr 344
 
4788 hidnplayr 345
        mov     cx, dx
3545 hidnplayr 346
        dec     cx
347
        shl     ecx, 16
348
        add     ecx, 9
349
 
4788 hidnplayr 350
        xor     edx, edx
351
        mov     dh, [V_Bus]
352
        mov     dl, [V_Dev]
3545 hidnplayr 353
 
354
        mov     esi, 0x0000c0ff        ; color: yellow if selected, blue otherwise
4788 hidnplayr 355
        cmp     [selected], dx
3545 hidnplayr 356
        jne     @f
357
        mov     esi, 0x00c0c000
358
       @@:
359
 
360
        shl     edx, 8
4788 hidnplayr 361
        or      dl, 0xff
3545 hidnplayr 362
 
363
        mcall   8
364
        pop     edx
365
 
366
        xor     esi, esi                ; Color of text
4788 hidnplayr 367
        movzx   ecx, [PCI_Vendor]       ; number to be written
3545 hidnplayr 368
        mcall   47, 0x00040100          ; Write Vendor ID
369
 
370
        add     edx, (4*6+18) shl 16
4788 hidnplayr 371
        movzx   ecx, [PCI_Device]       ; get Vendor ID
3545 hidnplayr 372
        mcall                           ; Draw Vendor ID to Window
373
 
374
        add     edx, (4*6+18) shl 16
4788 hidnplayr 375
        movzx   ecx, [V_Bus]
3545 hidnplayr 376
        mcall   ,0x00020100             ; draw bus number to screen
377
 
378
        add     edx, (2*6+18) shl 16
4788 hidnplayr 379
        movzx   ecx, [V_Dev]
3545 hidnplayr 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
4788 hidnplayr 384
        movzx   ecx, [PCI_Rev]
3545 hidnplayr 385
        mcall                           ; Draw Revision to screen
386
 
387
        add     edx, (2*6+18) shl 16
388
        movzx   ecx, [PCI_IRQ]
4788 hidnplayr 389
        cmp     cl, 0x0f                ; IRQ must be between 0 and 15
3545 hidnplayr 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
4788 hidnplayr 402
        mov     cx, [PCI_Vendor]
3545 hidnplayr 403
 
4788 hidnplayr 404
.fn:    mov     ax, [edx]
3545 hidnplayr 405
        add     edx, 6
4788 hidnplayr 406
        test    ax, ax
3545 hidnplayr 407
        jz      .find
4788 hidnplayr 408
        cmp     ax, cx
3545 hidnplayr 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
;------------------------------------------------------------------
4788 hidnplayr 416
        mov     eax, dword[PCI_Class]
3545 hidnplayr 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
 
4788 hidnplayr 476
        add     ebx, 4
3545 hidnplayr 477
        jmp     deviceloop
478
 
479
       nextdriver:
4788 hidnplayr 480
        add     ebx, 4
3545 hidnplayr 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 ?
4788 hidnplayr 551
; Dont change order
3545 hidnplayr 552
PCI_Vendor      dw ?
553
PCI_Device      dw ?
4788 hidnplayr 554
 
3545 hidnplayr 555
PCI_Bus         db ?
556
PCI_Dev         db ?
557
PCI_Rev         db ?
4788 hidnplayr 558
; Dont change order
3545 hidnplayr 559
PCI_Class       db ?
560
PCI_SubClass    db ?
561
PCI_Interface   db ?
562
PCI_IRQ         db ?
563
 
564
Proc_Info       process_information
565
 
566
param           rb 1024
567
 
568
 
569
I_END: