Subversion Repositories Kolibri OS

Rev

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

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