Subversion Repositories Kolibri OS

Rev

Rev 5166 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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