1 /* This file is part of the program psim.
3 Copyright (C) 1994-1998, 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 3 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, see <http://www.gnu.org/licenses/>.
21 #ifndef _EMUL_NETBSD_C_
22 #define _EMUL_NETBSD_C_
25 /* Note: this module is called via a table. There is no benefit in
28 #include "emul_generic.h"
29 #include "emul_netbsd.h"
39 #include <sys/types.h>
45 #include <sys/param.h>
49 #ifndef HAVE_SYS_RESOURCE_H
55 #include <sys/resource.h>
60 #include <sys/ioctl.h>
65 # define NAMLEN(dirent) strlen((dirent)->d_name)
67 # define dirent direct
68 # define NAMLEN(dirent) (dirent)->d_namlen
70 # include <sys/ndir.h>
81 #undef MAXPATHLEN /* sys/param.h might define this also */
89 #define WITH_NetBSD_HOST (NetBSD >= 199306)
90 #if WITH_NetBSD_HOST /* here NetBSD as that is what we're emulating */
91 #include <sys/syscall.h> /* FIXME - should not be including this one */
92 #include <sys/sysctl.h>
93 #include <sys/mount.h>
94 extern int getdirentries(int fd, char *buf, int nbytes, long *basep);
96 /* NetBSD post 2.0 has the statfs system call (if COMPAT_20), but does
97 not have struct statfs. In this case don't implement fstatfs.
98 FIXME: Should implement fstatvfs. */
99 #ifndef HAVE_STRUCT_STATFS
105 /* If this is not netbsd, don't allow fstatfs or getdirentries at this time */
107 #undef HAVE_GETDIRENTRIES
110 #if (BSD < 199306) /* here BSD as just a bug */
114 #ifndef STATIC_INLINE_EMUL_NETBSD
115 #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
120 #define SYS(X) ASSERT(call == (SYS_##X))
125 #if WITH_NetBSD_HOST && (PATH_MAX != 1024)
126 #error "PATH_MAX not 1024"
127 #elif !defined(PATH_MAX)
128 #define PATH_MAX 1024
134 NetBSD - Emulation of user programs for NetBSD/PPC
141 /* NetBSD's idea of what is needed to implement emulations */
143 struct _os_emul_data {
145 emul_syscall *syscalls;
150 STATIC_INLINE_EMUL_NETBSD void
151 write_stat(unsigned_word addr,
164 /* H2T(buf.st_spare1); */
166 /* H2T(buf.st_spare2); */
168 /* H2T(buf.st_spare3); */
169 #ifdef AC_STRUCT_ST_RDEV
172 #ifdef AC_STRUCT_ST_BLKSIZE
175 #ifdef AC_STRUCT_ST_BLOCKS
182 emul_write_buffer(&buf, addr, sizeof(buf), processor, cia);
187 STATIC_INLINE_EMUL_NETBSD void
188 write_statfs(unsigned_word addr,
202 H2T(buf.f_fsid.val[0]);
203 H2T(buf.f_fsid.val[1]);
206 /* f_fstypename[MFSNAMELEN]; */
207 /* f_mntonname[MNAMELEN]; */
208 /* f_mntfromname[MNAMELEN]; */
209 emul_write_buffer(&buf, addr, sizeof(buf), processor, cia);
214 STATIC_INLINE_EMUL_NETBSD void
215 write_timeval(unsigned_word addr,
222 emul_write_buffer(&t, addr, sizeof(t), processor, cia);
225 #ifdef HAVE_GETTIMEOFDAY
226 STATIC_INLINE_EMUL_NETBSD void
227 write_timezone(unsigned_word addr,
232 H2T(tz.tz_minuteswest);
234 emul_write_buffer(&tz, addr, sizeof(tz), processor, cia);
238 #ifdef HAVE_GETDIRENTRIES
239 STATIC_INLINE_EMUL_NETBSD void
240 write_direntries(unsigned_word addr,
248 struct dirent *in = (struct dirent*)buf;
249 ASSERT(in->d_reclen <= nbytes);
250 out = (struct dirent*)zalloc(in->d_reclen);
251 memcpy(out/*dest*/, in/*src*/, in->d_reclen);
256 emul_write_buffer(out, addr, in->d_reclen, processor, cia);
257 nbytes -= in->d_reclen;
258 addr += in->d_reclen;
266 #ifdef HAVE_GETRUSAGE
267 STATIC_INLINE_EMUL_NETBSD void
268 write_rusage(unsigned_word addr,
269 struct rusage rusage,
273 H2T(rusage.ru_utime.tv_sec); /* user time used */
274 H2T(rusage.ru_utime.tv_usec);
275 H2T(rusage.ru_stime.tv_sec); /* system time used */
276 H2T(rusage.ru_stime.tv_usec);
277 H2T(rusage.ru_maxrss); /* integral max resident set size */
278 H2T(rusage.ru_ixrss); /* integral shared text memory size */
279 H2T(rusage.ru_idrss); /* integral unshared data size */
280 H2T(rusage.ru_isrss); /* integral unshared stack size */
281 H2T(rusage.ru_minflt); /* page reclaims */
282 H2T(rusage.ru_majflt); /* page faults */
283 H2T(rusage.ru_nswap); /* swaps */
284 H2T(rusage.ru_inblock); /* block input operations */
285 H2T(rusage.ru_oublock); /* block output operations */
286 H2T(rusage.ru_msgsnd); /* messages sent */
287 H2T(rusage.ru_msgrcv); /* messages received */
288 H2T(rusage.ru_nsignals); /* signals received */
289 H2T(rusage.ru_nvcsw); /* voluntary context switches */
290 H2T(rusage.ru_nivcsw); /* involuntary context switches */
291 emul_write_buffer(&rusage, addr, sizeof(rusage), processor, cia);
296 do_exit(os_emul_data *emul,
302 int status = (int)cpu_registers(processor)->gpr[arg0];
304 if (WITH_TRACE && ppc_trace[trace_os_emul])
305 printf_filtered ("%d)\n", status);
307 cpu_halt(processor, cia, was_exited, status);
312 do_read(os_emul_data *emul,
318 void *scratch_buffer;
319 int d = (int)cpu_registers(processor)->gpr[arg0];
320 unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
321 int nbytes = cpu_registers(processor)->gpr[arg0+2];
325 if (WITH_TRACE && ppc_trace[trace_os_emul])
326 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
328 /* get a tempoary bufer */
329 scratch_buffer = zalloc(nbytes);
331 /* check if buffer exists by reading it */
332 emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia);
337 status = fread (scratch_buffer, 1, nbytes, stdin);
338 if (status == 0 && ferror (stdin))
342 status = read (d, scratch_buffer, nbytes);
344 emul_write_status(processor, status, errno);
346 emul_write_buffer(scratch_buffer, buf, status, processor, cia);
348 free(scratch_buffer);
353 do_write(os_emul_data *emul,
359 void *scratch_buffer = NULL;
360 int d = (int)cpu_registers(processor)->gpr[arg0];
361 unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
362 int nbytes = cpu_registers(processor)->gpr[arg0+2];
366 if (WITH_TRACE && ppc_trace[trace_os_emul])
367 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
369 /* get a tempoary bufer */
370 scratch_buffer = zalloc(nbytes); /* FIXME - nbytes == 0 */
373 emul_read_buffer(scratch_buffer, buf, nbytes,
377 status = write(d, scratch_buffer, nbytes);
378 emul_write_status(processor, status, errno);
379 free(scratch_buffer);
386 do_open(os_emul_data *emul,
392 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
393 char path_buf[PATH_MAX];
394 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
395 int flags = (int)cpu_registers(processor)->gpr[arg0+1];
396 int mode = (int)cpu_registers(processor)->gpr[arg0+2];
400 if (WITH_TRACE && ppc_trace[trace_os_emul])
401 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr, path, flags, mode);
405 /* Do some translation on 'flags' to match it to the host's version. */
406 /* These flag values were taken from the NetBSD 1.4 header files. */
407 if ((flags & 3) == 0)
408 hostflags = O_RDONLY;
409 else if ((flags & 3) == 1)
410 hostflags = O_WRONLY;
413 if (flags & 0x00000008)
414 hostflags |= O_APPEND;
415 if (flags & 0x00000200)
416 hostflags |= O_CREAT;
417 if (flags & 0x00000400)
418 hostflags |= O_TRUNC;
419 if (flags & 0x00000800)
422 /* Can't combine these statements, cuz open sets errno. */
423 status = open(path, hostflags, mode);
424 emul_write_status(processor, status, errno);
429 do_close(os_emul_data *emul,
435 int d = (int)cpu_registers(processor)->gpr[arg0];
438 if (WITH_TRACE && ppc_trace[trace_os_emul])
439 printf_filtered ("%d", d);
443 /* Can't combine these statements, cuz close sets errno. */
445 emul_write_status(processor, status, errno);
450 do_break(os_emul_data *emul,
456 /* just pass this onto the `vm' device */
457 unsigned_word new_break = cpu_registers(processor)->gpr[arg0];
460 if (WITH_TRACE && ppc_trace[trace_os_emul])
461 printf_filtered ("0x%lx", (long)cpu_registers(processor)->gpr[arg0]);
464 status = device_ioctl(emul->vm,
468 new_break); /*ioctl-data*/
469 emul_write_status(processor, 0, status);
477 do_getpid(os_emul_data *emul,
484 emul_write_status(processor, (int)getpid(), 0);
492 do_getuid(os_emul_data *emul,
499 emul_write_status(processor, (int)getuid(), 0);
507 do_geteuid(os_emul_data *emul,
514 emul_write_status(processor, (int)geteuid(), 0);
522 do_kill(os_emul_data *emul,
528 pid_t pid = cpu_registers(processor)->gpr[arg0];
529 int sig = cpu_registers(processor)->gpr[arg0+1];
531 if (WITH_TRACE && ppc_trace[trace_os_emul])
532 printf_filtered ("%d, %d", (int)pid, sig);
535 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
537 cpu_halt(processor, cia, was_signalled, sig);
545 do_dup(os_emul_data *emul,
551 int oldd = cpu_registers(processor)->gpr[arg0];
552 int status = dup(oldd);
555 if (WITH_TRACE && ppc_trace[trace_os_emul])
556 printf_filtered ("%d", oldd);
559 emul_write_status(processor, status, err);
567 do_getegid(os_emul_data *emul,
574 emul_write_status(processor, (int)getegid(), 0);
582 do_getgid(os_emul_data *emul,
589 emul_write_status(processor, (int)getgid(), 0);
593 #ifndef HAVE_SIGPROCMASK
594 #define do_sigprocmask 0
597 do_sigprocmask(os_emul_data *emul,
603 natural_word how = cpu_registers(processor)->gpr[arg0];
604 unsigned_word set = cpu_registers(processor)->gpr[arg0+1];
605 unsigned_word oset = cpu_registers(processor)->gpr[arg0+2];
606 #ifdef SYS_sigprocmask
610 if (WITH_TRACE && ppc_trace[trace_os_emul])
611 printf_filtered ("%ld, 0x%ld, 0x%ld", (long)how, (long)set, (long)oset);
613 emul_write_status(processor, 0, 0);
614 cpu_registers(processor)->gpr[4] = set;
622 do_ioctl(os_emul_data *emul,
628 int d = cpu_registers(processor)->gpr[arg0];
629 unsigned request = cpu_registers(processor)->gpr[arg0+1];
630 unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
632 #if !WITH_NetBSD_HOST
633 cpu_registers(processor)->gpr[arg0] = 0; /* just succeed */
635 unsigned dir = request & IOC_DIRMASK;
638 /* what we haven't done */
639 if (dir & IOC_IN /* write into the io device */
641 || !(dir & IOC_VOID))
642 error("do_ioctl() read or write of parameter not implemented\n");
643 status = ioctl(d, request, NULL);
644 emul_write_status(processor, status, errno);
647 if (WITH_TRACE && ppc_trace[trace_os_emul])
648 printf_filtered ("%d, 0x%x, 0x%lx", d, request, (long)argp_addr);
656 do_umask(os_emul_data *emul,
662 int mask = cpu_registers(processor)->gpr[arg0];
664 if (WITH_TRACE && ppc_trace[trace_os_emul])
665 printf_filtered ("0%o", mask);
668 emul_write_status(processor, umask(mask), 0);
676 do_dup2(os_emul_data *emul,
682 int oldd = cpu_registers(processor)->gpr[arg0];
683 int newd = cpu_registers(processor)->gpr[arg0+1];
684 int status = dup2(oldd, newd);
687 if (WITH_TRACE && ppc_trace[trace_os_emul])
688 printf_filtered ("%d, %d", oldd, newd);
691 emul_write_status(processor, status, err);
699 do_fcntl(os_emul_data *emul,
705 int fd = cpu_registers(processor)->gpr[arg0];
706 int cmd = cpu_registers(processor)->gpr[arg0+1];
707 int arg = cpu_registers(processor)->gpr[arg0+2];
710 if (WITH_TRACE && ppc_trace[trace_os_emul])
711 printf_filtered ("%d, %d, %d", fd, cmd, arg);
714 status = fcntl(fd, cmd, arg);
715 emul_write_status(processor, status, errno);
719 #ifndef HAVE_GETTIMEOFDAY
720 #define do_gettimeofday 0
723 do_gettimeofday(os_emul_data *emul,
729 unsigned_word t_addr = cpu_registers(processor)->gpr[arg0];
730 unsigned_word tz_addr = cpu_registers(processor)->gpr[arg0+1];
733 int status = gettimeofday((t_addr != 0 ? &t : NULL),
734 (tz_addr != 0 ? &tz : NULL));
737 if (WITH_TRACE && ppc_trace[trace_os_emul])
738 printf_filtered ("0x%lx, 0x%lx", (long)t_addr, (long)tz_addr);
741 emul_write_status(processor, status, err);
744 write_timeval(t_addr, t, processor, cia);
746 write_timezone(tz_addr, tz, processor, cia);
751 #ifndef HAVE_GETRUSAGE
752 #define do_getrusage 0
755 do_getrusage(os_emul_data *emul,
761 int who = cpu_registers(processor)->gpr[arg0];
762 unsigned_word rusage_addr = cpu_registers(processor)->gpr[arg0+1];
763 struct rusage rusage;
764 int status = getrusage(who, (rusage_addr != 0 ? &rusage : NULL));
767 if (WITH_TRACE && ppc_trace[trace_os_emul])
768 printf_filtered ("%d, 0x%lx", who, (long)rusage_addr);
771 emul_write_status(processor, status, err);
773 if (rusage_addr != 0)
774 write_rusage(rusage_addr, rusage, processor, cia);
784 do_fstatfs(os_emul_data *emul,
790 int fd = cpu_registers(processor)->gpr[arg0];
791 unsigned_word buf_addr = cpu_registers(processor)->gpr[arg0+1];
795 if (WITH_TRACE && ppc_trace[trace_os_emul])
796 printf_filtered ("%d, 0x%lx", fd, (long)buf_addr);
799 status = fstatfs(fd, (buf_addr == 0 ? NULL : &buf));
800 emul_write_status(processor, status, errno);
803 write_statfs(buf_addr, buf, processor, cia);
812 do_stat(os_emul_data *emul,
818 char path_buf[PATH_MAX];
819 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
820 unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
821 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
827 status = stat(path, &buf);
828 emul_write_status(processor, status, errno);
830 write_stat(stat_buf_addr, buf, processor, cia);
838 do_fstat(os_emul_data *emul,
844 int fd = cpu_registers(processor)->gpr[arg0];
845 unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
851 /* Can't combine these statements, cuz fstat sets errno. */
852 status = fstat(fd, &buf);
853 emul_write_status(processor, status, errno);
854 write_stat(stat_buf_addr, buf, processor, cia);
862 do_lstat(os_emul_data *emul,
868 char path_buf[PATH_MAX];
869 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
870 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
871 unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
877 /* Can't combine these statements, cuz lstat sets errno. */
878 status = lstat(path, &buf);
879 emul_write_status(processor, status, errno);
880 write_stat(stat_buf_addr, buf, processor, cia);
884 #ifndef HAVE_GETDIRENTRIES
885 #define do_getdirentries 0
888 do_getdirentries(os_emul_data *emul,
894 int fd = cpu_registers(processor)->gpr[arg0];
895 unsigned_word buf_addr = cpu_registers(processor)->gpr[arg0+1];
897 int nbytes = cpu_registers(processor)->gpr[arg0+2];
898 unsigned_word basep_addr = cpu_registers(processor)->gpr[arg0+3];
901 #ifdef SYS_getdirentries
904 if (buf_addr != 0 && nbytes >= 0)
905 buf = zalloc(nbytes);
908 status = getdirentries(fd,
909 (buf_addr == 0 ? NULL : buf),
911 (basep_addr == 0 ? NULL : &basep));
912 emul_write_status(processor, status, errno);
914 emul_write_word(basep_addr, basep, processor, cia);
916 write_direntries(buf_addr, buf, status, processor, cia);
924 do___syscall(os_emul_data *emul,
931 emul_do_system_call(emul,
933 cpu_registers(processor)->gpr[arg0],
943 do_lseek(os_emul_data *emul,
949 int fildes = cpu_registers(processor)->gpr[arg0];
950 off_t offset = emul_read_gpr64(processor, arg0+2);
951 int whence = cpu_registers(processor)->gpr[arg0+4];
954 status = lseek(fildes, offset, whence);
956 emul_write_status(processor, -1, errno);
958 emul_write_status(processor, 0, 0); /* success */
959 emul_write_gpr64(processor, 3, status);
965 do___sysctl(os_emul_data *emul,
971 /* call the arguments by their real name */
972 unsigned_word name = cpu_registers(processor)->gpr[arg0];
973 natural_word namelen = cpu_registers(processor)->gpr[arg0+1];
974 unsigned_word oldp = cpu_registers(processor)->gpr[arg0+2];
975 unsigned_word oldlenp = cpu_registers(processor)->gpr[arg0+3];
978 natural_word int_val;
981 /* pluck out the management information base id */
983 error("system_call()SYS___sysctl bad name[0]\n");
984 mib = vm_data_map_read_word(cpu_data_map(processor),
990 /* see what to do with it ... */
993 #if WITH_NetBSD_HOST && (CTL_HW != 6)
997 error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
998 mib = vm_data_map_read_word(cpu_data_map(processor),
1002 name += sizeof(mib);
1004 case 7/*HW_PAGESIZE*/:
1005 #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
1006 # error "HW_PAGESIZE"
1008 oldlen = vm_data_map_read_word(cpu_data_map(processor),
1012 if (sizeof(natural_word) > oldlen)
1013 error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
1015 oldlen = sizeof(int_val);
1016 emul_write_word(oldp, int_val, processor, cia);
1017 emul_write_word(oldlenp, oldlen, processor, cia);
1020 error("sysctl() CTL_HW.%d unknown\n", mib);
1025 error("sysctl() name[0]=%d unknown\n", (int)mib);
1028 emul_write_status(processor, 0, 0); /* always succeed */
1033 static emul_syscall_descriptor netbsd_descriptors[] = {
1034 /* 0 */ { 0, "syscall" },
1035 /* 1 */ { do_exit, "exit" },
1036 /* 2 */ { 0, "fork" },
1037 /* 3 */ { do_read, "read" },
1038 /* 4 */ { do_write, "write" },
1039 /* 5 */ { do_open, "open" },
1040 /* 6 */ { do_close, "close" },
1041 /* 7 */ { 0, "wait4" },
1042 { 0, }, /* 8 is old creat */
1043 /* 9 */ { 0, "link" },
1044 /* 10 */ { 0, "unlink" },
1045 { 0, }, /* 11 is obsolete execv */
1046 /* 12 */ { 0, "chdir" },
1047 /* 13 */ { 0, "fchdir" },
1048 /* 14 */ { 0, "mknod" },
1049 /* 15 */ { 0, "chmod" },
1050 /* 16 */ { 0, "chown" },
1051 /* 17 */ { do_break, "break" },
1052 /* 18 */ { 0, "getfsstat" },
1053 { 0, }, /* 19 is old lseek */
1054 /* 20 */ { do_getpid, "getpid" },
1055 /* 21 */ { 0, "mount" },
1056 /* 22 */ { 0, "unmount" },
1057 /* 23 */ { 0, "setuid" },
1058 /* 24 */ { do_getuid, "getuid" },
1059 /* 25 */ { do_geteuid, "geteuid" },
1060 /* 26 */ { 0, "ptrace" },
1061 /* 27 */ { 0, "recvmsg" },
1062 /* 28 */ { 0, "sendmsg" },
1063 /* 29 */ { 0, "recvfrom" },
1064 /* 30 */ { 0, "accept" },
1065 /* 31 */ { 0, "getpeername" },
1066 /* 32 */ { 0, "getsockname" },
1067 /* 33 */ { 0, "access" },
1068 /* 34 */ { 0, "chflags" },
1069 /* 35 */ { 0, "fchflags" },
1070 /* 36 */ { 0, "sync" },
1071 /* 37 */ { do_kill, "kill" },
1072 { 0, }, /* 38 is old stat */
1073 /* 39 */ { 0, "getppid" },
1074 { 0, }, /* 40 is old lstat */
1075 /* 41 */ { do_dup, "dup" },
1076 /* 42 */ { 0, "pipe" },
1077 /* 43 */ { do_getegid, "getegid" },
1078 /* 44 */ { 0, "profil" },
1079 /* 45 */ { 0, "ktrace" },
1080 /* 46 */ { 0, "sigaction" },
1081 /* 47 */ { do_getgid, "getgid" },
1082 /* 48 */ { do_sigprocmask, "sigprocmask" },
1083 /* 49 */ { 0, "getlogin" },
1084 /* 50 */ { 0, "setlogin" },
1085 /* 51 */ { 0, "acct" },
1086 /* 52 */ { 0, "sigpending" },
1087 /* 53 */ { 0, "sigaltstack" },
1088 /* 54 */ { do_ioctl, "ioctl" },
1089 /* 55 */ { 0, "reboot" },
1090 /* 56 */ { 0, "revoke" },
1091 /* 57 */ { 0, "symlink" },
1092 /* 58 */ { 0, "readlink" },
1093 /* 59 */ { 0, "execve" },
1094 /* 60 */ { do_umask, "umask" },
1095 /* 61 */ { 0, "chroot" },
1096 { 0, }, /* 62 is old fstat */
1097 { 0, }, /* 63 is old getkerninfo */
1098 { 0, }, /* 64 is old getpagesize */
1099 /* 65 */ { 0, "msync" },
1100 /* 66 */ { 0, "vfork" },
1101 { 0, }, /* 67 is obsolete vread */
1102 { 0, }, /* 68 is obsolete vwrite */
1103 /* 69 */ { 0, "sbrk" },
1104 /* 70 */ { 0, "sstk" },
1105 { 0, }, /* 71 is old mmap */
1106 /* 72 */ { 0, "vadvise" },
1107 /* 73 */ { 0, "munmap" },
1108 /* 74 */ { 0, "mprotect" },
1109 /* 75 */ { 0, "madvise" },
1110 { 0, }, /* 76 is obsolete vhangup */
1111 { 0, }, /* 77 is obsolete vlimit */
1112 /* 78 */ { 0, "mincore" },
1113 /* 79 */ { 0, "getgroups" },
1114 /* 80 */ { 0, "setgroups" },
1115 /* 81 */ { 0, "getpgrp" },
1116 /* 82 */ { 0, "setpgid" },
1117 /* 83 */ { 0, "setitimer" },
1118 { 0, }, /* 84 is old wait */
1119 /* 85 */ { 0, "swapon" },
1120 /* 86 */ { 0, "getitimer" },
1121 { 0, }, /* 87 is old gethostname */
1122 { 0, }, /* 88 is old sethostname */
1123 { 0, }, /* 89 is old getdtablesize */
1124 { do_dup2, "dup2" },
1126 /* 92 */ { do_fcntl, "fcntl" },
1127 /* 93 */ { 0, "select" },
1129 /* 95 */ { 0, "fsync" },
1130 /* 96 */ { 0, "setpriority" },
1131 /* 97 */ { 0, "socket" },
1132 /* 98 */ { 0, "connect" },
1133 { 0, }, /* 99 is old accept */
1134 /* 100 */ { 0, "getpriority" },
1135 { 0, }, /* 101 is old send */
1136 { 0, }, /* 102 is old recv */
1137 /* 103 */ { 0, "sigreturn" },
1138 /* 104 */ { 0, "bind" },
1139 /* 105 */ { 0, "setsockopt" },
1140 /* 106 */ { 0, "listen" },
1141 { 0, }, /* 107 is obsolete vtimes */
1142 { 0, }, /* 108 is old sigvec */
1143 { 0, }, /* 109 is old sigblock */
1144 { 0, }, /* 110 is old sigsetmask */
1145 /* 111 */ { 0, "sigsuspend" },
1146 { 0, }, /* 112 is old sigstack */
1147 { 0, }, /* 113 is old recvmsg */
1148 { 0, }, /* 114 is old sendmsg */
1149 /* - is obsolete vtrace */ { 0, "vtrace 115" },
1150 /* 116 */ { do_gettimeofday, "gettimeofday" },
1151 /* 117 */ { do_getrusage, "getrusage" },
1152 /* 118 */ { 0, "getsockopt" },
1153 /* 119 */ { 0, "resuba" },
1154 /* 120 */ { 0, "readv" },
1155 /* 121 */ { 0, "writev" },
1156 /* 122 */ { 0, "settimeofday" },
1157 /* 123 */ { 0, "fchown" },
1158 /* 124 */ { 0, "fchmod" },
1159 { 0, }, /* 125 is old recvfrom */
1160 { 0, }, /* 126 is old setreuid */
1161 { 0, }, /* 127 is old setregid */
1162 /* 128 */ { 0, "rename" },
1163 { 0, }, /* 129 is old truncate */
1164 { 0, }, /* 130 is old ftruncate */
1165 /* 131 */ { 0, "flock" },
1166 /* 132 */ { 0, "mkfifo" },
1167 /* 133 */ { 0, "sendto" },
1168 /* 134 */ { 0, "shutdown" },
1169 /* 135 */ { 0, "socketpair" },
1170 /* 136 */ { 0, "mkdir" },
1171 /* 137 */ { 0, "rmdir" },
1172 /* 138 */ { 0, "utimes" },
1173 { 0, }, /* 139 is obsolete 4.2 sigreturn */
1174 /* 140 */ { 0, "adjtime" },
1175 { 0, }, /* 141 is old getpeername */
1176 { 0, }, /* 142 is old gethostid */
1177 { 0, }, /* 143 is old sethostid */
1178 { 0, }, /* 144 is old getrlimit */
1179 { 0, }, /* 145 is old setrlimit */
1180 { 0, }, /* 146 is old killpg */
1181 /* 147 */ { 0, "setsid" },
1182 /* 148 */ { 0, "quotactl" },
1183 { 0, }, /* 149 is old quota */
1184 { 0, }, /* 150 is old getsockname */
1189 /* 155 */ { 0, "nfssvc" },
1190 { 0, }, /* 156 is old getdirentries */
1191 /* 157 */ { 0, "statfs" },
1192 /* 158 */ { do_fstatfs, "fstatfs" },
1195 /* 161 */ { 0, "getfh" },
1196 { 0, }, /* 162 is old getdomainname */
1197 { 0, }, /* 163 is old setdomainname */
1198 { 0, }, /* 164 is old uname */
1199 /* 165 */ { 0, "sysarch" },
1203 /* 169 */ { 0, "semsys" },
1204 /* 170 */ { 0, "msgsys" },
1205 /* 171 */ { 0, "shmsys" },
1215 /* 181 */ { 0, "setgid" },
1216 /* 182 */ { 0, "setegid" },
1217 /* 183 */ { 0, "seteuid" },
1218 /* 184 */ { 0, "lfs_bmapv" },
1219 /* 185 */ { 0, "lfs_markv" },
1220 /* 186 */ { 0, "lfs_segclean" },
1221 /* 187 */ { 0, "lfs_segwait" },
1222 /* 188 */ { do_stat, "stat" },
1223 /* 189 */ { do_fstat, "fstat" },
1224 /* 190 */ { do_lstat, "lstat" },
1225 /* 191 */ { 0, "pathconf" },
1226 /* 192 */ { 0, "fpathconf" },
1228 /* 194 */ { 0, "getrlimit" },
1229 /* 195 */ { 0, "setrlimit" },
1230 /* 196 */ { do_getdirentries, "getdirentries" },
1231 /* 197 */ { 0, "mmap" },
1232 /* 198 */ { do___syscall, "__syscall" },
1233 /* 199 */ { do_lseek, "lseek" },
1234 /* 200 */ { 0, "truncate" },
1235 /* 201 */ { 0, "ftruncate" },
1236 /* 202 */ { do___sysctl, "__sysctl" },
1237 /* 203 */ { 0, "mlock" },
1238 /* 204 */ { 0, "munlock" },
1241 static char *(netbsd_error_names[]) = {
1278 /* 36 */ "EINPROGRESS",
1279 /* 37 */ "EALREADY",
1280 /* 38 */ "ENOTSOCK",
1281 /* 39 */ "EDESTADDRREQ",
1282 /* 40 */ "EMSGSIZE",
1283 /* 41 */ "EPROTOTYPE",
1284 /* 42 */ "ENOPROTOOPT",
1285 /* 43 */ "EPROTONOSUPPORT",
1286 /* 44 */ "ESOCKTNOSUPPORT",
1287 /* 45 */ "EOPNOTSUPP",
1288 /* 46 */ "EPFNOSUPPORT",
1289 /* 47 */ "EAFNOSUPPORT",
1290 /* 48 */ "EADDRINUSE",
1291 /* 49 */ "EADDRNOTAVAIL",
1292 /* 50 */ "ENETDOWN",
1293 /* 51 */ "ENETUNREACH",
1294 /* 52 */ "ENETRESET",
1295 /* 53 */ "ECONNABORTED",
1296 /* 54 */ "ECONNRESET",
1299 /* 57 */ "ENOTCONN",
1300 /* 58 */ "ESHUTDOWN",
1301 /* 59 */ "ETOOMANYREFS",
1302 /* 60 */ "ETIMEDOUT",
1303 /* 61 */ "ECONNREFUSED",
1305 /* 63 */ "ENAMETOOLONG",
1306 /* 64 */ "EHOSTDOWN",
1307 /* 65 */ "EHOSTUNREACH",
1308 /* 66 */ "ENOTEMPTY",
1309 /* 67 */ "EPROCLIM",
1315 /* 73 */ "ERPCMISMATCH",
1316 /* 74 */ "EPROGUNAVAIL",
1317 /* 75 */ "EPROGMISMATCH",
1318 /* 76 */ "EPROCUNAVAIL",
1323 /* 81 */ "ENEEDAUTH",
1327 static char *(netbsd_signal_names[]) = {
1354 /* 26 */ "SIGVTALRM",
1356 /* 28 */ "SIGWINCH",
1362 static emul_syscall emul_netbsd_syscalls = {
1364 sizeof(netbsd_descriptors) / sizeof(netbsd_descriptors[0]),
1366 sizeof(netbsd_error_names) / sizeof(netbsd_error_names[0]),
1367 netbsd_signal_names,
1368 sizeof(netbsd_signal_names) / sizeof(netbsd_signal_names[0]),
1372 /* NetBSD's os_emul interface, most are just passed on to the generic
1375 static os_emul_data *
1376 emul_netbsd_create(device *root,
1380 unsigned_word top_of_stack;
1381 unsigned stack_size;
1383 os_emul_data *bsd_data;
1387 /* check that this emulation is really for us */
1388 if (name != NULL && strcmp(name, "netbsd") != 0)
1394 /* merge any emulation specific entries into the device tree */
1396 /* establish a few defaults */
1397 if (image->xvec->flavour == bfd_target_elf_flavour) {
1399 top_of_stack = 0xe0000000;
1400 stack_size = 0x00100000;
1404 top_of_stack = 0x20000000;
1405 stack_size = 0x00100000;
1409 emul_add_tree_options(root, image, "netbsd",
1410 (WITH_ENVIRONMENT == USER_ENVIRONMENT
1411 ? "user" : "virtual"),
1412 0 /*oea-interrupt-prefix*/);
1414 /* virtual memory - handles growth of stack/heap */
1415 vm = tree_parse(root, "/openprom/vm");
1416 tree_parse(vm, "./stack-base 0x%lx",
1417 (unsigned long)(top_of_stack - stack_size));
1418 tree_parse(vm, "./nr-bytes 0x%x", stack_size);
1420 filename = tree_quote_property (bfd_get_filename(image));
1421 tree_parse(root, "/openprom/vm/map-binary/file-name %s",
1425 /* finish the init */
1426 tree_parse(root, "/openprom/init/register/pc 0x%lx",
1427 (unsigned long)bfd_get_start_address(image));
1428 tree_parse(root, "/openprom/init/register/sp 0x%lx",
1429 (unsigned long)top_of_stack);
1430 tree_parse(root, "/openprom/init/register/msr 0x%x",
1431 ((tree_find_boolean_property(root, "/options/little-endian?")
1432 ? msr_little_endian_mode
1434 | (tree_find_boolean_property(root, "/openprom/options/floating-point?")
1435 ? (msr_floating_point_available
1436 | msr_floating_point_exception_mode_0
1437 | msr_floating_point_exception_mode_1)
1439 tree_parse(root, "/openprom/init/stack/stack-type %s",
1440 (elf_binary ? "ppc-elf" : "ppc-xcoff"));
1442 /* finally our emulation data */
1443 bsd_data = ZALLOC(os_emul_data);
1445 bsd_data->syscalls = &emul_netbsd_syscalls;
1450 emul_netbsd_init(os_emul_data *emul_data,
1457 emul_netbsd_system_call(cpu *processor,
1459 os_emul_data *emul_data)
1461 emul_do_system_call(emul_data,
1462 emul_data->syscalls,
1463 cpu_registers(processor)->gpr[0],
1464 3, /*r3 contains arg0*/
1469 const os_emul emul_netbsd = {
1473 emul_netbsd_system_call,
1474 0, /*instruction_call*/
1478 #endif /* _EMUL_NETBSD_C_ */