"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 File Reference

#include <stdio.h>
#include <stdlib.h>
#include "host.h"
#include "misc.h"
#include "machine.h"
#include "regs.h"
#include "memory.h"
#include "loader.h"
#include "sim.h"
#include "endian.h"
#include "eio.h"
#include "syscall.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/param.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <setjmp.h>
#include <sys/times.h>
#include <limits.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <termio.h>

Include dependency graph for target-pisa/syscall.c:

Include dependency graph

Go to the source code of this file.

Compounds

Defines

Functions

Variables


Define Documentation

#define MAXBUFSIZE   1024
 

Definition at line 505 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define NUM_IOCTL_BYTES   128
 

Definition at line 511 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TCGETA   1075082331
 

Definition at line 491 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TCGETP   1076130901
 

Definition at line 490 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TCSETAW   -2146143143
 

Definition at line 495 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TIOCGETC   1074164754
 

Definition at line 496 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TIOCGETP   1074164744
 

Definition at line 488 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TIOCGLTC   1074164852
 

Definition at line 492 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TIOCGWINSZ   1074295912
 

Definition at line 494 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TIOCLBIC   -2147191682
 

Definition at line 498 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TIOCLBIS   -2147191681
 

Definition at line 499 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TIOCLGET   0x4004747c
 

Definition at line 500 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TIOCLSET   -2147191683
 

Definition at line 501 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TIOCSETC   -2147060719
 

Definition at line 497 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TIOCSETP   -2147060727
 

Definition at line 489 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_IOCTL_TIOCSLTC   -2147060619
 

Definition at line 493 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_NFLAGS   (sizeof(ss_flag_table)/sizeof(ss_flag_table[0]))
 

Definition at line 638 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_O_APPEND   0x0008
 

Definition at line 592 of file target-pisa/syscall.c.

#define SS_O_CREAT   0x0200
 

Definition at line 593 of file target-pisa/syscall.c.

#define SS_O_EXCL   0x0800
 

Definition at line 595 of file target-pisa/syscall.c.

#define SS_O_NOCTTY   0x8000
 

Definition at line 597 of file target-pisa/syscall.c.

#define SS_O_NONBLOCK   0x4000
 

Definition at line 596 of file target-pisa/syscall.c.

#define SS_O_RDONLY   0
 

Definition at line 589 of file target-pisa/syscall.c.

#define SS_O_RDWR   2
 

Definition at line 591 of file target-pisa/syscall.c.

#define SS_O_SYNC   0x2000
 

Definition at line 598 of file target-pisa/syscall.c.

#define SS_O_TRUNC   0x0400
 

Definition at line 594 of file target-pisa/syscall.c.

#define SS_O_WRONLY   1
 

Definition at line 590 of file target-pisa/syscall.c.

#define SS_SYS_accept   99
 

Definition at line 373 of file target-pisa/syscall.c.

#define SS_SYS_access   33
 

Definition at line 306 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_acct   51
 

Definition at line 324 of file target-pisa/syscall.c.

#define SS_SYS_adjtime   140
 

Definition at line 416 of file target-pisa/syscall.c.

#define SS_SYS_async_daemon   163
 

Definition at line 453 of file target-pisa/syscall.c.

#define SS_SYS_atomic_op   155
 

Definition at line 434 of file target-pisa/syscall.c.

#define SS_SYS_audcntl   252
 

Definition at line 480 of file target-pisa/syscall.c.

#define SS_SYS_audgen   253
 

Definition at line 481 of file target-pisa/syscall.c.

#define SS_SYS_bind   104
 

Definition at line 379 of file target-pisa/syscall.c.

#define SS_SYS_brk   17
 

Definition at line 290 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_cachectl   153
 

Definition at line 433 of file target-pisa/syscall.c.

#define SS_SYS_cacheflush   152
 

Definition at line 432 of file target-pisa/syscall.c.

#define SS_SYS_chdir   12
 

Definition at line 285 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_chmod   15
 

Definition at line 288 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_chown   16
 

Definition at line 289 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_chroot   61
 

Definition at line 334 of file target-pisa/syscall.c.

#define SS_SYS_close   6
 

Definition at line 279 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_connect   98
 

Definition at line 372 of file target-pisa/syscall.c.

#define SS_SYS_creat   8
 

Definition at line 281 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_debug   154
 

Definition at line 437 of file target-pisa/syscall.c.

#define SS_SYS_dup   41
 

Definition at line 314 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_dup2   90
 

Definition at line 364 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_execv   11
 

Definition at line 284 of file target-pisa/syscall.c.

#define SS_SYS_execve   59
 

Definition at line 332 of file target-pisa/syscall.c.

#define SS_SYS_exportfs   169
 

Definition at line 459 of file target-pisa/syscall.c.

#define SS_SYS_fchmod   124
 

Definition at line 399 of file target-pisa/syscall.c.

#define SS_SYS_fchown   123
 

Definition at line 398 of file target-pisa/syscall.c.

#define SS_SYS_fcntl   92
 

Definition at line 366 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_flock   131
 

Definition at line 406 of file target-pisa/syscall.c.

#define SS_SYS_fork   2
 

Definition at line 275 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_fstat   62
 

Definition at line 335 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_fstatfs   161
 

Definition at line 440 of file target-pisa/syscall.c.

#define SS_SYS_fsync   95
 

Definition at line 369 of file target-pisa/syscall.c.

#define SS_SYS_ftruncate   130
 

Definition at line 405 of file target-pisa/syscall.c.

#define SS_SYS_getdirentries   159
 

Definition at line 456 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_getdomainname   165
 

Definition at line 457 of file target-pisa/syscall.c.

#define SS_SYS_getdopt   91
 

Definition at line 365 of file target-pisa/syscall.c.

#define SS_SYS_getdtablesize   89
 

Definition at line 363 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_getfh   164
 

Definition at line 455 of file target-pisa/syscall.c.

#define SS_SYS_getgid   47
 

Definition at line 320 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_getgroups   79
 

Definition at line 352 of file target-pisa/syscall.c.

#define SS_SYS_gethostid   142
 

Definition at line 418 of file target-pisa/syscall.c.

#define SS_SYS_gethostname   87
 

Definition at line 361 of file target-pisa/syscall.c.

#define SS_SYS_getitimer   86
 

Definition at line 360 of file target-pisa/syscall.c.

#define SS_SYS_getmnt   184
 

Definition at line 473 of file target-pisa/syscall.c.

#define SS_SYS_getpagesize   64
 

Definition at line 337 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_getpeername   141
 

Definition at line 417 of file target-pisa/syscall.c.

#define SS_SYS_getpgrp   81
 

Definition at line 354 of file target-pisa/syscall.c.

#define SS_SYS_getpid   20
 

Definition at line 293 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_getpriority   100
 

Definition at line 374 of file target-pisa/syscall.c.

#define SS_SYS_getrlimit   144
 

Definition at line 420 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_getrusage   117
 

Definition at line 392 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_getsockname   150
 

Definition at line 426 of file target-pisa/syscall.c.

#define SS_SYS_getsockopt   118
 

Definition at line 393 of file target-pisa/syscall.c.

#define SS_SYS_getsysinfo   256
 

Definition at line 484 of file target-pisa/syscall.c.

#define SS_SYS_gettimeofday   116
 

Definition at line 391 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_getuid   24
 

Definition at line 297 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_hdwconf   171
 

Definition at line 446 of file target-pisa/syscall.c.

#define SS_SYS_ioctl   54
 

Definition at line 327 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_kill   37
 

Definition at line 310 of file target-pisa/syscall.c.

#define SS_SYS_killpg   146
 

Definition at line 422 of file target-pisa/syscall.c.

#define SS_SYS_link   9
 

Definition at line 282 of file target-pisa/syscall.c.

#define SS_SYS_listen   106
 

Definition at line 381 of file target-pisa/syscall.c.

#define SS_SYS_lockf   182
 

Definition at line 471 of file target-pisa/syscall.c.

#define SS_SYS_lseek   19
 

Definition at line 292 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_lstat   40
 

Definition at line 313 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_madvise   75
 

Definition at line 348 of file target-pisa/syscall.c.

#define SS_SYS_mincore   78
 

Definition at line 351 of file target-pisa/syscall.c.

#define SS_SYS_mkdir   136
 

Definition at line 411 of file target-pisa/syscall.c.

#define SS_SYS_mknod   14
 

Definition at line 287 of file target-pisa/syscall.c.

#define SS_SYS_mmap   71
 

Definition at line 344 of file target-pisa/syscall.c.

#define SS_SYS_mount   21
 

Definition at line 294 of file target-pisa/syscall.c.

#define SS_SYS_mprotect   74
 

Definition at line 347 of file target-pisa/syscall.c.

#define SS_SYS_mremap   65
 

Definition at line 338 of file target-pisa/syscall.c.

#define SS_SYS_msgctl   172
 

Definition at line 461 of file target-pisa/syscall.c.

#define SS_SYS_msgget   173
 

Definition at line 462 of file target-pisa/syscall.c.

#define SS_SYS_msgrcv   174
 

Definition at line 463 of file target-pisa/syscall.c.

#define SS_SYS_msgsnd   175
 

Definition at line 464 of file target-pisa/syscall.c.

#define SS_SYS_munmap   73
 

Definition at line 346 of file target-pisa/syscall.c.

#define SS_SYS_nfs_biod   163
 

Definition at line 452 of file target-pisa/syscall.c.

#define SS_SYS_nfs_getfh   164
 

Definition at line 454 of file target-pisa/syscall.c.

#define SS_SYS_nfs_svc   158
 

Definition at line 450 of file target-pisa/syscall.c.

#define SS_SYS_nfssvc   158
 

Definition at line 451 of file target-pisa/syscall.c.

#define SS_SYS_open   5
 

Definition at line 278 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_pipe   42
 

Definition at line 315 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_plock   181
 

Definition at line 470 of file target-pisa/syscall.c.

#define SS_SYS_profil   44
 

Definition at line 317 of file target-pisa/syscall.c.

#define SS_SYS_ptrace   26
 

Definition at line 299 of file target-pisa/syscall.c.

#define SS_SYS_quota   149
 

Definition at line 425 of file target-pisa/syscall.c.

#define SS_SYS_quotactl   168
 

Definition at line 443 of file target-pisa/syscall.c.

#define SS_SYS_read   3
 

Definition at line 276 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_readlink   58
 

Definition at line 331 of file target-pisa/syscall.c.

#define SS_SYS_readv   120
 

Definition at line 395 of file target-pisa/syscall.c.

#define SS_SYS_reboot   55
 

Definition at line 328 of file target-pisa/syscall.c.

#define SS_SYS_recv   102
 

Definition at line 376 of file target-pisa/syscall.c.

#define SS_SYS_recvfrom   125
 

Definition at line 400 of file target-pisa/syscall.c.

#define SS_SYS_recvmsg   113
 

Definition at line 388 of file target-pisa/syscall.c.

#define SS_SYS_rename   128
 

Definition at line 403 of file target-pisa/syscall.c.

#define SS_SYS_rmdir   137
 

Definition at line 412 of file target-pisa/syscall.c.

#define SS_SYS_sbrk   69
 

Definition at line 342 of file target-pisa/syscall.c.

#define SS_SYS_select   93
 

Definition at line 367 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_semctl   176
 

Definition at line 465 of file target-pisa/syscall.c.

#define SS_SYS_semget   177
 

Definition at line 466 of file target-pisa/syscall.c.

#define SS_SYS_semop   178
 

Definition at line 467 of file target-pisa/syscall.c.

#define SS_SYS_send   101
 

Definition at line 375 of file target-pisa/syscall.c.

#define SS_SYS_sendmsg   114
 

Definition at line 389 of file target-pisa/syscall.c.

#define SS_SYS_sendto   133
 

Definition at line 408 of file target-pisa/syscall.c.

#define SS_SYS_setdomainname   166
 

Definition at line 458 of file target-pisa/syscall.c.

#define SS_SYS_setdopt   94
 

Definition at line 368 of file target-pisa/syscall.c.

#define SS_SYS_setgroups   80
 

Definition at line 353 of file target-pisa/syscall.c.

#define SS_SYS_sethostid   143
 

Definition at line 419 of file target-pisa/syscall.c.

#define SS_SYS_sethostname   88
 

Definition at line 362 of file target-pisa/syscall.c.

#define SS_SYS_setitimer   83
 

Definition at line 356 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_setpgrp   82
 

Definition at line 355 of file target-pisa/syscall.c.

#define SS_SYS_setpriority   96
 

Definition at line 370 of file target-pisa/syscall.c.

#define SS_SYS_setquota   148
 

Definition at line 424 of file target-pisa/syscall.c.

#define SS_SYS_setregid   127
 

Definition at line 402 of file target-pisa/syscall.c.

#define SS_SYS_setreuid   126
 

Definition at line 401 of file target-pisa/syscall.c.

#define SS_SYS_setrlimit   145
 

Definition at line 421 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_setsid   188
 

Definition at line 475 of file target-pisa/syscall.c.

#define SS_SYS_setsockopt   105
 

Definition at line 380 of file target-pisa/syscall.c.

#define SS_SYS_setsysinfo   257
 

Definition at line 485 of file target-pisa/syscall.c.

#define SS_SYS_settimeofday   122
 

Definition at line 397 of file target-pisa/syscall.c.

#define SS_SYS_shmsys   180
 

Definition at line 469 of file target-pisa/syscall.c.

#define SS_SYS_shutdown   134
 

Definition at line 409 of file target-pisa/syscall.c.

#define SS_SYS_sigblock   109
 

Definition at line 384 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_sigcleanup   139
 

Definition at line 414 of file target-pisa/syscall.c.

#define SS_SYS_sigpause   111
 

Definition at line 386 of file target-pisa/syscall.c.

#define SS_SYS_sigpending   187
 

Definition at line 474 of file target-pisa/syscall.c.

#define SS_SYS_sigreturn   103
 

Definition at line 377 of file target-pisa/syscall.c.

#define SS_SYS_sigsetmask   110
 

Definition at line 385 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_sigstack   112
 

Definition at line 387 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_sigvec   108
 

Definition at line 383 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_socket   97
 

Definition at line 371 of file target-pisa/syscall.c.

#define SS_SYS_socketpair   135
 

Definition at line 410 of file target-pisa/syscall.c.

#define SS_SYS_sstk   70
 

Definition at line 343 of file target-pisa/syscall.c.

#define SS_SYS_startcpu   254
 

Definition at line 482 of file target-pisa/syscall.c.

#define SS_SYS_stat   38
 

Definition at line 311 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_statfs   160
 

Definition at line 439 of file target-pisa/syscall.c.

#define SS_SYS_stopcpu   255
 

Definition at line 483 of file target-pisa/syscall.c.

#define SS_SYS_swapon   85
 

Definition at line 359 of file target-pisa/syscall.c.

#define SS_SYS_symlink   57
 

Definition at line 330 of file target-pisa/syscall.c.

#define SS_SYS_sync   36
 

Definition at line 309 of file target-pisa/syscall.c.

#define SS_SYS_syscall   0
 

Definition at line 273 of file target-pisa/syscall.c.

#define SS_SYS_sysmips   151
 

Definition at line 428 of file target-pisa/syscall.c.

#define SS_SYS_truncate   129
 

Definition at line 404 of file target-pisa/syscall.c.

#define SS_SYS_umask   60
 

Definition at line 333 of file target-pisa/syscall.c.

#define SS_SYS_umount   22
 

Definition at line 295 of file target-pisa/syscall.c.

#define SS_SYS_uname   179
 

Definition at line 468 of file target-pisa/syscall.c.

#define SS_SYS_unlink   10
 

Definition at line 283 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_unmount   162
 

Definition at line 441 of file target-pisa/syscall.c.

#define SS_SYS_ustat   183
 

Definition at line 472 of file target-pisa/syscall.c.

#define SS_SYS_utc_adjtime   234
 

Definition at line 479 of file target-pisa/syscall.c.

#define SS_SYS_utc_gettime   233
 

Definition at line 478 of file target-pisa/syscall.c.

#define SS_SYS_utimes   138
 

Definition at line 413 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_vadvise   72
 

Definition at line 345 of file target-pisa/syscall.c.

#define SS_SYS_vfork   66
 

Definition at line 339 of file target-pisa/syscall.c.

Referenced by sys_syscall().

#define SS_SYS_vhangup   76
 

Definition at line 349 of file target-pisa/syscall.c.

#define SS_SYS_wait   SYS_wait3
 

Definition at line 358 of file target-pisa/syscall.c.

#define SS_SYS_wait3   84
 

Definition at line 357 of file target-pisa/syscall.c.

#define SS_SYS_waitpid   189
 

Definition at line 476 of file target-pisa/syscall.c.

#define SS_SYS_writev   121
 

Definition at line 396 of file target-pisa/syscall.c.

Referenced by sys_syscall().


Function Documentation

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

Definition at line 647 of file target-pisa/syscall.c.

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

Referenced by eio_read_trace(), and eio_write_trace().

00652 {
00653   word_t syscode = regs->regs_R[2];
00654 
00655   /* first, check if an EIO trace is being consumed... */
00656   if (traceable && sim_eio_fd != NULL)
00657     {
00658       eio_read_trace(sim_eio_fd, sim_num_insn, regs, mem_fn, mem, inst);
00659 
00660       /* fini... */
00661       return;
00662     }
00663 #ifdef MD_CROSS_ENDIAN
00664   else if (syscode == SS_SYS_exit)
00665     {
00666       /* exit jumps to the target set in main() */
00667       longjmp(sim_exit_buf, /* exitcode + fudge */regs->regs_R[4]+1);
00668     }
00669   else
00670     fatal("cannot execute PISA system call on cross-endian host");
00671 
00672 #else /* !MD_CROSS_ENDIAN */
00673 
00674   /* no, OK execute the live system call... */
00675   switch (syscode)
00676     {
00677     case SS_SYS_exit:
00678       /* exit jumps to the target set in main() */
00679       longjmp(sim_exit_buf, /* exitcode + fudge */regs->regs_R[4]+1);
00680       break;
00681 
00682 #if 0
00683     case SS_SYS_fork:
00684       /* FIXME: this is broken... */
00685       regs->regs_R[2] = fork();
00686       if (regs->regs_R[2] != -1)
00687         {
00688           regs->regs_R[7] = 0;
00689           /* parent process */
00690           if (regs->regs_R[2] != 0)
00691           regs->regs_R[3] = 0;
00692         }
00693       else
00694         fatal("SYS_fork failed");
00695       break;
00696 #endif
00697 
00698 #if 0
00699     case SS_SYS_vfork:
00700       /* FIXME: this is broken... */
00701       int r31_parent = regs->regs_R[31];
00702       /* pid */regs->regs_R[2] = vfork();
00703       if (regs->regs_R[2] != -1)
00704         regs->regs_R[7] = 0;
00705       else
00706         fatal("vfork() in SYS_vfork failed");
00707       if (regs->regs_R[2] != 0)
00708         {
00709           regs->regs_R[3] = 0;
00710           regs->regs_R[7] = 0;
00711           regs->regs_R[31] = r31_parent;
00712         }
00713       break;
00714 #endif
00715 
00716     case SS_SYS_read:
00717       {
00718         char *buf;
00719 
00720         /* allocate same-sized input buffer in host memory */
00721         if (!(buf = (char *)calloc(/*nbytes*/regs->regs_R[6], sizeof(char))))
00722           fatal("out of memory in SYS_read");
00723 
00724         /* read data from file */
00725         /*nread*/regs->regs_R[2] =
00726           read(/*fd*/regs->regs_R[4], buf, /*nbytes*/regs->regs_R[6]);
00727 
00728         /* check for error condition */
00729         if (regs->regs_R[2] != -1)
00730           regs->regs_R[7] = 0;
00731         else
00732           {
00733             /* got an error, return details */
00734             regs->regs_R[2] = errno;
00735             regs->regs_R[7] = 1;
00736           }
00737 
00738         /* copy results back into host memory */
00739         mem_bcopy(mem_fn, mem,
00740                   Write, /*buf*/regs->regs_R[5],
00741                   buf, /*nread*/regs->regs_R[2]);
00742 
00743         /* done with input buffer */
00744         free(buf);
00745       }
00746       break;
00747 
00748     case SS_SYS_write:
00749       {
00750         char *buf;
00751 
00752         /* allocate same-sized output buffer in host memory */
00753         if (!(buf = (char *)calloc(/*nbytes*/regs->regs_R[6], sizeof(char))))
00754           fatal("out of memory in SYS_write");
00755 
00756         /* copy inputs into host memory */
00757         mem_bcopy(mem_fn, mem,
00758                   Read, /*buf*/regs->regs_R[5],
00759                   buf, /*nbytes*/regs->regs_R[6]);
00760 
00761         /* write data to file */
00762         if (sim_progfd && MD_OUTPUT_SYSCALL(regs))
00763           {
00764             /* redirect program output to file */
00765 
00766             /*nwritten*/regs->regs_R[2] =
00767               fwrite(buf, 1, /*nbytes*/regs->regs_R[6], sim_progfd);
00768           }
00769         else
00770           {
00771             /* perform program output request */
00772 
00773             /*nwritten*/regs->regs_R[2] =
00774               write(/*fd*/regs->regs_R[4],
00775                     buf, /*nbytes*/regs->regs_R[6]);
00776           }
00777 
00778         /* check for an error condition */
00779         if (regs->regs_R[2] == regs->regs_R[6])
00780           /*result*/regs->regs_R[7] = 0;
00781         else
00782           {
00783             /* got an error, return details */
00784             regs->regs_R[2] = errno;
00785             regs->regs_R[7] = 1;
00786           }
00787 
00788         /* done with output buffer */
00789         free(buf);
00790       }
00791       break;
00792 
00793     case SS_SYS_open:
00794       {
00795         char buf[MAXBUFSIZE];
00796         unsigned int i;
00797         int ss_flags = regs->regs_R[5], local_flags = 0;
00798 
00799         /* translate open(2) flags */
00800         for (i=0; i<SS_NFLAGS; i++)
00801           {
00802             if (ss_flags & ss_flag_table[i].ss_flag)
00803               {
00804                 ss_flags &= ~ss_flag_table[i].ss_flag;
00805                 local_flags |= ss_flag_table[i].local_flag;
00806               }
00807           }
00808         /* any target flags left? */
00809         if (ss_flags != 0)
00810           fatal("syscall: open: cannot decode flags: 0x%08x", ss_flags);
00811 
00812         /* copy filename to host memory */
00813         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[4], buf);
00814 
00815         /* open the file */
00816 #ifdef __CYGWIN32__
00817         /*fd*/regs->regs_R[2] =
00818           open(buf, local_flags|O_BINARY, /*mode*/regs->regs_R[6]);
00819 #else /* !__CYGWIN32__ */
00820         /*fd*/regs->regs_R[2] =
00821           open(buf, local_flags, /*mode*/regs->regs_R[6]);
00822 #endif /* __CYGWIN32__ */
00823         
00824         /* check for an error condition */
00825         if (regs->regs_R[2] != -1)
00826           regs->regs_R[7] = 0;
00827         else
00828           {
00829             /* got an error, return details */
00830             regs->regs_R[2] = errno;
00831             regs->regs_R[7] = 1;
00832           }
00833       }
00834       break;
00835 
00836     case SS_SYS_close:
00837       /* don't close stdin, stdout, or stderr as this messes up sim logs */
00838       if (/*fd*/regs->regs_R[4] == 0
00839           || /*fd*/regs->regs_R[4] == 1
00840           || /*fd*/regs->regs_R[4] == 2)
00841         {
00842           regs->regs_R[7] = 0;
00843           break;
00844         }
00845 
00846       /* close the file */
00847       regs->regs_R[2] = close(/*fd*/regs->regs_R[4]);
00848 
00849       /* check for an error condition */
00850       if (regs->regs_R[2] != -1)
00851         regs->regs_R[7] = 0;
00852       else
00853         {
00854           /* got an error, return details */
00855           regs->regs_R[2] = errno;
00856           regs->regs_R[7] = 1;
00857         }
00858       break;
00859 
00860     case SS_SYS_creat:
00861       {
00862         char buf[MAXBUFSIZE];
00863 
00864         /* copy filename to host memory */
00865         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[4], buf);
00866 
00867         /* create the file */
00868         /*fd*/regs->regs_R[2] = creat(buf, /*mode*/regs->regs_R[5]);
00869 
00870         /* check for an error condition */
00871         if (regs->regs_R[2] != -1)
00872           regs->regs_R[7] = 0;
00873         else
00874           {
00875             /* got an error, return details */
00876             regs->regs_R[2] = errno;
00877             regs->regs_R[7] = 1;
00878           }
00879       }
00880       break;
00881 
00882     case SS_SYS_unlink:
00883       {
00884         char buf[MAXBUFSIZE];
00885 
00886         /* copy filename to host memory */
00887         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[4], buf);
00888 
00889         /* delete the file */
00890         /*result*/regs->regs_R[2] = unlink(buf);
00891 
00892         /* check for an error condition */
00893         if (regs->regs_R[2] != -1)
00894           regs->regs_R[7] = 0;
00895         else
00896           {
00897             /* got an error, return details */
00898             regs->regs_R[2] = errno;
00899             regs->regs_R[7] = 1;
00900           }
00901       }
00902       break;
00903 
00904     case SS_SYS_chdir:
00905       {
00906         char buf[MAXBUFSIZE];
00907 
00908         /* copy filename to host memory */
00909         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[4], buf);
00910 
00911         /* change the working directory */
00912         /*result*/regs->regs_R[2] = chdir(buf);
00913 
00914         /* check for an error condition */
00915         if (regs->regs_R[2] != -1)
00916           regs->regs_R[7] = 0;
00917         else
00918           {
00919             /* got an error, return details */
00920             regs->regs_R[2] = errno;
00921             regs->regs_R[7] = 1;
00922           }
00923       }
00924       break;
00925 
00926     case SS_SYS_chmod:
00927       {
00928         char buf[MAXBUFSIZE];
00929 
00930         /* copy filename to host memory */
00931         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[4], buf);
00932 
00933         /* chmod the file */
00934         /*result*/regs->regs_R[2] = chmod(buf, /*mode*/regs->regs_R[5]);
00935 
00936         /* check for an error condition */
00937         if (regs->regs_R[2] != -1)
00938           regs->regs_R[7] = 0;
00939         else
00940           {
00941             /* got an error, return details */
00942             regs->regs_R[2] = errno;
00943             regs->regs_R[7] = 1;
00944           }
00945       }
00946       break;
00947 
00948     case SS_SYS_chown:
00949 #ifdef _MSC_VER
00950       warn("syscall chown() not yet implemented for MSC...");
00951       regs->regs_R[7] = 0;
00952 #else /* !_MSC_VER */
00953       {
00954         char buf[MAXBUFSIZE];
00955 
00956         /* copy filename to host memory */
00957         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[4], buf);
00958 
00959         /* chown the file */
00960         /*result*/regs->regs_R[2] = chown(buf, /*owner*/regs->regs_R[5],
00961                                     /*group*/regs->regs_R[6]);
00962 
00963         /* check for an error condition */
00964         if (regs->regs_R[2] != -1)
00965           regs->regs_R[7] = 0;
00966         else
00967           {
00968             /* got an error, return details */
00969             regs->regs_R[2] = errno;
00970             regs->regs_R[7] = 1;
00971           }
00972       }
00973 #endif /* _MSC_VER */
00974       break;
00975 
00976     case SS_SYS_brk:
00977       {
00978         md_addr_t addr;
00979 
00980         /* round the new heap pointer to the its page boundary */
00981         addr = ROUND_UP(/*base*/regs->regs_R[4], MD_PAGE_SIZE);
00982 
00983         /* check whether heap area has merged with stack area */
00984         if (addr >= ld_brk_point && addr < (md_addr_t)regs->regs_R[29])
00985           {
00986             regs->regs_R[2] = 0;
00987             regs->regs_R[7] = 0;
00988             ld_brk_point = addr;
00989           }
00990         else
00991           {
00992             /* out of address space, indicate error */
00993             regs->regs_R[2] = ENOMEM;
00994             regs->regs_R[7] = 1;
00995           }
00996       }
00997       break;
00998 
00999     case SS_SYS_lseek:
01000       /* seek into file */
01001       regs->regs_R[2] =
01002         lseek(/*fd*/regs->regs_R[4],
01003               /*off*/regs->regs_R[5], /*dir*/regs->regs_R[6]);
01004 
01005       /* check for an error condition */
01006       if (regs->regs_R[2] != -1)
01007         regs->regs_R[7] = 0;
01008       else
01009         {
01010           /* got an error, return details */
01011           regs->regs_R[2] = errno;
01012           regs->regs_R[7] = 1;
01013         }
01014       break;
01015 
01016     case SS_SYS_getpid:
01017       /* get the simulator process id */
01018       /*result*/regs->regs_R[2] = getpid();
01019 
01020       /* check for an error condition */
01021       if (regs->regs_R[2] != -1)
01022         regs->regs_R[7] = 0;
01023       else
01024         {
01025           /* got an error, return details */
01026           regs->regs_R[2] = errno;
01027           regs->regs_R[7] = 1;
01028         }
01029       break;
01030 
01031     case SS_SYS_getuid:
01032 #ifdef _MSC_VER
01033       warn("syscall getuid() not yet implemented for MSC...");
01034       regs->regs_R[7] = 0;
01035 #else /* !_MSC_VER */
01036       /* get current user id */
01037       /*first result*/regs->regs_R[2] = getuid();
01038 
01039       /* get effective user id */
01040       /*second result*/regs->regs_R[3] = geteuid();
01041 
01042       /* check for an error condition */
01043       if (regs->regs_R[2] != -1)
01044         regs->regs_R[7] = 0;
01045       else
01046         {
01047           /* got an error, return details */
01048           regs->regs_R[2] = errno;
01049           regs->regs_R[7] = 1;
01050         }
01051 #endif /* _MSC_VER */
01052       break;
01053 
01054     case SS_SYS_access:
01055       {
01056         char buf[MAXBUFSIZE];
01057 
01058         /* copy filename to host memory */
01059         mem_strcpy(mem_fn, mem, Read, /*fName*/regs->regs_R[4], buf);
01060 
01061         /* check access on the file */
01062         /*result*/regs->regs_R[2] = access(buf, /*mode*/regs->regs_R[5]);
01063 
01064         /* check for an error condition */
01065         if (regs->regs_R[2] != -1)
01066           regs->regs_R[7] = 0;
01067         else
01068           {
01069             /* got an error, return details */
01070             regs->regs_R[2] = errno;
01071             regs->regs_R[7] = 1;
01072           }
01073       }
01074       break;
01075 
01076     case SS_SYS_stat:
01077     case SS_SYS_lstat:
01078       {
01079         char buf[MAXBUFSIZE];
01080         struct ss_statbuf ss_sbuf;
01081 #ifdef _MSC_VER
01082         struct _stat sbuf;
01083 #else /* !_MSC_VER */
01084         struct stat sbuf;
01085 #endif /* _MSC_VER */
01086 
01087         /* copy filename to host memory */
01088         mem_strcpy(mem_fn, mem, Read, /*fName*/regs->regs_R[4], buf);
01089 
01090         /* stat() the file */
01091         if (syscode == SS_SYS_stat)
01092           /*result*/regs->regs_R[2] = stat(buf, &sbuf);
01093         else /* syscode == SS_SYS_lstat */
01094           {
01095 #ifdef _MSC_VER
01096             warn("syscall lstat() not yet implemented for MSC...");
01097             regs->regs_R[7] = 0;
01098             break;
01099 #else /* !_MSC_VER */
01100             /*result*/regs->regs_R[2] = lstat(buf, &sbuf);
01101 #endif /* _MSC_VER */
01102           }
01103 
01104         /* check for an error condition */
01105         if (regs->regs_R[2] != -1)
01106           regs->regs_R[7] = 0;
01107         else
01108           {
01109             /* got an error, return details */
01110             regs->regs_R[2] = errno;
01111             regs->regs_R[7] = 1;
01112           }
01113 
01114         /* translate from host stat structure to target format */
01115         ss_sbuf.ss_st_dev = MD_SWAPH(sbuf.st_dev);
01116         ss_sbuf.ss_pad = 0;
01117         ss_sbuf.ss_st_ino = MD_SWAPW(sbuf.st_ino);
01118         ss_sbuf.ss_st_mode = MD_SWAPH(sbuf.st_mode);
01119         ss_sbuf.ss_st_nlink = MD_SWAPH(sbuf.st_nlink);
01120         ss_sbuf.ss_st_uid = MD_SWAPH(sbuf.st_uid);
01121         ss_sbuf.ss_st_gid = MD_SWAPH(sbuf.st_gid);
01122         ss_sbuf.ss_st_rdev = MD_SWAPH(sbuf.st_rdev);
01123         ss_sbuf.ss_pad1 = 0;
01124         ss_sbuf.ss_st_size = MD_SWAPW(sbuf.st_size);
01125         ss_sbuf.ss_st_atime = MD_SWAPW(sbuf.st_atime);
01126         ss_sbuf.ss_st_spare1 = 0;
01127         ss_sbuf.ss_st_mtime = MD_SWAPW(sbuf.st_mtime);
01128         ss_sbuf.ss_st_spare2 = 0;
01129         ss_sbuf.ss_st_ctime = MD_SWAPW(sbuf.st_ctime);
01130         ss_sbuf.ss_st_spare3 = 0;
01131 #ifndef _MSC_VER
01132         ss_sbuf.ss_st_blksize = MD_SWAPW(sbuf.st_blksize);
01133         ss_sbuf.ss_st_blocks = MD_SWAPW(sbuf.st_blocks);
01134 #endif /* !_MSC_VER */
01135         ss_sbuf.ss_st_gennum = 0;
01136         ss_sbuf.ss_st_spare4 = 0;
01137 
01138         /* copy stat() results to simulator memory */
01139         mem_bcopy(mem_fn, mem, Write, /*sbuf*/regs->regs_R[5],
01140                   &ss_sbuf, sizeof(struct ss_statbuf));
01141       }
01142       break;
01143 
01144     case SS_SYS_dup:
01145       /* dup() the file descriptor */
01146       /*fd*/regs->regs_R[2] = dup(/*fd*/regs->regs_R[4]);
01147 
01148       /* check for an error condition */
01149       if (regs->regs_R[2] != -1)
01150         regs->regs_R[7] = 0;
01151       else
01152         {
01153           /* got an error, return details */
01154           regs->regs_R[2] = errno;
01155           regs->regs_R[7] = 1;
01156         }
01157       break;
01158 
01159 #ifndef _MSC_VER
01160     case SS_SYS_pipe:
01161       {
01162         int fd[2];
01163 
01164         /* copy pipe descriptors to host memory */;
01165         mem_bcopy(mem_fn, mem, Read, /*fd's*/regs->regs_R[4], fd, sizeof(fd));
01166 
01167         /* create a pipe */
01168         /*result*/regs->regs_R[7] = pipe(fd);
01169 
01170         /* copy descriptor results to result registers */
01171         /*pipe1*/regs->regs_R[2] = fd[0];
01172         /*pipe 2*/regs->regs_R[3] = fd[1];
01173 
01174         /* check for an error condition */
01175         if (regs->regs_R[7] == -1)
01176           {
01177             regs->regs_R[2] = errno;
01178             regs->regs_R[7] = 1;
01179           }
01180       }
01181       break;
01182 #endif
01183 
01184     case SS_SYS_getgid:
01185 #ifdef _MSC_VER
01186       warn("syscall getgid() not yet implemented for MSC...");
01187       regs->regs_R[7] = 0;
01188 #else /* !_MSC_VER */
01189       /* get current group id */
01190       /*first result*/regs->regs_R[2] = getgid();
01191 
01192       /* get current effective group id */
01193       /*second result*/regs->regs_R[3] = getegid();
01194 
01195         /* check for an error condition */
01196       if (regs->regs_R[2] != -1)
01197         regs->regs_R[7] = 0;
01198       else
01199         {
01200           /* got an error, return details */
01201           regs->regs_R[2] = errno;
01202           regs->regs_R[7] = 1;
01203         }
01204 #endif /* _MSC_VER */
01205       break;
01206 
01207     case SS_SYS_ioctl:
01208       {
01209         char buf[NUM_IOCTL_BYTES];
01210         int local_req = 0;
01211 
01212         /* convert target ioctl() request to host ioctl() request values */
01213         switch (/*req*/regs->regs_R[5]) {
01214 #ifdef TIOCGETP
01215         case SS_IOCTL_TIOCGETP:
01216           local_req = TIOCGETP;
01217           break;
01218 #endif
01219 #ifdef TIOCSETP
01220         case SS_IOCTL_TIOCSETP:
01221           local_req = TIOCSETP;
01222           break;
01223 #endif
01224 #ifdef TIOCGETP
01225         case SS_IOCTL_TCGETP:
01226           local_req = TIOCGETP;
01227           break;
01228 #endif
01229 #ifdef TCGETA
01230         case SS_IOCTL_TCGETA:
01231           local_req = TCGETA;
01232           break;
01233 #endif
01234 #ifdef TIOCGLTC
01235         case SS_IOCTL_TIOCGLTC:
01236           local_req = TIOCGLTC;
01237           break;
01238 #endif
01239 #ifdef TIOCSLTC
01240         case SS_IOCTL_TIOCSLTC:
01241           local_req = TIOCSLTC;
01242           break;
01243 #endif
01244 #ifdef TIOCGWINSZ
01245         case SS_IOCTL_TIOCGWINSZ:
01246           local_req = TIOCGWINSZ;
01247           break;
01248 #endif
01249 #ifdef TCSETAW
01250         case SS_IOCTL_TCSETAW:
01251           local_req = TCSETAW;
01252           break;
01253 #endif
01254 #ifdef TIOCGETC
01255         case SS_IOCTL_TIOCGETC:
01256           local_req = TIOCGETC;
01257           break;
01258 #endif
01259 #ifdef TIOCSETC
01260         case SS_IOCTL_TIOCSETC:
01261           local_req = TIOCSETC;
01262           break;
01263 #endif
01264 #ifdef TIOCLBIC
01265         case SS_IOCTL_TIOCLBIC:
01266           local_req = TIOCLBIC;
01267           break;
01268 #endif
01269 #ifdef TIOCLBIS
01270         case SS_IOCTL_TIOCLBIS:
01271           local_req = TIOCLBIS;
01272           break;
01273 #endif
01274 #ifdef TIOCLGET
01275         case SS_IOCTL_TIOCLGET:
01276           local_req = TIOCLGET;
01277           break;
01278 #endif
01279 #ifdef TIOCLSET
01280         case SS_IOCTL_TIOCLSET:
01281           local_req = TIOCLSET;
01282           break;
01283 #endif
01284         }
01285 
01286 #if !defined(TIOCGETP) && defined(linux)
01287         if (!local_req && /*req*/regs->regs_R[5] == SS_IOCTL_TIOCGETP)
01288           {
01289             struct termios lbuf;
01290             struct ss_sgttyb buf;
01291 
01292             /* result */regs->regs_R[2] =
01293                           tcgetattr(/* fd */(int)regs->regs_R[4], &lbuf);
01294 
01295             /* translate results */
01296             buf.sg_ispeed = lbuf.c_ispeed;
01297             buf.sg_ospeed = lbuf.c_ospeed;
01298             buf.sg_erase = lbuf.c_cc[VERASE];
01299             buf.sg_kill = lbuf.c_cc[VKILL];
01300             buf.sg_flags = 0;   /* FIXME: this is wrong... */
01301 
01302             mem_bcopy(mem_fn, mem, Write,
01303                       /* buf */regs->regs_R[6], &buf,
01304                       sizeof(struct ss_sgttyb));
01305 
01306             if (regs->regs_R[2] != -1)
01307               regs->regs_R[7] = 0;
01308             else /* probably not a typewriter, return details */
01309               {
01310                 regs->regs_R[2] = errno;
01311                 regs->regs_R[7] = 1;
01312               }
01313           }
01314         else
01315 #endif
01316 
01317         if (!local_req)
01318           {
01319             /* FIXME: could not translate the ioctl() request, just warn user
01320                and ignore the request */
01321             warn("syscall: ioctl: ioctl code not supported d=%d, req=%d",
01322                  regs->regs_R[4], regs->regs_R[5]);
01323             regs->regs_R[2] = 0;
01324             regs->regs_R[7] = 0;
01325           }
01326         else
01327           {
01328 #ifdef _MSC_VER
01329             warn("syscall getgid() not yet implemented for MSC...");
01330             regs->regs_R[7] = 0;
01331             break;
01332 #else /* !_MSC_VER */
01333 
01334 #if 0 /* FIXME: needed? */
01335 #ifdef TIOCGETP
01336             if (local_req == TIOCGETP && sim_progfd)
01337               {
01338                 /* program I/O has been redirected to file, make
01339                    termios() calls fail... */
01340 
01341                 /* got an error, return details */
01342                 regs->regs_R[2] = ENOTTY;
01343                 regs->regs_R[7] = 1;
01344                 break;
01345               }
01346 #endif
01347 #endif
01348             /* ioctl() code was successfully translated to a host code */
01349 
01350             /* if arg ptr exists, copy NUM_IOCTL_BYTES bytes to host mem */
01351             if (/*argp*/regs->regs_R[6] != 0)
01352               mem_bcopy(mem_fn, mem,
01353                         Read, /*argp*/regs->regs_R[6], buf, NUM_IOCTL_BYTES);
01354 
01355             /* perform the ioctl() call */
01356             /*result*/regs->regs_R[2] =
01357               ioctl(/*fd*/regs->regs_R[4], local_req, buf);
01358 
01359             /* if arg ptr exists, copy NUM_IOCTL_BYTES bytes from host mem */
01360             if (/*argp*/regs->regs_R[6] != 0)
01361               mem_bcopy(mem_fn, mem, Write, regs->regs_R[6],
01362                         buf, NUM_IOCTL_BYTES);
01363 
01364             /* check for an error condition */
01365             if (regs->regs_R[2] != -1)
01366               regs->regs_R[7] = 0;
01367             else
01368               { 
01369                 /* got an error, return details */
01370                 regs->regs_R[2] = errno;
01371                 regs->regs_R[7] = 1;
01372               }
01373 #endif /* _MSC_VER */
01374           }
01375       }
01376       break;
01377 
01378     case SS_SYS_fstat:
01379       {
01380         struct ss_statbuf ss_sbuf;
01381 #ifdef _MSC_VER
01382         struct _stat sbuf;
01383 #else /* !_MSC_VER */
01384         struct stat sbuf;
01385 #endif /* _MSC_VER */
01386 
01387         /* fstat() the file */
01388         /*result*/regs->regs_R[2] = fstat(/*fd*/regs->regs_R[4], &sbuf);
01389 
01390         /* check for an error condition */
01391         if (regs->regs_R[2] != -1)
01392           regs->regs_R[7] = 0;
01393         else
01394           {
01395             /* got an error, return details */
01396             regs->regs_R[2] = errno;
01397             regs->regs_R[7] = 1;
01398           }
01399 
01400         /* translate the stat structure to host format */
01401         ss_sbuf.ss_st_dev = MD_SWAPH(sbuf.st_dev);
01402         ss_sbuf.ss_pad = 0;
01403         ss_sbuf.ss_st_ino = MD_SWAPW(sbuf.st_ino);
01404         ss_sbuf.ss_st_mode = MD_SWAPH(sbuf.st_mode);
01405         ss_sbuf.ss_st_nlink = MD_SWAPH(sbuf.st_nlink);
01406         ss_sbuf.ss_st_uid = MD_SWAPH(sbuf.st_uid);
01407         ss_sbuf.ss_st_gid = MD_SWAPH(sbuf.st_gid);
01408         ss_sbuf.ss_st_rdev = MD_SWAPH(sbuf.st_rdev);
01409         ss_sbuf.ss_pad1 = 0;
01410         ss_sbuf.ss_st_size = MD_SWAPW(sbuf.st_size);
01411         ss_sbuf.ss_st_atime = MD_SWAPW(sbuf.st_atime);
01412         ss_sbuf.ss_st_spare1 = 0;
01413         ss_sbuf.ss_st_mtime = MD_SWAPW(sbuf.st_mtime);
01414         ss_sbuf.ss_st_spare2 = 0;
01415         ss_sbuf.ss_st_ctime = MD_SWAPW(sbuf.st_ctime);
01416         ss_sbuf.ss_st_spare3 = 0;
01417 #ifndef _MSC_VER
01418         ss_sbuf.ss_st_blksize = MD_SWAPW(sbuf.st_blksize);
01419         ss_sbuf.ss_st_blocks = MD_SWAPW(sbuf.st_blocks);
01420 #endif /* !_MSC_VER */
01421         ss_sbuf.ss_st_gennum = 0;
01422         ss_sbuf.ss_st_spare4 = 0;
01423 
01424         /* copy fstat() results to simulator memory */
01425         mem_bcopy(mem_fn, mem, Write, /*sbuf*/regs->regs_R[5],
01426                   &ss_sbuf, sizeof(struct ss_statbuf));
01427       }
01428       break;
01429 
01430     case SS_SYS_getpagesize:
01431       /* get target pagesize */
01432       regs->regs_R[2] = /* was: getpagesize() */MD_PAGE_SIZE;
01433 
01434       /* check for an error condition */
01435       if (regs->regs_R[2] != -1)
01436         regs->regs_R[7] = 0;
01437       else
01438         {
01439           /* got an error, return details */
01440           regs->regs_R[2] = errno;
01441           regs->regs_R[7] = 1;
01442         }
01443       break;
01444 
01445     case SS_SYS_setitimer:
01446       /* FIXME: the sigvec system call is ignored */
01447       regs->regs_R[2] = regs->regs_R[7] = 0;
01448       warn("syscall: setitimer ignored");
01449       break;
01450 
01451     case SS_SYS_getdtablesize:
01452 #if defined(_AIX)
01453       /* get descriptor table size */
01454       regs->regs_R[2] = getdtablesize();
01455 
01456       /* check for an error condition */
01457       if (regs->regs_R[2] != -1)
01458         regs->regs_R[7] = 0;
01459       else
01460         {
01461           /* got an error, return details */
01462           regs->regs_R[2] = errno;
01463           regs->regs_R[7] = 1;
01464         }
01465 #elif defined(__CYGWIN32__) || defined(ultrix) || defined(_MSC_VER)
01466       {
01467         /* no comparable system call found, try some reasonable defaults */
01468         warn("syscall: called getdtablesize()\n");
01469         regs->regs_R[2] = 16;
01470         regs->regs_R[7] = 0;
01471       }
01472 #else
01473       {
01474         struct rlimit rl;
01475 
01476         /* get descriptor table size in rlimit structure */
01477         if (getrlimit(RLIMIT_NOFILE, &rl) != -1)
01478           {
01479             regs->regs_R[2] = rl.rlim_cur;
01480             regs->regs_R[7] = 0;
01481           }
01482         else
01483           {
01484             /* got an error, return details */
01485             regs->regs_R[2] = errno;
01486             regs->regs_R[7] = 1;
01487           }
01488       }
01489 #endif
01490       break;
01491 
01492     case SS_SYS_dup2:
01493       /* dup2() the file descriptor */
01494       regs->regs_R[2] =
01495         dup2(/* fd1 */regs->regs_R[4], /* fd2 */regs->regs_R[5]);
01496 
01497       /* check for an error condition */
01498       if (regs->regs_R[2] != -1)
01499         regs->regs_R[7] = 0;
01500       else
01501         {
01502           /* got an error, return details */
01503           regs->regs_R[2] = errno;
01504           regs->regs_R[7] = 1;
01505         }
01506       break;
01507 
01508     case SS_SYS_fcntl:
01509 #ifdef _MSC_VER
01510       warn("syscall fcntl() not yet implemented for MSC...");
01511       regs->regs_R[7] = 0;
01512 #else /* !_MSC_VER */
01513       /* get fcntl() information on the file */
01514       regs->regs_R[2] =
01515         fcntl(/*fd*/regs->regs_R[4], /*cmd*/regs->regs_R[5],
01516               /*arg*/regs->regs_R[6]);
01517 
01518       /* check for an error condition */
01519       if (regs->regs_R[2] != -1)
01520         regs->regs_R[7] = 0;
01521       else
01522         {
01523           /* got an error, return details */
01524           regs->regs_R[2] = errno;
01525           regs->regs_R[7] = 1;
01526         }
01527 #endif /* _MSC_VER */
01528       break;
01529 
01530     case SS_SYS_select:
01531 #ifdef _MSC_VER
01532       warn("syscall select() not yet implemented for MSC...");
01533       regs->regs_R[7] = 0;
01534 #else /* !_MSC_VER */
01535       {
01536         fd_set readfd, writefd, exceptfd;
01537         fd_set *readfdp, *writefdp, *exceptfdp;
01538         struct timeval timeout, *timeoutp;
01539         word_t param5;
01540 
01541         /* FIXME: swap words? */
01542 
01543         /* read the 5th parameter (timeout) from the stack */
01544         mem_bcopy(mem_fn, mem,
01545                   Read, regs->regs_R[29]+16, &param5, sizeof(word_t));
01546 
01547         /* copy read file descriptor set into host memory */
01548         if (/*readfd*/regs->regs_R[5] != 0)
01549           {
01550             mem_bcopy(mem_fn, mem, Read, /*readfd*/regs->regs_R[5],
01551                       &readfd, sizeof(fd_set));
01552             readfdp = &readfd;
01553           }
01554         else
01555           readfdp = NULL;
01556 
01557         /* copy write file descriptor set into host memory */
01558         if (/*writefd*/regs->regs_R[6] != 0)
01559           {
01560             mem_bcopy(mem_fn, mem, Read, /*writefd*/regs->regs_R[6],
01561                       &writefd, sizeof(fd_set));
01562             writefdp = &writefd;
01563           }
01564         else
01565           writefdp = NULL;
01566 
01567         /* copy exception file descriptor set into host memory */
01568         if (/*exceptfd*/regs->regs_R[7] != 0)
01569           {
01570             mem_bcopy(mem_fn, mem, Read, /*exceptfd*/regs->regs_R[7],
01571                       &exceptfd, sizeof(fd_set));
01572             exceptfdp = &exceptfd;
01573           }
01574         else
01575           exceptfdp = NULL;
01576 
01577         /* copy timeout value into host memory */
01578         if (/*timeout*/param5 != 0)
01579           {
01580             mem_bcopy(mem_fn, mem, Read, /*timeout*/param5,
01581                       &timeout, sizeof(struct timeval));
01582             timeoutp = &timeout;
01583           }
01584         else
01585           timeoutp = NULL;
01586 
01587 #if defined(hpux) || defined(__hpux)
01588         /* select() on the specified file descriptors */
01589         /*result*/regs->regs_R[2] =
01590           select(/*nfd*/regs->regs_R[4],
01591                  (int *)readfdp, (int *)writefdp, (int *)exceptfdp, timeoutp);
01592 #else
01593         /* select() on the specified file descriptors */
01594         /*result*/regs->regs_R[2] =
01595           select(/*nfd*/regs->regs_R[4],
01596                  readfdp, writefdp, exceptfdp, timeoutp);
01597 #endif
01598 
01599         /* check for an error condition */
01600         if (regs->regs_R[2] != -1)
01601           regs->regs_R[7] = 0;
01602         else
01603           {
01604             /* got an error, return details */
01605             regs->regs_R[2] = errno;
01606             regs->regs_R[7] = 1;
01607           }
01608 
01609         /* copy read file descriptor set to target memory */
01610         if (/*readfd*/regs->regs_R[5] != 0)
01611           mem_bcopy(mem_fn, mem, Write, /*readfd*/regs->regs_R[5],
01612                     &readfd, sizeof(fd_set));
01613 
01614         /* copy write file descriptor set to target memory */
01615         if (/*writefd*/regs->regs_R[6] != 0)
01616           mem_bcopy(mem_fn, mem, Write, /*writefd*/regs->regs_R[6],
01617                     &writefd, sizeof(fd_set));
01618 
01619         /* copy exception file descriptor set to target memory */
01620         if (/*exceptfd*/regs->regs_R[7] != 0)
01621           mem_bcopy(mem_fn, mem, Write, /*exceptfd*/regs->regs_R[7],
01622                     &exceptfd, sizeof(fd_set));
01623 
01624         /* copy timeout value result to target memory */
01625         if (/* timeout */param5 != 0)
01626           mem_bcopy(mem_fn, mem, Write, /*timeout*/param5,
01627                     &timeout, sizeof(struct timeval));
01628       }
01629 #endif
01630       break;
01631 
01632     case SS_SYS_sigvec:
01633       /* FIXME: the sigvec system call is ignored */
01634       regs->regs_R[2] = regs->regs_R[7] = 0;
01635       warn("syscall: sigvec ignored");
01636       break;
01637 
01638     case SS_SYS_sigblock:
01639       /* FIXME: the sigblock system call is ignored */
01640       regs->regs_R[2] = regs->regs_R[7] = 0;
01641       warn("syscall: sigblock ignored");
01642       break;
01643 
01644     case SS_SYS_sigsetmask:
01645       /* FIXME: the sigsetmask system call is ignored */
01646       regs->regs_R[2] = regs->regs_R[7] = 0;
01647       warn("syscall: sigsetmask ignored");
01648       break;
01649 
01650 #if 0
01651     case SS_SYS_sigstack:
01652       /* FIXME: this is broken... */
01653       /* do not make the system call; instead, modify (the stack
01654          portion of) the simulator's main memory, ignore the 1st
01655          argument (regs->regs_R[4]), as it relates to signal handling */
01656       if (regs->regs_R[5] != 0)
01657         {
01658           (*maf)(Read, regs->regs_R[29]+28, (unsigned char *)&temp, 4);
01659           (*maf)(Write, regs->regs_R[5], (unsigned char *)&temp, 4);
01660         }
01661       regs->regs_R[2] = regs->regs_R[7] = 0;
01662       break;
01663 #endif
01664 
01665     case SS_SYS_gettimeofday:
01666 #ifdef _MSC_VER
01667       warn("syscall gettimeofday() not yet implemented for MSC...");
01668       regs->regs_R[7] = 0;
01669 #else /* _MSC_VER */
01670       {
01671         struct ss_timeval ss_tv;
01672         struct timeval tv, *tvp;
01673         struct ss_timezone ss_tz;
01674         struct timezone tz, *tzp;
01675 
01676         if (/*timeval*/regs->regs_R[4] != 0)
01677           {
01678             /* copy timeval into host memory */
01679             mem_bcopy(mem_fn, mem, Read, /*timeval*/regs->regs_R[4],
01680                       &ss_tv, sizeof(struct ss_timeval));
01681 
01682             /* convert target timeval structure to host format */
01683             tv.tv_sec = MD_SWAPW(ss_tv.ss_tv_sec);
01684             tv.tv_usec = MD_SWAPW(ss_tv.ss_tv_usec);
01685             tvp = &tv;
01686           }
01687         else
01688           tvp = NULL;
01689 
01690         if (/*timezone*/regs->regs_R[5] != 0)
01691           {
01692             /* copy timezone into host memory */
01693             mem_bcopy(mem_fn, mem, Read, /*timezone*/regs->regs_R[5],
01694                       &ss_tz, sizeof(struct ss_timezone));
01695 
01696             /* convert target timezone structure to host format */
01697             tz.tz_minuteswest = MD_SWAPW(ss_tz.ss_tz_minuteswest);
01698             tz.tz_dsttime = MD_SWAPW(ss_tz.ss_tz_dsttime);
01699             tzp = &tz;
01700           }
01701         else
01702           tzp = NULL;
01703 
01704         /* get time of day */
01705         /*result*/regs->regs_R[2] = gettimeofday(tvp, tzp);
01706 
01707         /* check for an error condition */
01708         if (regs->regs_R[2] != -1)
01709           regs->regs_R[7] = 0;
01710         else
01711           {
01712             /* got an error, indicate result */
01713             regs->regs_R[2] = errno;
01714             regs->regs_R[7] = 1;
01715           }
01716 
01717         if (/*timeval*/regs->regs_R[4] != 0)
01718           {
01719             /* convert host timeval structure to target format */
01720             ss_tv.ss_tv_sec = MD_SWAPW(tv.tv_sec);
01721             ss_tv.ss_tv_usec = MD_SWAPW(tv.tv_usec);
01722 
01723             /* copy timeval to target memory */
01724             mem_bcopy(mem_fn, mem, Write, /*timeval*/regs->regs_R[4],
01725                       &ss_tv, sizeof(struct ss_timeval));
01726           }
01727 
01728         if (/*timezone*/regs->regs_R[5] != 0)
01729           {
01730             /* convert host timezone structure to target format */
01731             ss_tz.ss_tz_minuteswest = MD_SWAPW(tz.tz_minuteswest);
01732             ss_tz.ss_tz_dsttime = MD_SWAPW(tz.tz_dsttime);
01733 
01734             /* copy timezone to target memory */
01735             mem_bcopy(mem_fn, mem, Write, /*timezone*/regs->regs_R[5],
01736                       &ss_tz, sizeof(struct ss_timezone));
01737           }
01738       }
01739 #endif /* !_MSC_VER */
01740       break;
01741 
01742     case SS_SYS_getrusage:
01743 #if defined(__svr4__) || defined(__USLC__) || defined(hpux) || defined(__hpux) || defined(_AIX)
01744       {
01745         struct tms tms_buf;
01746         struct ss_rusage rusage;
01747 
01748         /* get user and system times */
01749         if (times(&tms_buf) != -1)
01750           {
01751             /* no error */
01752             regs->regs_R[2] = 0;
01753             regs->regs_R[7] = 0;
01754           }
01755         else
01756           {
01757             /* got an error, indicate result */
01758             regs->regs_R[2] = errno;
01759             regs->regs_R[7] = 1;
01760           }
01761 
01762         /* initialize target rusage result structure */
01763 #if defined(__svr4__)
01764         memset(&rusage, '\0', sizeof(struct ss_rusage));
01765 #else /* !defined(__svr4__) */
01766         bzero(&rusage, sizeof(struct ss_rusage));
01767 #endif
01768 
01769         /* convert from host rusage structure to target format */
01770         rusage.ss_ru_utime.ss_tv_sec = tms_buf.tms_utime/CLK_TCK;
01771         rusage.ss_ru_utime.ss_tv_sec = MD_SWAPW(rusage.ss_ru_utime.ss_tv_sec);
01772         rusage.ss_ru_utime.ss_tv_usec = 0;
01773         rusage.ss_ru_stime.ss_tv_sec = tms_buf.tms_stime/CLK_TCK;
01774         rusage.ss_ru_stime.ss_tv_sec = MD_SWAPW(rusage.ss_ru_stime.ss_tv_sec);
01775         rusage.ss_ru_stime.ss_tv_usec = 0;
01776 
01777         /* copy rusage results into target memory */
01778         mem_bcopy(mem_fn, mem, Write, /*rusage*/regs->regs_R[5],
01779                   &rusage, sizeof(struct ss_rusage));
01780       }
01781 #elif defined(__unix__) || defined(unix)
01782       {
01783         struct rusage local_rusage;
01784         struct ss_rusage rusage;
01785 
01786         /* get rusage information */
01787         /*result*/regs->regs_R[2] =
01788           getrusage(/*who*/regs->regs_R[4], &local_rusage);
01789 
01790         /* check for an error condition */
01791         if (regs->regs_R[2] != -1)
01792           regs->regs_R[7] = 0;
01793         else
01794           {
01795             /* got an error, indicate result */
01796             regs->regs_R[2] = errno;
01797             regs->regs_R[7] = 1;
01798           }
01799 
01800         /* convert from host rusage structure to target format */
01801         rusage.ss_ru_utime.ss_tv_sec = local_rusage.ru_utime.tv_sec;
01802         rusage.ss_ru_utime.ss_tv_usec = local_rusage.ru_utime.tv_usec;
01803         rusage.ss_ru_utime.ss_tv_sec = MD_SWAPW(local_rusage.ru_utime.tv_sec);
01804         rusage.ss_ru_utime.ss_tv_usec =
01805           MD_SWAPW(local_rusage.ru_utime.tv_usec);
01806         rusage.ss_ru_stime.ss_tv_sec = local_rusage.ru_stime.tv_sec;
01807         rusage.ss_ru_stime.ss_tv_usec = local_rusage.ru_stime.tv_usec;
01808         rusage.ss_ru_stime.ss_tv_sec =
01809           MD_SWAPW(local_rusage.ru_stime.tv_sec);
01810         rusage.ss_ru_stime.ss_tv_usec =
01811           MD_SWAPW(local_rusage.ru_stime.tv_usec);
01812         rusage.ss_ru_maxrss = MD_SWAPW(local_rusage.ru_maxrss);
01813         rusage.ss_ru_ixrss = MD_SWAPW(local_rusage.ru_ixrss);
01814         rusage.ss_ru_idrss = MD_SWAPW(local_rusage.ru_idrss);
01815         rusage.ss_ru_isrss = MD_SWAPW(local_rusage.ru_isrss);
01816         rusage.ss_ru_minflt = MD_SWAPW(local_rusage.ru_minflt);
01817         rusage.ss_ru_majflt = MD_SWAPW(local_rusage.ru_majflt);
01818         rusage.ss_ru_nswap = MD_SWAPW(local_rusage.ru_nswap);
01819         rusage.ss_ru_inblock = MD_SWAPW(local_rusage.ru_inblock);
01820         rusage.ss_ru_oublock = MD_SWAPW(local_rusage.ru_oublock);
01821         rusage.ss_ru_msgsnd = MD_SWAPW(local_rusage.ru_msgsnd);
01822         rusage.ss_ru_msgrcv = MD_SWAPW(local_rusage.ru_msgrcv);
01823         rusage.ss_ru_nsignals = MD_SWAPW(local_rusage.ru_nsignals);
01824         rusage.ss_ru_nvcsw = MD_SWAPW(local_rusage.ru_nvcsw);
01825         rusage.ss_ru_nivcsw = MD_SWAPW(local_rusage.ru_nivcsw);
01826 
01827         /* copy rusage results into target memory */
01828         mem_bcopy(mem_fn, mem, Write, /*rusage*/regs->regs_R[5],
01829                   &rusage, sizeof(struct ss_rusage));
01830       }
01831 #elif defined(__CYGWIN32__) || defined(_MSC_VER)
01832             warn("syscall: called getrusage()\n");
01833             regs->regs_R[7] = 0;
01834 #else
01835 #error No getrusage() implementation!
01836 #endif
01837       break;
01838 
01839     case SS_SYS_writev:
01840 #ifdef _MSC_VER
01841       warn("syscall writev() not yet implemented for MSC...");
01842       regs->regs_R[7] = 0;
01843 #else /* !_MSC_VER */
01844       {
01845         int i;
01846         char *buf;
01847         struct iovec *iov;
01848 
01849         /* allocate host side I/O vectors */
01850         iov =
01851           (struct iovec *)malloc(/*iovcnt*/regs->regs_R[6]
01852                                  * sizeof(struct iovec));
01853         if (!iov)
01854           fatal("out of virtual memory in SYS_writev");
01855 
01856         /* copy target side pointer data into host side vector */
01857         mem_bcopy(mem_fn, mem, Read, /*iov*/regs->regs_R[5],
01858                   iov, /*iovcnt*/regs->regs_R[6] * sizeof(struct iovec));
01859 
01860         /* copy target side I/O vector buffers to host memory */
01861         for (i=0; i < /*iovcnt*/regs->regs_R[6]; i++)
01862           {
01863             iov[i].iov_base = (char *)MD_SWAPW((unsigned)iov[i].iov_base);
01864             iov[i].iov_len = MD_SWAPW(iov[i].iov_len);
01865             if (iov[i].iov_base != NULL)
01866               {
01867                 buf = (char *)calloc(iov[i].iov_len, sizeof(char));
01868                 if (!buf)
01869                   fatal("out of virtual memory in SYS_writev");
01870                 mem_bcopy(mem_fn, mem, Read, (md_addr_t)iov[i].iov_base,
01871                           buf, iov[i].iov_len);
01872                 iov[i].iov_base = buf;
01873               }
01874           }
01875 
01876         /* perform the vector'ed write */
01877         /*result*/regs->regs_R[2] =
01878           writev(/*fd*/regs->regs_R[4], iov, /*iovcnt*/regs->regs_R[6]);
01879 
01880         /* check for an error condition */
01881         if (regs->regs_R[2] != -1)
01882           regs->regs_R[7] = 0;
01883         else
01884           {
01885             /* got an error, indicate results */
01886             regs->regs_R[2] = errno;
01887             regs->regs_R[7] = 1;
01888           }
01889 
01890         /* free all the allocated memory */
01891         for (i=0; i < /*iovcnt*/regs->regs_R[6]; i++)
01892           {
01893             if (iov[i].iov_base)
01894               {
01895                 free(iov[i].iov_base);
01896                 iov[i].iov_base = NULL;
01897               }
01898           }
01899         free(iov);
01900       }
01901 #endif /* !_MSC_VER */
01902       break;
01903 
01904     case SS_SYS_utimes:
01905       {
01906         char buf[MAXBUFSIZE];
01907 
01908         /* copy filename to host memory */
01909         mem_strcpy(mem_fn, mem, Read, /*fname*/regs->regs_R[4], buf);
01910 
01911         if (/*timeval*/regs->regs_R[5] == 0)
01912           {
01913 #if defined(hpux) || defined(__hpux) || defined(__i386__)
01914             /* no utimes() in hpux, use utime() instead */
01915             /*result*/regs->regs_R[2] = utime(buf, NULL);
01916 #elif defined(_MSC_VER)
01917             /* no utimes() in MSC, use utime() instead */
01918             /*result*/regs->regs_R[2] = utime(buf, NULL);
01919 #elif defined(__svr4__) || defined(__USLC__) || defined(unix) || defined(_AIX) || defined(__alpha)
01920             /*result*/regs->regs_R[2] = utimes(buf, NULL);
01921 #elif defined(__CYGWIN32__)
01922             warn("syscall: called utimes()\n");
01923 #else
01924 #error No utimes() implementation!
01925 #endif
01926           }
01927         else
01928           {
01929             struct ss_timeval ss_tval[2];
01930 #ifndef _MSC_VER
01931             struct timeval tval[2];
01932 #endif /* !_MSC_VER */
01933 
01934             /* copy timeval structure to host memory */
01935             mem_bcopy(mem_fn, mem, Read, /*timeout*/regs->regs_R[5],
01936                       ss_tval, 2*sizeof(struct ss_timeval));
01937 
01938 #ifndef _MSC_VER
01939             /* convert timeval structure to host format */
01940             tval[0].tv_sec = MD_SWAPW(ss_tval[0].ss_tv_sec);
01941             tval[0].tv_usec = MD_SWAPW(ss_tval[0].ss_tv_usec);
01942             tval[1].tv_sec = MD_SWAPW(ss_tval[1].ss_tv_sec);
01943             tval[1].tv_usec = MD_SWAPW(ss_tval[1].ss_tv_usec);
01944 #endif /* !_MSC_VER */
01945 
01946 #if defined(hpux) || defined(__hpux) || defined(__svr4__)
01947             /* no utimes() in hpux, use utime() instead */
01948             {
01949               struct utimbuf ubuf;
01950 
01951               ubuf.actime = tval[0].tv_sec;
01952               ubuf.modtime = tval[1].tv_sec;
01953 
01954               /* result */regs->regs_R[2] = utime(buf, &ubuf);
01955             }
01956 #elif defined(_MSC_VER)
01957             /* no utimes() in MSC, use utime() instead */
01958             {
01959               struct _utimbuf ubuf;
01960 
01961               ubuf.actime = ss_tval[0].ss_tv_sec;
01962               ubuf.modtime = ss_tval[1].ss_tv_sec;
01963 
01964               /* result */regs->regs_R[2] = utime(buf, &ubuf);
01965             }
01966 #elif defined(__USLC__) || defined(unix) || defined(_AIX) || defined(__alpha)
01967             /* result */regs->regs_R[2] = utimes(buf, tval);
01968 #elif defined(__CYGWIN32__)
01969             warn("syscall: called utimes()\n");
01970 #else
01971 #error No utimes() implementation!
01972 #endif
01973           }
01974 
01975         /* check for an error condition */
01976         if (regs->regs_R[2] != -1)
01977           regs->regs_R[7] = 0;
01978         else
01979           {
01980             /* got an error, indicate results */
01981             regs->regs_R[2] = errno;
01982             regs->regs_R[7] = 1;
01983           }
01984       }
01985       break;
01986 
01987     case SS_SYS_getrlimit:
01988     case SS_SYS_setrlimit:
01989 #ifdef _MSC_VER
01990       warn("syscall get/setrlimit() not yet implemented for MSC...");
01991       regs->regs_R[7] = 0;
01992 #elif defined(__CYGWIN32__)
01993       warn("syscall: called get/setrlimit()\n");
01994       regs->regs_R[7] = 0;
01995 #else
01996       {
01997         /* FIXME: check this..., was: struct rlimit ss_rl; */
01998         struct ss_rlimit ss_rl;
01999         struct rlimit rl;
02000 
02001         /* copy rlimit structure to host memory */
02002         mem_bcopy(mem_fn, mem, Read, /*rlimit*/regs->regs_R[5],
02003                   &ss_rl, sizeof(struct ss_rlimit));
02004 
02005         /* convert rlimit structure to host format */
02006         rl.rlim_cur = MD_SWAPW(ss_rl.ss_rlim_cur);
02007         rl.rlim_max = MD_SWAPW(ss_rl.ss_rlim_max);
02008 
02009         /* get rlimit information */
02010         if (syscode == SS_SYS_getrlimit)
02011           /*result*/regs->regs_R[2] = getrlimit(regs->regs_R[4], &rl);
02012         else /* syscode == SS_SYS_setrlimit */
02013           /*result*/regs->regs_R[2] = setrlimit(regs->regs_R[4], &rl);
02014 
02015         /* check for an error condition */
02016         if (regs->regs_R[2] != -1)
02017           regs->regs_R[7] = 0;
02018         else
02019           {
02020             /* got an error, indicate results */
02021             regs->regs_R[2] = errno;
02022             regs->regs_R[7] = 1;
02023           }
02024 
02025         /* convert rlimit structure to target format */
02026         ss_rl.ss_rlim_cur = MD_SWAPW(rl.rlim_cur);
02027         ss_rl.ss_rlim_max = MD_SWAPW(rl.rlim_max);
02028 
02029         /* copy rlimit structure to target memory */
02030         mem_bcopy(mem_fn, mem, Write, /*rlimit*/regs->regs_R[5],
02031                   &ss_rl, sizeof(struct ss_rlimit));
02032       }
02033 #endif
02034       break;
02035 
02036 #if 0
02037     case SS_SYS_getdirentries:
02038       /* FIXME: this is currently broken due to incompatabilities in
02039          disk directory formats */
02040       {
02041         unsigned int i;
02042         char *buf;
02043         int base;
02044 
02045         buf = (char *)calloc(/* nbytes */regs->regs_R[6] + 1, sizeof(char));
02046         if (!buf)
02047           fatal("out of memory in SYS_getdirentries");
02048 
02049         /* copy in */
02050         for (i=0; i</* nbytes */regs->regs_R[6]; i++)
02051           (*maf)(Read, /* buf */regs->regs_R[5]+i,
02052                  (unsigned char *)&buf[i], 1);
02053         (*maf)(Read, /* basep */regs->regs_R[7], (unsigned char *)&base, 4);
02054 
02055         /*cc*/regs->regs_R[2] =
02056           getdirentries(/*fd*/regs->regs_R[4], buf,
02057                         /*nbytes*/regs->regs_R[6], &base);
02058 
02059         if (regs->regs_R[2] != -1)
02060           regs->regs_R[7] = 0;
02061         else
02062           {
02063             regs->regs_R[2] = errno;
02064             regs->regs_R[7] = 1;
02065           }
02066 
02067         /* copy out */
02068         for (i=0; i</* nbytes */regs->regs_R[6]; i++)
02069           (*maf)(Write, /* buf */regs->regs_R[5]+i,
02070                  (unsigned char *)&buf[i], 1);
02071         (*maf)(Write, /* basep */regs->regs_R[7], (unsigned char *)&base, 4);
02072 
02073         free(buf);
02074       }
02075       break;
02076 #endif
02077 
02078     default:
02079       panic("invalid/unimplemented system call encountered, code %d", syscode);
02080     }
02081 
02082 #endif /* MD_CROSS_ENDIAN */
02083 
02084 }


Variable Documentation

int local_flag
 

Definition at line 603 of file target-pisa/syscall.c.

int ss_flag
 

Definition at line 602 of file target-pisa/syscall.c.

struct { ... } ss_flag_table[]
 

Referenced by sys_syscall().



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