Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 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 <windows.h>
  15. #include <iostream>
  16. #include "Hw.h"
  17. #include "PCI-e.h"
  18.  
  19. #define NLIN 500 // number of lines in the display window
  20. #define NCOL 240 // number of columns in the display window
  21.  
  22. // Global variables
  23. char szBuffer[NLIN][NCOL]; // buffer for the window contents
  24. int cLine; // number of current line in the display buffer
  25.  
  26. // Declarations of external functions
  27. void DisplWindow(HWND hWnd);
  28.  
  29. //--------------------------------------------------------------------
  30. // Function AppScroll
  31. //--------------------------------------------------------------------
  32. //
  33. // Function: IOS application example with vertical scroll bar
  34. //
  35. // Parameters: - Handle to the application window
  36. //
  37. // Returns: 0 - Operation completed successfully
  38. // 1 - Error at initializing the Hw driver
  39. //
  40. //--------------------------------------------------------------------
  41.  
  42. PPCI_CONFIG0 getHeaderFromPCIe(byte busNr, byte devNr, byte fctNr)
  43. {
  44. //start address : PCI_CONFIG_START (different)
  45. DWORD64 qwFuncAddr = PCI_CONFIG_START;
  46. //shifts for : PCI bus, device, function
  47. qwFuncAddr = qwFuncAddr | (busNr << 20);//PCI 27...20
  48. qwFuncAddr = qwFuncAddr | (devNr << 15);//device 19...15
  49. qwFuncAddr = qwFuncAddr | (fctNr << 12);//function 14...12
  50. //return pointer
  51. return (PPCI_CONFIG0)qwFuncAddr;
  52. }
  53.  
  54. int AppScroll(HWND hWnd)
  55. {
  56. int i;
  57.  
  58. char szMes0[] = "Error initializing the Hw driver";
  59. char szMes1[] = "IOS Application";
  60.  
  61. // Initialize the Hw library
  62. if (!HwOpen()) {
  63. wsprintf(szBuffer[0], szMes0);
  64. MessageBox(NULL, szBuffer[0], "HwOpen", MB_ICONSTOP);
  65. return 1;
  66. }
  67.  
  68. // Erase the display buffer and the window contents
  69. for (i = 0; i < NLIN; i++) {
  70. memset (szBuffer[i], ' ', NCOL);
  71. }
  72. cLine = 1;
  73.  
  74. // Copy the start message into the display buffer and display the message
  75. wsprintf(szBuffer[cLine], szMes1);
  76. cLine += 2;
  77. DisplWindow(hWnd);
  78.  
  79. //--------------------------------------------------------------------
  80. // To be completed with the application's code
  81. //--------------------------------------------------------------------
  82.  
  83. for (int busNr = 0; busNr < 16; busNr++){
  84. for (int devNr = 0; devNr < 32; devNr++){
  85. for (int fctNr = 0; fctNr < 8; fctNr++){
  86. PPCI_CONFIG0 header = getHeaderFromPCIe(busNr, devNr, fctNr);
  87. WORD wVendorID = _inmw((DWORD_PTR)&header->VendorID);
  88. if (wVendorID != 0xFFFF){
  89. wsprintf(szBuffer[cLine], "Bus: %d | Device: %d | Function: %d | Class Code: %x | Sub Class Code: %x | Interface: %x\n | SubSystem Vendor: %x | SubSystem ID: %x\n",
  90. busNr, devNr, fctNr,
  91. _inm((DWORD_PTR)&header->BaseClass), _inm((DWORD_PTR)&header->SubClass),
  92. _inm((DWORD_PTR)&header->ProgInterface), _inm((DWORD_PTR)&header->SubSystVendorID),
  93. _inm((DWORD_PTR)&header->SubSystID)
  94. ); cLine++;
  95. PciClassTable->Class = _inm((DWORD_PTR)&header->BaseClass);
  96. PciClassTable->SubClass = _inm((DWORD_PTR)&header->SubClass);
  97. PciClassTable->ProgIf = _inm((DWORD_PTR)&header->ProgInterface);
  98. wsprintf(szBuffer[cLine], "Class Desc.: %s | Interface Desc.: %s\n", PciClassTable->ClassDesc, PciClassTable->ProgIfDesc); cLine++;
  99. wsprintf(szBuffer[cLine], "\n"); cLine++;
  100. }
  101. }
  102. }
  103. }
  104. // Display the messages
  105. DisplWindow(hWnd);
  106.  
  107. HwClose();
  108. return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement