Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 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. #include "PCI-vendor-dev.h"
  19.  
  20. #define NLIN 500 // number of lines in the display window
  21. #define NCOL 240 // number of columns in the display window
  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. DWORD getDoubleWord(BYTE busNr, BYTE devNr, BYTE fctNr, BYTE dwNumber)
  55. {
  56. DWORD configAddrPort = 0x800000000 | (busNr << 16) | (devNr << 11) | (fctNr << 8) | (dwNumber << 2);
  57.  
  58. __outpd(PCI_CONFIG_ADR, configAddrPort);
  59.  
  60. return __inpd(PCI_CONFIG_DATA);
  61.  
  62.  
  63. }
  64.  
  65. int AppScroll(HWND hWnd)
  66. {
  67. int i;
  68.  
  69. char szMes0[] = "Error initializing the Hw driver";
  70. char szMes1[] = "IOS Application";
  71.  
  72. // Initialize the Hw library
  73. if (!HwOpen()) {
  74. wsprintf(szBuffer[0], szMes0);
  75. MessageBox(NULL, szBuffer[0], "HwOpen", MB_ICONSTOP);
  76. return 1;
  77. }
  78.  
  79. // Erase the display buffer and the window contents
  80. for (i = 0; i < NLIN; i++) {
  81. memset(szBuffer[i], ' ', NCOL);
  82. }
  83. cLine = 1;
  84.  
  85. // Copy the start message into the display buffer and display the message
  86. wsprintf(szBuffer[cLine], szMes1);
  87. cLine += 2;
  88. DisplWindow(hWnd);
  89.  
  90. //--------------------------------------------------------------------
  91. // To be completed with the application's code
  92. //--------------------------------------------------------------------
  93.  
  94. for (int busNr = 0; busNr < 16; busNr++){
  95. for (int devNr = 0; devNr < 32; devNr++){
  96. for (int fctNr = 0; fctNr < 8; fctNr++){
  97. PPCI_CONFIG0 header = getHeaderFromPCIe(busNr, devNr, fctNr);
  98. WORD wVendorID = _inmw((DWORD_PTR)&header->VendorID);
  99. WORD wDeviceID = _inmw((DWORD_PTR)&header->DeviceID);
  100. if (wVendorID != 0xFFFF){
  101. 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",
  102. busNr, devNr, fctNr,
  103. _inm((DWORD_PTR)&header->BaseClass), _inm((DWORD_PTR)&header->SubClass),
  104. _inm((DWORD_PTR)&header->ProgInterface), _inm((DWORD_PTR)&header->SubSystVendorID),
  105. _inm((DWORD_PTR)&header->SubSystID)
  106. );
  107. cLine++;
  108. PciClassTable->Class = _inm((DWORD_PTR)&header->BaseClass);
  109. PciClassTable->SubClass = _inm((DWORD_PTR)&header->SubClass);
  110. PciClassTable->ProgIf = _inm((DWORD_PTR)&header->ProgInterface);
  111. wsprintf(szBuffer[cLine], "Class Desc.: %s | Interface Desc.: %s\n", PciClassTable->ClassDesc, PciClassTable->ProgIfDesc);
  112. cLine++;
  113. for (int i = 0; i < PCI_VENTABLE_LEN; i++){
  114. if (wVendorID == PciVenTable[i].VenId){
  115. wsprintf(szBuffer[cLine], "Vendor descriptor : %s ", PciVenTable[i].VenFull);
  116. cLine++;
  117. }
  118. }
  119. for (int i = 0; i < PCI_DEVTABLE_LEN; i++){
  120. if (wVendorID == PciDevTable[i].VenId && wDeviceID == PciDevTable[i].DevId){
  121. wsprintf(szBuffer[cLine], "Chip descriptor : %s ", PciDevTable[i].ChipDesc);
  122. cLine++;
  123.  
  124.  
  125. }
  126.  
  127.  
  128. }
  129. wsprintf(szBuffer[cLine], "____________________________________________________________________________________________________ \n ");
  130. cLine++;
  131. }
  132. }
  133. }
  134.  
  135. }
  136.  
  137. wsprintf(szBuffer[cLine++], "16 dwords from config\n");
  138. for (BYTE dwOffset = 0x00; dwOffset <= 0x0F; dwOffset += 0x01)
  139. {
  140. DWORD aux = getDoubleWord(0x00, 0x1F, 0x03, dwOffset);
  141. wsprintf(szBuffer[cLine++], "%x\n", aux);
  142. }
  143. // Display the messages
  144. DisplWindow(hWnd);
  145.  
  146. HwClose();
  147. return 0;
  148. }
  149. ///WAMq9n5n
  150. //MgqC0AnW
  151. //D8kmw1Pe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement