Subversion Repositories Kolibri OS

Rev

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

  1. ;***************************************************************
  2. ; project name:    PCI Device Enumeration
  3. ; target platform: KolibriOS
  4. ; compiler:        flat assembler 1.68
  5. ; version:         2.21
  6. ; last update:     December 2007
  7. ; maintained by:   Jason Delozier (cordata51@hotmail.com)
  8. ;                  Sergey Kuzmin (kuzmin_serg@list.ru)
  9. ;                  Mihailov Ilia (ghost.nsk@gmail.com)
  10. ;                  Artem Jerdev  (art_zh@yahoo.com)
  11. ; project site:    http://www.coolthemes.narod.ru/pcidev.html
  12. ;***************************************************************
  13. ;Summary: This program will attempt to scan the PCI Bus
  14. ;        and display basic information about each device
  15. ;        connected to the PCI Bus.
  16. ;***************************************************************
  17. include '../../../macros.inc'
  18. ;include 'macros.inc'
  19.  
  20. MEOS_APP_START
  21. CODE
  22.         call draw_window
  23.  
  24. still:  mcall   10                      ; wait here for event
  25.         dec     eax                     ; redraw request ?
  26.         jz      red
  27.         dec     eax                     ; key in buffer ?
  28.         jz      key
  29.         dec     eax                     ; button in buffer ?
  30.         jz      button
  31.         jmp     still
  32.  
  33. red:                                    ; redraw
  34.         mcall   9, Proc_Info, -1        ; window redraw requested so get new window coordinates and size
  35.         mov     eax, [Proc_Info.box.left]; store the window coordinates into the Form Structure
  36.         mov     [Form + 2], ax          ; x start position
  37.         mov     eax, [Proc_Info.box.top];
  38.         mov     [Form + 6], ax          ; ystart position
  39.         mov     eax, [Proc_Info.box.width]      ;
  40.         mov     [Form], ax              ; window width
  41.         mov     eax, [Proc_Info.box.height]     ;
  42.         mov     [Form + 4] ,ax          ; window height
  43.         call    draw_window             ; go redraw window now
  44.         jmp     still
  45.  
  46. key:                                    ; key
  47.         mcall   2                       ; just read it and ignore
  48.         jmp     still
  49. button:                                 ; button
  50.         mcall   17                      ; get id
  51.         cmp     ah, 1                   ; button id = 1 ?
  52.         jne     still
  53.         mcall   -1                      ; close this program
  54.  
  55. draw_window:
  56.         mov     byte [total], 0
  57.         mcall   12, 1                   ; start of draw
  58.         ; DRAW WINDOW
  59.         mcall   0, dword [Form], dword [Form + 4], 0x13ffffff, 0x805080d0, title
  60.         ; Insert horizontal bars  in list area
  61.         mov     eax, 13                 ; draw bar system function
  62.         mov     ebx, 18                 ; set Xstart position of bar
  63.         shl     ebx, 16                 ;
  64.         mov     bx, word [Form] ; get width of window
  65.         sub     bx, 32                  ; bar is 32 pixels shorter then window width
  66.         mov     ecx, 119 * 65536 + 10   ; set Ystart(109) and Height(10) of bar   109
  67.         mov     edx, 0xC0C0C0           ; set color of bar
  68. again:  ;begin draw bar loop
  69.         mcall                           ; draw bar to window area
  70.         shr     ecx, 16                 ; move the Ystart position to working area
  71.         add     ecx, 34                 ; add 34 pixels to Y Start (moves bar down)
  72.         cmp     cx, word [Form + 4]     ; is the Ystart position outside of window area
  73.         jae     nomo                    ; if so stop drawing bars
  74.         sub     ecx, 14                 ; if not, we only need 20 pixels between bar tops
  75.         shl     ecx, 16                 ; set that values as Ystart
  76.         add     ecx, 10                 ; Bar Height is always 10 pixels
  77.         jmp     again                   ; draw another bar
  78. nomo:                                   ;done drawing bars here
  79.         ; start PCI stuff
  80.         call    Get_PCI_Info            ; get pci version and last bus, scan for and draw each pci device
  81.  
  82.         ; Window inteface
  83.         mov     cx, [PCI_Version]
  84.         add     ch, '0'
  85.         mov     [PCIWin + 85], ch       ; 0xBADCODE but it works !
  86.         mov     ch, cl
  87.         shr     cl, 4
  88.         and     ch, 0x0f
  89.         add     cx, '00'
  90.         mov     [PCIWin + 87], cx
  91.         mov     cl, [PCI_LastBus]       ; will only work if [PCI_LastBus] < 10
  92.         add     cl, '0'
  93.         mov     [PCIWin + 106], cl
  94.  
  95.         mov     edx, PCIWin
  96.         mov     ebx, 20 * 65536 + 25    ; x start, ystart of text
  97.         mov     ecx, 0x224466           ; color of text
  98.         mov     eax, 4
  99. @@:     movzx   esi, byte[edx]
  100.         inc     edx
  101.         mcall
  102.         add     ebx, 10
  103.         add     edx, esi
  104.         cmp     byte[edx], -1
  105.         jne     @b
  106.         ; Quantity of devices...
  107.         movzx   ecx, byte [total]       ; number to draw
  108.         mcall   47, 0x00020000,,150 * 65536 + 65, 0x224466
  109.        
  110.         mov     ah, [MMIO_allowed]
  111.         or      ah, ah
  112.         jz      @f
  113.         mov     ah, [MMIO_Bus]  ; =255 if MMIO disabled / not found
  114.         and     ah, 0x7f
  115.         inc     ah
  116.         jo      @f     
  117.         call    Try_MMIO
  118. @@:
  119.         mcall   12, 2                   ; end of draw
  120.         ret
  121.  
  122. ;------------------------------------------------------------------
  123. ;* Gets the PCI Version and Last Bus
  124. Get_PCI_Info:
  125.         mcall   62, 0
  126.         mov     word [PCI_Version], ax
  127.         mcall   62, 1
  128.         mov     byte [PCI_LastBus], al
  129.         ;----------------------------------------------------------
  130.         ;* Get all devices on PCI Bus
  131.         cmp     al, 0xff                ; 0xFF means no pci bus found
  132.         jne     Pci_Exists              ;
  133.         ret                             ; if no bus then leave
  134. Pci_Exists:
  135.         mov     byte [V_Bus], 0         ; reset varibles
  136.         mov     byte [V_Dev], 0         ;
  137.         mov     edx,  20 * 65536 + 110  ; set start write position
  138. Start_Enum:
  139.         mov     bl, 6                   ; get a dword
  140.         mov     bh, byte [V_Bus]        ; bus of pci device
  141.         mov     ch, byte [V_Dev]        ; device number/function
  142.         mov     cl, 0                   ; offset to device/vendor id
  143.         mcall   62                      ; get ID's
  144.  
  145.         cmp     ax, 0                   ; Vendor ID should not be 0 or 0xFFFF
  146.         je      nextDev                 ; check next device if nothing exists here
  147.         cmp     ax, 0xffff              ;
  148.         je      nextDev                 ;
  149.  
  150.         mov     word [PCI_Vendor], ax   ; There is a device here, save the ID's
  151.         shr     eax, 16                 ;
  152.         mov     word [PCI_Device], ax   ;
  153.         mov     bl, 4                   ; Read config byte
  154.         mov     bh, byte [V_Bus]        ; Bus #
  155.         mov     ch, byte [V_Dev]        ; Device # on bus
  156.         mov     cl, 0x08                ; Register to read (Get Revision)
  157.         mcall   62                      ; Read it
  158.         mov     byte [PCI_Rev], al      ; Save it
  159.         mov     cl, 0x0b                ; Register to read (Get class)
  160.         mcall   62                      ; Read it
  161.  
  162.         mov     byte [PCI_Class], al    ; Save it
  163.         mov     cl, 0x0a                ; Register to read (Get Subclass)
  164.         mcall   62                      ; Read it
  165.         mov     byte [PCI_SubClass], al; Save it
  166. ; by Mario79 august 2006
  167.         mov     cl, 0x09                ; Register to read (Get Interface)
  168.         mcall   62                      ; Read it
  169.         mov  [PCI_Interface], al        ; Save it
  170. ;
  171. ; by Ghost april 2007
  172.         mov     cl, 0x3c                ; Register to read (Get IRQ)
  173. @@:     mcall   62                      ; Read it
  174.         mov     [PCI_IRQ], al           ; Save it
  175. ; by CleverMouse juny 2011
  176.         mov     cl, 0x0e
  177.         mcall   62
  178.         push    eax
  179.         inc     byte [total]            ; one more device found
  180.         call    Print_New_Device        ; print device info to screen
  181. ; don't scan for nonzero functions if zero function says "not multifunction device"
  182.         pop     eax
  183.         test    al, al
  184.         js      nextDev
  185.         test    byte [V_Dev], 7
  186.         jnz     nextDev
  187.         or      byte [V_Dev], 7
  188. nextDev:
  189.         inc     byte [V_Dev]            ; next device on this bus
  190.         jnz     Start_Enum              ; jump until we reach zero
  191.         ;(used to be JNO which caused bug!!! 30-4-2006, JMD)
  192.         mov     byte [V_Dev], 0         ; reset device number
  193.         inc     byte [V_Bus]            ; next bus
  194.         mov     al, byte [PCI_LastBus]  ; get last bus
  195.         cmp     byte [V_Bus], al        ; was it last bus
  196.         jbe     Start_Enum              ; if not jump to keep searching
  197.         ret
  198.  
  199. no_ummio_allowed:
  200.         xor     al,al
  201.         mov     [MMIO_allowed],al               ; re-enter the subroutine
  202. ;------------------------------------------------------------------
  203. ;* Print device info to screen
  204.  
  205. Print_New_Device:
  206.         xor     esi, esi                ; default text color
  207.         mov     cl, [MMIO_allowed]
  208.         or      cl,cl
  209.         jz      no_ummio_here
  210.         mov     ch, byte [V_Bus]
  211.         mov     cl, byte [V_Dev]
  212.         mcall   62, 11          ; detect uMMIO
  213.         and     ax,0x7fff
  214.         inc     ax                      ; -1 returned?
  215.         jo      no_ummio_allowed
  216.         inc     ax                      ; -2 returned?
  217.         jo      no_ummio_here
  218.         inc     ax                      ; -3 returned?
  219.         jo      no_ummio_here
  220.         mov     esi, 0x990033   ; highlighted text color
  221.         mov     bh, byte [V_Bus]
  222.         mov     bl, byte [V_Dev]
  223.         mov     byte [MMIO_Bus], bh
  224.         mov     byte [MMIO_Dev], bl
  225.         add     bh,'0'
  226.         mov     [PCIWin + 129], bh      ; uMMIO bus
  227.         mov     al, bl
  228.         shr     al, 1
  229.         shr     al, 1
  230.         shr     al, 1
  231.         add     al,'0'
  232.         mov     [PCIWin + 131], al      ; uMMIO device
  233.         and     bl, 7
  234.         add     bl, '0'
  235.         mov     [PCIWin + 133], bl      ; uMMIO function
  236.  
  237. no_ummio_here:
  238.         movzx   ecx,word [PCI_Vendor]   ; Pointer to number to be written
  239.         mcall   47, 0x00040100          ; Write Vendor ID
  240.         and     edx, 0xFFFF             ;*****************************************
  241.         or      edx, 54 * 65536 ; X start becomes 54
  242.         movzx   ecx, word [PCI_Device]  ; get Vendor ID
  243.         mcall                           ; Draw Vendor ID to Window
  244.         and     edx, 0xFFFF             ;*****************************************
  245.         or      edx, 98 * 65536 ; X start becomes 98
  246.         movzx   ecx, byte [V_Bus]       ; get bus number
  247.         mcall   ,0x00020100             ; draw bus number to screen
  248.         and     edx, 0xFFFF             ;*****************************************
  249.         or      edx, 128 * 65536        ; X start becomes 128
  250.         movzx   ecx, byte [V_Dev]       ; get device number
  251.         shr     ecx, 3                  ; device number is bits 3-7
  252.         mcall                           ; Draw device Number To Window
  253.  
  254.         and     edx, 0xFFFF             ;*****************************************
  255.         or      edx, 155 * 65536        ; X start becomes 155
  256.         movzx   ecx, byte [V_Dev]       ; get Function number
  257.         and     ecx, 7                  ; function is first 3 bits
  258.         mcall                           ; Draw Function Number To Window
  259.         and     edx, 0xFFFF             ;*****************************************
  260.         or      edx, 179 * 65536        ; X start becomes 179
  261.         movzx   ecx, byte [PCI_Rev]     ; get revision number
  262.         mcall                           ; Draw Revision to screen
  263.         and     edx, 0xFFFF             ;*****************************************
  264.         or      edx, 215*65536          ; X start becomes 215
  265.         movzx   ecx, byte [PCI_Class]   ; get PCI_Class
  266.         mcall                           ; Draw Class to screen
  267.         and     edx, 0xFFFF             ;*****************************************
  268.         or      edx, 250*65536          ; X start becomes 250
  269.         movzx   ecx, byte [PCI_SubClass]; get sub class
  270.         mcall                           ; Draw Sub Class to screen
  271. ; from Mario79 august 2006
  272.         and     edx, 0xFFFF             ;*****************************************
  273.         or      edx, 280 * 65536        ; X start becomes 280
  274.         movzx   ecx, [PCI_Interface]    ; get Interface
  275.         mcall
  276. ;
  277. ; from Ghost april 2007                 ;*****************************************
  278.         movzx   ecx, [PCI_IRQ]          ; get Interface
  279.         cmp     cl, 0x0f                ; IRQ between 0..15
  280.         ja      @f
  281.         and     edx, 0xFFFF
  282.         or      edx, 310 * 65536        ; X start becomes 310
  283.         mcall
  284. @@:
  285. ;
  286.         ;Write Names
  287.         movzx   ebx, dx         ; Set y position
  288.         or      ebx, 340 * 65536        ; set Xposition to 340
  289.  
  290. ;------------------------------------------------------------------
  291. ; Prints the Vendor's Name based on Vendor ID
  292. ;
  293. ; Modified on ??-04-2007 by Ghost for size
  294. ;------------------------------------------------------------------
  295.         mov     edx, VendorsTab
  296.         mov     cx, word[PCI_Vendor]
  297.  
  298. .fn:    mov     ax, [edx]
  299.         add     edx, 6
  300.         test    ax, ax
  301.         jz      .find
  302.         cmp     ax, cx
  303.         jne     .fn
  304. .find:  mov     edx, [edx - 4]
  305.         mcall   4,, 0x80000000          ; lets print the vendor Name
  306.  
  307. ;------------------------------------------------------------------
  308. ; Get description based on Class/Subclass
  309. ;
  310. ; Modified on ??-04-2007 by Ghost for size
  311. ;------------------------------------------------------------------
  312.         mov     eax, dword [PCI_Class]
  313.         and     eax, 0xffffff
  314.         xor     edx, edx
  315.         xor     esi, esi
  316. .fnc:   inc     esi
  317.         mov     ecx, [Classes + esi * 8 - 8]
  318.         cmp     cx, 0xffff
  319.         je      .endfc
  320.         cmp     cx, ax
  321.         jne     .fnc
  322.         test    ecx, 0xff000000
  323.         jz      @f
  324.         mov     edx, [Classes + esi * 8 - 4]
  325.         jmp     .fnc
  326. @@:     cmp     eax, ecx
  327.         jne     .fnc
  328.         xor     edx, edx
  329. .endfc: test    edx, edx
  330.         jnz     @f
  331.         mov     edx, [Classes + esi * 8 - 4]
  332. @@:
  333.         and     ebx, 0x0000FFFF         ; clear X position
  334.         or      ebx, 0x24E0000          ; set X position to 590 pixels
  335.         mcall   4,, 0x80000000,, 32     ; draw the text
  336.         movzx   edx, bx         ; get y coordinate
  337.         add     edx, 0x0014000A         ; add 10 to y coordinate and set x coordinate to 20
  338.         mov     [gr_pos], edx
  339.         ret
  340. ;------------------------------------------------------------------
  341. ; Get the user-MMIO related info
  342. ;
  343. ; Added on ??-12-2009 by art_zh
  344. ;------------------------------------------------------------------
  345. Try_MMIO:
  346.         xor     ebx, ebx
  347.         mov     edx, ebx
  348.         mov     bh, [MMIO_BAR]
  349.         or      bx, 12                  ; function 12
  350.         mov     ecx, 4096               ; =1 page to map
  351.         mcall   62
  352.         mov     [MMIO_Map], eax         ; store MMIO lin.addr.
  353.         mov     ecx, 0x80990022         ; print color : red
  354.         add     bh, '0'
  355.         cmp     eax, -3
  356.         jne     @f
  357.         mov     [bar_um+3], bh
  358.         mov     ebx, [gr_pos]
  359.         mov     edx, bar_um
  360.         mcall   4
  361.         jmp     mmio_next_bar
  362. @@:
  363.         cmp     eax, -4
  364.         jne     @f
  365.         mov     [bar_io+3], bh
  366.         mov     ebx, [gr_pos]
  367.         mov     edx, bar_io
  368.         mcall   4
  369.         jmp     mmio_next_bar
  370. @@:
  371.         cmp     bh, '6'         ; expansion ROM ?
  372.         je      @f
  373.         mov     [bar_ram+3], bh
  374.         mov     ebx, [gr_pos]
  375.         mov     edx, bar_ram
  376.         mcall   4
  377.         jmp     mmio_dump
  378. @@:
  379.         mov     ebx, [gr_pos]
  380.         mov     edx, bar_rom
  381.         mcall   4
  382.  
  383. mmio_dump:
  384.         mov     edx, [MMIO_Map]
  385.         mov     esi, 64
  386.         mov     ecx, 0x099              ; dump color : blue
  387.         add     ebx, 10
  388.         mov     [gr_pos], ebx
  389.         mcall   4
  390.         mov     ecx, [MMIO_Map]         ; release the tried page
  391.         mcall   62,13
  392.  
  393. mmio_next_bar:
  394.         mov     bh, [MMIO_BAR]
  395.         inc     bh
  396.         cmp     bh,7
  397.         je      @f
  398.         mov     [MMIO_BAR], bh
  399.         add     [gr_pos], 10
  400.         jmp     Try_MMIO
  401.  
  402. @@:
  403.         xor     bh,bh
  404.         mov     [MMIO_BAR], bh
  405.         ret
  406.  
  407.  
  408. include 'vendors.inc'
  409. ;------------------------------------------------------------------
  410. ; DATA AREA
  411. DATA
  412.  
  413.  
  414. Form:   dw 800 ; window width (no more, special for 800x600)
  415.         dw 100 ; window x start
  416.         dw 620 ; window height
  417.         dw 20 ; window y start
  418.  
  419. title   db 'PCI Device Enumerator v 2.21 by J.Delozier, S.Kuzmin, V.Hanla, M.Zakiyanov, A.Jerdev', 0
  420.  
  421. PCIWin mls \
  422.         '   Don`t forget to enable PCI Access to Applications in Setup Menu.',\
  423.         '',\
  424.         'PCI Version  = x.xx; Last PCI Bus = x',\
  425.         'User MMIO channel = 0F.F:F ',\
  426.         'Number of PCI units =',\
  427.         '',\
  428.         'VenID DevID Bus# Dev# Fnc Rev  Class  Subclass/ IRQ                 Company                      Description',\
  429.         '                                      Interface',\
  430.         '----- ----- ---- ---- --- ---  -----  --------- --- ------------------------------------------ ----------------'
  431.  
  432. bar_ram db 'BARx: MMIO block', 0
  433. bar_io  db 'BARx: IO ports',0
  434. bar_um  db 'BARx: unmapped',0
  435. bar_rom db 'BAR6: Expansion ROM', 0
  436.  
  437. ;------------------------------------------------------------------
  438. ; UNINITIALIZED DATA AREA
  439. UDATA
  440.  
  441. total           db ?
  442. V_Bus           db ?
  443. V_Dev           db ?
  444. PCI_Version     dw ?
  445. PCI_LastBus     db ?
  446. PCI_Device      dw ?
  447. PCI_Vendor      dw ?
  448. PCI_Bus         db ?
  449. PCI_Dev         db ?
  450. PCI_Rev         db ?
  451. ; don`t change order!!!
  452. PCI_Class       db ?
  453. PCI_SubClass    db ?
  454. PCI_Interface   db ?
  455. PCI_IRQ         db ?
  456.  
  457. align 4
  458. MMIO_Bus        db 255
  459. MMIO_Dev        db 255
  460. MMIO_BAR        db 0
  461. MMIO_allowed    db 1
  462. MMIO_Map        rd 8
  463.  
  464. gr_pos          dd ?
  465.  
  466. Proc_Info       process_information
  467. MEOS_APP_END
  468.  
  469.