Note: Find PCI Device on DOS/PC

一段找PCI Device 的Macro code from http://www.arium.com/support/macros.html

基本上跟 DOS下的 C code 差不多, 理面還有PCI Express access 的define.

//————————————————————–
// Scans the first 32 PCI busses and displays each device found.
//————————————————————–

define proc findpci()
{
  define byte busnumber     // 256 PCI buses per system
  define byte devnumber     // 32 PCI devices per bus
  define byte funcnumber    // 8 functions per PCI device
  define byte regnumber     // 64 registers per function
  define dword pciaddress
  define dword addr
  define dword data

  printf("nScanning register 00h of all devices on PCI busses 00h through 1Fh.n")
  printf("It may take several minutes for this process to complete.n")
  printf("A ‘Done’ message will be displayed when it is complete.nn")

  for (busnumber = 0; busnumber <= 01fh; busnumber++)
  {
    for (devnumber = 0; devnumber <= 1fh; devnumber++)
    {
      for (funcnumber = 0; funcnumber <= 07h; funcnumber++)
      {
        regnumber = 0h
        addr = pciaddr(busnumber,devnumber,funcnumber,regnumber)
        dport(0cf8h) = addr
        data = dport(0cfch)
        if (data != 0ffffffffh)
        {
          printf("Bus# %02X, Dev# %02X, ", busnumber, devnumber)
          printf("Func# %01X  —>  ", funcnumber)
          printf("Vendor ID = %04X   Device ID = %04Xn", data & 0000ffffh, data >> 16t)
       }
      }
    }
  }

  printf("nScan of busses 00h through 1Fh is now DONE.nn")
}

//——————————————————————–
// Returns a PCI register address. Write this address to dport CF8h to
// access a PCI register.
//——————————————————————–

define proc dword pciaddr(busnumber, devnumber, funcnumber, regnumber)

define byte busnumber     // 256 PCI buses per system
define byte devnumber     // 32 PCI devices per bus
define byte funcnumber    // 8 functions per PCI device
define byte regnumber     // 64 registers per function
{
  if(busnumber > 0xFF)
  {
    printf("Error: busnumber too largen");
    return 0;
  }
  if(devnumber > 0x1F)
  {
    printf("Error: devnumber too largen");
    return 0;
  }
  if(funcnumber > 0x7)
  {
    printf("Error: funcnumber too largen");
    return 0;
  }
  if(regnumber > 0xFF)
  {
    printf("Error: regnumber too largen");
    return 0;
  }

  define dword pciaddress = 00000000h
  pciaddress = pciaddress | busnumber
  pciaddress = pciaddress << 5t
  pciaddress = pciaddress | devnumber
  pciaddress = pciaddress << 3t
  pciaddress = pciaddress | funcnumber
  pciaddress = pciaddress << 8t
  pciaddress = pciaddress | regnumber
  pciaddress = pciaddress | 80000000h
  return (pciaddress)
}

廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s

%d 位部落客按了讚: