关闭

如何获取AHCI base address <二>

标签: ahcic#
707人阅读 评论(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;
        }


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:4628次
    • 积分:115
    • 等级:
    • 排名:千里之外
    • 原创:5篇
    • 转载:1篇
    • 译文:0篇
    • 评论:3条
    文章分类