如何获取AHCI base address <二>

来源:互联网 发布:在数组中添加元素 编辑:程序博客网 时间:2024/05/17 06:58

我之前有篇文章有些利用第三方工具包来获取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 Addressbit description 0- 2 Function Number 3- 7 Device Number 8-15 PCI Bus Number 16-31 Reserved RequirementsWinRing0 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;        }


原创粉丝点击