"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

syscall.h File Reference

#include <sys/types.h>
#include <sys/time.h>
#include "host.h"
#include "misc.h"
#include "machine.h"

Include dependency graph for syscall.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Functions


Function Documentation

void sys_syscall struct regs_t   regs,
mem_access_fn    mem_fn,
struct mem_t   mem,
md_inst_t    inst,
int    traceable
 

Definition at line 975 of file target-alpha/syscall.c.

References eio_read_trace(), fatal(), MAXBUFSIZE, MD_OUTPUT_SYSCALL, MD_SWAPH, MD_SWAPW, mem_access_fn, mem_bcopy(), mem_strcpy(), NUM_IOCTL_BYTES, panic(), Read, regs_t::regs_R, ROUND_UP, ss_sgttyb::sg_erase, ss_sgttyb::sg_flags, ss_sgttyb::sg_ispeed, ss_sgttyb::sg_kill, ss_sgttyb::sg_ospeed, ss_flag_table, SS_IOCTL_TCGETA, SS_IOCTL_TCGETP, SS_IOCTL_TCSETAW, SS_IOCTL_TIOCGETC, SS_IOCTL_TIOCGETP, SS_IOCTL_TIOCGLTC, SS_IOCTL_TIOCGWINSZ, SS_IOCTL_TIOCLBIC, SS_IOCTL_TIOCLBIS, SS_IOCTL_TIOCLGET, SS_IOCTL_TIOCLSET, SS_IOCTL_TIOCSETC, SS_IOCTL_TIOCSETP, SS_IOCTL_TIOCSLTC, SS_NFLAGS, ss_statbuf::ss_pad, ss_statbuf::ss_pad1, ss_rlimit::ss_rlim_cur, ss_rlimit::ss_rlim_max, ss_rusage::ss_ru_idrss, ss_rusage::ss_ru_inblock, ss_rusage::ss_ru_isrss, ss_rusage::ss_ru_ixrss, ss_rusage::ss_ru_majflt, ss_rusage::ss_ru_maxrss, ss_rusage::ss_ru_minflt, ss_rusage::ss_ru_msgrcv, ss_rusage::ss_ru_msgsnd, ss_rusage::ss_ru_nivcsw, ss_rusage::ss_ru_nsignals, ss_rusage::ss_ru_nswap, ss_rusage::ss_ru_nvcsw, ss_rusage::ss_ru_oublock, ss_rusage::ss_ru_stime, ss_rusage::ss_ru_utime, ss_statbuf::ss_st_atime, ss_statbuf::ss_st_blksize, ss_statbuf::ss_st_blocks, ss_statbuf::ss_st_ctime, ss_statbuf::ss_st_dev, ss_statbuf::ss_st_gennum, ss_statbuf::ss_st_gid, ss_statbuf::ss_st_ino, ss_statbuf::ss_st_mode, ss_statbuf::ss_st_mtime, ss_statbuf::ss_st_nlink, ss_statbuf::ss_st_rdev, ss_statbuf::ss_st_size, ss_statbuf::ss_st_spare1, ss_statbuf::ss_st_spare2, ss_statbuf::ss_st_spare3, ss_statbuf::ss_st_spare4, ss_statbuf::ss_st_uid, SS_SYS_access, SS_SYS_brk, SS_SYS_chdir, SS_SYS_chmod, SS_SYS_chown, SS_SYS_close, SS_SYS_creat, SS_SYS_dup, SS_SYS_dup2, SS_SYS_exit, SS_SYS_fcntl, SS_SYS_fork, SS_SYS_fstat, SS_SYS_getdirentries, SS_SYS_getdtablesize, SS_SYS_getgid, SS_SYS_getpagesize, SS_SYS_getpid, SS_SYS_getrlimit, SS_SYS_getrusage, SS_SYS_gettimeofday, SS_SYS_getuid, SS_SYS_ioctl, SS_SYS_lseek, SS_SYS_lstat, SS_SYS_open, SS_SYS_pipe, SS_SYS_read, SS_SYS_select, SS_SYS_setitimer, SS_SYS_setrlimit, SS_SYS_sigblock, SS_SYS_sigsetmask, SS_SYS_sigstack, SS_SYS_sigvec, SS_SYS_stat, SS_SYS_unlink, SS_SYS_utimes, SS_SYS_vfork, SS_SYS_write, SS_SYS_writev, ss_timeval::ss_tv_sec, ss_timeval::ss_tv_usec, ss_timezone::ss_tz_dsttime, ss_timezone::ss_tz_minuteswest, warn(), word_t, and Write.

Referenced by eio_read_trace(), and eio_write_trace().

00980 {
00981   qword_t syscode = regs->regs_R[MD_REG_V0];
00982 
00983   /* fix for syscall() which uses CALL_PAL CALLSYS for making system calls */
00984   if (syscode == OSF_SYS_syscall)
00985     syscode = regs->regs_R[MD_REG_A0];
00986 
00987   /* first, check if an EIO trace is being consumed... */
00988   if (traceable && sim_eio_fd != NULL)
00989     {
00990       eio_read_trace(sim_eio_fd, sim_num_insn, regs, mem_fn, mem, inst);
00991 
00992       /* kludge fix for sigreturn(), it modifies all registers */
00993       if (syscode == OSF_SYS_sigreturn)
00994         {
00995           int i;
00996           struct osf_sigcontext sc;
00997           md_addr_t sc_addr = regs->regs_R[MD_REG_A0];
00998 
00999           mem_bcopy(mem_fn, mem, Read, sc_addr, 
01000                     &sc, sizeof(struct osf_sigcontext));
01001           regs->regs_NPC = sc.sc_pc;
01002           for (i=0; i < 32; ++i)
01003             regs->regs_R[i] = sc.sc_regs[i];
01004           for (i=0; i < 32; ++i)
01005             regs->regs_F.q[i] = sc.sc_fpregs[i];
01006           regs->regs_C.fpcr = sc.sc_fpcr;
01007         }
01008 
01009       /* fini... */
01010       return;
01011     }
01012 
01013   /* no, OK execute the live system call... */
01014   switch (syscode)
01015     {
01016     case OSF_SYS_exit:
01017       /* exit jumps to the target set in main() */
01018       longjmp(sim_exit_buf,
01019               /* exitcode + fudge */(regs->regs_R[MD_REG_A0] & 0xff) + 1);
01020       break;
01021 
01022     case OSF_SYS_read:
01023       {
01024         char *buf;
01025 
01026         /* allocate same-sized input buffer in host memory */
01027         if (!(buf =
01028               (char *)calloc(/*nbytes*/regs->regs_R[MD_REG_A2], sizeof(char))))
01029           fatal("out of memory in SYS_read");
01030 
01031         /* read data from file */
01032         do {
01033           /*nread*/regs->regs_R[MD_REG_V0] =
01034             read(/*fd*/regs->regs_R[MD_REG_A0], buf,
01035                  /*nbytes*/regs->regs_R[MD_REG_A2]);
01036         } while (/*nread*/regs->regs_R[MD_REG_V0] == -1
01037                  && errno == EAGAIN);
01038 
01039         /* check for error condition */
01040         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01041           regs->regs_R[MD_REG_A3] = 0;
01042         else /* got an error, return details */
01043           {
01044             regs->regs_R[MD_REG_A3] = -1;
01045             regs->regs_R[MD_REG_V0] = errno;
01046           }
01047 
01048         /* copy results back into host memory */
01049         mem_bcopy(mem_fn, mem, Write,
01050                   /*buf*/regs->regs_R[MD_REG_A1], buf, /*nread*/regs->regs_R[MD_REG_A2]);
01051 
01052         /* done with input buffer */
01053         free(buf);
01054       }
01055       break;
01056 
01057     case OSF_SYS_write:
01058       {
01059         char *buf;
01060 
01061         /* allocate same-sized output buffer in host memory */
01062         if (!(buf =
01063               (char *)calloc(/*nbytes*/regs->regs_R[MD_REG_A2], sizeof(char))))
01064           fatal("out of memory in SYS_write");
01065 
01066         /* copy inputs into host memory */
01067         mem_bcopy(mem_fn, mem, Read, /*buf*/regs->regs_R[MD_REG_A1], buf,
01068                   /*nbytes*/regs->regs_R[MD_REG_A2]);
01069 
01070         /* write data to file */
01071         if (sim_progfd && MD_OUTPUT_SYSCALL(regs))
01072           {
01073             /* redirect program output to file */
01074 
01075             /*nwritten*/regs->regs_R[MD_REG_V0] =
01076               fwrite(buf, 1, /*nbytes*/regs->regs_R[MD_REG_A2], sim_progfd);
01077           }
01078         else
01079           {
01080             /* perform program output request */
01081 
01082             do {
01083               /*nwritten*/regs->regs_R[MD_REG_V0] =
01084                 write(/*fd*/regs->regs_R[MD_REG_A0],
01085                       buf, /*nbytes*/regs->regs_R[MD_REG_A2]);
01086             } while (/*nwritten*/regs->regs_R[MD_REG_V0] == -1
01087                      && errno == EAGAIN);
01088           }
01089 
01090         /* check for an error condition */
01091         if (regs->regs_R[MD_REG_V0] == regs->regs_R[MD_REG_A2])
01092           regs->regs_R[MD_REG_A3] = 0;
01093         else /* got an error, return details */
01094           {
01095             regs->regs_R[MD_REG_A3] = -1;
01096             regs->regs_R[MD_REG_V0] = errno;
01097           }
01098 
01099         /* done with output buffer */
01100         free(buf);
01101       }
01102       break;
01103 
01104 #if !defined(MIN_SYSCALL_MODE)
01105       /* ADDED BY CALDER 10/27/99 */
01106     case OSF_SYS_getdomainname:
01107       /* get program scheduling priority */
01108       {
01109         char *buf;
01110 
01111         buf = malloc(/* len */(size_t)regs->regs_R[MD_REG_A1]);
01112         if (!buf)
01113           fatal("out of virtual memory in gethostname()");
01114 
01115         /* result */regs->regs_R[MD_REG_V0] =
01116           getdomainname(/* name */buf,
01117                       /* len */(size_t)regs->regs_R[MD_REG_A1]);
01118 
01119         /* check for an error condition */
01120         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01121           regs->regs_R[MD_REG_A3] = 0;
01122         else /* got an error, return details */
01123           {
01124             regs->regs_R[MD_REG_A3] = -1;
01125             regs->regs_R[MD_REG_V0] = errno;
01126           }
01127 
01128         /* copy string back to simulated memory */
01129         mem_bcopy(mem_fn, mem, Write,
01130                   /* name */regs->regs_R[MD_REG_A0],
01131                   buf, /* len */regs->regs_R[MD_REG_A1]);
01132       }
01133       break;
01134 #endif
01135 
01136 #if !defined(MIN_SYSCALL_MODE)
01137       /* ADDED BY CALDER 10/27/99 */
01138     case OSF_SYS_flock:
01139       /* get flock() information on the file */
01140       {
01141         regs->regs_R[MD_REG_V0] =
01142           flock(/*fd*/(int)regs->regs_R[MD_REG_A0],
01143                 /*cmd*/(int)regs->regs_R[MD_REG_A1]);
01144 
01145         /* check for an error condition */
01146         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01147           regs->regs_R[MD_REG_A3] = 0;
01148         else /* got an error, return details */
01149           {
01150             regs->regs_R[MD_REG_A3] = -1;
01151             regs->regs_R[MD_REG_V0] = errno;
01152           }
01153       }
01154       break;
01155 #endif
01156 
01157 #if !defined(MIN_SYSCALL_MODE)
01158       /* ADDED BY CALDER 10/27/99 */
01159     case OSF_SYS_bind:
01160       {
01161         const struct sockaddr a_sock;
01162 
01163         mem_bcopy(mem_fn, mem, Read, /* serv_addr */regs->regs_R[MD_REG_A1],
01164                   &a_sock, /* addrlen */(int)regs->regs_R[MD_REG_A2]);
01165 
01166       regs->regs_R[MD_REG_V0] =
01167         bind((int) regs->regs_R[MD_REG_A0],
01168              &a_sock,(int) regs->regs_R[MD_REG_A2]);
01169 
01170       /* check for an error condition */
01171       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01172         regs->regs_R[MD_REG_A3] = 0;
01173       else /* got an error, return details */
01174         {
01175           regs->regs_R[MD_REG_A3] = -1;
01176           regs->regs_R[MD_REG_V0] = errno;
01177         }
01178       }
01179       break;
01180 #endif
01181 
01182 #if !defined(MIN_SYSCALL_MODE)
01183       /* ADDED BY CALDER 10/27/99 */
01184     case OSF_SYS_sendto:
01185       {
01186         char *buf = NULL;
01187         struct sockaddr d_sock;
01188         int buf_len = 0;
01189 
01190         buf_len = regs->regs_R[MD_REG_A2];
01191 
01192         if (buf_len > 0)
01193           buf = (char *) malloc(buf_len*sizeof(char));
01194 
01195         mem_bcopy(mem_fn, mem, Read, /* serv_addr */regs->regs_R[MD_REG_A1],
01196                   buf, /* addrlen */(int)regs->regs_R[MD_REG_A2]);
01197 
01198         if (regs->regs_R[MD_REG_A5] > 0) 
01199           mem_bcopy(mem_fn, mem, Read, regs->regs_R[MD_REG_A4],
01200                     &d_sock, (int)regs->regs_R[MD_REG_A5]);
01201 
01202         regs->regs_R[MD_REG_V0] =
01203           sendto((int) regs->regs_R[MD_REG_A0],
01204                  buf,(int) regs->regs_R[MD_REG_A2],
01205                  (int) regs->regs_R[MD_REG_A3],
01206                  &d_sock,(int) regs->regs_R[MD_REG_A5]);
01207 
01208         mem_bcopy(mem_fn, mem, Write, /* serv_addr */regs->regs_R[MD_REG_A1],
01209                   buf, /* addrlen */(int)regs->regs_R[MD_REG_A2]);
01210 
01211         /* maybe copy back whole size of sockaddr */
01212         if (regs->regs_R[MD_REG_A5] > 0)
01213           mem_bcopy(mem_fn, mem, Write, regs->regs_R[MD_REG_A4],
01214                     &d_sock, (int)regs->regs_R[MD_REG_A5]);
01215 
01216         /* check for an error condition */
01217         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01218           regs->regs_R[MD_REG_A3] = 0;
01219         else /* got an error, return details */
01220           {
01221             regs->regs_R[MD_REG_A3] = -1;
01222             regs->regs_R[MD_REG_V0] = errno;
01223           }
01224 
01225         if (buf != NULL) 
01226           free(buf);
01227       }
01228       break;
01229 #endif
01230 
01231 #if !defined(MIN_SYSCALL_MODE)
01232       /* ADDED BY CALDER 10/27/99 */
01233     case OSF_SYS_old_recvfrom:
01234     case OSF_SYS_recvfrom:
01235       {
01236         int addr_len;
01237         char *buf;
01238         struct sockaddr *a_sock;
01239       
01240         buf = (char *) malloc(sizeof(char)*regs->regs_R[MD_REG_A2]);
01241 
01242         mem_bcopy(mem_fn, mem, Read, /* serv_addr */regs->regs_R[MD_REG_A1],
01243                   buf, /* addrlen */(int)regs->regs_R[MD_REG_A2]);
01244 
01245         mem_bcopy(mem_fn, mem, Read, /* serv_addr */regs->regs_R[MD_REG_A5],
01246                   &addr_len, sizeof(int));
01247 
01248         a_sock = (struct sockaddr *)malloc(addr_len);
01249 
01250         mem_bcopy(mem_fn, mem, Read, regs->regs_R[MD_REG_A4],
01251                   a_sock, addr_len);
01252 
01253         regs->regs_R[MD_REG_V0] =
01254           recvfrom((int) regs->regs_R[MD_REG_A0],
01255                    buf,(int) regs->regs_R[MD_REG_A2],
01256                    (int) regs->regs_R[MD_REG_A3], a_sock,&addr_len);
01257 
01258         mem_bcopy(mem_fn, mem, Write, regs->regs_R[MD_REG_A1],
01259                   buf, (int) regs->regs_R[MD_REG_V0]);
01260 
01261         mem_bcopy(mem_fn, mem, Write, /* serv_addr */regs->regs_R[MD_REG_A5],
01262                   &addr_len, sizeof(int));
01263 
01264         mem_bcopy(mem_fn, mem, Write, regs->regs_R[MD_REG_A4],
01265                   a_sock, addr_len);
01266 
01267         /* check for an error condition */
01268         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01269           regs->regs_R[MD_REG_A3] = 0;
01270         else /* got an error, return details */
01271           {
01272             regs->regs_R[MD_REG_A3] = -1;
01273             regs->regs_R[MD_REG_V0] = errno;
01274           }
01275         if (buf != NULL)
01276           free(buf);
01277       }
01278       break;
01279 #endif
01280 
01281     case OSF_SYS_open:
01282       {
01283         char buf[MAXBUFSIZE];
01284         unsigned int i;
01285         int osf_flags = regs->regs_R[MD_REG_A1], local_flags = 0;
01286 
01287         /* translate open(2) flags */
01288         for (i=0; i < OSF_NFLAGS; i++)
01289           {
01290             if (osf_flags & osf_flag_table[i].osf_flag)
01291               {
01292                 osf_flags &= ~osf_flag_table[i].osf_flag;
01293                 local_flags |= osf_flag_table[i].local_flag;
01294               }
01295           }
01296         /* any target flags left? */
01297         if (osf_flags != 0)
01298           fatal("syscall: open: cannot decode flags: 0x%08x", osf_flags);
01299 
01300         /* copy filename to host memory */
01301         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[MD_REG_A0], buf);
01302 
01303         /* open the file */
01304 #ifdef __CYGWIN32__
01305         /*fd*/regs->regs_R[MD_REG_V0] =
01306           open(buf, local_flags|O_BINARY, /*mode*/regs->regs_R[MD_REG_A2]);
01307 #else /* !__CYGWIN32__ */
01308         /*fd*/regs->regs_R[MD_REG_V0] =
01309           open(buf, local_flags, /*mode*/regs->regs_R[MD_REG_A2]);
01310 #endif /* __CYGWIN32__ */
01311         
01312         /* check for an error condition */
01313         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01314           regs->regs_R[MD_REG_A3] = 0;
01315         else /* got an error, return details */
01316           {
01317             regs->regs_R[MD_REG_A3] = -1;
01318             regs->regs_R[MD_REG_V0] = errno;
01319           }
01320       }
01321       break;
01322 
01323     case OSF_SYS_close:
01324       /* don't close stdin, stdout, or stderr as this messes up sim logs */
01325       if (/*fd*/regs->regs_R[MD_REG_A0] == 0
01326           || /*fd*/regs->regs_R[MD_REG_A0] == 1
01327           || /*fd*/regs->regs_R[MD_REG_A0] == 2)
01328         {
01329           regs->regs_R[MD_REG_A3] = 0;
01330           break;
01331         }
01332 
01333       /* close the file */
01334       regs->regs_R[MD_REG_V0] = close(/*fd*/regs->regs_R[MD_REG_A0]);
01335 
01336       /* check for an error condition */
01337       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01338         regs->regs_R[MD_REG_A3] = 0;
01339       else /* got an error, return details */
01340         {
01341           regs->regs_R[MD_REG_A3] = -1;
01342           regs->regs_R[MD_REG_V0] = errno;
01343         }
01344       break;
01345 
01346 #if 0
01347     case OSF_SYS_creat:
01348       {
01349         char buf[MAXBUFSIZE];
01350 
01351         /* copy filename to host memory */
01352         mem_strcpy(mem_fn, Read, /*fname*/regs->regs_R[MD_REG_A0], buf);
01353 
01354         /* create the file */
01355         /*fd*/regs->regs_R[MD_REG_V0] =
01356           creat(buf, /*mode*/regs->regs_R[MD_REG_A1]);
01357 
01358         /* check for an error condition */
01359         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01360           regs->regs_R[MD_REG_A3] = 0;
01361         else /* got an error, return details */
01362           {
01363             regs->regs_R[MD_REG_A3] = -1;
01364             regs->regs_R[MD_REG_V0] = errno;
01365           }
01366       }
01367       break;
01368 #endif
01369 
01370     case OSF_SYS_unlink:
01371       {
01372         char buf[MAXBUFSIZE];
01373 
01374         /* copy filename to host memory */
01375         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[MD_REG_A0], buf);
01376 
01377         /* delete the file */
01378         /*result*/regs->regs_R[MD_REG_V0] = unlink(buf);
01379 
01380         /* check for an error condition */
01381         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01382           regs->regs_R[MD_REG_A3] = 0;
01383         else /* got an error, return details */
01384           {
01385             regs->regs_R[MD_REG_A3] = -1;
01386             regs->regs_R[MD_REG_V0] = errno;
01387           }
01388       }
01389       break;
01390 
01391     case OSF_SYS_chdir:
01392       {
01393         char buf[MAXBUFSIZE];
01394 
01395         /* copy filename to host memory */
01396         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[MD_REG_A0], buf);
01397 
01398         /* change the working directory */
01399         /*result*/regs->regs_R[MD_REG_V0] = chdir(buf);
01400 
01401         /* check for an error condition */
01402         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01403           regs->regs_R[MD_REG_A3] = 0;
01404         else /* got an error, return details */
01405           {
01406             regs->regs_R[MD_REG_A3] = -1;
01407             regs->regs_R[MD_REG_V0] = errno;
01408           }
01409       }
01410       break;
01411 
01412     case OSF_SYS_chmod:
01413       {
01414         char buf[MAXBUFSIZE];
01415 
01416         /* copy filename to host memory */
01417         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[MD_REG_A0], buf);
01418 
01419         /* chmod the file */
01420         /*result*/regs->regs_R[MD_REG_V0] =
01421           chmod(buf, /*mode*/regs->regs_R[MD_REG_A1]);
01422 
01423         /* check for an error condition */
01424         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01425           regs->regs_R[MD_REG_A3] = 0;
01426         else /* got an error, return details */
01427           {
01428             regs->regs_R[MD_REG_A3] = -1;
01429             regs->regs_R[MD_REG_V0] = errno;
01430           }
01431       }
01432       break;
01433 
01434     case OSF_SYS_chown:
01435 #ifdef _MSC_VER
01436       warn("syscall chown() not yet implemented for MSC...");
01437       regs->regs_R[MD_REG_A3] = 0;
01438 #else /* !_MSC_VER */
01439       {
01440         char buf[MAXBUFSIZE];
01441 
01442         /* copy filename to host memory */
01443         mem_strcpy(mem_fn, mem,Read, /*fname*/regs->regs_R[MD_REG_A0], buf);
01444 
01445         /* chown the file */
01446         /*result*/regs->regs_R[MD_REG_V0] =
01447           chown(buf, /*owner*/regs->regs_R[MD_REG_A1],
01448                 /*group*/regs->regs_R[MD_REG_A2]);
01449 
01450         /* check for an error condition */
01451         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01452           regs->regs_R[MD_REG_A3] = 0;
01453         else /* got an error, return details */
01454           {
01455             regs->regs_R[MD_REG_A3] = -1;
01456             regs->regs_R[MD_REG_V0] = errno;
01457           }
01458       }
01459 #endif /* _MSC_VER */
01460       break;
01461 
01462     case OSF_SYS_sbrk:
01463       {
01464         sqword_t delta;
01465         md_addr_t addr;
01466 
01467         delta = regs->regs_R[MD_REG_A0];
01468         addr = ld_brk_point + delta;
01469 
01470         if (verbose)
01471           myfprintf(stderr, "SYS_sbrk: delta: 0x%012p (%ld)\n", delta, delta);
01472 
01473         ld_brk_point = addr;
01474         regs->regs_R[MD_REG_V0] = ld_brk_point;
01475         regs->regs_R[MD_REG_A3] = 0;
01476 
01477         if (verbose)
01478           myfprintf(stderr, "ld_brk_point: 0x%012p\n", ld_brk_point);
01479 
01480 #if 0
01481         /* check whether heap area has merged with stack area */
01482         if (/* addr >= ld_brk_point && */ addr < regs->regs_R[MD_REG_SP])
01483           {
01484             regs->regs_R[MD_REG_A3] = 0;
01485             ld_brk_point = addr;
01486           }
01487         else
01488           {
01489             /* out of address space, indicate error */
01490             regs->regs_R[MD_REG_A3] = -1;
01491           }
01492 #endif
01493       }
01494       break;
01495 
01496     case OSF_SYS_obreak:
01497       {
01498         md_addr_t addr;
01499 
01500         /* round the new heap pointer to the its page boundary */
01501 #if 0
01502         addr = ROUND_UP(/*base*/regs->regs_R[MD_REG_A0], MD_PAGE_SIZE);
01503 #endif
01504         addr = /*base*/regs->regs_R[MD_REG_A0];
01505 
01506         if (verbose)
01507           myfprintf(stderr, "SYS_obreak: addr: 0x%012p\n", addr);
01508 
01509         ld_brk_point = addr;
01510         regs->regs_R[MD_REG_V0] = ld_brk_point;
01511         regs->regs_R[MD_REG_A3] = 0;
01512 
01513         if (verbose)
01514           myfprintf(stderr, "ld_brk_point: 0x%012p\n", ld_brk_point);
01515       }
01516       break;
01517 
01518     case OSF_SYS_lseek:
01519       /* seek into file */
01520       regs->regs_R[MD_REG_V0] =
01521         lseek(/*fd*/regs->regs_R[MD_REG_A0],
01522               /*off*/regs->regs_R[MD_REG_A1], /*dir*/regs->regs_R[MD_REG_A2]);
01523 
01524       /* check for an error condition */
01525       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01526         regs->regs_R[MD_REG_A3] = 0;
01527       else /* got an error, return details */
01528         {
01529           regs->regs_R[MD_REG_A3] = -1;
01530           regs->regs_R[MD_REG_V0] = errno;
01531         }
01532       break;
01533 
01534     case OSF_SYS_getpid:
01535       /* get the simulator process id */
01536       /*result*/regs->regs_R[MD_REG_V0] = getpid();
01537 
01538       /* check for an error condition */
01539       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01540         regs->regs_R[MD_REG_A3] = 0;
01541       else /* got an error, return details */
01542         {
01543           regs->regs_R[MD_REG_A3] = -1;
01544           regs->regs_R[MD_REG_V0] = errno;
01545         }
01546       break;
01547 
01548     case OSF_SYS_getuid:
01549 #ifdef _MSC_VER
01550       warn("syscall getuid() not yet implemented for MSC...");
01551       regs->regs_R[MD_REG_A3] = 0;
01552 #else /* !_MSC_VER */
01553       /* get current user id */
01554       /*first result*/regs->regs_R[MD_REG_V0] = getuid();
01555       /*second result*/regs->regs_R[MD_REG_A4] = geteuid();
01556 
01557       /* check for an error condition */
01558       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01559         regs->regs_R[MD_REG_A3] = 0;
01560       else /* got an error, return details */
01561         {
01562           regs->regs_R[MD_REG_A3] = -1;
01563           regs->regs_R[MD_REG_V0] = errno;
01564         }
01565 #endif /* _MSC_VER */
01566       break;
01567 
01568     case OSF_SYS_access:
01569       {
01570         char buf[MAXBUFSIZE];
01571 
01572         /* copy filename to host memory */
01573         mem_strcpy(mem_fn, mem, Read, /*fName*/regs->regs_R[MD_REG_A0], buf);
01574 
01575         /* check access on the file */
01576         /*result*/regs->regs_R[MD_REG_V0] =
01577           access(buf, /*mode*/regs->regs_R[MD_REG_A1]);
01578 
01579         /* check for an error condition */
01580         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01581           regs->regs_R[MD_REG_A3] = 0;
01582         else /* got an error, return details */
01583           {
01584             regs->regs_R[MD_REG_A3] = -1;
01585             regs->regs_R[MD_REG_V0] = errno;
01586           }
01587       }
01588       break;
01589 
01590     case OSF_SYS_stat:
01591     case OSF_SYS_lstat:
01592       {
01593         char buf[MAXBUFSIZE];
01594         struct osf_statbuf osf_sbuf;
01595 #ifdef _MSC_VER
01596         struct _stat sbuf;
01597 #else /* !_MSC_VER */
01598         struct stat sbuf;
01599 #endif /* _MSC_VER */
01600 
01601         /* copy filename to host memory */
01602         mem_strcpy(mem_fn, mem, Read, /*fName*/regs->regs_R[MD_REG_A0], buf);
01603 
01604         /* stat() the file */
01605         if (syscode == OSF_SYS_stat)
01606           /*result*/regs->regs_R[MD_REG_V0] = stat(buf, &sbuf);
01607         else /* syscode == OSF_SYS_lstat */
01608           {
01609 #ifdef _MSC_VER
01610             warn("syscall lstat() not yet implemented for MSC...");
01611             regs->regs_R[MD_REG_A3] = 0;
01612             break;
01613 #else /* !_MSC_VER */
01614             /*result*/regs->regs_R[MD_REG_V0] = lstat(buf, &sbuf);
01615 #endif /* _MSC_VER */
01616           }
01617 
01618         /* check for an error condition */
01619         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01620           regs->regs_R[MD_REG_A3] = 0;
01621         else /* got an error, return details */
01622           {
01623             regs->regs_R[MD_REG_A3] = -1;
01624             regs->regs_R[MD_REG_V0] = errno;
01625           }
01626 
01627         /* translate from host stat structure to target format */
01628         osf_sbuf.osf_st_dev = MD_SWAPW(sbuf.st_dev);
01629         osf_sbuf.osf_st_ino = MD_SWAPW(sbuf.st_ino);
01630         osf_sbuf.osf_st_mode = MD_SWAPW(sbuf.st_mode);
01631         osf_sbuf.osf_st_nlink = MD_SWAPH(sbuf.st_nlink);
01632         osf_sbuf.osf_st_uid = MD_SWAPW(sbuf.st_uid);
01633         osf_sbuf.osf_st_gid = MD_SWAPW(sbuf.st_gid);
01634         osf_sbuf.osf_st_rdev = MD_SWAPW(sbuf.st_rdev);
01635         osf_sbuf.osf_st_size = MD_SWAPQ(sbuf.st_size);
01636         osf_sbuf.osf_st_atime = MD_SWAPW(sbuf.st_atime);
01637         osf_sbuf.osf_st_mtime = MD_SWAPW(sbuf.st_mtime);
01638         osf_sbuf.osf_st_ctime = MD_SWAPW(sbuf.st_ctime);
01639 #ifndef _MSC_VER
01640         osf_sbuf.osf_st_blksize = MD_SWAPW(sbuf.st_blksize);
01641         osf_sbuf.osf_st_blocks = MD_SWAPW(sbuf.st_blocks);
01642 #endif /* !_MSC_VER */
01643 
01644         /* copy stat() results to simulator memory */
01645         mem_bcopy(mem_fn, mem, Write, /*sbuf*/regs->regs_R[MD_REG_A1],
01646                   &osf_sbuf, sizeof(struct osf_statbuf));
01647       }
01648       break;
01649 
01650     case OSF_SYS_dup:
01651       /* dup() the file descriptor */
01652       /*fd*/regs->regs_R[MD_REG_V0] = dup(/*fd*/regs->regs_R[MD_REG_A0]);
01653 
01654       /* check for an error condition */
01655       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01656         regs->regs_R[MD_REG_A3] = 0;
01657       else /* got an error, return details */
01658         {
01659           regs->regs_R[MD_REG_A3] = -1;
01660           regs->regs_R[MD_REG_V0] = errno;
01661         }
01662       break;
01663 
01664 #if 0
01665     case OSF_SYS_pipe:
01666       {
01667         int fd[2];
01668 
01669         /* copy pipe descriptors to host memory */;
01670         mem_bcopy(mem_fn, mem, Read, /*fd's*/regs->regs_R[MD_REG_A0],
01671                   fd, sizeof(fd));
01672 
01673         /* create a pipe */
01674         /*result*/regs->regs_R[7] = pipe(fd);
01675 
01676         /* copy descriptor results to result registers */
01677         /*pipe1*/regs->regs_R[MD_REG_V0] = fd[0];
01678         /*pipe 2*/regs->regs_R[3] = fd[1];
01679 
01680         /* check for an error condition */
01681         if (regs->regs_R[7] == (qword_t)-1)
01682           {
01683             regs->regs_R[MD_REG_V0] = errno;
01684             regs->regs_R[7] = 1;
01685           }
01686       }
01687       break;
01688 #endif
01689 
01690     case OSF_SYS_getgid:
01691 #ifdef _MSC_VER
01692       warn("syscall getgid() not yet implemented for MSC...");
01693       regs->regs_R[MD_REG_A3] = 0;
01694 #else /* !_MSC_VER */
01695       /* get current group id */
01696       /*first result*/regs->regs_R[MD_REG_V0] = getgid();
01697       /*second result*/regs->regs_R[MD_REG_A4] = getegid();
01698 
01699       /* check for an error condition */
01700       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01701         regs->regs_R[MD_REG_A3] = 0;
01702       else /* got an error, return details */
01703         {
01704           regs->regs_R[MD_REG_A3] = -1;
01705           regs->regs_R[MD_REG_V0] = errno;
01706         }
01707 #endif /* _MSC_VER */
01708       break;
01709 
01710     case OSF_SYS_ioctl:
01711       switch (/* req */regs->regs_R[MD_REG_A1])
01712         {
01713 #if !defined(TIOCGETP) && defined(linux)
01714         case OSF_TIOCGETP: /* <Out,TIOCGETP,6> */
01715           {
01716             struct termios lbuf;
01717             struct osf_sgttyb buf;
01718 
01719             /* result */regs->regs_R[MD_REG_V0] =
01720                           tcgetattr(/* fd */(int)regs->regs_R[MD_REG_A0],
01721                                     &lbuf);
01722 
01723             /* translate results */
01724             buf.sg_ispeed = lbuf.c_ispeed;
01725             buf.sg_ospeed = lbuf.c_ospeed;
01726             buf.sg_erase = lbuf.c_cc[VERASE];
01727             buf.sg_kill = lbuf.c_cc[VKILL];
01728             buf.sg_flags = 0;   /* FIXME: this is wrong... */
01729 
01730             mem_bcopy(mem_fn, mem, Write,
01731                       /* buf */regs->regs_R[MD_REG_A2], &buf,
01732                       sizeof(struct osf_sgttyb));
01733 
01734             if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01735               regs->regs_R[MD_REG_A3] = 0;
01736             else /* probably not a typewriter, return details */
01737               {
01738                 regs->regs_R[MD_REG_A3] = -1;
01739                 regs->regs_R[MD_REG_V0] = errno;
01740               }
01741           }
01742           break;
01743 #endif
01744 #ifdef TIOCGETP
01745         case OSF_TIOCGETP: /* <Out,TIOCGETP,6> */
01746           {
01747             struct sgttyb lbuf;
01748             struct osf_sgttyb buf;
01749 
01750             /* result */regs->regs_R[MD_REG_V0] =
01751               ioctl(/* fd */(int)regs->regs_R[MD_REG_A0],
01752                     /* req */TIOCGETP,
01753                     &lbuf);
01754 
01755             /* translate results */
01756             buf.sg_ispeed = lbuf.sg_ispeed;
01757             buf.sg_ospeed = lbuf.sg_ospeed;
01758             buf.sg_erase = lbuf.sg_erase;
01759             buf.sg_kill = lbuf.sg_kill;
01760             buf.sg_flags = lbuf.sg_flags;
01761             mem_bcopy(mem_fn, mem, Write,
01762                       /* buf */regs->regs_R[MD_REG_A2], &buf,
01763                       sizeof(struct osf_sgttyb));
01764 
01765             if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01766               regs->regs_R[MD_REG_A3] = 0;
01767             else /* not a typewriter, return details */
01768               {
01769                 regs->regs_R[MD_REG_A3] = -1;
01770                 regs->regs_R[MD_REG_V0] = errno;
01771               }
01772           }
01773           break;
01774 #endif
01775 #ifdef FIONREAD
01776         case OSF_FIONREAD:
01777           {
01778             int nread;
01779 
01780             /* result */regs->regs_R[MD_REG_V0] =
01781               ioctl(/* fd */(int)regs->regs_R[MD_REG_A0],
01782                     /* req */FIONREAD,
01783                     /* arg */&nread);
01784 
01785             mem_bcopy(mem_fn, mem, Write,
01786                       /* arg */regs->regs_R[MD_REG_A2],
01787                       &nread, sizeof(nread));
01788 
01789             if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01790               regs->regs_R[MD_REG_A3] = 0;
01791             else /* not a typewriter, return details */
01792               {
01793                 regs->regs_R[MD_REG_A3] = -1;
01794                 regs->regs_R[MD_REG_V0] = errno;
01795               }
01796           }
01797           break;
01798 #endif
01799 #ifdef FIONBIO
01800         case /*FIXME*/FIONBIO:
01801           {
01802             int arg = 0;
01803 
01804             if (regs->regs_R[MD_REG_A2])
01805               mem_bcopy(mem_fn, mem, Read,
01806                       /* arg */regs->regs_R[MD_REG_A2],
01807                       &arg, sizeof(arg));
01808 
01809 #ifdef NOTNOW
01810             fprintf(stderr, "FIONBIO: %d, %d\n",
01811                     (int)regs->regs_R[MD_REG_A0],
01812                     arg);
01813 #endif
01814             /* result */regs->regs_R[MD_REG_V0] =
01815               ioctl(/* fd */(int)regs->regs_R[MD_REG_A0],
01816                     /* req */FIONBIO,
01817                     /* arg */&arg);
01818 
01819             if (regs->regs_R[MD_REG_A2])
01820               mem_bcopy(mem_fn, mem, Write,
01821                       /* arg */regs->regs_R[MD_REG_A2],
01822                       &arg, sizeof(arg));
01823 
01824             if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01825               regs->regs_R[MD_REG_A3] = 0;
01826             else /* not a typewriter, return details */
01827               {
01828                 regs->regs_R[MD_REG_A3] = -1;
01829                 regs->regs_R[MD_REG_V0] = errno;
01830               }
01831           }
01832           break;
01833 #endif
01834         default:
01835           warn("unsupported ioctl call: ioctl(%ld, ...)",
01836                regs->regs_R[MD_REG_A1]);
01837           regs->regs_R[MD_REG_A3] = 0;
01838           break;
01839         }
01840       break;
01841 
01842 #if 0
01843       {
01844         char buf[NUM_IOCTL_BYTES];
01845         int local_req = 0;
01846 
01847         /* convert target ioctl() request to host ioctl() request values */
01848         switch (/*req*/regs->regs_R[MD_REG_A1]) {
01849 /* #if !defined(__CYGWIN32__) */
01850         case SS_IOCTL_TIOCGETP:
01851           local_req = TIOCGETP;
01852           break;
01853         case SS_IOCTL_TIOCSETP:
01854           local_req = TIOCSETP;
01855           break;
01856         case SS_IOCTL_TCGETP:
01857           local_req = TIOCGETP;
01858           break;
01859 /* #endif */
01860 #ifdef TCGETA
01861         case SS_IOCTL_TCGETA:
01862           local_req = TCGETA;
01863           break;
01864 #endif
01865 #ifdef TIOCGLTC
01866         case SS_IOCTL_TIOCGLTC:
01867           local_req = TIOCGLTC;
01868           break;
01869 #endif
01870 #ifdef TIOCSLTC
01871         case SS_IOCTL_TIOCSLTC:
01872           local_req = TIOCSLTC;
01873           break;
01874 #endif
01875         case SS_IOCTL_TIOCGWINSZ:
01876           local_req = TIOCGWINSZ;
01877           break;
01878 #ifdef TCSETAW
01879         case SS_IOCTL_TCSETAW:
01880           local_req = TCSETAW;
01881           break;
01882 #endif
01883 #ifdef TIOCGETC
01884         case SS_IOCTL_TIOCGETC:
01885           local_req = TIOCGETC;
01886           break;
01887 #endif
01888 #ifdef TIOCSETC
01889         case SS_IOCTL_TIOCSETC:
01890           local_req = TIOCSETC;
01891           break;
01892 #endif
01893 #ifdef TIOCLBIC
01894         case SS_IOCTL_TIOCLBIC:
01895           local_req = TIOCLBIC;
01896           break;
01897 #endif
01898 #ifdef TIOCLBIS
01899         case SS_IOCTL_TIOCLBIS:
01900           local_req = TIOCLBIS;
01901           break;
01902 #endif
01903 #ifdef TIOCLGET
01904         case SS_IOCTL_TIOCLGET:
01905           local_req = TIOCLGET;
01906           break;
01907 #endif
01908 #ifdef TIOCLSET
01909         case SS_IOCTL_TIOCLSET:
01910           local_req = TIOCLSET;
01911           break;
01912 #endif
01913         }
01914 
01915         if (!local_req)
01916           {
01917             /* FIXME: could not translate the ioctl() request, just warn user
01918                and ignore the request */
01919             warn("syscall: ioctl: ioctl code not supported d=%d, req=%d",
01920                  regs->regs_R[MD_REG_A0], regs->regs_R[MD_REG_A1]);
01921             regs->regs_R[MD_REG_V0] = 0;
01922             regs->regs_R[7] = 0;
01923           }
01924         else
01925           {
01926             /* ioctl() code was successfully translated to a host code */
01927 
01928             /* if arg ptr exists, copy NUM_IOCTL_BYTES bytes to host mem */
01929             if (/*argp*/regs->regs_R[MD_REG_A2] != 0)
01930               mem_bcopy(mem_fn, mem, Read, /*argp*/regs->regs_R[MD_REG_A2],
01931                         buf, NUM_IOCTL_BYTES);
01932 
01933             /* perform the ioctl() call */
01934             /*result*/regs->regs_R[MD_REG_V0] =
01935               ioctl(/*fd*/regs->regs_R[MD_REG_A0], local_req, buf);
01936 
01937             /* if arg ptr exists, copy NUM_IOCTL_BYTES bytes from host mem */
01938             if (/*argp*/regs->regs_R[MD_REG_A2] != 0)
01939               mem_bcopy(mem_fn, mem, Write, regs->regs_R[MD_REG_A2],
01940                         buf, NUM_IOCTL_BYTES);
01941 
01942             /* check for an error condition */
01943             if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01944               regs->regs_R[7] = 0;
01945             else
01946               { 
01947                 /* got an error, return details */
01948                 regs->regs_R[MD_REG_V0] = errno;
01949                 regs->regs_R[7] = 1;
01950               }
01951           }
01952       }
01953       break;
01954 #endif
01955 
01956     case OSF_SYS_fstat:
01957       {
01958         struct osf_statbuf osf_sbuf;
01959 #ifdef _MSC_VER
01960         struct _stat sbuf;
01961 #else /* !_MSC_VER */
01962         struct stat sbuf;
01963 #endif /* _MSC_VER */
01964 
01965         /* fstat() the file */
01966         /*result*/regs->regs_R[MD_REG_V0] =
01967           fstat(/*fd*/regs->regs_R[MD_REG_A0], &sbuf);
01968 
01969         /* check for an error condition */
01970         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
01971           regs->regs_R[MD_REG_A3] = 0;
01972         else /* got an error, return details */
01973           {
01974             regs->regs_R[MD_REG_A3] = -1;
01975             regs->regs_R[MD_REG_V0] = errno;
01976           }
01977 
01978         /* translate the stat structure to host format */
01979         osf_sbuf.osf_st_dev = MD_SWAPW(sbuf.st_dev);
01980         osf_sbuf.osf_st_ino = MD_SWAPW(sbuf.st_ino);
01981         osf_sbuf.osf_st_mode = MD_SWAPW(sbuf.st_mode);
01982         osf_sbuf.osf_st_nlink = MD_SWAPH(sbuf.st_nlink);
01983         osf_sbuf.osf_st_uid = MD_SWAPW(sbuf.st_uid);
01984         osf_sbuf.osf_st_gid = MD_SWAPW(sbuf.st_gid);
01985         osf_sbuf.osf_st_rdev = MD_SWAPW(sbuf.st_rdev);
01986         osf_sbuf.osf_st_size = MD_SWAPQ(sbuf.st_size);
01987         osf_sbuf.osf_st_atime = MD_SWAPW(sbuf.st_atime);
01988         osf_sbuf.osf_st_mtime = MD_SWAPW(sbuf.st_mtime);
01989         osf_sbuf.osf_st_ctime = MD_SWAPW(sbuf.st_ctime);
01990 #ifndef _MSC_VER
01991         osf_sbuf.osf_st_blksize = MD_SWAPW(sbuf.st_blksize);
01992         osf_sbuf.osf_st_blocks = MD_SWAPW(sbuf.st_blocks);
01993 #endif /* !_MSC_VER */
01994 
01995         /* copy fstat() results to simulator memory */
01996         mem_bcopy(mem_fn, mem, Write, /*sbuf*/regs->regs_R[MD_REG_A1],
01997                   &osf_sbuf, sizeof(struct osf_statbuf));
01998       }
01999       break;
02000 
02001     case OSF_SYS_getpagesize:
02002       /* get target pagesize */
02003       regs->regs_R[MD_REG_V0] = /* was: getpagesize() */MD_PAGE_SIZE;
02004 
02005       /* check for an error condition */
02006       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02007         regs->regs_R[MD_REG_A3] = 0;
02008       else /* got an error, return details */
02009         {
02010           regs->regs_R[MD_REG_A3] = -1;
02011           regs->regs_R[MD_REG_V0] = errno;
02012         }
02013       break;
02014 
02015     case OSF_SYS_setitimer:
02016       /* FIXME: the sigvec system call is ignored */
02017       warn("syscall: setitimer ignored");
02018       regs->regs_R[MD_REG_A3] = 0;
02019       break;
02020 
02021     case OSF_SYS_table:
02022       {
02023         qword_t table_id, table_index, buf_addr, num_elem, size_elem;
02024         struct osf_tbl_sysinfo sysinfo;
02025         
02026         table_id = regs->regs_R[MD_REG_A1];
02027         table_index = regs->regs_R[MD_REG_A2];
02028         buf_addr = regs->regs_R[MD_REG_A3];
02029         num_elem = regs->regs_R[MD_REG_A4];
02030         size_elem = regs->regs_R[MD_REG_A5];
02031         
02032         switch(table_id)
02033         {
02034         case OSF_TBL_SYSINFO:
02035           if (table_index != 0)
02036             {
02037               panic("table: table id TBL_SYSINFO requires 0 index, got %08d",
02038                     table_index );
02039             }
02040           else if (num_elem != 1)
02041             {
02042               panic("table: table id TBL_SYSINFO requires 1 elts, got %08d",
02043                     num_elem );
02044             }
02045           else
02046             {
02047               struct rusage rusage_info;
02048               
02049               /* use getrusage() to determine user & system time */
02050               if (getrusage(RUSAGE_SELF, &rusage_info) < 0)
02051                 {
02052                   /* abort the system call */
02053                   regs->regs_R[MD_REG_A3] = -1;
02054                   /* not kosher to pass off errno of getrusage() as errno
02055                      of table(), but what the heck... */
02056                   regs->regs_R[MD_REG_V0] = errno;
02057                   break;
02058                 }
02059               
02060               /* use sysconf() to determine clock tick frequency */
02061               sysinfo.si_hz = sysconf(_SC_CLK_TCK);
02062 
02063               /* convert user and system time into clock ticks */
02064               sysinfo.si_user = rusage_info.ru_utime.tv_sec * sysinfo.si_hz + 
02065                 (rusage_info.ru_utime.tv_usec * sysinfo.si_hz) / 1000000UL;
02066               sysinfo.si_sys = rusage_info.ru_stime.tv_sec * sysinfo.si_hz + 
02067                 (rusage_info.ru_stime.tv_usec * sysinfo.si_hz) / 1000000UL;
02068 
02069               /* following can't be determined in a portable manner and
02070                  are ignored */
02071               sysinfo.si_nice = 0;
02072               sysinfo.si_idle = 0;
02073               sysinfo.si_phz = 0;
02074               sysinfo.si_boottime = 0;
02075               sysinfo.wait = 0;
02076 
02077               /* copy structure into simulator memory */
02078               mem_bcopy(mem_fn, mem, Write, buf_addr,
02079                         &sysinfo, sizeof(struct osf_tbl_sysinfo));
02080 
02081               /* return success */
02082               regs->regs_R[MD_REG_A3] = 0;
02083             }
02084           break;
02085 
02086         default:
02087           warn("table: unsupported table id %d requested, ignored", table_id);
02088           regs->regs_R[MD_REG_A3] = 0;
02089         }
02090       }
02091       break;
02092 
02093     case OSF_SYS_getdtablesize:
02094 #if defined(_AIX) || defined(__alpha)
02095       /* get descriptor table size */
02096       regs->regs_R[MD_REG_V0] = getdtablesize();
02097 
02098       /* check for an error condition */
02099       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02100         regs->regs_R[MD_REG_A3] = 0;
02101       else /* got an error, return details */
02102         {
02103           regs->regs_R[MD_REG_A3] = -1;
02104           regs->regs_R[MD_REG_V0] = errno;
02105         }
02106 #elif defined(ultrix)
02107       {
02108         /* no comparable system call found, try some reasonable defaults */
02109         warn("syscall: called getdtablesize\n");
02110         regs->regs_R[MD_REG_V0] = 16;
02111         regs->regs_R[MD_REG_A3] = 0;
02112       }
02113 #elif defined(MIN_SYSCALL_MODE)
02114       {
02115         /* no comparable system call found, try some reasonable defaults */
02116         warn("syscall: called getdtablesize\n");
02117         regs->regs_R[MD_REG_V0] = 16;
02118         regs->regs_R[MD_REG_A3] = 0;
02119       }
02120 #else
02121       {
02122         struct rlimit rl;
02123 
02124         /* get descriptor table size in rlimit structure */
02125         if (getrlimit(RLIMIT_NOFILE, &rl) != (qword_t)-1)
02126           {
02127             regs->regs_R[MD_REG_V0] = rl.rlim_cur;
02128             regs->regs_R[MD_REG_A3] = 0;
02129           }
02130         else /* got an error, return details */
02131           {
02132             regs->regs_R[MD_REG_A3] = -1;
02133             regs->regs_R[MD_REG_V0] = errno;
02134           }
02135       }
02136 #endif
02137       break;
02138 
02139     case OSF_SYS_dup2:
02140       /* dup2() the file descriptor */
02141       regs->regs_R[MD_REG_V0] =
02142         dup2(/*fd1*/regs->regs_R[MD_REG_A0], /*fd2*/regs->regs_R[MD_REG_A1]);
02143 
02144       /* check for an error condition */
02145       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02146         regs->regs_R[MD_REG_A3] = 0;
02147       else /* got an error, return details */
02148         {
02149           regs->regs_R[MD_REG_A3] = -1;
02150           regs->regs_R[MD_REG_V0] = errno;
02151         }
02152       break;
02153 
02154     case OSF_SYS_fcntl:
02155 #ifdef _MSC_VER
02156       warn("syscall fcntl() not yet implemented for MSC...");
02157       regs->regs_R[MD_REG_A3] = 0;
02158 #else /* !_MSC_VER */
02159       /* get fcntl() information on the file */
02160       regs->regs_R[MD_REG_V0] =
02161         fcntl(/*fd*/regs->regs_R[MD_REG_A0],
02162               /*cmd*/regs->regs_R[MD_REG_A1], /*arg*/regs->regs_R[MD_REG_A2]);
02163 
02164       /* check for an error condition */
02165       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02166         regs->regs_R[MD_REG_A3] = 0;
02167       else /* got an error, return details */
02168         {
02169           regs->regs_R[MD_REG_A3] = -1;
02170           regs->regs_R[MD_REG_V0] = errno;
02171         }
02172 #endif /* _MSC_VER */
02173       break;
02174 
02175 #if 0
02176     case OSF_SYS_sigvec:
02177       /* FIXME: the sigvec system call is ignored */
02178       warn("syscall: sigvec ignored");
02179       regs->regs_R[MD_REG_A3] = 0;
02180       break;
02181 #endif
02182 
02183 #if 0
02184     case OSF_SYS_sigblock:
02185       /* FIXME: the sigblock system call is ignored */
02186       warn("syscall: sigblock ignored");
02187       regs->regs_R[MD_REG_A3] = 0;
02188       break;
02189 #endif
02190 
02191 #if 0
02192     case OSF_SYS_sigsetmask:
02193       /* FIXME: the sigsetmask system call is ignored */
02194       warn("syscall: sigsetmask ignored");
02195       regs->regs_R[MD_REG_A3] = 0;
02196       break;
02197 #endif
02198 
02199     case OSF_SYS_gettimeofday:
02200 #ifdef _MSC_VER
02201       warn("syscall gettimeofday() not yet implemented for MSC...");
02202       regs->regs_R[MD_REG_A3] = 0;
02203 #else /* _MSC_VER */
02204       {
02205         struct osf_timeval osf_tv;
02206         struct timeval tv, *tvp;
02207         struct osf_timezone osf_tz;
02208         struct timezone tz, *tzp;
02209 
02210         if (/*timeval*/regs->regs_R[MD_REG_A0] != 0)
02211           {
02212             /* copy timeval into host memory */
02213             mem_bcopy(mem_fn, mem, Read, /*timeval*/regs->regs_R[MD_REG_A0],
02214                       &osf_tv, sizeof(struct osf_timeval));
02215 
02216             /* convert target timeval structure to host format */
02217             tv.tv_sec = MD_SWAPW(osf_tv.osf_tv_sec);
02218             tv.tv_usec = MD_SWAPW(osf_tv.osf_tv_usec);
02219             tvp = &tv;
02220           }
02221         else
02222           tvp = NULL;
02223 
02224         if (/*timezone*/regs->regs_R[MD_REG_A1] != 0)
02225           {
02226             /* copy timezone into host memory */
02227             mem_bcopy(mem_fn, mem, Read, /*timezone*/regs->regs_R[MD_REG_A1],
02228                       &osf_tz, sizeof(struct osf_timezone));
02229 
02230             /* convert target timezone structure to host format */
02231             tz.tz_minuteswest = MD_SWAPW(osf_tz.osf_tz_minuteswest);
02232             tz.tz_dsttime = MD_SWAPW(osf_tz.osf_tz_dsttime);
02233             tzp = &tz;
02234           }
02235         else
02236           tzp = NULL;
02237 
02238         /* get time of day */
02239         /*result*/regs->regs_R[MD_REG_V0] = gettimeofday(tvp, tzp);
02240 
02241         /* check for an error condition */
02242         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02243           regs->regs_R[MD_REG_A3] = 0;
02244         else /* got an error, return details */
02245           {
02246             regs->regs_R[MD_REG_A3] = -1;
02247             regs->regs_R[MD_REG_V0] = errno;
02248           }
02249 
02250         if (/*timeval*/regs->regs_R[MD_REG_A0] != 0)
02251           {
02252             /* convert host timeval structure to target format */
02253             osf_tv.osf_tv_sec = MD_SWAPW(tv.tv_sec);
02254             osf_tv.osf_tv_usec = MD_SWAPW(tv.tv_usec);
02255 
02256             /* copy timeval to target memory */
02257             mem_bcopy(mem_fn, mem, Write, /*timeval*/regs->regs_R[MD_REG_A0],
02258                       &osf_tv, sizeof(struct osf_timeval));
02259           }
02260 
02261         if (/*timezone*/regs->regs_R[MD_REG_A1] != 0)
02262           {
02263             /* convert host timezone structure to target format */
02264             osf_tz.osf_tz_minuteswest = MD_SWAPW(tz.tz_minuteswest);
02265             osf_tz.osf_tz_dsttime = MD_SWAPW(tz.tz_dsttime);
02266 
02267             /* copy timezone to target memory */
02268             mem_bcopy(mem_fn, mem, Write, /*timezone*/regs->regs_R[MD_REG_A1],
02269                       &osf_tz, sizeof(struct osf_timezone));
02270           }
02271       }
02272 #endif /* !_MSC_VER */
02273       break;
02274 
02275     case OSF_SYS_getrusage:
02276 #if defined(__svr4__) || defined(__USLC__) || defined(hpux) || defined(__hpux) || defined(_AIX)
02277       {
02278         struct tms tms_buf;
02279         struct osf_rusage rusage;
02280 
02281         /* get user and system times */
02282         if (times(&tms_buf) != (qword_t)-1)
02283           {
02284             /* no error */
02285             regs->regs_R[MD_REG_V0] = 0;
02286             regs->regs_R[MD_REG_A3] = 0;
02287           }
02288         else /* got an error, indicate result */
02289           {
02290             regs->regs_R[MD_REG_A3] = -1;
02291             regs->regs_R[MD_REG_V0] = errno;
02292           }
02293 
02294         /* initialize target rusage result structure */
02295 #if defined(__svr4__)
02296         memset(&rusage, '\0', sizeof(struct osf_rusage));
02297 #else /* !defined(__svr4__) */
02298         bzero(&rusage, sizeof(struct osf_rusage));
02299 #endif
02300 
02301         /* convert from host rusage structure to target format */
02302         rusage.osf_ru_utime.osf_tv_sec = MD_SWAPW(tms_buf.tms_utime/CLK_TCK);
02303         rusage.osf_ru_utime.osf_tv_sec =
02304           MD_SWAPW(rusage.osf_ru_utime.osf_tv_sec);
02305         rusage.osf_ru_utime.osf_tv_usec = 0;
02306         rusage.osf_ru_stime.osf_tv_sec = MD_SWAPW(tms_buf.tms_stime/CLK_TCK);
02307         rusage.osf_ru_stime.osf_tv_sec =
02308           MD_SWAPW(rusage.osf_ru_stime.osf_tv_sec);
02309         rusage.osf_ru_stime.osf_tv_usec = 0;
02310 
02311         /* copy rusage results into target memory */
02312         mem_bcopy(mem_fn, mem, Write, /*rusage*/regs->regs_R[MD_REG_A1],
02313                   &rusage, sizeof(struct osf_rusage));
02314       }
02315 #elif defined(__unix__)
02316       {
02317         struct rusage local_rusage;
02318         struct osf_rusage rusage;
02319 
02320         /* get rusage information */
02321         /*result*/regs->regs_R[MD_REG_V0] =
02322           getrusage(/*who*/regs->regs_R[MD_REG_A0], &local_rusage);
02323 
02324         /* check for an error condition */
02325         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02326           regs->regs_R[MD_REG_A3] = 0;
02327         else /* got an error, return details */
02328           {
02329             regs->regs_R[MD_REG_A3] = -1;
02330             regs->regs_R[MD_REG_V0] = errno;
02331           }
02332 
02333         /* convert from host rusage structure to target format */
02334         rusage.osf_ru_utime.osf_tv_sec =
02335           MD_SWAPW(local_rusage.ru_utime.tv_sec);
02336         rusage.osf_ru_utime.osf_tv_usec =
02337           MD_SWAPW(local_rusage.ru_utime.tv_usec);
02338         rusage.osf_ru_utime.osf_tv_sec =
02339           MD_SWAPW(local_rusage.ru_utime.tv_sec);
02340         rusage.osf_ru_utime.osf_tv_usec =
02341           MD_SWAPW(local_rusage.ru_utime.tv_usec);
02342         rusage.osf_ru_stime.osf_tv_sec =
02343           MD_SWAPW(local_rusage.ru_stime.tv_sec);
02344         rusage.osf_ru_stime.osf_tv_usec =
02345           MD_SWAPW(local_rusage.ru_stime.tv_usec);
02346         rusage.osf_ru_stime.osf_tv_sec =
02347           MD_SWAPW(local_rusage.ru_stime.tv_sec);
02348         rusage.osf_ru_stime.osf_tv_usec =
02349           MD_SWAPW(local_rusage.ru_stime.tv_usec);
02350         rusage.osf_ru_maxrss = MD_SWAPW(local_rusage.ru_maxrss);
02351         rusage.osf_ru_ixrss = MD_SWAPW(local_rusage.ru_ixrss);
02352         rusage.osf_ru_idrss = MD_SWAPW(local_rusage.ru_idrss);
02353         rusage.osf_ru_isrss = MD_SWAPW(local_rusage.ru_isrss);
02354         rusage.osf_ru_minflt = MD_SWAPW(local_rusage.ru_minflt);
02355         rusage.osf_ru_majflt = MD_SWAPW(local_rusage.ru_majflt);
02356         rusage.osf_ru_nswap = MD_SWAPW(local_rusage.ru_nswap);
02357         rusage.osf_ru_inblock = MD_SWAPW(local_rusage.ru_inblock);
02358         rusage.osf_ru_oublock = MD_SWAPW(local_rusage.ru_oublock);
02359         rusage.osf_ru_msgsnd = MD_SWAPW(local_rusage.ru_msgsnd);
02360         rusage.osf_ru_msgrcv = MD_SWAPW(local_rusage.ru_msgrcv);
02361         rusage.osf_ru_nsignals = MD_SWAPW(local_rusage.ru_nsignals);
02362         rusage.osf_ru_nvcsw = MD_SWAPW(local_rusage.ru_nvcsw);
02363         rusage.osf_ru_nivcsw = MD_SWAPW(local_rusage.ru_nivcsw);
02364 
02365         /* copy rusage results into target memory */
02366         mem_bcopy(mem_fn, mem, Write, /*rusage*/regs->regs_R[MD_REG_A1],
02367                   &rusage, sizeof(struct osf_rusage));
02368       }
02369 #elif defined(__CYGWIN32__) || defined(_MSC_VER)
02370             warn("syscall: called getrusage\n");
02371             regs->regs_R[7] = 0;
02372 #else
02373 #error No getrusage() implementation!
02374 #endif
02375       break;
02376 
02377     case OSF_SYS_utimes:
02378       {
02379         char buf[MAXBUFSIZE];
02380 
02381         /* copy filename to host memory */
02382         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[MD_REG_A0], buf);
02383 
02384         if (/*timeval*/regs->regs_R[MD_REG_A1] == 0)
02385           {
02386 #if defined(hpux) || defined(__hpux) || defined(__i386__)
02387             /* no utimes() in hpux, use utime() instead */
02388             /*result*/regs->regs_R[MD_REG_V0] = utime(buf, NULL);
02389 #elif defined(_MSC_VER)
02390             /* no utimes() in MSC, use utime() instead */
02391             /*result*/regs->regs_R[MD_REG_V0] = utime(buf, NULL);
02392 #elif defined(__svr4__) || defined(__USLC__) || defined(unix) || defined(_AIX) || defined(__alpha)
02393             /*result*/regs->regs_R[MD_REG_V0] = utimes(buf, NULL);
02394 #elif defined(__CYGWIN32__)
02395             warn("syscall: called utimes\n");
02396 #else
02397 #error No utimes() implementation!
02398 #endif
02399           }
02400         else
02401           {
02402             struct osf_timeval osf_tval[2];
02403 #ifndef _MSC_VER
02404             struct timeval tval[2];
02405 #endif /* !_MSC_VER */
02406 
02407             /* copy timeval structure to host memory */
02408             mem_bcopy(mem_fn, mem, Read, /*timeout*/regs->regs_R[MD_REG_A1],
02409                       osf_tval, 2*sizeof(struct osf_timeval));
02410 
02411 #ifndef _MSC_VER
02412             /* convert timeval structure to host format */
02413             tval[0].tv_sec = MD_SWAPW(osf_tval[0].osf_tv_sec);
02414             tval[0].tv_usec = MD_SWAPW(osf_tval[0].osf_tv_usec);
02415             tval[1].tv_sec = MD_SWAPW(osf_tval[1].osf_tv_sec);
02416             tval[1].tv_usec = MD_SWAPW(osf_tval[1].osf_tv_usec);
02417 #endif /* !_MSC_VER */
02418 
02419 #if defined(hpux) || defined(__hpux) || defined(__svr4__)
02420             /* no utimes() in hpux, use utime() instead */
02421             {
02422               struct utimbuf ubuf;
02423 
02424               ubuf.actime = MD_SWAPW(tval[0].tv_sec);
02425               ubuf.modtime = MD_SWAPW(tval[1].tv_sec);
02426 
02427               /* result */regs->regs_R[MD_REG_V0] = utime(buf, &ubuf);
02428             }
02429 #elif defined(_MSC_VER)
02430             /* no utimes() in hpux, use utime() instead */
02431             {
02432               struct _utimbuf ubuf;
02433 
02434               ubuf.actime = MD_SWAPW(osf_tval[0].osf_tv_sec);
02435               ubuf.modtime = MD_SWAPW(osf_tval[1].osf_tv_sec);
02436 
02437               /* result */regs->regs_R[MD_REG_V0] = utime(buf, &ubuf);
02438             }
02439 #elif defined(__USLC__) || defined(unix) || defined(_AIX) || defined(__alpha)
02440             /* result */regs->regs_R[MD_REG_V0] = utimes(buf, tval);
02441 #elif defined(__CYGWIN32__)
02442             warn("syscall: called utimes\n");
02443 #else
02444 #error No utimes() implementation!
02445 #endif
02446           }
02447 
02448         /* check for an error condition */
02449         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02450           regs->regs_R[MD_REG_A3] = 0;
02451         else /* got an error, return details */
02452           {
02453             regs->regs_R[MD_REG_A3] = -1;
02454             regs->regs_R[MD_REG_V0] = errno;
02455           }
02456       }
02457       break;
02458 
02459     case OSF_SYS_getrlimit:
02460     case OSF_SYS_setrlimit:
02461 #ifdef _MSC_VER
02462       warn("syscall get/setrlimit() not yet implemented for MSC...");
02463       regs->regs_R[MD_REG_A3] = 0;
02464 #elif defined(__CYGWIN32__)
02465       {
02466         warn("syscall: called get/setrlimit\n");
02467         regs->regs_R[MD_REG_A3] = 0;
02468       }
02469 #else
02470       {
02471         struct osf_rlimit osf_rl;
02472         struct rlimit rl;
02473 
02474         /* copy rlimit structure to host memory */
02475         mem_bcopy(mem_fn, mem, Read, /*rlimit*/regs->regs_R[MD_REG_A1],
02476                   &osf_rl, sizeof(struct osf_rlimit));
02477 
02478         /* convert rlimit structure to host format */
02479         rl.rlim_cur = MD_SWAPQ(osf_rl.osf_rlim_cur);
02480         rl.rlim_max = MD_SWAPQ(osf_rl.osf_rlim_max);
02481 
02482         /* get rlimit information */
02483         if (syscode == OSF_SYS_getrlimit)
02484           /*result*/regs->regs_R[MD_REG_V0] =
02485             getrlimit(regs->regs_R[MD_REG_A0], &rl);
02486         else /* syscode == OSF_SYS_setrlimit */
02487           /*result*/regs->regs_R[MD_REG_V0] =
02488             setrlimit(regs->regs_R[MD_REG_A0], &rl);
02489 
02490         /* check for an error condition */
02491         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02492           regs->regs_R[MD_REG_A3] = 0;
02493         else /* got an error, return details */
02494           {
02495             regs->regs_R[MD_REG_A3] = -1;
02496             regs->regs_R[MD_REG_V0] = errno;
02497           }
02498 
02499         /* convert rlimit structure to target format */
02500         osf_rl.osf_rlim_cur = MD_SWAPQ(rl.rlim_cur);
02501         osf_rl.osf_rlim_max = MD_SWAPQ(rl.rlim_max);
02502 
02503         /* copy rlimit structure to target memory */
02504         mem_bcopy(mem_fn, mem, Write, /*rlimit*/regs->regs_R[MD_REG_A1],
02505                   &osf_rl, sizeof(struct osf_rlimit));
02506       }
02507 #endif
02508       break;
02509 
02510     case OSF_SYS_sigprocmask:
02511       {
02512         static int first = TRUE;
02513 
02514         if (first)
02515           {
02516             warn("partially supported sigprocmask() call...");
02517             first = FALSE;
02518           }
02519 
02520         /* from klauser@cs.colorado.edu: there are a couple bugs in the
02521            sigprocmask implementation; here is a fix: the problem comes from an
02522            impedance mismatch between application/libc interface and
02523            libc/syscall interface, the former of which you read about in the
02524            manpage, the latter of which you actually intercept here.  The
02525            following is mostly correct, but does not capture some minor
02526            details, which you only get right if you really let the kernel
02527            handle it. (e.g. you can't really ever block sigkill etc.) */
02528 
02529         regs->regs_R[MD_REG_V0] = sigmask;
02530         regs->regs_R[MD_REG_A3] = 0;
02531 
02532         switch (regs->regs_R[MD_REG_A0])
02533           {
02534           case OSF_SIG_BLOCK:
02535             sigmask |= regs->regs_R[MD_REG_A1];
02536             break;
02537           case OSF_SIG_UNBLOCK:
02538             sigmask &= ~regs->regs_R[MD_REG_A1];
02539             break;
02540           case OSF_SIG_SETMASK:
02541             sigmask = regs->regs_R[MD_REG_A1];
02542             break;
02543           default:
02544             regs->regs_R[MD_REG_V0] = EINVAL;
02545             regs->regs_R[MD_REG_A3] = 1;
02546           }
02547 
02548 #if 0 /* FIXME: obsolete... */
02549         if (regs->regs_R[MD_REG_A2] > /* FIXME: why? */0x10000000)
02550           mem_bcopy(mem_fn, mem, Write, regs->regs_R[MD_REG_A2],
02551                     &sigmask, sizeof(sigmask));
02552 
02553         if (regs->regs_R[MD_REG_A1] != 0)
02554           {
02555             switch (regs->regs_R[MD_REG_A0])
02556               {
02557               case OSF_SIG_BLOCK:
02558                 sigmask |= regs->regs_R[MD_REG_A1];
02559                 break;
02560               case OSF_SIG_UNBLOCK:
02561                 sigmask &= regs->regs_R[MD_REG_A1]; /* I think */
02562               break;
02563               case OSF_SIG_SETMASK:
02564                 sigmask = regs->regs_R[MD_REG_A1]; /* I think */
02565                 break;
02566               default:
02567                 panic("illegal how value to sigprocmask()");
02568               }
02569           }
02570         regs->regs_R[MD_REG_V0] = 0;
02571         regs->regs_R[MD_REG_A3] = 0;
02572 #endif
02573       }
02574       break;
02575 
02576     case OSF_SYS_sigaction:
02577       {
02578         int signum;
02579         static int first = TRUE;
02580 
02581         if (first)
02582           {
02583             warn("partially supported sigaction() call...");
02584             first = FALSE;
02585           }
02586 
02587         signum = regs->regs_R[MD_REG_A0];
02588         if (regs->regs_R[MD_REG_A1] != 0)
02589           sigaction_array[signum] = regs->regs_R[MD_REG_A1];
02590 
02591         if (regs->regs_R[MD_REG_A2])
02592           regs->regs_R[MD_REG_A2] = sigaction_array[signum];
02593 
02594         regs->regs_R[MD_REG_V0] = 0;
02595 
02596         /* for some reason, __sigaction expects A3 to have a 0 return value */
02597         regs->regs_R[MD_REG_A3] = 0;
02598   
02599         /* FIXME: still need to add code so that on a signal, the 
02600            correct action is actually taken. */
02601 
02602         /* FIXME: still need to add support for returning the correct
02603            error messages (EFAULT, EINVAL) */
02604       }
02605       break;
02606 
02607     case OSF_SYS_sigstack:
02608       warn("unsupported sigstack() call...");
02609       regs->regs_R[MD_REG_A3] = 0;
02610       break;
02611 
02612     case OSF_SYS_sigreturn:
02613       {
02614         int i;
02615         struct osf_sigcontext sc;
02616         static int first = TRUE;
02617 
02618         if (first)
02619           {
02620             warn("partially supported sigreturn() call...");
02621             first = FALSE;
02622           }
02623 
02624         mem_bcopy(mem_fn, mem, Read, /* sc */regs->regs_R[MD_REG_A0],
02625                   &sc, sizeof(struct osf_sigcontext));
02626 
02627         sigmask = MD_SWAPQ(sc.sc_mask); /* was: prog_sigmask */
02628         regs->regs_NPC = MD_SWAPQ(sc.sc_pc);
02629 
02630         /* FIXME: should check for the branch delay bit */
02631         /* FIXME: current->nextpc = current->pc + 4; not sure about this... */
02632         for (i=0; i < 32; ++i)
02633           regs->regs_R[i] = sc.sc_regs[i];
02634         for (i=0; i < 32; ++i)
02635           regs->regs_F.q[i] = sc.sc_fpregs[i];
02636         regs->regs_C.fpcr = sc.sc_fpcr;
02637       }
02638       break;
02639 
02640     case OSF_SYS_uswitch:
02641       warn("unsupported uswitch() call...");
02642       regs->regs_R[MD_REG_V0] = regs->regs_R[MD_REG_A1]; 
02643       break;
02644 
02645     case OSF_SYS_setsysinfo:
02646       warn("unsupported setsysinfo() call...");
02647       regs->regs_R[MD_REG_V0] = 0; 
02648       break;
02649 
02650 #if !defined(MIN_SYSCALL_MODE)
02651     case OSF_SYS_getdirentries:
02652       {
02653         int i, cnt, osf_cnt;
02654         struct dirent *p;
02655         sword_t fd = regs->regs_R[MD_REG_A0];
02656         md_addr_t osf_buf = regs->regs_R[MD_REG_A1];
02657         char *buf;
02658         sword_t osf_nbytes = regs->regs_R[MD_REG_A2];
02659         md_addr_t osf_pbase = regs->regs_R[MD_REG_A3];
02660         sqword_t osf_base;
02661         long base = 0;
02662 
02663         /* number of entries in simulated memory */
02664         if (!osf_nbytes)
02665           warn("attempting to get 0 directory entries...");
02666 
02667         /* allocate local memory, whatever fits */
02668         buf = calloc(1, osf_nbytes);
02669         if (!buf)
02670           fatal("out of virtual memory");
02671 
02672         /* get directory entries */
02673 #if defined(__svr4__)
02674         base = lseek ((int)fd, (off_t)0, SEEK_CUR);
02675         regs->regs_R[MD_REG_V0] =
02676           getdents((int)fd, (struct dirent *)buf, (size_t)osf_nbytes);
02677 #else /* !__svr4__ */
02678         regs->regs_R[MD_REG_V0] =
02679           getdirentries((int)fd, buf, (size_t)osf_nbytes, &base);
02680 #endif
02681 
02682         /* check for an error condition */
02683         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02684           {
02685             regs->regs_R[MD_REG_A3] = 0;
02686 
02687             /* anything to copy back? */
02688             if (regs->regs_R[MD_REG_V0] > 0)
02689               {
02690                 /* copy all possible results to simulated space */
02691                 for (i=0, cnt=0, osf_cnt=0, p=(struct dirent *)buf;
02692                      cnt < regs->regs_R[MD_REG_V0] && p->d_reclen > 0;
02693                      i++, cnt += p->d_reclen, p=(struct dirent *)(buf+cnt))
02694                   {
02695                     struct osf_dirent osf_dirent;
02696 
02697                     osf_dirent.d_ino = MD_SWAPW(p->d_ino);
02698                     osf_dirent.d_namlen = MD_SWAPH(strlen(p->d_name));
02699                     strcpy(osf_dirent.d_name, p->d_name);
02700                     osf_dirent.d_reclen = MD_SWAPH(OSF_DIRENT_SZ(p->d_name));
02701 
02702                     mem_bcopy(mem_fn, mem, Write,
02703                               osf_buf + osf_cnt,
02704                               &osf_dirent, OSF_DIRENT_SZ(p->d_name));
02705                     osf_cnt += OSF_DIRENT_SZ(p->d_name);
02706                   }
02707 
02708                 if (osf_pbase != 0)
02709                   {
02710                     osf_base = (sqword_t)base;
02711                     mem_bcopy(mem_fn, mem, Write, osf_pbase,
02712                               &osf_base, sizeof(osf_base));
02713                   }
02714 
02715                 /* update V0 to indicate translated read length */
02716                 regs->regs_R[MD_REG_V0] = osf_cnt;
02717               }
02718           }
02719         else /* got an error, return details */
02720           {
02721             regs->regs_R[MD_REG_A3] = -1;
02722             regs->regs_R[MD_REG_V0] = errno;
02723           }
02724 
02725         free(buf);
02726       }
02727       break;
02728 #endif
02729 
02730 #if !defined(MIN_SYSCALL_MODE)
02731     case OSF_SYS_truncate:
02732       {
02733         char buf[MAXBUFSIZE];
02734 
02735         /* copy filename to host memory */
02736         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[MD_REG_A0], buf);
02737 
02738         /* truncate the file */
02739         /*result*/regs->regs_R[MD_REG_V0] =
02740           truncate(buf, /* length */(size_t)regs->regs_R[MD_REG_A1]);
02741 
02742         /* check for an error condition */
02743         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02744           regs->regs_R[MD_REG_A3] = 0;
02745         else /* got an error, return details */
02746           {
02747             regs->regs_R[MD_REG_A3] = -1;
02748             regs->regs_R[MD_REG_V0] = errno;
02749           }
02750       }
02751       break;
02752 #endif
02753 
02754 #if !defined(__CYGWIN32__) && !defined(_MSC_VER)
02755     case OSF_SYS_ftruncate:
02756       /* truncate the file */
02757       /*result*/regs->regs_R[MD_REG_V0] =
02758         ftruncate(/* fd */(int)regs->regs_R[MD_REG_A0],
02759                  /* length */(size_t)regs->regs_R[MD_REG_A1]);
02760 
02761       /* check for an error condition */
02762       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02763         regs->regs_R[MD_REG_A3] = 0;
02764       else /* got an error, return details */
02765         {
02766           regs->regs_R[MD_REG_A3] = -1;
02767           regs->regs_R[MD_REG_V0] = errno;
02768         }
02769       break;
02770 #endif
02771 
02772 #if !defined(MIN_SYSCALL_MODE)
02773     case OSF_SYS_statfs:
02774       {
02775         char buf[MAXBUFSIZE];
02776         struct osf_statfs osf_sbuf;
02777         struct statfs sbuf;
02778 
02779         /* copy filename to host memory */
02780         mem_strcpy(mem_fn, mem, Read, /*fName*/regs->regs_R[MD_REG_A0], buf);
02781 
02782         /* statfs() the fs */
02783         /*result*/regs->regs_R[MD_REG_V0] = statfs(buf, &sbuf);
02784 
02785         /* check for an error condition */
02786         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02787           regs->regs_R[MD_REG_A3] = 0;
02788         else /* got an error, return details */
02789           {
02790             regs->regs_R[MD_REG_A3] = -1;
02791             regs->regs_R[MD_REG_V0] = errno;
02792           }
02793 
02794         /* translate from host stat structure to target format */
02795 #if defined(__svr4__) || defined(__osf__)
02796         osf_sbuf.f_type = MD_SWAPH(0x6969) /* NFS, whatever... */;
02797 #else /* !__svr4__ */
02798         osf_sbuf.f_type = MD_SWAPH(sbuf.f_type);
02799 #endif
02800         osf_sbuf.f_fsize = MD_SWAPW(sbuf.f_bsize);
02801         osf_sbuf.f_blocks = MD_SWAPW(sbuf.f_blocks);
02802         osf_sbuf.f_bfree = MD_SWAPW(sbuf.f_bfree);
02803         osf_sbuf.f_bavail = MD_SWAPW(sbuf.f_bavail);
02804         osf_sbuf.f_files = MD_SWAPW(sbuf.f_files);
02805         osf_sbuf.f_ffree = MD_SWAPW(sbuf.f_ffree);
02806         /* osf_sbuf.f_fsid = MD_SWAPW(sbuf.f_fsid); */
02807 
02808         /* copy stat() results to simulator memory */
02809         mem_bcopy(mem_fn, mem, Write, /*sbuf*/regs->regs_R[MD_REG_A1],
02810                   &osf_sbuf, sizeof(struct osf_statbuf));
02811       }
02812       break;
02813 #endif
02814 
02815 #if !defined(MIN_SYSCALL_MODE)
02816     case OSF_SYS_setregid:
02817       /* set real and effective group ID */
02818 
02819       /*result*/regs->regs_R[MD_REG_V0] =
02820         setregid(/* rgid */(gid_t)regs->regs_R[MD_REG_A0],
02821                  /* egid */(gid_t)regs->regs_R[MD_REG_A1]);
02822 
02823       /* check for an error condition */
02824       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02825         regs->regs_R[MD_REG_A3] = 0;
02826       else /* got an error, return details */
02827         {
02828           regs->regs_R[MD_REG_A3] = -1;
02829           regs->regs_R[MD_REG_V0] = errno;
02830         }
02831       break;
02832 #endif
02833 
02834 #if !defined(MIN_SYSCALL_MODE)
02835     case OSF_SYS_setreuid:
02836       /* set real and effective user ID */
02837 
02838       /*result*/regs->regs_R[MD_REG_V0] =
02839         setreuid(/* ruid */(uid_t)regs->regs_R[MD_REG_A0],
02840                  /* euid */(uid_t)regs->regs_R[MD_REG_A1]);
02841 
02842       /* check for an error condition */
02843       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02844         regs->regs_R[MD_REG_A3] = 0;
02845       else /* got an error, return details */
02846         {
02847           regs->regs_R[MD_REG_A3] = -1;
02848           regs->regs_R[MD_REG_V0] = errno;
02849         }
02850       break;
02851 #endif
02852 
02853 #if !defined(MIN_SYSCALL_MODE)
02854     case OSF_SYS_socket:
02855       /* create an endpoint for communication */
02856 
02857       /* result */regs->regs_R[MD_REG_V0] =
02858         socket(/* domain */xlate_arg((int)regs->regs_R[MD_REG_A0],
02859                                      family_map, N_ELT(family_map),
02860                                      "socket(family)"),
02861                /* type */xlate_arg((int)regs->regs_R[MD_REG_A1],
02862                                    socktype_map, N_ELT(socktype_map),
02863                                    "socket(type)"),
02864                /* protocol */xlate_arg((int)regs->regs_R[MD_REG_A2],
02865                                        family_map, N_ELT(family_map),
02866                                        "socket(proto)"));
02867 
02868       /* check for an error condition */
02869       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02870         regs->regs_R[MD_REG_A3] = 0;
02871       else /* got an error, return details */
02872         {
02873           regs->regs_R[MD_REG_A3] = -1;
02874           regs->regs_R[MD_REG_V0] = errno;
02875         }
02876       break;
02877 #endif
02878 
02879 #if !defined(MIN_SYSCALL_MODE)
02880     case OSF_SYS_connect:
02881       {
02882         struct osf_sockaddr osf_sa;
02883 
02884         /* initiate a connection on a socket */
02885 
02886         /* get the socket address */
02887         if (regs->regs_R[MD_REG_A2] > sizeof(struct osf_sockaddr))
02888           {
02889             fatal("sockaddr size overflow: addrlen = %d",
02890                   regs->regs_R[MD_REG_A2]);
02891           }
02892         /* copy sockaddr structure to host memory */
02893         mem_bcopy(mem_fn, mem, Read, /* serv_addr */regs->regs_R[MD_REG_A1],
02894                   &osf_sa, /* addrlen */(int)regs->regs_R[MD_REG_A2]);
02895 #if 0
02896         int i;
02897         sa.sa_family = osf_sa.sa_family;
02898         for (i=0; i < regs->regs_R[MD_REG_A2]; i++)
02899           sa.sa_data[i] = osf_sa.sa_data[i];
02900 #endif
02901         /* result */regs->regs_R[MD_REG_V0] =
02902           connect(/* sockfd */(int)regs->regs_R[MD_REG_A0],
02903                   (void *)&osf_sa, /* addrlen */(int)regs->regs_R[MD_REG_A2]);
02904 
02905         /* check for an error condition */
02906         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02907           regs->regs_R[MD_REG_A3] = 0;
02908         else /* got an error, return details */
02909           {
02910             regs->regs_R[MD_REG_A3] = -1;
02911             regs->regs_R[MD_REG_V0] = errno;
02912           }
02913       }
02914       break;
02915 #endif
02916 
02917 #if !defined(MIN_SYSCALL_MODE)
02918     case OSF_SYS_uname:
02919       /* get name and information about current kernel */
02920 
02921       regs->regs_R[MD_REG_A3] = -1;
02922       regs->regs_R[MD_REG_V0] = EPERM;
02923       break;
02924 #endif
02925 
02926 #if !defined(MIN_SYSCALL_MODE)
02927     case OSF_SYS_writev:
02928       {
02929         int i;
02930         char *buf;
02931         struct iovec *iov;
02932 
02933         /* allocate host side I/O vectors */
02934         iov =
02935           (struct iovec *)malloc(/* iovcnt */regs->regs_R[MD_REG_A2]
02936                                  * sizeof(struct iovec));
02937         if (!iov)
02938           fatal("out of virtual memory in SYS_writev");
02939 
02940         /* copy target side I/O vector buffers to host memory */
02941         for (i=0; i < /* iovcnt */regs->regs_R[MD_REG_A2]; i++)
02942           {
02943             struct osf_iovec osf_iov;
02944 
02945             /* copy target side pointer data into host side vector */
02946             mem_bcopy(mem_fn, mem, Read,
02947                       (/*iov*/regs->regs_R[MD_REG_A1]
02948                        + i*sizeof(struct osf_iovec)),
02949                       &osf_iov, sizeof(struct osf_iovec));
02950 
02951             iov[i].iov_len = MD_SWAPW(osf_iov.iov_len);
02952             if (osf_iov.iov_base != 0 && osf_iov.iov_len != 0)
02953               {
02954                 buf = (char *)calloc(MD_SWAPW(osf_iov.iov_len), sizeof(char));
02955                 if (!buf)
02956                   fatal("out of virtual memory in SYS_writev");
02957                 mem_bcopy(mem_fn, mem, Read, MD_SWAPQ(osf_iov.iov_base),
02958                           buf, MD_SWAPW(osf_iov.iov_len));
02959                 iov[i].iov_base = buf;
02960               }
02961             else
02962               iov[i].iov_base = NULL;
02963           }
02964 
02965         /* perform the vector'ed write */
02966         do {
02967           /*result*/regs->regs_R[MD_REG_V0] =
02968             writev(/* fd */(int)regs->regs_R[MD_REG_A0], iov,
02969                    /* iovcnt */(size_t)regs->regs_R[MD_REG_A2]);
02970         } while (/*result*/regs->regs_R[MD_REG_V0] == -1
02971                  && errno == EAGAIN);
02972 
02973         /* check for an error condition */
02974         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
02975           regs->regs_R[MD_REG_A3] = 0;
02976         else /* got an error, return details */
02977           {
02978             regs->regs_R[MD_REG_A3] = -1;
02979             regs->regs_R[MD_REG_V0] = errno;
02980           }
02981 
02982         /* free all the allocated memory */
02983         for (i=0; i < /* iovcnt */regs->regs_R[MD_REG_A2]; i++)
02984           {
02985             if (iov[i].iov_base)
02986               {
02987                 free(iov[i].iov_base);
02988                 iov[i].iov_base = NULL;
02989               }
02990           }
02991         free(iov);
02992       }
02993       break;
02994 #endif
02995 
02996 #if !defined(MIN_SYSCALL_MODE)
02997     case OSF_SYS_readv:
02998       {
02999         int i;
03000         char *buf = NULL;
03001         struct osf_iovec *osf_iov;
03002         struct iovec *iov;
03003 
03004         /* allocate host side I/O vectors */
03005         osf_iov =
03006           calloc(/* iovcnt */regs->regs_R[MD_REG_A2],
03007                  sizeof(struct osf_iovec));
03008         if (!osf_iov)
03009           fatal("out of virtual memory in SYS_readv");
03010 
03011         iov =
03012           calloc(/* iovcnt */regs->regs_R[MD_REG_A2], sizeof(struct iovec));
03013         if (!iov)
03014           fatal("out of virtual memory in SYS_readv");
03015 
03016         /* copy host side I/O vector buffers */
03017         for (i=0; i < /* iovcnt */regs->regs_R[MD_REG_A2]; i++)
03018           {
03019             /* copy target side pointer data into host side vector */
03020             mem_bcopy(mem_fn, mem, Read,
03021                       (/*iov*/regs->regs_R[MD_REG_A1]
03022                        + i*sizeof(struct osf_iovec)),
03023                       &osf_iov[i], sizeof(struct osf_iovec));
03024 
03025             iov[i].iov_len = MD_SWAPW(osf_iov[i].iov_len);
03026             if (osf_iov[i].iov_base != 0 && osf_iov[i].iov_len != 0)
03027               {
03028                 buf =
03029                   (char *)calloc(MD_SWAPW(osf_iov[i].iov_len), sizeof(char));
03030                 if (!buf)
03031                   fatal("out of virtual memory in SYS_readv");
03032                 iov[i].iov_base = buf;
03033               }
03034             else
03035               iov[i].iov_base = NULL;
03036           }
03037 
03038         /* perform the vector'ed read */
03039         do {
03040           /*result*/regs->regs_R[MD_REG_V0] =
03041             readv(/* fd */(int)regs->regs_R[MD_REG_A0], iov,
03042                   /* iovcnt */(size_t)regs->regs_R[MD_REG_A2]);
03043         } while (/*result*/regs->regs_R[MD_REG_V0] == -1
03044                  && errno == EAGAIN);
03045 
03046         /* copy target side I/O vector buffers to host memory */
03047         for (i=0; i < /* iovcnt */regs->regs_R[MD_REG_A2]; i++)
03048           {
03049             if (osf_iov[i].iov_base != 0)
03050               {
03051                 mem_bcopy(mem_fn, mem, Write, MD_SWAPQ(osf_iov[i].iov_base),
03052                           iov[i].iov_base, MD_SWAPW(osf_iov[i].iov_len));
03053               }
03054           }
03055 
03056         /* check for an error condition */
03057         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03058           regs->regs_R[MD_REG_A3] = 0;
03059         else /* got an error, return details */
03060           {
03061             regs->regs_R[MD_REG_A3] = -1;
03062             regs->regs_R[MD_REG_V0] = errno;
03063           }
03064 
03065         /* free all the allocated memory */
03066         for (i=0; i < /* iovcnt */regs->regs_R[MD_REG_A2]; i++)
03067           {
03068             if (iov[i].iov_base)
03069               {
03070                 free(iov[i].iov_base);
03071                 iov[i].iov_base = NULL;
03072               }
03073           }
03074 
03075         if (osf_iov)
03076           free(osf_iov);
03077         if (iov)
03078           free(iov);
03079       }
03080       break;
03081 #endif
03082 
03083 #if !defined(MIN_SYSCALL_MODE)
03084     case OSF_SYS_setsockopt:
03085       {
03086         char *buf;
03087         struct xlate_table_t *map;
03088         int nmap;
03089 
03090         /* set options on sockets */
03091 
03092         /* copy optval to host memory */
03093         if (/* optval */regs->regs_R[MD_REG_A3] != 0
03094             && /* optlen */regs->regs_R[MD_REG_A4] != 0)
03095           {
03096             buf = calloc(1, /* optlen */(size_t)regs->regs_R[MD_REG_A4]);
03097             if (!buf)
03098               fatal("cannot allocate memory in OSF_SYS_setsockopt");
03099             
03100             /* copy target side pointer data into host side vector */
03101             mem_bcopy(mem_fn, mem, Read,
03102                       /* optval */regs->regs_R[MD_REG_A3],
03103                       buf, /* optlen */(int)regs->regs_R[MD_REG_A4]);
03104           }
03105         else
03106           buf = NULL;
03107 
03108         /* pick the correct translation table */
03109         if ((int)regs->regs_R[MD_REG_A1] == OSF_SOL_SOCKET)
03110           {
03111             map = sockopt_map;
03112             nmap = N_ELT(sockopt_map);
03113           }
03114         else if ((int)regs->regs_R[MD_REG_A1] == OSF_SOL_TCP)
03115           {
03116             map = tcpopt_map;
03117             nmap = N_ELT(tcpopt_map);
03118           }
03119         else
03120           {
03121             warn("no translation map available for `setsockopt()': %d",
03122                  (int)regs->regs_R[MD_REG_A1]);
03123             map = sockopt_map;
03124             nmap = N_ELT(sockopt_map);
03125           }
03126 
03127         /* result */regs->regs_R[MD_REG_V0] =
03128           setsockopt(/* sock */(int)regs->regs_R[MD_REG_A0],
03129                      /* level */xlate_arg((int)regs->regs_R[MD_REG_A1],
03130                                           socklevel_map, N_ELT(socklevel_map),
03131                                           "setsockopt(level)"),
03132                      /* optname */xlate_arg((int)regs->regs_R[MD_REG_A2],
03133                                             map, nmap,
03134                                             "setsockopt(opt)"),
03135                      /* optval */buf,
03136                      /* optlen */regs->regs_R[MD_REG_A4]);
03137 
03138         /* check for an error condition */
03139         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03140           regs->regs_R[MD_REG_A3] = 0;
03141         else /* got an error, return details */
03142           {
03143             regs->regs_R[MD_REG_A3] = -1;
03144             regs->regs_R[MD_REG_V0] = errno;
03145           }
03146 
03147         if (buf != NULL)
03148           free(buf);
03149       }
03150       break;
03151 #endif
03152 
03153 #if !defined(MIN_SYSCALL_MODE)
03154     case OSF_SYS_old_getsockname:
03155       {
03156         /* get socket name */
03157         char *buf;
03158         word_t osf_addrlen;
03159         int addrlen;
03160 
03161         /* get simulator memory parameters to host memory */
03162         mem_bcopy(mem_fn, mem, Read,
03163                   /* paddrlen */regs->regs_R[MD_REG_A2],
03164                   &osf_addrlen, sizeof(osf_addrlen));
03165         addrlen = (int)osf_addrlen;
03166         if (addrlen != 0)
03167           {
03168             buf = calloc(1, addrlen);
03169             if (!buf)
03170               fatal("cannot allocate memory in OSF_SYS_old_getsockname");
03171           }
03172         else
03173           buf = NULL;
03174         
03175         /* result */regs->regs_R[MD_REG_V0] =
03176           getsockname(/* sock */(int)regs->regs_R[MD_REG_A0],
03177                       /* name */(struct sockaddr *)buf,
03178                       /* namelen */&addrlen);
03179 
03180         /* check for an error condition */
03181         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03182           regs->regs_R[MD_REG_A3] = 0;
03183         else /* got an error, return details */
03184           {
03185             regs->regs_R[MD_REG_A3] = -1;
03186             regs->regs_R[MD_REG_V0] = errno;
03187           }
03188 
03189         /* copy results to simulator memory */
03190         if (addrlen != 0)
03191           mem_bcopy(mem_fn, mem, Write,
03192                     /* addr */regs->regs_R[MD_REG_A1],
03193                     buf, addrlen);
03194         osf_addrlen = (qword_t)addrlen;
03195         mem_bcopy(mem_fn, mem, Write,
03196                   /* paddrlen */regs->regs_R[MD_REG_A2],
03197                   &osf_addrlen, sizeof(osf_addrlen));
03198 
03199         if (buf != NULL)
03200           free(buf);
03201       }
03202       break;
03203 #endif
03204 
03205 #if !defined(MIN_SYSCALL_MODE)
03206     case OSF_SYS_old_getpeername:
03207       {
03208         /* get socket name */
03209         char *buf;
03210         word_t osf_addrlen;
03211         int addrlen;
03212 
03213         /* get simulator memory parameters to host memory */
03214         mem_bcopy(mem_fn, mem, Read,
03215                   /* paddrlen */regs->regs_R[MD_REG_A2],
03216                   &osf_addrlen, sizeof(osf_addrlen));
03217         addrlen = (int)osf_addrlen;
03218         if (addrlen != 0)
03219           {
03220             buf = calloc(1, addrlen);
03221             if (!buf)
03222               fatal("cannot allocate memory in OSF_SYS_old_getsockname");
03223           }
03224         else
03225           buf = NULL;
03226         
03227         /* result */regs->regs_R[MD_REG_V0] =
03228           getpeername(/* sock */(int)regs->regs_R[MD_REG_A0],
03229                       /* name */(struct sockaddr *)buf,
03230                       /* namelen */&addrlen);
03231 
03232         /* check for an error condition */
03233         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03234           regs->regs_R[MD_REG_A3] = 0;
03235         else /* got an error, return details */
03236           {
03237             regs->regs_R[MD_REG_A3] = -1;
03238             regs->regs_R[MD_REG_V0] = errno;
03239           }
03240 
03241         /* copy results to simulator memory */
03242         if (addrlen != 0)
03243           mem_bcopy(mem_fn, mem, Write,
03244                     /* addr */regs->regs_R[MD_REG_A1],
03245                     buf, addrlen);
03246         osf_addrlen = (qword_t)addrlen;
03247         mem_bcopy(mem_fn, mem, Write,
03248                   /* paddrlen */regs->regs_R[MD_REG_A2],
03249                   &osf_addrlen, sizeof(osf_addrlen));
03250 
03251         if (buf != NULL)
03252           free(buf);
03253       }
03254       break;
03255 #endif
03256 
03257 #if !defined(MIN_SYSCALL_MODE)
03258     case OSF_SYS_setgid:
03259       /* set group ID */
03260 
03261       /*result*/regs->regs_R[MD_REG_V0] =
03262         setgid(/* gid */(gid_t)regs->regs_R[MD_REG_A0]);
03263 
03264       /* check for an error condition */
03265       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03266         regs->regs_R[MD_REG_A3] = 0;
03267       else /* got an error, return details */
03268         {
03269           regs->regs_R[MD_REG_A3] = -1;
03270           regs->regs_R[MD_REG_V0] = errno;
03271         }
03272       break;
03273 #endif
03274 
03275 #if !defined(MIN_SYSCALL_MODE)
03276     case OSF_SYS_setuid:
03277       /* set user ID */
03278 
03279       /*result*/regs->regs_R[MD_REG_V0] =
03280         setuid(/* uid */(uid_t)regs->regs_R[MD_REG_A0]);
03281 
03282       /* check for an error condition */
03283       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03284         regs->regs_R[MD_REG_A3] = 0;
03285       else /* got an error, return details */
03286         {
03287           regs->regs_R[MD_REG_A3] = -1;
03288           regs->regs_R[MD_REG_V0] = errno;
03289         }
03290       break;
03291 #endif
03292 
03293 #if !defined(MIN_SYSCALL_MODE)
03294     case OSF_SYS_getpriority:
03295       /* get program scheduling priority */
03296 
03297       /*result*/regs->regs_R[MD_REG_V0] =
03298         getpriority(/* which */(int)regs->regs_R[MD_REG_A0],
03299                     /* who */(int)regs->regs_R[MD_REG_A1]);
03300 
03301       /* check for an error condition */
03302       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03303         regs->regs_R[MD_REG_A3] = 0;
03304       else /* got an error, return details */
03305         {
03306           regs->regs_R[MD_REG_A3] = -1;
03307           regs->regs_R[MD_REG_V0] = errno;
03308         }
03309       break;
03310 #endif
03311 
03312 #if !defined(MIN_SYSCALL_MODE)
03313     case OSF_SYS_setpriority:
03314       /* set program scheduling priority */
03315 
03316       /*result*/regs->regs_R[MD_REG_V0] =
03317         setpriority(/* which */(int)regs->regs_R[MD_REG_A0],
03318                     /* who */(int)regs->regs_R[MD_REG_A1],
03319                     /* prio */(int)regs->regs_R[MD_REG_A2]);
03320 
03321       /* check for an error condition */
03322       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03323         regs->regs_R[MD_REG_A3] = 0;
03324       else /* got an error, return details */
03325         {
03326           regs->regs_R[MD_REG_A3] = -1;
03327           regs->regs_R[MD_REG_V0] = errno;
03328         }
03329       break;
03330 #endif
03331 
03332 #if !defined(MIN_SYSCALL_MODE)
03333     case OSF_SYS_select:
03334       {
03335         fd_set readfd, writefd, exceptfd;
03336         fd_set *readfdp, *writefdp, *exceptfdp;
03337         struct timeval timeout, *timeoutp;
03338 
03339         /* copy read file descriptor set into host memory */
03340         if (/* readfds */regs->regs_R[MD_REG_A1] != 0)
03341           {
03342             mem_bcopy(mem_fn, mem, Read,
03343                       /* readfds */regs->regs_R[MD_REG_A1],
03344                       &readfd, sizeof(fd_set));
03345             readfdp = &readfd;
03346           }
03347         else
03348           readfdp = NULL;
03349 
03350         /* copy write file descriptor set into host memory */
03351         if (/* writefds */regs->regs_R[MD_REG_A2] != 0)
03352           {
03353             mem_bcopy(mem_fn, mem, Read,
03354                       /* writefds */regs->regs_R[MD_REG_A2],
03355                       &writefd, sizeof(fd_set));
03356             writefdp = &writefd;
03357           }
03358         else
03359           writefdp = NULL;
03360 
03361         /* copy exception file descriptor set into host memory */
03362         if (/* exceptfds */regs->regs_R[MD_REG_A3] != 0)
03363           {
03364             mem_bcopy(mem_fn, mem, Read,
03365                       /* exceptfds */regs->regs_R[MD_REG_A3],
03366                       &exceptfd, sizeof(fd_set));
03367             exceptfdp = &exceptfd;
03368           }
03369         else
03370           exceptfdp = NULL;
03371 
03372         /* copy timeout value into host memory */
03373         if (/* timeout */regs->regs_R[MD_REG_A4] != 0)
03374           {
03375             mem_bcopy(mem_fn, mem, Read,
03376                       /* timeout */regs->regs_R[MD_REG_A4],
03377                       &timeout, sizeof(struct timeval));
03378             timeoutp = &timeout;
03379           }
03380         else
03381           timeoutp = NULL;
03382 
03383 #if defined(hpux) || defined(__hpux)
03384         /* select() on the specified file descriptors */
03385         /* result */regs->regs_R[MD_REG_V0] =
03386           select(/* nfds */regs->regs_R[MD_REG_A0],
03387                  (int *)readfdp, (int *)writefdp, (int *)exceptfdp, timeoutp);
03388 #else
03389         /* select() on the specified file descriptors */
03390         /* result */regs->regs_R[MD_REG_V0] =
03391           select(/* nfds */regs->regs_R[MD_REG_A0],
03392                  readfdp, writefdp, exceptfdp, timeoutp);
03393 #endif
03394 
03395         /* check for an error condition */
03396         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03397           regs->regs_R[MD_REG_A3] = 0;
03398         else /* got an error, return details */
03399           {
03400             regs->regs_R[MD_REG_A3] = -1;
03401             regs->regs_R[MD_REG_V0] = errno;
03402           }
03403 
03404         /* copy read file descriptor set to target memory */
03405         if (/* readfds */regs->regs_R[MD_REG_A1] != 0)
03406           mem_bcopy(mem_fn, mem, Write,
03407                     /* readfds */regs->regs_R[MD_REG_A1],
03408                     &readfd, sizeof(fd_set));
03409 
03410         /* copy write file descriptor set to target memory */
03411         if (/* writefds */regs->regs_R[MD_REG_A2] != 0)
03412           mem_bcopy(mem_fn, mem, Write,
03413                     /* writefds */regs->regs_R[MD_REG_A2],
03414                     &writefd, sizeof(fd_set));
03415 
03416         /* copy exception file descriptor set to target memory */
03417         if (/* exceptfds */regs->regs_R[MD_REG_A3] != 0)
03418           mem_bcopy(mem_fn, mem, Write,
03419                     /* exceptfds */regs->regs_R[MD_REG_A3],
03420                     &exceptfd, sizeof(fd_set));
03421 
03422         /* copy timeout value result to target memory */
03423         if (/* timeout */regs->regs_R[MD_REG_A4] != 0)
03424           mem_bcopy(mem_fn, mem, Write,
03425                     /* timeout */regs->regs_R[MD_REG_A4],
03426                     &timeout, sizeof(struct timeval));
03427       }
03428       break;
03429 #endif
03430 
03431 #if !defined(MIN_SYSCALL_MODE)
03432     case OSF_SYS_shutdown:
03433       /* shuts down socket send and receive operations */
03434 
03435       /*result*/regs->regs_R[MD_REG_V0] =
03436         shutdown(/* sock */(int)regs->regs_R[MD_REG_A0],
03437                  /* how */(int)regs->regs_R[MD_REG_A1]);
03438 
03439       /* check for an error condition */
03440       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03441         regs->regs_R[MD_REG_A3] = 0;
03442       else /* got an error, return details */
03443         {
03444           regs->regs_R[MD_REG_A3] = -1;
03445           regs->regs_R[MD_REG_V0] = errno;
03446         }
03447       break;
03448 #endif
03449 
03450 #if !defined(MIN_SYSCALL_MODE)
03451     case OSF_SYS_poll:
03452       {
03453         int i;
03454         struct pollfd *fds;
03455 
03456         /* allocate host side I/O vectors */
03457         fds = calloc(/* nfds */regs->regs_R[MD_REG_A1], sizeof(struct pollfd));
03458         if (!fds)
03459           fatal("out of virtual memory in SYS_poll");
03460 
03461         /* copy target side I/O vector buffers to host memory */
03462         for (i=0; i < /* nfds */regs->regs_R[MD_REG_A1]; i++)
03463           {
03464             /* copy target side pointer data into host side vector */
03465             mem_bcopy(mem_fn, mem, Read,
03466                       (/* fds */regs->regs_R[MD_REG_A0]
03467                        + i*sizeof(struct pollfd)),
03468                       &fds[i], sizeof(struct pollfd));
03469           }
03470 
03471         /* perform the vector'ed write */
03472         /* result */regs->regs_R[MD_REG_V0] =
03473           poll(/* fds */fds,
03474                /* nfds */(unsigned long)regs->regs_R[MD_REG_A1],
03475                /* timeout */(int)regs->regs_R[MD_REG_A2]);
03476 
03477         /* check for an error condition */
03478         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03479           regs->regs_R[MD_REG_A3] = 0;
03480         else /* got an error, return details */
03481           {
03482             regs->regs_R[MD_REG_A3] = -1;
03483             regs->regs_R[MD_REG_V0] = errno;
03484           }
03485 
03486         /* copy target side I/O vector buffers to host memory */
03487         for (i=0; i < /* nfds */regs->regs_R[MD_REG_A1]; i++)
03488           {
03489             /* copy target side pointer data into host side vector */
03490             mem_bcopy(mem_fn, mem, Write,
03491                       (/* fds */regs->regs_R[MD_REG_A0]
03492                        + i*sizeof(struct pollfd)),
03493                       &fds[i], sizeof(struct pollfd));
03494           }
03495 
03496         /* free all the allocated memory */
03497         free(fds);
03498       }
03499       break;
03500 #endif
03501 
03502     case OSF_SYS_usleep_thread:
03503 #if 0
03504       fprintf(stderr, "usleep(%d)\n", (unsigned int)regs->regs_R[MD_REG_A0]);
03505 #endif
03506 #ifdef alpha
03507       regs->regs_R[MD_REG_V0] = usleep((unsigned int)regs->regs_R[MD_REG_A0]);
03508 #else
03509       usleep((unsigned int)regs->regs_R[MD_REG_A0]);
03510       regs->regs_R[MD_REG_V0] = 0;
03511 #endif
03512       /* check for an error condition */
03513       if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03514         regs->regs_R[MD_REG_A3] = 0;
03515       else /* got an error, return details */
03516         {
03517           regs->regs_R[MD_REG_A3] = -1;
03518           regs->regs_R[MD_REG_V0] = errno;
03519         }
03520 #if 0
03521       warn("unsupported usleep_thread() call...");
03522       regs->regs_R[MD_REG_V0] = 0; 
03523 #endif
03524       break;
03525       
03526 #if !defined(MIN_SYSCALL_MODE)
03527     case OSF_SYS_gethostname:
03528       /* get program scheduling priority */
03529       {
03530         char *buf;
03531 
03532         buf = malloc(/* len */(size_t)regs->regs_R[MD_REG_A1]);
03533         if (!buf)
03534           fatal("out of virtual memory in gethostname()");
03535 
03536         /* result */regs->regs_R[MD_REG_V0] =
03537           gethostname(/* name */buf,
03538                       /* len */(size_t)regs->regs_R[MD_REG_A1]);
03539 
03540         /* check for an error condition */
03541         if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
03542           regs->regs_R[MD_REG_A3] = 0;
03543         else /* got an error, return details */
03544           {
03545             regs->regs_R[MD_REG_A3] = -1;
03546             regs->regs_R[MD_REG_V0] = errno;
03547           }
03548 
03549         /* copy string back to simulated memory */
03550         mem_bcopy(mem_fn, mem, Write,
03551                   /* name */regs->regs_R[MD_REG_A0],
03552                   buf, /* len */regs->regs_R[MD_REG_A1]);
03553       }
03554       break;
03555 #endif
03556 
03557     case OSF_SYS_madvise:
03558       warn("unsupported madvise() call ignored...");
03559       regs->regs_R[MD_REG_V0] = 0;
03560       break;
03561 
03562     default:
03563       warn("invalid/unimplemented syscall %ld, PC=0x%08p, RA=0x%08p, winging it",
03564            syscode, regs->regs_PC, regs->regs_R[MD_REG_RA]);
03565       regs->regs_R[MD_REG_A3] = -1;
03566       regs->regs_R[MD_REG_V0] = 0;
03567 #if 0
03568       fatal("invalid/unimplemented system call encountered, code %d", syscode);
03569 #endif
03570     }
03571 
03572   if (verbose)
03573     fprintf(stderr, "syscall(%d): returned %d:%d...\n",
03574             (int)syscode, (int)regs->regs_R[MD_REG_A3],
03575             (int)regs->regs_R[MD_REG_V0]);
03576 }



UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214