happypotato
驱动牛犊
驱动牛犊
  • 注册日期2004-03-31
  • 最后登录2005-09-01
  • 粉丝0
  • 关注0
  • 积分11分
  • 威望3点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1001回复:2

有关驱动找卡的那段程序

楼主#
更多 发布于:2004-09-23 16:22
压根不会编译驱动,直接从网上down了一段源码用,就是开始的部分
写0xcf8读0xcfc的
#include "stdio.h"
#include "windows.h"
DWORD DWORD_In(WORD io_Port)
{   DWORD val;
    _asm {
        mov dx,io_Port
        in eax,dx
        mov val,eax
    }
    return val;
}
DWORD DWORD_Out(WORD io_Port,DWORD val)
{
    _asm {
        mov dx,io_Port
        mov eax,val
        out dx,eax
    }
    return 0;
}
int main()
{    
    DWORD io_CF8;   // port 0xcf8
    DWORD io_CFC;   // port 0xcfc
    int i;
    io_CF8=0x80000000;   //because the first bit is enable/disable
    for(;;)              //so must be 1,so from 0x800000000
    {    
        
        DWORD_Out(0xcf8,io_CF8);
        io_CFC=DWORD_In(0xcfc);
        
        if (io_CFC!=0xffffffff)  //if =0xffffffff,then is a invalid
        {                        //bus number and device number
            printf("\nPCI device has found,the pci config address=%lx\n",io_CF8);
            printf("its Bus Numer is %lx \n",(io_CF8&0x00ff0000)/0x10000);
            printf("its Device Number is %lx \n",(io_CF8&0x0000f800)/0x800);
            printf("its Functin Number is %lx \n",(io_CF8&0x700)/0x100);

            printf("this device's deviceID and vendorID=%lx\n",io_CFC);
            for (i=0 ;i<=15;i++)
            {
            DWORD_Out(0xcf8,io_CF8+4*i);  //read DWORD
            switch (i)
            {
            case 0:
                   printf("Device Number and Vendor Number =%lx");
                break;
            case 1:
                printf("Status and Command =");
                break;
            case 2:
                printf("Class Code and Revision ID=");
                break;
            case 3:
                printf("Bist and Header Type and Latency Timer and Cacne Line

Size=");
                break;
            case 4:         //PCI Configration has 6 base address
            case 5:         //register
           case 6:
            case 7:
            case 8:
            case 9:
                printf("Base Address Register=");
                break;
            case 10:
            case 11:
            case 13:
            case 14:
                printf("Reserved =");
                break;
            case 12:
                printf("Expansion ROM Base Address=");
                break;
            case 15:  //attention:the interrupt IRQ= this result&0xff
                printf("Max_Lat Min_Gnt Interrupt Pin Interrupt line=");
                break;
            }
            printf("%lx\n",DWORD_In(0xcfc));
            }
            
        }
        io_CF8+=0x800;    
        
        if (io_CF8>=0x80FFFF00)    
            break;
    }
    
   return 0;
}  
为什么编译没有错误,在单步运行到 “out dx,eax”的时候就运行不下去了呢?提示说:
unhandled exception in qudong.exe:0xc0000096;privileged instruction.
      
不要笑我太无知
seaquester
驱动大牛
驱动大牛
  • 注册日期2002-05-22
  • 最后登录2016-06-16
  • 粉丝0
  • 关注0
  • 积分500分
  • 威望115点
  • 贡献值0点
  • 好评度107点
  • 原创分0分
  • 专家分52分
沙发#
发布于:2004-09-23 18:23
这段程序不能在Win2000/XP下用
八风舞遥翩,九野弄清音。 鸣高常向月,善舞不迎人。
happypotato
驱动牛犊
驱动牛犊
  • 注册日期2004-03-31
  • 最后登录2005-09-01
  • 粉丝0
  • 关注0
  • 积分11分
  • 威望3点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2004-09-27 08:47
那么在win2000下要写0xcf8,读0xcfc要各自用什么函数呢?
不要笑我太无知
游客

返回顶部