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

📄 syscall.c.svn-base

📁 模拟多核状态下龙芯处理器的功能
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
	  }
	else
	  {
#ifdef _MSC_VER
	    warn("syscall getgid() not yet implemented for MSC...");
	    regs->regs_R[7] = 0;
	    break;
#else /* !_MSC_VER */

#if 0 /* FIXME: needed? */
#ifdef TIOCGETP
	    if (local_req == TIOCGETP && sim_progfd)
	      {
		/* program I/O has been redirected to file, make
		   termios() calls fail... */

		/* got an error, return details */
		regs->regs_R[2] = ENOTTY;
		regs->regs_R[7] = 1;
		break;
	      }
#endif
#endif
	    /* ioctl() code was successfully translated to a host code */

	    /* if arg ptr exists, copy NUM_IOCTL_BYTES bytes to host mem */
	    if (/*argp*/regs->regs_R[6] != 0)
	      mem_bcopy(mem_fn, mem,
			Read, /*argp*/regs->regs_R[6], buf, NUM_IOCTL_BYTES);

	    /* perform the ioctl() call */
	    /*result*/regs->regs_R[2] =
	      ioctl(/*fd*/regs->regs_R[4], local_req, buf);

	    /* if arg ptr exists, copy NUM_IOCTL_BYTES bytes from host mem */
	    if (/*argp*/regs->regs_R[6] != 0)
	      mem_bcopy(mem_fn, mem, Write, regs->regs_R[6],
			buf, NUM_IOCTL_BYTES);

	    /* check for an error condition */
	    if (regs->regs_R[2] != -1)
	      regs->regs_R[7] = 0;
	    else
	      {	
		/* got an error, return details */
		regs->regs_R[2] = errno;
		regs->regs_R[7] = 1;
	      }
#endif /* _MSC_VER */
	  }
      }
      break;


	case SS_SYS_fcntl64:/* the fcntl64 syscall may be buggy, so use the fcntl as well */ 
	case SS_SYS_fcntl:
#ifdef _MSC_VER
      warn("syscall fcntl() not yet implemented for MSC...");
      regs->regs_R[7] = 0;
#else /* !_MSC_VER */
      /* get fcntl() information on the file */
      regs->regs_R[2] =
	fcntl(/*fd*/regs->regs_R[4], /*cmd*/regs->regs_R[5],
	      /*arg*/regs->regs_R[6]);

      /* check for an error condition */
      if (regs->regs_R[2] != -1)
	regs->regs_R[7] = 0;
      else
	{
	  /* got an error, return details */
	  regs->regs_R[2] = errno;
	  regs->regs_R[7] = 1;
	}
#endif /* _MSC_VER */
      break;


	case SS_SYS_setpgid:
#ifdef _MSC_VER_	
	warn("syscall setpgid() not yet implemented for MSC...");
	regs->regs_R[7] = 0;
#else /*!_MSC_VER_*/
	  /*setpgid*/regs->regs_R[2] = setpgid(/*pid*/regs->regs_R[4], 
	                                     /*pgid*/regs->regs_R[5]);
	  /* check for an error condition */
      if (regs->regs_R[2] != -1)
		regs->regs_R[7] = 0;
      else
	{
	  /* got an error, return details */
	  regs->regs_R[2] = errno;
	  regs->regs_R[7] = 1;
	}
#endif /*_MSC_VER_*/
    break;
	

	case SS_SYS_olduname:
	{
		struct oldold_utsname *name;
		
		name = (struct oldold_utsname *)malloc(sizeof(struct oldold_utsname));
		if (!name)
	      fatal("out of virtual memory in SYS_uname");
		
		/*result*/regs->regs_R[2] = uname(name);

		/* copy host side memory into target side pointer data */
		mem_bcopy(mem_fn, mem, Write, regs->regs_R[4],
		  name, sizeof(struct oldold_utsname));

		if (regs->regs_R[2] != -1)
		  regs->regs_R[7] = 0;
		else
		  {
			regs->regs_R[2] = errno;
		    regs->regs_R[7] = 1;
		  }
 
		/* free the host memory */
		free(name);
	}
	break;


	case SS_SYS_umask:
	{
	  /*result*/regs->regs_R[2] = umask(/*mask*/regs->regs_R[4]);

	  /* check for an error condition */
      if (regs->regs_R[2] != -1)
		regs->regs_R[7] = 0;
      else
	  {
	    /* got an error, return details */
	    regs->regs_R[2] = errno;
	    regs->regs_R[7] = 1;
	  }
	}
	break;
	

	case SS_SYS_chroot:
	{
		char buf[MAXBUFSIZE];

		/* copy arguments to the host memroy */
		mem_strcpy(mem_fn, mem, Read, /*filename*/regs->regs_R[4], buf);

		/*result*/regs->regs_R[2] = chroot(buf);

		/* check for an error condition */
      if (regs->regs_R[2] != -1)
		regs->regs_R[7] = 0;
      else
	  {
	    /* got an error, return details */
	    regs->regs_R[2] = errno;
	    regs->regs_R[7] = 1;
	  }
	}
	break;


	case SS_SYS_ustat:
	{
		int i;
		struct ustat ubuf;
		struct ss_ustat ss_ubuf;

		/*result*/regs->regs_R[2] = ustat(/*dev*/regs->regs_R[4], &ubuf);

		/* translate from host ustat structure to target format */
		ss_ubuf.ss_f_tfree = MD_SWAPW((long)ubuf.f_tfree);
		ss_ubuf.ss_f_tinode = MD_SWAPW((unsigned long)ubuf.f_tinode);
		for (i=0; i<6; i++)
		{
		  ss_ubuf.ss_f_fname[i] = ubuf.f_fname[i];
		  ss_ubuf.ss_f_fpack[i] = ubuf.f_fpack[i];
		}

		/* copy the result to the target memory */
		mem_bcopy(mem_fn, mem, Write, /*ubuf*/regs->regs_R[5], 
		  &ss_ubuf, sizeof(struct ss_ustat));

		/* check for an error condition */
        if (regs->regs_R[2] != -1)
		  regs->regs_R[7] = 0;
        else
	    {
	      /* got an error, return details */
	      regs->regs_R[2] = errno;
	      regs->regs_R[7] = 1;
	    }
	}
	break;


	case SS_SYS_dup2:
      /* dup2() the file descriptor */
      regs->regs_R[2] =
	dup2(/* fd1 */regs->regs_R[4], /* fd2 */regs->regs_R[5]);

      /* check for an error condition */
      if (regs->regs_R[2] != -1) {
	regs->regs_R[7] = 0;
#ifdef DUMP_SIMPOINT
	  {
	    extern void record_file_dup2(int oldfd,int newfd);
	    record_file_dup2(regs->regs_R[4],regs->regs_R[5]);
	  }
#endif
      }
      else
	{
	  /* got an error, return details */
	  regs->regs_R[2] = errno;
	  regs->regs_R[7] = 1;
	}
      break;


	case SS_SYS_getppid:
#ifdef _MSC_VER
      warn("syscall getppid() not yet implemented for MSC...");
      regs->regs_R[7] = 0;
#else /*!_MSC_VER_*/
	  /*result*/regs->regs_R[2] = getppid();

      /* check for an error condition */
      if (regs->regs_R[2] != -1)
	    regs->regs_R[7] = 0;
      else
	  {
	    /* got an error, return details */
	    regs->regs_R[2] = errno;
	    regs->regs_R[7] = 1;
	  }
#endif /* _MSC_VER */
      break;   


	case SS_SYS_getpgrp:
#ifdef _MSC_VER
      warn("syscall getpgrp() not yet implemented for MSC...");
      regs->regs_R[7] = 0;
#else /*!_MSC_VER_*/
	  /*result*/regs->regs_R[2] = getpgrp();

      /* check for an error condition */
      if (regs->regs_R[2] != -1)
	    regs->regs_R[7] = 0;
      else
	  {
	    /* got an error, return details */
	    regs->regs_R[2] = errno;
	    regs->regs_R[7] = 1;
	  }
#endif /* _MSC_VER */
      break;    


	case SS_SYS_setsid:
#ifdef _MSC_VER
      warn("syscall setsid() not yet implemented for MSC...");
      regs->regs_R[7] = 0;
#else /*!_MSC_VER_*/
	  /*result*/regs->regs_R[2] = setsid();

      /* check for an error condition */
      if (regs->regs_R[2] != -1)
	    regs->regs_R[7] = 0;
      else
	  {
	    /* got an error, return details */
	    regs->regs_R[2] = errno;
	    regs->regs_R[7] = 1;
	  }
#endif /* _MSC_VER */
      break;    


	/* this syscall may be buggy */
	case SS_SYS_sigaction:
	{
		struct sigaction * act, * oact;

		act = (struct sigaction*)malloc(sizeof(struct sigaction));
		oact = (struct sigaction*)malloc(sizeof(struct sigaction));
		if ((!act)||(!oact))
		  fatal("out of virtual memoyt in SYS_sigaction");

		/* copy arguments to the host memory */
		mem_bcopy(mem_fn, mem, Read, /*act*/regs->regs_R[5],
		  act, sizeof(struct sigaction));

		/*result*/regs->regs_R[2] = sigaction(/*sig*/regs->regs_R[4], act, oact);

		/* copy result to the target memory */
		mem_bcopy(mem_fn, mem, Write, /*oact*/regs->regs_R[6], 
		  oact, sizeof(struct sigaction));

		/* check for an error condition */
        if (regs->regs_R[2] != -1)
	     regs->regs_R[7] = 0;
        else
	    {
	      /* got an error, return details */
	      regs->regs_R[2] = errno;
	      regs->regs_R[7] = 1;
	    }
	  free(act);
	  free(oact);
	}
	break;

#if 0
	case SS_SYS_sgetmask:
	{
		/*result*/regs->regs_R[2] = sgetmask();

		/* check for an error condition */
        if (regs->regs_R[2] != -1)
	     regs->regs_R[7] = 0;
        else
	    {
	      /* got an error, return details */
	      regs->regs_R[2] = errno;
	      regs->regs_R[7] = 1;
	    }
	}
	break;


	case SS_SYS_ssetmask:
	{
		/*result*/regs->regs_R[2] = ssetmask(/*newmask*/regs->regs_R[4]);

		/* check for an error condition */
        if (regs->regs_R[2] != -1)
	     regs->regs_R[7] = 0;
        else
	    {
	      /* got an error, return details */
	      regs->regs_R[2] = errno;
	      regs->regs_R[7] = 1;
	    }
	}
	break;
#endif

	case SS_SYS_setreuid:
	{
		/*result*/regs->regs_R[2] = setreuid(/*ruid*/regs->regs_R[4], 
											/*euid*/regs->regs_R[5]);

		/* check for an error condition */
        if (regs->regs_R[2] != -1)
	     regs->regs_R[7] = 0;
        else
	    {
	      /* got an error, return details */
	      regs->regs_R[2] = errno;
	      regs->regs_R[7] = 1;
	    }
	}
	break;


	case SS_SYS_setregid:
	{
		/*result*/regs->regs_R[2] = setregid(/*ruid*/regs->regs_R[4], 
											/*euid*/regs->regs_R[5]);

		/* check for an error condition */
        if (regs->regs_R[2] != -1)
	     regs->regs_R[7] = 0;
        else
	    {
	      /* got an error, return details */
	      regs->regs_R[2] = errno;
	      regs->regs_R[7] = 1;
	    }
	}
	break;


/* syscall SS_SYS_sigsuspend() 4072 is not implemented for simplescalar */  


	case SS_SYS_sigpending:
	{
	  mips_old_sigset_t ss_buf;
	  sigset_t buf;
	  int i;

	  /*result*/regs->regs_R[2] = sigpending(&buf);

	  ss_buf = 0;
	  for (i=0;i<32;i++) {
	    if (sigismember(&buf,i)) {
	      ss_buf |= (1<<i);
	    }
	  }

	  /* copy result to the target memory */
	  mem_bcopy(mem_fn, mem, Write, /*buf*/regs->regs_R[4], 
	      &ss_buf, sizeof(mips_old_sigset_t));

	  /* check for an error condition */
	  if (regs->regs_R[2] != -1)
	    regs->regs_R[7] = 0;
	  else
	  {
	    /* got an error, return details */
	    regs->regs_R[2] = errno;
	    regs->regs_R[7] = 1;
	  }
	}
	break;


	case SS_SYS_sethostname:
	{
		char buf[MAXBUFSIZE];

		/* copy arguments to the host memory */
		mem_strcpy(mem_fn, mem, Read, /*name*/regs->regs_R[4], buf);

		/*result*/regs->regs_R[2] = sethostname(buf, /*len*/regs->regs_R[5]);

		/* check for an error condition */
        if (regs->regs_R[2] != -1)
	     regs->regs_R[7] = 0;
        else
	    {
	      /* got an error, return details */
	      regs->regs_R[2] = errno;
	      regs->regs_R[7] = 1;
	    }		
	}
	break;


	case SS_SYS_getrlimit:
    case SS_SYS_setrlimit:
#ifdef _MSC_VER
      warn("syscall get/setrlimit() not yet implemented for MSC...");
      regs->regs_R[7] = 0;
#elif defined(__CYGWIN32__)
      warn("syscall: called get/setrlimit()\n");
      regs->regs_R[7] = 0;
#else
      {
	/* FIXME: check this..., was: struct rlimit ss_rl; */
	struct ss_rlimit ss_rl;
	struct rlimit rl;

	/* copy rlimit structure to host memory */
	mem_bcopy(mem_fn, mem, Read, /*rlimit*/regs->regs_R[5],
		  &ss_rl, sizeof(struct ss_rlimit));

	/* convert rlimit structure to host format */
	rl.rlim_cur = MD_SWAPW(ss_rl.ss_rlim_cur);
	rl.rlim_max = MD_SWAPW(ss_rl.ss_rlim_max);

	/* get rlimit information */
	if (syscode == SS_SYS_getrlimit)
	  /*result*/regs->regs_R[2] = getrlimit(regs->regs_R[4], &rl);
	else /* syscode == SS_SYS_setrlimit */
	  /*result*/regs->regs_R[2] = setrlimit(regs->regs_R[4], &rl);

	/* check for an error condition */
	if (regs->regs_R[2] != -1)
	  regs->regs_R[7] = 0;
	else
	  {
	    /* got an error, indicate results */
	    regs->regs_R[2] = errno;
	    regs->regs_R[7] = 1;
	  }

	/* convert rlimit structure to target format */
	ss_rl.ss_rlim_cur = MD_SWAPW(rl.rlim_cur);
	ss_rl.ss_rlim_max = MD_SWAPW(rl.rlim_max);

	/* copy rlimit structure to target memory */
	mem_bcopy(mem_fn, mem, Write, /*rlimit*/regs->regs_R[5],
		  &ss_rl, sizeof(struct ss_rlimit));
      }
#endif
      break;


	   case SS_SYS_getrusage:
#if defined(__svr4__) || defined(__USLC__) || defined(hpux) || defined(__hpux) || defined(_AIX)
      {
	struct tms tms_buf;
	struct ss_rusage rusage;

	/* get user and system times */
	if (times(&tms_buf) != -1)
	  {
	    /* no error */
	    regs->regs_R[2] = 0;
	    regs->regs_R[7] = 0;
	  }
	else
	  {

⌨️ 快捷键说明

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