Subversion Repositories Kolibri OS

Rev

Rev 4515 | 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
;;                                                                 ;;
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
227
        je      nextDev                 ; check next device if nothing exists here
4788 hidnplayr 228
 
3545 hidnplayr 229
        cmp     ax, 0xffff              ;
230
        je      nextDev                 ;
231
 
4788 hidnplayr 232
        mov     [PCI_Vendor], ax        ; There is a device here, save the ID's
3545 hidnplayr 233
        shr     eax, 16                 ;
4788 hidnplayr 234
        mov     [PCI_Device], ax        ;
235
        mov     bl, 4                   ; Read config byte
236
        mov     bh, [V_Bus]             ; Bus #
237
        mov     ch, [V_Dev]             ; Device # on bus
238
        mov     cl, 0x08                ; Register to read (Get Revision)
3545 hidnplayr 239
        mcall   62                      ; Read it
4788 hidnplayr 240
        mov     [PCI_Rev], al           ; Save it
241
        mov     cl, 0x0b                ; Register to read (Get class)
3545 hidnplayr 242
        mcall   62                      ; Read it
243
 
4788 hidnplayr 244
        mov     [PCI_Class], al         ; Save it
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
248
        mov     cl, 0x09                ; Register to read (Get Interface)
3545 hidnplayr 249
        mcall   62                      ; Read it
250
        mov     [PCI_Interface], al     ; Save it
4788 hidnplayr 251
        mov     cl, 0x3c                ; Register to read (Get IRQ)
3545 hidnplayr 252
@@:     mcall   62                      ; Read it
253
        mov     [PCI_IRQ], al           ; Save it
254
 
4515 hidnplayr 255
        cmp     [PCI_Class], 2          ; network controller
3618 hidnplayr 256
        je      @f
3545 hidnplayr 257
 
4515 hidnplayr 258
        cmp     [PCI_Class], 6          ; bridge type device
3545 hidnplayr 259
        jne     nextDev
4515 hidnplayr 260
        cmp     [PCI_SubClass], 0x80    ; PCI-other bridge (for nvidia chipset)
3618 hidnplayr 261
        jne     nextDev
4515 hidnplayr 262
        cmp     [PCI_Vendor], 0x10DE    ; nvidia
263
        jne     nextDev
3618 hidnplayr 264
       @@:
265
 
3545 hidnplayr 266
        cmp     byte[param], 0
267
        jne     load_and_start
268
 
269
        mov     cl, 0x0e
270
        mcall   62
271
 
272
        push    eax
273
        call    Print_New_Device        ; print device info to screen
274
        pop     eax
275
        test    al, al
276
        js      nextDev
277
 
278
nextdev2:
4788 hidnplayr 279
        test    [V_Dev], 7
3545 hidnplayr 280
        jnz     nextDev
281
 
4788 hidnplayr 282
        or      [V_Dev], 7
3545 hidnplayr 283
 
284
nextDev:
285
        inc     [V_Dev]                 ; lower 3 bits are the function number
4788 hidnplayr 286
        jnz     Start_Enum              ; jump until we reach zero
3545 hidnplayr 287
 
4788 hidnplayr 288
        mov     [V_Dev], 0              ; reset device number
289
        inc     [V_Bus]                 ; next bus
290
        mov     al, [PCI_LastBus]       ; get last bus
291
        cmp     [V_Bus], al             ; was it last bus
3545 hidnplayr 292
        jbe     Start_Enum              ; if not jump to keep searching
293
        ret
294
 
295
 
296
 
297
load_and_start:
298
 
299
        call    get_drv_ptr
300
        cmp     eax, lbl_none
301
        je      .next
302
 
303
        mov     ecx, eax
304
        mcall   68, 16
305
        test    eax, eax
306
        jz      .next
307
        mov     [IOCTL.handle], eax
308
 
309
        mov     al, [V_Dev]
310
        mov     [hardwareinfo.pci_dev], al
311
        mov     al, [V_Bus]
312
        mov     [hardwareinfo.pci_bus], al
313
 
314
        mov     [IOCTL.io_code], 1 ; SRV_HOOK
315
        mov     [IOCTL.inp_size], 3
316
        mov     [IOCTL.input], hardwareinfo
317
        mov     [IOCTL.out_size], 0
318
        mov     [IOCTL.output], 0
319
 
320
        mcall   68, 17, IOCTL
321
 
322
       .next:
323
        cmp     byte[param], 'A'
324
        je      nextdev2
325
        jmp     exit
326
 
327
 
328
 
329
;------------------------------------------------------------------
330
;* Print device info to screen
331
Print_New_Device:
332
 
333
        push    edx                     ; Magic ! (to print a button...)
334
 
335
        mov     ebx, 18 shl 16
4788 hidnplayr 336
        mov     bx, [Form]
337
        sub     bx, 36
3545 hidnplayr 338
 
4788 hidnplayr 339
        mov     cx, dx
3545 hidnplayr 340
        dec     cx
341
        shl     ecx, 16
342
        add     ecx, 9
343
 
4788 hidnplayr 344
        xor     edx, edx
345
        mov     dh, [V_Bus]
346
        mov     dl, [V_Dev]
3545 hidnplayr 347
 
348
        mov     esi, 0x0000c0ff        ; color: yellow if selected, blue otherwise
4788 hidnplayr 349
        cmp     [selected], dx
3545 hidnplayr 350
        jne     @f
351
        mov     esi, 0x00c0c000
352
       @@:
353
 
354
        shl     edx, 8
4788 hidnplayr 355
        or      dl, 0xff
3545 hidnplayr 356
 
357
        mcall   8
358
        pop     edx
359
 
360
        xor     esi, esi                ; Color of text
4788 hidnplayr 361
        movzx   ecx, [PCI_Vendor]       ; number to be written
3545 hidnplayr 362
        mcall   47, 0x00040100          ; Write Vendor ID
363
 
364
        add     edx, (4*6+18) shl 16
4788 hidnplayr 365
        movzx   ecx, [PCI_Device]       ; get Vendor ID
3545 hidnplayr 366
        mcall                           ; Draw Vendor ID to Window
367
 
368
        add     edx, (4*6+18) shl 16
4788 hidnplayr 369
        movzx   ecx, [V_Bus]
3545 hidnplayr 370
        mcall   ,0x00020100             ; draw bus number to screen
371
 
372
        add     edx, (2*6+18) shl 16
4788 hidnplayr 373
        movzx   ecx, [V_Dev]
3545 hidnplayr 374
        shr     ecx, 3                  ; device number is bits 3-7
375
        mcall                           ; Draw device Number To Window
376
 
377
        add     edx, (2*6+18) shl 16
4788 hidnplayr 378
        movzx   ecx, [PCI_Rev]
3545 hidnplayr 379
        mcall                           ; Draw Revision to screen
380
 
381
        add     edx, (2*6+18) shl 16
382
        movzx   ecx, [PCI_IRQ]
4788 hidnplayr 383
        cmp     cl, 0x0f                ; IRQ must be between 0 and 15
3545 hidnplayr 384
        ja      @f
385
        mcall
386
@@:
387
;
388
        ;Write Names
389
        movzx   ebx, dx                 ; Set y position
390
        or      ebx, 230 shl 16         ; set Xposition
391
 
392
;------------------------------------------------------------------
393
; Prints the Vendor's Name based on Vendor ID
394
;------------------------------------------------------------------
395
        mov     edx, VendorsTab
4788 hidnplayr 396
        mov     cx, [PCI_Vendor]
3545 hidnplayr 397
 
4788 hidnplayr 398
.fn:    mov     ax, [edx]
3545 hidnplayr 399
        add     edx, 6
4788 hidnplayr 400
        test    ax, ax
3545 hidnplayr 401
        jz      .find
4788 hidnplayr 402
        cmp     ax, cx
3545 hidnplayr 403
        jne     .fn
404
.find:  mov     edx, [edx - 4]
405
        mcall   4,, 0x80000000          ; lets print the vendor Name
406
 
407
;------------------------------------------------------------------
408
; Get description based on Class/Subclass
409
;------------------------------------------------------------------
4788 hidnplayr 410
        mov     eax, dword[PCI_Class]
3545 hidnplayr 411
        and     eax, 0xffffff
412
        xor     edx, edx
413
        xor     esi, esi
414
.fnc:   inc     esi
415
        mov     ecx, [Classes + esi * 8 - 8]
416
        cmp     cx , 0xffff
417
        je      .endfc
418
        cmp     cx , ax
419
        jne     .fnc
420
        test    ecx, 0xff000000
421
        jz      @f
422
        mov     edx, [Classes + esi * 8 - 4]
423
        jmp     .fnc
424
@@:     cmp     eax, ecx
425
        jne     .fnc
426
        xor     edx, edx
427
.endfc: test    edx, edx
428
        jnz     @f
429
        mov     edx, [Classes + esi * 8 - 4]
430
@@:
431
        add     ebx, 288 shl 16
432
        mcall   4,, 0x80000000,, 32     ; draw the text
433
        movzx   edx, bx                 ; get y coordinate
434
        add     edx, 0x0014000A         ; add 10 to y coordinate and set x coordinate to 20
435
 
436
;------------------------------------------------------------------
437
; Print Driver Name
438
;------------------------------------------------------------------
439
        push    edx
440
        add     ebx, 120 shl 16
441
        push    ebx
442
 
443
        call    get_drv_ptr
444
        mov     edx, eax
445
        pop     ebx
446
        mcall   4,,0x80000000          ; lets print the vendor Name
447
        pop     edx
448
        ret
449
 
450
get_drv_ptr:
451
        mov     eax, driverlist        ; eax will be the pointer to latest driver title
452
        mov     ebx, driverlist        ; ebx is the current pointer
453
        mov     ecx, dword[PCI_Vendor] ; the device/vendor id of we want to find
454
 
455
       driverloop:
456
        inc     ebx
457
 
458
        cmp     byte[ebx],0
459
        jne     driverloop
460
 
461
        inc     ebx                    ; the device/vendor id list for the driver eax is pointing to starts here.
462
 
463
       deviceloop:
464
        cmp     dword[ebx],0
465
        je      nextdriver
466
 
467
        cmp     dword[ebx],ecx
468
        je      driverfound
469
 
4788 hidnplayr 470
        add     ebx, 4
3545 hidnplayr 471
        jmp     deviceloop
472
 
473
       nextdriver:
4788 hidnplayr 474
        add     ebx, 4
3545 hidnplayr 475
 
476
        cmp     dword[ebx],0
477
        je      nodriver
478
 
479
        mov     eax,ebx
480
        jmp     driverloop
481
 
482
       nodriver:
483
        mov     eax, lbl_none          ; lets print the vendor Name
484
        ret
485
 
486
       driverfound:
487
        ret
488
 
489
include 'vendors.inc'
490
include 'drivers.inc'
491
 
492
 
493
;------------------------------------------------------------------
494
; DATA AREA
495
 
496
 
497
DATA
498
 
499
 
500
Form:   dw 800 ; window width (no more, special for 800x600)
501
        dw 100 ; window x start
502
        dw 220 ; window height
503
        dw 100 ; window y start
504
 
505
title           db 'Network Driver Control Center', 0
506
 
507
caption         db 'Vendor Device Bus  Dev  Rev  IRQ   Company                                         Description         DRIVER',0
508
nonefound       db 'No compatible devices were found!',0
509
btn_start       db 'Start device',0
510
btn_reset       db 'Reset device',0
511
btn_stop        db 'Stop device',0
512
lbl_none        db 'none',0
513
load_error      db 'Could not load driver!',0
514
 
515
hardwareinfo:
516
   .type        db 1 ; pci
517
   .pci_bus     db ?
518
   .pci_dev     db ?
519
 
520
 
521
IM_END:
522
 
523
;------------------------------------------------------------------
524
; UNINITIALIZED DATA AREA
525
 
526
 
527
IOCTL:
528
   .handle      dd ?
529
   .io_code     dd ?
530
   .input       dd ?
531
   .inp_size    dd ?
532
   .output      dd ?
533
   .out_size    dd ?
534
 
535
drivernumber    db ?
536
MAC             dp ?
537
 
538
 
539
type            db ?
540
selected        dw ?
541
V_Bus           db ?
542
V_Dev           db ?
543
PCI_Version     dw ?
544
PCI_LastBus     db ?
4788 hidnplayr 545
; Dont change order
3545 hidnplayr 546
PCI_Vendor      dw ?
547
PCI_Device      dw ?
4788 hidnplayr 548
 
3545 hidnplayr 549
PCI_Bus         db ?
550
PCI_Dev         db ?
551
PCI_Rev         db ?
4788 hidnplayr 552
; Dont change order
3545 hidnplayr 553
PCI_Class       db ?
554
PCI_SubClass    db ?
555
PCI_Interface   db ?
556
PCI_IRQ         db ?
557
 
558
Proc_Info       process_information
559
 
560
param           rb 1024
561
 
562
 
563
I_END: