如何获取AHCI base address <二>

3 篇文章 0 订阅

我之前有篇文章有些利用第三方工具包来获取AHCI base address,这次我要讲的是利用WinRing0这个开源dll来完成这个功能。

请看WinRing0API的说明:

Support Functions for PCI Access 
C++ (OlsDef.h) *Macro
// Bus Number, Device Number and Function Number to PCI Device Address#define PciBusDevFunc(Bus, Dev, Func) ((Bus&0xFF)<<8) | ((Dev&0x1F)<<3) | (Func&7)
// PCI Device Address to Bus Number
#define PciGetBus(address)            ((address>>8) & 0xFF)
// PCI Device Address to Device Number#define PciGetDev(address)            ((address>>3) & 0x1F)
// PCI Device Address to Function Number
#define PciGetFunc(address)           (address&7)C# (OpenLibSys.cs) 
// Bus Number, Device Number and Function Number to PCI Device Addresspublic uint PciBusDevFunc(uint bus, uint dev, uint func)
{
    return ((bus&0xFF)<<8) | ((dev&0x1F)<<3) | (func&7);
}
// PCI Device Address to Bus Numberpublic uint PciGetBus(uint address)
{
    return ((address>>8) & 0xFF);
}
// PCI Device Address to Device Numberpublic uint PciGetDev(uint address)
{
    return ((address>>3) & 0x1F);
}
// PCI Device Address to Function Numberpublic uint PciGetFunc(uint address)
{
    return (address&7);
}PCI Device Address
bit description 
0- 2 Function Number 
3- 7 Device Number 
8-15 PCI Bus Number 
16-31 Reserved 

Requirements
WinRing0 1.0 or later 

啦啦啦 看到了吧 我们可以用OpenLibSys.cs中现成的

PciBusDevFunc(uint bus, uint dev, uint func)
方法,就可以得到AHCI base address啦!有木有很激动?!

  附上调用的代码

 /**getAHCIbaseAddress**/
        public string getAHCIbaseAddress()
        {
            uint address = ols.PciBusDevFunc(0x00, 0x1F, 0x02);

            //add by kelsey
            string ahciBaseAddress = "";

            // Host Bridge
            if (address != 0xFFFFFFFF)
            {
                for (int i = 0; i < 256; i += 16)
                {
                    //str += i.ToString("X2") + "|";
                    for (int j = 0; j < 16; j++)
                    {
                        if (i == 32 && j == 4)
                        {
                            ahciBaseAddress = (ols.ReadPciConfigDword(address, (byte)(i + j))).ToString("X2");
                            break;
                        }
                    }
                }
                Console.WriteLine("ahciBaseAddress ==" + ahciBaseAddress);
            }
            return ahciBaseAddress;
        }


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值