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

📄 pci.c

📁 此代码用于生成测试PCI设备的Verilog代码(Verilog代码为一种硬件描述语言)。此代码可以直接运行于LINUX下。
💻 C
📖 第 1 页 / 共 2 页
字号:
	    if (idx < word_addr)		  use_val = val[idx];	    else		  use_val = 0;	    value.format = vpiIntVal;	    value.value.integer = use_val;	    vpi_put_value(word, &value, 0, vpiNoDelay);	    idx += 1;      }      return 0;}static int master_response_compiletf(char*cd){      return 0;}static int master_response_calltf(char*cd){      int rc;      char buf[1024], *cp;      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);      vpiHandle argv = vpi_iterate(vpiArgument, sys);      vpiHandle word;      assert(argv);      cp = buf;      while ((word = vpi_scan(argv))) {	    s_vpi_value value;	    value.format = vpiIntVal;	    vpi_get_value(word, &value);	    *cp++ = ' ';	    sprintf(cp, "0x%x", value.value.integer);	    cp += strlen(cp);      }      *cp++ = '\n';      *cp = 0;      fputs(buf, cfd1);      fflush(cfd1);      return 0;}static int memory_open_sizetf(void){      return 32;}static int memory_open_compiletf(char*cd){      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);      vpiHandle argv = vpi_iterate(vpiArgument, sys);      vpiHandle path, size;	/* Make sure the first argument exists. */      path = vpi_scan(argv);      assert(path);	/* Make sure the second argument exists. */      size = vpi_scan(argv);      assert(size);      return 0;}static int memory_open_calltf(char*cd){      int rc;      int id;      s_vpi_value value;      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);      vpiHandle argv = vpi_iterate(vpiArgument, sys);      vpiHandle path, size;	/* Make sure the first argument exists and is a reg. */      path = vpi_scan(argv);      assert(path);	/* Make sure the second argument exists and is a memory. */      size = vpi_scan(argv);      assert(size);      id = 0;      value.format = vpiStringVal;      vpi_get_value(path, &value);      memory_map[id].path = strdup(value.value.str);      value.format = vpiIntVal;      vpi_get_value(size, &value);      memory_map[id].fd = open(memory_map[id].path, O_RDWR|O_CREAT, 0666);      if (memory_map[id].fd == -1) {	    perror(memory_map[id].path);      }      memory_map[id].size = value.value.integer;      ftruncate(memory_map[id].fd, value.value.integer);      memory_map[id].base = mmap(0, value.value.integer,				 PROT_READ|PROT_WRITE,				 MAP_SHARED, memory_map[id].fd, 0);      if (memory_map[id].base == MAP_FAILED) {	    vpi_printf("pci: Failed to map %s: errno=%d\n",		       memory_map[id].path, errno);      }      assert(memory_map[id].base != MAP_FAILED);      value.format = vpiIntVal;      value.value.integer = id;      vpi_put_value(sys, &value, 0, vpiNoDelay);      return 0;}static int memory_peek_sizetf(void){      return 32;}static int memory_peek_compiletf(char*cd){      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);      vpiHandle argv = vpi_iterate(vpiArgument, sys);      vpiHandle fd, addr, bar, junk;      assert(argv);      fd = vpi_scan(argv);      assert(fd);      addr = vpi_scan(argv);      assert(addr);      bar = vpi_scan(argv);      assert(bar);      junk = vpi_scan(argv);      assert(junk == 0);      return 0;}static int memory_peek_calltf(char*cd){      int id;      unsigned address, bar_select;      s_vpi_value value;      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);      vpiHandle argv = vpi_iterate(vpiArgument, sys);      vpiHandle fd, addr, bar;      assert(argv);      fd = vpi_scan(argv);      assert(fd);      value.format = vpiIntVal;      vpi_get_value(fd, &value);      id = value.value.integer;      addr = vpi_scan(argv);      assert(addr);      value.format = vpiIntVal;      vpi_get_value(addr, &value);      address = value.value.integer % memory_map[id].size;      bar = vpi_scan(argv);      assert(bar);      value.format = vpiIntVal;      vpi_get_value(bar, &value);      bar_select = value.value.integer;      switch (bar_select) {	  case 0:	    value.format = vpiIntVal;	    value.value.integer =		    (memory_map[id].base[address+0] <<  0)		  | (memory_map[id].base[address+1] <<  8)		  | (memory_map[id].base[address+2] << 16)		  | (memory_map[id].base[address+3] << 24);	    break;	  case 1:	    value.format = vpiIntVal;	    value.value.integer = memory_map[id].control_regs[address/4];	    break;	  default:	    value.format = vpiIntVal;	    value.value.integer = 0xffffffff;	    break;      }      vpi_put_value(sys, &value, 0, vpiNoDelay);      return 0;}static int memory_poke_compiletf(char*cd){      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);      vpiHandle argv = vpi_iterate(vpiArgument, sys);      vpiHandle fd, addr, word, bar, junk;      assert(argv);      fd = vpi_scan(argv);      assert(fd);      addr = vpi_scan(argv);      assert(addr);      word = vpi_scan(argv);      assert(word);      bar = vpi_scan(argv);      assert(bar);      junk = vpi_scan(argv);      assert(junk == 0);      return 0;}static int memory_poke_calltf(char*cd){      int id;      unsigned address, bar_select;      unsigned long word_val;      s_vpi_value value;      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);      vpiHandle argv = vpi_iterate(vpiArgument, sys);      vpiHandle fd, addr, word, bar;      assert(argv);      fd = vpi_scan(argv);      assert(fd);      value.format = vpiIntVal;      vpi_get_value(fd, &value);      id = value.value.integer;      addr = vpi_scan(argv);      assert(addr);      value.format = vpiIntVal;      vpi_get_value(addr, &value);      address = value.value.integer % memory_map[id].size;      word = vpi_scan(argv);      assert(word);      value.format = vpiIntVal;      vpi_get_value(word, &value);      word_val = value.value.integer;      bar = vpi_scan(argv);      assert(bar);      value.format = vpiIntVal;      vpi_get_value(bar, &value);      bar_select = value.value.integer;      switch (bar_select) {	  case 0:	    memory_map[id].base[address+0] = word_val & 0xff;	    word_val >>= 8;	    memory_map[id].base[address+1] = word_val & 0xff;	    word_val >>= 8;	    memory_map[id].base[address+2] = word_val & 0xff;	    word_val >>= 8;	    memory_map[id].base[address+3] = word_val & 0xff;	    break;	  case 1:	    memory_map[id].control_regs[address/4] = word_val;	    if (address == 0)		  memdev_command(id);	    break;	  default:	    break;      }      return 0;}static void sys_pci_register(){      s_vpi_systf_data tf_data;      s_cb_data cb_data;      tf_data.type      = vpiSysTask;      tf_data.tfname    = "$pci_master_command";      tf_data.calltf    = master_command_calltf;      tf_data.compiletf = master_command_compiletf;      tf_data.sizetf    = 0;      tf_data.user_data = "$pci_master_command";      vpi_register_systf(&tf_data);      tf_data.type      = vpiSysTask;      tf_data.tfname    = "$pci_master_response";      tf_data.calltf    = master_response_calltf;      tf_data.compiletf = master_response_compiletf;      tf_data.sizetf    = 0;      tf_data.user_data = "$pci_master_response";      vpi_register_systf(&tf_data);      tf_data.type      = vpiSysFunc;      tf_data.tfname    = "$pci_memory_open";      tf_data.calltf    = memory_open_calltf;      tf_data.compiletf = memory_open_compiletf;      tf_data.sizetf    = memory_open_sizetf;      tf_data.user_data = "$pci_memory_open";      vpi_register_systf(&tf_data);      tf_data.type      = vpiSysFunc;      tf_data.tfname    = "$pci_memory_peek";      tf_data.calltf    = memory_peek_calltf;      tf_data.compiletf = memory_peek_compiletf;      tf_data.sizetf    = memory_peek_sizetf;      tf_data.user_data = "$pci_memory_peek";      vpi_register_systf(&tf_data);      tf_data.type      = vpiSysTask;      tf_data.tfname    = "$pci_memory_poke";      tf_data.calltf    = memory_poke_calltf;      tf_data.compiletf = memory_poke_compiletf;      tf_data.sizetf    = 0;      tf_data.user_data = "$pci_memory_poke";      vpi_register_systf(&tf_data);	/* Arrange for a cleanup function to be called when the	   simulation is finished. */      cb_data.reason = cbEndOfSimulation;      cb_data.cb_rtn = cleanup;      cb_data.obj    = 0;      cb_data.time   = 0;      vpi_register_cb(&cb_data);}void (*vlog_startup_routines[])() = {      sys_pci_register,      0};/* * $Log: pci.c,v $ * Revision 1.8  2003/11/07 00:52:26  steve *  Remember to close memory dump file. * * Revision 1.7  2003/09/16 23:35:15  steve *  Respond to LOAD and SAVE commands * * Revision 1.6  2003/02/21 20:34:25  steve *  Difference diagnostics for memory compare. * * Revision 1.5  2002/10/16 16:58:12  steve *  License updates. * * Revision 1.4  2002/08/22 01:30:06  steve *  Add the pcisim memdev device to the library. * * Revision 1.3  2002/05/29 05:27:48  steve *  mmap correct fd * * Revision 1.2  2002/05/12 23:53:14  steve *  Add memory write cycles to master and memory. * * Revision 1.1  2002/05/12 22:17:17  steve *  Add pcisim to CVS. * */

⌨️ 快捷键说明

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