"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.c

Go to the documentation of this file.
00001 /*
00002  * syscall.c - proxy system call handler routines
00003  *
00004  * This file is a part of the SimpleScalar tool suite written by
00005  * Todd M. Austin as a part of the Multiscalar Research Project.
00006  *  
00007  * The tool suite is currently maintained by Doug Burger and Todd M. Austin.
00008  * 
00009  * Copyright (C) 1994, 1995, 1996, 1997 by Todd M. Austin
00010  *
00011  * This source file is distributed "as is" in the hope that it will be
00012  * useful.  The tool set comes with no warranty, and no author or
00013  * distributor accepts any responsibility for the consequences of its
00014  * use. 
00015  * 
00016  * Everyone is granted permission to copy, modify and redistribute
00017  * this tool set under the following conditions:
00018  * 
00019  *    This source code is distributed for non-commercial use only. 
00020  *    Please contact the maintainer for restrictions applying to 
00021  *    commercial use.
00022  *
00023  *    Permission is granted to anyone to make or distribute copies
00024  *    of this source code, either as received or modified, in any
00025  *    medium, provided that all copyright notices, permission and
00026  *    nonwarranty notices are preserved, and that the distributor
00027  *    grants the recipient permission for further redistribution as
00028  *    permitted by this document.
00029  *
00030  *    Permission is granted to distribute this file in compiled
00031  *    or executable form under the same conditions that apply for
00032  *    source code, provided that either:
00033  *
00034  *    A. it is accompanied by the corresponding machine-readable
00035  *       source code,
00036  *    B. it is accompanied by a written offer, with no time limit,
00037  *       to give anyone a machine-readable copy of the corresponding
00038  *       source code in return for reimbursement of the cost of
00039  *       distribution.  This written offer must permit verbatim
00040  *       duplication by anyone, or
00041  *    C. it is distributed by someone who received only the
00042  *       executable form, and is accompanied by a copy of the
00043  *       written offer of source code that they received concurrently.
00044  *
00045  * In other words, you are welcome to use, share and improve this
00046  * source file.  You are forbidden to forbid anyone else to use, share
00047  * and improve what you give them.
00048  *
00049  * INTERNET: dburger@cs.wisc.edu
00050  * US Mail:  1210 W. Dayton Street, Madison, WI 53706
00051  *
00052  * $Id: syscall.c,v 1.1.1.1 2000/05/26 15:22:27 taustin Exp $
00053  *
00054  * $Log: syscall.c,v $
00055  * Revision 1.1.1.1  2000/05/26 15:22:27  taustin
00056  * SimpleScalar Tool Set
00057  *
00058  *
00059  * Revision 1.6  1999/12/31 19:00:40  taustin
00060  * quad_t naming conflicts removed
00061  * cross-endian execution support added (w/ limited syscall support)
00062  * extensive extensions to the Alpha OSF system call model
00063  *
00064  * Revision 1.5  1999/12/13 18:59:54  taustin
00065  * cross endian execution support added
00066  *
00067  * Revision 1.4  1999/03/08 06:40:09  taustin
00068  * added SVR4 host support
00069  *
00070  * Revision 1.3  1998/09/03 22:20:59  taustin
00071  * iov_len field in osf_iov fixed (was qword_t changed to word_t)
00072  * added portable padding to osf_iov type definition
00073  * fixed sigprocmask implementation (from Klauser)
00074  * usleep_thread() implementation added
00075  *
00076  * Revision 1.2  1998/08/31 17:19:44  taustin
00077  * ported to MS VC++
00078  * added FIONREAD ioctl() support
00079  * added support for socket(), select(), writev(), readv(), setregid()
00080  *     setreuid(), connect(), setsockopt(), getsockname(), getpeername(),
00081  *     setgid(), setuid(), getpriority(), setpriority(), shutdown(), poll()
00082  * change invalid system call from panic() to fatal()
00083  *
00084  * Revision 1.1  1998/08/27 16:54:53  taustin
00085  * Initial revision
00086  *
00087  * Revision 1.1  1998/05/06  01:08:39  calder
00088  * Initial revision
00089  *
00090  * Revision 1.5  1997/04/16  22:12:17  taustin
00091  * added Ultrix host support
00092  *
00093  * Revision 1.4  1997/03/11  01:37:37  taustin
00094  * updated copyright
00095  * long/int tweaks made for ALPHA target support
00096  * syscall structures are now more portable across platforms
00097  * various target supports added
00098  *
00099  * Revision 1.3  1996/12/27  15:56:09  taustin
00100  * updated comments
00101  * removed system prototypes
00102  *
00103  * Revision 1.1  1996/12/05  18:52:32  taustin
00104  * Initial revision
00105  *
00106  *
00107  */
00108 
00109 #include <stdio.h>
00110 #include <stdlib.h>
00111 
00112 /* only enable a minimal set of systen call proxies if on limited
00113    hosts or if in cross endian live execution mode */
00114 #ifndef MIN_SYSCALL_MODE
00115 #if defined(_MSC_VER) || defined(__CYGWIN32__) || defined(MD_CROSS_ENDIAN)
00116 #define MIN_SYSCALL_MODE
00117 #endif
00118 #endif /* !MIN_SYSCALL_MODE */
00119 
00120 /* live execution only support on same-endian hosts... */
00121 #ifdef _MSC_VER
00122 #include <io.h>
00123 #else /* !_MSC_VER */
00124 #include <unistd.h>
00125 #endif
00126 #include <fcntl.h>
00127 #include <sys/types.h>
00128 #ifndef _MSC_VER
00129 #include <sys/param.h>
00130 #endif
00131 #include <errno.h>
00132 #include <time.h>
00133 #ifndef _MSC_VER
00134 #include <sys/time.h>
00135 #endif
00136 #ifndef _MSC_VER
00137 #include <sys/resource.h>
00138 #endif
00139 #include <signal.h>
00140 #ifndef _MSC_VER
00141 #include <sys/file.h>
00142 #endif
00143 #include <sys/stat.h>
00144 #ifndef _MSC_VER
00145 #include <sys/uio.h>
00146 #endif
00147 #include <setjmp.h>
00148 #ifndef _MSC_VER
00149 #include <sys/times.h>
00150 #endif
00151 #include <limits.h>
00152 #ifndef _MSC_VER
00153 #include <sys/ioctl.h>
00154 #endif
00155 #if defined(linux)
00156 #include <utime.h>
00157 #include <dirent.h>
00158 #include <sys/vfs.h>
00159 #endif
00160 #if defined(_AIX)
00161 #include <sys/statfs.h>
00162 #else /* !_AIX */
00163 #ifndef _MSC_VER
00164 #include <sys/mount.h>
00165 #endif
00166 #endif /* !_AIX */
00167 #if !defined(linux) && !defined(sparc) && !defined(hpux) && !defined(__hpux) && !defined(__CYGWIN32__) && !defined(ultrix)
00168 #ifndef _MSC_VER
00169 #include <sys/select.h>
00170 #endif
00171 #endif
00172 #ifdef linux
00173 #include <sgtty.h>
00174 #include <netinet/tcp.h>
00175 #include <netinet/udp.h>
00176 #include <netinet/in.h>
00177 #endif /* linux */
00178 
00179 #if defined(__svr4__)
00180 #include <sys/dirent.h>
00181 #include <sys/filio.h>
00182 #elif defined(__osf__)
00183 #include <dirent.h>
00184 /* -- For some weird reason, getdirentries() is not declared in any
00185  * -- header file under /usr/include on the Alpha boxen that I tried
00186  * -- SS-Alpha on. But the function exists in the libraries.
00187  */
00188 int getdirentries(int fd, char *buf, int nbytes, long *basep);
00189 #endif
00190 
00191 #if defined(__svr4__) || defined(__osf__)
00192 #include <sys/statvfs.h>
00193 #define statfs statvfs
00194 #include <sys/time.h>
00195 #include <utime.h>
00196 #include <sgtty.h>
00197 #include <netinet/in.h>
00198 #include <netinet/tcp.h>
00199 #endif
00200 
00201 #if defined(sparc) && defined(__unix__)
00202 #if defined(__svr4__) || defined(__USLC__)
00203 #include <dirent.h>
00204 #else
00205 #include <sys/dir.h>
00206 #endif
00207 
00208 /* dorks */
00209 #undef NL0
00210 #undef NL1
00211 #undef CR0
00212 #undef CR1
00213 #undef CR2
00214 #undef CR3
00215 #undef TAB0
00216 #undef TAB1
00217 #undef TAB2
00218 #undef XTABS
00219 #undef BS0
00220 #undef BS1
00221 #undef FF0
00222 #undef FF1
00223 #undef ECHO
00224 #undef NOFLSH
00225 #undef TOSTOP
00226 #undef FLUSHO
00227 #undef PENDIN
00228 #endif
00229 
00230 #if defined(hpux) || defined(__hpux)
00231 #undef CR0
00232 #endif
00233 
00234 #ifdef __FreeBSD__
00235 #include <sys/ioctl_compat.h>
00236 #else
00237 #ifndef _MSC_VER
00238 #include <termio.h>
00239 #endif
00240 #endif
00241 
00242 #if defined(hpux) || defined(__hpux)
00243 /* et tu, dorks! */
00244 #undef HUPCL
00245 #undef ECHO
00246 #undef B50
00247 #undef B75
00248 #undef B110
00249 #undef B134
00250 #undef B150
00251 #undef B200
00252 #undef B300
00253 #undef B600
00254 #undef B1200
00255 #undef B1800
00256 #undef B2400
00257 #undef B4800
00258 #undef B9600
00259 #undef B19200
00260 #undef B38400
00261 #undef NL0
00262 #undef NL1
00263 #undef CR0
00264 #undef CR1
00265 #undef CR2
00266 #undef CR3
00267 #undef TAB0
00268 #undef TAB1
00269 #undef BS0
00270 #undef BS1
00271 #undef FF0
00272 #undef FF1
00273 #undef EXTA
00274 #undef EXTB
00275 #undef B900
00276 #undef B3600
00277 #undef B7200
00278 #undef XTABS
00279 #include <sgtty.h>
00280 #include <utime.h>
00281 #endif
00282 
00283 #ifdef __CYGWIN32__
00284 #include <sys/unistd.h>
00285 #include <sys/vfs.h>
00286 #endif
00287 
00288 #include <sys/socket.h>
00289 #include <sys/poll.h>
00290 
00291 #ifdef _MSC_VER
00292 #define access          _access
00293 #define chmod           _chmod
00294 #define chdir           _chdir
00295 #define unlink          _unlink
00296 #define open            _open
00297 #define creat           _creat
00298 #define pipe            _pipe
00299 #define dup             _dup
00300 #define dup2            _dup2
00301 #define stat            _stat
00302 #define fstat           _fstat
00303 #define lseek           _lseek
00304 #define read            _read
00305 #define write           _write
00306 #define close           _close
00307 #define getpid          _getpid
00308 #define utime           _utime
00309 #include <sys/utime.h>
00310 #endif /* _MSC_VER */
00311 
00312 #include "host.h"
00313 #include "misc.h"
00314 #include "machine.h"
00315 #include "regs.h"
00316 #include "memory.h"
00317 #include "loader.h"
00318 #include "sim.h"
00319 #include "endian.h"
00320 #include "eio.h"
00321 #include "syscall.h"
00322 
00323 #define OSF_SYS_syscall     0
00324 /* OSF_SYS_exit moved to alpha.h */
00325 #define OSF_SYS_fork        2
00326 #define OSF_SYS_read        3
00327 /* OSF_SYS_write moved to alpha.h */
00328 #define OSF_SYS_old_open    5       /* 5 is old open */
00329 #define OSF_SYS_close       6
00330 #define OSF_SYS_wait4       7
00331 #define OSF_SYS_old_creat   8       /* 8 is old creat */
00332 #define OSF_SYS_link        9
00333 #define OSF_SYS_unlink      10
00334 #define OSF_SYS_execv       11
00335 #define OSF_SYS_chdir       12
00336 #define OSF_SYS_fchdir      13
00337 #define OSF_SYS_mknod       14
00338 #define OSF_SYS_chmod       15
00339 #define OSF_SYS_chown       16
00340 #define OSF_SYS_obreak      17
00341 #define OSF_SYS_getfsstat   18
00342 #define OSF_SYS_lseek       19
00343 #define OSF_SYS_getpid      20
00344 #define OSF_SYS_mount       21
00345 #define OSF_SYS_unmount     22
00346 #define OSF_SYS_setuid      23
00347 #define OSF_SYS_getuid      24
00348 #define OSF_SYS_exec_with_loader    25
00349 #define OSF_SYS_ptrace      26
00350 #ifdef  COMPAT_43
00351 #define OSF_SYS_nrecvmsg    27
00352 #define OSF_SYS_nsendmsg    28
00353 #define OSF_SYS_nrecvfrom   29
00354 #define OSF_SYS_naccept     30
00355 #define OSF_SYS_ngetpeername        31
00356 #define OSF_SYS_ngetsockname        32
00357 #else
00358 #define OSF_SYS_recvmsg     27
00359 #define OSF_SYS_sendmsg     28
00360 #define OSF_SYS_recvfrom    29
00361 #define OSF_SYS_accept      30
00362 #define OSF_SYS_getpeername 31
00363 #define OSF_SYS_getsockname 32
00364 #endif
00365 #define OSF_SYS_access      33
00366 #define OSF_SYS_chflags     34
00367 #define OSF_SYS_fchflags    35
00368 #define OSF_SYS_sync        36
00369 #define OSF_SYS_kill        37
00370 #define OSF_SYS_old_stat    38      /* 38 is old stat */
00371 #define OSF_SYS_setpgid     39
00372 #define OSF_SYS_old_lstat   40      /* 40 is old lstat */
00373 #define OSF_SYS_dup 41
00374 #define OSF_SYS_pipe        42
00375 #define OSF_SYS_set_program_attributes      43
00376 #define OSF_SYS_profil      44
00377 #define OSF_SYS_open        45
00378                                 /* 46 is obsolete osigaction */
00379 #define OSF_SYS_getgid      47
00380 #define OSF_SYS_sigprocmask 48
00381 #define OSF_SYS_getlogin    49
00382 #define OSF_SYS_setlogin    50
00383 #define OSF_SYS_acct        51
00384 #define OSF_SYS_sigpending  52
00385 #define OSF_SYS_ioctl       54
00386 #define OSF_SYS_reboot      55
00387 #define OSF_SYS_revoke      56
00388 #define OSF_SYS_symlink     57
00389 #define OSF_SYS_readlink    58
00390 #define OSF_SYS_execve      59
00391 #define OSF_SYS_umask       60
00392 #define OSF_SYS_chroot      61
00393 #define OSF_SYS_old_fstat   62      /* 62 is old fstat */
00394 #define OSF_SYS_getpgrp     63
00395 #define OSF_SYS_getpagesize 64
00396 #define OSF_SYS_mremap      65
00397 #define OSF_SYS_vfork       66
00398 #define OSF_SYS_stat        67
00399 #define OSF_SYS_lstat       68
00400 #define OSF_SYS_sbrk        69
00401 #define OSF_SYS_sstk        70
00402 #define OSF_SYS_mmap        71
00403 #define OSF_SYS_ovadvise    72
00404 #define OSF_SYS_munmap      73
00405 #define OSF_SYS_mprotect    74
00406 #define OSF_SYS_madvise     75
00407 #define OSF_SYS_old_vhangup 76      /* 76 is old vhangup */
00408 #define OSF_SYS_kmodcall    77
00409 #define OSF_SYS_mincore     78
00410 #define OSF_SYS_getgroups   79
00411 #define OSF_SYS_setgroups   80
00412 #define OSF_SYS_old_getpgrp 81      /* 81 is old getpgrp */
00413 #define OSF_SYS_setpgrp     82
00414 #define OSF_SYS_setitimer   83
00415 #define OSF_SYS_old_wait    84      /* 84 is old wait */
00416 #define OSF_SYS_table       85
00417 #define OSF_SYS_getitimer   86
00418 #define OSF_SYS_gethostname 87
00419 #define OSF_SYS_sethostname 88
00420 #define OSF_SYS_getdtablesize       89
00421 #define OSF_SYS_dup2        90
00422 #define OSF_SYS_fstat       91
00423 #define OSF_SYS_fcntl       92
00424 #define OSF_SYS_select      93
00425 #define OSF_SYS_poll        94
00426 #define OSF_SYS_fsync       95
00427 #define OSF_SYS_setpriority 96
00428 #define OSF_SYS_socket      97
00429 #define OSF_SYS_connect     98
00430 #ifdef  COMPAT_43
00431 #define OSF_SYS_accept      99
00432 #else
00433 #define OSF_SYS_old_accept  99      /* 99 is old accept */
00434 #endif
00435 #define OSF_SYS_getpriority 100
00436 #ifdef  COMPAT_43
00437 #define OSF_SYS_send        101
00438 #define OSF_SYS_recv        102
00439 #else
00440 #define OSF_SYS_old_send    101     /* 101 is old send */
00441 #define OSF_SYS_old_recv    102     /* 102 is old recv */
00442 #endif
00443 #define OSF_SYS_sigreturn   103
00444 #define OSF_SYS_bind        104
00445 #define OSF_SYS_setsockopt  105
00446 #define OSF_SYS_listen      106
00447 #define OSF_SYS_plock       107
00448 #define OSF_SYS_old_sigvec  108     /* 108 is old sigvec */
00449 #define OSF_SYS_old_sigblock        109     /* 109 is old sigblock */
00450 #define OSF_SYS_old_sigsetmask      110     /* 110 is old sigsetmask */
00451 #define OSF_SYS_sigsuspend  111
00452 #define OSF_SYS_sigstack    112
00453 #ifdef  COMPAT_43
00454 #define OSF_SYS_recvmsg     113
00455 #define OSF_SYS_sendmsg     114
00456 #else
00457 #define OSF_SYS_old_recvmsg 113     /* 113 is old recvmsg */
00458 #define OSF_SYS_old_sendmsg 114     /* 114 is old sendmsg */
00459 #endif
00460                                 /* 115 is obsolete vtrace */
00461 #define OSF_SYS_gettimeofday        116
00462 #define OSF_SYS_getrusage   117
00463 #define OSF_SYS_getsockopt  118
00464 #define OSF_SYS_readv       120
00465 #define OSF_SYS_writev      121
00466 #define OSF_SYS_settimeofday        122
00467 #define OSF_SYS_fchown      123
00468 #define OSF_SYS_fchmod      124
00469 #ifdef  COMPAT_43
00470 #define OSF_SYS_recvfrom    125
00471 #else
00472 #define OSF_SYS_old_recvfrom        125     /* 125 is old recvfrom */
00473 #endif
00474 #define OSF_SYS_setreuid    126
00475 #define OSF_SYS_setregid    127
00476 #define OSF_SYS_rename      128
00477 #define OSF_SYS_truncate    129
00478 #define OSF_SYS_ftruncate   130
00479 #define OSF_SYS_flock       131
00480 #define OSF_SYS_setgid      132
00481 #define OSF_SYS_sendto      133
00482 #define OSF_SYS_shutdown    134
00483 #define OSF_SYS_socketpair  135
00484 #define OSF_SYS_mkdir       136
00485 #define OSF_SYS_rmdir       137
00486 #define OSF_SYS_utimes      138
00487                                 /* 139 is obsolete 4.2 sigreturn */
00488 #define OSF_SYS_adjtime     140
00489 #ifdef  COMPAT_43
00490 #define OSF_SYS_getpeername 141
00491 #else
00492 #define OSF_SYS_old_getpeername     141     /* 141 is old getpeername */
00493 #endif
00494 #define OSF_SYS_gethostid   142
00495 #define OSF_SYS_sethostid   143
00496 #define OSF_SYS_getrlimit   144
00497 #define OSF_SYS_setrlimit   145
00498 #define OSF_SYS_old_killpg  146     /* 146 is old killpg */
00499 #define OSF_SYS_setsid      147
00500 #define OSF_SYS_quotactl    148
00501 #define OSF_SYS_oldquota    149
00502 #ifdef  COMPAT_43
00503 #define OSF_SYS_getsockname 150
00504 #else
00505 #define OSF_SYS_old_getsockname     150     /* 150 is old getsockname */
00506 #endif
00507 #define OSF_SYS_pid_block   153
00508 #define OSF_SYS_pid_unblock 154
00509 #define OSF_SYS_sigaction   156
00510 #define OSF_SYS_sigwaitprim 157
00511 #define OSF_SYS_nfssvc      158
00512 #define OSF_SYS_getdirentries       159
00513 #define OSF_SYS_statfs      160
00514 #define OSF_SYS_fstatfs     161
00515 #define OSF_SYS_async_daemon        163
00516 #define OSF_SYS_getfh       164
00517 #define OSF_SYS_getdomainname       165
00518 #define OSF_SYS_setdomainname       166
00519 #define OSF_SYS_exportfs    169
00520 #define OSF_SYS_alt_plock   181     /* 181 is alternate plock */
00521 #define OSF_SYS_getmnt      184
00522 #define OSF_SYS_alt_sigpending      187     /* 187 is alternate sigpending */
00523 #define OSF_SYS_alt_setsid  188     /* 188 is alternate setsid */
00524 #define OSF_SYS_swapon      199
00525 #define OSF_SYS_msgctl      200
00526 #define OSF_SYS_msgget      201
00527 #define OSF_SYS_msgrcv      202
00528 #define OSF_SYS_msgsnd      203
00529 #define OSF_SYS_semctl      204
00530 #define OSF_SYS_semget      205
00531 #define OSF_SYS_semop       206
00532 #define OSF_SYS_uname       207
00533 #define OSF_SYS_lchown      208
00534 #define OSF_SYS_shmat       209
00535 #define OSF_SYS_shmctl      210
00536 #define OSF_SYS_shmdt       211
00537 #define OSF_SYS_shmget      212
00538 #define OSF_SYS_mvalid      213
00539 #define OSF_SYS_getaddressconf      214
00540 #define OSF_SYS_msleep      215
00541 #define OSF_SYS_mwakeup     216
00542 #define OSF_SYS_msync       217
00543 #define OSF_SYS_signal      218
00544 #define OSF_SYS_utc_gettime 219
00545 #define OSF_SYS_utc_adjtime 220
00546 #define OSF_SYS_security    222
00547 #define OSF_SYS_kloadcall   223
00548 #define OSF_SYS_getpgid     233
00549 #define OSF_SYS_getsid      234
00550 #define OSF_SYS_sigaltstack 235
00551 #define OSF_SYS_waitid      236
00552 #define OSF_SYS_priocntlset 237
00553 #define OSF_SYS_sigsendset  238
00554 #define OSF_SYS_set_speculative     239
00555 #define OSF_SYS_msfs_syscall        240
00556 #define OSF_SYS_sysinfo     241
00557 #define OSF_SYS_uadmin      242
00558 #define OSF_SYS_fuser       243
00559 #define OSF_SYS_proplist_syscall    244
00560 #define OSF_SYS_ntp_adjtime 245
00561 #define OSF_SYS_ntp_gettime 246
00562 #define OSF_SYS_pathconf    247
00563 #define OSF_SYS_fpathconf   248
00564 #define OSF_SYS_uswitch     250
00565 #define OSF_SYS_usleep_thread       251
00566 #define OSF_SYS_audcntl     252
00567 #define OSF_SYS_audgen      253
00568 #define OSF_SYS_sysfs       254
00569 #define OSF_SYS_subOSF_SYS_info 255
00570 #define OSF_SYS_getsysinfo  256
00571 #define OSF_SYS_setsysinfo  257
00572 #define OSF_SYS_afs_syscall 258
00573 #define OSF_SYS_swapctl     259
00574 #define OSF_SYS_memcntl     260
00575 #define OSF_SYS_fdatasync   261
00576 
00577 /* translate system call arguments */
00578 struct xlate_table_t
00579 {
00580   int target_val;
00581   int host_val;
00582 };
00583 
00584 int
00585 xlate_arg(int target_val, struct xlate_table_t *map, int map_sz, char *name)
00586 {
00587   int i;
00588 
00589   for (i=0; i < map_sz; i++)
00590     {
00591       if (target_val == map[i].target_val)
00592         return map[i].host_val;
00593     }
00594 
00595   /* not found, issue warning and return target_val */
00596   warn("could not translate argument for `%s': %d", name, target_val);
00597   return target_val;
00598 }
00599 
00600 /* internal system call buffer size, used primarily for file name arguments,
00601    argument larger than this will be truncated */
00602 #define MAXBUFSIZE              1024
00603 
00604 /* total bytes to copy from a valid pointer argument for ioctl() calls,
00605    syscall.c does not decode ioctl() calls to determine the size of the
00606    arguments that reside in memory, instead, the ioctl() proxy simply copies
00607    NUM_IOCTL_BYTES bytes from the pointer argument to host memory */
00608 #define NUM_IOCTL_BYTES         128
00609 
00610 /* OSF ioctl() requests */
00611 #define OSF_TIOCGETP            0x40067408
00612 #define OSF_FIONREAD            0x4004667f
00613 
00614 /* target stat() buffer definition, the host stat buffer format is
00615    automagically mapped to/from this format in syscall.c */
00616 struct  osf_statbuf
00617 {
00618   word_t osf_st_dev;
00619   word_t osf_st_ino;
00620   word_t osf_st_mode;
00621   half_t osf_st_nlink;
00622   half_t pad0;                  /* to match Alpha/AXP padding... */
00623   word_t osf_st_uid;
00624   word_t osf_st_gid;
00625   word_t osf_st_rdev;
00626   word_t pad1;                  /* to match Alpha/AXP padding... */
00627   qword_t osf_st_size;
00628   word_t osf_st_atime;
00629   word_t osf_st_spare1;
00630   word_t osf_st_mtime;
00631   word_t osf_st_spare2;
00632   word_t osf_st_ctime;
00633   word_t osf_st_spare3;
00634   word_t osf_st_blksize;
00635   word_t osf_st_blocks;
00636   word_t osf_st_gennum;
00637   word_t osf_st_spare4;
00638 };
00639 
00640 struct osf_sgttyb {
00641   byte_t sg_ispeed;     /* input speed */
00642   byte_t sg_ospeed;     /* output speed */
00643   byte_t sg_erase;      /* erase character */
00644   byte_t sg_kill;       /* kill character */
00645   shalf_t sg_flags;     /* mode flags */
00646 };
00647 
00648 #define OSF_NSIG                32
00649 
00650 #define OSF_SIG_BLOCK           1
00651 #define OSF_SIG_UNBLOCK         2
00652 #define OSF_SIG_SETMASK         3
00653 
00654 struct osf_sigcontext {
00655   qword_t sc_onstack;              /* sigstack state to restore */
00656   qword_t sc_mask;                 /* signal mask to restore */
00657   qword_t sc_pc;                   /* pc at time of signal */
00658   qword_t sc_ps;                   /* psl to retore */
00659   qword_t sc_regs[32];             /* processor regs 0 to 31 */
00660   qword_t sc_ownedfp;              /* fp has been used */
00661   qword_t sc_fpregs[32];           /* fp regs 0 to 31 */
00662   qword_t sc_fpcr;                 /* floating point control register */
00663   qword_t sc_fp_control;           /* software fpcr */
00664 };
00665 
00666 struct osf_statfs {
00667   shalf_t f_type;               /* type of filesystem (see below) */
00668   shalf_t f_flags;              /* copy of mount flags */
00669   word_t f_fsize;               /* fundamental filesystem block size */
00670   word_t f_bsize;               /* optimal transfer block size */
00671   word_t f_blocks;              /* total data blocks in file system, */
00672   /* note: may not represent fs size. */
00673   word_t f_bfree;               /* free blocks in fs */
00674   word_t f_bavail;              /* free blocks avail to non-su */
00675   word_t f_files;               /* total file nodes in file system */
00676   word_t f_ffree;               /* free file nodes in fs */
00677   qword_t f_fsid;               /* file system id */
00678   word_t f_spare[9];            /* spare for later */
00679 };
00680 
00681 struct osf_timeval
00682 {
00683   sword_t osf_tv_sec;           /* seconds */
00684   sword_t osf_tv_usec;          /* microseconds */
00685 };
00686 
00687 struct osf_timezone
00688 {
00689   sword_t osf_tz_minuteswest;   /* minutes west of Greenwich */
00690   sword_t osf_tz_dsttime;       /* type of dst correction */
00691 };
00692 
00693 /* target getrusage() buffer definition, the host stat buffer format is
00694    automagically mapped to/from this format in syscall.c */
00695 struct osf_rusage
00696 {
00697   struct osf_timeval osf_ru_utime;
00698   struct osf_timeval osf_ru_stime;
00699   sword_t osf_ru_maxrss;
00700   sword_t osf_ru_ixrss;
00701   sword_t osf_ru_idrss;
00702   sword_t osf_ru_isrss;
00703   sword_t osf_ru_minflt;
00704   sword_t osf_ru_majflt;
00705   sword_t osf_ru_nswap;
00706   sword_t osf_ru_inblock;
00707   sword_t osf_ru_oublock;
00708   sword_t osf_ru_msgsnd;
00709   sword_t osf_ru_msgrcv;
00710   sword_t osf_ru_nsignals;
00711   sword_t osf_ru_nvcsw;
00712   sword_t osf_ru_nivcsw;
00713 };
00714 
00715 struct osf_rlimit
00716 {
00717   qword_t osf_rlim_cur;         /* current (soft) limit */
00718   qword_t osf_rlim_max;         /* maximum value for rlim_cur */
00719 };
00720 
00721 struct osf_sockaddr
00722 {
00723   half_t sa_family;             /* address family, AF_xxx */
00724   byte_t sa_data[24];           /* 14 bytes of protocol address */
00725 };
00726 
00727 struct osf_iovec
00728 {
00729   md_addr_t iov_base;           /* starting address */
00730   word_t iov_len;               /* length in bytes */
00731   word_t pad;
00732 };
00733 
00734 /* returns size of DIRENT structure */
00735 #define OSF_DIRENT_SZ(STR)                                              \
00736   (sizeof(word_t) + 2*sizeof(half_t) + (((strlen(STR) + 1) + 3)/4)*4)
00737   /* was: (sizeof(word_t) + 2*sizeof(half_t) + strlen(STR) + 1) */
00738 
00739 struct osf_dirent
00740 {
00741   word_t d_ino;                 /* file number of entry */
00742   half_t d_reclen;              /* length of this record */
00743   half_t d_namlen;              /* length of string in d_name */
00744   char d_name[256];             /* DUMMY NAME LENGTH */
00745                                 /* the real maximum length is */
00746                                 /* returned by pathconf() */
00747                                 /* At this time, this MUST */
00748                                 /* be 256 -- the kernel */
00749                                 /* requires it */
00750 };
00751 
00752 /* open(2) flags for Alpha/AXP OSF target, syscall.c automagically maps
00753    between these codes to/from host open(2) flags */
00754 #define OSF_O_RDONLY            0x0000
00755 #define OSF_O_WRONLY            0x0001
00756 #define OSF_O_RDWR              0x0002
00757 #define OSF_O_NONBLOCK          0x0004
00758 #define OSF_O_APPEND            0x0008
00759 #define OSF_O_CREAT             0x0200
00760 #define OSF_O_TRUNC             0x0400
00761 #define OSF_O_EXCL              0x0800
00762 #define OSF_O_NOCTTY            0x1000
00763 #define OSF_O_SYNC              0x4000
00764 
00765 /* open(2) flags translation table for SimpleScalar target */
00766 struct {
00767   int osf_flag;
00768   int local_flag;
00769 } osf_flag_table[] = {
00770   /* target flag */     /* host flag */
00771 #ifdef _MSC_VER
00772   { OSF_O_RDONLY,       _O_RDONLY },
00773   { OSF_O_WRONLY,       _O_WRONLY },
00774   { OSF_O_RDWR,         _O_RDWR },
00775   { OSF_O_APPEND,       _O_APPEND },
00776   { OSF_O_CREAT,        _O_CREAT },
00777   { OSF_O_TRUNC,        _O_TRUNC },
00778   { OSF_O_EXCL,         _O_EXCL },
00779 #ifdef _O_NONBLOCK
00780   { OSF_O_NONBLOCK,     _O_NONBLOCK },
00781 #endif
00782 #ifdef _O_NOCTTY
00783   { OSF_O_NOCTTY,       _O_NOCTTY },
00784 #endif
00785 #ifdef _O_SYNC
00786   { OSF_O_SYNC,         _O_SYNC },
00787 #endif
00788 #else /* !_MSC_VER */
00789   { OSF_O_RDONLY,       O_RDONLY },
00790   { OSF_O_WRONLY,       O_WRONLY },
00791   { OSF_O_RDWR,         O_RDWR },
00792   { OSF_O_APPEND,       O_APPEND },
00793   { OSF_O_CREAT,        O_CREAT },
00794   { OSF_O_TRUNC,        O_TRUNC },
00795   { OSF_O_EXCL,         O_EXCL },
00796   { OSF_O_NONBLOCK,     O_NONBLOCK },
00797   { OSF_O_NOCTTY,       O_NOCTTY },
00798 #ifdef O_SYNC
00799   { OSF_O_SYNC,         O_SYNC },
00800 #endif
00801 #endif /* _MSC_VER */
00802 };
00803 #define OSF_NFLAGS      (sizeof(osf_flag_table)/sizeof(osf_flag_table[0]))
00804 
00805 qword_t sigmask = 0;
00806 
00807 qword_t sigaction_array[OSF_NSIG] =
00808  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
00809 
00810 /* setsockopt option names */
00811 #define OSF_SO_DEBUG            0x0001
00812 #define OSF_SO_ACCEPTCONN       0x0002
00813 #define OSF_SO_REUSEADDR        0x0004
00814 #define OSF_SO_KEEPALIVE        0x0008
00815 #define OSF_SO_DONTROUTE        0x0010
00816 #define OSF_SO_BROADCAST        0x0020
00817 #define OSF_SO_USELOOPBACK      0x0040
00818 #define OSF_SO_LINGER           0x0080
00819 #define OSF_SO_OOBINLINE        0x0100
00820 #define OSF_SO_REUSEPORT        0x0200
00821 
00822 struct xlate_table_t sockopt_map[] =
00823 {
00824   { OSF_SO_DEBUG,       SO_DEBUG },
00825 #ifdef SO_ACCEPTCONN
00826   { OSF_SO_ACCEPTCONN,  SO_ACCEPTCONN },
00827 #endif
00828   { OSF_SO_REUSEADDR,   SO_REUSEADDR },
00829   { OSF_SO_KEEPALIVE,   SO_KEEPALIVE },
00830   { OSF_SO_DONTROUTE,   SO_DONTROUTE },
00831   { OSF_SO_BROADCAST,   SO_BROADCAST },
00832 #ifdef SO_USELOOPBACK
00833   { OSF_SO_USELOOPBACK, SO_USELOOPBACK },
00834 #endif
00835   { OSF_SO_LINGER,      SO_LINGER },
00836   { OSF_SO_OOBINLINE,   SO_OOBINLINE },
00837 #ifdef SO_REUSEPORT
00838   { OSF_SO_REUSEPORT,   SO_REUSEPORT }
00839 #endif
00840 };
00841 
00842 /* setsockopt TCP options */
00843 #define OSF_TCP_NODELAY         0x01 /* don't delay send to coalesce packets */
00844 #define OSF_TCP_MAXSEG          0x02 /* maximum segment size */
00845 #define OSF_TCP_RPTR2RXT        0x03 /* set repeat count for R2 RXT timer */
00846 #define OSF_TCP_KEEPIDLE        0x04 /* secs before initial keepalive probe */
00847 #define OSF_TCP_KEEPINTVL       0x05 /* seconds between keepalive probes */
00848 #define OSF_TCP_KEEPCNT         0x06 /* num of keepalive probes before drop */
00849 #define OSF_TCP_KEEPINIT        0x07 /* initial connect timeout (seconds) */
00850 #define OSF_TCP_PUSH            0x08 /* set push bit in outbnd data packets */
00851 #define OSF_TCP_NODELACK        0x09 /* don't delay send to coalesce packets */
00852 
00853 struct xlate_table_t tcpopt_map[] =
00854 {
00855   { OSF_TCP_NODELAY,    TCP_NODELAY },
00856   { OSF_TCP_MAXSEG,     TCP_MAXSEG },
00857 #ifdef TCP_RPTR2RXT
00858   { OSF_TCP_RPTR2RXT,   TCP_RPTR2RXT },
00859 #endif
00860 #ifdef TCP_KEEPIDLE
00861   { OSF_TCP_KEEPIDLE,   TCP_KEEPIDLE },
00862 #endif
00863 #ifdef TCP_KEEPINTVL
00864   { OSF_TCP_KEEPINTVL,  TCP_KEEPINTVL },
00865 #endif
00866 #ifdef TCP_KEEPCNT
00867   { OSF_TCP_KEEPCNT,    TCP_KEEPCNT },
00868 #endif
00869 #ifdef TCP_KEEPINIT
00870   { OSF_TCP_KEEPINIT,   TCP_KEEPINIT },
00871 #endif
00872 #ifdef TCP_PUSH
00873   { OSF_TCP_PUSH,       TCP_PUSH },
00874 #endif
00875 #ifdef TCP_NODELACK
00876   { OSF_TCP_NODELACK,   TCP_NODELACK }
00877 #endif
00878 };
00879 
00880 /* setsockopt level names */
00881 #define OSF_SOL_SOCKET          0xffff  /* options for socket level */
00882 #define OSF_SOL_IP              0       /* dummy for IP */
00883 #define OSF_SOL_TCP             6       /* tcp */
00884 #define OSF_SOL_UDP             17      /* user datagram protocol */
00885 
00886 struct xlate_table_t socklevel_map[] =
00887 {
00888 #if defined(__svr4__) || defined(__osf__)
00889   { OSF_SOL_SOCKET,     SOL_SOCKET },
00890   { OSF_SOL_IP,         IPPROTO_IP },
00891   { OSF_SOL_TCP,        IPPROTO_TCP },
00892   { OSF_SOL_UDP,        IPPROTO_UDP }
00893 #else
00894   { OSF_SOL_SOCKET,     SOL_SOCKET },
00895   { OSF_SOL_IP,         SOL_IP },
00896   { OSF_SOL_TCP,        SOL_TCP },
00897   { OSF_SOL_UDP,        SOL_UDP }
00898 #endif
00899 };
00900 
00901 /* socket() address families */
00902 #define OSF_AF_UNSPEC           0
00903 #define OSF_AF_UNIX             1       /* Unix domain sockets */
00904 #define OSF_AF_INET             2       /* internet IP protocol */
00905 #define OSF_AF_IMPLINK          3       /* arpanet imp addresses */
00906 #define OSF_AF_PUP              4       /* pup protocols: e.g. BSP */
00907 #define OSF_AF_CHAOS            5       /* mit CHAOS protocols */
00908 #define OSF_AF_NS               6       /* XEROX NS protocols */
00909 #define OSF_AF_ISO              7       /* ISO protocols */
00910 
00911 struct xlate_table_t family_map[] =
00912 {
00913   { OSF_AF_UNSPEC,      AF_UNSPEC },
00914   { OSF_AF_UNIX,        AF_UNIX },
00915   { OSF_AF_INET,        AF_INET },
00916 #ifdef AF_IMPLINK
00917   { OSF_AF_IMPLINK,     AF_IMPLINK },
00918 #endif
00919 #ifdef AF_PUP
00920   { OSF_AF_PUP,         AF_PUP },
00921 #endif
00922 #ifdef AF_CHAOS
00923   { OSF_AF_CHAOS,       AF_CHAOS },
00924 #endif
00925 #ifdef AF_NS
00926   { OSF_AF_NS,          AF_NS },
00927 #endif
00928 #ifdef AF_ISO
00929   { OSF_AF_ISO,         AF_ISO }
00930 #endif
00931 };
00932 
00933 /* socket() socket types */
00934 #define OSF_SOCK_STREAM         1       /* stream (connection) socket */
00935 #define OSF_SOCK_DGRAM          2       /* datagram (conn.less) socket */
00936 #define OSF_SOCK_RAW            3       /* raw socket */
00937 #define OSF_SOCK_RDM            4       /* reliably-delivered message */
00938 #define OSF_SOCK_SEQPACKET      5       /* sequential packet socket */
00939 
00940 struct xlate_table_t socktype_map[] =
00941 {
00942   { OSF_SOCK_STREAM,    SOCK_STREAM },
00943   { OSF_SOCK_DGRAM,     SOCK_DGRAM },
00944   { OSF_SOCK_RAW,       SOCK_RAW },
00945   { OSF_SOCK_RDM,       SOCK_RDM },
00946   { OSF_SOCK_SEQPACKET, SOCK_SEQPACKET }
00947 };
00948 
00949 /* OSF table() call. Right now, we only support TBL_SYSINFO queries */
00950 #define OSF_TBL_SYSINFO         12
00951 struct osf_tbl_sysinfo 
00952 {
00953   long si_user;         /* user time */
00954   long si_nice;         /* nice time */
00955   long si_sys;          /* system time */
00956   long si_idle;         /* idle time */
00957   long si_hz;
00958   long si_phz;
00959   long si_boottime;     /* boot time in seconds */
00960   long wait;            /* wait time */
00961 };
00962 
00963 
00964 /* OSF SYSCALL -- standard system call sequence
00965    the kernel expects arguments to be passed with the normal C calling
00966    sequence; v0 should contain the system call number; on return from the
00967    kernel mode, a3 will be 0 to indicate no error and non-zero to indicate an
00968    error; if an error occurred v0 will contain an errno; if the kernel return
00969    an error, setup a valid gp and jmp to _cerror */
00970 
00971 /* syscall proxy handler, architect registers and memory are assumed to be
00972    precise when this function is called, register and memory are updated with
00973    the results of the sustem call */
00974 void
00975 sys_syscall(struct regs_t *regs,        /* registers to access */
00976             mem_access_fn mem_fn,       /* generic memory accessor */
00977             struct mem_t *mem,          /* memory space to access */
00978             md_inst_t inst,             /* system call inst */
00979             int traceable)              /* traceable system call? */
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