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 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>
46 #include <sys/param.h>
50 #ifndef HAVE_SYS_RESOURCE_H
56 #include <sys/resource.h>
61 #include <sys/ioctl.h>
66 # define NAMLEN(dirent) strlen((dirent)->d_name)
68 # define dirent direct
69 # define NAMLEN(dirent) (dirent)->d_namlen
71 # include <sys/ndir.h>
82 #undef MAXPATHLEN /* sys/param.h might define this also */
90 #define WITH_NetBSD_HOST (NetBSD >= 199306)
91 #if WITH_NetBSD_HOST /* here NetBSD as that is what we're emulating */
92 #include <sys/syscall.h> /* FIXME - should not be including this one */
93 #include <sys/sysctl.h>
94 #include <sys/mount.h>
95 extern int getdirentries(int fd, char *buf, int nbytes, long *basep);
97 /* NetBSD post 2.0 has the statfs system call (if COMPAT_20), but does
98 not have struct statfs. In this case don't implement fstatfs.
99 FIXME: Should implement fstatvfs. */
100 #ifndef HAVE_STRUCT_STATFS
106 /* If this is not netbsd, don't allow fstatfs or getdirentries at this time */
108 #undef HAVE_GETDIRENTRIES
111 #if (BSD < 199306) /* here BSD as just a bug */
115 #ifndef STATIC_INLINE_EMUL_NETBSD
116 #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
121 #define SYS(X) ASSERT(call == (SYS_##X))
126 #if WITH_NetBSD_HOST && (PATH_MAX != 1024)
127 #error "PATH_MAX not 1024"
128 #elif !defined(PATH_MAX)
129 #define PATH_MAX 1024
135 NetBSD - Emulation of user programs for NetBSD/PPC
142 /* NetBSD's idea of what is needed to implement emulations */
144 struct _os_emul_data {
146 emul_syscall *syscalls;
151 STATIC_INLINE_EMUL_NETBSD void
152 write_stat(unsigned_word addr,
165 /* H2T(buf.st_spare1); */
167 /* H2T(buf.st_spare2); */
169 /* H2T(buf.st_spare3); */
170 #ifdef AC_STRUCT_ST_RDEV
173 #ifdef AC_STRUCT_ST_BLKSIZE
176 #ifdef AC_STRUCT_ST_BLOCKS
183 emul_write_buffer(&buf, addr, sizeof(buf), processor, cia);
188 STATIC_INLINE_EMUL_NETBSD void
189 write_statfs(unsigned_word addr,
203 H2T(buf.f_fsid.val[0]);
204 H2T(buf.f_fsid.val[1]);
207 /* f_fstypename[MFSNAMELEN]; */
208 /* f_mntonname[MNAMELEN]; */
209 /* f_mntfromname[MNAMELEN]; */
210 emul_write_buffer(&buf, addr, sizeof(buf), processor, cia);
215 STATIC_INLINE_EMUL_NETBSD void
216 write_timeval(unsigned_word addr,
223 emul_write_buffer(&t, addr, sizeof(t), processor, cia);
226 #ifdef HAVE_GETTIMEOFDAY
227 STATIC_INLINE_EMUL_NETBSD void
228 write_timezone(unsigned_word addr,
233 H2T(tz.tz_minuteswest);
235 emul_write_buffer(&tz, addr, sizeof(tz), processor, cia);
239 #ifdef HAVE_GETDIRENTRIES
240 STATIC_INLINE_EMUL_NETBSD void
241 write_direntries(unsigned_word addr,
249 struct dirent *in = (struct dirent*)buf;
250 ASSERT(in->d_reclen <= nbytes);
251 out = (struct dirent*)zalloc(in->d_reclen);
252 memcpy(out/*dest*/, in/*src*/, in->d_reclen);
257 emul_write_buffer(out, addr, in->d_reclen, processor, cia);
258 nbytes -= in->d_reclen;
259 addr += in->d_reclen;
267 #ifdef HAVE_GETRUSAGE
268 STATIC_INLINE_EMUL_NETBSD void
269 write_rusage(unsigned_word addr,
270 struct rusage rusage,
274 H2T(rusage.ru_utime.tv_sec); /* user time used */
275 H2T(rusage.ru_utime.tv_usec);
276 H2T(rusage.ru_stime.tv_sec); /* system time used */
277 H2T(rusage.ru_stime.tv_usec);
278 H2T(rusage.ru_maxrss); /* integral max resident set size */
279 H2T(rusage.ru_ixrss); /* integral shared text memory size */
280 H2T(rusage.ru_idrss); /* integral unshared data size */
281 H2T(rusage.ru_isrss); /* integral unshared stack size */
282 H2T(rusage.ru_minflt); /* page reclaims */
283 H2T(rusage.ru_majflt); /* page faults */
284 H2T(rusage.ru_nswap); /* swaps */
285 H2T(rusage.ru_inblock); /* block input operations */
286 H2T(rusage.ru_oublock); /* block output operations */
287 H2T(rusage.ru_msgsnd); /* messages sent */
288 H2T(rusage.ru_msgrcv); /* messages received */
289 H2T(rusage.ru_nsignals); /* signals received */
290 H2T(rusage.ru_nvcsw); /* voluntary context switches */
291 H2T(rusage.ru_nivcsw); /* involuntary context switches */
292 emul_write_buffer(&rusage, addr, sizeof(rusage), processor, cia);
297 do_exit(os_emul_data *emul,
303 int status = (int)cpu_registers(processor)->gpr[arg0];
305 if (WITH_TRACE && ppc_trace[trace_os_emul])
306 printf_filtered ("%d)\n", status);
308 cpu_halt(processor, cia, was_exited, status);
313 do_read(os_emul_data *emul,
319 void *scratch_buffer;
320 int d = (int)cpu_registers(processor)->gpr[arg0];
321 unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
322 int nbytes = cpu_registers(processor)->gpr[arg0+2];
326 if (WITH_TRACE && ppc_trace[trace_os_emul])
327 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
329 /* get a tempoary bufer */
330 scratch_buffer = zalloc(nbytes);
332 /* check if buffer exists by reading it */
333 emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia);
338 status = fread (scratch_buffer, 1, nbytes, stdin);
339 if (status == 0 && ferror (stdin))
343 status = read (d, scratch_buffer, nbytes);
345 emul_write_status(processor, status, errno);
347 emul_write_buffer(scratch_buffer, buf, status, processor, cia);
349 zfree(scratch_buffer);
354 do_write(os_emul_data *emul,
360 void *scratch_buffer = NULL;
361 int d = (int)cpu_registers(processor)->gpr[arg0];
362 unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
363 int nbytes = cpu_registers(processor)->gpr[arg0+2];
367 if (WITH_TRACE && ppc_trace[trace_os_emul])
368 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
370 /* get a tempoary bufer */
371 scratch_buffer = zalloc(nbytes); /* FIXME - nbytes == 0 */
374 emul_read_buffer(scratch_buffer, buf, nbytes,
378 status = write(d, scratch_buffer, nbytes);
379 emul_write_status(processor, status, errno);
380 zfree(scratch_buffer);
387 do_open(os_emul_data *emul,
393 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
394 char path_buf[PATH_MAX];
395 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
396 int flags = (int)cpu_registers(processor)->gpr[arg0+1];
397 int mode = (int)cpu_registers(processor)->gpr[arg0+2];
401 if (WITH_TRACE && ppc_trace[trace_os_emul])
402 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr, path, flags, mode);
406 /* Do some translation on 'flags' to match it to the host's version. */
407 /* These flag values were taken from the NetBSD 1.4 header files. */
408 if ((flags & 3) == 0)
409 hostflags = O_RDONLY;
410 else if ((flags & 3) == 1)
411 hostflags = O_WRONLY;
414 if (flags & 0x00000008)
415 hostflags |= O_APPEND;
416 if (flags & 0x00000200)
417 hostflags |= O_CREAT;
418 if (flags & 0x00000400)
419 hostflags |= O_TRUNC;
420 if (flags & 0x00000800)
423 /* Can't combine these statements, cuz open sets errno. */
424 status = open(path, hostflags, mode);
425 emul_write_status(processor, status, errno);
430 do_close(os_emul_data *emul,
436 int d = (int)cpu_registers(processor)->gpr[arg0];
439 if (WITH_TRACE && ppc_trace[trace_os_emul])
440 printf_filtered ("%d", d);
444 /* Can't combine these statements, cuz close sets errno. */
446 emul_write_status(processor, status, errno);
451 do_break(os_emul_data *emul,
457 /* just pass this onto the `vm' device */
458 unsigned_word new_break = cpu_registers(processor)->gpr[arg0];
461 if (WITH_TRACE && ppc_trace[trace_os_emul])
462 printf_filtered ("0x%lx", (long)cpu_registers(processor)->gpr[arg0]);
465 status = device_ioctl(emul->vm,
469 new_break); /*ioctl-data*/
470 emul_write_status(processor, 0, status);
478 do_getpid(os_emul_data *emul,
485 emul_write_status(processor, (int)getpid(), 0);
493 do_getuid(os_emul_data *emul,
500 emul_write_status(processor, (int)getuid(), 0);
508 do_geteuid(os_emul_data *emul,
515 emul_write_status(processor, (int)geteuid(), 0);
523 do_kill(os_emul_data *emul,
529 pid_t pid = cpu_registers(processor)->gpr[arg0];
530 int sig = cpu_registers(processor)->gpr[arg0+1];
532 if (WITH_TRACE && ppc_trace[trace_os_emul])
533 printf_filtered ("%d, %d", (int)pid, sig);
536 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
538 cpu_halt(processor, cia, was_signalled, sig);
546 do_dup(os_emul_data *emul,
552 int oldd = cpu_registers(processor)->gpr[arg0];
553 int status = dup(oldd);
556 if (WITH_TRACE && ppc_trace[trace_os_emul])
557 printf_filtered ("%d", oldd);
560 emul_write_status(processor, status, err);
568 do_getegid(os_emul_data *emul,
575 emul_write_status(processor, (int)getegid(), 0);
583 do_getgid(os_emul_data *emul,
590 emul_write_status(processor, (int)getgid(), 0);
594 #ifndef HAVE_SIGPROCMASK
595 #define do_sigprocmask 0
598 do_sigprocmask(os_emul_data *emul,
604 natural_word how = cpu_registers(processor)->gpr[arg0];
605 unsigned_word set = cpu_registers(processor)->gpr[arg0+1];
606 unsigned_word oset = cpu_registers(processor)->gpr[arg0+2];
607 #ifdef SYS_sigprocmask
611 if (WITH_TRACE && ppc_trace[trace_os_emul])
612 printf_filtered ("%ld, 0x%ld, 0x%ld", (long)how, (long)set, (long)oset);
614 emul_write_status(processor, 0, 0);
615 cpu_registers(processor)->gpr[4] = set;
623 do_ioctl(os_emul_data *emul,
629 int d = cpu_registers(processor)->gpr[arg0];
630 unsigned request = cpu_registers(processor)->gpr[arg0+1];
631 unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
633 #if !WITH_NetBSD_HOST
634 cpu_registers(processor)->gpr[arg0] = 0; /* just succeed */
636 unsigned dir = request & IOC_DIRMASK;
639 /* what we haven't done */
640 if (dir & IOC_IN /* write into the io device */
642 || !(dir & IOC_VOID))
643 error("do_ioctl() read or write of parameter not implemented\n");
644 status = ioctl(d, request, NULL);
645 emul_write_status(processor, status, errno);
648 if (WITH_TRACE && ppc_trace[trace_os_emul])
649 printf_filtered ("%d, 0x%x, 0x%lx", d, request, (long)argp_addr);
657 do_umask(os_emul_data *emul,
663 int mask = cpu_registers(processor)->gpr[arg0];
665 if (WITH_TRACE && ppc_trace[trace_os_emul])
666 printf_filtered ("0%o", mask);
669 emul_write_status(processor, umask(mask), 0);
677 do_dup2(os_emul_data *emul,
683 int oldd = cpu_registers(processor)->gpr[arg0];
684 int newd = cpu_registers(processor)->gpr[arg0+1];
685 int status = dup2(oldd, newd);
688 if (WITH_TRACE && ppc_trace[trace_os_emul])
689 printf_filtered ("%d, %d", oldd, newd);
692 emul_write_status(processor, status, err);
700 do_fcntl(os_emul_data *emul,
706 int fd = cpu_registers(processor)->gpr[arg0];
707 int cmd = cpu_registers(processor)->gpr[arg0+1];
708 int arg = cpu_registers(processor)->gpr[arg0+2];
711 if (WITH_TRACE && ppc_trace[trace_os_emul])
712 printf_filtered ("%d, %d, %d", fd, cmd, arg);
715 status = fcntl(fd, cmd, arg);
716 emul_write_status(processor, status, errno);
720 #ifndef HAVE_GETTIMEOFDAY
721 #define do_gettimeofday 0
724 do_gettimeofday(os_emul_data *emul,
730 unsigned_word t_addr = cpu_registers(processor)->gpr[arg0];
731 unsigned_word tz_addr = cpu_registers(processor)->gpr[arg0+1];
734 int status = gettimeofday((t_addr != 0 ? &t : NULL),
735 (tz_addr != 0 ? &tz : NULL));
738 if (WITH_TRACE && ppc_trace[trace_os_emul])
739 printf_filtered ("0x%lx, 0x%lx", (long)t_addr, (long)tz_addr);
742 emul_write_status(processor, status, err);
745 write_timeval(t_addr, t, processor, cia);
747 write_timezone(tz_addr, tz, processor, cia);
752 #ifndef HAVE_GETRUSAGE
753 #define do_getrusage 0
756 do_getrusage(os_emul_data *emul,
762 int who = cpu_registers(processor)->gpr[arg0];
763 unsigned_word rusage_addr = cpu_registers(processor)->gpr[arg0+1];
764 struct rusage rusage;
765 int status = getrusage(who, (rusage_addr != 0 ? &rusage : NULL));
768 if (WITH_TRACE && ppc_trace[trace_os_emul])
769 printf_filtered ("%d, 0x%lx", who, (long)rusage_addr);
772 emul_write_status(processor, status, err);
774 if (rusage_addr != 0)
775 write_rusage(rusage_addr, rusage, processor, cia);
785 do_fstatfs(os_emul_data *emul,
791 int fd = cpu_registers(processor)->gpr[arg0];
792 unsigned_word buf_addr = cpu_registers(processor)->gpr[arg0+1];
796 if (WITH_TRACE && ppc_trace[trace_os_emul])
797 printf_filtered ("%d, 0x%lx", fd, (long)buf_addr);
800 status = fstatfs(fd, (buf_addr == 0 ? NULL : &buf));
801 emul_write_status(processor, status, errno);
804 write_statfs(buf_addr, buf, processor, cia);
813 do_stat(os_emul_data *emul,
819 char path_buf[PATH_MAX];
820 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
821 unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
822 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
828 status = stat(path, &buf);
829 emul_write_status(processor, status, errno);
831 write_stat(stat_buf_addr, buf, processor, cia);
839 do_fstat(os_emul_data *emul,
845 int fd = cpu_registers(processor)->gpr[arg0];
846 unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
852 /* Can't combine these statements, cuz fstat sets errno. */
853 status = fstat(fd, &buf);
854 emul_write_status(processor, status, errno);
855 write_stat(stat_buf_addr, buf, processor, cia);
863 do_lstat(os_emul_data *emul,
869 char path_buf[PATH_MAX];
870 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
871 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
872 unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
878 /* Can't combine these statements, cuz lstat sets errno. */
879 status = lstat(path, &buf);
880 emul_write_status(processor, status, errno);
881 write_stat(stat_buf_addr, buf, processor, cia);
885 #ifndef HAVE_GETDIRENTRIES
886 #define do_getdirentries 0
889 do_getdirentries(os_emul_data *emul,
895 int fd = cpu_registers(processor)->gpr[arg0];
896 unsigned_word buf_addr = cpu_registers(processor)->gpr[arg0+1];
898 int nbytes = cpu_registers(processor)->gpr[arg0+2];
899 unsigned_word basep_addr = cpu_registers(processor)->gpr[arg0+3];
902 #ifdef SYS_getdirentries
905 if (buf_addr != 0 && nbytes >= 0)
906 buf = zalloc(nbytes);
909 status = getdirentries(fd,
910 (buf_addr == 0 ? NULL : buf),
912 (basep_addr == 0 ? NULL : &basep));
913 emul_write_status(processor, status, errno);
915 emul_write_word(basep_addr, basep, processor, cia);
917 write_direntries(buf_addr, buf, status, processor, cia);
925 do___syscall(os_emul_data *emul,
932 emul_do_system_call(emul,
934 cpu_registers(processor)->gpr[arg0],
944 do_lseek(os_emul_data *emul,
950 int fildes = cpu_registers(processor)->gpr[arg0];
951 off_t offset = emul_read_gpr64(processor, arg0+2);
952 int whence = cpu_registers(processor)->gpr[arg0+4];
955 status = lseek(fildes, offset, whence);
957 emul_write_status(processor, -1, errno);
959 emul_write_status(processor, 0, 0); /* success */
960 emul_write_gpr64(processor, 3, status);
966 do___sysctl(os_emul_data *emul,
972 /* call the arguments by their real name */
973 unsigned_word name = cpu_registers(processor)->gpr[arg0];
974 natural_word namelen = cpu_registers(processor)->gpr[arg0+1];
975 unsigned_word oldp = cpu_registers(processor)->gpr[arg0+2];
976 unsigned_word oldlenp = cpu_registers(processor)->gpr[arg0+3];
979 natural_word int_val;
982 /* pluck out the management information base id */
984 error("system_call()SYS___sysctl bad name[0]\n");
985 mib = vm_data_map_read_word(cpu_data_map(processor),
991 /* see what to do with it ... */
994 #if WITH_NetBSD_HOST && (CTL_HW != 6)
998 error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
999 mib = vm_data_map_read_word(cpu_data_map(processor),
1003 name += sizeof(mib);
1005 case 7/*HW_PAGESIZE*/:
1006 #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
1007 # error "HW_PAGESIZE"
1009 oldlen = vm_data_map_read_word(cpu_data_map(processor),
1013 if (sizeof(natural_word) > oldlen)
1014 error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
1016 oldlen = sizeof(int_val);
1017 emul_write_word(oldp, int_val, processor, cia);
1018 emul_write_word(oldlenp, oldlen, processor, cia);
1021 error("sysctl() CTL_HW.%d unknown\n", mib);
1026 error("sysctl() name[0]=%d unknown\n", (int)mib);
1029 emul_write_status(processor, 0, 0); /* always succeed */
1034 static emul_syscall_descriptor netbsd_descriptors[] = {
1035 /* 0 */ { 0, "syscall" },
1036 /* 1 */ { do_exit, "exit" },
1037 /* 2 */ { 0, "fork" },
1038 /* 3 */ { do_read, "read" },
1039 /* 4 */ { do_write, "write" },
1040 /* 5 */ { do_open, "open" },
1041 /* 6 */ { do_close, "close" },
1042 /* 7 */ { 0, "wait4" },
1043 { 0, }, /* 8 is old creat */
1044 /* 9 */ { 0, "link" },
1045 /* 10 */ { 0, "unlink" },
1046 { 0, }, /* 11 is obsolete execv */
1047 /* 12 */ { 0, "chdir" },
1048 /* 13 */ { 0, "fchdir" },
1049 /* 14 */ { 0, "mknod" },
1050 /* 15 */ { 0, "chmod" },
1051 /* 16 */ { 0, "chown" },
1052 /* 17 */ { do_break, "break" },
1053 /* 18 */ { 0, "getfsstat" },
1054 { 0, }, /* 19 is old lseek */
1055 /* 20 */ { do_getpid, "getpid" },
1056 /* 21 */ { 0, "mount" },
1057 /* 22 */ { 0, "unmount" },
1058 /* 23 */ { 0, "setuid" },
1059 /* 24 */ { do_getuid, "getuid" },
1060 /* 25 */ { do_geteuid, "geteuid" },
1061 /* 26 */ { 0, "ptrace" },
1062 /* 27 */ { 0, "recvmsg" },
1063 /* 28 */ { 0, "sendmsg" },
1064 /* 29 */ { 0, "recvfrom" },
1065 /* 30 */ { 0, "accept" },
1066 /* 31 */ { 0, "getpeername" },
1067 /* 32 */ { 0, "getsockname" },
1068 /* 33 */ { 0, "access" },
1069 /* 34 */ { 0, "chflags" },
1070 /* 35 */ { 0, "fchflags" },
1071 /* 36 */ { 0, "sync" },
1072 /* 37 */ { do_kill, "kill" },
1073 { 0, }, /* 38 is old stat */
1074 /* 39 */ { 0, "getppid" },
1075 { 0, }, /* 40 is old lstat */
1076 /* 41 */ { do_dup, "dup" },
1077 /* 42 */ { 0, "pipe" },
1078 /* 43 */ { do_getegid, "getegid" },
1079 /* 44 */ { 0, "profil" },
1080 /* 45 */ { 0, "ktrace" },
1081 /* 46 */ { 0, "sigaction" },
1082 /* 47 */ { do_getgid, "getgid" },
1083 /* 48 */ { do_sigprocmask, "sigprocmask" },
1084 /* 49 */ { 0, "getlogin" },
1085 /* 50 */ { 0, "setlogin" },
1086 /* 51 */ { 0, "acct" },
1087 /* 52 */ { 0, "sigpending" },
1088 /* 53 */ { 0, "sigaltstack" },
1089 /* 54 */ { do_ioctl, "ioctl" },
1090 /* 55 */ { 0, "reboot" },
1091 /* 56 */ { 0, "revoke" },
1092 /* 57 */ { 0, "symlink" },
1093 /* 58 */ { 0, "readlink" },
1094 /* 59 */ { 0, "execve" },
1095 /* 60 */ { do_umask, "umask" },
1096 /* 61 */ { 0, "chroot" },
1097 { 0, }, /* 62 is old fstat */
1098 { 0, }, /* 63 is old getkerninfo */
1099 { 0, }, /* 64 is old getpagesize */
1100 /* 65 */ { 0, "msync" },
1101 /* 66 */ { 0, "vfork" },
1102 { 0, }, /* 67 is obsolete vread */
1103 { 0, }, /* 68 is obsolete vwrite */
1104 /* 69 */ { 0, "sbrk" },
1105 /* 70 */ { 0, "sstk" },
1106 { 0, }, /* 71 is old mmap */
1107 /* 72 */ { 0, "vadvise" },
1108 /* 73 */ { 0, "munmap" },
1109 /* 74 */ { 0, "mprotect" },
1110 /* 75 */ { 0, "madvise" },
1111 { 0, }, /* 76 is obsolete vhangup */
1112 { 0, }, /* 77 is obsolete vlimit */
1113 /* 78 */ { 0, "mincore" },
1114 /* 79 */ { 0, "getgroups" },
1115 /* 80 */ { 0, "setgroups" },
1116 /* 81 */ { 0, "getpgrp" },
1117 /* 82 */ { 0, "setpgid" },
1118 /* 83 */ { 0, "setitimer" },
1119 { 0, }, /* 84 is old wait */
1120 /* 85 */ { 0, "swapon" },
1121 /* 86 */ { 0, "getitimer" },
1122 { 0, }, /* 87 is old gethostname */
1123 { 0, }, /* 88 is old sethostname */
1124 { 0, }, /* 89 is old getdtablesize */
1125 { do_dup2, "dup2" },
1127 /* 92 */ { do_fcntl, "fcntl" },
1128 /* 93 */ { 0, "select" },
1130 /* 95 */ { 0, "fsync" },
1131 /* 96 */ { 0, "setpriority" },
1132 /* 97 */ { 0, "socket" },
1133 /* 98 */ { 0, "connect" },
1134 { 0, }, /* 99 is old accept */
1135 /* 100 */ { 0, "getpriority" },
1136 { 0, }, /* 101 is old send */
1137 { 0, }, /* 102 is old recv */
1138 /* 103 */ { 0, "sigreturn" },
1139 /* 104 */ { 0, "bind" },
1140 /* 105 */ { 0, "setsockopt" },
1141 /* 106 */ { 0, "listen" },
1142 { 0, }, /* 107 is obsolete vtimes */
1143 { 0, }, /* 108 is old sigvec */
1144 { 0, }, /* 109 is old sigblock */
1145 { 0, }, /* 110 is old sigsetmask */
1146 /* 111 */ { 0, "sigsuspend" },
1147 { 0, }, /* 112 is old sigstack */
1148 { 0, }, /* 113 is old recvmsg */
1149 { 0, }, /* 114 is old sendmsg */
1150 /* - is obsolete vtrace */ { 0, "vtrace 115" },
1151 /* 116 */ { do_gettimeofday, "gettimeofday" },
1152 /* 117 */ { do_getrusage, "getrusage" },
1153 /* 118 */ { 0, "getsockopt" },
1154 /* 119 */ { 0, "resuba" },
1155 /* 120 */ { 0, "readv" },
1156 /* 121 */ { 0, "writev" },
1157 /* 122 */ { 0, "settimeofday" },
1158 /* 123 */ { 0, "fchown" },
1159 /* 124 */ { 0, "fchmod" },
1160 { 0, }, /* 125 is old recvfrom */
1161 { 0, }, /* 126 is old setreuid */
1162 { 0, }, /* 127 is old setregid */
1163 /* 128 */ { 0, "rename" },
1164 { 0, }, /* 129 is old truncate */
1165 { 0, }, /* 130 is old ftruncate */
1166 /* 131 */ { 0, "flock" },
1167 /* 132 */ { 0, "mkfifo" },
1168 /* 133 */ { 0, "sendto" },
1169 /* 134 */ { 0, "shutdown" },
1170 /* 135 */ { 0, "socketpair" },
1171 /* 136 */ { 0, "mkdir" },
1172 /* 137 */ { 0, "rmdir" },
1173 /* 138 */ { 0, "utimes" },
1174 { 0, }, /* 139 is obsolete 4.2 sigreturn */
1175 /* 140 */ { 0, "adjtime" },
1176 { 0, }, /* 141 is old getpeername */
1177 { 0, }, /* 142 is old gethostid */
1178 { 0, }, /* 143 is old sethostid */
1179 { 0, }, /* 144 is old getrlimit */
1180 { 0, }, /* 145 is old setrlimit */
1181 { 0, }, /* 146 is old killpg */
1182 /* 147 */ { 0, "setsid" },
1183 /* 148 */ { 0, "quotactl" },
1184 { 0, }, /* 149 is old quota */
1185 { 0, }, /* 150 is old getsockname */
1190 /* 155 */ { 0, "nfssvc" },
1191 { 0, }, /* 156 is old getdirentries */
1192 /* 157 */ { 0, "statfs" },
1193 /* 158 */ { do_fstatfs, "fstatfs" },
1196 /* 161 */ { 0, "getfh" },
1197 { 0, }, /* 162 is old getdomainname */
1198 { 0, }, /* 163 is old setdomainname */
1199 { 0, }, /* 164 is old uname */
1200 /* 165 */ { 0, "sysarch" },
1204 /* 169 */ { 0, "semsys" },
1205 /* 170 */ { 0, "msgsys" },
1206 /* 171 */ { 0, "shmsys" },
1216 /* 181 */ { 0, "setgid" },
1217 /* 182 */ { 0, "setegid" },
1218 /* 183 */ { 0, "seteuid" },
1219 /* 184 */ { 0, "lfs_bmapv" },
1220 /* 185 */ { 0, "lfs_markv" },
1221 /* 186 */ { 0, "lfs_segclean" },
1222 /* 187 */ { 0, "lfs_segwait" },
1223 /* 188 */ { do_stat, "stat" },
1224 /* 189 */ { do_fstat, "fstat" },
1225 /* 190 */ { do_lstat, "lstat" },
1226 /* 191 */ { 0, "pathconf" },
1227 /* 192 */ { 0, "fpathconf" },
1229 /* 194 */ { 0, "getrlimit" },
1230 /* 195 */ { 0, "setrlimit" },
1231 /* 196 */ { do_getdirentries, "getdirentries" },
1232 /* 197 */ { 0, "mmap" },
1233 /* 198 */ { do___syscall, "__syscall" },
1234 /* 199 */ { do_lseek, "lseek" },
1235 /* 200 */ { 0, "truncate" },
1236 /* 201 */ { 0, "ftruncate" },
1237 /* 202 */ { do___sysctl, "__sysctl" },
1238 /* 203 */ { 0, "mlock" },
1239 /* 204 */ { 0, "munlock" },
1242 static char *(netbsd_error_names[]) = {
1279 /* 36 */ "EINPROGRESS",
1280 /* 37 */ "EALREADY",
1281 /* 38 */ "ENOTSOCK",
1282 /* 39 */ "EDESTADDRREQ",
1283 /* 40 */ "EMSGSIZE",
1284 /* 41 */ "EPROTOTYPE",
1285 /* 42 */ "ENOPROTOOPT",
1286 /* 43 */ "EPROTONOSUPPORT",
1287 /* 44 */ "ESOCKTNOSUPPORT",
1288 /* 45 */ "EOPNOTSUPP",
1289 /* 46 */ "EPFNOSUPPORT",
1290 /* 47 */ "EAFNOSUPPORT",
1291 /* 48 */ "EADDRINUSE",
1292 /* 49 */ "EADDRNOTAVAIL",
1293 /* 50 */ "ENETDOWN",
1294 /* 51 */ "ENETUNREACH",
1295 /* 52 */ "ENETRESET",
1296 /* 53 */ "ECONNABORTED",
1297 /* 54 */ "ECONNRESET",
1300 /* 57 */ "ENOTCONN",
1301 /* 58 */ "ESHUTDOWN",
1302 /* 59 */ "ETOOMANYREFS",
1303 /* 60 */ "ETIMEDOUT",
1304 /* 61 */ "ECONNREFUSED",
1306 /* 63 */ "ENAMETOOLONG",
1307 /* 64 */ "EHOSTDOWN",
1308 /* 65 */ "EHOSTUNREACH",
1309 /* 66 */ "ENOTEMPTY",
1310 /* 67 */ "EPROCLIM",
1316 /* 73 */ "ERPCMISMATCH",
1317 /* 74 */ "EPROGUNAVAIL",
1318 /* 75 */ "EPROGMISMATCH",
1319 /* 76 */ "EPROCUNAVAIL",
1324 /* 81 */ "ENEEDAUTH",
1328 static char *(netbsd_signal_names[]) = {
1355 /* 26 */ "SIGVTALRM",
1357 /* 28 */ "SIGWINCH",
1363 static emul_syscall emul_netbsd_syscalls = {
1365 sizeof(netbsd_descriptors) / sizeof(netbsd_descriptors[0]),
1367 sizeof(netbsd_error_names) / sizeof(netbsd_error_names[0]),
1368 netbsd_signal_names,
1369 sizeof(netbsd_signal_names) / sizeof(netbsd_signal_names[0]),
1373 /* NetBSD's os_emul interface, most are just passed on to the generic
1376 static os_emul_data *
1377 emul_netbsd_create(device *root,
1381 unsigned_word top_of_stack;
1382 unsigned stack_size;
1384 os_emul_data *bsd_data;
1388 /* check that this emulation is really for us */
1389 if (name != NULL && strcmp(name, "netbsd") != 0)
1395 /* merge any emulation specific entries into the device tree */
1397 /* establish a few defaults */
1398 if (image->xvec->flavour == bfd_target_elf_flavour) {
1400 top_of_stack = 0xe0000000;
1401 stack_size = 0x00100000;
1405 top_of_stack = 0x20000000;
1406 stack_size = 0x00100000;
1410 emul_add_tree_options(root, image, "netbsd",
1411 (WITH_ENVIRONMENT == USER_ENVIRONMENT
1412 ? "user" : "virtual"),
1413 0 /*oea-interrupt-prefix*/);
1415 /* virtual memory - handles growth of stack/heap */
1416 vm = tree_parse(root, "/openprom/vm");
1417 tree_parse(vm, "./stack-base 0x%lx",
1418 (unsigned long)(top_of_stack - stack_size));
1419 tree_parse(vm, "./nr-bytes 0x%x", stack_size);
1421 filename = tree_quote_property (bfd_get_filename(image));
1422 tree_parse(root, "/openprom/vm/map-binary/file-name %s",
1426 /* finish the init */
1427 tree_parse(root, "/openprom/init/register/pc 0x%lx",
1428 (unsigned long)bfd_get_start_address(image));
1429 tree_parse(root, "/openprom/init/register/sp 0x%lx",
1430 (unsigned long)top_of_stack);
1431 tree_parse(root, "/openprom/init/register/msr 0x%x",
1432 ((tree_find_boolean_property(root, "/options/little-endian?")
1433 ? msr_little_endian_mode
1435 | (tree_find_boolean_property(root, "/openprom/options/floating-point?")
1436 ? (msr_floating_point_available
1437 | msr_floating_point_exception_mode_0
1438 | msr_floating_point_exception_mode_1)
1440 tree_parse(root, "/openprom/init/stack/stack-type %s",
1441 (elf_binary ? "ppc-elf" : "ppc-xcoff"));
1443 /* finally our emulation data */
1444 bsd_data = ZALLOC(os_emul_data);
1446 bsd_data->syscalls = &emul_netbsd_syscalls;
1451 emul_netbsd_init(os_emul_data *emul_data,
1458 emul_netbsd_system_call(cpu *processor,
1460 os_emul_data *emul_data)
1462 emul_do_system_call(emul_data,
1463 emul_data->syscalls,
1464 cpu_registers(processor)->gpr[0],
1465 3, /*r3 contains arg0*/
1470 const os_emul emul_netbsd = {
1474 emul_netbsd_system_call,
1475 0, /*instruction_call*/
1479 #endif /* _EMUL_NETBSD_C_ */