Пример #1
0
static void
hostcons_putchar(int c)
{
	uint8_t ch = c;

	host_write(1, &ch, 1);
}
Пример #2
0
// Flush the contents of the block containing VA out to disk if
// necessary, then clear the PTE_D bit using sys_page_map.
// If the block is not in the block cache or is not dirty, does
// nothing.
// Hint: Use va_is_mapped, va_is_dirty, and ide_write.
// Hint: Use the PTE_SYSCALL constant when calling sys_page_map.
// Hint: Don't forget to round addr down.
void
flush_block(void *addr)
	{
		uint64_t blockno = ((uint64_t)addr - DISKMAP) / BLKSIZE;
		int r;
		
		if (addr < (void*)DISKMAP || addr >= (void*)(DISKMAP + DISKSIZE))
			panic("flush_block of bad va %08x", addr);
	
		// LAB 5: Your code here.
		//panic("flush_block not implemented");
		if(va_is_mapped(addr) == false || va_is_dirty(addr) == false)
		{
			return;
		}
		addr = ROUNDDOWN(addr, PGSIZE);
#ifdef VMM_GUEST
		if(0 != host_write((uint32_t) (blockno * BLKSECTS), (void*)addr, BLKSECTS))
		{
			panic("ide read failed in Page Fault Handling");		
		}
#else
		if(0 != ide_write((uint32_t) (blockno * BLKSECTS), (void*)addr, BLKSECTS))
		{
			panic("ide write failed in Flush Block");	
		}
#endif	
		if ((r = sys_page_map(0, addr, 0, addr, PTE_SYSCALL)) < 0)
		{
			panic("in flush_block, sys_page_map: %e", r);
		}
	}
Пример #3
0
static int host_command3(struct sscape_info *devc, int cmd, int parm1, int parm2)
{
	unsigned char buf[10];

	buf[0] = (unsigned char) (cmd & 0xff);
	buf[1] = (unsigned char) (parm1 & 0xff);
	buf[2] = (unsigned char) (parm2 & 0xff);
	return host_write(devc, buf, 3);
}
Пример #4
0
int LJCL_GPU_MemoryT::init(const int ntypes,
                           double **host_cutsq, double **host_lj1, 
                           double **host_lj2, double **host_lj3, 
                           double **host_lj4, double **host_offset, 
                           double *host_special_lj, const int nlocal,
                           const int nall, const int max_nbors,
                           const int maxspecial, const double cell_size,
                           const double gpu_split, FILE *_screen,
                           double **host_cut_ljsq, const double host_cut_coulsq,
                           double *host_special_coul, const double qqrd2e,
                           const double g_ewald) {
  int success;
  success=this->init_atomic(nlocal,nall,max_nbors,maxspecial,cell_size,gpu_split,
                            _screen,ljcl_cut_gpu_kernel);
  if (success!=0)
    return success;

  // If atom type constants fit in shared memory use fast kernel
  int lj_types=ntypes;
  shared_types=false;
  int max_shared_types=this->device->max_shared_types();
  if (lj_types<=max_shared_types && this->_block_size>=max_shared_types) {
    lj_types=max_shared_types;
    shared_types=true;
  }
  _lj_types=lj_types;

  // Allocate a host write buffer for data initialization
  UCL_H_Vec<numtyp> host_write(lj_types*lj_types*32,*(this->ucl_device),
                               UCL_WRITE_OPTIMIZED);

  for (int i=0; i<lj_types*lj_types; i++)
    host_write[i]=0.0;

  lj1.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
  this->atom->type_pack4(ntypes,lj_types,lj1,host_write,host_lj1,host_lj2,
			 host_cutsq, host_cut_ljsq);

  lj3.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
  this->atom->type_pack4(ntypes,lj_types,lj3,host_write,host_lj3,host_lj4,
		         host_offset);

  sp_lj.alloc(8,*(this->ucl_device),UCL_READ_ONLY);
  for (int i=0; i<4; i++) {
    host_write[i]=host_special_lj[i];
    host_write[i+4]=host_special_coul[i];
  }
  ucl_copy(sp_lj,host_write,8,false);

  _cut_coulsq=host_cut_coulsq;
  _qqrd2e=qqrd2e;
  _g_ewald=g_ewald;

  _allocated=true;
  this->_max_bytes=lj1.row_bytes()+lj3.row_bytes()+sp_lj.row_bytes();
  return 0;
}
Пример #5
0
static int
host_command1 (struct sscape_info *devc, int cmd)
{
  unsigned char   buf[10];

  buf[0] = (unsigned char) (cmd & 0xff);

  return host_write (devc, buf, 1);
}
Пример #6
0
static int
host_command2(struct sscape_info * devc, int cmd, int parm1)
{
	u_char   buf[10];

	buf[0] = (u_char) (cmd & 0xff);
	buf[1] = (u_char) (parm1 & 0xff);

	return host_write(devc, buf, 2);
}
Пример #7
0
void
nuse_vif_pipe_write(struct nuse_vif *vif, struct SimDevice *dev,
		    unsigned char *data, int len)
{
	int sock = vif->sock;
	int ret = host_write(sock, data, len);

	if (ret == -1)
		perror ("write");
}
Пример #8
0
// Flush the contents of the block containing VA out to disk if
// necessary, then clear the PTE_D bit using sys_page_map.
// If the block is not in the block cache or is not dirty, does
// nothing.
// Hint: Use va_is_mapped, va_is_dirty, and ide_write.
// Hint: Use the PTE_SYSCALL constant when calling sys_page_map.
// Hint: Don't forget to round addr down.
    void
flush_block(void *addr)
{
	uint64_t blockno = ((uint64_t)addr - DISKMAP) / BLKSIZE;
	int r;

    if (addr < (void*)DISKMAP || addr >= (void*)(DISKMAP + DISKSIZE))
        panic("flush_block of bad va %08x", addr);
		
			// LAB 5: Your code here.
	if((va_is_mapped(addr))&&(va_is_dirty(addr)))
	#ifndef VMM_GUEST
		ide_write(blockno*BLKSECTS, ROUNDDOWN(addr,BLKSIZE), BLKSECTS);
	#else
		host_write(blockno*BLKSECTS, ROUNDDOWN(addr,BLKSIZE), BLKSECTS);
	#endif	
	if((va_is_mapped(addr)) && ((r = sys_page_map(0, ROUNDDOWN(addr,PGSIZE), 0, ROUNDDOWN(addr,PGSIZE), PTE_SYSCALL&~PTE_D)) < 0))
			panic("Couldn't flush disk page%e",r);
}
Пример #9
0
// Flush the contents of the block containing VA out to disk if
// necessary, then clear the PTE_D bit using sys_page_map.
// If the block is not in the block cache or is not dirty, does
// nothing.
// Hint: Use va_is_mapped, va_is_dirty, and ide_write.
// Hint: Use the PTE_SYSCALL constant when calling sys_page_map.
// Hint: Don't forget to round addr down.
void
flush_block(void *addr)
{
	uint64_t blockno = ((uint64_t)addr - DISKMAP) / BLKSIZE;
	int r;	

	if (addr < (void*)DISKMAP || addr >= (void*)(DISKMAP + DISKSIZE))
		panic("flush_block of bad va %08x", addr);

	// LAB 5: Your code here.
	addr = ROUNDDOWN(addr,BLKSIZE);
	if (va_is_mapped(addr) && va_is_dirty(addr))
#ifdef VMM_GUEST
		host_write(blockno*BLKSECTS, addr, BLKSECTS);
#else
		ide_write(blockno*BLKSECTS, addr, BLKSECTS);
#endif
	if(va_is_mapped(addr)) {
		if ((r = sys_page_map(0,addr,0,addr,PTE_SYSCALL&~PTE_D))<0)
			cprintf("error in flushing the block : %e\n",r);
	}
	//panic("flush_block not implemented");
}
int main(int argc, char **argv)
{
   int status;
   int nrx_fd;
   int host_rfd;
   int host_wfd;
   int use_stdin = 0;
   char * ser_dev = NULL;
   int port = 12345;
   char * filename = default_filename;
   void * handle = NULL;
   int host_flash = 0;
   int input_baudrate = 115200;
   speed_t baudrate = B115200;
   int opt;

   struct ifreq ifr;
   struct nanoioctl nr;
   
   while((opt = getopt(argc, argv, "d:s:p:f:b:i")) != -1) {
      switch(opt) {
         case 'b':
            input_baudrate = atoi(optarg);
            switch(input_baudrate) {
               case 9600: baudrate = B9600; break;
               case 19200: baudrate = B19200; break;
               case 38400: baudrate = B38400; break;
               case 57600: baudrate = B57600; break;
               case 115200: baudrate = B115200; break;
               default: usage();
            }
            break;
         case 'd':
            debug = atoi(optarg);
            break;
         case 'f':
            filename = optarg;
            break;
         case 'i':
            use_stdin = 1;
            break;
         case 'p':
            port = atoi(optarg);
            break;
         case 's':
            ser_dev = optarg;
            break;
         default:
            break;
      }
   }
   if(optind == argc)
      usage();

   strcpy(ifr.ifr_name, argv[optind]);
   ifr.ifr_data = (char *)&nr;
   memset(&nr,0,sizeof(nr));
   nr.magic = NR_MAGIC;

   APP_INFO("Nanoradio network interface: %s\n", ifr.ifr_name);
   APP_INFO("Saving persistent MIB data of type HOST to: %s\n", filename);

   if(use_stdin) {
      APP_INFO("Using stdin/stdout as client interface\n");
      host_wfd = host_rfd = open_terminal();
      redirect_stdout("/tmp/hic_proxy.log");
   } else if(ser_dev) 
      {
	APP_INFO("Using %s (baudrate = %d) as serial client interface\n", ser_dev,input_baudrate);
	host_wfd = host_rfd = open_serial(ser_dev, baudrate);
      }
   else 
      {
         APP_INFO("Using ethernet as client interface\n");
         host_wfd = host_rfd = open_socket(port);
      }
    
   nrx_fd = socket(AF_INET, SOCK_DGRAM, 0);
   if(nrx_fd < 0) err(1, "socket");

   for(;;) {      
      status = poll_host(host_rfd, &ifr);
      if(status) {
	
         
         if((nr.data[TYPE_INDEX] ==  HIC_MESSAGE_TYPE_FLASH_PRG))
            {
               APP_DEBUG("flash cmd recieved\n");

               //examine flash cmd
               handle = flash_cmd(&ifr,handle,filename);
 
               if(handle)
                  {
                     //send local host flash cmd reply
                     host_write(host_wfd, nr.data, nr.length);
                  }
               else
                  {
                     //forward to target
                     nrx_write(nrx_fd, &ifr);
                  }
            }
         else
            {
               //forward to target
               nrx_write(nrx_fd, &ifr);
            }
      }
	
      status = poll_target(nrx_fd, &ifr);
  
      if(status)
         host_write(host_wfd, nr.data, nr.length);

      usleep(5000);
   }

   if(!use_stdin) {
      close(host_rfd);
   }
   close(nrx_fd);
}
Пример #11
0
void hostif_put(char c)
{
	host_write(STDOUT_FILENO, &c, 1);
}