⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcil.c

📁 linux 下PCI设备的扫描程序。gcc,C+ASM完成。
💻 C
字号:
/*================================================*This Utility scans all pci devices in the system.*By Sanyo@Asustek*===============================================*/#include <stdio.h>#include <unistd.h>#include <sys/io.h>#define PCIIndexP	0xcf8#define PCIDataP	0xcfc#define DummyP		0x80unsigned short int GetVendorID(unsigned long PCIDData_T);unsigned short int GetDeviceID(unsigned long PCIDData_T);int 		   Prt_CPRight(void);int main(){	int nLst;	unsigned char bus,dev,func;	unsigned long PCIAddr,PCIDData;	unsigned int vendorID,deviceID;	nLst=0;	/* Get access to the ports */	/*if(ioperm(PCIIndexP,8,1)){perror("ioperm");exit(1);}	if(ioperm(PCIDataP ,3,1)){perror("ioperm");exit(1);}	*/	iopl(3);	Prt_CPRight();	/* Begin scan here */	for(bus=0;bus<0xfe;bus++)		for(dev=0;dev<=0x1f;dev++)			for(func=0;func<=7;func++)			{			PCIAddr=(0x8000<<16)|((bus<<8|dev<<3|func)<<8);				asm("movl	%1,%%eax\n"\				    "mov	%2,%%dx\n"\				    "out	%%eax,%%dx\n"\				    "mov	%3,%%dx\n"\				    "in		%%dx,%%eax\n"\				    "movl	%%eax,%0\n"\				    :"=a"(PCIDData)				    :"a"(PCIAddr),"i"(PCIIndexP),"i"(PCIDataP)				    ,"i"(DummyP)				    );				if(PCIDData!=0xffffffff)				{					vendorID=GetVendorID(PCIDData);					deviceID=GetDeviceID(PCIDData);					printf("%2x  Bus:%2x  Dev:%2x  Func:%x======Vendor:%4x,Device:%4x\n",nLst,bus,dev,func,vendorID,deviceID);					nLst++;				}				else				{					break;				}			}	/* We don't need the ports anymore */	/*	if(ioperm(PCIIndexP,8,0)){perror("ioperm");exit(1);}	if(ioperm(PCIDataP ,3,0)){perror("ioperm");exit(1);}	*/	iopl(0);	exit(0); }unsigned short int GetVendorID(unsigned long PCIDData_T){	unsigned short int vID=0xFFFF;	asm("movl 	%1,%%eax\n"\	    "mov	%%ax,%0\n" 	   :"+d"(vID)	   :"a"(PCIDData_T)	   );	return vID;}unsigned short int GetDeviceID(unsigned long PCIDData_T){        unsigned short int dID=0xFFFF;        asm("movl       %1,%%eax\n"\	    "rol	$0x10,%%eax\n"\            "mov        %%ax,%0\n"           :"+d"(dID)           :"a"(PCIDData_T)           );        return dID;}int Prt_CPRight(void){	printf("********************************************************  \n");	printf("            PCI List Utility 0.01 for Linux             \n\n");	printf("                              Sanyo@AsusTek  20060406     \n");	printf("********************************************************  \n");	return 0;				 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -