Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.10 KB | None | 0 0
  1. //--------------------------------------------------------------------
  2. // TUCN, Computer Science Department
  3. // Input/Output Systems and Peripheral Devices
  4. //--------------------------------------------------------------------
  5. // http://users.utcluj.ro/~baruch/en/pages/teaching/inputoutput-systems/laboratory.php
  6. //--------------------------------------------------------------------
  7. // File:        AppScroll-e.cpp
  8. // Date:        10.10.2015
  9. // Modified:    21.11.2015
  10. //--------------------------------------------------------------------
  11. // IOS application example with vertical scroll bar
  12. //--------------------------------------------------------------------
  13.  
  14. #include <iostream>
  15. #include <cstdio>
  16. #include <windows.h>
  17. #include "Hw.h"
  18. #include "PCI-e.h"
  19. #include "PCI-vendor-dev.h"
  20. using namespace std;
  21.  
  22. #define NLIN 500                                // number of lines in the display window
  23. #define NCOL 240                                // number of columns in the display window
  24.  
  25. // Global variables
  26. char szBuffer[NLIN][NCOL];                      // buffer for the window contents
  27. int  cLine;                                     // number of current line in the display buffer
  28.  
  29. // Declarations of external functions
  30. void DisplWindow(HWND hWnd);
  31.  
  32. DWORD64 qvFuncAddr;
  33.  
  34. PPCI_CONFIG0 returnsPointer(WORD busNumber, WORD deviceNumber, WORD PCIeFunctionNumber){
  35.     DWORD64 qwAdrDisp = PCI_CONFIG_START;
  36.     qwAdrDisp = qwAdrDisp | (busNumber << 20) | (deviceNumber << 15) | (PCIeFunctionNumber << 12);
  37.     return (PPCI_CONFIG0)qwAdrDisp;
  38. }
  39.  
  40. DWORD readDWORD(byte bus_number, byte device_number, byte function_number, byte dw_number) {
  41.     DWORD data = ((1 << 31) | (bus_number << 16) | (device_number << 11) | (function_number << 8) | (dw_number << 2));
  42.     __outpd(PCI_CONFIG_ADR, data);
  43.     DWORD readData = __inpd(PCI_CONFIG_DATA);
  44.     return readData;
  45. }
  46.  
  47. void returnsInfo(BYTE baseClass, BYTE subClass, BYTE progInterface){
  48.     for (int i = 0; i < PCI_CLASS_TABLE_LEN; i++)
  49.     {
  50.         if (PciClassTable[i].Class == baseClass && PciClassTable[i].SubClass == subClass
  51.             && PciClassTable[i].ProgIf == progInterface)
  52.         {
  53.             wsprintf(szBuffer[cLine++], "class subclass descriptor = %s progInterface descriptor = %X \n\n",
  54.                 PciClassTable[i].ClassDesc, PciClassTable[i].ProgIfDesc);
  55.             freopen("output.txt", "w", stdout);
  56.             cout << PciClassTable[i].ProgIfDesc;
  57.         }
  58.     }
  59. }
  60.  
  61. void returnsIds(DWORD vendorId, DWORD deviceId){
  62.     for (int i = 0; i < PCI_VENTABLE_LEN; i++)
  63.         if (PciVenTable[i].VenId == vendorId)
  64.             wsprintf(szBuffer[cLine++], "vendor id = %d  vendor descriptor = %s ",
  65.             PciVenTable[i].VenId, PciVenTable[i].VenFull);
  66.  
  67.     for (int i = 0; i < PCI_DEVTABLE_LEN; i++)
  68.         if (PciDevTable[i].VenId == vendorId && PciDevTable[i].DevId == deviceId)
  69.             wsprintf(szBuffer[cLine++], "device id = %d  device descriptor = %s ",
  70.             PciDevTable[i].DevId, PciDevTable[i].ChipDesc);
  71. }
  72.  
  73. //--------------------------------------------------------------------
  74. // Function AppScroll
  75. //--------------------------------------------------------------------
  76. //
  77. // Function:    IOS application example with vertical scroll bar
  78. //
  79. // Parameters:  - Handle to the application window
  80. //
  81. // Returns:     0 - Operation completed successfully
  82. //              1 - Error at initializing the Hw driver
  83. //
  84. //--------------------------------------------------------------------
  85.  
  86. int AppScroll(HWND hWnd)
  87. {
  88.     int   i;
  89.  
  90.     char szMes0[] = "Error initializing the Hw driver";
  91.     char szMes1[] = "IOS Application";
  92.  
  93.     // Initialize the Hw library
  94.     if (!HwOpen()) {
  95.         wsprintf(szBuffer[0], szMes0);
  96.         MessageBox(NULL, szBuffer[0], "HwOpen", MB_ICONSTOP);
  97.         return 1;
  98.     }
  99.  
  100.     // Erase the display buffer and the window contents
  101.     for (i = 0; i < NLIN; i++) {
  102.         memset(szBuffer[i], ' ', NCOL);
  103.     }
  104.     cLine = 1;
  105.  
  106.     // Copy the start message into the display buffer and display the message
  107.     wsprintf(szBuffer[cLine], szMes1);
  108.     cLine += 2;
  109.     DisplWindow(hWnd);
  110.  
  111.     //--------------------------------------------------------------------
  112.     // To be completed with the application's code
  113.     //--------------------------------------------------------------------
  114.  
  115.     for (int i = 0; i < 15; i++)
  116.         for (int j = 0; j < 31; j++)
  117.             for (int k = 0; k < 7; k++)
  118.             {
  119.                 ///2.7.2, 2.7.3
  120.                 PPCI_CONFIG0 pRegPci = returnsPointer(i, j, k);
  121.                 WORD wVendorID = _inmw((DWORD_PTR)&pRegPci->VendorID);
  122.  
  123.                 if (wVendorID == 0xFFFF)
  124.                     continue;
  125.                 wsprintf(szBuffer[cLine++], "2.7.3\n", i, j, k);
  126.                
  127.                 wsprintf(szBuffer[cLine++], "bus = %d  device = %d  function = %d", i, j, k);
  128.                 DWORD baseClass = _inmw((DWORD_PTR)&pRegPci->BaseClass);
  129.                 DWORD subClass = _inmw((DWORD_PTR)&pRegPci->SubClass);
  130.                 DWORD progInterface = _inmw((DWORD_PTR)&pRegPci->ProgInterface);
  131.                 DWORD subSystVendorID = _inmw((DWORD_PTR)&pRegPci->SubSystVendorID);
  132.                 DWORD deviceId = _inmw((DWORD_PTR)&pRegPci->BaseClass);
  133.  
  134.                 returnsInfo(baseClass, subClass, progInterface);
  135.                 returnsIds(wVendorID, deviceId);
  136.  
  137.                 wsprintf(szBuffer[cLine++], "baseclass = %d  subclass = %d  progInterface = %d, subsystVendorID = %d",
  138.                     baseClass, subClass, progInterface, subSystVendorID);
  139.  
  140.                 ///2.7.4
  141.                 wsprintf(szBuffer[cLine++], "\n2.7.4\n");
  142.                 WORD vendor_id = LOWORD(readDWORD(i, j, k, 0));
  143.                 WORD device_id = HIWORD(readDWORD(i, j, k, 0));
  144.  
  145.                 if (vendor_id != 0xFFFF){
  146.                     wsprintf(szBuffer[cLine++], "bus = %d  device = %d  function = %d", i, j, k);
  147.                     wsprintf(szBuffer[cLine++], "class: %x\n", (HIWORD(readDWORD(i, j, k, 0x02)) << 7) | HIBYTE(LOWORD(i, j, k, 0x02)));
  148.                     wsprintf(szBuffer[cLine++], "vendorId = %d\n", vendor_id);
  149.  
  150.                     for (int index = 0; index < PCI_VENTABLE_LEN; index++) {
  151.                         if (PciVenTable[index].VenId == vendor_id) {
  152.                             wsprintf(szBuffer[cLine++], "vendor information: %s\n", PciVenTable[index].VenFull);
  153.                         }
  154.                     }
  155.                     for (int index = 0; index < PCI_DEVTABLE_LEN; index++) {
  156.                         if (PciDevTable[index].DevId == device_id) {
  157.                             wsprintf(szBuffer[cLine++], "chip descriptor: %s\n", PciDevTable[index].ChipDesc);
  158.                         }
  159.                     }
  160.                
  161.                 }
  162.  
  163.                 wsprintf(szBuffer[cLine++], "--------------------------------------------------");
  164.                 wsprintf(szBuffer[cLine++], "\n\n\n\n\n");
  165.             }
  166.  
  167.     // Display the messages
  168.     DisplWindow(hWnd);
  169.  
  170.     HwClose();
  171.     return 0;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement