#ifndef _EMUL_NETBSD_C_
#define _EMUL_NETBSD_C_
#include "emul_generic.h"
#include "emul_netbsd.h"
#ifdef HAVE_STRING_H
#include <string.h>
#else
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/errno.h>
#include <sys/param.h>
#include <sys/time.h>
#ifdef HAVE_GETRUSAGE
#ifndef HAVE_SYS_RESOURCE_H
#undef HAVE_GETRUSAGE
#endif
#endif
#ifdef HAVE_GETRUSAGE
#include <sys/resource.h>
int getrusage();
#endif
#if HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#if HAVE_DIRENT_H
# include <dirent.h>
# define NAMLEN(dirent) strlen((dirent)->d_name)
#else
# define dirent direct
# define NAMLEN(dirent) (dirent)->d_namlen
# if HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
# if HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
# if HAVE_NDIR_H
# include <ndir.h>
# endif
#endif
#ifdef HAVE_UNISTD_H
#undef MAXPATHLEN
#include <unistd.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#define WITH_NetBSD_HOST (NetBSD >= 199306)
#if WITH_NetBSD_HOST
#include <sys/syscall.h>
#include <sys/sysctl.h>
#include <sys/mount.h>
extern int getdirentries(int fd, char *buf, int nbytes, long *basep);
#else
#undef HAVE_FSTATFS
#undef HAVE_GETDIRENTRIES
#endif
#if (BSD < 199306)
extern int errno;
#endif
#ifndef STATIC_INLINE_EMUL_NETBSD
#define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
#endif
#if WITH_NetBSD_HOST
#define SYS(X) ASSERT(call == (SYS_##X))
#else
#define SYS(X)
#endif
#if WITH_NetBSD_HOST && (PATH_MAX != 1024)
#error "PATH_MAX not 1024"
#elif !defined(PATH_MAX)
#define PATH_MAX 1024
#endif
struct _os_emul_data {
device *vm;
emul_syscall *syscalls;
};
STATIC_INLINE_EMUL_NETBSD void
write_stat(unsigned_word addr,
struct stat buf,
cpu *processor,
unsigned_word cia)
{
H2T(buf.st_dev);
H2T(buf.st_ino);
H2T(buf.st_mode);
H2T(buf.st_nlink);
H2T(buf.st_uid);
H2T(buf.st_gid);
H2T(buf.st_size);
H2T(buf.st_atime);
H2T(buf.st_mtime);
H2T(buf.st_ctime);
#ifdef AC_STRUCT_ST_RDEV
H2T(buf.st_rdev);
#endif
#ifdef AC_STRUCT_ST_BLKSIZE
H2T(buf.st_blksize);
#endif
#ifdef AC_STRUCT_ST_BLOCKS
H2T(buf.st_blocks);
#endif
#if WITH_NetBSD_HOST
H2T(buf.st_flags);
H2T(buf.st_gen);
#endif
emul_write_buffer(&buf, addr, sizeof(buf), processor, cia);
}
#ifdef HAVE_FSTATFS
STATIC_INLINE_EMUL_NETBSD void
write_statfs(unsigned_word addr,
struct statfs buf,
cpu *processor,
unsigned_word cia)
{
H2T(buf.f_type);
H2T(buf.f_flags);
H2T(buf.f_bsize);
H2T(buf.f_iosize);
H2T(buf.f_blocks);
H2T(buf.f_bfree);
H2T(buf.f_bavail);
H2T(buf.f_files);
H2T(buf.f_ffree);
H2T(buf.f_fsid.val[0]);
H2T(buf.f_fsid.val[1]);
H2T(buf.f_owner);
emul_write_buffer(&buf, addr, sizeof(buf), processor, cia);
}
#endif
STATIC_INLINE_EMUL_NETBSD void
write_timeval(unsigned_word addr,
struct timeval t,
cpu *processor,
unsigned_word cia)
{
H2T(t.tv_sec);
H2T(t.tv_usec);
emul_write_buffer(&t, addr, sizeof(t), processor, cia);
}
STATIC_INLINE_EMUL_NETBSD void
write_timezone(unsigned_word addr,
struct timezone tz,
cpu *processor,
unsigned_word cia)
{
H2T(tz.tz_minuteswest);
H2T(tz.tz_dsttime);
emul_write_buffer(&tz, addr, sizeof(tz), processor, cia);
}
#ifdef HAVE_GETDIRENTRIES
STATIC_INLINE_EMUL_NETBSD void
write_direntries(unsigned_word addr,
char *buf,
int nbytes,
cpu *processor,
unsigned_word cia)
{
while (nbytes > 0) {
struct dirent *out;
struct dirent *in = (struct dirent*)buf;
ASSERT(in->d_reclen <= nbytes);
out = (struct dirent*)zalloc(in->d_reclen);
memcpy(out, in, in->d_reclen);
H2T(out->d_fileno);
H2T(out->d_reclen);
H2T(out->d_type);
H2T(out->d_namlen);
emul_write_buffer(out, addr, in->d_reclen, processor, cia);
nbytes -= in->d_reclen;
addr += in->d_reclen;
buf += in->d_reclen;
zfree(out);
}
}
#endif
#ifdef HAVE_GETRUSAGE
STATIC_INLINE_EMUL_NETBSD void
write_rusage(unsigned_word addr,
struct rusage rusage,
cpu *processor,
unsigned_word cia)
{
H2T(rusage.ru_utime.tv_sec);
H2T(rusage.ru_utime.tv_usec);
H2T(rusage.ru_stime.tv_sec);
H2T(rusage.ru_stime.tv_usec);
H2T(rusage.ru_maxrss);
H2T(rusage.ru_ixrss);
H2T(rusage.ru_idrss);
H2T(rusage.ru_isrss);
H2T(rusage.ru_minflt);
H2T(rusage.ru_majflt);
H2T(rusage.ru_nswap);
H2T(rusage.ru_inblock);
H2T(rusage.ru_oublock);
H2T(rusage.ru_msgsnd);
H2T(rusage.ru_msgrcv);
H2T(rusage.ru_nsignals);
H2T(rusage.ru_nvcsw);
H2T(rusage.ru_nivcsw);
emul_write_buffer(&rusage, addr, sizeof(rusage), processor, cia);
}
#endif
static void
do_exit(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
int status = (int)cpu_registers(processor)->gpr[arg0];
SYS(exit);
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("%d)\n", status);
cpu_halt(processor, cia, was_exited, status);
}
static void
do_read(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
void *scratch_buffer;
int d = (int)cpu_registers(processor)->gpr[arg0];
unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
int nbytes = cpu_registers(processor)->gpr[arg0+2];
int status;
SYS(read);
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
scratch_buffer = zalloc(nbytes);
emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia);
#if 0
if (d == 0) {
status = fread (scratch_buffer, 1, nbytes, stdin);
if (status == 0 && ferror (stdin))
status = -1;
}
#endif
status = read (d, scratch_buffer, nbytes);
emul_write_status(processor, status, errno);
if (status > 0)
emul_write_buffer(scratch_buffer, buf, status, processor, cia);
zfree(scratch_buffer);
}
static void
do_write(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
void *scratch_buffer = NULL;
int d = (int)cpu_registers(processor)->gpr[arg0];
unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
int nbytes = cpu_registers(processor)->gpr[arg0+2];
int status;
SYS(write);
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
scratch_buffer = zalloc(nbytes);
emul_read_buffer(scratch_buffer, buf, nbytes,
processor, cia);
status = write(d, scratch_buffer, nbytes);
emul_write_status(processor, status, errno);
zfree(scratch_buffer);
flush_stdoutput();
}
static void
do_open(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
char path_buf[PATH_MAX];
char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
int flags = (int)cpu_registers(processor)->gpr[arg0+1];
int mode = (int)cpu_registers(processor)->gpr[arg0+2];
int hostflags;
int status;
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr, path, flags, mode);
SYS(open);
if ((flags & 3) == 0)
hostflags = O_RDONLY;
else if ((flags & 3) == 1)
hostflags = O_WRONLY;
else
hostflags = O_RDWR;
if (flags & 0x00000008)
hostflags |= O_APPEND;
if (flags & 0x00000200)
hostflags |= O_CREAT;
if (flags & 0x00000400)
hostflags |= O_TRUNC;
if (flags & 0x00000800)
hostflags |= O_EXCL;
status = open(path, hostflags, mode);
emul_write_status(processor, status, errno);
}
static void
do_close(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
int d = (int)cpu_registers(processor)->gpr[arg0];
int status;
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("%d", d);
SYS(close);
status = close(d);
emul_write_status(processor, status, errno);
}
static void
do_break(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
unsigned_word new_break = cpu_registers(processor)->gpr[arg0];
int status;
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("0x%lx", (long)cpu_registers(processor)->gpr[arg0]);
SYS(break);
status = device_ioctl(emul->vm,
processor,
cia,
device_ioctl_break,
new_break);
emul_write_status(processor, 0, status);
}
#ifndef HAVE_GETPID
#define do_getpid 0
#else
static void
do_getpid(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
SYS(getpid);
emul_write_status(processor, (int)getpid(), 0);
}
#endif
#ifndef HAVE_GETUID
#define do_getuid 0
#else
static void
do_getuid(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
SYS(getuid);
emul_write_status(processor, (int)getuid(), 0);
}
#endif
#ifndef HAVE_GETEUID
#define do_geteuid 0
#else
static void
do_geteuid(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
SYS(geteuid);
emul_write_status(processor, (int)geteuid(), 0);
}
#endif
#ifndef HAVE_KILL
#define do_kill 0
#else
static void
do_kill(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
pid_t pid = cpu_registers(processor)->gpr[arg0];
int sig = cpu_registers(processor)->gpr[arg0+1];
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("%d, %d", (int)pid, sig);
SYS(kill);
printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
(long)cia);
cpu_halt(processor, cia, was_signalled, sig);
}
#endif
#ifndef HAVE_DUP
#define do_dup 0
#else
static void
do_dup(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
int oldd = cpu_registers(processor)->gpr[arg0];
int status = dup(oldd);
int err = errno;
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("%d", oldd);
SYS(dup);
emul_write_status(processor, status, err);
}
#endif
#ifndef HAVE_GETEGID
#define do_getegid 0
#else
static void
do_getegid(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
SYS(getegid);
emul_write_status(processor, (int)getegid(), 0);
}
#endif
#ifndef HAVE_GETGID
#define do_getgid 0
#else
static void
do_getgid(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
SYS(getgid);
emul_write_status(processor, (int)getgid(), 0);
}
#endif
#ifndef HAVE_SIGPROCMASK
#define do_sigprocmask 0
#else
static void
do_sigprocmask(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
natural_word how = cpu_registers(processor)->gpr[arg0];
unsigned_word set = cpu_registers(processor)->gpr[arg0+1];
unsigned_word oset = cpu_registers(processor)->gpr[arg0+2];
#ifdef SYS_sigprocmask
SYS(sigprocmask);
#endif
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("%ld, 0x%ld, 0x%ld", (long)how, (long)set, (long)oset);
emul_write_status(processor, 0, 0);
cpu_registers(processor)->gpr[4] = set;
}
#endif
#ifndef HAVE_IOCTL
#define do_ioctl 0
#else
static void
do_ioctl(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
int d = cpu_registers(processor)->gpr[arg0];
unsigned request = cpu_registers(processor)->gpr[arg0+1];
unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
#if !WITH_NetBSD_HOST
cpu_registers(processor)->gpr[arg0] = 0;
#else
unsigned dir = request & IOC_DIRMASK;
int status;
SYS(ioctl);
if (dir & IOC_IN
|| dir & IOC_OUT
|| !(dir & IOC_VOID))
error("do_ioctl() read or write of parameter not implemented\n");
status = ioctl(d, request, NULL);
emul_write_status(processor, status, errno);
#endif
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("%d, 0x%x, 0x%lx", d, request, (long)argp_addr);
}
#endif
#ifndef HAVE_UMASK
#define do_umask 0
#else
static void
do_umask(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
int mask = cpu_registers(processor)->gpr[arg0];
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("0%o", mask);
SYS(umask);
emul_write_status(processor, umask(mask), 0);
}
#endif
#ifndef HAVE_DUP2
#define do_dup2 0
#else
static void
do_dup2(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
int oldd = cpu_registers(processor)->gpr[arg0];
int newd = cpu_registers(processor)->gpr[arg0+1];
int status = dup2(oldd, newd);
int err = errno;
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("%d, %d", oldd, newd);
SYS(dup2);
emul_write_status(processor, status, err);
}
#endif
#ifndef HAVE_FCNTL
#define do_fcntl 0
#else
static void
do_fcntl(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
int fd = cpu_registers(processor)->gpr[arg0];
int cmd = cpu_registers(processor)->gpr[arg0+1];
int arg = cpu_registers(processor)->gpr[arg0+2];
int status;
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("%d, %d, %d", fd, cmd, arg);
SYS(fcntl);
status = fcntl(fd, cmd, arg);
emul_write_status(processor, status, errno);
}
#endif
#ifndef HAVE_GETTIMEOFDAY
#define do_gettimeofday 0
#else
static void
do_gettimeofday(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
unsigned_word t_addr = cpu_registers(processor)->gpr[arg0];
unsigned_word tz_addr = cpu_registers(processor)->gpr[arg0+1];
struct timeval t;
struct timezone tz;
int status = gettimeofday((t_addr != 0 ? &t : NULL),
(tz_addr != 0 ? &tz : NULL));
int err = errno;
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("0x%lx, 0x%lx", (long)t_addr, (long)tz_addr);
SYS(gettimeofday);
emul_write_status(processor, status, err);
if (status == 0) {
if (t_addr != 0)
write_timeval(t_addr, t, processor, cia);
if (tz_addr != 0)
write_timezone(tz_addr, tz, processor, cia);
}
}
#endif
#ifndef HAVE_GETRUSAGE
#define do_getrusage 0
#else
static void
do_getrusage(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
int who = cpu_registers(processor)->gpr[arg0];
unsigned_word rusage_addr = cpu_registers(processor)->gpr[arg0+1];
struct rusage rusage;
int status = getrusage(who, (rusage_addr != 0 ? &rusage : NULL));
int err = errno;
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("%d, 0x%lx", who, (long)rusage_addr);
SYS(getrusage);
emul_write_status(processor, status, err);
if (status == 0) {
if (rusage_addr != 0)
write_rusage(rusage_addr, rusage, processor, cia);
}
}
#endif
#ifndef HAVE_FSTATFS
#define do_fstatfs 0
#else
static void
do_fstatfs(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
int fd = cpu_registers(processor)->gpr[arg0];
unsigned_word buf_addr = cpu_registers(processor)->gpr[arg0+1];
struct statfs buf;
int status;
if (WITH_TRACE && ppc_trace[trace_os_emul])
printf_filtered ("%d, 0x%lx", fd, (long)buf_addr);
SYS(fstatfs);
status = fstatfs(fd, (buf_addr == 0 ? NULL : &buf));
emul_write_status(processor, status, errno);
if (status == 0) {
if (buf_addr != 0)
write_statfs(buf_addr, buf, processor, cia);
}
}
#endif
#ifndef HAVE_STAT
#define do_stat 0
#else
static void
do_stat(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
char path_buf[PATH_MAX];
unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
struct stat buf;
int status;
#ifdef SYS_stat
SYS(stat);
#endif
status = stat(path, &buf);
emul_write_status(processor, status, errno);
if (status == 0)
write_stat(stat_buf_addr, buf, processor, cia);
}
#endif
#ifndef HAVE_FSTAT
#define do_fstat 0
#else
static void
do_fstat(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
int fd = cpu_registers(processor)->gpr[arg0];
unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
struct stat buf;
int status;
#ifdef SYS_fstat
SYS(fstat);
#endif
status = fstat(fd, &buf);
emul_write_status(processor, status, errno);
write_stat(stat_buf_addr, buf, processor, cia);
}
#endif
#ifndef HAVE_LSTAT
#define do_lstat 0
#else
static void
do_lstat(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
char path_buf[PATH_MAX];
unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
struct stat buf;
int status;
#ifdef SYS_lstat
SYS(lstat);
#endif
status = lstat(path, &buf);
emul_write_status(processor, status, errno);
write_stat(stat_buf_addr, buf, processor, cia);
}
#endif
#ifndef HAVE_GETDIRENTRIES
#define do_getdirentries 0
#else
static void
do_getdirentries(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
int fd = cpu_registers(processor)->gpr[arg0];
unsigned_word buf_addr = cpu_registers(processor)->gpr[arg0+1];
char *buf;
int nbytes = cpu_registers(processor)->gpr[arg0+2];
unsigned_word basep_addr = cpu_registers(processor)->gpr[arg0+3];
long basep;
int status;
#ifdef SYS_getdirentries
SYS(getdirentries);
#endif
if (buf_addr != 0 && nbytes >= 0)
buf = zalloc(nbytes);
else
buf = NULL;
status = getdirentries(fd,
(buf_addr == 0 ? NULL : buf),
nbytes,
(basep_addr == 0 ? NULL : &basep));
emul_write_status(processor, status, errno);
if (basep_addr != 0)
emul_write_word(basep_addr, basep, processor, cia);
if (status > 0)
write_direntries(buf_addr, buf, status, processor, cia);
if (buf != NULL)
zfree(buf);
}
#endif
static void
do___syscall(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
SYS(__syscall);
emul_do_system_call(emul,
emul->syscalls,
cpu_registers(processor)->gpr[arg0],
arg0 + 1,
processor,
cia);
}
#ifndef HAVE_LSEEK
#define do_lseek 0
#else
static void
do_lseek(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
int fildes = cpu_registers(processor)->gpr[arg0];
off_t offset = emul_read_gpr64(processor, arg0+2);
int whence = cpu_registers(processor)->gpr[arg0+4];
off_t status;
SYS(lseek);
status = lseek(fildes, offset, whence);
if (status == -1)
emul_write_status(processor, -1, errno);
else {
emul_write_status(processor, 0, 0);
emul_write_gpr64(processor, 3, status);
}
}
#endif
static void
do___sysctl(os_emul_data *emul,
unsigned call,
const int arg0,
cpu *processor,
unsigned_word cia)
{
unsigned_word name = cpu_registers(processor)->gpr[arg0];
natural_word namelen = cpu_registers(processor)->gpr[arg0+1];
unsigned_word oldp = cpu_registers(processor)->gpr[arg0+2];
unsigned_word oldlenp = cpu_registers(processor)->gpr[arg0+3];
natural_word oldlen;
natural_word mib;
natural_word int_val;
SYS(__sysctl);
if (namelen < 1)
error("system_call()SYS___sysctl bad name[0]\n");
mib = vm_data_map_read_word(cpu_data_map(processor),
name,
processor,
cia);
name += sizeof(mib);
switch ((int)mib) {
case 6:
#if WITH_NetBSD_HOST && (CTL_HW != 6)
# error "CTL_HW"
#endif
if (namelen < 2)
error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
mib = vm_data_map_read_word(cpu_data_map(processor),
name,
processor,
cia);
name += sizeof(mib);
switch ((int)mib) {
case 7:
#if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
# error "HW_PAGESIZE"
#endif
oldlen = vm_data_map_read_word(cpu_data_map(processor),
oldlenp,
processor,
cia);
if (sizeof(natural_word) > oldlen)
error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
int_val = 8192;
oldlen = sizeof(int_val);
emul_write_word(oldp, int_val, processor, cia);
emul_write_word(oldlenp, oldlen, processor, cia);
break;
default:
error("sysctl() CTL_HW.%d unknown\n", mib);
break;
}
break;
default:
error("sysctl() name[0]=%d unknown\n", (int)mib);
break;
}
emul_write_status(processor, 0, 0);
}
static emul_syscall_descriptor netbsd_descriptors[] = {
{ 0, "syscall" },
{ do_exit, "exit" },
{ 0, "fork" },
{ do_read, "read" },
{ do_write, "write" },
{ do_open, "open" },
{ do_close, "close" },
{ 0, "wait4" },
{ 0, },
{ 0, "link" },
{ 0, "unlink" },
{ 0, },
{ 0, "chdir" },
{ 0, "fchdir" },
{ 0, "mknod" },
{ 0, "chmod" },
{ 0, "chown" },
{ do_break, "break" },
{ 0, "getfsstat" },
{ 0, },
{ do_getpid, "getpid" },
{ 0, "mount" },
{ 0, "unmount" },
{ 0, "setuid" },
{ do_getuid, "getuid" },
{ do_geteuid, "geteuid" },
{ 0, "ptrace" },
{ 0, "recvmsg" },
{ 0, "sendmsg" },
{ 0, "recvfrom" },
{ 0, "accept" },
{ 0, "getpeername" },
{ 0, "getsockname" },
{ 0, "access" },
{ 0, "chflags" },
{ 0, "fchflags" },
{ 0, "sync" },
{ do_kill, "kill" },
{ 0, },
{ 0, "getppid" },
{ 0, },
{ do_dup, "dup" },
{ 0, "pipe" },
{ do_getegid, "getegid" },
{ 0, "profil" },
{ 0, "ktrace" },
{ 0, "sigaction" },
{ do_getgid, "getgid" },
{ do_sigprocmask, "sigprocmask" },
{ 0, "getlogin" },
{ 0, "setlogin" },
{ 0, "acct" },
{ 0, "sigpending" },
{ 0, "sigaltstack" },
{ do_ioctl, "ioctl" },
{ 0, "reboot" },
{ 0, "revoke" },
{ 0, "symlink" },
{ 0, "readlink" },
{ 0, "execve" },
{ do_umask, "umask" },
{ 0, "chroot" },
{ 0, },
{ 0, },
{ 0, },
{ 0, "msync" },
{ 0, "vfork" },
{ 0, },
{ 0, },
{ 0, "sbrk" },
{ 0, "sstk" },
{ 0, },
{ 0, "vadvise" },
{ 0, "munmap" },
{ 0, "mprotect" },
{ 0, "madvise" },
{ 0, },
{ 0, },
{ 0, "mincore" },
{ 0, "getgroups" },
{ 0, "setgroups" },
{ 0, "getpgrp" },
{ 0, "setpgid" },
{ 0, "setitimer" },
{ 0, },
{ 0, "swapon" },
{ 0, "getitimer" },
{ 0, },
{ 0, },
{ 0, },
{ do_dup2, "dup2" },
{ 0, },
{ do_fcntl, "fcntl" },
{ 0, "select" },
{ 0, },
{ 0, "fsync" },
{ 0, "setpriority" },
{ 0, "socket" },
{ 0, "connect" },
{ 0, },
{ 0, "getpriority" },
{ 0, },
{ 0, },
{ 0, "sigreturn" },
{ 0, "bind" },
{ 0, "setsockopt" },
{ 0, "listen" },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, "sigsuspend" },
{ 0, },
{ 0, },
{ 0, },
{ 0, "vtrace 115" },
{ do_gettimeofday, "gettimeofday" },
{ do_getrusage, "getrusage" },
{ 0, "getsockopt" },
{ 0, "resuba" },
{ 0, "readv" },
{ 0, "writev" },
{ 0, "settimeofday" },
{ 0, "fchown" },
{ 0, "fchmod" },
{ 0, },
{ 0, },
{ 0, },
{ 0, "rename" },
{ 0, },
{ 0, },
{ 0, "flock" },
{ 0, "mkfifo" },
{ 0, "sendto" },
{ 0, "shutdown" },
{ 0, "socketpair" },
{ 0, "mkdir" },
{ 0, "rmdir" },
{ 0, "utimes" },
{ 0, },
{ 0, "adjtime" },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, "setsid" },
{ 0, "quotactl" },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, "nfssvc" },
{ 0, },
{ 0, "statfs" },
{ do_fstatfs, "fstatfs" },
{ 0, },
{ 0, },
{ 0, "getfh" },
{ 0, },
{ 0, },
{ 0, },
{ 0, "sysarch" },
{ 0, },
{ 0, },
{ 0, },
{ 0, "semsys" },
{ 0, "msgsys" },
{ 0, "shmsys" },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, },
{ 0, "setgid" },
{ 0, "setegid" },
{ 0, "seteuid" },
{ 0, "lfs_bmapv" },
{ 0, "lfs_markv" },
{ 0, "lfs_segclean" },
{ 0, "lfs_segwait" },
{ do_stat, "stat" },
{ do_fstat, "fstat" },
{ do_lstat, "lstat" },
{ 0, "pathconf" },
{ 0, "fpathconf" },
{ 0, },
{ 0, "getrlimit" },
{ 0, "setrlimit" },
{ do_getdirentries, "getdirentries" },
{ 0, "mmap" },
{ do___syscall, "__syscall" },
{ do_lseek, "lseek" },
{ 0, "truncate" },
{ 0, "ftruncate" },
{ do___sysctl, "__sysctl" },
{ 0, "mlock" },
{ 0, "munlock" },
};
static char *(netbsd_error_names[]) = {
"ESUCCESS",
"EPERM",
"ENOENT",
"ESRCH",
"EINTR",
"EIO",
"ENXIO",
"E2BIG",
"ENOEXEC",
"EBADF",
"ECHILD",
"EDEADLK",
"ENOMEM",
"EACCES",
"EFAULT",
"ENOTBLK",
"EBUSY",
"EEXIST",
"EXDEV",
"ENODEV",
"ENOTDIR",
"EISDIR",
"EINVAL",
"ENFILE",
"EMFILE",
"ENOTTY",
"ETXTBSY",
"EFBIG",
"ENOSPC",
"ESPIPE",
"EROFS",
"EMLINK",
"EPIPE",
"EDOM",
"ERANGE",
"EAGAIN",
"EINPROGRESS",
"EALREADY",
"ENOTSOCK",
"EDESTADDRREQ",
"EMSGSIZE",
"EPROTOTYPE",
"ENOPROTOOPT",
"EPROTONOSUPPORT",
"ESOCKTNOSUPPORT",
"EOPNOTSUPP",
"EPFNOSUPPORT",
"EAFNOSUPPORT",
"EADDRINUSE",
"EADDRNOTAVAIL",
"ENETDOWN",
"ENETUNREACH",
"ENETRESET",
"ECONNABORTED",
"ECONNRESET",
"ENOBUFS",
"EISCONN",
"ENOTCONN",
"ESHUTDOWN",
"ETOOMANYREFS",
"ETIMEDOUT",
"ECONNREFUSED",
"ELOOP",
"ENAMETOOLONG",
"EHOSTDOWN",
"EHOSTUNREACH",
"ENOTEMPTY",
"EPROCLIM",
"EUSERS",
"EDQUOT",
"ESTALE",
"EREMOTE",
"EBADRPC",
"ERPCMISMATCH",
"EPROGUNAVAIL",
"EPROGMISMATCH",
"EPROCUNAVAIL",
"ENOLCK",
"ENOSYS",
"EFTYPE",
"EAUTH",
"ENEEDAUTH",
"ELAST",
};
static char *(netbsd_signal_names[]) = {
0,
"SIGHUP",
"SIGINT",
"SIGQUIT",
"SIGILL",
"SIGTRAP",
"SIGABRT",
"SIGEMT",
"SIGFPE",
"SIGKILL",
"SIGBUS",
"SIGSEGV",
"SIGSYS",
"SIGPIPE",
"SIGALRM",
"SIGTERM",
"SIGURG",
"SIGSTOP",
"SIGTSTP",
"SIGCONT",
"SIGCHLD",
"SIGTTIN",
"SIGTTOU",
"SIGIO",
"SIGXCPU",
"SIGXFSZ",
"SIGVTALRM",
"SIGPROF",
"SIGWINCH",
"SIGINFO",
"SIGUSR1",
"SIGUSR2",
};
static emul_syscall emul_netbsd_syscalls = {
netbsd_descriptors,
sizeof(netbsd_descriptors) / sizeof(netbsd_descriptors[0]),
netbsd_error_names,
sizeof(netbsd_error_names) / sizeof(netbsd_error_names[0]),
netbsd_signal_names,
sizeof(netbsd_signal_names) / sizeof(netbsd_signal_names[0]),
};
static os_emul_data *
emul_netbsd_create(device *root,
bfd *image,
const char *name)
{
unsigned_word top_of_stack;
unsigned stack_size;
int elf_binary;
os_emul_data *bsd_data;
device *vm;
if (name != NULL && strcmp(name, "netbsd") != 0)
return NULL;
if (image == NULL)
return NULL;
if (image->xvec->flavour == bfd_target_elf_flavour) {
elf_binary = 1;
top_of_stack = 0xe0000000;
stack_size = 0x00100000;
}
else {
elf_binary = 0;
top_of_stack = 0x20000000;
stack_size = 0x00100000;
}
emul_add_tree_options(root, image, "netbsd",
(WITH_ENVIRONMENT == USER_ENVIRONMENT
? "user" : "virtual"),
0 );
vm = tree_parse(root, "/openprom/vm");
tree_parse(vm, "./stack-base 0x%lx",
(unsigned long)(top_of_stack - stack_size));
tree_parse(vm, "./nr-bytes 0x%x", stack_size);
tree_parse(root, "/openprom/vm/map-binary/file-name %s",
bfd_get_filename(image));
tree_parse(root, "/openprom/init/register/pc 0x%lx",
(unsigned long)bfd_get_start_address(image));
tree_parse(root, "/openprom/init/register/sp 0x%lx",
(unsigned long)top_of_stack);
tree_parse(root, "/openprom/init/register/msr 0x%x",
((tree_find_boolean_property(root, "/options/little-endian?")
? msr_little_endian_mode
: 0)
| (tree_find_boolean_property(root, "/openprom/options/floating-point?")
? (msr_floating_point_available
| msr_floating_point_exception_mode_0
| msr_floating_point_exception_mode_1)
: 0)));
tree_parse(root, "/openprom/init/stack/stack-type %s",
(elf_binary ? "ppc-elf" : "ppc-xcoff"));
bsd_data = ZALLOC(os_emul_data);
bsd_data->vm = vm;
bsd_data->syscalls = &emul_netbsd_syscalls;
return bsd_data;
}
static void
emul_netbsd_init(os_emul_data *emul_data,
int nr_cpus)
{
}
static void
emul_netbsd_system_call(cpu *processor,
unsigned_word cia,
os_emul_data *emul_data)
{
emul_do_system_call(emul_data,
emul_data->syscalls,
cpu_registers(processor)->gpr[0],
3,
processor,
cia);
}
const os_emul emul_netbsd = {
"netbsd",
emul_netbsd_create,
emul_netbsd_init,
emul_netbsd_system_call,
0,
0
};
#endif _EMUL_NETBSD_C_