⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcisim_memdev.c

📁 此代码用于生成测试PCI设备的Verilog代码(Verilog代码为一种硬件描述语言)。此代码可以直接运行于LINUX下。
💻 C
字号:
/* * Copyright (c) 2002 Picture Elements, Inc. *    Stephen Williams (steve@picturel.com) */#ident "$Id: pcisim_memdev.c,v 1.4 2003/09/16 23:38:08 steve Exp $"# include  "pcisim_memdev.h"# include  "pcisim.h"# include  <malloc.h># define FILL_CMD    0x0000# define COMPARE_CMD 0x0001# define LOAD_CMD    0x0002# define SAVE_CMD    0x0003struct pcisim_memdev_s {      unsigned config;      unsigned long bar0;      unsigned long bar1;};static void m1writel(struct pcisim_memdev_s*xsp,		     unsigned long off, unsigned long val){      pcisim_writel(xsp->bar1 + off, val);}static unsigned long m1readl(struct pcisim_memdev_s*xsp,			     unsigned long off){      return pcisim_readl(xsp->bar1 + off);}pcisim_memdev_t pcisim_memdev_init(unsigned config){      unsigned long val;      struct pcisim_memdev_s*xsp = calloc(1, sizeof(struct pcisim_memdev_s));      xsp->config = config;      val = pcisim_config_read(xsp->config + 16);      xsp->bar0 = val & ~15;      val = pcisim_config_read(xsp->config + 20);      xsp->bar1 = val & ~15;      return xsp;}unsigned long pcisim_memdev_start(pcisim_memdev_t xsp){      return xsp->bar0;}void pcisim_memdev_fill(pcisim_memdev_t xsp,			unsigned long off, unsigned cnt,			unsigned long fill){      m1writel(xsp,  4, off);      m1writel(xsp,  8, cnt);      m1writel(xsp, 12, fill);	/* This starts the command going. */      m1writel(xsp,  0, FILL_CMD);}int pcisim_memdev_compare(pcisim_memdev_t xsp,			  unsigned long off0,			  unsigned long off1,			  unsigned cnt0){      unsigned long rc;      m1writel(xsp,  4, off0);      m1writel(xsp,  8, cnt0);      m1writel(xsp, 12, off1);      m1writel(xsp,  0, COMPARE_CMD);      rc = m1readl(xsp, 0);      return (rc == 0)? 0 : 1;}int pcisim_memdev_load(pcisim_memdev_t xsp,		       unsigned long offset,		       unsigned long count,		       const char*file){      int rc;      m1writel(xsp,  4, offset);      m1writel(xsp,  8, count);      rc = 12;      while (file[0] != 0) {	    unsigned long word = 0;	    word |= ((unsigned long)file[0] <<  0) & 0x000000ffUL;	    if (file[0] != 0) file += 1;	    word |= ((unsigned long)file[0] <<  8) & 0x0000ff00UL;	    if (file[0] != 0) file += 1;	    word |= ((unsigned long)file[0] << 16) & 0x00ff0000UL;	    if (file[0] != 0) file += 1;	    word |= ((unsigned long)file[0] << 24) & 0xff000000UL;	    if (file[0] != 0) file += 1;	    m1writel(xsp, rc, word);	    rc += 4;      }      m1writel(xsp, rc, 0);      m1writel(xsp, 0, LOAD_CMD);      rc = m1readl(xsp, 0);      return rc;}int pcisim_memdev_save(pcisim_memdev_t xsp,		       unsigned long offset,		       unsigned long count,		       const char*file){      int rc;      m1writel(xsp,  4, offset);      m1writel(xsp,  8, count);      rc = 12;      while (file[0] != 0) {	    unsigned long word = 0;	    word |= (file[0] <<  0) & 0x000000ffUL;	    if (file[0] != 0) file += 1;	    word |= (file[0] <<  8) & 0x0000ff00UL;	    if (file[0] != 0) file += 1;	    word |= (file[0] << 16) & 0x00ff0000UL;	    if (file[0] != 0) file += 1;	    word |= (file[0] << 24) & 0xff000000UL;	    if (file[0] != 0) file += 1;	    m1writel(xsp, rc, word);	    rc += 4;      }      m1writel(xsp, rc, 0);      m1writel(xsp, 0, SAVE_CMD);      rc = m1readl(xsp, 0);      return rc;}			  /* * $Log: pcisim_memdev.c,v $ * Revision 1.4  2003/09/16 23:38:08  steve *  Add load and save commands. * * Revision 1.3  2002/10/16 16:54:24  steve *  Copyright and License notice. * * Revision 1.2  2002/09/08 00:03:10  steve *  Reorder compare parameters to be consistent with memcmp * * Revision 1.1  2002/08/22 01:30:06  steve *  Add the pcisim memdev device to the library. * */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -