Subversion Repositories Kolibri OS

Rev

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