Subversion Repositories Kolibri OS

Rev

Rev 2364 | 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. format binary as ""
  10.  
  11. use32
  12.                org    0x0
  13.  
  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
  21.  
  22. type_ethernet equ 1
  23.  
  24. include '../macros.inc'
  25. include 'proc32.inc'
  26. include 'struct.inc'
  27.  
  28. START:
  29.         ; first, check boot parameters
  30.  
  31.         cmp     byte[param], 0
  32.         je      .noparams
  33.  
  34.         mcall 40, 0
  35.  
  36.  
  37.         push    .launch_zeroconf_exit
  38.         cmp     byte[param], 'A'        ; A for All
  39.         je      Get_PCI_Info
  40.  
  41.         cmp     byte[param], 'F'        ; F for First
  42.         je      Get_PCI_Info
  43.  
  44.         ret
  45.  
  46. .launch_zeroconf_exit:
  47.         mcall   70, zeroconf
  48.         mcall   -1
  49.  
  50. .noparams:
  51.         call draw_window
  52.  
  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
  61.  
  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
  74.  
  75. key:                                    ; key
  76.         mcall   2                       ; just read it and ignore
  77.         jmp     still
  78. button:                                 ; button
  79.         mcall   17                      ; get id
  80.  
  81.         cmp     ah, 1                   ; button id = 1 ?
  82.         jne     @f
  83. exit:   mcall   -1                      ; close this program
  84.        @@:
  85.         cmp     eax,0x0000ff00
  86.         jg      load_drv
  87.  
  88.         cmp     ah, 4
  89.         je      hook
  90.  
  91.         cmp     ah, 5
  92.         je      reset
  93.  
  94.         cmp     ah, 6
  95.         je      unload
  96.  
  97.         jmp     still
  98.  
  99.  
  100. load_drv:
  101.         shr     eax, 16
  102.         mov     word [selected], ax
  103.  
  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
  109.  
  110.         mov     word [PCI_Vendor], ax
  111.         shr     eax, 16
  112.         mov     word [PCI_Device], ax
  113.         call    get_drv_ptr
  114.  
  115.         mov     ecx, eax
  116.         mcall   68, 16
  117.  
  118.         mov     [IOCTL.handle], eax
  119.  
  120.         call    draw_window
  121.  
  122.         cmp     [IOCTL.handle], 0
  123.         jne     still
  124.  
  125.         mcall   4, 20 shl 16 + 30, 1 shl 31 + 0x00ff0000 , load_error
  126.  
  127.         jmp     still
  128.  
  129.  
  130. hook:
  131.         mov     ax , [selected]
  132.         test    ax , ax
  133.         jz      still
  134.  
  135.         mov     [hardwareinfo.pci_dev], al
  136.         mov     [hardwareinfo.pci_bus], ah
  137.  
  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
  143.  
  144.         mcall   68, 17, IOCTL
  145.  
  146.         mov     byte[drivernumber], al
  147.  
  148.         jmp     still
  149.  
  150. reset:
  151.         movzx   ebx, byte[drivernumber]
  152.         mcall   74,,2
  153.  
  154.         jmp     still
  155.  
  156. unload:
  157.         movzx   ebx, byte[drivernumber]
  158.         mcall   74,,3
  159.  
  160.         jmp     still
  161.  
  162. draw_window:
  163.         mcall   12, 1                   ; start of draw
  164.         mcall   0, dword [Form], dword [Form + 4], 0x13ffffff, 0x805080d0, title
  165.  
  166.         mcall   8, 136 shl 16 + 100, 35 shl 16 + 18, 4, 0x00007f00       ; SLIP
  167.  
  168.         call    Get_PCI_Info            ; get pci version and last bus, scan for and draw each pci device
  169.  
  170.         cmp     edx, 20 shl 16 + 110
  171.         je      .nonefound
  172.  
  173.         mcall   4, 20 shl 16 + 100, 1 shl 31 + 0x00000000 , caption
  174.  
  175.         cmp     [selected], 0
  176.         jz      .done
  177.         cmp     [IOCTL.handle] ,0
  178.         jz      .done
  179.  
  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
  183.  
  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
  187.  
  188. ;        mcall   , 140 shl 16 + 62, 1 shl 31 + 0x00000000 , devicename
  189.  
  190.         jmp     .done
  191.  
  192. .nonefound:
  193.         mcall   4, 20 shl 16 + 30, 1 shl 31 + 0x00ff0000 , nonefound
  194. .done:
  195.         mcall   12, 2                   ; end of draw
  196.         ret
  197.  
  198.  
  199.  
  200.  
  201.  
  202. ;------------------------------------------------------------------
  203. ;* Gets the PCI Version and Last Bus
  204. Get_PCI_Info:
  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
  215. Pci_Exists:
  216.         mov     byte [V_Bus], 0         ; reset varibles
  217.         mov     byte [V_Dev], 0         ;
  218. Start_Enum:
  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
  224.  
  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                 ;
  229.  
  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
  252. ;
  253. ;        inc     byte [total]            ; one more device found
  254.  
  255.         cmp     byte [PCI_Class],2
  256.         jne     nextDev
  257.  
  258.         cmp     byte[param], 0
  259.         jne     load_and_start
  260.  
  261.         call    Print_New_Device        ; print device info to screen
  262.  
  263. nextDev:
  264.         add     byte [V_Dev], 8         ; lower 3 bits are the function number
  265.  
  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
  273.  
  274.  
  275.  
  276. load_and_start:
  277.  
  278.         call    get_drv_ptr
  279.         cmp     eax, lbl_none
  280.         je      .next
  281.  
  282.         mov     ecx, eax
  283.         mcall   68, 16
  284.         test    eax, eax
  285.         jz      .next
  286.         mov     [IOCTL.handle], eax
  287.  
  288.         mov     al, [V_Dev]
  289.         mov     [hardwareinfo.pci_dev], al
  290.         mov     al, [V_Bus]
  291.         mov     [hardwareinfo.pci_bus], al
  292.  
  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
  298.  
  299.         mcall   68, 17, IOCTL
  300.  
  301.        .next:
  302.         cmp     byte[param], 'A'
  303.         je      nextDev
  304.         jmp     exit
  305.  
  306.  
  307.  
  308. ;------------------------------------------------------------------
  309. ;* Print device info to screen
  310. Print_New_Device:
  311.  
  312.         push    edx                     ; Magic ! (to print a button...)
  313.  
  314.         mov     ebx, 18 shl 16
  315.         mov     bx , [Form]
  316.         sub     bx , 36
  317.  
  318.         mov     cx , dx
  319.         dec     cx
  320.         shl     ecx, 16
  321.         add     ecx, 9
  322.  
  323.         movzx   edx, byte [V_Bus]
  324.         shl     dx , 8
  325.         mov     dl , byte [V_Dev]
  326.  
  327.         mov     esi, 0x0000c0ff        ; color: yellow if selected, blue otherwise
  328.         cmp     word [selected], dx
  329.         jne     @f
  330.         mov     esi, 0x00c0c000
  331.        @@:
  332.  
  333.         shl     edx, 8
  334.         or      dl , 0xff
  335.  
  336.         mcall   8
  337.         pop     edx
  338.  
  339.         xor     esi, esi                ; Color of text
  340.         movzx   ecx, word [PCI_Vendor]  ; number to be written
  341.         mcall   47, 0x00040100          ; Write Vendor ID
  342.  
  343.         add     edx, (4*6+18) shl 16
  344.         movzx   ecx, word [PCI_Device]  ; get Vendor ID
  345.         mcall                           ; Draw Vendor ID to Window
  346.  
  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
  350.  
  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
  355.  
  356.         add     edx, (2*6+18) shl 16
  357.         movzx   ecx, byte [PCI_Rev]     ; get revision number
  358.         mcall                           ; Draw Revision to screen
  359.  
  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
  365. @@:
  366. ;
  367.         ;Write Names
  368.         movzx   ebx, dx                 ; Set y position
  369.         or      ebx, 230 shl 16         ; set Xposition
  370.  
  371. ;------------------------------------------------------------------
  372. ; Prints the Vendor's Name based on Vendor ID
  373. ;------------------------------------------------------------------
  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
  385.  
  386. ;------------------------------------------------------------------
  387. ; Get description based on Class/Subclass
  388. ;------------------------------------------------------------------
  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
  414.  
  415. ;------------------------------------------------------------------
  416. ; Print Driver Name
  417. ;------------------------------------------------------------------
  418.         push    edx
  419.         add     ebx, 120 shl 16
  420.         push    ebx
  421.  
  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
  428.  
  429. get_drv_ptr:
  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
  433.  
  434.        driverloop:
  435.         inc     ebx
  436.  
  437.         cmp     byte[ebx],0
  438.         jne     driverloop
  439.  
  440.         inc     ebx                    ; the device/vendor id list for the driver eax is pointing to starts here.
  441.  
  442.        deviceloop:
  443.         cmp     dword[ebx],0
  444.         je      nextdriver
  445.  
  446.         cmp     dword[ebx],ecx
  447.         je      driverfound
  448.  
  449.         add     ebx,4
  450.         jmp     deviceloop
  451.  
  452.        nextdriver:
  453.         add     ebx,4
  454.  
  455.         cmp     dword[ebx],0
  456.         je      nodriver
  457.  
  458.         mov     eax,ebx
  459.         jmp     driverloop
  460.  
  461.        nodriver:
  462.         mov     eax, lbl_none          ; lets print the vendor Name
  463.         ret
  464.  
  465.        driverfound:
  466.         ret
  467.  
  468. include 'vendors.inc'
  469. include 'drivers.inc'
  470.  
  471.  
  472. ;------------------------------------------------------------------
  473. ; DATA AREA
  474.  
  475.  
  476. DATA
  477.  
  478.  
  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
  483.  
  484. title   db 'Network Driver Control Center', 0
  485.  
  486. caption db 'Vendor Device Bus  Dev  Rev  IRQ   Company                                         Description         DRIVER',0
  487. nonefound db 'No compatible devices were found!',0
  488. btn_start db 'Start device',0
  489. btn_reset db 'Reset device',0
  490. btn_stop db 'Stop device',0
  491. lbl_none db 'none',0
  492. load_error db 'Could not load driver!',0
  493.  
  494. devicename     db 'test'
  495. rb 64
  496.                 db 0
  497.  
  498. hardwareinfo:
  499.    .type        db 1 ; pci
  500.    .pci_bus     db ?
  501.    .pci_dev     db ?
  502.  
  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
  510.  
  511.  
  512. IM_END:
  513.  
  514. ;------------------------------------------------------------------
  515. ; UNINITIALIZED DATA AREA
  516.  
  517.  
  518. IOCTL:
  519.    .handle      dd ?
  520.    .io_code     dd ?
  521.    .input       dd ?
  522.    .inp_size    dd ?
  523.    .output      dd ?
  524.    .out_size    dd ?
  525.  
  526. drivernumber    db ?
  527. MAC             dp ?
  528.  
  529.  
  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 ?
  541. ; don`t change order!!!
  542. PCI_Class       db ?
  543. PCI_SubClass    db ?
  544. PCI_Interface   db ?
  545. PCI_IRQ         db ?
  546.  
  547. Proc_Info       process_information
  548.  
  549. param           rb 1024
  550.  
  551.  
  552. I_END: