Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------------------------------------------------------------
- // TUCN, Computer Science Department
- // Input/Output Systems and Peripheral Devices
- //--------------------------------------------------------------------
- // http://users.utcluj.ro/~baruch/en/pages/teaching/inputoutput-systems/laboratory.php
- //--------------------------------------------------------------------
- // File: AppScroll-e.cpp
- // Date: 10.10.2015
- // Modified: 21.11.2015
- //--------------------------------------------------------------------
- // IOS application example with vertical scroll bar
- //--------------------------------------------------------------------
- #include <windows.h>
- #include <iostream>
- #include "Hw.h"
- #include "PCI-e.h"
- #define NLIN 500 // number of lines in the display window
- #define NCOL 240 // number of columns in the display window
- // Global variables
- char szBuffer[NLIN][NCOL]; // buffer for the window contents
- int cLine; // number of current line in the display buffer
- // Declarations of external functions
- void DisplWindow(HWND hWnd);
- //--------------------------------------------------------------------
- // Function AppScroll
- //--------------------------------------------------------------------
- //
- // Function: IOS application example with vertical scroll bar
- //
- // Parameters: - Handle to the application window
- //
- // Returns: 0 - Operation completed successfully
- // 1 - Error at initializing the Hw driver
- //
- //--------------------------------------------------------------------
- PPCI_CONFIG0 getHeaderFromPCIe(byte busNr, byte devNr, byte fctNr)
- {
- //start address : PCI_CONFIG_START (different)
- DWORD64 qwFuncAddr = PCI_CONFIG_START;
- //shifts for : PCI bus, device, function
- qwFuncAddr = qwFuncAddr | (busNr << 20);//PCI 27...20
- qwFuncAddr = qwFuncAddr | (devNr << 15);//device 19...15
- qwFuncAddr = qwFuncAddr | (fctNr << 12);//function 14...12
- //return pointer
- return (PPCI_CONFIG0)qwFuncAddr;
- }
- int AppScroll(HWND hWnd)
- {
- int i;
- char szMes0[] = "Error initializing the Hw driver";
- char szMes1[] = "IOS Application";
- // Initialize the Hw library
- if (!HwOpen()) {
- wsprintf(szBuffer[0], szMes0);
- MessageBox(NULL, szBuffer[0], "HwOpen", MB_ICONSTOP);
- return 1;
- }
- // Erase the display buffer and the window contents
- for (i = 0; i < NLIN; i++) {
- memset (szBuffer[i], ' ', NCOL);
- }
- cLine = 1;
- // Copy the start message into the display buffer and display the message
- wsprintf(szBuffer[cLine], szMes1);
- cLine += 2;
- DisplWindow(hWnd);
- //--------------------------------------------------------------------
- // To be completed with the application's code
- //--------------------------------------------------------------------
- for (int busNr = 0; busNr < 16; busNr++){
- for (int devNr = 0; devNr < 32; devNr++){
- for (int fctNr = 0; fctNr < 8; fctNr++){
- PPCI_CONFIG0 header = getHeaderFromPCIe(busNr, devNr, fctNr);
- WORD wVendorID = _inmw((DWORD_PTR)&header->VendorID);
- if (wVendorID != 0xFFFF){
- 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",
- busNr, devNr, fctNr,
- _inm((DWORD_PTR)&header->BaseClass), _inm((DWORD_PTR)&header->SubClass),
- _inm((DWORD_PTR)&header->ProgInterface), _inm((DWORD_PTR)&header->SubSystVendorID),
- _inm((DWORD_PTR)&header->SubSystID)
- ); cLine++;
- PciClassTable->Class = _inm((DWORD_PTR)&header->BaseClass);
- PciClassTable->SubClass = _inm((DWORD_PTR)&header->SubClass);
- PciClassTable->ProgIf = _inm((DWORD_PTR)&header->ProgInterface);
- wsprintf(szBuffer[cLine], "Class Desc.: %s | Interface Desc.: %s\n", PciClassTable->ClassDesc, PciClassTable->ProgIfDesc); cLine++;
- wsprintf(szBuffer[cLine], "\n"); cLine++;
- }
- }
- }
- }
- // Display the messages
- DisplWindow(hWnd);
- HwClose();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement