Subversion Repositories Kolibri OS

Rev

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