计算机寄存器端口,用C+自己写的看计算机硬件端口寄存器内容

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include

#include

#include "winio.h"

#include

using namespace std;

/*PCI配置空间寄存器*/

#define PCI_CONFIG_ADDRESS 0xCF8

#define PCI_CONFIG_DATA 0xCFC #define PCI_TYPE0_ADDRESSES 6

#define PCI_TYPE1_ADDRESSES 2

#define PCI_TYPE2_ADDRESSES 5

typedef struct _PCI_COMMON_CONFIG{

USHORT VendorID; //(ro)

USHORT DeviceID; //(ro)

USHORT Command; //Device control

USHORT Status;

UCHAR RevisionID; //(ro)

UCHAR ProgIf; //(ro)

UCHAR SubClass; //(ro)

UCHAR BaseClass; //(ro)

UCHAR CacheLineSize; //(ro+)

UCHAR LatencyTimer; //(ro+)

UCHAR HeaderType; //(ro)

UCHAR BIST; //Built in self test union{

struct _PCI_HEADER_TYPE_0{

ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];

ULONG CIS;

USHORT SubVendorID;

USHORT SubSystemID;

ULONG ROMBaseAddress;

UCHAR CapabilitiesPtr;

UCHAR Reserved1[3];

ULONG Reserved2;

UCHAR InterruptLine; //

UCHAR InterruptPin; //(ro)

UCHAR MinimumGrant; //(ro)

UCHAR MaximumLatency; //(ro)

}type0;

//end_wdm end_ntminiport end_ntndis

//

//PCI to PCI Bridge

// struct _PCI_HEADER_TYPE_1{

ULONG BaseAddresses[PCI_TYPE1_ADDRESSES];

UCHAR PrimaryBus;

UCHAR SecondaryBus;

UCHAR SubordinateBus;

UCHAR SecondaryLatency;

UCHAR IOBase;

UCHAR IOLimit;

USHORT SecondaryStatus;

USHORT MemoryBase;

USHORT MemoryLimit;

USHORT PrefetchBase;

USHORT PrefetchLimit;

ULONG PrefetchBaseUpper32;

ULONG PrefetchLimitUpper32;

USHORT IOBaseUpper16;

USHORT IOLimitUpper16;

UCHAR CapabilitiesPtr;

UCHAR Reserved1[3];

ULONG ROMBaseAddress;

UCHAR InterruptLine;

UCHAR InterruptPin;

USHORT BridgeControl;

}type1; //

//PCI to CARDBUS Bridge

// struct _PCI_HEADER_TYPE_2{

ULONG SocketRegistersBaseAddress;

UCHAR CapabilitiesPtr;

UCHAR Reserved;

USHORT SecondaryStatus;

UCHAR PrimaryBus;

UCHAR SecondaryBus;

UCHAR SubordinateBus;

UCHAR SecondaryLatency;

struct{

ULONG Base;

ULONG Limit;

}Range[PCI_TYPE2_ADDRESSES-1];

UCHAR InterruptLine;

UCHAR InterruptPin;

USHORT BridgeControl;

}type2;

//begin_wdm begin_ntminiport begin_ntndis

}u; UCHAR DeviceSpecific[192];

}PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG; typedef struct _PCI_SLOT_NUMBER{

union{

struct{

ULONG FunctionNumber:3;

ULONG DeviceNumber:5;

ULONG Reserved:24;

}bits;

ULONG AsULONG;

}u;

}PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;

void DisplayPCIConfiguation(int bus,int dev,int func)

{

DWORD dwAddr;

DWORD dwData; PCI_COMMON_CONFIG pci_config;

PCI_SLOT_NUMBER SlotNumber; SlotNumber.u.AsULONG=0;

SlotNumber.u.bits.DeviceNumber=dev;

SlotNumber.u.bits.FunctionNumber=func;

dwAddr=0x80000000|(bus<<16)|(SlotNumber.u.AsULONG<<8); /*256字节的PCI配置空间*/

for(int i=0;i<0x100;i+=4)

{

/*Read*/

SetPortVal(PCI_CONFIG_ADDRESS, dwAddr|i, 4);

GetPortVal(PCI_CONFIG_DATA, &dwData, 4);

memcpy(((PUCHAR)&pci_config)+i,&dwData,4);

}

printf("bus:%d\tdev:%d\tfunc:%d\n",bus,dev,func); printf("VendorID:%x\n",pci_config.VendorID);

printf("DeviceID:%x\n",pci_config.DeviceID);

printf("Command:%x\n",pci_config.Command);

printf("Status:%x\n",pci_config.Status);

printf("RevisionID:%x\n",pci_config.RevisionID);

printf("ProgIf:%x\n",pci_config.ProgIf);

printf("SubClass:%x\n",pci_config.SubClass);

printf("BaseClase:%x\n",pci_config.BaseClass);

printf("CacheLineSize:%x\n",pci_config.CacheLineSize);

printf("LatencyTimer:%x\n",pci_config.LatencyTimer);

printf("HeaderType:%x\n",pci_config.HeaderType);

printf("BIST:%x\n",pci_config.BIST);

for(i=0;i<6;i++)

{

printf("BaseAddresses[%d]:0X%08X\n",i,pci_config.u.type0.BaseAddresses[i]);

}

printf("InterruptLine:%d\n",pci_config.u.type0.InterruptLine);

printf("InterruptPin:%d\n",pci_config.u.type0.InterruptPin);

}

int main()

{

bool bResult=0;

bResult = InitializeWinIo();

if (bResult)

{

DisplayPCIConfiguation(0,7,2);

RemoveWinIoDriver();

ShutdownWinIo();

}

else

{

printf("WinIo初始化期间出错。\n");

exit(1);

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值