Subversion Repositories Kolibri OS

Rev

Rev 1253 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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