OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-6.8/] [pre-binutils-2.20.1-sync/] [sim/] [ppc/] [emul_unix.c] - Diff between revs 24 and 157

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 24 Rev 157
/*  This file is part of the program psim.
/*  This file is part of the program psim.
 
 
    Copyright (C) 1996-1998, Andrew Cagney <cagney@highland.com.au>
    Copyright (C) 1996-1998, Andrew Cagney <cagney@highland.com.au>
 
 
    This program is free software; you can redistribute it and/or modify
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    (at your option) any later version.
 
 
    This program is distributed in the hope that it will be useful,
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    GNU General Public License for more details.
 
 
    You should have received a copy of the GNU General Public License
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 
    */
    */
 
 
 
 
#ifndef _EMUL_UNIX_C_
#ifndef _EMUL_UNIX_C_
#define _EMUL_UNIX_C_
#define _EMUL_UNIX_C_
 
 
 
 
/* Note: this module is called via a table.  There is no benefit in
/* Note: this module is called via a table.  There is no benefit in
   making it inline */
   making it inline */
 
 
#include "emul_generic.h"
#include "emul_generic.h"
#include "emul_unix.h"
#include "emul_unix.h"
 
 
#ifdef HAVE_STRING_H
#ifdef HAVE_STRING_H
#include <string.h>
#include <string.h>
#else
#else
#ifdef HAVE_STRINGS_H
#ifdef HAVE_STRINGS_H
#include <strings.h>
#include <strings.h>
#endif
#endif
#endif
#endif
 
 
#ifdef HAVE_SYS_TYPES_H
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#include <sys/types.h>
#endif
#endif
 
 
#ifdef HAVE_SYS_TYPES_H
#ifdef HAVE_SYS_TYPES_H
#include <sys/stat.h>
#include <sys/stat.h>
#else
#else
#undef HAVE_STAT
#undef HAVE_STAT
#undef HAVE_LSTAT
#undef HAVE_LSTAT
#undef HAVE_FSTAT
#undef HAVE_FSTAT
#endif
#endif
 
 
#include <stdio.h>
#include <stdio.h>
#include <signal.h>
#include <signal.h>
#include <errno.h>
#include <errno.h>
 
 
#ifdef HAVE_FCNTL_H
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#include <fcntl.h>
#endif
#endif
 
 
#ifdef HAVE_SYS_PARAM_H
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#include <sys/param.h>
#endif
#endif
 
 
#ifdef HAVE_SYS_TIME_H
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#include <sys/time.h>
#endif
#endif
 
 
#ifndef HAVE_TERMIOS_STRUCTURE
#ifndef HAVE_TERMIOS_STRUCTURE
#undef HAVE_SYS_TERMIOS_H
#undef HAVE_SYS_TERMIOS_H
#undef HAVE_TCGETATTR
#undef HAVE_TCGETATTR
#else
#else
#ifndef HAVE_SYS_TERMIOS_H
#ifndef HAVE_SYS_TERMIOS_H
#undef HAVE_TERMIOS_STRUCTURE
#undef HAVE_TERMIOS_STRUCTURE
#endif
#endif
#endif
#endif
 
 
#ifdef HAVE_TERMIOS_STRUCTURE
#ifdef HAVE_TERMIOS_STRUCTURE
#include <sys/termios.h>
#include <sys/termios.h>
 
 
/* If we have TERMIOS, use that for the termio structure, since some systems
/* If we have TERMIOS, use that for the termio structure, since some systems
   don't like including both sys/termios.h and sys/termio.h at the same
   don't like including both sys/termios.h and sys/termio.h at the same
   time.  */
   time.  */
#undef  HAVE_TERMIO_STRUCTURE
#undef  HAVE_TERMIO_STRUCTURE
#undef  TCGETA
#undef  TCGETA
#undef  termio
#undef  termio
#define termio termios
#define termio termios
#endif
#endif
 
 
#ifndef HAVE_TERMIO_STRUCTURE
#ifndef HAVE_TERMIO_STRUCTURE
#undef HAVE_SYS_TERMIO_H
#undef HAVE_SYS_TERMIO_H
#else
#else
#ifndef HAVE_SYS_TERMIO_H
#ifndef HAVE_SYS_TERMIO_H
#undef HAVE_TERMIO_STRUCTURE
#undef HAVE_TERMIO_STRUCTURE
#endif
#endif
#endif
#endif
 
 
#ifdef HAVE_TERMIO_STRUCTURE
#ifdef HAVE_TERMIO_STRUCTURE
#include <sys/termio.h>
#include <sys/termio.h>
#endif
#endif
 
 
#ifdef HAVE_GETRUSAGE
#ifdef HAVE_GETRUSAGE
#ifndef HAVE_SYS_RESOURCE_H
#ifndef HAVE_SYS_RESOURCE_H
#undef HAVE_GETRUSAGE
#undef HAVE_GETRUSAGE
#endif
#endif
#endif
#endif
 
 
#ifdef HAVE_GETRUSAGE
#ifdef HAVE_GETRUSAGE
#include <sys/resource.h>
#include <sys/resource.h>
int getrusage();
int getrusage();
#endif
#endif
 
 
#if HAVE_DIRENT_H
#if HAVE_DIRENT_H
# include <dirent.h>
# include <dirent.h>
# define NAMLEN(dirent) strlen((dirent)->d_name)
# define NAMLEN(dirent) strlen((dirent)->d_name)
#else
#else
# define dirent direct
# define dirent direct
# define NAMLEN(dirent) (dirent)->d_namlen
# define NAMLEN(dirent) (dirent)->d_namlen
# if HAVE_SYS_NDIR_H
# if HAVE_SYS_NDIR_H
#  include <sys/ndir.h>
#  include <sys/ndir.h>
# endif
# endif
# if HAVE_SYS_DIR_H
# if HAVE_SYS_DIR_H
#  include <sys/dir.h>
#  include <sys/dir.h>
# endif
# endif
# if HAVE_NDIR_H
# if HAVE_NDIR_H
#  include <ndir.h>
#  include <ndir.h>
# endif
# endif
#endif
#endif
 
 
#ifdef HAVE_UNISTD_H
#ifdef HAVE_UNISTD_H
#undef MAXPATHLEN               /* sys/param.h might define this also */
#undef MAXPATHLEN               /* sys/param.h might define this also */
#include <unistd.h>
#include <unistd.h>
#endif
#endif
 
 
#ifdef HAVE_STDLIB_H
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#include <stdlib.h>
#endif
#endif
 
 
#if defined(BSD) && !defined(errno) && (BSD < 199306)   /* here BSD as just a bug */
#if defined(BSD) && !defined(errno) && (BSD < 199306)   /* here BSD as just a bug */
extern int errno;
extern int errno;
#endif
#endif
 
 
#ifndef STATIC_INLINE_EMUL_UNIX
#ifndef STATIC_INLINE_EMUL_UNIX
#define STATIC_INLINE_EMUL_UNIX STATIC_INLINE
#define STATIC_INLINE_EMUL_UNIX STATIC_INLINE
#endif
#endif
 
 
#ifndef PATH_MAX
#ifndef PATH_MAX
#define PATH_MAX 1024
#define PATH_MAX 1024
#endif
#endif
 
 
#ifndef EINVAL
#ifndef EINVAL
#define EINVAL -1
#define EINVAL -1
#endif
#endif
 
 
/* UNIX's idea of what is needed to implement emulations */
/* UNIX's idea of what is needed to implement emulations */
 
 
struct _os_emul_data {
struct _os_emul_data {
  device *vm;
  device *vm;
  emul_syscall *syscalls;
  emul_syscall *syscalls;
};
};
 
 


/* Emulation of simple UNIX system calls that are common on all systems.  */
/* Emulation of simple UNIX system calls that are common on all systems.  */
 
 
/* Structures that are common agmonst the UNIX varients */
/* Structures that are common agmonst the UNIX varients */
struct unix_timeval {
struct unix_timeval {
  signed32 tv_sec;              /* seconds */
  signed32 tv_sec;              /* seconds */
  signed32 tv_usec;             /* microseconds */
  signed32 tv_usec;             /* microseconds */
};
};
 
 
struct unix_timezone {
struct unix_timezone {
  signed32 tz_minuteswest;      /* minutes west of Greenwich */
  signed32 tz_minuteswest;      /* minutes west of Greenwich */
  signed32 tz_dsttime;          /* type of dst correction */
  signed32 tz_dsttime;          /* type of dst correction */
};
};
 
 
#define UNIX_RUSAGE_SELF        0
#define UNIX_RUSAGE_SELF        0
#define UNIX_RUSAGE_CHILDREN    (-1)
#define UNIX_RUSAGE_CHILDREN    (-1)
#define UNIX_RUSAGE_BOTH        (-2)    /* sys_wait4() uses this */
#define UNIX_RUSAGE_BOTH        (-2)    /* sys_wait4() uses this */
 
 
struct  unix_rusage {
struct  unix_rusage {
        struct unix_timeval ru_utime;   /* user time used */
        struct unix_timeval ru_utime;   /* user time used */
        struct unix_timeval ru_stime;   /* system time used */
        struct unix_timeval ru_stime;   /* system time used */
        signed32 ru_maxrss;             /* maximum resident set size */
        signed32 ru_maxrss;             /* maximum resident set size */
        signed32 ru_ixrss;              /* integral shared memory size */
        signed32 ru_ixrss;              /* integral shared memory size */
        signed32 ru_idrss;              /* integral unshared data size */
        signed32 ru_idrss;              /* integral unshared data size */
        signed32 ru_isrss;              /* integral unshared stack size */
        signed32 ru_isrss;              /* integral unshared stack size */
        signed32 ru_minflt;             /* any page faults not requiring I/O */
        signed32 ru_minflt;             /* any page faults not requiring I/O */
        signed32 ru_majflt;             /* any page faults requiring I/O */
        signed32 ru_majflt;             /* any page faults requiring I/O */
        signed32 ru_nswap;              /* swaps */
        signed32 ru_nswap;              /* swaps */
        signed32 ru_inblock;            /* block input operations */
        signed32 ru_inblock;            /* block input operations */
        signed32 ru_oublock;            /* block output operations */
        signed32 ru_oublock;            /* block output operations */
        signed32 ru_msgsnd;             /* messages sent */
        signed32 ru_msgsnd;             /* messages sent */
        signed32 ru_msgrcv;             /* messages received */
        signed32 ru_msgrcv;             /* messages received */
        signed32 ru_nsignals;           /* signals received */
        signed32 ru_nsignals;           /* signals received */
        signed32 ru_nvcsw;              /* voluntary context switches */
        signed32 ru_nvcsw;              /* voluntary context switches */
        signed32 ru_nivcsw;             /* involuntary " */
        signed32 ru_nivcsw;             /* involuntary " */
};
};
 
 
 
 
static void
static void
do_unix_exit(os_emul_data *emul,
do_unix_exit(os_emul_data *emul,
             unsigned call,
             unsigned call,
             const int arg0,
             const int arg0,
             cpu *processor,
             cpu *processor,
             unsigned_word cia)
             unsigned_word cia)
{
{
  int status = (int)cpu_registers(processor)->gpr[arg0];
  int status = (int)cpu_registers(processor)->gpr[arg0];
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%d)\n", status);
    printf_filtered ("%d)\n", status);
 
 
  cpu_halt(processor, cia, was_exited, status);
  cpu_halt(processor, cia, was_exited, status);
}
}
 
 
 
 
static void
static void
do_unix_read(os_emul_data *emul,
do_unix_read(os_emul_data *emul,
             unsigned call,
             unsigned call,
             const int arg0,
             const int arg0,
             cpu *processor,
             cpu *processor,
             unsigned_word cia)
             unsigned_word cia)
{
{
  void *scratch_buffer;
  void *scratch_buffer;
  int d = (int)cpu_registers(processor)->gpr[arg0];
  int d = (int)cpu_registers(processor)->gpr[arg0];
  unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
  int nbytes = cpu_registers(processor)->gpr[arg0+2];
  int nbytes = cpu_registers(processor)->gpr[arg0+2];
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
    printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
 
 
  /* get a tempoary bufer */
  /* get a tempoary bufer */
  scratch_buffer = zalloc(nbytes);
  scratch_buffer = zalloc(nbytes);
 
 
  /* check if buffer exists by reading it */
  /* check if buffer exists by reading it */
  emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia);
  emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia);
 
 
  /* read */
  /* read */
  status = read (d, scratch_buffer, nbytes);
  status = read (d, scratch_buffer, nbytes);
 
 
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
  if (status > 0)
  if (status > 0)
    emul_write_buffer(scratch_buffer, buf, status, processor, cia);
    emul_write_buffer(scratch_buffer, buf, status, processor, cia);
 
 
  zfree(scratch_buffer);
  zfree(scratch_buffer);
}
}
 
 
 
 
static void
static void
do_unix_write(os_emul_data *emul,
do_unix_write(os_emul_data *emul,
              unsigned call,
              unsigned call,
              const int arg0,
              const int arg0,
              cpu *processor,
              cpu *processor,
              unsigned_word cia)
              unsigned_word cia)
{
{
  void *scratch_buffer = NULL;
  void *scratch_buffer = NULL;
  int d = (int)cpu_registers(processor)->gpr[arg0];
  int d = (int)cpu_registers(processor)->gpr[arg0];
  unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
  int nbytes = cpu_registers(processor)->gpr[arg0+2];
  int nbytes = cpu_registers(processor)->gpr[arg0+2];
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
    printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
 
 
  /* get a tempoary bufer */
  /* get a tempoary bufer */
  scratch_buffer = zalloc(nbytes); /* FIXME - nbytes == 0 */
  scratch_buffer = zalloc(nbytes); /* FIXME - nbytes == 0 */
 
 
  /* copy in */
  /* copy in */
  emul_read_buffer(scratch_buffer, buf, nbytes,
  emul_read_buffer(scratch_buffer, buf, nbytes,
                   processor, cia);
                   processor, cia);
 
 
  /* write */
  /* write */
  status = write(d, scratch_buffer, nbytes);
  status = write(d, scratch_buffer, nbytes);
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
  zfree(scratch_buffer);
  zfree(scratch_buffer);
 
 
  flush_stdoutput();
  flush_stdoutput();
}
}
 
 
 
 
static void
static void
do_unix_open(os_emul_data *emul,
do_unix_open(os_emul_data *emul,
             unsigned call,
             unsigned call,
             const int arg0,
             const int arg0,
             cpu *processor,
             cpu *processor,
             unsigned_word cia)
             unsigned_word cia)
{
{
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  char path_buf[PATH_MAX];
  char path_buf[PATH_MAX];
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  int flags = (int)cpu_registers(processor)->gpr[arg0+1];
  int flags = (int)cpu_registers(processor)->gpr[arg0+1];
  int mode = (int)cpu_registers(processor)->gpr[arg0+2];
  int mode = (int)cpu_registers(processor)->gpr[arg0+2];
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr, path, flags, mode);
    printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr, path, flags, mode);
 
 
  status = open(path, flags, mode);
  status = open(path, flags, mode);
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
 
 
 
 
static void
static void
do_unix_close(os_emul_data *emul,
do_unix_close(os_emul_data *emul,
              unsigned call,
              unsigned call,
              const int arg0,
              const int arg0,
              cpu *processor,
              cpu *processor,
              unsigned_word cia)
              unsigned_word cia)
{
{
  int d = (int)cpu_registers(processor)->gpr[arg0];
  int d = (int)cpu_registers(processor)->gpr[arg0];
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%d", d);
    printf_filtered ("%d", d);
 
 
  status = close(d);
  status = close(d);
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
 
 
 
 
static void
static void
do_unix_break(os_emul_data *emul,
do_unix_break(os_emul_data *emul,
              unsigned call,
              unsigned call,
              const int arg0,
              const int arg0,
              cpu *processor,
              cpu *processor,
              unsigned_word cia)
              unsigned_word cia)
{
{
  /* just pass this onto the `vm' device */
  /* just pass this onto the `vm' device */
  unsigned_word new_break = cpu_registers(processor)->gpr[arg0];
  unsigned_word new_break = cpu_registers(processor)->gpr[arg0];
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx", (long)cpu_registers(processor)->gpr[arg0]);
    printf_filtered ("0x%lx", (long)cpu_registers(processor)->gpr[arg0]);
 
 
  status = device_ioctl(emul->vm,
  status = device_ioctl(emul->vm,
                        processor,
                        processor,
                        cia,
                        cia,
                        device_ioctl_break,
                        device_ioctl_break,
                        new_break); /*ioctl-data*/
                        new_break); /*ioctl-data*/
 
 
  emul_write_status(processor, 0, status);
  emul_write_status(processor, 0, status);
}
}
 
 
#ifndef HAVE_ACCESS
#ifndef HAVE_ACCESS
#define do_unix_access 0
#define do_unix_access 0
#else
#else
static void
static void
do_unix_access(os_emul_data *emul,
do_unix_access(os_emul_data *emul,
               unsigned call,
               unsigned call,
               const int arg0,
               const int arg0,
               cpu *processor,
               cpu *processor,
               unsigned_word cia)
               unsigned_word cia)
{
{
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  char path_buf[PATH_MAX];
  char path_buf[PATH_MAX];
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  int mode = (int)cpu_registers(processor)->gpr[arg0+1];
  int mode = (int)cpu_registers(processor)->gpr[arg0+1];
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx [%s], 0x%x [0%o]", (long)path_addr, path, mode, mode);
    printf_filtered ("0x%lx [%s], 0x%x [0%o]", (long)path_addr, path, mode, mode);
 
 
  status = access(path, mode);
  status = access(path, mode);
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_GETPID
#ifndef HAVE_GETPID
#define do_unix_getpid 0
#define do_unix_getpid 0
#else
#else
static void
static void
do_unix_getpid(os_emul_data *emul,
do_unix_getpid(os_emul_data *emul,
               unsigned call,
               unsigned call,
               const int arg0,
               const int arg0,
               cpu *processor,
               cpu *processor,
               unsigned_word cia)
               unsigned_word cia)
{
{
  pid_t status = getpid();
  pid_t status = getpid();
  emul_write_status(processor, (int)status, errno);
  emul_write_status(processor, (int)status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_GETPPID
#ifndef HAVE_GETPPID
#define do_unix_getppid 0
#define do_unix_getppid 0
#else
#else
static void
static void
do_unix_getppid(os_emul_data *emul,
do_unix_getppid(os_emul_data *emul,
                unsigned call,
                unsigned call,
                const int arg0,
                const int arg0,
                cpu *processor,
                cpu *processor,
                unsigned_word cia)
                unsigned_word cia)
{
{
  pid_t status = getppid();
  pid_t status = getppid();
  emul_write_status(processor, (int)status, errno);
  emul_write_status(processor, (int)status, errno);
}
}
#endif
#endif
 
 
#if !defined(HAVE_GETPID) || !defined(HAVE_GETPPID)
#if !defined(HAVE_GETPID) || !defined(HAVE_GETPPID)
#define do_unix_getpid2 0
#define do_unix_getpid2 0
#else
#else
static void
static void
do_unix_getpid2(os_emul_data *emul,
do_unix_getpid2(os_emul_data *emul,
                unsigned call,
                unsigned call,
                const int arg0,
                const int arg0,
                cpu *processor,
                cpu *processor,
                unsigned_word cia)
                unsigned_word cia)
{
{
  int pid  = (int)getpid();
  int pid  = (int)getpid();
  int ppid = (int)getppid();
  int ppid = (int)getppid();
  emul_write2_status(processor, pid, ppid, errno);
  emul_write2_status(processor, pid, ppid, errno);
}
}
#endif
#endif
 
 
#if !defined(HAVE_GETUID) || !defined(HAVE_GETEUID)
#if !defined(HAVE_GETUID) || !defined(HAVE_GETEUID)
#define do_unix_getuid2 0
#define do_unix_getuid2 0
#else
#else
static void
static void
do_unix_getuid2(os_emul_data *emul,
do_unix_getuid2(os_emul_data *emul,
                unsigned call,
                unsigned call,
                const int arg0,
                const int arg0,
                cpu *processor,
                cpu *processor,
                unsigned_word cia)
                unsigned_word cia)
{
{
  uid_t uid  = getuid();
  uid_t uid  = getuid();
  uid_t euid = geteuid();
  uid_t euid = geteuid();
  emul_write2_status(processor, (int)uid, (int)euid, errno);
  emul_write2_status(processor, (int)uid, (int)euid, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_GETUID
#ifndef HAVE_GETUID
#define do_unix_getuid 0
#define do_unix_getuid 0
#else
#else
static void
static void
do_unix_getuid(os_emul_data *emul,
do_unix_getuid(os_emul_data *emul,
               unsigned call,
               unsigned call,
               const int arg0,
               const int arg0,
               cpu *processor,
               cpu *processor,
               unsigned_word cia)
               unsigned_word cia)
{
{
  uid_t status = getuid();
  uid_t status = getuid();
  emul_write_status(processor, (int)status, errno);
  emul_write_status(processor, (int)status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_GETEUID
#ifndef HAVE_GETEUID
#define do_unix_geteuid 0
#define do_unix_geteuid 0
#else
#else
static void
static void
do_unix_geteuid(os_emul_data *emul,
do_unix_geteuid(os_emul_data *emul,
                unsigned call,
                unsigned call,
                const int arg0,
                const int arg0,
                cpu *processor,
                cpu *processor,
                unsigned_word cia)
                unsigned_word cia)
{
{
  uid_t status = geteuid();
  uid_t status = geteuid();
  emul_write_status(processor, (int)status, errno);
  emul_write_status(processor, (int)status, errno);
}
}
#endif
#endif
 
 
#if 0
#if 0
#ifndef HAVE_KILL
#ifndef HAVE_KILL
#define do_unix_kill 0
#define do_unix_kill 0
#else
#else
static void
static void
do_unix_kill(os_emul_data *emul,
do_unix_kill(os_emul_data *emul,
             unsigned call,
             unsigned call,
             const int arg0,
             const int arg0,
             cpu *processor,
             cpu *processor,
             unsigned_word cia)
             unsigned_word cia)
{
{
  pid_t pid = cpu_registers(processor)->gpr[arg0];
  pid_t pid = cpu_registers(processor)->gpr[arg0];
  int sig = cpu_registers(processor)->gpr[arg0+1];
  int sig = cpu_registers(processor)->gpr[arg0+1];
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%d, %d", (int)pid, sig);
    printf_filtered ("%d, %d", (int)pid, sig);
 
 
  printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
  printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
                  (long)cia);
                  (long)cia);
 
 
  cpu_halt(processor, cia, was_signalled, sig);
  cpu_halt(processor, cia, was_signalled, sig);
}
}
#endif
#endif
#endif
#endif
 
 
#ifndef HAVE_DUP
#ifndef HAVE_DUP
#define do_unix_dup 0
#define do_unix_dup 0
#else
#else
static void
static void
do_unix_dup(os_emul_data *emul,
do_unix_dup(os_emul_data *emul,
            unsigned call,
            unsigned call,
            const int arg0,
            const int arg0,
            cpu *processor,
            cpu *processor,
            unsigned_word cia)
            unsigned_word cia)
{
{
  int oldd = cpu_registers(processor)->gpr[arg0];
  int oldd = cpu_registers(processor)->gpr[arg0];
  int status = dup(oldd);
  int status = dup(oldd);
  int err = errno;
  int err = errno;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%d", oldd);
    printf_filtered ("%d", oldd);
 
 
  emul_write_status(processor, status, err);
  emul_write_status(processor, status, err);
}
}
#endif
#endif
 
 
#ifndef HAVE_DUP2
#ifndef HAVE_DUP2
#define do_unix_dup2 0
#define do_unix_dup2 0
#else
#else
static void
static void
do_unix_dup2(os_emul_data *emul,
do_unix_dup2(os_emul_data *emul,
             unsigned call,
             unsigned call,
             const int arg0,
             const int arg0,
             cpu *processor,
             cpu *processor,
             unsigned_word cia)
             unsigned_word cia)
{
{
  int oldd = cpu_registers(processor)->gpr[arg0];
  int oldd = cpu_registers(processor)->gpr[arg0];
  int newd = cpu_registers(processor)->gpr[arg0+1];
  int newd = cpu_registers(processor)->gpr[arg0+1];
  int status = dup2(oldd, newd);
  int status = dup2(oldd, newd);
  int err = errno;
  int err = errno;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%d, %d", oldd, newd);
    printf_filtered ("%d, %d", oldd, newd);
 
 
  emul_write_status(processor, status, err);
  emul_write_status(processor, status, err);
}
}
#endif
#endif
 
 
#ifndef HAVE_LSEEK
#ifndef HAVE_LSEEK
#define do_unix_lseek 0
#define do_unix_lseek 0
#else
#else
static void
static void
do_unix_lseek(os_emul_data *emul,
do_unix_lseek(os_emul_data *emul,
              unsigned call,
              unsigned call,
              const int arg0,
              const int arg0,
              cpu *processor,
              cpu *processor,
              unsigned_word cia)
              unsigned_word cia)
{
{
  int fildes   = (int)cpu_registers(processor)->gpr[arg0];
  int fildes   = (int)cpu_registers(processor)->gpr[arg0];
  off_t offset = (off_t)cpu_registers(processor)->gpr[arg0+1];
  off_t offset = (off_t)cpu_registers(processor)->gpr[arg0+1];
  int whence   = (int)cpu_registers(processor)->gpr[arg0+2];
  int whence   = (int)cpu_registers(processor)->gpr[arg0+2];
  off_t status;
  off_t status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%d %ld %d", fildes, (long)offset, whence);
    printf_filtered ("%d %ld %d", fildes, (long)offset, whence);
 
 
  status = lseek(fildes, offset, whence);
  status = lseek(fildes, offset, whence);
  emul_write_status(processor, (int)status, errno);
  emul_write_status(processor, (int)status, errno);
}
}
#endif
#endif
 
 
 
 
#if !defined(HAVE_GETGID) || !defined(HAVE_GETEGID)
#if !defined(HAVE_GETGID) || !defined(HAVE_GETEGID)
#define do_unix_getgid2 0
#define do_unix_getgid2 0
#else
#else
static void
static void
do_unix_getgid2(os_emul_data *emul,
do_unix_getgid2(os_emul_data *emul,
                unsigned call,
                unsigned call,
                const int arg0,
                const int arg0,
                cpu *processor,
                cpu *processor,
                unsigned_word cia)
                unsigned_word cia)
{
{
  gid_t gid  = getgid();
  gid_t gid  = getgid();
  gid_t egid = getegid();
  gid_t egid = getegid();
  emul_write2_status(processor, (int)gid, (int)egid, errno);
  emul_write2_status(processor, (int)gid, (int)egid, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_GETGID
#ifndef HAVE_GETGID
#define do_unix_getgid 0
#define do_unix_getgid 0
#else
#else
static void
static void
do_unix_getgid(os_emul_data *emul,
do_unix_getgid(os_emul_data *emul,
               unsigned call,
               unsigned call,
               const int arg0,
               const int arg0,
               cpu *processor,
               cpu *processor,
               unsigned_word cia)
               unsigned_word cia)
{
{
  gid_t status = getgid();
  gid_t status = getgid();
  emul_write_status(processor, (int)status, errno);
  emul_write_status(processor, (int)status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_GETEGID
#ifndef HAVE_GETEGID
#define do_unix_getegid 0
#define do_unix_getegid 0
#else
#else
static void
static void
do_unix_getegid(os_emul_data *emul,
do_unix_getegid(os_emul_data *emul,
                unsigned call,
                unsigned call,
                const int arg0,
                const int arg0,
                cpu *processor,
                cpu *processor,
                unsigned_word cia)
                unsigned_word cia)
{
{
  gid_t status = getegid();
  gid_t status = getegid();
  emul_write_status(processor, (int)status, errno);
  emul_write_status(processor, (int)status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_UMASK
#ifndef HAVE_UMASK
#define do_unix_umask 0
#define do_unix_umask 0
#else
#else
static void
static void
do_unix_umask(os_emul_data *emul,
do_unix_umask(os_emul_data *emul,
              unsigned call,
              unsigned call,
              const int arg0,
              const int arg0,
              cpu *processor,
              cpu *processor,
              unsigned_word cia)
              unsigned_word cia)
{
{
  mode_t mask = (mode_t)cpu_registers(processor)->gpr[arg0];
  mode_t mask = (mode_t)cpu_registers(processor)->gpr[arg0];
  int status = umask(mask);
  int status = umask(mask);
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0%o", (unsigned int)mask);
    printf_filtered ("0%o", (unsigned int)mask);
 
 
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_CHDIR
#ifndef HAVE_CHDIR
#define do_unix_chdir 0
#define do_unix_chdir 0
#else
#else
static void
static void
do_unix_chdir(os_emul_data *emul,
do_unix_chdir(os_emul_data *emul,
              unsigned call,
              unsigned call,
              const int arg0,
              const int arg0,
              cpu *processor,
              cpu *processor,
              unsigned_word cia)
              unsigned_word cia)
{
{
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  char path_buf[PATH_MAX];
  char path_buf[PATH_MAX];
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx [%s]", (long)path_addr, path);
    printf_filtered ("0x%lx [%s]", (long)path_addr, path);
 
 
  status = chdir(path);
  status = chdir(path);
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_LINK
#ifndef HAVE_LINK
#define do_unix_link 0
#define do_unix_link 0
#else
#else
static void
static void
do_unix_link(os_emul_data *emul,
do_unix_link(os_emul_data *emul,
             unsigned call,
             unsigned call,
             const int arg0,
             const int arg0,
             cpu *processor,
             cpu *processor,
             unsigned_word cia)
             unsigned_word cia)
{
{
  unsigned_word path1_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word path1_addr = cpu_registers(processor)->gpr[arg0];
  char path1_buf[PATH_MAX];
  char path1_buf[PATH_MAX];
  char *path1 = emul_read_string(path1_buf, path1_addr, PATH_MAX, processor, cia);
  char *path1 = emul_read_string(path1_buf, path1_addr, PATH_MAX, processor, cia);
  unsigned_word path2_addr = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word path2_addr = cpu_registers(processor)->gpr[arg0+1];
  char path2_buf[PATH_MAX];
  char path2_buf[PATH_MAX];
  char *path2 = emul_read_string(path2_buf, path2_addr, PATH_MAX, processor, cia);
  char *path2 = emul_read_string(path2_buf, path2_addr, PATH_MAX, processor, cia);
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr, path1, (long)path2_addr, path2);
    printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr, path1, (long)path2_addr, path2);
 
 
  status = link(path1, path2);
  status = link(path1, path2);
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_SYMLINK
#ifndef HAVE_SYMLINK
#define do_unix_symlink 0
#define do_unix_symlink 0
#else
#else
static void
static void
do_unix_symlink(os_emul_data *emul,
do_unix_symlink(os_emul_data *emul,
                unsigned call,
                unsigned call,
                const int arg0,
                const int arg0,
                cpu *processor,
                cpu *processor,
                unsigned_word cia)
                unsigned_word cia)
{
{
  unsigned_word path1_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word path1_addr = cpu_registers(processor)->gpr[arg0];
  char path1_buf[PATH_MAX];
  char path1_buf[PATH_MAX];
  char *path1 = emul_read_string(path1_buf, path1_addr, PATH_MAX, processor, cia);
  char *path1 = emul_read_string(path1_buf, path1_addr, PATH_MAX, processor, cia);
  unsigned_word path2_addr = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word path2_addr = cpu_registers(processor)->gpr[arg0+1];
  char path2_buf[PATH_MAX];
  char path2_buf[PATH_MAX];
  char *path2 = emul_read_string(path2_buf, path2_addr, PATH_MAX, processor, cia);
  char *path2 = emul_read_string(path2_buf, path2_addr, PATH_MAX, processor, cia);
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr, path1, (long)path2_addr, path2);
    printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr, path1, (long)path2_addr, path2);
 
 
  status = symlink(path1, path2);
  status = symlink(path1, path2);
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_UNLINK
#ifndef HAVE_UNLINK
#define do_unix_unlink 0
#define do_unix_unlink 0
#else
#else
static void
static void
do_unix_unlink(os_emul_data *emul,
do_unix_unlink(os_emul_data *emul,
               unsigned call,
               unsigned call,
               const int arg0,
               const int arg0,
               cpu *processor,
               cpu *processor,
               unsigned_word cia)
               unsigned_word cia)
{
{
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  char path_buf[PATH_MAX];
  char path_buf[PATH_MAX];
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx [%s]", (long)path_addr, path);
    printf_filtered ("0x%lx [%s]", (long)path_addr, path);
 
 
  status = unlink(path);
  status = unlink(path);
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_MKDIR
#ifndef HAVE_MKDIR
#define do_unix_mkdir 0
#define do_unix_mkdir 0
#else
#else
static void
static void
do_unix_mkdir(os_emul_data *emul,
do_unix_mkdir(os_emul_data *emul,
              unsigned call,
              unsigned call,
              const int arg0,
              const int arg0,
              cpu *processor,
              cpu *processor,
              unsigned_word cia)
              unsigned_word cia)
{
{
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  char path_buf[PATH_MAX];
  char path_buf[PATH_MAX];
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  int mode = (int)cpu_registers(processor)->gpr[arg0+1];
  int mode = (int)cpu_registers(processor)->gpr[arg0+1];
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx [%s], 0%3o", (long)path_addr, path, mode);
    printf_filtered ("0x%lx [%s], 0%3o", (long)path_addr, path, mode);
 
 
#ifdef USE_WIN32API
#ifdef USE_WIN32API
  status = mkdir(path);
  status = mkdir(path);
#else
#else
  status = mkdir(path, mode);
  status = mkdir(path, mode);
#endif
#endif
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_RMDIR
#ifndef HAVE_RMDIR
#define do_unix_rmdir 0
#define do_unix_rmdir 0
#else
#else
static void
static void
do_unix_rmdir(os_emul_data *emul,
do_unix_rmdir(os_emul_data *emul,
              unsigned call,
              unsigned call,
              const int arg0,
              const int arg0,
              cpu *processor,
              cpu *processor,
              unsigned_word cia)
              unsigned_word cia)
{
{
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  char path_buf[PATH_MAX];
  char path_buf[PATH_MAX];
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx [%s]", (long)path_addr, path);
    printf_filtered ("0x%lx [%s]", (long)path_addr, path);
 
 
  status = rmdir(path);
  status = rmdir(path);
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_TIME
#ifndef HAVE_TIME
#define do_unix_time 0
#define do_unix_time 0
#else
#else
static void
static void
do_unix_time(os_emul_data *emul,
do_unix_time(os_emul_data *emul,
             unsigned call,
             unsigned call,
             const int arg0,
             const int arg0,
             cpu *processor,
             cpu *processor,
             unsigned_word cia)
             unsigned_word cia)
{
{
  unsigned_word tp = cpu_registers(processor)->gpr[arg0];
  unsigned_word tp = cpu_registers(processor)->gpr[arg0];
  time_t now = time ((time_t *)0);
  time_t now = time ((time_t *)0);
  unsigned_word status = H2T_4(now);
  unsigned_word status = H2T_4(now);
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx", (long)tp);
    printf_filtered ("0x%lx", (long)tp);
 
 
  emul_write_status(processor, (int)status, errno);
  emul_write_status(processor, (int)status, errno);
 
 
  if (tp)
  if (tp)
    emul_write_buffer(&status, tp, sizeof(status), processor, cia);
    emul_write_buffer(&status, tp, sizeof(status), processor, cia);
}
}
#endif
#endif
 
 
#if !defined(HAVE_GETTIMEOFDAY) || !defined(HAVE_SYS_TIME_H)
#if !defined(HAVE_GETTIMEOFDAY) || !defined(HAVE_SYS_TIME_H)
#define do_unix_gettimeofday 0
#define do_unix_gettimeofday 0
#else
#else
static void
static void
do_unix_gettimeofday(os_emul_data *emul,
do_unix_gettimeofday(os_emul_data *emul,
                     unsigned call,
                     unsigned call,
                     const int arg0,
                     const int arg0,
                     cpu *processor,
                     cpu *processor,
                     unsigned_word cia)
                     unsigned_word cia)
{
{
  unsigned_word tv = cpu_registers(processor)->gpr[arg0];
  unsigned_word tv = cpu_registers(processor)->gpr[arg0];
  unsigned_word tz = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word tz = cpu_registers(processor)->gpr[arg0+1];
  struct unix_timeval target_timeval;
  struct unix_timeval target_timeval;
  struct timeval host_timeval;
  struct timeval host_timeval;
  struct unix_timezone target_timezone;
  struct unix_timezone target_timezone;
  struct timezone host_timezone;
  struct timezone host_timezone;
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx, 0x%lx", (long)tv, (long)tz);
    printf_filtered ("0x%lx, 0x%lx", (long)tv, (long)tz);
 
 
  /* Just in case the system doesn't set the timezone structure */
  /* Just in case the system doesn't set the timezone structure */
  host_timezone.tz_minuteswest = 0;
  host_timezone.tz_minuteswest = 0;
  host_timezone.tz_dsttime = 0;
  host_timezone.tz_dsttime = 0;
 
 
  status = gettimeofday(&host_timeval, &host_timezone);
  status = gettimeofday(&host_timeval, &host_timezone);
  if (status >= 0) {
  if (status >= 0) {
    if (tv) {
    if (tv) {
      target_timeval.tv_sec = H2T_4(host_timeval.tv_sec);
      target_timeval.tv_sec = H2T_4(host_timeval.tv_sec);
      target_timeval.tv_usec = H2T_4(host_timeval.tv_usec);
      target_timeval.tv_usec = H2T_4(host_timeval.tv_usec);
      emul_write_buffer((void *) &target_timeval, tv, sizeof(target_timeval), processor, cia);
      emul_write_buffer((void *) &target_timeval, tv, sizeof(target_timeval), processor, cia);
    }
    }
 
 
    if (tz) {
    if (tz) {
      target_timezone.tz_minuteswest = H2T_4(host_timezone.tz_minuteswest);
      target_timezone.tz_minuteswest = H2T_4(host_timezone.tz_minuteswest);
      target_timezone.tz_dsttime = H2T_4(host_timezone.tz_dsttime);
      target_timezone.tz_dsttime = H2T_4(host_timezone.tz_dsttime);
      emul_write_buffer((void *) &target_timezone, tv, sizeof(target_timezone), processor, cia);
      emul_write_buffer((void *) &target_timezone, tv, sizeof(target_timezone), processor, cia);
    }
    }
  }
  }
 
 
  emul_write_status(processor, (int)status, errno);
  emul_write_status(processor, (int)status, errno);
}
}
#endif
#endif
 
 
 
 
#ifndef HAVE_GETRUSAGE
#ifndef HAVE_GETRUSAGE
#define do_unix_getrusage 0
#define do_unix_getrusage 0
#else
#else
static void
static void
do_unix_getrusage(os_emul_data *emul,
do_unix_getrusage(os_emul_data *emul,
                  unsigned call,
                  unsigned call,
                  const int arg0,
                  const int arg0,
                  cpu *processor,
                  cpu *processor,
                  unsigned_word cia)
                  unsigned_word cia)
{
{
  signed_word who = (signed_word)cpu_registers(processor)->gpr[arg0];
  signed_word who = (signed_word)cpu_registers(processor)->gpr[arg0];
  unsigned_word usage = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word usage = cpu_registers(processor)->gpr[arg0+1];
  struct rusage host_rusage, host_rusage2;
  struct rusage host_rusage, host_rusage2;
  struct unix_rusage target_rusage;
  struct unix_rusage target_rusage;
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%ld, 0x%lx", (long)who, (long)usage);
    printf_filtered ("%ld, 0x%lx", (long)who, (long)usage);
 
 
  switch (who) {
  switch (who) {
  default:
  default:
    status = -1;
    status = -1;
    errno = EINVAL;
    errno = EINVAL;
    break;
    break;
 
 
  case UNIX_RUSAGE_SELF:
  case UNIX_RUSAGE_SELF:
    status = getrusage(RUSAGE_SELF, &host_rusage);
    status = getrusage(RUSAGE_SELF, &host_rusage);
    break;
    break;
 
 
  case UNIX_RUSAGE_CHILDREN:
  case UNIX_RUSAGE_CHILDREN:
    status = getrusage(RUSAGE_CHILDREN, &host_rusage);
    status = getrusage(RUSAGE_CHILDREN, &host_rusage);
    break;
    break;
 
 
  case UNIX_RUSAGE_BOTH:
  case UNIX_RUSAGE_BOTH:
    status = getrusage(RUSAGE_SELF, &host_rusage);
    status = getrusage(RUSAGE_SELF, &host_rusage);
    if (status >= 0) {
    if (status >= 0) {
      status = getrusage(RUSAGE_CHILDREN, &host_rusage2);
      status = getrusage(RUSAGE_CHILDREN, &host_rusage2);
      if (status >= 0) {
      if (status >= 0) {
        host_rusage.ru_utime.tv_sec += host_rusage2.ru_utime.tv_sec;
        host_rusage.ru_utime.tv_sec += host_rusage2.ru_utime.tv_sec;
        host_rusage.ru_utime.tv_usec += host_rusage2.ru_utime.tv_usec;
        host_rusage.ru_utime.tv_usec += host_rusage2.ru_utime.tv_usec;
        host_rusage.ru_stime.tv_sec += host_rusage2.ru_stime.tv_sec;
        host_rusage.ru_stime.tv_sec += host_rusage2.ru_stime.tv_sec;
        host_rusage.ru_stime.tv_usec += host_rusage2.ru_stime.tv_usec;
        host_rusage.ru_stime.tv_usec += host_rusage2.ru_stime.tv_usec;
        host_rusage.ru_maxrss += host_rusage2.ru_maxrss;
        host_rusage.ru_maxrss += host_rusage2.ru_maxrss;
        host_rusage.ru_ixrss += host_rusage2.ru_ixrss;
        host_rusage.ru_ixrss += host_rusage2.ru_ixrss;
        host_rusage.ru_idrss += host_rusage2.ru_idrss;
        host_rusage.ru_idrss += host_rusage2.ru_idrss;
        host_rusage.ru_isrss += host_rusage2.ru_isrss;
        host_rusage.ru_isrss += host_rusage2.ru_isrss;
        host_rusage.ru_minflt += host_rusage2.ru_minflt;
        host_rusage.ru_minflt += host_rusage2.ru_minflt;
        host_rusage.ru_majflt += host_rusage2.ru_majflt;
        host_rusage.ru_majflt += host_rusage2.ru_majflt;
        host_rusage.ru_nswap += host_rusage2.ru_nswap;
        host_rusage.ru_nswap += host_rusage2.ru_nswap;
        host_rusage.ru_inblock += host_rusage2.ru_inblock;
        host_rusage.ru_inblock += host_rusage2.ru_inblock;
        host_rusage.ru_oublock += host_rusage2.ru_oublock;
        host_rusage.ru_oublock += host_rusage2.ru_oublock;
        host_rusage.ru_msgsnd += host_rusage2.ru_msgsnd;
        host_rusage.ru_msgsnd += host_rusage2.ru_msgsnd;
        host_rusage.ru_msgrcv += host_rusage2.ru_msgrcv;
        host_rusage.ru_msgrcv += host_rusage2.ru_msgrcv;
        host_rusage.ru_nsignals += host_rusage2.ru_nsignals;
        host_rusage.ru_nsignals += host_rusage2.ru_nsignals;
        host_rusage.ru_nvcsw += host_rusage2.ru_nvcsw;
        host_rusage.ru_nvcsw += host_rusage2.ru_nvcsw;
        host_rusage.ru_nivcsw += host_rusage2.ru_nivcsw;
        host_rusage.ru_nivcsw += host_rusage2.ru_nivcsw;
      }
      }
    }
    }
  }
  }
 
 
  if (status >= 0) {
  if (status >= 0) {
    target_rusage.ru_utime.tv_sec = H2T_4(host_rusage2.ru_utime.tv_sec);
    target_rusage.ru_utime.tv_sec = H2T_4(host_rusage2.ru_utime.tv_sec);
    target_rusage.ru_utime.tv_usec = H2T_4(host_rusage2.ru_utime.tv_usec);
    target_rusage.ru_utime.tv_usec = H2T_4(host_rusage2.ru_utime.tv_usec);
    target_rusage.ru_stime.tv_sec = H2T_4(host_rusage2.ru_stime.tv_sec);
    target_rusage.ru_stime.tv_sec = H2T_4(host_rusage2.ru_stime.tv_sec);
    target_rusage.ru_stime.tv_usec = H2T_4(host_rusage2.ru_stime.tv_usec);
    target_rusage.ru_stime.tv_usec = H2T_4(host_rusage2.ru_stime.tv_usec);
    target_rusage.ru_maxrss = H2T_4(host_rusage2.ru_maxrss);
    target_rusage.ru_maxrss = H2T_4(host_rusage2.ru_maxrss);
    target_rusage.ru_ixrss = H2T_4(host_rusage2.ru_ixrss);
    target_rusage.ru_ixrss = H2T_4(host_rusage2.ru_ixrss);
    target_rusage.ru_idrss = H2T_4(host_rusage2.ru_idrss);
    target_rusage.ru_idrss = H2T_4(host_rusage2.ru_idrss);
    target_rusage.ru_isrss = H2T_4(host_rusage2.ru_isrss);
    target_rusage.ru_isrss = H2T_4(host_rusage2.ru_isrss);
    target_rusage.ru_minflt = H2T_4(host_rusage2.ru_minflt);
    target_rusage.ru_minflt = H2T_4(host_rusage2.ru_minflt);
    target_rusage.ru_majflt = H2T_4(host_rusage2.ru_majflt);
    target_rusage.ru_majflt = H2T_4(host_rusage2.ru_majflt);
    target_rusage.ru_nswap = H2T_4(host_rusage2.ru_nswap);
    target_rusage.ru_nswap = H2T_4(host_rusage2.ru_nswap);
    target_rusage.ru_inblock = H2T_4(host_rusage2.ru_inblock);
    target_rusage.ru_inblock = H2T_4(host_rusage2.ru_inblock);
    target_rusage.ru_oublock = H2T_4(host_rusage2.ru_oublock);
    target_rusage.ru_oublock = H2T_4(host_rusage2.ru_oublock);
    target_rusage.ru_msgsnd = H2T_4(host_rusage2.ru_msgsnd);
    target_rusage.ru_msgsnd = H2T_4(host_rusage2.ru_msgsnd);
    target_rusage.ru_msgrcv = H2T_4(host_rusage2.ru_msgrcv);
    target_rusage.ru_msgrcv = H2T_4(host_rusage2.ru_msgrcv);
    target_rusage.ru_nsignals = H2T_4(host_rusage2.ru_nsignals);
    target_rusage.ru_nsignals = H2T_4(host_rusage2.ru_nsignals);
    target_rusage.ru_nvcsw = H2T_4(host_rusage2.ru_nvcsw);
    target_rusage.ru_nvcsw = H2T_4(host_rusage2.ru_nvcsw);
    target_rusage.ru_nivcsw = H2T_4(host_rusage2.ru_nivcsw);
    target_rusage.ru_nivcsw = H2T_4(host_rusage2.ru_nivcsw);
    emul_write_buffer((void *) &target_rusage, usage, sizeof(target_rusage), processor, cia);
    emul_write_buffer((void *) &target_rusage, usage, sizeof(target_rusage), processor, cia);
  }
  }
 
 
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
 
 
static void
static void
do_unix_nop(os_emul_data *emul,
do_unix_nop(os_emul_data *emul,
            unsigned call,
            unsigned call,
            const int arg0,
            const int arg0,
            cpu *processor,
            cpu *processor,
            unsigned_word cia)
            unsigned_word cia)
{
{
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
    printf_filtered ("0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
                     (long)cpu_registers(processor)->gpr[arg0],
                     (long)cpu_registers(processor)->gpr[arg0],
                     (long)cpu_registers(processor)->gpr[arg0+1],
                     (long)cpu_registers(processor)->gpr[arg0+1],
                     (long)cpu_registers(processor)->gpr[arg0+2],
                     (long)cpu_registers(processor)->gpr[arg0+2],
                     (long)cpu_registers(processor)->gpr[arg0+3],
                     (long)cpu_registers(processor)->gpr[arg0+3],
                     (long)cpu_registers(processor)->gpr[arg0+4],
                     (long)cpu_registers(processor)->gpr[arg0+4],
                     (long)cpu_registers(processor)->gpr[arg0+5]);
                     (long)cpu_registers(processor)->gpr[arg0+5]);
 
 
  emul_write_status(processor, 0, errno);
  emul_write_status(processor, 0, errno);
}
}
 
 


/* Common code for initializing the system call stuff */
/* Common code for initializing the system call stuff */
 
 
static os_emul_data *
static os_emul_data *
emul_unix_create(device *root,
emul_unix_create(device *root,
                 bfd *image,
                 bfd *image,
                 const char *name,
                 const char *name,
                 emul_syscall *syscall)
                 emul_syscall *syscall)
{
{
  unsigned_word top_of_stack;
  unsigned_word top_of_stack;
  unsigned stack_size;
  unsigned stack_size;
  int elf_binary;
  int elf_binary;
  os_emul_data *data;
  os_emul_data *data;
  device *vm;
  device *vm;
  char *filename;
  char *filename;
 
 
  /* merge any emulation specific entries into the device tree */
  /* merge any emulation specific entries into the device tree */
 
 
  /* establish a few defaults */
  /* establish a few defaults */
  if (image->xvec->flavour == bfd_target_elf_flavour) {
  if (image->xvec->flavour == bfd_target_elf_flavour) {
    elf_binary = 1;
    elf_binary = 1;
    top_of_stack = 0xe0000000;
    top_of_stack = 0xe0000000;
    stack_size =   0x00100000;
    stack_size =   0x00100000;
  }
  }
  else {
  else {
    elf_binary = 0;
    elf_binary = 0;
    top_of_stack = 0x20000000;
    top_of_stack = 0x20000000;
    stack_size =   0x00100000;
    stack_size =   0x00100000;
  }
  }
 
 
  /* options */
  /* options */
  emul_add_tree_options(root, image, name,
  emul_add_tree_options(root, image, name,
                        (WITH_ENVIRONMENT == USER_ENVIRONMENT
                        (WITH_ENVIRONMENT == USER_ENVIRONMENT
                         ? "user" : "virtual"),
                         ? "user" : "virtual"),
                        0 /*oea-interrupt-prefix*/);
                        0 /*oea-interrupt-prefix*/);
 
 
  /* virtual memory - handles growth of stack/heap */
  /* virtual memory - handles growth of stack/heap */
  vm = tree_parse(root, "/openprom/vm@0x%lx",
  vm = tree_parse(root, "/openprom/vm@0x%lx",
                  (unsigned long)(top_of_stack - stack_size));
                  (unsigned long)(top_of_stack - stack_size));
  tree_parse(vm, "./stack-base 0x%lx",
  tree_parse(vm, "./stack-base 0x%lx",
             (unsigned long)(top_of_stack - stack_size));
             (unsigned long)(top_of_stack - stack_size));
  tree_parse(vm, "./nr-bytes 0x%x", stack_size);
  tree_parse(vm, "./nr-bytes 0x%x", stack_size);
 
 
  filename = tree_quote_property (bfd_get_filename(image));
  filename = tree_quote_property (bfd_get_filename(image));
  tree_parse(root, "/openprom/vm/map-binary/file-name %s",
  tree_parse(root, "/openprom/vm/map-binary/file-name %s",
             filename);
             filename);
  free (filename);
  free (filename);
 
 
  /* finish the init */
  /* finish the init */
  tree_parse(root, "/openprom/init/register/pc 0x%lx",
  tree_parse(root, "/openprom/init/register/pc 0x%lx",
             (unsigned long)bfd_get_start_address(image));
             (unsigned long)bfd_get_start_address(image));
  tree_parse(root, "/openprom/init/register/sp 0x%lx",
  tree_parse(root, "/openprom/init/register/sp 0x%lx",
             (unsigned long)top_of_stack);
             (unsigned long)top_of_stack);
  tree_parse(root, "/openprom/init/register/msr 0x%x",
  tree_parse(root, "/openprom/init/register/msr 0x%x",
             ((tree_find_boolean_property(root, "/options/little-endian?")
             ((tree_find_boolean_property(root, "/options/little-endian?")
               ? msr_little_endian_mode
               ? msr_little_endian_mode
               : 0)
               : 0)
              | (tree_find_boolean_property(root, "/openprom/options/floating-point?")
              | (tree_find_boolean_property(root, "/openprom/options/floating-point?")
                 ? (msr_floating_point_available
                 ? (msr_floating_point_available
                    | msr_floating_point_exception_mode_0
                    | msr_floating_point_exception_mode_0
                    | msr_floating_point_exception_mode_1)
                    | msr_floating_point_exception_mode_1)
                 : 0)));
                 : 0)));
  tree_parse(root, "/openprom/init/stack/stack-type %s",
  tree_parse(root, "/openprom/init/stack/stack-type %s",
             (elf_binary ? "ppc-elf" : "ppc-xcoff"));
             (elf_binary ? "ppc-elf" : "ppc-xcoff"));
 
 
  /* finally our emulation data */
  /* finally our emulation data */
  data = ZALLOC(os_emul_data);
  data = ZALLOC(os_emul_data);
  data->vm = vm;
  data->vm = vm;
  data->syscalls = syscall;
  data->syscalls = syscall;
  return data;
  return data;
}
}
 
 


/* EMULATION
/* EMULATION
 
 
   Solaris - Emulation of user programs for Solaris/PPC
   Solaris - Emulation of user programs for Solaris/PPC
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   */
   */
 
 
 
 
/* Solaris specific implementation */
/* Solaris specific implementation */
 
 
typedef signed32        solaris_uid_t;
typedef signed32        solaris_uid_t;
typedef signed32        solaris_gid_t;
typedef signed32        solaris_gid_t;
typedef signed32        solaris_off_t;
typedef signed32        solaris_off_t;
typedef signed32        solaris_pid_t;
typedef signed32        solaris_pid_t;
typedef signed32        solaris_time_t;
typedef signed32        solaris_time_t;
typedef unsigned32      solaris_dev_t;
typedef unsigned32      solaris_dev_t;
typedef unsigned32      solaris_ino_t;
typedef unsigned32      solaris_ino_t;
typedef unsigned32      solaris_mode_t;
typedef unsigned32      solaris_mode_t;
typedef unsigned32      solaris_nlink_t;
typedef unsigned32      solaris_nlink_t;
 
 
#ifdef HAVE_SYS_STAT_H
#ifdef HAVE_SYS_STAT_H
#define SOLARIS_ST_FSTYPSZ 16           /* array size for file system type name */
#define SOLARIS_ST_FSTYPSZ 16           /* array size for file system type name */
 
 
struct solaris_stat {
struct solaris_stat {
  solaris_dev_t         st_dev;
  solaris_dev_t         st_dev;
  signed32              st_pad1[3];     /* reserved for network id */
  signed32              st_pad1[3];     /* reserved for network id */
  solaris_ino_t         st_ino;
  solaris_ino_t         st_ino;
  solaris_mode_t        st_mode;
  solaris_mode_t        st_mode;
  solaris_nlink_t       st_nlink;
  solaris_nlink_t       st_nlink;
  solaris_uid_t         st_uid;
  solaris_uid_t         st_uid;
  solaris_gid_t         st_gid;
  solaris_gid_t         st_gid;
  solaris_dev_t         st_rdev;
  solaris_dev_t         st_rdev;
  signed32              st_pad2[2];
  signed32              st_pad2[2];
  solaris_off_t         st_size;
  solaris_off_t         st_size;
  signed32              st_pad3;        /* future off_t expansion */
  signed32              st_pad3;        /* future off_t expansion */
  struct unix_timeval   st_atim;
  struct unix_timeval   st_atim;
  struct unix_timeval   st_mtim;
  struct unix_timeval   st_mtim;
  struct unix_timeval   st_ctim;
  struct unix_timeval   st_ctim;
  signed32              st_blksize;
  signed32              st_blksize;
  signed32              st_blocks;
  signed32              st_blocks;
  char                  st_fstype[SOLARIS_ST_FSTYPSZ];
  char                  st_fstype[SOLARIS_ST_FSTYPSZ];
  signed32              st_pad4[8];     /* expansion area */
  signed32              st_pad4[8];     /* expansion area */
};
};
 
 
/* Convert from host stat structure to solaris stat structure */
/* Convert from host stat structure to solaris stat structure */
STATIC_INLINE_EMUL_UNIX void
STATIC_INLINE_EMUL_UNIX void
convert_to_solaris_stat(unsigned_word addr,
convert_to_solaris_stat(unsigned_word addr,
                        struct stat *host,
                        struct stat *host,
                        cpu *processor,
                        cpu *processor,
                        unsigned_word cia)
                        unsigned_word cia)
{
{
  struct solaris_stat target;
  struct solaris_stat target;
  int i;
  int i;
 
 
  target.st_dev   = H2T_4(host->st_dev);
  target.st_dev   = H2T_4(host->st_dev);
  target.st_ino   = H2T_4(host->st_ino);
  target.st_ino   = H2T_4(host->st_ino);
  target.st_mode  = H2T_4(host->st_mode);
  target.st_mode  = H2T_4(host->st_mode);
  target.st_nlink = H2T_4(host->st_nlink);
  target.st_nlink = H2T_4(host->st_nlink);
  target.st_uid   = H2T_4(host->st_uid);
  target.st_uid   = H2T_4(host->st_uid);
  target.st_gid   = H2T_4(host->st_gid);
  target.st_gid   = H2T_4(host->st_gid);
  target.st_size  = H2T_4(host->st_size);
  target.st_size  = H2T_4(host->st_size);
 
 
#ifdef HAVE_ST_RDEV
#ifdef HAVE_ST_RDEV
  target.st_rdev  = H2T_4(host->st_rdev);
  target.st_rdev  = H2T_4(host->st_rdev);
#else
#else
  target.st_rdev  = 0;
  target.st_rdev  = 0;
#endif
#endif
 
 
#ifdef HAVE_ST_BLKSIZE
#ifdef HAVE_ST_BLKSIZE
  target.st_blksize = H2T_4(host->st_blksize);
  target.st_blksize = H2T_4(host->st_blksize);
#else
#else
  target.st_blksize = 0;
  target.st_blksize = 0;
#endif
#endif
 
 
#ifdef HAVE_ST_BLOCKS
#ifdef HAVE_ST_BLOCKS
  target.st_blocks  = H2T_4(host->st_blocks);
  target.st_blocks  = H2T_4(host->st_blocks);
#else
#else
  target.st_blocks  = 0;
  target.st_blocks  = 0;
#endif
#endif
 
 
  target.st_atim.tv_sec  = H2T_4(host->st_atime);
  target.st_atim.tv_sec  = H2T_4(host->st_atime);
  target.st_atim.tv_usec = 0;
  target.st_atim.tv_usec = 0;
 
 
  target.st_ctim.tv_sec  = H2T_4(host->st_ctime);
  target.st_ctim.tv_sec  = H2T_4(host->st_ctime);
  target.st_ctim.tv_usec = 0;
  target.st_ctim.tv_usec = 0;
 
 
  target.st_mtim.tv_sec  = H2T_4(host->st_mtime);
  target.st_mtim.tv_sec  = H2T_4(host->st_mtime);
  target.st_mtim.tv_usec = 0;
  target.st_mtim.tv_usec = 0;
 
 
  for (i = 0; i < sizeof (target.st_pad1) / sizeof (target.st_pad1[0]); i++)
  for (i = 0; i < sizeof (target.st_pad1) / sizeof (target.st_pad1[0]); i++)
    target.st_pad1[i] = 0;
    target.st_pad1[i] = 0;
 
 
  for (i = 0; i < sizeof (target.st_pad2) / sizeof (target.st_pad2[0]); i++)
  for (i = 0; i < sizeof (target.st_pad2) / sizeof (target.st_pad2[0]); i++)
    target.st_pad2[i] = 0;
    target.st_pad2[i] = 0;
 
 
  target.st_pad3 = 0;
  target.st_pad3 = 0;
 
 
  for (i = 0; i < sizeof (target.st_pad4) / sizeof (target.st_pad4[0]); i++)
  for (i = 0; i < sizeof (target.st_pad4) / sizeof (target.st_pad4[0]); i++)
    target.st_pad4[i] = 0;
    target.st_pad4[i] = 0;
 
 
  /* For now, just punt and always say it is a ufs file */
  /* For now, just punt and always say it is a ufs file */
  strcpy (target.st_fstype, "ufs");
  strcpy (target.st_fstype, "ufs");
 
 
  emul_write_buffer(&target, addr, sizeof(target), processor, cia);
  emul_write_buffer(&target, addr, sizeof(target), processor, cia);
}
}
#endif /* HAVE_SYS_STAT_H */
#endif /* HAVE_SYS_STAT_H */
 
 
#ifndef HAVE_STAT
#ifndef HAVE_STAT
#define do_solaris_stat 0
#define do_solaris_stat 0
#else
#else
static void
static void
do_solaris_stat(os_emul_data *emul,
do_solaris_stat(os_emul_data *emul,
                unsigned call,
                unsigned call,
                const int arg0,
                const int arg0,
                cpu *processor,
                cpu *processor,
                unsigned_word cia)
                unsigned_word cia)
{
{
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
  char path_buf[PATH_MAX];
  char path_buf[PATH_MAX];
  struct stat buf;
  struct stat buf;
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
    printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
 
 
  status = stat (path, &buf);
  status = stat (path, &buf);
  if (status == 0)
  if (status == 0)
    convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
    convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
 
 
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_LSTAT
#ifndef HAVE_LSTAT
#define do_solaris_lstat 0
#define do_solaris_lstat 0
#else
#else
static void
static void
do_solaris_lstat(os_emul_data *emul,
do_solaris_lstat(os_emul_data *emul,
                 unsigned call,
                 unsigned call,
                 const int arg0,
                 const int arg0,
                 cpu *processor,
                 cpu *processor,
                 unsigned_word cia)
                 unsigned_word cia)
{
{
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
  char path_buf[PATH_MAX];
  char path_buf[PATH_MAX];
  struct stat buf;
  struct stat buf;
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
    printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
 
 
  status = lstat (path, &buf);
  status = lstat (path, &buf);
  if (status == 0)
  if (status == 0)
    convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
    convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
 
 
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_FSTAT
#ifndef HAVE_FSTAT
#define do_solaris_fstat 0
#define do_solaris_fstat 0
#else
#else
static void
static void
do_solaris_fstat(os_emul_data *emul,
do_solaris_fstat(os_emul_data *emul,
                 unsigned call,
                 unsigned call,
                 const int arg0,
                 const int arg0,
                 cpu *processor,
                 cpu *processor,
                 unsigned_word cia)
                 unsigned_word cia)
{
{
  int fildes = (int)cpu_registers(processor)->gpr[arg0];
  int fildes = (int)cpu_registers(processor)->gpr[arg0];
  unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
  struct stat buf;
  struct stat buf;
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt);
    printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt);
 
 
  status = fstat (fildes, &buf);
  status = fstat (fildes, &buf);
  if (status == 0)
  if (status == 0)
    convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
    convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
 
 
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
#define SOLARIS_TIOC      ('T'<<8)
#define SOLARIS_TIOC      ('T'<<8)
#define SOLARIS_NCC       8
#define SOLARIS_NCC       8
#define SOLARIS_NCCS      19
#define SOLARIS_NCCS      19
 
 
#define SOLARIS_VINTR     0
#define SOLARIS_VINTR     0
#define SOLARIS_VQUIT     1
#define SOLARIS_VQUIT     1
#define SOLARIS_VERASE    2
#define SOLARIS_VERASE    2
#define SOLARIS_VKILL     3
#define SOLARIS_VKILL     3
#define SOLARIS_VEOF      4
#define SOLARIS_VEOF      4
#define SOLARIS_VEOL      5
#define SOLARIS_VEOL      5
#define SOLARIS_VEOL2     6
#define SOLARIS_VEOL2     6
#define SOLARIS_VSWTCH    7
#define SOLARIS_VSWTCH    7
#define SOLARIS_VSTART    8
#define SOLARIS_VSTART    8
#define SOLARIS_VSTOP     9
#define SOLARIS_VSTOP     9
#define SOLARIS_VSUSP    10
#define SOLARIS_VSUSP    10
#define SOLARIS_VDSUSP   11
#define SOLARIS_VDSUSP   11
#define SOLARIS_VREPRINT 12
#define SOLARIS_VREPRINT 12
#define SOLARIS_VDISCARD 13
#define SOLARIS_VDISCARD 13
#define SOLARIS_VWERASE  14
#define SOLARIS_VWERASE  14
#define SOLARIS_VLNEXT   15
#define SOLARIS_VLNEXT   15
#endif
#endif
 
 
#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
/* Convert to/from host termio structure */
/* Convert to/from host termio structure */
 
 
struct solaris_termio {
struct solaris_termio {
        unsigned16      c_iflag;                /* input modes */
        unsigned16      c_iflag;                /* input modes */
        unsigned16      c_oflag;                /* output modes */
        unsigned16      c_oflag;                /* output modes */
        unsigned16      c_cflag;                /* control modes */
        unsigned16      c_cflag;                /* control modes */
        unsigned16      c_lflag;                /* line discipline modes */
        unsigned16      c_lflag;                /* line discipline modes */
        unsigned8       c_line;                 /* line discipline */
        unsigned8       c_line;                 /* line discipline */
        unsigned8       c_cc[SOLARIS_NCC];      /* control chars */
        unsigned8       c_cc[SOLARIS_NCC];      /* control chars */
};
};
 
 
STATIC_INLINE_EMUL_UNIX void
STATIC_INLINE_EMUL_UNIX void
convert_to_solaris_termio(unsigned_word addr,
convert_to_solaris_termio(unsigned_word addr,
                          struct termio *host,
                          struct termio *host,
                          cpu *processor,
                          cpu *processor,
                          unsigned_word cia)
                          unsigned_word cia)
{
{
  struct solaris_termio target;
  struct solaris_termio target;
  int i;
  int i;
 
 
  target.c_iflag = H2T_2 (host->c_iflag);
  target.c_iflag = H2T_2 (host->c_iflag);
  target.c_oflag = H2T_2 (host->c_oflag);
  target.c_oflag = H2T_2 (host->c_oflag);
  target.c_cflag = H2T_2 (host->c_cflag);
  target.c_cflag = H2T_2 (host->c_cflag);
  target.c_lflag = H2T_2 (host->c_lflag);
  target.c_lflag = H2T_2 (host->c_lflag);
 
 
#if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
#if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
  target.c_line  = host->c_line;
  target.c_line  = host->c_line;
#else
#else
  target.c_line  = 0;
  target.c_line  = 0;
#endif
#endif
 
 
  for (i = 0; i < SOLARIS_NCC; i++)
  for (i = 0; i < SOLARIS_NCC; i++)
    target.c_cc[i] = 0;
    target.c_cc[i] = 0;
 
 
#ifdef VINTR
#ifdef VINTR
  target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];
  target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];
#endif
#endif
 
 
#ifdef VQUIT
#ifdef VQUIT
  target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];
  target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];
#endif
#endif
 
 
#ifdef VERASE
#ifdef VERASE
  target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];
  target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];
#endif
#endif
 
 
#ifdef VKILL
#ifdef VKILL
  target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];
  target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];
#endif
#endif
 
 
#ifdef VEOF
#ifdef VEOF
  target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];
  target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];
#endif
#endif
 
 
#ifdef VEOL
#ifdef VEOL
  target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];
  target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];
#endif
#endif
 
 
#ifdef VEOL2
#ifdef VEOL2
  target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];
  target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];
#endif
#endif
 
 
#ifdef VSWTCH
#ifdef VSWTCH
  target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];
  target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];
 
 
#else
#else
#ifdef VSWTC
#ifdef VSWTC
  target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];
  target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];
#endif
#endif
#endif
#endif
 
 
  emul_write_buffer(&target, addr, sizeof(target), processor, cia);
  emul_write_buffer(&target, addr, sizeof(target), processor, cia);
}
}
#endif /* HAVE_TERMIO_STRUCTURE || HAVE_TERMIOS_STRUCTURE */
#endif /* HAVE_TERMIO_STRUCTURE || HAVE_TERMIOS_STRUCTURE */
 
 
#ifdef HAVE_TERMIOS_STRUCTURE
#ifdef HAVE_TERMIOS_STRUCTURE
/* Convert to/from host termios structure */
/* Convert to/from host termios structure */
 
 
typedef unsigned32 solaris_tcflag_t;
typedef unsigned32 solaris_tcflag_t;
typedef unsigned8  solaris_cc_t;
typedef unsigned8  solaris_cc_t;
typedef unsigned32 solaris_speed_t;
typedef unsigned32 solaris_speed_t;
 
 
struct solaris_termios {
struct solaris_termios {
  solaris_tcflag_t      c_iflag;
  solaris_tcflag_t      c_iflag;
  solaris_tcflag_t      c_oflag;
  solaris_tcflag_t      c_oflag;
  solaris_tcflag_t      c_cflag;
  solaris_tcflag_t      c_cflag;
  solaris_tcflag_t      c_lflag;
  solaris_tcflag_t      c_lflag;
  solaris_cc_t          c_cc[SOLARIS_NCCS];
  solaris_cc_t          c_cc[SOLARIS_NCCS];
};
};
 
 
STATIC_INLINE_EMUL_UNIX void
STATIC_INLINE_EMUL_UNIX void
convert_to_solaris_termios(unsigned_word addr,
convert_to_solaris_termios(unsigned_word addr,
                           struct termios *host,
                           struct termios *host,
                           cpu *processor,
                           cpu *processor,
                           unsigned_word cia)
                           unsigned_word cia)
{
{
  struct solaris_termios target;
  struct solaris_termios target;
  int i;
  int i;
 
 
  target.c_iflag = H2T_4 (host->c_iflag);
  target.c_iflag = H2T_4 (host->c_iflag);
  target.c_oflag = H2T_4 (host->c_oflag);
  target.c_oflag = H2T_4 (host->c_oflag);
  target.c_cflag = H2T_4 (host->c_cflag);
  target.c_cflag = H2T_4 (host->c_cflag);
  target.c_lflag = H2T_4 (host->c_lflag);
  target.c_lflag = H2T_4 (host->c_lflag);
 
 
  for (i = 0; i < SOLARIS_NCCS; i++)
  for (i = 0; i < SOLARIS_NCCS; i++)
    target.c_cc[i] = 0;
    target.c_cc[i] = 0;
 
 
#ifdef VINTR
#ifdef VINTR
  target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];
  target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];
#endif
#endif
 
 
#ifdef VQUIT
#ifdef VQUIT
  target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];
  target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];
#endif
#endif
 
 
#ifdef VERASE
#ifdef VERASE
  target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];
  target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];
#endif
#endif
 
 
#ifdef VKILL
#ifdef VKILL
  target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];
  target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];
#endif
#endif
 
 
#ifdef VEOF
#ifdef VEOF
  target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];
  target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];
#endif
#endif
 
 
#ifdef VEOL
#ifdef VEOL
  target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];
  target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];
#endif
#endif
 
 
#ifdef VEOL2
#ifdef VEOL2
  target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];
  target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];
#endif
#endif
 
 
#ifdef VSWTCH
#ifdef VSWTCH
  target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];
  target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];
 
 
#else
#else
#ifdef VSWTC
#ifdef VSWTC
  target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];
  target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];
#endif
#endif
#endif
#endif
 
 
#ifdef VSTART
#ifdef VSTART
  target.c_cc[SOLARIS_VSTART] = host->c_cc[VSTART];
  target.c_cc[SOLARIS_VSTART] = host->c_cc[VSTART];
#endif
#endif
 
 
#ifdef VSTOP
#ifdef VSTOP
  target.c_cc[SOLARIS_VSTOP] = host->c_cc[VSTOP];
  target.c_cc[SOLARIS_VSTOP] = host->c_cc[VSTOP];
#endif
#endif
 
 
#ifdef VSUSP
#ifdef VSUSP
  target.c_cc[SOLARIS_VSUSP] = host->c_cc[VSUSP];
  target.c_cc[SOLARIS_VSUSP] = host->c_cc[VSUSP];
#endif
#endif
 
 
#ifdef VDSUSP
#ifdef VDSUSP
  target.c_cc[SOLARIS_VDSUSP] = host->c_cc[VDSUSP];
  target.c_cc[SOLARIS_VDSUSP] = host->c_cc[VDSUSP];
#endif
#endif
 
 
#ifdef VREPRINT
#ifdef VREPRINT
  target.c_cc[SOLARIS_VREPRINT] = host->c_cc[VREPRINT];
  target.c_cc[SOLARIS_VREPRINT] = host->c_cc[VREPRINT];
#endif
#endif
 
 
#ifdef VDISCARD
#ifdef VDISCARD
  target.c_cc[SOLARIS_VDISCARD] = host->c_cc[VDISCARD];
  target.c_cc[SOLARIS_VDISCARD] = host->c_cc[VDISCARD];
#endif
#endif
 
 
#ifdef VWERASE
#ifdef VWERASE
  target.c_cc[SOLARIS_VWERASE] = host->c_cc[VWERASE];
  target.c_cc[SOLARIS_VWERASE] = host->c_cc[VWERASE];
#endif
#endif
 
 
#ifdef VLNEXT
#ifdef VLNEXT
  target.c_cc[SOLARIS_VLNEXT] = host->c_cc[VLNEXT];
  target.c_cc[SOLARIS_VLNEXT] = host->c_cc[VLNEXT];
#endif
#endif
 
 
  emul_write_buffer(&target, addr, sizeof(target), processor, cia);
  emul_write_buffer(&target, addr, sizeof(target), processor, cia);
}
}
#endif /* HAVE_TERMIOS_STRUCTURE */
#endif /* HAVE_TERMIOS_STRUCTURE */
 
 
#ifndef HAVE_IOCTL
#ifndef HAVE_IOCTL
#define do_solaris_ioctl 0
#define do_solaris_ioctl 0
#else
#else
static void
static void
do_solaris_ioctl(os_emul_data *emul,
do_solaris_ioctl(os_emul_data *emul,
                 unsigned call,
                 unsigned call,
                 const int arg0,
                 const int arg0,
                 cpu *processor,
                 cpu *processor,
                 unsigned_word cia)
                 unsigned_word cia)
{
{
  int fildes = cpu_registers(processor)->gpr[arg0];
  int fildes = cpu_registers(processor)->gpr[arg0];
  unsigned request = cpu_registers(processor)->gpr[arg0+1];
  unsigned request = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
  unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
  int status = 0;
  int status = 0;
  const char *name = "<unknown>";
  const char *name = "<unknown>";
 
 
#ifdef HAVE_TERMIOS_STRUCTURE
#ifdef HAVE_TERMIOS_STRUCTURE
  struct termios host_termio;
  struct termios host_termio;
 
 
#else
#else
#ifdef HAVE_TERMIO_STRUCTURE
#ifdef HAVE_TERMIO_STRUCTURE
  struct termio host_termio;
  struct termio host_termio;
#endif
#endif
#endif
#endif
 
 
  switch (request)
  switch (request)
    {
    {
    case 0:                                      /* make sure we have at least one case */
    case 0:                                      /* make sure we have at least one case */
    default:
    default:
      status = -1;
      status = -1;
      errno = EINVAL;
      errno = EINVAL;
      break;
      break;
 
 
#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
#if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
#if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
    case SOLARIS_TIOC | 1:                      /* TCGETA */
    case SOLARIS_TIOC | 1:                      /* TCGETA */
      name = "TCGETA";
      name = "TCGETA";
#ifdef HAVE_TCGETATTR
#ifdef HAVE_TCGETATTR
      status = tcgetattr(fildes, &host_termio);
      status = tcgetattr(fildes, &host_termio);
#elif defined(TCGETS)
#elif defined(TCGETS)
      status = ioctl (fildes, TCGETS, &host_termio);
      status = ioctl (fildes, TCGETS, &host_termio);
#else
#else
      status = ioctl (fildes, TCGETA, &host_termio);
      status = ioctl (fildes, TCGETA, &host_termio);
#endif
#endif
      if (status == 0)
      if (status == 0)
        convert_to_solaris_termio (argp_addr, &host_termio, processor, cia);
        convert_to_solaris_termio (argp_addr, &host_termio, processor, cia);
      break;
      break;
#endif /* TCGETA */
#endif /* TCGETA */
#endif /* HAVE_TERMIO_STRUCTURE */
#endif /* HAVE_TERMIO_STRUCTURE */
 
 
#ifdef HAVE_TERMIOS_STRUCTURE
#ifdef HAVE_TERMIOS_STRUCTURE
#if defined(TCGETS) || defined(HAVE_TCGETATTR)
#if defined(TCGETS) || defined(HAVE_TCGETATTR)
    case SOLARIS_TIOC | 13:                     /* TCGETS */
    case SOLARIS_TIOC | 13:                     /* TCGETS */
      name = "TCGETS";
      name = "TCGETS";
#ifdef HAVE_TCGETATTR
#ifdef HAVE_TCGETATTR
      status = tcgetattr(fildes, &host_termio);
      status = tcgetattr(fildes, &host_termio);
#else
#else
      status = ioctl (fildes, TCGETS, &host_termio);
      status = ioctl (fildes, TCGETS, &host_termio);
#endif
#endif
      if (status == 0)
      if (status == 0)
        convert_to_solaris_termios (argp_addr, &host_termio, processor, cia);
        convert_to_solaris_termios (argp_addr, &host_termio, processor, cia);
      break;
      break;
#endif /* TCGETS */
#endif /* TCGETS */
#endif /* HAVE_TERMIOS_STRUCTURE */
#endif /* HAVE_TERMIOS_STRUCTURE */
    }
    }
 
 
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);
    printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);
}
}
#endif /* HAVE_IOCTL */
#endif /* HAVE_IOCTL */
 
 
static emul_syscall_descriptor solaris_descriptors[] = {
static emul_syscall_descriptor solaris_descriptors[] = {
  /*   0 */ { 0, "syscall" },
  /*   0 */ { 0, "syscall" },
  /*   1 */ { do_unix_exit, "exit" },
  /*   1 */ { do_unix_exit, "exit" },
  /*   2 */ { 0, "fork" },
  /*   2 */ { 0, "fork" },
  /*   3 */ { do_unix_read, "read" },
  /*   3 */ { do_unix_read, "read" },
  /*   4 */ { do_unix_write, "write" },
  /*   4 */ { do_unix_write, "write" },
  /*   5 */ { do_unix_open, "open" },
  /*   5 */ { do_unix_open, "open" },
  /*   6 */ { do_unix_close, "close" },
  /*   6 */ { do_unix_close, "close" },
  /*   7 */ { 0, "wait" },
  /*   7 */ { 0, "wait" },
  /*   8 */ { 0, "creat" },
  /*   8 */ { 0, "creat" },
  /*   9 */ { do_unix_link, "link" },
  /*   9 */ { do_unix_link, "link" },
  /*  10 */ { do_unix_unlink, "unlink" },
  /*  10 */ { do_unix_unlink, "unlink" },
  /*  11 */ { 0, "exec" },
  /*  11 */ { 0, "exec" },
  /*  12 */ { do_unix_chdir, "chdir" },
  /*  12 */ { do_unix_chdir, "chdir" },
  /*  13 */ { do_unix_time, "time" },
  /*  13 */ { do_unix_time, "time" },
  /*  14 */ { 0, "mknod" },
  /*  14 */ { 0, "mknod" },
  /*  15 */ { 0, "chmod" },
  /*  15 */ { 0, "chmod" },
  /*  16 */ { 0, "chown" },
  /*  16 */ { 0, "chown" },
  /*  17 */ { do_unix_break, "brk" },
  /*  17 */ { do_unix_break, "brk" },
  /*  18 */ { do_solaris_stat, "stat" },
  /*  18 */ { do_solaris_stat, "stat" },
  /*  19 */ { do_unix_lseek, "lseek" },
  /*  19 */ { do_unix_lseek, "lseek" },
  /*  20 */ { do_unix_getpid2, "getpid" },
  /*  20 */ { do_unix_getpid2, "getpid" },
  /*  21 */ { 0, "mount" },
  /*  21 */ { 0, "mount" },
  /*  22 */ { 0, "umount" },
  /*  22 */ { 0, "umount" },
  /*  23 */ { 0, "setuid" },
  /*  23 */ { 0, "setuid" },
  /*  24 */ { do_unix_getuid2, "getuid" },
  /*  24 */ { do_unix_getuid2, "getuid" },
  /*  25 */ { 0, "stime" },
  /*  25 */ { 0, "stime" },
  /*  26 */ { 0, "ptrace" },
  /*  26 */ { 0, "ptrace" },
  /*  27 */ { 0, "alarm" },
  /*  27 */ { 0, "alarm" },
  /*  28 */ { do_solaris_fstat, "fstat" },
  /*  28 */ { do_solaris_fstat, "fstat" },
  /*  29 */ { 0, "pause" },
  /*  29 */ { 0, "pause" },
  /*  30 */ { 0, "utime" },
  /*  30 */ { 0, "utime" },
  /*  31 */ { 0, "stty" },
  /*  31 */ { 0, "stty" },
  /*  32 */ { 0, "gtty" },
  /*  32 */ { 0, "gtty" },
  /*  33 */ { do_unix_access, "access" },
  /*  33 */ { do_unix_access, "access" },
  /*  34 */ { 0, "nice" },
  /*  34 */ { 0, "nice" },
  /*  35 */ { 0, "statfs" },
  /*  35 */ { 0, "statfs" },
  /*  36 */ { 0, "sync" },
  /*  36 */ { 0, "sync" },
  /*  37 */ { 0, "kill" },
  /*  37 */ { 0, "kill" },
  /*  38 */ { 0, "fstatfs" },
  /*  38 */ { 0, "fstatfs" },
  /*  39 */ { 0, "pgrpsys" },
  /*  39 */ { 0, "pgrpsys" },
  /*  40 */ { 0, "xenix" },
  /*  40 */ { 0, "xenix" },
  /*  41 */ { do_unix_dup, "dup" },
  /*  41 */ { do_unix_dup, "dup" },
  /*  42 */ { 0, "pipe" },
  /*  42 */ { 0, "pipe" },
  /*  43 */ { 0, "times" },
  /*  43 */ { 0, "times" },
  /*  44 */ { 0, "profil" },
  /*  44 */ { 0, "profil" },
  /*  45 */ { 0, "plock" },
  /*  45 */ { 0, "plock" },
  /*  46 */ { 0, "setgid" },
  /*  46 */ { 0, "setgid" },
  /*  47 */ { do_unix_getgid2, "getgid" },
  /*  47 */ { do_unix_getgid2, "getgid" },
  /*  48 */ { 0, "signal" },
  /*  48 */ { 0, "signal" },
  /*  49 */ { 0, "msgsys" },
  /*  49 */ { 0, "msgsys" },
  /*  50 */ { 0, "syssun" },
  /*  50 */ { 0, "syssun" },
  /*  51 */ { 0, "acct" },
  /*  51 */ { 0, "acct" },
  /*  52 */ { 0, "shmsys" },
  /*  52 */ { 0, "shmsys" },
  /*  53 */ { 0, "semsys" },
  /*  53 */ { 0, "semsys" },
  /*  54 */ { do_solaris_ioctl, "ioctl" },
  /*  54 */ { do_solaris_ioctl, "ioctl" },
  /*  55 */ { 0, "uadmin" },
  /*  55 */ { 0, "uadmin" },
  /*  56 */ { 0, 0 /* reserved for exch */ },
  /*  56 */ { 0, 0 /* reserved for exch */ },
  /*  57 */ { 0, "utssys" },
  /*  57 */ { 0, "utssys" },
  /*  58 */ { 0, "fdsync" },
  /*  58 */ { 0, "fdsync" },
  /*  59 */ { 0, "execve" },
  /*  59 */ { 0, "execve" },
  /*  60 */ { do_unix_umask, "umask" },
  /*  60 */ { do_unix_umask, "umask" },
  /*  61 */ { 0, "chroot" },
  /*  61 */ { 0, "chroot" },
  /*  62 */ { 0, "fcntl" },
  /*  62 */ { 0, "fcntl" },
  /*  63 */ { 0, "ulimit" },
  /*  63 */ { 0, "ulimit" },
  /*  64 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  64 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  64 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  64 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  65 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  65 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  66 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  66 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  67 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  67 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  68 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  68 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  69 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  69 */ { 0, 0 /* reserved for UNIX PC */ },
  /*  70 */ { 0, 0 /* was advfs */ },
  /*  70 */ { 0, 0 /* was advfs */ },
  /*  71 */ { 0, 0 /* was unadvfs */ },
  /*  71 */ { 0, 0 /* was unadvfs */ },
  /*  72 */ { 0, 0 /* was rmount */ },
  /*  72 */ { 0, 0 /* was rmount */ },
  /*  73 */ { 0, 0 /* was rumount */ },
  /*  73 */ { 0, 0 /* was rumount */ },
  /*  74 */ { 0, 0 /* was rfstart */ },
  /*  74 */ { 0, 0 /* was rfstart */ },
  /*  75 */ { 0, 0 /* was sigret */ },
  /*  75 */ { 0, 0 /* was sigret */ },
  /*  76 */ { 0, 0 /* was rdebug */ },
  /*  76 */ { 0, 0 /* was rdebug */ },
  /*  77 */ { 0, 0 /* was rfstop */ },
  /*  77 */ { 0, 0 /* was rfstop */ },
  /*  78 */ { 0, 0 /* was rfsys */ },
  /*  78 */ { 0, 0 /* was rfsys */ },
  /*  79 */ { do_unix_rmdir, "rmdir" },
  /*  79 */ { do_unix_rmdir, "rmdir" },
  /*  80 */ { do_unix_mkdir, "mkdir" },
  /*  80 */ { do_unix_mkdir, "mkdir" },
  /*  81 */ { 0, "getdents" },
  /*  81 */ { 0, "getdents" },
  /*  82 */ { 0, 0 /* was libattach */ },
  /*  82 */ { 0, 0 /* was libattach */ },
  /*  83 */ { 0, 0 /* was libdetach */ },
  /*  83 */ { 0, 0 /* was libdetach */ },
  /*  84 */ { 0, "sysfs" },
  /*  84 */ { 0, "sysfs" },
  /*  85 */ { 0, "getmsg" },
  /*  85 */ { 0, "getmsg" },
  /*  86 */ { 0, "putmsg" },
  /*  86 */ { 0, "putmsg" },
  /*  87 */ { 0, "poll" },
  /*  87 */ { 0, "poll" },
  /*  88 */ { do_solaris_lstat, "lstat" },
  /*  88 */ { do_solaris_lstat, "lstat" },
  /*  89 */ { do_unix_symlink, "symlink" },
  /*  89 */ { do_unix_symlink, "symlink" },
  /*  90 */ { 0, "readlink" },
  /*  90 */ { 0, "readlink" },
  /*  91 */ { 0, "setgroups" },
  /*  91 */ { 0, "setgroups" },
  /*  92 */ { 0, "getgroups" },
  /*  92 */ { 0, "getgroups" },
  /*  93 */ { 0, "fchmod" },
  /*  93 */ { 0, "fchmod" },
  /*  94 */ { 0, "fchown" },
  /*  94 */ { 0, "fchown" },
  /*  95 */ { 0, "sigprocmask" },
  /*  95 */ { 0, "sigprocmask" },
  /*  96 */ { 0, "sigsuspend" },
  /*  96 */ { 0, "sigsuspend" },
  /*  97 */ { do_unix_nop, "sigaltstack" },
  /*  97 */ { do_unix_nop, "sigaltstack" },
  /*  98 */ { do_unix_nop, "sigaction" },
  /*  98 */ { do_unix_nop, "sigaction" },
  /*  99 */ { 0, "sigpending" },
  /*  99 */ { 0, "sigpending" },
  /* 100 */ { 0, "context" },
  /* 100 */ { 0, "context" },
  /* 101 */ { 0, "evsys" },
  /* 101 */ { 0, "evsys" },
  /* 102 */ { 0, "evtrapret" },
  /* 102 */ { 0, "evtrapret" },
  /* 103 */ { 0, "statvfs" },
  /* 103 */ { 0, "statvfs" },
  /* 104 */ { 0, "fstatvfs" },
  /* 104 */ { 0, "fstatvfs" },
  /* 105 */ { 0, 0 /* reserved */ },
  /* 105 */ { 0, 0 /* reserved */ },
  /* 106 */ { 0, "nfssys" },
  /* 106 */ { 0, "nfssys" },
  /* 107 */ { 0, "waitsys" },
  /* 107 */ { 0, "waitsys" },
  /* 108 */ { 0, "sigsendsys" },
  /* 108 */ { 0, "sigsendsys" },
  /* 109 */ { 0, "hrtsys" },
  /* 109 */ { 0, "hrtsys" },
  /* 110 */ { 0, "acancel" },
  /* 110 */ { 0, "acancel" },
  /* 111 */ { 0, "async" },
  /* 111 */ { 0, "async" },
  /* 112 */ { 0, "priocntlsys" },
  /* 112 */ { 0, "priocntlsys" },
  /* 113 */ { 0, "pathconf" },
  /* 113 */ { 0, "pathconf" },
  /* 114 */ { 0, "mincore" },
  /* 114 */ { 0, "mincore" },
  /* 115 */ { 0, "mmap" },
  /* 115 */ { 0, "mmap" },
  /* 116 */ { 0, "mprotect" },
  /* 116 */ { 0, "mprotect" },
  /* 117 */ { 0, "munmap" },
  /* 117 */ { 0, "munmap" },
  /* 118 */ { 0, "fpathconf" },
  /* 118 */ { 0, "fpathconf" },
  /* 119 */ { 0, "vfork" },
  /* 119 */ { 0, "vfork" },
  /* 120 */ { 0, "fchdir" },
  /* 120 */ { 0, "fchdir" },
  /* 121 */ { 0, "readv" },
  /* 121 */ { 0, "readv" },
  /* 122 */ { 0, "writev" },
  /* 122 */ { 0, "writev" },
  /* 123 */ { 0, "xstat" },
  /* 123 */ { 0, "xstat" },
  /* 124 */ { 0, "lxstat" },
  /* 124 */ { 0, "lxstat" },
  /* 125 */ { 0, "fxstat" },
  /* 125 */ { 0, "fxstat" },
  /* 126 */ { 0, "xmknod" },
  /* 126 */ { 0, "xmknod" },
  /* 127 */ { 0, "clocal" },
  /* 127 */ { 0, "clocal" },
  /* 128 */ { 0, "setrlimit" },
  /* 128 */ { 0, "setrlimit" },
  /* 129 */ { 0, "getrlimit" },
  /* 129 */ { 0, "getrlimit" },
  /* 130 */ { 0, "lchown" },
  /* 130 */ { 0, "lchown" },
  /* 131 */ { 0, "memcntl" },
  /* 131 */ { 0, "memcntl" },
  /* 132 */ { 0, "getpmsg" },
  /* 132 */ { 0, "getpmsg" },
  /* 133 */ { 0, "putpmsg" },
  /* 133 */ { 0, "putpmsg" },
  /* 134 */ { 0, "rename" },
  /* 134 */ { 0, "rename" },
  /* 135 */ { 0, "uname" },
  /* 135 */ { 0, "uname" },
  /* 136 */ { 0, "setegid" },
  /* 136 */ { 0, "setegid" },
  /* 137 */ { 0, "sysconfig" },
  /* 137 */ { 0, "sysconfig" },
  /* 138 */ { 0, "adjtime" },
  /* 138 */ { 0, "adjtime" },
  /* 139 */ { 0, "systeminfo" },
  /* 139 */ { 0, "systeminfo" },
  /* 140 */ { 0, 0 /* reserved */ },
  /* 140 */ { 0, 0 /* reserved */ },
  /* 141 */ { 0, "seteuid" },
  /* 141 */ { 0, "seteuid" },
  /* 142 */ { 0, "vtrace" },
  /* 142 */ { 0, "vtrace" },
  /* 143 */ { 0, "fork1" },
  /* 143 */ { 0, "fork1" },
  /* 144 */ { 0, "sigtimedwait" },
  /* 144 */ { 0, "sigtimedwait" },
  /* 145 */ { 0, "lwp_info" },
  /* 145 */ { 0, "lwp_info" },
  /* 146 */ { 0, "yield" },
  /* 146 */ { 0, "yield" },
  /* 147 */ { 0, "lwp_sema_wait" },
  /* 147 */ { 0, "lwp_sema_wait" },
  /* 148 */ { 0, "lwp_sema_post" },
  /* 148 */ { 0, "lwp_sema_post" },
  /* 149 */ { 0, 0 /* reserved */ },
  /* 149 */ { 0, 0 /* reserved */ },
  /* 150 */ { 0, 0 /* reserved */ },
  /* 150 */ { 0, 0 /* reserved */ },
  /* 151 */ { 0, 0 /* reserved */ },
  /* 151 */ { 0, 0 /* reserved */ },
  /* 152 */ { 0, "modctl" },
  /* 152 */ { 0, "modctl" },
  /* 153 */ { 0, "fchroot" },
  /* 153 */ { 0, "fchroot" },
  /* 154 */ { 0, "utimes" },
  /* 154 */ { 0, "utimes" },
  /* 155 */ { 0, "vhangup" },
  /* 155 */ { 0, "vhangup" },
  /* 156 */ { do_unix_gettimeofday, "gettimeofday" },
  /* 156 */ { do_unix_gettimeofday, "gettimeofday" },
  /* 157 */ { 0, "getitimer" },
  /* 157 */ { 0, "getitimer" },
  /* 158 */ { 0, "setitimer" },
  /* 158 */ { 0, "setitimer" },
  /* 159 */ { 0, "lwp_create" },
  /* 159 */ { 0, "lwp_create" },
  /* 160 */ { 0, "lwp_exit" },
  /* 160 */ { 0, "lwp_exit" },
  /* 161 */ { 0, "lwp_suspend" },
  /* 161 */ { 0, "lwp_suspend" },
  /* 162 */ { 0, "lwp_continue" },
  /* 162 */ { 0, "lwp_continue" },
  /* 163 */ { 0, "lwp_kill" },
  /* 163 */ { 0, "lwp_kill" },
  /* 164 */ { 0, "lwp_self" },
  /* 164 */ { 0, "lwp_self" },
  /* 165 */ { 0, "lwp_setprivate" },
  /* 165 */ { 0, "lwp_setprivate" },
  /* 166 */ { 0, "lwp_getprivate" },
  /* 166 */ { 0, "lwp_getprivate" },
  /* 167 */ { 0, "lwp_wait" },
  /* 167 */ { 0, "lwp_wait" },
  /* 168 */ { 0, "lwp_mutex_unlock" },
  /* 168 */ { 0, "lwp_mutex_unlock" },
  /* 169 */ { 0, "lwp_mutex_lock" },
  /* 169 */ { 0, "lwp_mutex_lock" },
  /* 170 */ { 0, "lwp_cond_wait" },
  /* 170 */ { 0, "lwp_cond_wait" },
  /* 171 */ { 0, "lwp_cond_signal" },
  /* 171 */ { 0, "lwp_cond_signal" },
  /* 172 */ { 0, "lwp_cond_broadcast" },
  /* 172 */ { 0, "lwp_cond_broadcast" },
  /* 173 */ { 0, "pread" },
  /* 173 */ { 0, "pread" },
  /* 174 */ { 0, "pwrite" },
  /* 174 */ { 0, "pwrite" },
  /* 175 */ { 0, "llseek" },
  /* 175 */ { 0, "llseek" },
  /* 176 */ { 0, "inst_sync" },
  /* 176 */ { 0, "inst_sync" },
  /* 177 */ { 0, 0 /* reserved */ },
  /* 177 */ { 0, 0 /* reserved */ },
  /* 178 */ { 0, "kaio" },
  /* 178 */ { 0, "kaio" },
  /* 179 */ { 0, 0 /* reserved */ },
  /* 179 */ { 0, 0 /* reserved */ },
  /* 180 */ { 0, 0 /* reserved */ },
  /* 180 */ { 0, 0 /* reserved */ },
  /* 181 */ { 0, 0 /* reserved */ },
  /* 181 */ { 0, 0 /* reserved */ },
  /* 182 */ { 0, 0 /* reserved */ },
  /* 182 */ { 0, 0 /* reserved */ },
  /* 183 */ { 0, 0 /* reserved */ },
  /* 183 */ { 0, 0 /* reserved */ },
  /* 184 */ { 0, "tsolsys" },
  /* 184 */ { 0, "tsolsys" },
  /* 185 */ { 0, "acl" },
  /* 185 */ { 0, "acl" },
  /* 186 */ { 0, "auditsys" },
  /* 186 */ { 0, "auditsys" },
  /* 187 */ { 0, "processor_bind" },
  /* 187 */ { 0, "processor_bind" },
  /* 188 */ { 0, "processor_info" },
  /* 188 */ { 0, "processor_info" },
  /* 189 */ { 0, "p_online" },
  /* 189 */ { 0, "p_online" },
  /* 190 */ { 0, "sigqueue" },
  /* 190 */ { 0, "sigqueue" },
  /* 191 */ { 0, "clock_gettime" },
  /* 191 */ { 0, "clock_gettime" },
  /* 192 */ { 0, "clock_settime" },
  /* 192 */ { 0, "clock_settime" },
  /* 193 */ { 0, "clock_getres" },
  /* 193 */ { 0, "clock_getres" },
  /* 194 */ { 0, "timer_create" },
  /* 194 */ { 0, "timer_create" },
  /* 195 */ { 0, "timer_delete" },
  /* 195 */ { 0, "timer_delete" },
  /* 196 */ { 0, "timer_settime" },
  /* 196 */ { 0, "timer_settime" },
  /* 197 */ { 0, "timer_gettime" },
  /* 197 */ { 0, "timer_gettime" },
  /* 198 */ { 0, "timer_getoverrun" },
  /* 198 */ { 0, "timer_getoverrun" },
  /* 199 */ { 0, "nanosleep" },
  /* 199 */ { 0, "nanosleep" },
  /* 200 */ { 0, "facl" },
  /* 200 */ { 0, "facl" },
  /* 201 */ { 0, "door" },
  /* 201 */ { 0, "door" },
  /* 202 */ { 0, "setreuid" },
  /* 202 */ { 0, "setreuid" },
  /* 203 */ { 0, "setregid" },
  /* 203 */ { 0, "setregid" },
  /* 204 */ { 0, "install_utrap" },
  /* 204 */ { 0, "install_utrap" },
  /* 205 */ { 0, 0 /* reserved */ },
  /* 205 */ { 0, 0 /* reserved */ },
  /* 206 */ { 0, 0 /* reserved */ },
  /* 206 */ { 0, 0 /* reserved */ },
  /* 207 */ { 0, 0 /* reserved */ },
  /* 207 */ { 0, 0 /* reserved */ },
  /* 208 */ { 0, 0 /* reserved */ },
  /* 208 */ { 0, 0 /* reserved */ },
  /* 209 */ { 0, 0 /* reserved */ },
  /* 209 */ { 0, 0 /* reserved */ },
  /* 210 */ { 0, "signotifywait" },
  /* 210 */ { 0, "signotifywait" },
  /* 211 */ { 0, "lwp_sigredirect" },
  /* 211 */ { 0, "lwp_sigredirect" },
  /* 212 */ { 0, "lwp_alarm" },
  /* 212 */ { 0, "lwp_alarm" },
};
};
 
 
static char *(solaris_error_names[]) = {
static char *(solaris_error_names[]) = {
  /*   0 */ "ESUCCESS",
  /*   0 */ "ESUCCESS",
  /*   1 */ "EPERM",
  /*   1 */ "EPERM",
  /*   2 */ "ENOENT",
  /*   2 */ "ENOENT",
  /*   3 */ "ESRCH",
  /*   3 */ "ESRCH",
  /*   4 */ "EINTR",
  /*   4 */ "EINTR",
  /*   5 */ "EIO",
  /*   5 */ "EIO",
  /*   6 */ "ENXIO",
  /*   6 */ "ENXIO",
  /*   7 */ "E2BIG",
  /*   7 */ "E2BIG",
  /*   8 */ "ENOEXEC",
  /*   8 */ "ENOEXEC",
  /*   9 */ "EBADF",
  /*   9 */ "EBADF",
  /*  10 */ "ECHILD",
  /*  10 */ "ECHILD",
  /*  11 */ "EAGAIN",
  /*  11 */ "EAGAIN",
  /*  12 */ "ENOMEM",
  /*  12 */ "ENOMEM",
  /*  13 */ "EACCES",
  /*  13 */ "EACCES",
  /*  14 */ "EFAULT",
  /*  14 */ "EFAULT",
  /*  15 */ "ENOTBLK",
  /*  15 */ "ENOTBLK",
  /*  16 */ "EBUSY",
  /*  16 */ "EBUSY",
  /*  17 */ "EEXIST",
  /*  17 */ "EEXIST",
  /*  18 */ "EXDEV",
  /*  18 */ "EXDEV",
  /*  19 */ "ENODEV",
  /*  19 */ "ENODEV",
  /*  20 */ "ENOTDIR",
  /*  20 */ "ENOTDIR",
  /*  21 */ "EISDIR",
  /*  21 */ "EISDIR",
  /*  22 */ "EINVAL",
  /*  22 */ "EINVAL",
  /*  23 */ "ENFILE",
  /*  23 */ "ENFILE",
  /*  24 */ "EMFILE",
  /*  24 */ "EMFILE",
  /*  25 */ "ENOTTY",
  /*  25 */ "ENOTTY",
  /*  26 */ "ETXTBSY",
  /*  26 */ "ETXTBSY",
  /*  27 */ "EFBIG",
  /*  27 */ "EFBIG",
  /*  28 */ "ENOSPC",
  /*  28 */ "ENOSPC",
  /*  29 */ "ESPIPE",
  /*  29 */ "ESPIPE",
  /*  30 */ "EROFS",
  /*  30 */ "EROFS",
  /*  31 */ "EMLINK",
  /*  31 */ "EMLINK",
  /*  32 */ "EPIPE",
  /*  32 */ "EPIPE",
  /*  33 */ "EDOM",
  /*  33 */ "EDOM",
  /*  34 */ "ERANGE",
  /*  34 */ "ERANGE",
  /*  35 */ "ENOMSG",
  /*  35 */ "ENOMSG",
  /*  36 */ "EIDRM",
  /*  36 */ "EIDRM",
  /*  37 */ "ECHRNG",
  /*  37 */ "ECHRNG",
  /*  38 */ "EL2NSYNC",
  /*  38 */ "EL2NSYNC",
  /*  39 */ "EL3HLT",
  /*  39 */ "EL3HLT",
  /*  40 */ "EL3RST",
  /*  40 */ "EL3RST",
  /*  41 */ "ELNRNG",
  /*  41 */ "ELNRNG",
  /*  42 */ "EUNATCH",
  /*  42 */ "EUNATCH",
  /*  43 */ "ENOCSI",
  /*  43 */ "ENOCSI",
  /*  44 */ "EL2HLT",
  /*  44 */ "EL2HLT",
  /*  45 */ "EDEADLK",
  /*  45 */ "EDEADLK",
  /*  46 */ "ENOLCK",
  /*  46 */ "ENOLCK",
  /*  47 */ "ECANCELED",
  /*  47 */ "ECANCELED",
  /*  48 */ "ENOTSUP",
  /*  48 */ "ENOTSUP",
  /*  49 */ "EDQUOT",
  /*  49 */ "EDQUOT",
  /*  50 */ "EBADE",
  /*  50 */ "EBADE",
  /*  51 */ "EBADR",
  /*  51 */ "EBADR",
  /*  52 */ "EXFULL",
  /*  52 */ "EXFULL",
  /*  53 */ "ENOANO",
  /*  53 */ "ENOANO",
  /*  54 */ "EBADRQC",
  /*  54 */ "EBADRQC",
  /*  55 */ "EBADSLT",
  /*  55 */ "EBADSLT",
  /*  56 */ "EDEADLOCK",
  /*  56 */ "EDEADLOCK",
  /*  57 */ "EBFONT",
  /*  57 */ "EBFONT",
  /*  58 */ "Error code 58",
  /*  58 */ "Error code 58",
  /*  59 */ "Error code 59",
  /*  59 */ "Error code 59",
  /*  60 */ "ENOSTR",
  /*  60 */ "ENOSTR",
  /*  61 */ "ENODATA",
  /*  61 */ "ENODATA",
  /*  62 */ "ETIME",
  /*  62 */ "ETIME",
  /*  63 */ "ENOSR",
  /*  63 */ "ENOSR",
  /*  64 */ "ENONET",
  /*  64 */ "ENONET",
  /*  65 */ "ENOPKG",
  /*  65 */ "ENOPKG",
  /*  66 */ "EREMOTE",
  /*  66 */ "EREMOTE",
  /*  67 */ "ENOLINK",
  /*  67 */ "ENOLINK",
  /*  68 */ "EADV",
  /*  68 */ "EADV",
  /*  69 */ "ESRMNT",
  /*  69 */ "ESRMNT",
  /*  70 */ "ECOMM",
  /*  70 */ "ECOMM",
  /*  71 */ "EPROTO",
  /*  71 */ "EPROTO",
  /*  72 */ "Error code 72",
  /*  72 */ "Error code 72",
  /*  73 */ "Error code 73",
  /*  73 */ "Error code 73",
  /*  74 */ "EMULTIHOP",
  /*  74 */ "EMULTIHOP",
  /*  75 */ "Error code 75",
  /*  75 */ "Error code 75",
  /*  76 */ "Error code 76",
  /*  76 */ "Error code 76",
  /*  77 */ "EBADMSG",
  /*  77 */ "EBADMSG",
  /*  78 */ "ENAMETOOLONG",
  /*  78 */ "ENAMETOOLONG",
  /*  79 */ "EOVERFLOW",
  /*  79 */ "EOVERFLOW",
  /*  80 */ "ENOTUNIQ",
  /*  80 */ "ENOTUNIQ",
  /*  81 */ "EBADFD",
  /*  81 */ "EBADFD",
  /*  82 */ "EREMCHG",
  /*  82 */ "EREMCHG",
  /*  83 */ "ELIBACC",
  /*  83 */ "ELIBACC",
  /*  84 */ "ELIBBAD",
  /*  84 */ "ELIBBAD",
  /*  85 */ "ELIBSCN",
  /*  85 */ "ELIBSCN",
  /*  86 */ "ELIBMAX",
  /*  86 */ "ELIBMAX",
  /*  87 */ "ELIBEXEC",
  /*  87 */ "ELIBEXEC",
  /*  88 */ "EILSEQ",
  /*  88 */ "EILSEQ",
  /*  89 */ "ENOSYS",
  /*  89 */ "ENOSYS",
  /*  90 */ "ELOOP",
  /*  90 */ "ELOOP",
  /*  91 */ "ERESTART",
  /*  91 */ "ERESTART",
  /*  92 */ "ESTRPIPE",
  /*  92 */ "ESTRPIPE",
  /*  93 */ "ENOTEMPTY",
  /*  93 */ "ENOTEMPTY",
  /*  94 */ "EUSERS",
  /*  94 */ "EUSERS",
  /*  95 */ "ENOTSOCK",
  /*  95 */ "ENOTSOCK",
  /*  96 */ "EDESTADDRREQ",
  /*  96 */ "EDESTADDRREQ",
  /*  97 */ "EMSGSIZE",
  /*  97 */ "EMSGSIZE",
  /*  98 */ "EPROTOTYPE",
  /*  98 */ "EPROTOTYPE",
  /*  99 */ "ENOPROTOOPT",
  /*  99 */ "ENOPROTOOPT",
  /* 100 */ "Error code 100",
  /* 100 */ "Error code 100",
  /* 101 */ "Error code 101",
  /* 101 */ "Error code 101",
  /* 102 */ "Error code 102",
  /* 102 */ "Error code 102",
  /* 103 */ "Error code 103",
  /* 103 */ "Error code 103",
  /* 104 */ "Error code 104",
  /* 104 */ "Error code 104",
  /* 105 */ "Error code 105",
  /* 105 */ "Error code 105",
  /* 106 */ "Error code 106",
  /* 106 */ "Error code 106",
  /* 107 */ "Error code 107",
  /* 107 */ "Error code 107",
  /* 108 */ "Error code 108",
  /* 108 */ "Error code 108",
  /* 109 */ "Error code 109",
  /* 109 */ "Error code 109",
  /* 110 */ "Error code 110",
  /* 110 */ "Error code 110",
  /* 111 */ "Error code 111",
  /* 111 */ "Error code 111",
  /* 112 */ "Error code 112",
  /* 112 */ "Error code 112",
  /* 113 */ "Error code 113",
  /* 113 */ "Error code 113",
  /* 114 */ "Error code 114",
  /* 114 */ "Error code 114",
  /* 115 */ "Error code 115",
  /* 115 */ "Error code 115",
  /* 116 */ "Error code 116",
  /* 116 */ "Error code 116",
  /* 117 */ "Error code 117",
  /* 117 */ "Error code 117",
  /* 118 */ "Error code 118",
  /* 118 */ "Error code 118",
  /* 119 */ "Error code 119",
  /* 119 */ "Error code 119",
  /* 120 */ "EPROTONOSUPPORT",
  /* 120 */ "EPROTONOSUPPORT",
  /* 121 */ "ESOCKTNOSUPPORT",
  /* 121 */ "ESOCKTNOSUPPORT",
  /* 122 */ "EOPNOTSUPP",
  /* 122 */ "EOPNOTSUPP",
  /* 123 */ "EPFNOSUPPORT",
  /* 123 */ "EPFNOSUPPORT",
  /* 124 */ "EAFNOSUPPORT",
  /* 124 */ "EAFNOSUPPORT",
  /* 125 */ "EADDRINUSE",
  /* 125 */ "EADDRINUSE",
  /* 126 */ "EADDRNOTAVAIL",
  /* 126 */ "EADDRNOTAVAIL",
  /* 127 */ "ENETDOWN",
  /* 127 */ "ENETDOWN",
  /* 128 */ "ENETUNREACH",
  /* 128 */ "ENETUNREACH",
  /* 129 */ "ENETRESET",
  /* 129 */ "ENETRESET",
  /* 130 */ "ECONNABORTED",
  /* 130 */ "ECONNABORTED",
  /* 131 */ "ECONNRESET",
  /* 131 */ "ECONNRESET",
  /* 132 */ "ENOBUFS",
  /* 132 */ "ENOBUFS",
  /* 133 */ "EISCONN",
  /* 133 */ "EISCONN",
  /* 134 */ "ENOTCONN",
  /* 134 */ "ENOTCONN",
  /* 135 */ "Error code 135",   /* XENIX has 135 - 142 */
  /* 135 */ "Error code 135",   /* XENIX has 135 - 142 */
  /* 136 */ "Error code 136",
  /* 136 */ "Error code 136",
  /* 137 */ "Error code 137",
  /* 137 */ "Error code 137",
  /* 138 */ "Error code 138",
  /* 138 */ "Error code 138",
  /* 139 */ "Error code 139",
  /* 139 */ "Error code 139",
  /* 140 */ "Error code 140",
  /* 140 */ "Error code 140",
  /* 141 */ "Error code 141",
  /* 141 */ "Error code 141",
  /* 142 */ "Error code 142",
  /* 142 */ "Error code 142",
  /* 143 */ "ESHUTDOWN",
  /* 143 */ "ESHUTDOWN",
  /* 144 */ "ETOOMANYREFS",
  /* 144 */ "ETOOMANYREFS",
  /* 145 */ "ETIMEDOUT",
  /* 145 */ "ETIMEDOUT",
  /* 146 */ "ECONNREFUSED",
  /* 146 */ "ECONNREFUSED",
  /* 147 */ "EHOSTDOWN",
  /* 147 */ "EHOSTDOWN",
  /* 148 */ "EHOSTUNREACH",
  /* 148 */ "EHOSTUNREACH",
  /* 149 */ "EALREADY",
  /* 149 */ "EALREADY",
  /* 150 */ "EINPROGRESS",
  /* 150 */ "EINPROGRESS",
  /* 151 */ "ESTALE",
  /* 151 */ "ESTALE",
};
};
 
 
static char *(solaris_signal_names[]) = {
static char *(solaris_signal_names[]) = {
  /*  0 */ 0,
  /*  0 */ 0,
  /*  1 */ "SIGHUP",
  /*  1 */ "SIGHUP",
  /*  2 */ "SIGINT",
  /*  2 */ "SIGINT",
  /*  3 */ "SIGQUIT",
  /*  3 */ "SIGQUIT",
  /*  4 */ "SIGILL",
  /*  4 */ "SIGILL",
  /*  5 */ "SIGTRAP",
  /*  5 */ "SIGTRAP",
  /*  6 */ "SIGABRT",
  /*  6 */ "SIGABRT",
  /*  7 */ "SIGEMT",
  /*  7 */ "SIGEMT",
  /*  8 */ "SIGFPE",
  /*  8 */ "SIGFPE",
  /*  9 */ "SIGKILL",
  /*  9 */ "SIGKILL",
  /* 10 */ "SIGBUS",
  /* 10 */ "SIGBUS",
  /* 11 */ "SIGSEGV",
  /* 11 */ "SIGSEGV",
  /* 12 */ "SIGSYS",
  /* 12 */ "SIGSYS",
  /* 13 */ "SIGPIPE",
  /* 13 */ "SIGPIPE",
  /* 14 */ "SIGALRM",
  /* 14 */ "SIGALRM",
  /* 15 */ "SIGTERM",
  /* 15 */ "SIGTERM",
  /* 16 */ "SIGUSR1",
  /* 16 */ "SIGUSR1",
  /* 17 */ "SIGUSR2",
  /* 17 */ "SIGUSR2",
  /* 18 */ "SIGCHLD",
  /* 18 */ "SIGCHLD",
  /* 19 */ "SIGPWR",
  /* 19 */ "SIGPWR",
  /* 20 */ "SIGWINCH",
  /* 20 */ "SIGWINCH",
  /* 21 */ "SIGURG",
  /* 21 */ "SIGURG",
  /* 22 */ "SIGPOLL",
  /* 22 */ "SIGPOLL",
  /* 23 */ "SIGSTOP",
  /* 23 */ "SIGSTOP",
  /* 24 */ "SIGTSTP",
  /* 24 */ "SIGTSTP",
  /* 25 */ "SIGCONT",
  /* 25 */ "SIGCONT",
  /* 26 */ "SIGTTIN",
  /* 26 */ "SIGTTIN",
  /* 27 */ "SIGTTOU",
  /* 27 */ "SIGTTOU",
  /* 28 */ "SIGVTALRM",
  /* 28 */ "SIGVTALRM",
  /* 29 */ "SIGPROF",
  /* 29 */ "SIGPROF",
  /* 30 */ "SIGXCPU",
  /* 30 */ "SIGXCPU",
  /* 31 */ "SIGXFSZ",
  /* 31 */ "SIGXFSZ",
  /* 32 */ "SIGWAITING",
  /* 32 */ "SIGWAITING",
  /* 33 */ "SIGLWP",
  /* 33 */ "SIGLWP",
  /* 34 */ "SIGFREEZE",
  /* 34 */ "SIGFREEZE",
  /* 35 */ "SIGTHAW",
  /* 35 */ "SIGTHAW",
  /* 36 */ "SIGCANCEL",
  /* 36 */ "SIGCANCEL",
};
};
 
 
static emul_syscall emul_solaris_syscalls = {
static emul_syscall emul_solaris_syscalls = {
  solaris_descriptors,
  solaris_descriptors,
  sizeof(solaris_descriptors) / sizeof(solaris_descriptors[0]),
  sizeof(solaris_descriptors) / sizeof(solaris_descriptors[0]),
  solaris_error_names,
  solaris_error_names,
  sizeof(solaris_error_names) / sizeof(solaris_error_names[0]),
  sizeof(solaris_error_names) / sizeof(solaris_error_names[0]),
  solaris_signal_names,
  solaris_signal_names,
  sizeof(solaris_signal_names) / sizeof(solaris_signal_names[0]),
  sizeof(solaris_signal_names) / sizeof(solaris_signal_names[0]),
};
};
 
 
 
 
/* Solaris's os_emul interface, most are just passed on to the generic
/* Solaris's os_emul interface, most are just passed on to the generic
   syscall stuff */
   syscall stuff */
 
 
static os_emul_data *
static os_emul_data *
emul_solaris_create(device *root,
emul_solaris_create(device *root,
                    bfd *image,
                    bfd *image,
                    const char *name)
                    const char *name)
{
{
  /* check that this emulation is really for us */
  /* check that this emulation is really for us */
  if (name != NULL && strcmp(name, "solaris") != 0)
  if (name != NULL && strcmp(name, "solaris") != 0)
    return NULL;
    return NULL;
 
 
  if (image == NULL)
  if (image == NULL)
    return NULL;
    return NULL;
 
 
  return emul_unix_create(root, image, "solaris", &emul_solaris_syscalls);
  return emul_unix_create(root, image, "solaris", &emul_solaris_syscalls);
}
}
 
 
static void
static void
emul_solaris_init(os_emul_data *emul_data,
emul_solaris_init(os_emul_data *emul_data,
                  int nr_cpus)
                  int nr_cpus)
{
{
  /* nothing yet */
  /* nothing yet */
}
}
 
 
static void
static void
emul_solaris_system_call(cpu *processor,
emul_solaris_system_call(cpu *processor,
                         unsigned_word cia,
                         unsigned_word cia,
                         os_emul_data *emul_data)
                         os_emul_data *emul_data)
{
{
  emul_do_system_call(emul_data,
  emul_do_system_call(emul_data,
                      emul_data->syscalls,
                      emul_data->syscalls,
                      cpu_registers(processor)->gpr[0],
                      cpu_registers(processor)->gpr[0],
                      3, /*r3 contains arg0*/
                      3, /*r3 contains arg0*/
                      processor,
                      processor,
                      cia);
                      cia);
}
}
 
 
const os_emul emul_solaris = {
const os_emul emul_solaris = {
  "solaris",
  "solaris",
  emul_solaris_create,
  emul_solaris_create,
  emul_solaris_init,
  emul_solaris_init,
  emul_solaris_system_call,
  emul_solaris_system_call,
  0, /*instruction_call*/
  0, /*instruction_call*/
  0  /*data*/
  0  /*data*/
};
};
 
 


/* EMULATION
/* EMULATION
 
 
   Linux - Emulation of user programs for Linux/PPC
   Linux - Emulation of user programs for Linux/PPC
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   */
   */
 
 
 
 
/* Linux specific implementation */
/* Linux specific implementation */
 
 
typedef unsigned32      linux_dev_t;
typedef unsigned32      linux_dev_t;
typedef unsigned32      linux_ino_t;
typedef unsigned32      linux_ino_t;
typedef unsigned32      linux_mode_t;
typedef unsigned32      linux_mode_t;
typedef unsigned16      linux_nlink_t;
typedef unsigned16      linux_nlink_t;
typedef signed32        linux_off_t;
typedef signed32        linux_off_t;
typedef signed32        linux_pid_t;
typedef signed32        linux_pid_t;
typedef unsigned32      linux_uid_t;
typedef unsigned32      linux_uid_t;
typedef unsigned32      linux_gid_t;
typedef unsigned32      linux_gid_t;
typedef unsigned32      linux_size_t;
typedef unsigned32      linux_size_t;
typedef signed32        linux_ssize_t;
typedef signed32        linux_ssize_t;
typedef signed32        linux_ptrdiff_t;
typedef signed32        linux_ptrdiff_t;
typedef signed32        linux_time_t;
typedef signed32        linux_time_t;
typedef signed32        linux_clock_t;
typedef signed32        linux_clock_t;
typedef signed32        linux_daddr_t;
typedef signed32        linux_daddr_t;
 
 
#ifdef HAVE_SYS_STAT_H
#ifdef HAVE_SYS_STAT_H
/* For the PowerPC, don't both with the 'old' stat structure, since there
/* For the PowerPC, don't both with the 'old' stat structure, since there
   should be no extant binaries with that structure.  */
   should be no extant binaries with that structure.  */
 
 
struct linux_stat {
struct linux_stat {
        linux_dev_t     st_dev;
        linux_dev_t     st_dev;
        linux_ino_t     st_ino;
        linux_ino_t     st_ino;
        linux_mode_t    st_mode;
        linux_mode_t    st_mode;
        linux_nlink_t   st_nlink;
        linux_nlink_t   st_nlink;
        linux_uid_t     st_uid;
        linux_uid_t     st_uid;
        linux_gid_t     st_gid;
        linux_gid_t     st_gid;
        linux_dev_t     st_rdev;
        linux_dev_t     st_rdev;
        linux_off_t     st_size;
        linux_off_t     st_size;
        unsigned32      st_blksize;
        unsigned32      st_blksize;
        unsigned32      st_blocks;
        unsigned32      st_blocks;
        unsigned32      st_atimx;       /* don't use st_{a,c,m}time, that might a macro */
        unsigned32      st_atimx;       /* don't use st_{a,c,m}time, that might a macro */
        unsigned32      __unused1;      /* defined by the host's stat.h */
        unsigned32      __unused1;      /* defined by the host's stat.h */
        unsigned32      st_mtimx;
        unsigned32      st_mtimx;
        unsigned32      __unused2;
        unsigned32      __unused2;
        unsigned32      st_ctimx;
        unsigned32      st_ctimx;
        unsigned32      __unused3;
        unsigned32      __unused3;
        unsigned32      __unused4;
        unsigned32      __unused4;
        unsigned32      __unused5;
        unsigned32      __unused5;
};
};
 
 
/* Convert from host stat structure to solaris stat structure */
/* Convert from host stat structure to solaris stat structure */
STATIC_INLINE_EMUL_UNIX void
STATIC_INLINE_EMUL_UNIX void
convert_to_linux_stat(unsigned_word addr,
convert_to_linux_stat(unsigned_word addr,
                      struct stat *host,
                      struct stat *host,
                      cpu *processor,
                      cpu *processor,
                      unsigned_word cia)
                      unsigned_word cia)
{
{
  struct linux_stat target;
  struct linux_stat target;
 
 
  target.st_dev   = H2T_4(host->st_dev);
  target.st_dev   = H2T_4(host->st_dev);
  target.st_ino   = H2T_4(host->st_ino);
  target.st_ino   = H2T_4(host->st_ino);
  target.st_mode  = H2T_4(host->st_mode);
  target.st_mode  = H2T_4(host->st_mode);
  target.st_nlink = H2T_2(host->st_nlink);
  target.st_nlink = H2T_2(host->st_nlink);
  target.st_uid   = H2T_4(host->st_uid);
  target.st_uid   = H2T_4(host->st_uid);
  target.st_gid   = H2T_4(host->st_gid);
  target.st_gid   = H2T_4(host->st_gid);
  target.st_size  = H2T_4(host->st_size);
  target.st_size  = H2T_4(host->st_size);
 
 
#ifdef HAVE_ST_RDEV
#ifdef HAVE_ST_RDEV
  target.st_rdev  = H2T_4(host->st_rdev);
  target.st_rdev  = H2T_4(host->st_rdev);
#else
#else
  target.st_rdev  = 0;
  target.st_rdev  = 0;
#endif
#endif
 
 
#ifdef HAVE_ST_BLKSIZE
#ifdef HAVE_ST_BLKSIZE
  target.st_blksize = H2T_4(host->st_blksize);
  target.st_blksize = H2T_4(host->st_blksize);
#else
#else
  target.st_blksize = 0;
  target.st_blksize = 0;
#endif
#endif
 
 
#ifdef HAVE_ST_BLOCKS
#ifdef HAVE_ST_BLOCKS
  target.st_blocks  = H2T_4(host->st_blocks);
  target.st_blocks  = H2T_4(host->st_blocks);
#else
#else
  target.st_blocks  = 0;
  target.st_blocks  = 0;
#endif
#endif
 
 
  target.st_atimx   = H2T_4(host->st_atime);
  target.st_atimx   = H2T_4(host->st_atime);
  target.st_ctimx   = H2T_4(host->st_ctime);
  target.st_ctimx   = H2T_4(host->st_ctime);
  target.st_mtimx   = H2T_4(host->st_mtime);
  target.st_mtimx   = H2T_4(host->st_mtime);
  target.__unused1  = 0;
  target.__unused1  = 0;
  target.__unused2  = 0;
  target.__unused2  = 0;
  target.__unused3  = 0;
  target.__unused3  = 0;
  target.__unused4  = 0;
  target.__unused4  = 0;
  target.__unused5  = 0;
  target.__unused5  = 0;
 
 
  emul_write_buffer(&target, addr, sizeof(target), processor, cia);
  emul_write_buffer(&target, addr, sizeof(target), processor, cia);
}
}
#endif /* HAVE_SYS_STAT_H */
#endif /* HAVE_SYS_STAT_H */
 
 
#ifndef HAVE_STAT
#ifndef HAVE_STAT
#define do_linux_stat 0
#define do_linux_stat 0
#else
#else
static void
static void
do_linux_stat(os_emul_data *emul,
do_linux_stat(os_emul_data *emul,
              unsigned call,
              unsigned call,
              const int arg0,
              const int arg0,
              cpu *processor,
              cpu *processor,
              unsigned_word cia)
              unsigned_word cia)
{
{
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
  char path_buf[PATH_MAX];
  char path_buf[PATH_MAX];
  struct stat buf;
  struct stat buf;
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
    printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
 
 
  status = stat (path, &buf);
  status = stat (path, &buf);
  if (status == 0)
  if (status == 0)
    convert_to_linux_stat (stat_pkt, &buf, processor, cia);
    convert_to_linux_stat (stat_pkt, &buf, processor, cia);
 
 
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_LSTAT
#ifndef HAVE_LSTAT
#define do_linux_lstat 0
#define do_linux_lstat 0
#else
#else
static void
static void
do_linux_lstat(os_emul_data *emul,
do_linux_lstat(os_emul_data *emul,
               unsigned call,
               unsigned call,
               const int arg0,
               const int arg0,
               cpu *processor,
               cpu *processor,
               unsigned_word cia)
               unsigned_word cia)
{
{
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
  unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
  char path_buf[PATH_MAX];
  char path_buf[PATH_MAX];
  struct stat buf;
  struct stat buf;
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
    printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
 
 
  status = lstat (path, &buf);
  status = lstat (path, &buf);
  if (status == 0)
  if (status == 0)
    convert_to_linux_stat (stat_pkt, &buf, processor, cia);
    convert_to_linux_stat (stat_pkt, &buf, processor, cia);
 
 
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#ifndef HAVE_FSTAT
#ifndef HAVE_FSTAT
#define do_linux_fstat 0
#define do_linux_fstat 0
#else
#else
static void
static void
do_linux_fstat(os_emul_data *emul,
do_linux_fstat(os_emul_data *emul,
               unsigned call,
               unsigned call,
               const int arg0,
               const int arg0,
               cpu *processor,
               cpu *processor,
               unsigned_word cia)
               unsigned_word cia)
{
{
  int fildes = (int)cpu_registers(processor)->gpr[arg0];
  int fildes = (int)cpu_registers(processor)->gpr[arg0];
  unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
  struct stat buf;
  struct stat buf;
  int status;
  int status;
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt);
    printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt);
 
 
  status = fstat (fildes, &buf);
  status = fstat (fildes, &buf);
  if (status == 0)
  if (status == 0)
    convert_to_linux_stat (stat_pkt, &buf, processor, cia);
    convert_to_linux_stat (stat_pkt, &buf, processor, cia);
 
 
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
}
}
#endif
#endif
 
 
#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
#define LINUX_NCC               10
#define LINUX_NCC               10
#define LINUX_NCCS              19
#define LINUX_NCCS              19
 
 
#define LINUX_VINTR              0
#define LINUX_VINTR              0
#define LINUX_VQUIT              1
#define LINUX_VQUIT              1
#define LINUX_VERASE             2
#define LINUX_VERASE             2
#define LINUX_VKILL              3
#define LINUX_VKILL              3
#define LINUX_VEOF               4
#define LINUX_VEOF               4
#define LINUX_VMIN               5
#define LINUX_VMIN               5
#define LINUX_VEOL               6
#define LINUX_VEOL               6
#define LINUX_VTIME              7
#define LINUX_VTIME              7
#define LINUX_VEOL2              8
#define LINUX_VEOL2              8
#define LINUX_VSWTC              9
#define LINUX_VSWTC              9
#define LINUX_VWERASE           10
#define LINUX_VWERASE           10
#define LINUX_VREPRINT          11
#define LINUX_VREPRINT          11
#define LINUX_VSUSP             12
#define LINUX_VSUSP             12
#define LINUX_VSTART            13
#define LINUX_VSTART            13
#define LINUX_VSTOP             14
#define LINUX_VSTOP             14
#define LINUX_VLNEXT            15
#define LINUX_VLNEXT            15
#define LINUX_VDISCARD          16
#define LINUX_VDISCARD          16
 
 
#define LINUX_IOC_NRBITS         8
#define LINUX_IOC_NRBITS         8
#define LINUX_IOC_TYPEBITS       8
#define LINUX_IOC_TYPEBITS       8
#define LINUX_IOC_SIZEBITS      13
#define LINUX_IOC_SIZEBITS      13
#define LINUX_IOC_DIRBITS        3
#define LINUX_IOC_DIRBITS        3
 
 
#define LINUX_IOC_NRMASK        ((1 << LINUX_IOC_NRBITS)-1)
#define LINUX_IOC_NRMASK        ((1 << LINUX_IOC_NRBITS)-1)
#define LINUX_IOC_TYPEMASK      ((1 << LINUX_IOC_TYPEBITS)-1)
#define LINUX_IOC_TYPEMASK      ((1 << LINUX_IOC_TYPEBITS)-1)
#define LINUX_IOC_SIZEMASK      ((1 << LINUX_IOC_SIZEBITS)-1)
#define LINUX_IOC_SIZEMASK      ((1 << LINUX_IOC_SIZEBITS)-1)
#define LINUX_IOC_DIRMASK       ((1 << LINUX_IOC_DIRBITS)-1)
#define LINUX_IOC_DIRMASK       ((1 << LINUX_IOC_DIRBITS)-1)
 
 
#define LINUX_IOC_NRSHIFT       0
#define LINUX_IOC_NRSHIFT       0
#define LINUX_IOC_TYPESHIFT     (LINUX_IOC_NRSHIFT+LINUX_IOC_NRBITS)
#define LINUX_IOC_TYPESHIFT     (LINUX_IOC_NRSHIFT+LINUX_IOC_NRBITS)
#define LINUX_IOC_SIZESHIFT     (LINUX_IOC_TYPESHIFT+LINUX_IOC_TYPEBITS)
#define LINUX_IOC_SIZESHIFT     (LINUX_IOC_TYPESHIFT+LINUX_IOC_TYPEBITS)
#define LINUX_IOC_DIRSHIFT      (LINUX_IOC_SIZESHIFT+LINUX_IOC_SIZEBITS)
#define LINUX_IOC_DIRSHIFT      (LINUX_IOC_SIZESHIFT+LINUX_IOC_SIZEBITS)
 
 
/*
/*
 * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
 * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
 * And this turns out useful to catch old ioctl numbers in header
 * And this turns out useful to catch old ioctl numbers in header
 * files for us.
 * files for us.
 */
 */
#define LINUX_IOC_NONE          1U
#define LINUX_IOC_NONE          1U
#define LINUX_IOC_READ          2U
#define LINUX_IOC_READ          2U
#define LINUX_IOC_WRITE         4U
#define LINUX_IOC_WRITE         4U
 
 
#define LINUX_IOC(dir,type,nr,size) \
#define LINUX_IOC(dir,type,nr,size) \
        (((dir)  << LINUX_IOC_DIRSHIFT) | \
        (((dir)  << LINUX_IOC_DIRSHIFT) | \
         ((type) << LINUX_IOC_TYPESHIFT) | \
         ((type) << LINUX_IOC_TYPESHIFT) | \
         ((nr)   << LINUX_IOC_NRSHIFT) | \
         ((nr)   << LINUX_IOC_NRSHIFT) | \
         ((size) << LINUX_IOC_SIZESHIFT))
         ((size) << LINUX_IOC_SIZESHIFT))
 
 
/* used to create numbers */
/* used to create numbers */
#define LINUX_IO(type,nr)        LINUX_IOC(LINUX_IOC_NONE,(type),(nr),0)
#define LINUX_IO(type,nr)        LINUX_IOC(LINUX_IOC_NONE,(type),(nr),0)
#define LINUX_IOR(type,nr,size)  LINUX_IOC(LINUX_IOC_READ,(type),(nr),sizeof(size))
#define LINUX_IOR(type,nr,size)  LINUX_IOC(LINUX_IOC_READ,(type),(nr),sizeof(size))
#define LINUX_IOW(type,nr,size)  LINUX_IOC(LINUX_IOC_WRITE,(type),(nr),sizeof(size))
#define LINUX_IOW(type,nr,size)  LINUX_IOC(LINUX_IOC_WRITE,(type),(nr),sizeof(size))
#define LINUX_IOWR(type,nr,size) LINUX_IOC(LINUX_IOC_READ|LINUX_IOC_WRITE,(type),(nr),sizeof(size))
#define LINUX_IOWR(type,nr,size) LINUX_IOC(LINUX_IOC_READ|LINUX_IOC_WRITE,(type),(nr),sizeof(size))
#endif
#endif
 
 
#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
/* Convert to/from host termio structure */
/* Convert to/from host termio structure */
 
 
struct linux_termio {
struct linux_termio {
        unsigned16      c_iflag;                /* input modes */
        unsigned16      c_iflag;                /* input modes */
        unsigned16      c_oflag;                /* output modes */
        unsigned16      c_oflag;                /* output modes */
        unsigned16      c_cflag;                /* control modes */
        unsigned16      c_cflag;                /* control modes */
        unsigned16      c_lflag;                /* line discipline modes */
        unsigned16      c_lflag;                /* line discipline modes */
        unsigned8       c_line;                 /* line discipline */
        unsigned8       c_line;                 /* line discipline */
        unsigned8       c_cc[LINUX_NCC];        /* control chars */
        unsigned8       c_cc[LINUX_NCC];        /* control chars */
};
};
 
 
STATIC_INLINE_EMUL_UNIX void
STATIC_INLINE_EMUL_UNIX void
convert_to_linux_termio(unsigned_word addr,
convert_to_linux_termio(unsigned_word addr,
                        struct termio *host,
                        struct termio *host,
                        cpu *processor,
                        cpu *processor,
                        unsigned_word cia)
                        unsigned_word cia)
{
{
  struct linux_termio target;
  struct linux_termio target;
  int i;
  int i;
 
 
  target.c_iflag = H2T_2 (host->c_iflag);
  target.c_iflag = H2T_2 (host->c_iflag);
  target.c_oflag = H2T_2 (host->c_oflag);
  target.c_oflag = H2T_2 (host->c_oflag);
  target.c_cflag = H2T_2 (host->c_cflag);
  target.c_cflag = H2T_2 (host->c_cflag);
  target.c_lflag = H2T_2 (host->c_lflag);
  target.c_lflag = H2T_2 (host->c_lflag);
 
 
#if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
#if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
  target.c_line  = host->c_line;
  target.c_line  = host->c_line;
#else
#else
  target.c_line  = 0;
  target.c_line  = 0;
#endif
#endif
 
 
  for (i = 0; i < LINUX_NCC; i++)
  for (i = 0; i < LINUX_NCC; i++)
    target.c_cc[i] = 0;
    target.c_cc[i] = 0;
 
 
#ifdef VINTR
#ifdef VINTR
  target.c_cc[LINUX_VINTR] = host->c_cc[VINTR];
  target.c_cc[LINUX_VINTR] = host->c_cc[VINTR];
#endif
#endif
 
 
#ifdef VQUIT
#ifdef VQUIT
  target.c_cc[LINUX_VQUIT] = host->c_cc[VQUIT];
  target.c_cc[LINUX_VQUIT] = host->c_cc[VQUIT];
#endif
#endif
 
 
#ifdef VERASE
#ifdef VERASE
  target.c_cc[LINUX_VERASE] = host->c_cc[VERASE];
  target.c_cc[LINUX_VERASE] = host->c_cc[VERASE];
#endif
#endif
 
 
#ifdef VKILL
#ifdef VKILL
  target.c_cc[LINUX_VKILL] = host->c_cc[VKILL];
  target.c_cc[LINUX_VKILL] = host->c_cc[VKILL];
#endif
#endif
 
 
#ifdef VEOF
#ifdef VEOF
  target.c_cc[LINUX_VEOF] = host->c_cc[VEOF];
  target.c_cc[LINUX_VEOF] = host->c_cc[VEOF];
#endif
#endif
 
 
#ifdef VMIN
#ifdef VMIN
  target.c_cc[LINUX_VMIN] = host->c_cc[VMIN];
  target.c_cc[LINUX_VMIN] = host->c_cc[VMIN];
#endif
#endif
 
 
#ifdef VEOL
#ifdef VEOL
  target.c_cc[LINUX_VEOL] = host->c_cc[VEOL];
  target.c_cc[LINUX_VEOL] = host->c_cc[VEOL];
#endif
#endif
 
 
#ifdef VTIME
#ifdef VTIME
  target.c_cc[LINUX_VTIME] = host->c_cc[VTIME];
  target.c_cc[LINUX_VTIME] = host->c_cc[VTIME];
#endif
#endif
 
 
#ifdef VEOL2
#ifdef VEOL2
  target.c_cc[LINUX_VEOL2] = host->c_cc[VEOL2];
  target.c_cc[LINUX_VEOL2] = host->c_cc[VEOL2];
#endif
#endif
 
 
#ifdef VSWTC
#ifdef VSWTC
  target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTC];
  target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTC];
#endif
#endif
 
 
#ifdef VSWTCH
#ifdef VSWTCH
  target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTCH];
  target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTCH];
#endif
#endif
 
 
  emul_write_buffer(&target, addr, sizeof(target), processor, cia);
  emul_write_buffer(&target, addr, sizeof(target), processor, cia);
}
}
#endif /* HAVE_TERMIO_STRUCTURE */
#endif /* HAVE_TERMIO_STRUCTURE */
 
 
#ifdef HAVE_TERMIOS_STRUCTURE
#ifdef HAVE_TERMIOS_STRUCTURE
/* Convert to/from host termios structure */
/* Convert to/from host termios structure */
 
 
typedef unsigned32 linux_tcflag_t;
typedef unsigned32 linux_tcflag_t;
typedef unsigned8  linux_cc_t;
typedef unsigned8  linux_cc_t;
typedef unsigned32 linux_speed_t;
typedef unsigned32 linux_speed_t;
 
 
struct linux_termios {
struct linux_termios {
  linux_tcflag_t        c_iflag;
  linux_tcflag_t        c_iflag;
  linux_tcflag_t        c_oflag;
  linux_tcflag_t        c_oflag;
  linux_tcflag_t        c_cflag;
  linux_tcflag_t        c_cflag;
  linux_tcflag_t        c_lflag;
  linux_tcflag_t        c_lflag;
  linux_cc_t            c_cc[LINUX_NCCS];
  linux_cc_t            c_cc[LINUX_NCCS];
  linux_cc_t            c_line;
  linux_cc_t            c_line;
  signed32              c_ispeed;
  signed32              c_ispeed;
  signed32              c_ospeed;
  signed32              c_ospeed;
};
};
 
 
STATIC_INLINE_EMUL_UNIX void
STATIC_INLINE_EMUL_UNIX void
convert_to_linux_termios(unsigned_word addr,
convert_to_linux_termios(unsigned_word addr,
                         struct termios *host,
                         struct termios *host,
                         cpu *processor,
                         cpu *processor,
                         unsigned_word cia)
                         unsigned_word cia)
{
{
  struct linux_termios target;
  struct linux_termios target;
  int i;
  int i;
 
 
  target.c_iflag = H2T_4 (host->c_iflag);
  target.c_iflag = H2T_4 (host->c_iflag);
  target.c_oflag = H2T_4 (host->c_oflag);
  target.c_oflag = H2T_4 (host->c_oflag);
  target.c_cflag = H2T_4 (host->c_cflag);
  target.c_cflag = H2T_4 (host->c_cflag);
  target.c_lflag = H2T_4 (host->c_lflag);
  target.c_lflag = H2T_4 (host->c_lflag);
 
 
  for (i = 0; i < LINUX_NCCS; i++)
  for (i = 0; i < LINUX_NCCS; i++)
    target.c_cc[i] = 0;
    target.c_cc[i] = 0;
 
 
#ifdef VINTR
#ifdef VINTR
  target.c_cc[LINUX_VINTR] = host->c_cc[VINTR];
  target.c_cc[LINUX_VINTR] = host->c_cc[VINTR];
#endif
#endif
 
 
#ifdef VQUIT
#ifdef VQUIT
  target.c_cc[LINUX_VQUIT] = host->c_cc[VQUIT];
  target.c_cc[LINUX_VQUIT] = host->c_cc[VQUIT];
#endif
#endif
 
 
#ifdef VERASE
#ifdef VERASE
  target.c_cc[LINUX_VERASE] = host->c_cc[VERASE];
  target.c_cc[LINUX_VERASE] = host->c_cc[VERASE];
#endif
#endif
 
 
#ifdef VKILL
#ifdef VKILL
  target.c_cc[LINUX_VKILL] = host->c_cc[VKILL];
  target.c_cc[LINUX_VKILL] = host->c_cc[VKILL];
#endif
#endif
 
 
#ifdef VEOF
#ifdef VEOF
  target.c_cc[LINUX_VEOF] = host->c_cc[VEOF];
  target.c_cc[LINUX_VEOF] = host->c_cc[VEOF];
#endif
#endif
 
 
#ifdef VEOL
#ifdef VEOL
  target.c_cc[LINUX_VEOL] = host->c_cc[VEOL];
  target.c_cc[LINUX_VEOL] = host->c_cc[VEOL];
#endif
#endif
 
 
#ifdef VEOL2
#ifdef VEOL2
  target.c_cc[LINUX_VEOL2] = host->c_cc[VEOL2];
  target.c_cc[LINUX_VEOL2] = host->c_cc[VEOL2];
#endif
#endif
 
 
#ifdef VSWTCH
#ifdef VSWTCH
  target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTCH];
  target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTCH];
#endif
#endif
 
 
#ifdef HAVE_TERMIOS_CLINE
#ifdef HAVE_TERMIOS_CLINE
  target.c_line   = host->c_line;
  target.c_line   = host->c_line;
#else
#else
  target.c_line   = 0;
  target.c_line   = 0;
#endif
#endif
 
 
#ifdef HAVE_CFGETISPEED
#ifdef HAVE_CFGETISPEED
  target.c_ispeed = cfgetispeed (host);
  target.c_ispeed = cfgetispeed (host);
#else
#else
  target.c_ispeed = 0;
  target.c_ispeed = 0;
#endif
#endif
 
 
#ifdef HAVE_CFGETOSPEED
#ifdef HAVE_CFGETOSPEED
  target.c_ospeed = cfgetospeed (host);
  target.c_ospeed = cfgetospeed (host);
#else
#else
  target.c_ospeed = 0;
  target.c_ospeed = 0;
#endif
#endif
 
 
  emul_write_buffer(&target, addr, sizeof(target), processor, cia);
  emul_write_buffer(&target, addr, sizeof(target), processor, cia);
}
}
#endif /* HAVE_TERMIOS_STRUCTURE */
#endif /* HAVE_TERMIOS_STRUCTURE */
 
 
#ifndef HAVE_IOCTL
#ifndef HAVE_IOCTL
#define do_linux_ioctl 0
#define do_linux_ioctl 0
#else
#else
static void
static void
do_linux_ioctl(os_emul_data *emul,
do_linux_ioctl(os_emul_data *emul,
               unsigned call,
               unsigned call,
               const int arg0,
               const int arg0,
               cpu *processor,
               cpu *processor,
               unsigned_word cia)
               unsigned_word cia)
{
{
  int fildes = cpu_registers(processor)->gpr[arg0];
  int fildes = cpu_registers(processor)->gpr[arg0];
  unsigned request = cpu_registers(processor)->gpr[arg0+1];
  unsigned request = cpu_registers(processor)->gpr[arg0+1];
  unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
  unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
  int status = 0;
  int status = 0;
  const char *name = "<unknown>";
  const char *name = "<unknown>";
 
 
#ifdef HAVE_TERMIOS_STRUCTURE
#ifdef HAVE_TERMIOS_STRUCTURE
  struct termios host_termio;
  struct termios host_termio;
 
 
#else
#else
#ifdef HAVE_TERMIO_STRUCTURE
#ifdef HAVE_TERMIO_STRUCTURE
  struct termio host_termio;
  struct termio host_termio;
#endif
#endif
#endif
#endif
 
 
  switch (request)
  switch (request)
    {
    {
    case 0:                                      /* make sure we have at least one case */
    case 0:                                      /* make sure we have at least one case */
    default:
    default:
      status = -1;
      status = -1;
      errno = EINVAL;
      errno = EINVAL;
      break;
      break;
 
 
#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
#if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
#if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
    case LINUX_IOR('t', 23, struct linux_termio):       /* TCGETA */
    case LINUX_IOR('t', 23, struct linux_termio):       /* TCGETA */
      name = "TCGETA";
      name = "TCGETA";
#ifdef HAVE_TCGETATTR
#ifdef HAVE_TCGETATTR
      status = tcgetattr(fildes, &host_termio);
      status = tcgetattr(fildes, &host_termio);
#elif defined(TCGETS)
#elif defined(TCGETS)
      status = ioctl (fildes, TCGETS, &host_termio);
      status = ioctl (fildes, TCGETS, &host_termio);
#else
#else
      status = ioctl (fildes, TCGETA, &host_termio);
      status = ioctl (fildes, TCGETA, &host_termio);
#endif
#endif
      if (status == 0)
      if (status == 0)
        convert_to_linux_termio (argp_addr, &host_termio, processor, cia);
        convert_to_linux_termio (argp_addr, &host_termio, processor, cia);
      break;
      break;
#endif /* TCGETA */
#endif /* TCGETA */
#endif /* HAVE_TERMIO_STRUCTURE */
#endif /* HAVE_TERMIO_STRUCTURE */
 
 
#ifdef HAVE_TERMIOS_STRUCTURE
#ifdef HAVE_TERMIOS_STRUCTURE
#if defined(TCGETS) || defined(HAVE_TCGETATTR)
#if defined(TCGETS) || defined(HAVE_TCGETATTR)
    case LINUX_IOR('t', 19, struct linux_termios):      /* TCGETS */
    case LINUX_IOR('t', 19, struct linux_termios):      /* TCGETS */
      name = "TCGETS";
      name = "TCGETS";
#ifdef HAVE_TCGETATTR
#ifdef HAVE_TCGETATTR
      status = tcgetattr(fildes, &host_termio);
      status = tcgetattr(fildes, &host_termio);
#else
#else
      status = ioctl (fildes, TCGETS, &host_termio);
      status = ioctl (fildes, TCGETS, &host_termio);
#endif
#endif
      if (status == 0)
      if (status == 0)
        convert_to_linux_termios (argp_addr, &host_termio, processor, cia);
        convert_to_linux_termios (argp_addr, &host_termio, processor, cia);
      break;
      break;
#endif /* TCGETS */
#endif /* TCGETS */
#endif /* HAVE_TERMIOS_STRUCTURE */
#endif /* HAVE_TERMIOS_STRUCTURE */
    }
    }
 
 
  emul_write_status(processor, status, errno);
  emul_write_status(processor, status, errno);
 
 
  if (WITH_TRACE && ppc_trace[trace_os_emul])
  if (WITH_TRACE && ppc_trace[trace_os_emul])
    printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);
    printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);
}
}
#endif /* HAVE_IOCTL */
#endif /* HAVE_IOCTL */
 
 
static emul_syscall_descriptor linux_descriptors[] = {
static emul_syscall_descriptor linux_descriptors[] = {
  /*   0 */ { 0, "setup" },
  /*   0 */ { 0, "setup" },
  /*   1 */ { do_unix_exit, "exit" },
  /*   1 */ { do_unix_exit, "exit" },
  /*   2 */ { 0, "fork" },
  /*   2 */ { 0, "fork" },
  /*   3 */ { do_unix_read, "read" },
  /*   3 */ { do_unix_read, "read" },
  /*   4 */ { do_unix_write, "write" },
  /*   4 */ { do_unix_write, "write" },
  /*   5 */ { do_unix_open, "open" },
  /*   5 */ { do_unix_open, "open" },
  /*   6 */ { do_unix_close, "close" },
  /*   6 */ { do_unix_close, "close" },
  /*   7 */ { 0, "waitpid" },
  /*   7 */ { 0, "waitpid" },
  /*   8 */ { 0, "creat" },
  /*   8 */ { 0, "creat" },
  /*   9 */ { do_unix_link, "link" },
  /*   9 */ { do_unix_link, "link" },
  /*  10 */ { do_unix_unlink, "unlink" },
  /*  10 */ { do_unix_unlink, "unlink" },
  /*  11 */ { 0, "execve" },
  /*  11 */ { 0, "execve" },
  /*  12 */ { do_unix_chdir, "chdir" },
  /*  12 */ { do_unix_chdir, "chdir" },
  /*  13 */ { do_unix_time, "time" },
  /*  13 */ { do_unix_time, "time" },
  /*  14 */ { 0, "mknod" },
  /*  14 */ { 0, "mknod" },
  /*  15 */ { 0, "chmod" },
  /*  15 */ { 0, "chmod" },
  /*  16 */ { 0, "chown" },
  /*  16 */ { 0, "chown" },
  /*  17 */ { 0, "break" },
  /*  17 */ { 0, "break" },
  /*  18 */ { 0, "stat" },
  /*  18 */ { 0, "stat" },
  /*  19 */ { do_unix_lseek, "lseek" },
  /*  19 */ { do_unix_lseek, "lseek" },
  /*  20 */ { do_unix_getpid, "getpid" },
  /*  20 */ { do_unix_getpid, "getpid" },
  /*  21 */ { 0, "mount" },
  /*  21 */ { 0, "mount" },
  /*  22 */ { 0, "umount" },
  /*  22 */ { 0, "umount" },
  /*  23 */ { 0, "setuid" },
  /*  23 */ { 0, "setuid" },
  /*  24 */ { do_unix_getuid, "getuid" },
  /*  24 */ { do_unix_getuid, "getuid" },
  /*  25 */ { 0, "stime" },
  /*  25 */ { 0, "stime" },
  /*  26 */ { 0, "ptrace" },
  /*  26 */ { 0, "ptrace" },
  /*  27 */ { 0, "alarm" },
  /*  27 */ { 0, "alarm" },
  /*  28 */ { 0, "fstat" },
  /*  28 */ { 0, "fstat" },
  /*  29 */ { 0, "pause" },
  /*  29 */ { 0, "pause" },
  /*  30 */ { 0, "utime" },
  /*  30 */ { 0, "utime" },
  /*  31 */ { 0, "stty" },
  /*  31 */ { 0, "stty" },
  /*  32 */ { 0, "gtty" },
  /*  32 */ { 0, "gtty" },
  /*  33 */ { do_unix_access, "access" },
  /*  33 */ { do_unix_access, "access" },
  /*  34 */ { 0, "nice" },
  /*  34 */ { 0, "nice" },
  /*  35 */ { 0, "ftime" },
  /*  35 */ { 0, "ftime" },
  /*  36 */ { 0, "sync" },
  /*  36 */ { 0, "sync" },
  /*  37 */ { 0, "kill" },
  /*  37 */ { 0, "kill" },
  /*  38 */ { 0, "rename" },
  /*  38 */ { 0, "rename" },
  /*  39 */ { do_unix_mkdir, "mkdir" },
  /*  39 */ { do_unix_mkdir, "mkdir" },
  /*  40 */ { do_unix_rmdir, "rmdir" },
  /*  40 */ { do_unix_rmdir, "rmdir" },
  /*  41 */ { do_unix_dup, "dup" },
  /*  41 */ { do_unix_dup, "dup" },
  /*  42 */ { 0, "pipe" },
  /*  42 */ { 0, "pipe" },
  /*  43 */ { 0, "times" },
  /*  43 */ { 0, "times" },
  /*  44 */ { 0, "prof" },
  /*  44 */ { 0, "prof" },
  /*  45 */ { do_unix_break, "brk" },
  /*  45 */ { do_unix_break, "brk" },
  /*  46 */ { 0, "setgid" },
  /*  46 */ { 0, "setgid" },
  /*  47 */ { do_unix_getgid, "getgid" },
  /*  47 */ { do_unix_getgid, "getgid" },
  /*  48 */ { 0, "signal" },
  /*  48 */ { 0, "signal" },
  /*  49 */ { do_unix_geteuid, "geteuid" },
  /*  49 */ { do_unix_geteuid, "geteuid" },
  /*  50 */ { do_unix_getegid, "getegid" },
  /*  50 */ { do_unix_getegid, "getegid" },
  /*  51 */ { 0, "acct" },
  /*  51 */ { 0, "acct" },
  /*  52 */ { 0, "phys" },
  /*  52 */ { 0, "phys" },
  /*  53 */ { 0, "lock" },
  /*  53 */ { 0, "lock" },
  /*  54 */ { do_linux_ioctl, "ioctl" },
  /*  54 */ { do_linux_ioctl, "ioctl" },
  /*  55 */ { 0, "fcntl" },
  /*  55 */ { 0, "fcntl" },
  /*  56 */ { 0, "mpx" },
  /*  56 */ { 0, "mpx" },
  /*  57 */ { 0, "setpgid" },
  /*  57 */ { 0, "setpgid" },
  /*  58 */ { 0, "ulimit" },
  /*  58 */ { 0, "ulimit" },
  /*  59 */ { 0, "olduname" },
  /*  59 */ { 0, "olduname" },
  /*  60 */ { do_unix_umask, "umask" },
  /*  60 */ { do_unix_umask, "umask" },
  /*  61 */ { 0, "chroot" },
  /*  61 */ { 0, "chroot" },
  /*  62 */ { 0, "ustat" },
  /*  62 */ { 0, "ustat" },
  /*  63 */ { do_unix_dup2, "dup2" },
  /*  63 */ { do_unix_dup2, "dup2" },
  /*  64 */ { do_unix_getppid, "getppid" },
  /*  64 */ { do_unix_getppid, "getppid" },
  /*  65 */ { 0, "getpgrp" },
  /*  65 */ { 0, "getpgrp" },
  /*  66 */ { 0, "setsid" },
  /*  66 */ { 0, "setsid" },
  /*  67 */ { 0, "sigaction" },
  /*  67 */ { 0, "sigaction" },
  /*  68 */ { 0, "sgetmask" },
  /*  68 */ { 0, "sgetmask" },
  /*  69 */ { 0, "ssetmask" },
  /*  69 */ { 0, "ssetmask" },
  /*  70 */ { 0, "setreuid" },
  /*  70 */ { 0, "setreuid" },
  /*  71 */ { 0, "setregid" },
  /*  71 */ { 0, "setregid" },
  /*  72 */ { 0, "sigsuspend" },
  /*  72 */ { 0, "sigsuspend" },
  /*  73 */ { 0, "sigpending" },
  /*  73 */ { 0, "sigpending" },
  /*  74 */ { 0, "sethostname" },
  /*  74 */ { 0, "sethostname" },
  /*  75 */ { 0, "setrlimit" },
  /*  75 */ { 0, "setrlimit" },
  /*  76 */ { 0, "getrlimit" },
  /*  76 */ { 0, "getrlimit" },
  /*  77 */ { do_unix_getrusage, "getrusage" },
  /*  77 */ { do_unix_getrusage, "getrusage" },
  /*  78 */ { do_unix_gettimeofday, "gettimeofday" },
  /*  78 */ { do_unix_gettimeofday, "gettimeofday" },
  /*  79 */ { 0, "settimeofday" },
  /*  79 */ { 0, "settimeofday" },
  /*  80 */ { 0, "getgroups" },
  /*  80 */ { 0, "getgroups" },
  /*  81 */ { 0, "setgroups" },
  /*  81 */ { 0, "setgroups" },
  /*  82 */ { 0, "select" },
  /*  82 */ { 0, "select" },
  /*  83 */ { do_unix_symlink, "symlink" },
  /*  83 */ { do_unix_symlink, "symlink" },
  /*  84 */ { 0, "lstat" },
  /*  84 */ { 0, "lstat" },
  /*  85 */ { 0, "readlink" },
  /*  85 */ { 0, "readlink" },
  /*  86 */ { 0, "uselib" },
  /*  86 */ { 0, "uselib" },
  /*  87 */ { 0, "swapon" },
  /*  87 */ { 0, "swapon" },
  /*  88 */ { 0, "reboot" },
  /*  88 */ { 0, "reboot" },
  /*  89 */ { 0, "readdir" },
  /*  89 */ { 0, "readdir" },
  /*  90 */ { 0, "mmap" },
  /*  90 */ { 0, "mmap" },
  /*  91 */ { 0, "munmap" },
  /*  91 */ { 0, "munmap" },
  /*  92 */ { 0, "truncate" },
  /*  92 */ { 0, "truncate" },
  /*  93 */ { 0, "ftruncate" },
  /*  93 */ { 0, "ftruncate" },
  /*  94 */ { 0, "fchmod" },
  /*  94 */ { 0, "fchmod" },
  /*  95 */ { 0, "fchown" },
  /*  95 */ { 0, "fchown" },
  /*  96 */ { 0, "getpriority" },
  /*  96 */ { 0, "getpriority" },
  /*  97 */ { 0, "setpriority" },
  /*  97 */ { 0, "setpriority" },
  /*  98 */ { 0, "profil" },
  /*  98 */ { 0, "profil" },
  /*  99 */ { 0, "statfs" },
  /*  99 */ { 0, "statfs" },
  /* 100 */ { 0, "fstatfs" },
  /* 100 */ { 0, "fstatfs" },
  /* 101 */ { 0, "ioperm" },
  /* 101 */ { 0, "ioperm" },
  /* 102 */ { 0, "socketcall" },
  /* 102 */ { 0, "socketcall" },
  /* 103 */ { 0, "syslog" },
  /* 103 */ { 0, "syslog" },
  /* 104 */ { 0, "setitimer" },
  /* 104 */ { 0, "setitimer" },
  /* 105 */ { 0, "getitimer" },
  /* 105 */ { 0, "getitimer" },
  /* 106 */ { do_linux_stat, "newstat" },
  /* 106 */ { do_linux_stat, "newstat" },
  /* 107 */ { do_linux_lstat, "newlstat" },
  /* 107 */ { do_linux_lstat, "newlstat" },
  /* 108 */ { do_linux_fstat, "newfstat" },
  /* 108 */ { do_linux_fstat, "newfstat" },
  /* 109 */ { 0, "uname" },
  /* 109 */ { 0, "uname" },
  /* 110 */ { 0, "iopl" },
  /* 110 */ { 0, "iopl" },
  /* 111 */ { 0, "vhangup" },
  /* 111 */ { 0, "vhangup" },
  /* 112 */ { 0, "idle" },
  /* 112 */ { 0, "idle" },
  /* 113 */ { 0, "vm86" },
  /* 113 */ { 0, "vm86" },
  /* 114 */ { 0, "wait4" },
  /* 114 */ { 0, "wait4" },
  /* 115 */ { 0, "swapoff" },
  /* 115 */ { 0, "swapoff" },
  /* 116 */ { 0, "sysinfo" },
  /* 116 */ { 0, "sysinfo" },
  /* 117 */ { 0, "ipc" },
  /* 117 */ { 0, "ipc" },
  /* 118 */ { 0, "fsync" },
  /* 118 */ { 0, "fsync" },
  /* 119 */ { 0, "sigreturn" },
  /* 119 */ { 0, "sigreturn" },
  /* 120 */ { 0, "clone" },
  /* 120 */ { 0, "clone" },
  /* 121 */ { 0, "setdomainname" },
  /* 121 */ { 0, "setdomainname" },
  /* 122 */ { 0, "newuname" },
  /* 122 */ { 0, "newuname" },
  /* 123 */ { 0, "modify_ldt" },
  /* 123 */ { 0, "modify_ldt" },
  /* 124 */ { 0, "adjtimex" },
  /* 124 */ { 0, "adjtimex" },
  /* 125 */ { 0, "mprotect" },
  /* 125 */ { 0, "mprotect" },
  /* 126 */ { 0, "sigprocmask" },
  /* 126 */ { 0, "sigprocmask" },
  /* 127 */ { 0, "create_module" },
  /* 127 */ { 0, "create_module" },
  /* 128 */ { 0, "init_module" },
  /* 128 */ { 0, "init_module" },
  /* 129 */ { 0, "delete_module" },
  /* 129 */ { 0, "delete_module" },
  /* 130 */ { 0, "get_kernel_syms" },
  /* 130 */ { 0, "get_kernel_syms" },
  /* 131 */ { 0, "quotactl" },
  /* 131 */ { 0, "quotactl" },
  /* 132 */ { 0, "getpgid" },
  /* 132 */ { 0, "getpgid" },
  /* 133 */ { 0, "fchdir" },
  /* 133 */ { 0, "fchdir" },
  /* 134 */ { 0, "bdflush" },
  /* 134 */ { 0, "bdflush" },
  /* 135 */ { 0, "sysfs" },
  /* 135 */ { 0, "sysfs" },
  /* 136 */ { 0, "personality" },
  /* 136 */ { 0, "personality" },
  /* 137 */ { 0, "afs_syscall" },
  /* 137 */ { 0, "afs_syscall" },
  /* 138 */ { 0, "setfsuid" },
  /* 138 */ { 0, "setfsuid" },
  /* 139 */ { 0, "setfsgid" },
  /* 139 */ { 0, "setfsgid" },
  /* 140 */ { 0, "llseek" },
  /* 140 */ { 0, "llseek" },
  /* 141 */ { 0, "getdents" },
  /* 141 */ { 0, "getdents" },
  /* 142 */ { 0, "newselect" },
  /* 142 */ { 0, "newselect" },
  /* 143 */ { 0, "flock" },
  /* 143 */ { 0, "flock" },
  /* 144 */ { 0, "msync" },
  /* 144 */ { 0, "msync" },
  /* 145 */ { 0, "readv" },
  /* 145 */ { 0, "readv" },
  /* 146 */ { 0, "writev" },
  /* 146 */ { 0, "writev" },
  /* 147 */ { 0, "getsid" },
  /* 147 */ { 0, "getsid" },
  /* 148 */ { 0, "fdatasync" },
  /* 148 */ { 0, "fdatasync" },
  /* 149 */ { 0, "sysctl" },
  /* 149 */ { 0, "sysctl" },
  /* 150 */ { 0, "mlock" },
  /* 150 */ { 0, "mlock" },
  /* 151 */ { 0, "munlock" },
  /* 151 */ { 0, "munlock" },
  /* 152 */ { 0, "mlockall" },
  /* 152 */ { 0, "mlockall" },
  /* 153 */ { 0, "munlockall" },
  /* 153 */ { 0, "munlockall" },
  /* 154 */ { 0, "sched_setparam" },
  /* 154 */ { 0, "sched_setparam" },
  /* 155 */ { 0, "sched_getparam" },
  /* 155 */ { 0, "sched_getparam" },
  /* 156 */ { 0, "sched_setscheduler" },
  /* 156 */ { 0, "sched_setscheduler" },
  /* 157 */ { 0, "sched_getscheduler" },
  /* 157 */ { 0, "sched_getscheduler" },
  /* 158 */ { 0, "sched_yield" },
  /* 158 */ { 0, "sched_yield" },
  /* 159 */ { 0, "sched_get_priority_max" },
  /* 159 */ { 0, "sched_get_priority_max" },
  /* 160 */ { 0, "sched_get_priority_min" },
  /* 160 */ { 0, "sched_get_priority_min" },
  /* 161 */ { 0, "sched_rr_get_interval" },
  /* 161 */ { 0, "sched_rr_get_interval" },
};
};
 
 
static char *(linux_error_names[]) = {
static char *(linux_error_names[]) = {
  /*   0 */ "ESUCCESS",
  /*   0 */ "ESUCCESS",
  /*   1 */ "EPERM",
  /*   1 */ "EPERM",
  /*   2 */ "ENOENT",
  /*   2 */ "ENOENT",
  /*   3 */ "ESRCH",
  /*   3 */ "ESRCH",
  /*   4 */ "EINTR",
  /*   4 */ "EINTR",
  /*   5 */ "EIO",
  /*   5 */ "EIO",
  /*   6 */ "ENXIO",
  /*   6 */ "ENXIO",
  /*   7 */ "E2BIG",
  /*   7 */ "E2BIG",
  /*   8 */ "ENOEXEC",
  /*   8 */ "ENOEXEC",
  /*   9 */ "EBADF",
  /*   9 */ "EBADF",
  /*  10 */ "ECHILD",
  /*  10 */ "ECHILD",
  /*  11 */ "EAGAIN",
  /*  11 */ "EAGAIN",
  /*  12 */ "ENOMEM",
  /*  12 */ "ENOMEM",
  /*  13 */ "EACCES",
  /*  13 */ "EACCES",
  /*  14 */ "EFAULT",
  /*  14 */ "EFAULT",
  /*  15 */ "ENOTBLK",
  /*  15 */ "ENOTBLK",
  /*  16 */ "EBUSY",
  /*  16 */ "EBUSY",
  /*  17 */ "EEXIST",
  /*  17 */ "EEXIST",
  /*  18 */ "EXDEV",
  /*  18 */ "EXDEV",
  /*  19 */ "ENODEV",
  /*  19 */ "ENODEV",
  /*  20 */ "ENOTDIR",
  /*  20 */ "ENOTDIR",
  /*  21 */ "EISDIR",
  /*  21 */ "EISDIR",
  /*  22 */ "EINVAL",
  /*  22 */ "EINVAL",
  /*  23 */ "ENFILE",
  /*  23 */ "ENFILE",
  /*  24 */ "EMFILE",
  /*  24 */ "EMFILE",
  /*  25 */ "ENOTTY",
  /*  25 */ "ENOTTY",
  /*  26 */ "ETXTBSY",
  /*  26 */ "ETXTBSY",
  /*  27 */ "EFBIG",
  /*  27 */ "EFBIG",
  /*  28 */ "ENOSPC",
  /*  28 */ "ENOSPC",
  /*  29 */ "ESPIPE",
  /*  29 */ "ESPIPE",
  /*  30 */ "EROFS",
  /*  30 */ "EROFS",
  /*  31 */ "EMLINK",
  /*  31 */ "EMLINK",
  /*  32 */ "EPIPE",
  /*  32 */ "EPIPE",
  /*  33 */ "EDOM",
  /*  33 */ "EDOM",
  /*  34 */ "ERANGE",
  /*  34 */ "ERANGE",
  /*  35 */ "EDEADLK",
  /*  35 */ "EDEADLK",
  /*  36 */ "ENAMETOOLONG",
  /*  36 */ "ENAMETOOLONG",
  /*  37 */ "ENOLCK",
  /*  37 */ "ENOLCK",
  /*  38 */ "ENOSYS",
  /*  38 */ "ENOSYS",
  /*  39 */ "ENOTEMPTY",
  /*  39 */ "ENOTEMPTY",
  /*  40 */ "ELOOP",
  /*  40 */ "ELOOP",
  /*  41 */ 0,
  /*  41 */ 0,
  /*  42 */ "ENOMSG",
  /*  42 */ "ENOMSG",
  /*  43 */ "EIDRM",
  /*  43 */ "EIDRM",
  /*  44 */ "ECHRNG",
  /*  44 */ "ECHRNG",
  /*  45 */ "EL2NSYNC",
  /*  45 */ "EL2NSYNC",
  /*  46 */ "EL3HLT",
  /*  46 */ "EL3HLT",
  /*  47 */ "EL3RST",
  /*  47 */ "EL3RST",
  /*  48 */ "ELNRNG",
  /*  48 */ "ELNRNG",
  /*  49 */ "EUNATCH",
  /*  49 */ "EUNATCH",
  /*  50 */ "ENOCSI",
  /*  50 */ "ENOCSI",
  /*  51 */ "EL2HLT",
  /*  51 */ "EL2HLT",
  /*  52 */ "EBADE",
  /*  52 */ "EBADE",
  /*  53 */ "EBADR",
  /*  53 */ "EBADR",
  /*  54 */ "EXFULL",
  /*  54 */ "EXFULL",
  /*  55 */ "ENOANO",
  /*  55 */ "ENOANO",
  /*  56 */ "EBADRQC",
  /*  56 */ "EBADRQC",
  /*  57 */ "EBADSLT",
  /*  57 */ "EBADSLT",
  /*  58 */ "EDEADLOCK",
  /*  58 */ "EDEADLOCK",
  /*  59 */ "EBFONT",
  /*  59 */ "EBFONT",
  /*  60 */ "ENOSTR",
  /*  60 */ "ENOSTR",
  /*  61 */ "ENODATA",
  /*  61 */ "ENODATA",
  /*  62 */ "ETIME",
  /*  62 */ "ETIME",
  /*  63 */ "ENOSR",
  /*  63 */ "ENOSR",
  /*  64 */ "ENONET",
  /*  64 */ "ENONET",
  /*  65 */ "ENOPKG",
  /*  65 */ "ENOPKG",
  /*  66 */ "EREMOTE",
  /*  66 */ "EREMOTE",
  /*  67 */ "ENOLINK",
  /*  67 */ "ENOLINK",
  /*  68 */ "EADV",
  /*  68 */ "EADV",
  /*  69 */ "ESRMNT",
  /*  69 */ "ESRMNT",
  /*  70 */ "ECOMM",
  /*  70 */ "ECOMM",
  /*  71 */ "EPROTO",
  /*  71 */ "EPROTO",
  /*  72 */ "EMULTIHOP",
  /*  72 */ "EMULTIHOP",
  /*  73 */ "EDOTDOT",
  /*  73 */ "EDOTDOT",
  /*  74 */ "EBADMSG",
  /*  74 */ "EBADMSG",
  /*  75 */ "EOVERFLOW",
  /*  75 */ "EOVERFLOW",
  /*  76 */ "ENOTUNIQ",
  /*  76 */ "ENOTUNIQ",
  /*  77 */ "EBADFD",
  /*  77 */ "EBADFD",
  /*  78 */ "EREMCHG",
  /*  78 */ "EREMCHG",
  /*  79 */ "ELIBACC",
  /*  79 */ "ELIBACC",
  /*  80 */ "ELIBBAD",
  /*  80 */ "ELIBBAD",
  /*  81 */ "ELIBSCN",
  /*  81 */ "ELIBSCN",
  /*  82 */ "ELIBMAX",
  /*  82 */ "ELIBMAX",
  /*  83 */ "ELIBEXEC",
  /*  83 */ "ELIBEXEC",
  /*  84 */ "EILSEQ",
  /*  84 */ "EILSEQ",
  /*  85 */ "ERESTART",
  /*  85 */ "ERESTART",
  /*  86 */ "ESTRPIPE",
  /*  86 */ "ESTRPIPE",
  /*  87 */ "EUSERS",
  /*  87 */ "EUSERS",
  /*  88 */ "ENOTSOCK",
  /*  88 */ "ENOTSOCK",
  /*  89 */ "EDESTADDRREQ",
  /*  89 */ "EDESTADDRREQ",
  /*  90 */ "EMSGSIZE",
  /*  90 */ "EMSGSIZE",
  /*  91 */ "EPROTOTYPE",
  /*  91 */ "EPROTOTYPE",
  /*  92 */ "ENOPROTOOPT",
  /*  92 */ "ENOPROTOOPT",
  /*  93 */ "EPROTONOSUPPORT",
  /*  93 */ "EPROTONOSUPPORT",
  /*  94 */ "ESOCKTNOSUPPORT",
  /*  94 */ "ESOCKTNOSUPPORT",
  /*  95 */ "EOPNOTSUPP",
  /*  95 */ "EOPNOTSUPP",
  /*  96 */ "EPFNOSUPPORT",
  /*  96 */ "EPFNOSUPPORT",
  /*  97 */ "EAFNOSUPPORT",
  /*  97 */ "EAFNOSUPPORT",
  /*  98 */ "EADDRINUSE",
  /*  98 */ "EADDRINUSE",
  /*  99 */ "EADDRNOTAVAIL",
  /*  99 */ "EADDRNOTAVAIL",
  /* 100 */ "ENETDOWN",
  /* 100 */ "ENETDOWN",
  /* 101 */ "ENETUNREACH",
  /* 101 */ "ENETUNREACH",
  /* 102 */ "ENETRESET",
  /* 102 */ "ENETRESET",
  /* 103 */ "ECONNABORTED",
  /* 103 */ "ECONNABORTED",
  /* 104 */ "ECONNRESET",
  /* 104 */ "ECONNRESET",
  /* 105 */ "ENOBUFS",
  /* 105 */ "ENOBUFS",
  /* 106 */ "EISCONN",
  /* 106 */ "EISCONN",
  /* 107 */ "ENOTCONN",
  /* 107 */ "ENOTCONN",
  /* 108 */ "ESHUTDOWN",
  /* 108 */ "ESHUTDOWN",
  /* 109 */ "ETOOMANYREFS",
  /* 109 */ "ETOOMANYREFS",
  /* 110 */ "ETIMEDOUT",
  /* 110 */ "ETIMEDOUT",
  /* 111 */ "ECONNREFUSED",
  /* 111 */ "ECONNREFUSED",
  /* 112 */ "EHOSTDOWN",
  /* 112 */ "EHOSTDOWN",
  /* 113 */ "EHOSTUNREACH",
  /* 113 */ "EHOSTUNREACH",
  /* 114 */ "EALREADY",
  /* 114 */ "EALREADY",
  /* 115 */ "EINPROGRESS",
  /* 115 */ "EINPROGRESS",
  /* 116 */ "ESTALE",
  /* 116 */ "ESTALE",
  /* 117 */ "EUCLEAN",
  /* 117 */ "EUCLEAN",
  /* 118 */ "ENOTNAM",
  /* 118 */ "ENOTNAM",
  /* 119 */ "ENAVAIL",
  /* 119 */ "ENAVAIL",
  /* 120 */ "EISNAM",
  /* 120 */ "EISNAM",
  /* 121 */ "EREMOTEIO",
  /* 121 */ "EREMOTEIO",
  /* 122 */ "EDQUOT",
  /* 122 */ "EDQUOT",
};
};
 
 
static char *(linux_signal_names[]) = {
static char *(linux_signal_names[]) = {
  /*  0 */ 0,
  /*  0 */ 0,
  /*  1 */ "SIGHUP",
  /*  1 */ "SIGHUP",
  /*  2 */ "SIGINT",
  /*  2 */ "SIGINT",
  /*  3 */ "SIGQUIT",
  /*  3 */ "SIGQUIT",
  /*  4 */ "SIGILL",
  /*  4 */ "SIGILL",
  /*  5 */ "SIGTRAP",
  /*  5 */ "SIGTRAP",
  /*  6 */ "SIGABRT",
  /*  6 */ "SIGABRT",
  /*  6 */ "SIGIOT",
  /*  6 */ "SIGIOT",
  /*  7 */ "SIGBUS",
  /*  7 */ "SIGBUS",
  /*  8 */ "SIGFPE",
  /*  8 */ "SIGFPE",
  /*  9 */ "SIGKILL",
  /*  9 */ "SIGKILL",
  /* 10 */ "SIGUSR1",
  /* 10 */ "SIGUSR1",
  /* 11 */ "SIGSEGV",
  /* 11 */ "SIGSEGV",
  /* 12 */ "SIGUSR2",
  /* 12 */ "SIGUSR2",
  /* 13 */ "SIGPIPE",
  /* 13 */ "SIGPIPE",
  /* 14 */ "SIGALRM",
  /* 14 */ "SIGALRM",
  /* 15 */ "SIGTERM",
  /* 15 */ "SIGTERM",
  /* 16 */ "SIGSTKFLT",
  /* 16 */ "SIGSTKFLT",
  /* 17 */ "SIGCHLD",
  /* 17 */ "SIGCHLD",
  /* 18 */ "SIGCONT",
  /* 18 */ "SIGCONT",
  /* 19 */ "SIGSTOP",
  /* 19 */ "SIGSTOP",
  /* 20 */ "SIGTSTP",
  /* 20 */ "SIGTSTP",
  /* 21 */ "SIGTTIN",
  /* 21 */ "SIGTTIN",
  /* 22 */ "SIGTTOU",
  /* 22 */ "SIGTTOU",
  /* 23 */ "SIGURG",
  /* 23 */ "SIGURG",
  /* 24 */ "SIGXCPU",
  /* 24 */ "SIGXCPU",
  /* 25 */ "SIGXFSZ",
  /* 25 */ "SIGXFSZ",
  /* 26 */ "SIGVTALRM",
  /* 26 */ "SIGVTALRM",
  /* 27 */ "SIGPROF",
  /* 27 */ "SIGPROF",
  /* 28 */ "SIGWINCH",
  /* 28 */ "SIGWINCH",
  /* 29 */ "SIGIO",
  /* 29 */ "SIGIO",
  /* 30 */ "SIGPWR",
  /* 30 */ "SIGPWR",
  /* 31 */ "SIGUNUSED",
  /* 31 */ "SIGUNUSED",
};
};
 
 
static emul_syscall emul_linux_syscalls = {
static emul_syscall emul_linux_syscalls = {
  linux_descriptors,
  linux_descriptors,
  sizeof(linux_descriptors) / sizeof(linux_descriptors[0]),
  sizeof(linux_descriptors) / sizeof(linux_descriptors[0]),
  linux_error_names,
  linux_error_names,
  sizeof(linux_error_names) / sizeof(linux_error_names[0]),
  sizeof(linux_error_names) / sizeof(linux_error_names[0]),
  linux_signal_names,
  linux_signal_names,
  sizeof(linux_signal_names) / sizeof(linux_signal_names[0]),
  sizeof(linux_signal_names) / sizeof(linux_signal_names[0]),
};
};
 
 
 
 
/* Linux's os_emul interface, most are just passed on to the generic
/* Linux's os_emul interface, most are just passed on to the generic
   syscall stuff */
   syscall stuff */
 
 
static os_emul_data *
static os_emul_data *
emul_linux_create(device *root,
emul_linux_create(device *root,
                  bfd *image,
                  bfd *image,
                  const char *name)
                  const char *name)
{
{
  /* check that this emulation is really for us */
  /* check that this emulation is really for us */
  if (name != NULL && strcmp(name, "linux") != 0)
  if (name != NULL && strcmp(name, "linux") != 0)
    return NULL;
    return NULL;
 
 
  if (image == NULL)
  if (image == NULL)
    return NULL;
    return NULL;
 
 
  return emul_unix_create(root, image, "linux", &emul_linux_syscalls);
  return emul_unix_create(root, image, "linux", &emul_linux_syscalls);
}
}
 
 
static void
static void
emul_linux_init(os_emul_data *emul_data,
emul_linux_init(os_emul_data *emul_data,
                int nr_cpus)
                int nr_cpus)
{
{
  /* nothing yet */
  /* nothing yet */
}
}
 
 
static void
static void
emul_linux_system_call(cpu *processor,
emul_linux_system_call(cpu *processor,
                       unsigned_word cia,
                       unsigned_word cia,
                       os_emul_data *emul_data)
                       os_emul_data *emul_data)
{
{
  emul_do_system_call(emul_data,
  emul_do_system_call(emul_data,
                      emul_data->syscalls,
                      emul_data->syscalls,
                      cpu_registers(processor)->gpr[0],
                      cpu_registers(processor)->gpr[0],
                      3, /*r3 contains arg0*/
                      3, /*r3 contains arg0*/
                      processor,
                      processor,
                      cia);
                      cia);
}
}
 
 
const os_emul emul_linux = {
const os_emul emul_linux = {
  "linux",
  "linux",
  emul_linux_create,
  emul_linux_create,
  emul_linux_init,
  emul_linux_init,
  emul_linux_system_call,
  emul_linux_system_call,
  0, /*instruction_call*/
  0, /*instruction_call*/
  0  /*data*/
  0  /*data*/
};
};
 
 
#endif /* _EMUL_UNIX_C_ */
#endif /* _EMUL_UNIX_C_ */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.