Subversion Repositories Kolibri OS

Rev

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