#include <stdio.h> #include <conio.h> typedef unsigned char BYTE; typedef unsigned int WORD; typedef unsigned long DWORD; #define PDI_BUS_MAX 0xFF #define PDI_DEVICE_MAX 0x1F #define PDI_FUNCTION_MAX 0x7 #define MK_PDI(bus,dev,func) (WORD)((bus&0xFF)<<8 | (dev&0x1F)<<3 | (func&0x7)) #define PCI_CONFIG_ADDRESS 0xCF8 #define PCI_CONFIG_DATA 0xCFC #define MK_PCICFGADDR(bus,dev,func) (DWORD)(0x80000000L | (DWORD)MK_PDI(bus,dev,func)<<8) DWORD inpd(int portid) { DWORD dwRet; asm mov dx, portid; asm lea bx, dwRet; __emit__( 0x66,0x50, // push EAX 0x66,0xED, // in EAX,DX 0x66,0x89,0x07, // mov [BX],EAX 0x66,0x58 ); // pop EAX return dwRet; } void outpd(int portid, DWORD dwVal) { asm mov dx, portid; asm lea bx, dwVal; __emit__ ( 0x66,0x50, // push EAX 0x66,0x8B,0x07, // mov EAX,[BX] 0x66,0xEF, // out DX,EAX 0x66,0x58 ); // pop EAX return; } int main(void) { int bus, dev, func; int j=0; DWORD dwAddr; DWORD dwData; DWORD dwDataBase; DWORD dwSub; DWORD dwInter; //clrscr(); //printf("/n"); printf("Bus/tDev/tFunc/tVendor/tDevice/tClass/t/t/tInterruptPin/n"); for(bus = 0; bus <= PDI_BUS_MAX; ++bus) { for(dev = 0; dev <= PDI_DEVICE_MAX; ++dev) { for(func = 0; func <= PDI_FUNCTION_MAX; ++func) { dwAddr = MK_PCICFGADDR(bus, dev, func); // printf("now begin enum"); outpd(PCI_CONFIG_ADDRESS, dwAddr); dwData = inpd(PCI_CONFIG_DATA); if ((WORD)dwData != 0xFFFF) { /* bus/dev/func */ printf("%2.2X/t%2.2X/t%2.2X/t", bus, dev, func); /* Vendor/Device */ printf("%4.4X/t%4.4X/t", (WORD)dwData, dwData>>16); /* Class Code */ outpd(PCI_CONFIG_ADDRESS, dwAddr | 0x8); dwData = inpd(PCI_CONFIG_DATA); dwDataBase=((dwData>>8)&0xFF0000); dwSub=((dwData>>8)&0x00FF00); dwInter=((dwData>>8)&0x0000FF); // char arr[40]; if(dwDataBase==0x10000) { if(dwSub==0x000000) { printf("%-24s","SCSI"); } else if((dwSub==0x000100)||(dwSub==0x000101)||(dwSub==0x000110)||(dwSub==0x000111)) { printf("%-24s","IDE"); } else { printf("%-24s","Mass Storage Controllers"); } // gotoxy(65,j+2); } else if(dwDataBase==0x20000) { if(dwSub==0x000000) { printf("%-24s","Ethernet Controller"); } else { printf("%-24s","Network controller"); } //gotoxy(65,j+2); } else if(dwDataBase==0x30000) { printf("%-24s","VGA(PCI Express)"); //gotoxy(65,j+2); } else if(dwDataBase==0x40000) { printf("%-24s","Multimedia device"); // gotoxy(65,j+2); } else if(dwDataBase==0x50000) { if(dwSub==0x000000) { printf("%-24s","RAM"); } else if(dwSub==0x000100) { printf("%-24s","Flash"); } else { printf("%-24s","Other Memory controller"); } //gotoxy(65,j+2); } else if(dwDataBase==0x60000) { if(dwSub==0x000000) { printf("%-24s","Host Bridge"); } else if(dwSub==0x000100) { printf("%-24s","ISA Bridge"); } //printf("%-24s","Bridge device"); else if(dwSub==0x000200) { printf("%-24s","EISA Bridge"); } else if(dwSub==0x000400) { printf("%-24s","PCI Bridge"); } else { printf("%-24s","Ohter Bridge device"); } //gotoxy(65,j+2); } else if(dwDataBase==0x70000) { printf("%-24s","Simple communication controllers"); // gotoxy(65,j+2); } else if(dwDataBase==0x80000) { printf("%-24s","Base system peripherals"); // gotoxy(65,j+2); } else if(dwDataBase==0x90000) { printf("%-24s","Input devices"); //gotoxy(65,j+2); } else if(dwDataBase==0xA0000) { printf("%-24s","Docking stations"); //gotoxy(65,j+2); } else if(dwDataBase==0xB0000) { printf("%-24s","Processors"); //gotoxy(65,j+2); } else if(dwDataBase==0xC0000) { if(dwSub==0x000000) { printf("%-24s","IEEE 1394(FireWire)"); } else if(dwSub==0x000300) { printf("%-24s","USB"); } else { printf("%-24s","Other bus controllers"); } // gotoxy(65,j+2); } else if(dwDataBase==0xD0000) { printf("%-24s","Wireless controller"); // gotoxy(65,j+2); } else if(dwDataBase==0xE0000) { printf("%-24s","Intelligent I/O controllers"); //gotoxy(65,j+2); } else if(dwDataBase==0xF0000) { printf("%-24s","Satallite communication controllers"); //gotoxy(65,j+2); } else if(dwDataBase==0x100000) { printf("%-24s""Encryption/Decryption controllers"); // gotoxy(65,j+2); } /* IRQ/intPin */ outpd(PCI_CONFIG_ADDRESS, dwAddr | 0x3C); dwData = inpd(PCI_CONFIG_DATA); printf("%d", (BYTE)(dwData>>8)); printf("/n"); char ch; j++; if(j>18) { j=0; printf("press enter key to continue"); while((ch=getchar())!='/n'&&ch!=EOF) { getchar(); } } } } } } return 0; }