PCI访问完整代码

读取PCI,BUS 0,DEV 0,FUN 0配置空间中完整的256字节的数据:

#include   
#include   
#include   
#include   
  
  
int a[16][16];  
void output()/*矩阵输出*/  
{  
  
    int i,j,h;  
    clrscr();  
    printf("  ");  
    for(i = 1;i<17;i++)  
    {  
        a[0][i] = i-1;  
        printf(" %02x",a[0][i]);  
    }  
    printf("\n");  
    for(j = 0;j<16;j++)  
    {  
        a[j+1][0] = j;  
        printf("%02x",a[j+1][0]);  
        for(h = 1;h<17;h++)  
        {  
            printf(" %02x",a[j+1][h]);  
        }  
        printf("\n");  
    }     
  
}  
unsigned long int get(unsigned long int Addr)/*寻址读取数据*/  
{  
    unsigned long int data;  
    asm mov dx,0xcf8     
    asm db 0x66     
    asm mov ax, Addr  
    asm db 0x66     
    asm out dx,ax     
    asm mov dx,0xcfc     
    asm db 0x66     
    asm in ax,dx     
    asm db 0x66     
    asm mov data,ax  
    return data;  
}  
  
void main()  
{  
    int n,m,k,l;  
    int offset;  
    unsigned long int Addr,Bus,Dev,Fun,data,ll,lh,hl,hh;  
    unsigned long int Baseaddress;  
    offset = 0;  
    Baseaddress = 0x80000000;  
    Bus = 0;  
    Dev = 0;  
    Fun = 0;  
    l = 0;  
    m = 1;  
    for(n = 0;n<64;n++)  
    {  
        Addr = Baseaddress+(Bus<<16)+(Dev<<11)+(Fun<<8)+offset;  
        data = get(Addr);  
        offset = offset+4;  
        ll = data&0x000000ff;/*将32位数据拆减成8位输出*/  
        lh = (data>>8)&0x0000ff;  
        hl = (data>>16)&0x00ff;  
        hh = (data>>24)&0xff;  
        a[m][l*4+1] = ll;  
        a[m][l*4+2] = lh;  
        a[m][l*4+3] = hl;  
        a[m][l*4+4] = hh;  
        l++;  
        if(0 == n%4&& 0 != n)  
        {  
            m++;  
            l = l-4;  
        }  
    }  
   output();  
   getch();  
}  

 

转载于:https://www.cnblogs.com/wudibuzaijia/p/8481071.html

你可能感兴趣的:(PCI访问完整代码)