Subversion Repositories Kolibri OS

Rev

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