1 /* This file is part of the program psim.
3 Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef _EMUL_NETBSD_C_
23 #define _EMUL_NETBSD_C_
26 /* Note: this module is called via a table. There is no benefit in
29 #include "emul_generic.h"
30 #include "emul_netbsd.h"
40 #include <sys/types.h>
45 #include <sys/errno.h>
46 #include <sys/param.h>
50 #ifndef HAVE_SYS_RESOURCE_H
56 #include <sys/resource.h>
61 #include <sys/ioctl.h>
65 #include <sys/mount.h>
70 # define NAMLEN(dirent) strlen((dirent)->d_name)
72 # define dirent direct
73 # define NAMLEN(dirent) (dirent)->d_namlen
75 # include <sys/ndir.h>
93 #define WITH_NetBSD_HOST (NetBSD >= 199306)
94 #if WITH_NetBSD_HOST /* here NetBSD as that is what we're emulating */
95 #include <sys/syscall.h> /* FIXME - should not be including this one */
96 #include <sys/sysctl.h>
97 extern int getdirentries(int fd, char *buf, int nbytes, long *basep);
100 /* If this is not netbsd, don't allow fstatfs or getdirentries at this time */
102 #undef HAVE_GETDIRENTRIES
105 #if (BSD < 199306) /* here BSD as just a bug */
109 #ifndef STATIC_INLINE_EMUL_NETBSD
110 #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
115 #define SYS(X) ASSERT(call == (SYS_##X))
120 #if WITH_NetBSD_HOST && (PATH_MAX != 1024)
121 #error "PATH_MAX not 1024"
122 #elif !defined(PATH_MAX)
123 #define PATH_MAX 1024
127 /* NetBSD's idea of what is needed to implement emulations */
129 struct _os_emul_data {
131 emul_syscall *syscalls;
136 STATIC_INLINE_EMUL_NETBSD void
137 write_stat(unsigned_word addr,
150 /* H2T(buf.st_spare1); */
152 /* H2T(buf.st_spare2); */
154 /* H2T(buf.st_spare3); */
155 #ifdef AC_STRUCT_ST_RDEV
158 #ifdef AC_STRUCT_ST_BLKSIZE
161 #ifdef AC_STRUCT_ST_BLOCKS
168 emul_write_buffer(&buf, addr, sizeof(buf), processor, cia);
173 STATIC_INLINE_EMUL_NETBSD void
174 write_statfs(unsigned_word addr,
188 H2T(buf.f_fsid.val[0]);
189 H2T(buf.f_fsid.val[1]);
192 /* f_fstypename[MFSNAMELEN]; */
193 /* f_mntonname[MNAMELEN]; */
194 /* f_mntfromname[MNAMELEN]; */
195 emul_write_buffer(&buf, addr, sizeof(buf), processor, cia);
200 STATIC_INLINE_EMUL_NETBSD void
201 write_timeval(unsigned_word addr,
208 emul_write_buffer(&t, addr, sizeof(t), processor, cia);
212 STATIC_INLINE_EMUL_NETBSD void
213 write_timezone(unsigned_word addr,
218 H2T(tz.tz_minuteswest);
220 emul_write_buffer(&tz, addr, sizeof(tz), processor, cia);
224 #ifdef HAVE_GETDIRENTRIES
225 STATIC_INLINE_EMUL_NETBSD void
226 write_direntries(unsigned_word addr,
234 struct dirent *in = (struct dirent*)buf;
235 ASSERT(in->d_reclen <= nbytes);
236 out = (struct dirent*)zalloc(in->d_reclen);
237 memcpy(out/*dest*/, in/*src*/, in->d_reclen);
242 emul_write_buffer(out, addr, in->d_reclen, processor, cia);
243 nbytes -= in->d_reclen;
244 addr += in->d_reclen;
252 #ifdef HAVE_GETRUSAGE
253 STATIC_INLINE_EMUL_NETBSD void
254 write_rusage(unsigned_word addr,
255 struct rusage rusage,
259 H2T(rusage.ru_utime.tv_sec); /* user time used */
260 H2T(rusage.ru_utime.tv_usec);
261 H2T(rusage.ru_stime.tv_sec); /* system time used */
262 H2T(rusage.ru_stime.tv_usec);
263 H2T(rusage.ru_maxrss); /* integral max resident set size */
264 H2T(rusage.ru_ixrss); /* integral shared text memory size */
265 H2T(rusage.ru_idrss); /* integral unshared data size */
266 H2T(rusage.ru_isrss); /* integral unshared stack size */
267 H2T(rusage.ru_minflt); /* page reclaims */
268 H2T(rusage.ru_majflt); /* page faults */
269 H2T(rusage.ru_nswap); /* swaps */
270 H2T(rusage.ru_inblock); /* block input operations */
271 H2T(rusage.ru_oublock); /* block output operations */
272 H2T(rusage.ru_msgsnd); /* messages sent */
273 H2T(rusage.ru_msgrcv); /* messages received */
274 H2T(rusage.ru_nsignals); /* signals received */
275 H2T(rusage.ru_nvcsw); /* voluntary context switches */
276 H2T(rusage.ru_nivcsw); /* involuntary context switches */
277 emul_write_buffer(&rusage, addr, sizeof(rusage), processor, cia);
282 do_exit(os_emul_data *emul,
288 int status = (int)cpu_registers(processor)->gpr[arg0];
290 if (WITH_TRACE && ppc_trace[trace_os_emul])
291 printf_filtered ("%d)\n", status);
293 cpu_halt(processor, cia, was_exited, status);
298 do_read(os_emul_data *emul,
304 void *scratch_buffer;
305 int d = (int)cpu_registers(processor)->gpr[arg0];
306 unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
307 int nbytes = cpu_registers(processor)->gpr[arg0+2];
311 if (WITH_TRACE && ppc_trace[trace_os_emul])
312 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
314 /* get a tempoary bufer */
315 scratch_buffer = zalloc(nbytes);
317 /* check if buffer exists by reading it */
318 emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia);
323 status = fread (scratch_buffer, 1, nbytes, stdin);
324 if (status == 0 && ferror (stdin))
328 status = read (d, scratch_buffer, nbytes);
330 emul_write_status(processor, status, errno);
332 emul_write_buffer(scratch_buffer, buf, status, processor, cia);
334 zfree(scratch_buffer);
339 do_write(os_emul_data *emul,
345 void *scratch_buffer = NULL;
347 int d = (int)cpu_registers(processor)->gpr[arg0];
348 unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
349 int nbytes = cpu_registers(processor)->gpr[arg0+2];
353 if (WITH_TRACE && ppc_trace[trace_os_emul])
354 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
356 /* get a tempoary bufer */
357 scratch_buffer = zalloc(nbytes); /* FIXME - nbytes == 0 */
360 nr_moved = vm_data_map_read_buffer(cpu_data_map(processor),
364 if (nr_moved != nbytes) {
365 /* FIXME - should handle better */
366 error("system_call()write copy failed (nr_moved=%d != nbytes=%d)\n",
371 status = write(d, scratch_buffer, nbytes);
372 emul_write_status(processor, status, errno);
373 zfree(scratch_buffer);
380 do_open(os_emul_data *emul,
386 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
387 char path_buf[PATH_MAX];
388 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
389 int flags = (int)cpu_registers(processor)->gpr[arg0+1];
390 int mode = (int)cpu_registers(processor)->gpr[arg0+2];
392 if (WITH_TRACE && ppc_trace[trace_os_emul])
393 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr, path, flags, mode);
396 emul_write_status(processor, open(path, flags, mode), errno);
401 do_close(os_emul_data *emul,
407 int d = (int)cpu_registers(processor)->gpr[arg0];
409 if (WITH_TRACE && ppc_trace[trace_os_emul])
410 printf_filtered ("%d", d);
413 emul_write_status(processor, close(d), errno);
418 do_break(os_emul_data *emul,
424 /* just pass this onto the `vm' device */
425 psim *system = cpu_system(processor);
426 unsigned_word new_break = cpu_registers(processor)->gpr[arg0];
429 if (WITH_TRACE && ppc_trace[trace_os_emul])
430 printf_filtered ("0x%lx", (long)cpu_registers(processor)->gpr[arg0]);
433 status = device_ioctl(emul->vm,
437 new_break); /*ioctl-data*/
438 emul_write_status(processor, 0, status);
446 do_getpid(os_emul_data *emul,
453 emul_write_status(processor, (int)getpid(), 0);
461 do_getuid(os_emul_data *emul,
468 emul_write_status(processor, (int)getuid(), 0);
476 do_geteuid(os_emul_data *emul,
483 emul_write_status(processor, (int)geteuid(), 0);
491 do_kill(os_emul_data *emul,
497 pid_t pid = cpu_registers(processor)->gpr[arg0];
498 int sig = cpu_registers(processor)->gpr[arg0+1];
500 if (WITH_TRACE && ppc_trace[trace_os_emul])
501 printf_filtered ("%d, %d", (int)pid, sig);
504 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
506 cpu_halt(processor, cia, was_signalled, sig);
514 do_dup(os_emul_data *emul,
520 int oldd = cpu_registers(processor)->gpr[arg0];
521 int status = dup(oldd);
524 if (WITH_TRACE && ppc_trace[trace_os_emul])
525 printf_filtered ("%d", oldd);
528 emul_write_status(processor, status, err);
536 do_getegid(os_emul_data *emul,
543 emul_write_status(processor, (int)getegid(), 0);
551 do_getgid(os_emul_data *emul,
558 emul_write_status(processor, (int)getgid(), 0);
562 #ifndef HAVE_SIGPROCMASK
563 #define do_sigprocmask 0
566 do_sigprocmask(os_emul_data *emul,
572 natural_word how = cpu_registers(processor)->gpr[arg0];
573 unsigned_word set = cpu_registers(processor)->gpr[arg0+1];
574 unsigned_word oset = cpu_registers(processor)->gpr[arg0+2];
577 if (WITH_TRACE && ppc_trace[trace_os_emul])
578 printf_filtered ("%ld, 0x%ld, 0x%ld", (long)how, (long)set, (long)oset);
580 emul_write_status(processor, 0, 0);
581 cpu_registers(processor)->gpr[4] = set;
589 do_ioctl(os_emul_data *emul,
595 int d = cpu_registers(processor)->gpr[arg0];
596 unsigned request = cpu_registers(processor)->gpr[arg0+1];
597 unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
599 #if !WITH_NetBSD_HOST
600 cpu_registers(processor)->gpr[arg0] = 0; /* just succeed */
602 unsigned dir = request & IOC_DIRMASK;
605 /* what we haven't done */
606 if (dir & IOC_IN /* write into the io device */
608 || !(dir & IOC_VOID))
609 error("do_ioctl() read or write of parameter not implemented\n");
610 status = ioctl(d, request, NULL);
611 emul_write_status(processor, status, errno);
614 if (WITH_TRACE && ppc_trace[trace_os_emul])
615 printf_filtered ("%d, 0x%x, 0x%lx", d, request, (long)argp_addr);
623 do_umask(os_emul_data *emul,
629 int mask = cpu_registers(processor)->gpr[arg0];
631 if (WITH_TRACE && ppc_trace[trace_os_emul])
632 printf_filtered ("0%o", mask);
635 emul_write_status(processor, umask(mask), 0);
643 do_dup2(os_emul_data *emul,
649 int oldd = cpu_registers(processor)->gpr[arg0];
650 int newd = cpu_registers(processor)->gpr[arg0+1];
651 int status = dup2(oldd, newd);
654 if (WITH_TRACE && ppc_trace[trace_os_emul])
655 printf_filtered ("%d, %d", oldd, newd);
658 emul_write_status(processor, status, err);
666 do_fcntl(os_emul_data *emul,
672 int fd = cpu_registers(processor)->gpr[arg0];
673 int cmd = cpu_registers(processor)->gpr[arg0+1];
674 int arg = cpu_registers(processor)->gpr[arg0+2];
677 if (WITH_TRACE && ppc_trace[trace_os_emul])
678 printf_filtered ("%d, %d, %d", fd, cmd, arg);
681 status = fcntl(fd, cmd, arg);
682 emul_write_status(processor, status, errno);
686 #ifndef HAVE_GETTIMEOFDAY
687 #define do_gettimeofday 0
690 do_gettimeofday(os_emul_data *emul,
696 unsigned_word t_addr = cpu_registers(processor)->gpr[arg0];
697 unsigned_word tz_addr = cpu_registers(processor)->gpr[arg0+1];
700 int status = gettimeofday((t_addr != 0 ? &t : NULL),
701 (tz_addr != 0 ? &tz : NULL));
704 if (WITH_TRACE && ppc_trace[trace_os_emul])
705 printf_filtered ("0x%lx, 0x%lx", (long)t_addr, (long)tz_addr);
708 emul_write_status(processor, status, err);
711 write_timeval(t_addr, t, processor, cia);
713 write_timezone(tz_addr, tz, processor, cia);
718 #ifndef HAVE_GETRUSAGE
719 #define do_getrusage 0
722 do_getrusage(os_emul_data *emul,
728 int who = cpu_registers(processor)->gpr[arg0];
729 unsigned_word rusage_addr = cpu_registers(processor)->gpr[arg0+1];
730 struct rusage rusage;
731 int status = getrusage(who, (rusage_addr != 0 ? &rusage : NULL));
734 if (WITH_TRACE && ppc_trace[trace_os_emul])
735 printf_filtered ("%d, 0x%lx", who, (long)rusage_addr);
738 emul_write_status(processor, status, err);
740 if (rusage_addr != 0)
741 write_rusage(rusage_addr, rusage, processor, cia);
751 do_fstatfs(os_emul_data *emul,
757 int fd = cpu_registers(processor)->gpr[arg0];
758 unsigned_word buf_addr = cpu_registers(processor)->gpr[arg0+1];
762 if (WITH_TRACE && ppc_trace[trace_os_emul])
763 printf_filtered ("%d, 0x%lx", fd, (long)buf_addr);
766 status = fstatfs(fd, (buf_addr == 0 ? NULL : &buf));
767 emul_write_status(processor, status, errno);
770 write_statfs(buf_addr, buf, processor, cia);
779 do_stat(os_emul_data *emul,
785 char path_buf[PATH_MAX];
786 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
787 unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
788 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
792 status = stat(path, &buf);
793 emul_write_status(processor, status, errno);
795 write_stat(stat_buf_addr, buf, processor, cia);
803 do_fstat(os_emul_data *emul,
809 int fd = cpu_registers(processor)->gpr[arg0];
810 unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
813 emul_write_status(processor, fstat(fd, &buf), errno);
814 write_stat(stat_buf_addr, buf, processor, cia);
822 do_lstat(os_emul_data *emul,
828 char path_buf[PATH_MAX];
829 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
830 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
831 unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
834 emul_write_status(processor, stat(path, &buf), errno);
835 write_stat(stat_buf_addr, buf, processor, cia);
839 #ifndef HAVE_GETDIRENTRIES
840 #define do_getdirentries 0
843 do_getdirentries(os_emul_data *emul,
849 int fd = cpu_registers(processor)->gpr[arg0];
850 unsigned_word buf_addr = cpu_registers(processor)->gpr[arg0+1];
852 int nbytes = cpu_registers(processor)->gpr[arg0+2];
853 unsigned_word basep_addr = cpu_registers(processor)->gpr[arg0+3];
857 if (buf_addr != 0 && nbytes >= 0)
858 buf = zalloc(nbytes);
861 status = getdirentries(fd,
862 (buf_addr == 0 ? NULL : buf),
864 (basep_addr == 0 ? NULL : &basep));
865 emul_write_status(processor, status, errno);
867 emul_write_word(basep_addr, basep, processor, cia);
869 write_direntries(buf_addr, buf, status, processor, cia);
877 do___syscall(os_emul_data *emul,
884 emul_do_system_call(emul,
886 cpu_registers(processor)->gpr[arg0],
896 do_lseek(os_emul_data *emul,
902 int fildes = cpu_registers(processor)->gpr[arg0];
903 off_t offset = emul_read_gpr64(processor, arg0+2);
904 int whence = cpu_registers(processor)->gpr[arg0+4];
907 status = lseek(fildes, offset, whence);
909 emul_write_status(processor, -1, errno);
911 emul_write_status(processor, 0, 0); /* success */
912 emul_write_gpr64(processor, 3, status);
918 do___sysctl(os_emul_data *emul,
924 /* call the arguments by their real name */
925 unsigned_word name = cpu_registers(processor)->gpr[arg0];
926 natural_word namelen = cpu_registers(processor)->gpr[arg0+1];
927 unsigned_word oldp = cpu_registers(processor)->gpr[arg0+2];
928 unsigned_word oldlenp = cpu_registers(processor)->gpr[arg0+3];
931 natural_word int_val;
934 /* pluck out the management information base id */
936 error("system_call()SYS___sysctl bad name[0]\n");
937 mib = vm_data_map_read_word(cpu_data_map(processor),
943 /* see what to do with it ... */
946 #if WITH_NetBSD_HOST && (CTL_HW != 6)
950 error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
951 mib = vm_data_map_read_word(cpu_data_map(processor),
957 case 7/*HW_PAGESIZE*/:
958 #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
959 # error "HW_PAGESIZE"
961 oldlen = vm_data_map_read_word(cpu_data_map(processor),
965 if (sizeof(natural_word) > oldlen)
966 error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
968 oldlen = sizeof(int_val);
969 emul_write_word(oldp, int_val, processor, cia);
970 emul_write_word(oldlenp, oldlen, processor, cia);
973 error("sysctl() CTL_HW.%d unknown\n", mib);
978 error("sysctl() name[0]=%d unknown\n", (int)mib);
981 emul_write_status(processor, 0, 0); /* always succeed */
986 static emul_syscall_descriptor netbsd_descriptors[] = {
987 /* 0 */ { 0, "syscall" },
988 /* 1 */ { do_exit, "exit" },
989 /* 2 */ { 0, "fork" },
990 /* 3 */ { do_read, "read" },
991 /* 4 */ { do_write, "write" },
992 /* 5 */ { do_open, "open" },
993 /* 6 */ { do_close, "close" },
994 /* 7 */ { 0, "wait4" },
995 { 0, }, /* 8 is old creat */
996 /* 9 */ { 0, "link" },
997 /* 10 */ { 0, "unlink" },
998 { 0, }, /* 11 is obsolete execv */
999 /* 12 */ { 0, "chdir" },
1000 /* 13 */ { 0, "fchdir" },
1001 /* 14 */ { 0, "mknod" },
1002 /* 15 */ { 0, "chmod" },
1003 /* 16 */ { 0, "chown" },
1004 /* 17 */ { do_break, "break" },
1005 /* 18 */ { 0, "getfsstat" },
1006 { 0, }, /* 19 is old lseek */
1007 /* 20 */ { do_getpid, "getpid" },
1008 /* 21 */ { 0, "mount" },
1009 /* 22 */ { 0, "unmount" },
1010 /* 23 */ { 0, "setuid" },
1011 /* 24 */ { do_getuid, "getuid" },
1012 /* 25 */ { do_geteuid, "geteuid" },
1013 /* 26 */ { 0, "ptrace" },
1014 /* 27 */ { 0, "recvmsg" },
1015 /* 28 */ { 0, "sendmsg" },
1016 /* 29 */ { 0, "recvfrom" },
1017 /* 30 */ { 0, "accept" },
1018 /* 31 */ { 0, "getpeername" },
1019 /* 32 */ { 0, "getsockname" },
1020 /* 33 */ { 0, "access" },
1021 /* 34 */ { 0, "chflags" },
1022 /* 35 */ { 0, "fchflags" },
1023 /* 36 */ { 0, "sync" },
1024 /* 37 */ { do_kill, "kill" },
1025 { 0, }, /* 38 is old stat */
1026 /* 39 */ { 0, "getppid" },
1027 { 0, }, /* 40 is old lstat */
1028 /* 41 */ { do_dup, "dup" },
1029 /* 42 */ { 0, "pipe" },
1030 /* 43 */ { do_getegid, "getegid" },
1031 /* 44 */ { 0, "profil" },
1032 /* 45 */ { 0, "ktrace" },
1033 /* 46 */ { 0, "sigaction" },
1034 /* 47 */ { do_getgid, "getgid" },
1035 /* 48 */ { do_sigprocmask, "sigprocmask" },
1036 /* 49 */ { 0, "getlogin" },
1037 /* 50 */ { 0, "setlogin" },
1038 /* 51 */ { 0, "acct" },
1039 /* 52 */ { 0, "sigpending" },
1040 /* 53 */ { 0, "sigaltstack" },
1041 /* 54 */ { do_ioctl, "ioctl" },
1042 /* 55 */ { 0, "reboot" },
1043 /* 56 */ { 0, "revoke" },
1044 /* 57 */ { 0, "symlink" },
1045 /* 58 */ { 0, "readlink" },
1046 /* 59 */ { 0, "execve" },
1047 /* 60 */ { do_umask, "umask" },
1048 /* 61 */ { 0, "chroot" },
1049 { 0, }, /* 62 is old fstat */
1050 { 0, }, /* 63 is old getkerninfo */
1051 { 0, }, /* 64 is old getpagesize */
1052 /* 65 */ { 0, "msync" },
1053 /* 66 */ { 0, "vfork" },
1054 { 0, }, /* 67 is obsolete vread */
1055 { 0, }, /* 68 is obsolete vwrite */
1056 /* 69 */ { 0, "sbrk" },
1057 /* 70 */ { 0, "sstk" },
1058 { 0, }, /* 71 is old mmap */
1059 /* 72 */ { 0, "vadvise" },
1060 /* 73 */ { 0, "munmap" },
1061 /* 74 */ { 0, "mprotect" },
1062 /* 75 */ { 0, "madvise" },
1063 { 0, }, /* 76 is obsolete vhangup */
1064 { 0, }, /* 77 is obsolete vlimit */
1065 /* 78 */ { 0, "mincore" },
1066 /* 79 */ { 0, "getgroups" },
1067 /* 80 */ { 0, "setgroups" },
1068 /* 81 */ { 0, "getpgrp" },
1069 /* 82 */ { 0, "setpgid" },
1070 /* 83 */ { 0, "setitimer" },
1071 { 0, }, /* 84 is old wait */
1072 /* 85 */ { 0, "swapon" },
1073 /* 86 */ { 0, "getitimer" },
1074 { 0, }, /* 87 is old gethostname */
1075 { 0, }, /* 88 is old sethostname */
1076 { 0, }, /* 89 is old getdtablesize */
1077 { do_dup2, "dup2" },
1079 /* 92 */ { do_fcntl, "fcntl" },
1080 /* 93 */ { 0, "select" },
1082 /* 95 */ { 0, "fsync" },
1083 /* 96 */ { 0, "setpriority" },
1084 /* 97 */ { 0, "socket" },
1085 /* 98 */ { 0, "connect" },
1086 { 0, }, /* 99 is old accept */
1087 /* 100 */ { 0, "getpriority" },
1088 { 0, }, /* 101 is old send */
1089 { 0, }, /* 102 is old recv */
1090 /* 103 */ { 0, "sigreturn" },
1091 /* 104 */ { 0, "bind" },
1092 /* 105 */ { 0, "setsockopt" },
1093 /* 106 */ { 0, "listen" },
1094 { 0, }, /* 107 is obsolete vtimes */
1095 { 0, }, /* 108 is old sigvec */
1096 { 0, }, /* 109 is old sigblock */
1097 { 0, }, /* 110 is old sigsetmask */
1098 /* 111 */ { 0, "sigsuspend" },
1099 { 0, }, /* 112 is old sigstack */
1100 { 0, }, /* 113 is old recvmsg */
1101 { 0, }, /* 114 is old sendmsg */
1102 /* - is obsolete vtrace */ { 0, "vtrace 115" },
1103 /* 116 */ { do_gettimeofday, "gettimeofday" },
1104 /* 117 */ { do_getrusage, "getrusage" },
1105 /* 118 */ { 0, "getsockopt" },
1106 /* 119 */ { 0, "resuba" },
1107 /* 120 */ { 0, "readv" },
1108 /* 121 */ { 0, "writev" },
1109 /* 122 */ { 0, "settimeofday" },
1110 /* 123 */ { 0, "fchown" },
1111 /* 124 */ { 0, "fchmod" },
1112 { 0, }, /* 125 is old recvfrom */
1113 { 0, }, /* 126 is old setreuid */
1114 { 0, }, /* 127 is old setregid */
1115 /* 128 */ { 0, "rename" },
1116 { 0, }, /* 129 is old truncate */
1117 { 0, }, /* 130 is old ftruncate */
1118 /* 131 */ { 0, "flock" },
1119 /* 132 */ { 0, "mkfifo" },
1120 /* 133 */ { 0, "sendto" },
1121 /* 134 */ { 0, "shutdown" },
1122 /* 135 */ { 0, "socketpair" },
1123 /* 136 */ { 0, "mkdir" },
1124 /* 137 */ { 0, "rmdir" },
1125 /* 138 */ { 0, "utimes" },
1126 { 0, }, /* 139 is obsolete 4.2 sigreturn */
1127 /* 140 */ { 0, "adjtime" },
1128 { 0, }, /* 141 is old getpeername */
1129 { 0, }, /* 142 is old gethostid */
1130 { 0, }, /* 143 is old sethostid */
1131 { 0, }, /* 144 is old getrlimit */
1132 { 0, }, /* 145 is old setrlimit */
1133 { 0, }, /* 146 is old killpg */
1134 /* 147 */ { 0, "setsid" },
1135 /* 148 */ { 0, "quotactl" },
1136 { 0, }, /* 149 is old quota */
1137 { 0, }, /* 150 is old getsockname */
1142 /* 155 */ { 0, "nfssvc" },
1143 { 0, }, /* 156 is old getdirentries */
1144 /* 157 */ { 0, "statfs" },
1145 /* 158 */ { do_fstatfs, "fstatfs" },
1148 /* 161 */ { 0, "getfh" },
1149 { 0, }, /* 162 is old getdomainname */
1150 { 0, }, /* 163 is old setdomainname */
1151 { 0, }, /* 164 is old uname */
1152 /* 165 */ { 0, "sysarch" },
1156 /* 169 */ { 0, "semsys" },
1157 /* 170 */ { 0, "msgsys" },
1158 /* 171 */ { 0, "shmsys" },
1168 /* 181 */ { 0, "setgid" },
1169 /* 182 */ { 0, "setegid" },
1170 /* 183 */ { 0, "seteuid" },
1171 /* 184 */ { 0, "lfs_bmapv" },
1172 /* 185 */ { 0, "lfs_markv" },
1173 /* 186 */ { 0, "lfs_segclean" },
1174 /* 187 */ { 0, "lfs_segwait" },
1175 /* 188 */ { do_stat, "stat" },
1176 /* 189 */ { do_fstat, "fstat" },
1177 /* 190 */ { do_lstat, "lstat" },
1178 /* 191 */ { 0, "pathconf" },
1179 /* 192 */ { 0, "fpathconf" },
1181 /* 194 */ { 0, "getrlimit" },
1182 /* 195 */ { 0, "setrlimit" },
1183 /* 196 */ { do_getdirentries, "getdirentries" },
1184 /* 197 */ { 0, "mmap" },
1185 /* 198 */ { do___syscall, "__syscall" },
1186 /* 199 */ { do_lseek, "lseek" },
1187 /* 200 */ { 0, "truncate" },
1188 /* 201 */ { 0, "ftruncate" },
1189 /* 202 */ { do___sysctl, "__sysctl" },
1190 /* 203 */ { 0, "mlock" },
1191 /* 204 */ { 0, "munlock" },
1194 static char *(netbsd_error_names[]) = {
1231 /* 36 */ "EINPROGRESS",
1232 /* 37 */ "EALREADY",
1233 /* 38 */ "ENOTSOCK",
1234 /* 39 */ "EDESTADDRREQ",
1235 /* 40 */ "EMSGSIZE",
1236 /* 41 */ "EPROTOTYPE",
1237 /* 42 */ "ENOPROTOOPT",
1238 /* 43 */ "EPROTONOSUPPORT",
1239 /* 44 */ "ESOCKTNOSUPPORT",
1240 /* 45 */ "EOPNOTSUPP",
1241 /* 46 */ "EPFNOSUPPORT",
1242 /* 47 */ "EAFNOSUPPORT",
1243 /* 48 */ "EADDRINUSE",
1244 /* 49 */ "EADDRNOTAVAIL",
1245 /* 50 */ "ENETDOWN",
1246 /* 51 */ "ENETUNREACH",
1247 /* 52 */ "ENETRESET",
1248 /* 53 */ "ECONNABORTED",
1249 /* 54 */ "ECONNRESET",
1252 /* 57 */ "ENOTCONN",
1253 /* 58 */ "ESHUTDOWN",
1254 /* 59 */ "ETOOMANYREFS",
1255 /* 60 */ "ETIMEDOUT",
1256 /* 61 */ "ECONNREFUSED",
1258 /* 63 */ "ENAMETOOLONG",
1259 /* 64 */ "EHOSTDOWN",
1260 /* 65 */ "EHOSTUNREACH",
1261 /* 66 */ "ENOTEMPTY",
1262 /* 67 */ "EPROCLIM",
1268 /* 73 */ "ERPCMISMATCH",
1269 /* 74 */ "EPROGUNAVAIL",
1270 /* 75 */ "EPROGMISMATCH",
1271 /* 76 */ "EPROCUNAVAIL",
1276 /* 81 */ "ENEEDAUTH",
1280 static char *(netbsd_signal_names[]) = {
1307 /* 26 */ "SIGVTALRM",
1309 /* 28 */ "SIGWINCH",
1315 static emul_syscall emul_netbsd_syscalls = {
1317 sizeof(netbsd_descriptors) / sizeof(netbsd_descriptors[0]),
1319 sizeof(netbsd_error_names) / sizeof(netbsd_error_names[0]),
1320 netbsd_signal_names,
1321 sizeof(netbsd_signal_names) / sizeof(netbsd_signal_names[0]),
1325 /* NetBSD's os_emul interface, most are just passed on to the generic
1328 static os_emul_data *
1329 emul_netbsd_create(device *root,
1333 unsigned_word top_of_stack;
1334 unsigned stack_size;
1336 os_emul_data *bsd_data;
1339 /* check that this emulation is really for us */
1340 if (name != NULL && strcmp(name, "netbsd") != 0)
1346 /* merge any emulation specific entries into the device tree */
1348 /* establish a few defaults */
1349 if (image->xvec->flavour == bfd_target_elf_flavour) {
1351 top_of_stack = 0xe0000000;
1352 stack_size = 0x00100000;
1356 top_of_stack = 0x20000000;
1357 stack_size = 0x00100000;
1361 emul_add_tree_options(root, image, "netbsd",
1362 (WITH_ENVIRONMENT == USER_ENVIRONMENT
1363 ? "user" : "virtual"),
1364 0 /*oea-interrupt-prefix*/);
1366 /* virtual memory - handles growth of stack/heap */
1367 vm = device_tree_add_parsed(root, "/openprom/vm@0x%lx",
1368 (unsigned long)(top_of_stack - stack_size));
1369 device_tree_add_parsed(vm, "./stack-base 0x%lx",
1370 (unsigned long)(top_of_stack - stack_size));
1371 device_tree_add_parsed(vm, "./nr-bytes 0x%x", stack_size);
1373 device_tree_add_parsed(root, "/openprom/vm/map-binary/file-name %s",
1374 bfd_get_filename(image));
1376 /* finish the init */
1377 device_tree_add_parsed(root, "/openprom/init/register/pc 0x%lx",
1378 (unsigned long)bfd_get_start_address(image));
1379 device_tree_add_parsed(root, "/openprom/init/register/sp 0x%lx",
1380 (unsigned long)top_of_stack);
1381 device_tree_add_parsed(root, "/openprom/init/register/msr 0x%x",
1382 (device_find_boolean_property(root, "/options/little-endian?")
1383 ? msr_little_endian_mode
1385 device_tree_add_parsed(root, "/openprom/init/stack/stack-type %s",
1386 (elf_binary ? "elf" : "xcoff"));
1388 /* finally our emulation data */
1389 bsd_data = ZALLOC(os_emul_data);
1391 bsd_data->syscalls = &emul_netbsd_syscalls;
1396 emul_netbsd_init(os_emul_data *emul_data,
1403 emul_netbsd_system_call(cpu *processor,
1405 os_emul_data *emul_data)
1407 emul_do_system_call(emul_data,
1408 emul_data->syscalls,
1409 cpu_registers(processor)->gpr[0],
1410 3, /*r3 contains arg0*/
1415 const os_emul emul_netbsd = {
1419 emul_netbsd_system_call,
1420 0, /*instruction_call*/
1424 #endif _EMUL_NETBSD_C_