📄 exp03_pci设备查询和配置空间的读取.cpp
字号:
/***************************************/
/* PCI设备查询及其配置空间的读取 */
/* Win9X/me下可以用 */
/* 显示数据含义可查看PCI22规范中的介绍 */
/***************************************/
#include "stdio.h"
#include "windows.h"
DWORD DWORD_In(WORD io_Port)
{
DWORD val;
_asm {
mov dx,io_Port
in eax,dx
mov val,eax
}
return val;
}
DWORD DWORD_Out(WORD io_Port,DWORD val)
{
_asm {
mov dx,io_Port
mov eax,val
out dx,eax
}
return 0;
}
int main()
{
DWORD io_CF8; // port 0xcf8 Address
DWORD io_CFC; // port 0xcfc Data
DWORD io_CFC_TEMP = 0xffffffff; // temp
int i;
io_CF8=0x80000000; //file://because the first bit is enable/disable
//file://so must be 1,so from 0x800000000
do{
DWORD_Out(0xcf8,io_CF8);
io_CFC = DWORD_In(0xcfc);
if (io_CFC == io_CFC_TEMP) //防止配置空间数据重复
io_CFC = 0xffffffff;
else
io_CFC_TEMP = io_CFC;
if (io_CFC != 0xffffffff) //file://if =0xffffffff,then is a invalid
{ //file://bus number and device number
printf("\nPCI device has found,the pci config address = %lx \n",io_CF8);
printf("its Bus Numer is %lx \n",(io_CF8&0x00ff0000)/0x10000);
printf("its Device Number is %lx \n",(io_CF8&0x0000f800)/0x800);
printf("its Functin Number is %lx \n",(io_CF8&0x700)/0x100);
printf("its Register Number is %lx \n",(io_CF8&0xfc)>>2);
for (i=0 ;i<=15;i++)
{
DWORD_Out(0xcf8,io_CF8+4*i); //file://read DWORD
io_CFC=DWORD_In(0xcfc);
switch (i)
{
case 0:
printf("00H Device Number = %lx Vendor Number = %lx \n",
(io_CFC&0xffff0000)/0x10000,io_CFC&0xffff);
break;
case 1:
printf("04H Status = %lx Command = %lx \n",
(io_CFC&0xffff0000)/0x10000,io_CFC&0xffff);
break;
case 2:
printf("08H Class Code = %lx Revision ID = %lx \n",
(io_CFC&0xffffff00)/0x100,io_CFC&0xff);
break;
case 3:
printf("0CH Bist = %lx Header Type = %lx Latency Timer = %lx Cache Line Size = %lx \n",
(io_CFC&0xff000000)/0x1000000,(io_CFC&0xff0000)/0x10000,(io_CFC&0xff00)/0x100,io_CFC&0xff);
break;
case 4: //file://PCI Configration has 6 base address
//file://register
printf("10H Base Address Register #0 ,");
if (io_CFC == 0)
printf("None \n");
else
if (io_CFC&0x1)
{
printf("I/O = %lx \n",io_CFC&0xfffffffc);
}else
{
printf("Memory = %lx Prefetchable = %lx Type = %lx \n",
io_CFC&0xfffffff0,(io_CFC&0x8)>>3,(io_CFC&0x6)>>1);
}
break;
case 5:
printf("14H Base Address Register #1 ,");
if (io_CFC == 0)
printf("None \n");
else
if (io_CFC&0x1)
{
printf("I/O = %lx \n",io_CFC&0xfffffffc);
}else
{
printf("Memory = %lx Prefetchable = %lx Type = %lx \n",
io_CFC&0xfffffff0,(io_CFC&0x8)>>3,(io_CFC&0x6)>>1);
}
break;
case 6:
printf("18H Base Address Register #2 ,");
if (io_CFC == 0)
printf("None \n");
else
if (io_CFC&0x1)
{
printf("I/O = %lx \n",io_CFC&0xfffffffc);
}else
{
printf("Memory = %lx Prefetchable = %lx Type = %lx \n",
io_CFC&0xfffffff0,(io_CFC&0x8)>>3,(io_CFC&0x6)>>1);
}
break;
case 7:
printf("1CH Base Address Register #3 ,");
if (io_CFC == 0)
printf("None \n");
else
if (io_CFC&0x1)
{
printf("I/O = %lx \n",io_CFC&0xfffffffc);
}else
{
printf("Memory = %lx Prefetchable = %lx Type = %lx \n",
io_CFC&0xfffffff0,(io_CFC&0x8)>>3,(io_CFC&0x6)>>1);
}
break;
case 8:
printf("20H Base Address Register #4 ,");
if (io_CFC == 0)
printf("None \n");
else
if (io_CFC&0x1)
{
printf("I/O = %lx \n",io_CFC&0xfffffffc);
}else
{
printf("Memory = %lx Prefetchable = %lx Type = %lx \n",
io_CFC&0xfffffff0,(io_CFC&0x8)>>3,(io_CFC&0x6)>>1);
}
break;
case 9:
printf("24H Base Address Register #5 ,");
if (io_CFC == 0)
printf("None \n");
else
if (io_CFC&0x1)
{
printf("I/O = %lx \n",io_CFC&0xfffffffc);
}else
{
printf("Memory = %lx Prefetchable = %lx Type = %lx \n",
io_CFC&0xfffffff0,(io_CFC&0x8)>>3,(io_CFC&0x6)>>1);
}
break;
case 10:
printf("28H Cardbus CIS Pointer = %lx \n",io_CFC);
break;
case 11:
printf("2CH Subsystem ID = %lx Subsystem Vendor ID = %lx \n",
(io_CFC&0xffff0000)/0x10000,io_CFC&0xffff);
break;
case 12:
printf("30H Expanslon ROM Base Address = %lx \n",io_CFC);
break;
case 13:
printf("34H Capabilities Pointer = %lx \n",io_CFC&0xf);
break;
case 14:
printf("38H Reserved \n");
break;
case 15: //file://attention:the interrupt IRQ= this result&0xff
printf("3CH Max_Lat = %lx Min_Gnt =%lx Interrupt Pin = %lx Interrupt Line = %lx \n",
(io_CFC&0xff000000)/0x1000000,(io_CFC&0xff0000)/0x10000,(io_CFC&0xff00)/0x100,io_CFC&0xff);
break;
}
}
printf("\nPress ENTER to NEXT!");
getchar();
}
io_CF8 += 0x100;
}while(io_CF8<0x80FFFF00);
printf("\nPress ENTER to EXIT!");
getchar();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -