Subversion Repositories Kolibri OS

Rev

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

  1. ;***************************************************************
  2. ; project name:    PCI Device Enumeration
  3. ; target platform: KolibriOS and MenuetOS
  4. ; compiler:        flat assmebler 1.63.2
  5. ; version:         1.31
  6. ; last update:     13(th) May 2006
  7. ; maintained by:   Jason Delozier (cordata51)
  8. ; e-mail:          cordata51@hotmail.com
  9. ; project site:    http://www.asmfreaks.com/menuetos
  10. ;***************************************************************
  11. ;Summary: This program will attempt to scan the PCI Bus
  12. ;        and display basic information about each device
  13. ;        connected to the PCI Bus.
  14. ;***************************************************************
  15. ;HISTORY:
  16. ;keep dates in european format (dd/mm/yyyy), please
  17. ; '!' means big changes
  18. ; to-do:
  19. ;PCI version should be normalized (0210->02.10)
  20. ;----------------------------------------------------------------
  21. ;1.31: PCIDEV   13/05/2006
  22. ;Author:    Jason Delozier <cordata51@hotmail.com>
  23. ;Features:
  24. ;           fixed
  25. ;                 * ! bug in Company Name look up code that would cause Unknown Name errors.
  26. ;                 * ! possible bugs, many instructions missing byte, word, dword prefixes
  27. ;                 * ! possible bug which could have occured after removing  "PREVIOUSVERSIONLIST"
  28. ;                     entry in loop up code and not fixing jump parameters.
  29. ;           added
  30. ;                 *  comments to various parts of the code
  31. ;           optimized
  32. ;                 * various parts of the source, too many to remember and mention.
  33. ;                 * changed entries for Subclasses in vendors.inc to Byte format, saves a little space.
  34. ;----------------------------------------------------------------
  35. ;1.30: PCIDEV   11/05/2006
  36. ;Author:    Sergey Kuzmin aka Wildwest <kuzmin_serg@list.ru>
  37. ;Features:
  38. ;           added
  39. ;                * 3 new vendor id's (ESS from Madis Kalme and 2 id's
  40. ;                  forgotten from 1.15 release: Broadcom -SiByte and Chaintech Comp.)
  41. ;                       changed
  42. ;                            * I don't know why other devs (Jason or Victor) changed window style
  43. ;                  to old ugly one, so I changed it back to skinned type 3.
  44. ;                * the same goes to the use of macroc.inc - it is enabled again.
  45. ;           deleted
  46. ;                * there is no more label "PREVIOUSVERSIONLIST" - id's moved to the
  47. ;                  appropriate parts of global list.
  48. ;----------------------------------------------------------------
  49. ;1.29: PCIDEV   30/04/2006
  50. ;Author:    Jason Delozier <cordata51@hotmail.com>
  51. ;Features:
  52. ;           fixed
  53. ;                 * ! bug that would not allow devices with device
  54. ;                   numbers > 16 to be displayed.
  55. ;           added
  56. ;                 * ! another heading called "FNC" (function) which allows
  57. ;                   the multipurpose Device/Function varible to be split and
  58. ;                   displayed to the user properly.
  59. ;                 * horizontal bars to display for easier reading.
  60. ;           optimized
  61. ;                 * vendor/description search routines for speed and space.
  62. ;----------------------------------------------------------------
  63. ;1.25: PCIDEV   02/10/2005
  64. ;Author:    Sergey Kuzmin aka Wildwest <kuzmin_serg@list.ru>
  65. ;Features:
  66. ;            changed
  67. ;                                       * ! Description is based on Class and SubClass
  68. ;                     now (PCI 3.0). The Names of Classes and SubClasses
  69. ;                     are in the end of Vendors.inc
  70. ;            deleted
  71. ;                  * label "Descriptions" (names of Classes)
  72. ;
  73. ;----------------------------------------------------------------
  74. ;1.20: PCIDEV   16/08/2005
  75. ;Author:    Victor Alberto Gil Hanla a.k.a. vhanla <vhanla@gmail.com>
  76. ;Features:
  77. ;           added
  78. ;                  * ! many vendor lists (865)
  79. ;           deleted
  80. ;                  * previous version's list
  81. ;           changed
  82. ;                  * previous Company Name searching and printing
  83. ;----------------------------------------------------------------
  84. ;1.15: PCIDEV   03/06/2005
  85. ;Author:    Sergey Kuzmin aka Wildwest <kuzmin_serg@list.ru>
  86. ;Features:
  87. ;           added
  88. ;                                  * quantity of devices,
  89. ;                                  * ! detection of Company Name based on Vendor ID,
  90. ;                                  * database of VenID (35 ID's),
  91. ;                                  * macros.inc for smaller size,
  92. ;           changed
  93. ;                                  * interface+(skinned window),
  94. ;                                  * VenID before DevID in 'table'(was DevID before VenID)
  95. ;----------------------------------------------------------------
  96. ;1.0: PCIDEV    30/01/2005
  97. ;Author:    Jason Delozier
  98. ;Features:
  99. ;          able to
  100. ;                 * detect PCI version,
  101. ;                 * quantity of PCI buses,
  102. ;                 * Vendor&Device ID for appropriate Device on Bus;
  103. ;                 * detect Revision, Class and Subclass of Device,
  104. ;                 * and make Description based on Class
  105. ;-------------------------------------------------------------
  106. use32
  107.  
  108.         org    0x0
  109.  
  110.         db     'MENUET01'; 8 byte id
  111.         dd     0x01      ; header version
  112.         dd     START     ; start of code
  113.         dd     I_END     ; size of image
  114.         dd     0xFFFF    ; memory for app = 64 KB
  115.         dd     I_END     ; esp
  116.         dd     0x0 , 0x0 ; I_Param , I_Icon
  117.  
  118.  
  119. include 'macros.inc'
  120. include 'vendors.inc'
  121. include 'lang.inc'
  122.  
  123. START:    ; start of execution
  124.      call draw_window
  125.  
  126. still:
  127.     mov  eax,10   ; wait here for event
  128.     int  0x40
  129.  
  130.     cmp  eax,1   ; redraw request ?
  131.     je  red
  132.     cmp  eax,2   ; key in buffer ?
  133.     je  key
  134.     cmp  eax,3   ; button in buffer ?
  135.     je  button
  136.  
  137.     jmp  still
  138.  
  139.   red:    ; redraw
  140.     mov eax, 9              ;window redraw requested so get new window coordinates and size
  141.     mov ebx, Proc_Info      ;area to store process information
  142.     mov ecx, -1             ;
  143.     int 0x40                ;get the process information
  144.     mov eax,[Proc_Info+34]  ;store the window coordinates into the Form Structure
  145.     mov [Form+2], ax        ;x start position
  146.     mov eax,[Proc_Info+38]  ;
  147.     mov [Form+6],ax         ;ystart position
  148.     mov eax,[Proc_Info+42]  ;
  149.     mov [Form],ax           ;window width
  150.     mov eax,[Proc_Info+46]  ;
  151.     mov [Form+4] ,ax        ;window height
  152.     call draw_window        ;go redraw window now
  153.     jmp  still
  154.  
  155.   key:    ; key
  156.     mov  eax,2   ; just read it and ignore
  157.     int  0x40
  158.     jmp  still
  159.   button:   ; button
  160.     mov  eax,17   ; get id
  161.     int  0x40
  162.  
  163.     cmp  ah,1   ; button id=1 ?
  164.     jne  noclose
  165.  
  166.     mov  eax,-1   ; close this program
  167.     int  0x40
  168.   noclose:
  169.     jmp  still
  170.  
  171.  
  172.  
  173.  
  174. ;   *********************************************
  175. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  176. ;   *********************************************
  177. Form:
  178.    dw 780 ;window width
  179.    dw 100 ;window x start
  180.    dw 420 ;window height
  181.    dw 100 ;window y start
  182.  
  183.  
  184.  
  185. draw_window:
  186.  
  187.     mov byte [total],0
  188.  
  189.     mov  eax,12      ; function 12:tell os about windowdraw
  190.     mov  ebx,1       ; 1, start of draw
  191.     int  0x40
  192.     ; DRAW WINDOW
  193.     mov  eax,0                     ; function 0 : define and draw window
  194.     mov  ebx, dword [Form]         ; x/width of window
  195.     mov  ecx, dword [Form+4]       ; y/height of window
  196.     mov  edx,0x03ffffff            ; color of work area RRGGBB,8->color gl
  197.     mov  esi,0x805080d0            ; color of grab bar  RRGGBB,8->color gl
  198.     mov  edi,0x005080d0            ; color of frames    RRGGBB
  199.     int  0x40                      ; draw the window
  200.     ; WINDOW LABEL
  201.     mov  eax,4                     ; function 4 : write text to window
  202.     mov  ebx,8*65536+8             ; [x start] *65536 + [y start]
  203.     mov  ecx,0x10ddeeff            ; font 1 & color ( 0xF0RRGGBB )
  204.     mov  edx,labelt                ; pointer to text beginning
  205.     mov  esi,labellen-labelt       ; text length
  206.     int  0x40
  207.  
  208.     ;draw captions to window
  209.     mov ebx, 20*65536+25           ;x start, ystart of text
  210.     mov ecx, 0x224466              ;color of text
  211.     mov edx, dword PCIWin          ;start of text buffer
  212.     mov esi, 106                   ;lenght of line
  213. newline:                           ;
  214.     mov eax, 4                     ;draw text system function
  215.     int 0x40                       ;draw the text
  216.     add ebx, 10                    ;one line down
  217.     add edx, esi                   ;add lenght of line to offset of text buffer
  218.     cmp byte[edx], byte 'x'        ;is it the end of buffer?
  219.     jne newline                    ;if not draw another line of text
  220.  
  221.     ;Insert horizontal bars  in list area
  222.     mov eax, 13                    ;draw bar system function
  223.     mov ebx, 18                    ;set Xstart position of bar
  224.     shl ebx, 16                    ;
  225.     mov bx,word [Form]             ;get width of window
  226.     sub bx, 32                     ;bar is 32 pixels shorter then window width
  227.     mov ecx, 109*65536+10          ;set Ystart(109) and Height(10) of bar
  228.     mov edx, 0xb6b6b6              ;set color of bar
  229.    again:                          ;begin draw bar loop
  230.     int 0x40                       ;draw bar to window area
  231.     shr ecx, 16                    ;move the Ystart position to working area
  232.     add ecx, 34                    ;add 34 pixels to Y Start (moves bar down)
  233.     cmp cx,word [Form+4]           ;is the Ystart position outside of window area
  234.     jae nomo                       ;if so stop drawing bars
  235.     sub ecx, 14                    ;if not, we only need 20 pixels between bar tops
  236.     shl ecx, 16                    ;set that values as Ystart
  237.     add ecx, 10                    ;Bar Height is always 10 pixels
  238.     jmp again                      ;draw another bar
  239.    nomo:                           ;done drawing bars here
  240.  
  241.     ;start PCI stuff
  242.     call Get_PCI_Info              ;get pci version and last bus
  243.     mov cx,word [PCI_Version]      ;number to draw
  244.     mov eax, 47                    ;draw number system function
  245.     xor esi, esi                   ;color of text
  246.     mov ebx, 0x00040100            ;4 digits to draw in hex format
  247.     mov edx, 110*65536+45          ;x/y start position of number
  248.     int 0x40                       ;draw pci version to window
  249.     mov cl,byte [PCI_LastBus]      ;number to draw
  250.     mov ebx, 0x00020100            ;2 digits hex format
  251.     add edx, 10                    ;one line below pci version
  252.     int 0x40                       ;draw the last bus to window
  253.  
  254.     call scan_Pci                  ;scan for and draw each pci device
  255.  
  256.     movzx ecx, byte [total]        ;number to draw
  257.     mov eax, 47                    ;draw number system function
  258.     mov ebx, 0x00020000            ;2 digits to draw in decimal format
  259.     xor esi, esi                   ;color of text
  260.     mov edx, 150*65536+65          ;x/y position to draw to
  261.     int 0x40                       ;draw total number of devices to window
  262.  
  263.     mov  eax,12                    ; function 12:tell os about windowdraw
  264.     mov  ebx,2                     ; 2, end of draw
  265.     int  0x40
  266.  
  267.     ret
  268. ;   ***********************************************
  269. ;   *******  END WINDOW DEFINITIONS & DRAW  *******
  270. ;   ***********************************************
  271.  
  272.  
  273. ;******************************************************
  274. ;* Gets the PCI Versioin and Last Bus
  275. Get_PCI_Info:
  276.     mov eax, 62
  277.     xor ebx, ebx
  278.     int 0x40
  279.     mov word [PCI_Version], ax
  280.     mov eax, 62
  281.     mov ebx, 1
  282.     int 0x40
  283.     mov byte [PCI_LastBus], al
  284. ret
  285. ;******************************************************
  286.  
  287.  
  288. ;******************************************************
  289. ;* Get all devices on PCI Bus
  290. scan_Pci:
  291.    cmp  byte [PCI_LastBus],0xff ;0xFF means no pci bus found
  292.    jne  Pci_Exists              ;
  293.    ret                          ;if no bus then leave
  294. Pci_Exists:
  295.    mov  byte [V_Bus], 0         ;reset varibles
  296.    mov  byte [V_Dev], 0         ;
  297.    mov  edx,  20*65536+110      ;set start write position
  298. Start_Enum:
  299.    mov  bl, 6                   ;get a dword
  300.    mov  bh, byte [V_Bus]        ;bus of pci device
  301.    mov  ch, byte [V_Dev]        ;device number/function
  302.    mov  cl, 0                   ;offset to device/vendor id
  303.    mov  eax, 62                 ;pci system function
  304.    int  0x40                    ;get ID's
  305.  
  306.    cmp  ax, 0                   ;Vendor ID should not be 0 or 0xFFFF
  307.    je   nextDev                 ;check next device if nothing exists here
  308.    cmp  ax, 0xffff              ;
  309.    je   nextDev                 ;
  310.  
  311.    mov  word [PCI_Vendor], ax   ;There is a device here, save the ID's
  312.    shr  eax, 16                 ;
  313.    mov  word [PCI_Device], ax   ;
  314.    mov  eax, 62                 ;PCI Sys Function
  315.    mov  bl, 4                   ;Read config byte
  316.    mov  bh, byte [V_Bus]        ;Bus #
  317.    mov  ch, byte [V_Dev]        ;Device # on bus
  318.    mov  cl, 0x08                ;Register to read (Get Revision)
  319.    int  0x40                    ;Read it
  320.    mov  byte [PCI_Rev], al      ;Save it
  321.    mov  eax, 62                 ;PCI Sys Function
  322.    mov  cl, 0x0b                ;Register to read (Get class)
  323.    int  0x40                    ;Read it
  324.    mov  byte [PCI_Class], al    ;Save it
  325.    mov  eax, 62                 ;PCI Sys Function
  326.    mov  cl, 0x0a                ;Register to read (Get Subclass)
  327.    int  0x40                    ;Read it
  328.    mov  byte [PCI_SubClass], al ;Save it
  329.    inc  byte [total]            ;one more device found
  330.    call Print_New_Device        ;print device info to screen
  331. nextDev:
  332.    inc  byte [V_Dev]            ;next device on this bus
  333.    jnz  Start_Enum              ;jump until we reach zero
  334.                                 ;(used to be JNO which caused bug!!! 30-4-2006, JMD)
  335.    mov  byte [V_Dev], 0         ;reset device number
  336.    inc  byte [V_Bus]            ;next bus
  337.    mov  al, byte [PCI_LastBus]  ;get last bus
  338.    cmp  byte [V_Bus], al        ;was it last bus
  339.    jbe  Start_Enum              ;if not jump to keep searching
  340. ret
  341. ;******************************************************
  342.  
  343.  
  344.  
  345. ;******************************************************
  346. ;* Print device info to screen
  347. Print_New_Device:
  348.    mov   eax, 47                ;Write number to screen system function
  349.    mov   ebx, 0x00040100        ;4 byte number, print in hexidecimal
  350.    xor   esi, esi               ;Color of text
  351.    movzx ecx,word [PCI_Vendor]  ;Pointer to number to be written
  352.    int   0x40                   ;Write Vendor ID
  353.    and   edx, 0xFFFF            ;*****************************************
  354.    or    edx, 54*65536          ;X start becomes 54
  355.    movzx ecx,word [PCI_Device]  ;get Vendor ID
  356.    int   0x40                   ;Draw Vendor ID to Window
  357.    mov   ebx, 0x00020100        ;2 digit number, in hexidecimal format
  358.    and   edx, 0xFFFF            ;*****************************************
  359.    or    edx, 98*65536          ;X start becomes 98
  360.    movzx ecx,byte [V_Bus]       ;get bus number
  361.    int   0x40                   ;draw bus number to screen
  362.    and   edx, 0xFFFF            ;*****************************************
  363.    or    edx, 128*65536         ;X start becomes 128
  364.    movzx ecx,byte [V_Dev]       ;get device number
  365.    shr   ecx, 3                 ;device number is bits 3-7
  366.    int   0x40                   ;Draw device Number To Window
  367.    and   edx, 0xFFFF            ;*****************************************
  368.    or    edx, 155*65536         ;X start becomes 155
  369.    movzx ecx, byte [V_Dev]      ;get Function number
  370.    and   ecx, 7                 ;function is first 3 bits
  371.    int   0x40                   ;Draw Function Number To Window
  372.    and   edx, 0xFFFF            ;*****************************************
  373.    or    edx, 179*65536         ;X start becomes 179
  374.    movzx ecx,byte [PCI_Rev]     ;get revision number
  375.    int   0x40                   ;Draw Revision to screen
  376.    and   edx, 0xFFFF            ;*****************************************
  377.    or    edx, 215*65536         ;X start becomes 215
  378.    movzx ecx,byte [PCI_Class]   ;get PCI_Class
  379.    int   0x40                   ;Draw Class to screen
  380.    and   edx, 0xFFFF            ;*****************************************
  381.    or    edx, 266*65536         ;X start becomes 266
  382.    movzx ecx,byte [PCI_SubClass];get sub class
  383.    int   0x40                   ;Draw Sub Class to screen
  384.    ;Write Names
  385.    movzx ebx, dx                ;Set y position
  386.    or    ebx, 310*65536         ;set Xposition to 310
  387.  
  388. ;**********************************************************
  389. ;Prints the Vendor's Name based on Vendor ID
  390. ;
  391. ; modified part by vhanla (I know it is not a fastest way to search)
  392. ; it needs optimization... HELP this project!
  393. ;
  394. ; Modified on 30-04-2006 by JMD for size
  395. ;-----------------------------------------------------------------------------
  396.     ;first determine which list to find the vendor in
  397.     mov ax, word [PCI_Vendor]
  398.     mov ecx, 255           ;# vendors in most lists
  399.     cmp ax,4800            ;Check if Vendor's value is less than this number
  400.     jae next1              ;if it is less, let's continue, or jump to next1
  401.       mov edx, _FIRSTPART  ;select this list
  402.       jmp rep1             ;start searching list
  403.   next1:                   ;
  404.     cmp ax,5314            ;same thing happening here as above^
  405.     jae next2              ;
  406.       mov edx, _SECONDPART ;
  407.       jmp rep1             ;
  408.   next2:                   ;
  409.     cmp ax,5574            ;
  410.     jae next3              ;
  411.       mov edx, _THIRDPART  ;
  412.       jmp rep1             ;
  413.   next3:                   ;
  414.       mov ecx, 110         ;only 110 vendors in this list
  415.       mov edx, _FOURTHPART ;
  416.  
  417.   rep1:
  418.    cmp ax,word[edx+50]     ;are Vendor ID's the same?
  419.    je  ex                  ;if so jump to print the description to screen
  420.    add edx, 52             ;if not put us at start of next description
  421.    dec ecx                 ;one less description in list
  422.    jnz rep1                ;was it our last?
  423.    mov edx, _UNKNOWN       ;if so we dont know this Vendor
  424.  
  425.  ex:
  426.   ;lets print the vendor Name
  427.    xor ecx, ecx            ;font color
  428.    mov eax,4               ;OS CMD
  429.    mov esi,50              ;Length of text
  430.    int 0x40                ;Print the text
  431. ;------------------------------------------------------------------
  432.  
  433. ;------------------------------------------------------------------
  434. ;Get description based on Class/Subclass
  435.    cmp   byte [PCI_Class], 11h    ;we only know of 17 classes
  436.    ja    endd                     ;if its more then, its unknown to us, so jump
  437.    movzx eax, byte [PCI_Class]    ;load our class
  438.    shl   eax, 3                   ;multiply for jump table
  439.    mov   ecx, [ClassList+eax+4]   ;number of descriptions for this class
  440.    mov   edx, [ClassList+eax]     ;start of description list for class
  441.    movzx eax, byte [PCI_SubClass] ;get subclass
  442.  repu1:
  443.    cmp   al,byte[edx+32]          ;are subclasses the same?
  444.    je    endd                     ;if so jump to print the description to screen
  445.    add   edx, 33                  ;if not put us at start of next description
  446.    dec   ecx                      ;one less description in list
  447.    jnz   repu1                    ;was it our last?
  448.    mov   edx,_UNKNOWND            ;if so its unknown device
  449.  endd:
  450.    and   ebx, 0x0000FFFF          ;clear X position
  451.    or    ebx, 0x02300000          ;set X position to 560 pixels
  452.    xor   ecx, ecx                 ;color of text
  453.    mov   eax,4                    ;draw text system function
  454.    mov   esi,32                   ;length of text to draw
  455.    int   0x40                     ;draw the text
  456.  
  457.    movzx edx, bx                  ;get y coordinate
  458.    add   edx, 0x0014000A          ;add 10 to y coordinate and set x coordinate to 20
  459. ret
  460.  
  461. ClassList:
  462.  dd Class0 ,  2, Class1 , 8, Class2,  8, Class3, 4
  463.  dd Class4 ,  4, Class5 , 3, Class6, 12, Class7, 7
  464.  dd Class8 ,  8, Class9 , 6, ClassA,  2, ClassB, 7
  465.  dd ClassC , 10, ClassD , 8, ClassE,  1, ClassF, 4
  466.  dd Class10,  3, Class11, 5
  467. ;------------------------------------------------------------------
  468.  
  469.  
  470.  
  471. ; DATA AREA
  472.  
  473. labelt:
  474. db 'PCI Device Enumeration v 1.31 by J. Delozier, S. Kuzmin and V. Hanla'
  475.  labellen:
  476.  
  477. if lang eq de
  478. PCIWin:
  479. db 'Im Einstellungsmenue muss der PCI Zugriff eingeschaltet sein.      '
  480. db '                                       '
  481. db '                                                                   '
  482. db '                                       '
  483. db 'PCI Version  =                                                     '
  484. db '                                       '
  485. db 'Letzter PCI Bus =                                                  '
  486. db '                                       '
  487. db 'Anzahl von Geraeten =                                              '
  488. db '                                       '
  489. db '                                                                   '
  490. db '                                       '
  491. db 'VenID DevID Bus# Dev# Fnc Rev  Class  Subclass               Herste'
  492. db 'ller                    Beschreibung   '
  493. db '----- ----- ---- ---- --- ---  -----  -------- --------------------'
  494. db '---------------------- ----------------'
  495. db 'x'
  496. else
  497. PCIWin:
  498. db 'Please remember to enable PCI Access to Applications in Setup Menu.'
  499. db '                                       '
  500. db '                                                                   '
  501. db '                                       '
  502. db 'PCI Version  =                                                     '
  503. db '                                       '
  504. db 'Last PCI Bus =                                                     '
  505. db '                                       '
  506. db 'Number of devices =                                                '
  507. db '                                       '
  508. db '                                                                   '
  509. db '                                       '
  510. db 'VenID DevID Bus# Dev# Fnc Rev  Class  Subclass                 Comp'
  511. db 'any                      Description   '
  512. db '----- ----- ---- ---- --- ---  -----  -------- --------------------'
  513. db '---------------------- ----------------'
  514. db 'x'
  515. end if
  516.  
  517.  
  518. total        db 0
  519. V_Bus        db 0
  520. V_Dev        db 0
  521. PCI_Version  dw 0
  522. PCI_LastBus  db 0
  523. PCI_Device   dw 0
  524. PCI_Vendor   dw 0
  525. PCI_Bus      db 0
  526. PCI_Dev      db 0
  527. PCI_Rev      db 0
  528. PCI_Class    db 0
  529. PCI_SubClass db 0
  530.  
  531.  
  532. Proc_Info:
  533.  times 1024 db 0
  534.  
  535. I_END: