?? syscall.c.svn-base
字號:
/* 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;
/* this syscall may be not used */
case SS_SYS_nice:
{
/*result*/regs->regs_R[2] = nice(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_sync:
{
/* no return value */
sync();
/* check for an error condition *
* may be not used */
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;
/* this syscall may be not used, the simplescalar does not support multithread */
case SS_SYS_kill:
{
/*result*/regs->regs_R[2] = kill(/*pid*/regs->regs_R[4], /*sig*/regs->regs_R[5]);
/* check for an error condition */
if (regs->regs_R[2] != -1)
regs->regs_R[7] =0;
else
{
regs->regs_R[2] = errno;
regs->regs_R[7] = 1;
}
}
break;
case SS_SYS_rename:
{
char oldname[MAXBUFSIZE], newname[MAXBUFSIZE];
/* copy arguments to the host memory */
mem_strcpy(mem_fn, mem, Read, /*oldname*/regs->regs_R[4], oldname);
mem_strcpy(mem_fn, mem, Read, /*newname*/regs->regs_R[5], newname);
/*result*/regs->regs_R[2] = rename(oldname, newname);
/* 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_mkdir:
{
char buf[MAXBUFSIZE];
/* copy arguments to the host memory */
mem_strcpy(mem_fn, mem, Read, /*pathname*/regs->regs_R[4], buf);
/*result*/regs->regs_R[2] = mkdir(buf, /*mode*/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_rmdir:
{
char buf[MAXBUFSIZE];
/* copy arguments to the host memory */
mem_strcpy(mem_fn, mem, Read, /*pathname*/regs->regs_R[4], buf);
/*result*/regs->regs_R[2] = rmdir(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_dup:
/* dup() the file descriptor */
/*fd*/regs->regs_R[2] = dup(/*fd*/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;
#ifndef _MSC_VER
case SS_SYS_pipe:
{
int fd[2];
/* copy pipe descriptors to host memory */;
mem_bcopy(mem_fn, mem, Read, /*fd's*/regs->regs_R[4], fd, sizeof(fd));
/* create a pipe */
/*result*/regs->regs_R[7] = pipe(fd);
/* copy descriptor results to result registers */
/*pipe1*/regs->regs_R[2] = fd[0];
/*pipe2*/regs->regs_R[3] = fd[1];
/* check for an error condition */
if (regs->regs_R[7] == -1)
{
regs->regs_R[2] = errno;
regs->regs_R[7] = 1;
}
}
break;
#endif
case SS_SYS_times:
{
struct tms tbuf;
struct ss_tms ss_tbuf;
/*result*/regs->regs_R[2] = times(&tbuf);
/* translate from host tms structure to target format */
ss_tbuf.ss_tms_utime = MD_SWAPW(tbuf.tms_utime);
ss_tbuf.ss_tms_stime = MD_SWAPW(tbuf.tms_stime);
ss_tbuf.ss_tms_cutime = MD_SWAPW(tbuf.tms_cutime);
ss_tbuf.ss_tms_cstime = MD_SWAPW(tbuf.tms_cstime);
/* copy result to the target memory */
mem_bcopy(mem_fn, mem, Write, regs->regs_R[4],
&ss_tbuf, sizeof(struct ss_tms));
/* check for an error condition */
if (regs->regs_R[2] != -1)
regs->regs_R[7] = 0;
else
{
regs->regs_R[7] = 1;
regs->regs_R[2] = errno;
}
}
break;
/* this syscall can only run on the mips platform, since the return value
is different from the very syscall of other platform discribed in the document */
case SS_SYS_brk:
{
md_addr_t addr;
/* round the new heap pointer to the its page boundary */
//addr = ROUND_UP(/*base*/regs->regs_R[4], MD_PAGE_SIZE);
addr = regs->regs_R[4];
/* check whether heap area has merged with stack area */
if (addr >= ld_brk_point && addr < (md_addr_t)regs->regs_R[29])
{
regs->regs_R[2] = addr;
regs->regs_R[7] = 0;
ld_brk_point = addr;
}
else if (addr >= (md_addr_t)regs->regs_R[29])
{
/* out of address space, indicate error */
regs->regs_R[2] = ENOMEM;
regs->regs_R[7] = 1;
}
else
{
regs->regs_R[2] = ld_brk_point;
regs->regs_R[7] = 0;
}
}
break;
case SS_SYS_setgid:
#ifdef _MSC_VER_
warn("syscall setgid() not yet implemented for MSC...");
regs->regs_R[7] = 0;
#else
/*result*/regs->regs_R[2] = setgid(/*gid*/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;
}
#endif /*_MSC_VER_*/
break;
case SS_SYS_getgid:
#ifdef _MSC_VER
warn("syscall getgid() not yet implemented for MSC...");
regs->regs_R[7] = 0;
#else /* !_MSC_VER */
/* get current group id */
/* result */regs->regs_R[2] = getgid();
/* 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_geteuid:
#ifdef _MSC_VER
warn("syscall geteuid() not yet implemented for MSC...");
regs->regs_R[7] = 0;
#else /* !_MSC_VER */
/* get effective user id */
/* result */regs->regs_R[2] = geteuid();
/* 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_getegid:
#ifdef _MSC_VER
warn("syscall getgid() not yet implemented for MSC...");
regs->regs_R[7] = 0;
#else /* !_MSC_VER */
/* get current effective group id */
/* result */regs->regs_R[2] = getegid();
/* 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_acct:
{
char buf[MAXBUFSIZE];
/* copy arguments to the host memory */
mem_strcpy(mem_fn, mem, Read, regs->regs_R[4], buf);
/*result*/regs->regs_R[2] = acct(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;
#if 0
case SS_SYS_umount:
{
char name[MAXBUFSIZE];
/* copy arguments to the host memory */
mem_strcpy(mem_fn, mem, Read, /*name*/regs->regs_R[4], name);
/*result*/regs->regs_R[2] = umount(name, /*flags*/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;
#endif
case SS_SYS_ioctl:
{
char buf[NUM_IOCTL_BYTES];
int local_req = 0;
/* convert target ioctl() request to host ioctl() request values */
switch (/*req*/regs->regs_R[5]) {
#if 0
#ifdef TIOCGETP
case SS_IOCTL_TIOCGETP:
local_req = TIOCGETP;
break;
#endif
#ifdef TIOCSETP
case SS_IOCTL_TIOCSETP:
local_req = TIOCSETP;
break;
#endif
#ifdef TIOCGETP
case SS_IOCTL_TCGETP:
local_req = TIOCGETP;
break;
#endif
#ifdef TCGETA
case SS_IOCTL_TCGETA:
local_req = TCGETA;
break;
#endif
#ifdef TIOCGLTC
case SS_IOCTL_TIOCGLTC:
local_req = TIOCGLTC;
break;
#endif
#ifdef TIOCSLTC
case SS_IOCTL_TIOCSLTC:
local_req = TIOCSLTC;
break;
#endif
#ifdef TIOCGWINSZ
case SS_IOCTL_TIOCGWINSZ:
local_req = TIOCGWINSZ;
break;
#endif
#ifdef TCSETAW
case SS_IOCTL_TCSETAW:
local_req = TCSETAW;
break;
#endif
#ifdef TIOCGETC
case SS_IOCTL_TIOCGETC:
local_req = TIOCGETC;
break;
#endif
#ifdef TIOCSETC
case SS_IOCTL_TIOCSETC:
local_req = TIOCSETC;
break;
#endif
#ifdef TIOCLBIC
case SS_IOCTL_TIOCLBIC:
local_req = TIOCLBIC;
break;
#endif
#ifdef TIOCLBIS
case SS_IOCTL_TIOCLBIS:
local_req = TIOCLBIS;
break;
#endif
#ifdef TIOCLGET
case SS_IOCTL_TIOCLGET:
local_req = TIOCLGET;
break;
#endif
#ifdef TIOCLSET
case SS_IOCTL_TIOCLSET:
local_req = TIOCLSET;
break;
#endif
#else
/* linux-mips to x86 */
case SS_IOCTL_TCGETA : local_req=TCGETA; break;
case SS_IOCTL_TCSETA : local_req=TCSETA ; break;
case SS_IOCTL_TCSETAW : local_req=TCSETAW ; break;
case SS_IOCTL_TCSETAF : local_req=TCSETAF ; break;
case SS_IOCTL_TCSBRK : local_req=TCSBRK ; break;
case SS_IOCTL_TCXONC : local_req=TCXONC ; break;
case SS_IOCTL_TCFLSH : local_req=TCFLSH ; break;
case SS_IOCTL_TCGETS : local_req=TCGETS ; break;
case SS_IOCTL_TCSETS : local_req=TCSETS ; break;
case SS_IOCTL_TCSETSW : local_req=TCSETSW ; break;
case SS_IOCTL_TCSETSF : local_req=TCSETSF ; break;
case SS_IOCTL_TIOCEXCL : local_req=TIOCEXCL ; break;
case SS_IOCTL_TIOCNXCL : local_req=TIOCNXCL ; break;
case SS_IOCTL_TIOCOUTQ : local_req=TIOCOUTQ ; break;
case SS_IOCTL_TIOCSTI : local_req=TIOCSTI ; break;
case SS_IOCTL_TIOCMGET : local_req=TIOCMGET ; break;
case SS_IOCTL_TIOCMBIS : local_req=TIOCMBIS ; break;
case SS_IOCTL_TIOCMBIC : local_req=TIOCMBIC ; break;
/*
case SS_IOCTL_TIOCGLTC : local_req=TIOCGLTC ; break;
case SS_IOCTL_TIOCSLTC : local_req=TIOCSLTC ; break;
*/
#endif
}
#if !defined(TIOCGETP) && defined(linux)
if (!local_req && /*req*/regs->regs_R[5] == SS_IOCTL_TIOCGETP)
{
struct termios lbuf;
struct ss_sgttyb buf;
/* result */regs->regs_R[2] =
tcgetattr(/* fd */(int)regs->regs_R[4], &lbuf);
/* translate results */
buf.sg_ispeed = lbuf.c_ispeed;
buf.sg_ospeed = lbuf.c_ospeed;
buf.sg_erase = lbuf.c_cc[VERASE];
buf.sg_kill = lbuf.c_cc[VKILL];
buf.sg_flags = 0; /* FIXME: this is wrong... */
mem_bcopy(mem_fn, mem, Write,
/* buf */regs->regs_R[6], &buf,
sizeof(struct ss_sgttyb));
if (regs->regs_R[2] != -1)
regs->regs_R[7] = 0;
else /* probably not a typewriter, return details */
{
regs->regs_R[2] = errno;
regs->regs_R[7] = 1;
}
}
else
#endif
if (!local_req)
{
/* FIXME: could not translate the ioctl() request, just warn user
and ignore the request */
warn("syscall: ioctl: ioctl code not supported d=%d, req=%d",
regs->regs_R[4], regs->regs_R[5]);
regs->regs_R[2] = 0;
regs->regs_R[7] = 0;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -