在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
EETOP诚邀模拟IC相关培训讲师 创芯人才网--重磅上线啦!
查看: 3333|回复: 1

这段程序那里不对,运行出现 应用程序出现异常 错误

[复制链接]
发表于 2004-8-8 14:47:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
[这个贴子最后由sunyzs在 2004/08/08 02:48pm 第 1 次编辑]

#include "stdio.h"
typedef unsigned long DWORD;
typedef unsigned short WORD;
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=");
          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 CacheLineSize=");
          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;
}
发表于 2004-8-9 08:43:57 | 显示全部楼层

这段程序那里不对,运行出现 应用程序出现异常 错误

基于NT的系统(NT,2k,XP)不能在应用层对io空间进行操作。
你可以安装windriver,然后用向导产生程序进行操作。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-6-10 05:36 , Processed in 0.025431 second(s), 10 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表