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>
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>
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 extern int getdirentries(int fd, char *buf, int nbytes, long *basep);
97 /* If this is not netbsd, don't allow fstatfs or getdirentries at this time */
99 #undef HAVE_GETDIRENTRIES
102 #if (BSD < 199306) /* here BSD as just a bug */
106 #ifndef STATIC_INLINE_EMUL_NETBSD
107 #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
112 #define SYS(X) ASSERT(call == (SYS_##X))
117 #if WITH_NetBSD_HOST && (PATH_MAX != 1024)
118 #error "PATH_MAX not 1024"
119 #elif !defined(PATH_MAX)
120 #define PATH_MAX 1024
126 NetBSD - Emulation of user programs for NetBSD/PPC
133 /* NetBSD's idea of what is needed to implement emulations */
135 struct _os_emul_data {
137 emul_syscall *syscalls;
142 STATIC_INLINE_EMUL_NETBSD void
143 write_stat(unsigned_word addr,
156 /* H2T(buf.st_spare1); */
158 /* H2T(buf.st_spare2); */
160 /* H2T(buf.st_spare3); */
161 #ifdef AC_STRUCT_ST_RDEV
164 #ifdef AC_STRUCT_ST_BLKSIZE
167 #ifdef AC_STRUCT_ST_BLOCKS
174 emul_write_buffer(&buf, addr, sizeof(buf), processor, cia);
179 STATIC_INLINE_EMUL_NETBSD void
180 write_statfs(unsigned_word addr,
194 H2T(buf.f_fsid.val[0]);
195 H2T(buf.f_fsid.val[1]);
198 /* f_fstypename[MFSNAMELEN]; */
199 /* f_mntonname[MNAMELEN]; */
200 /* f_mntfromname[MNAMELEN]; */
201 emul_write_buffer(&buf, addr, sizeof(buf), processor, cia);
206 STATIC_INLINE_EMUL_NETBSD void
207 write_timeval(unsigned_word addr,
214 emul_write_buffer(&t, addr, sizeof(t), processor, cia);
218 STATIC_INLINE_EMUL_NETBSD void
219 write_timezone(unsigned_word addr,
224 H2T(tz.tz_minuteswest);
226 emul_write_buffer(&tz, addr, sizeof(tz), processor, cia);
230 #ifdef HAVE_GETDIRENTRIES
231 STATIC_INLINE_EMUL_NETBSD void
232 write_direntries(unsigned_word addr,
240 struct dirent *in = (struct dirent*)buf;
241 ASSERT(in->d_reclen <= nbytes);
242 out = (struct dirent*)zalloc(in->d_reclen);
243 memcpy(out/*dest*/, in/*src*/, in->d_reclen);
248 emul_write_buffer(out, addr, in->d_reclen, processor, cia);
249 nbytes -= in->d_reclen;
250 addr += in->d_reclen;
258 #ifdef HAVE_GETRUSAGE
259 STATIC_INLINE_EMUL_NETBSD void
260 write_rusage(unsigned_word addr,
261 struct rusage rusage,
265 H2T(rusage.ru_utime.tv_sec); /* user time used */
266 H2T(rusage.ru_utime.tv_usec);
267 H2T(rusage.ru_stime.tv_sec); /* system time used */
268 H2T(rusage.ru_stime.tv_usec);
269 H2T(rusage.ru_maxrss); /* integral max resident set size */
270 H2T(rusage.ru_ixrss); /* integral shared text memory size */
271 H2T(rusage.ru_idrss); /* integral unshared data size */
272 H2T(rusage.ru_isrss); /* integral unshared stack size */
273 H2T(rusage.ru_minflt); /* page reclaims */
274 H2T(rusage.ru_majflt); /* page faults */
275 H2T(rusage.ru_nswap); /* swaps */
276 H2T(rusage.ru_inblock); /* block input operations */
277 H2T(rusage.ru_oublock); /* block output operations */
278 H2T(rusage.ru_msgsnd); /* messages sent */
279 H2T(rusage.ru_msgrcv); /* messages received */
280 H2T(rusage.ru_nsignals); /* signals received */
281 H2T(rusage.ru_nvcsw); /* voluntary context switches */
282 H2T(rusage.ru_nivcsw); /* involuntary context switches */
283 emul_write_buffer(&rusage, addr, sizeof(rusage), processor, cia);
288 do_exit(os_emul_data *emul,
294 int status = (int)cpu_registers(processor)->gpr[arg0];
296 if (WITH_TRACE && ppc_trace[trace_os_emul])
297 printf_filtered ("%d)\n", status);
299 cpu_halt(processor, cia, was_exited, status);
304 do_read(os_emul_data *emul,
310 void *scratch_buffer;
311 int d = (int)cpu_registers(processor)->gpr[arg0];
312 unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
313 int nbytes = cpu_registers(processor)->gpr[arg0+2];
317 if (WITH_TRACE && ppc_trace[trace_os_emul])
318 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
320 /* get a tempoary bufer */
321 scratch_buffer = zalloc(nbytes);
323 /* check if buffer exists by reading it */
324 emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia);
329 status = fread (scratch_buffer, 1, nbytes, stdin);
330 if (status == 0 && ferror (stdin))
334 status = read (d, scratch_buffer, nbytes);
336 emul_write_status(processor, status, errno);
338 emul_write_buffer(scratch_buffer, buf, status, processor, cia);
340 zfree(scratch_buffer);
345 do_write(os_emul_data *emul,
351 void *scratch_buffer = NULL;
352 int d = (int)cpu_registers(processor)->gpr[arg0];
353 unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
354 int nbytes = cpu_registers(processor)->gpr[arg0+2];
358 if (WITH_TRACE && ppc_trace[trace_os_emul])
359 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
361 /* get a tempoary bufer */
362 scratch_buffer = zalloc(nbytes); /* FIXME - nbytes == 0 */
365 emul_read_buffer(scratch_buffer, buf, nbytes,
369 status = write(d, scratch_buffer, nbytes);
370 emul_write_status(processor, status, errno);
371 zfree(scratch_buffer);
378 do_open(os_emul_data *emul,
384 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
385 char path_buf[PATH_MAX];
386 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
387 int flags = (int)cpu_registers(processor)->gpr[arg0+1];
388 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);
397 /* Do some translation on 'flags' to match it to the host's version. */
398 /* These flag values were taken from the NetBSD 1.4 header files. */
399 if ((flags & 3) == 0)
400 hostflags = O_RDONLY;
401 else if ((flags & 3) == 1)
402 hostflags = O_WRONLY;
405 if (flags & 0x00000008)
406 hostflags |= O_APPEND;
407 if (flags & 0x00000200)
408 hostflags |= O_CREAT;
409 if (flags & 0x00000400)
410 hostflags |= O_TRUNC;
411 if (flags & 0x00000800)
414 /* Can't combine these statements, cuz open sets errno. */
415 status = open(path, hostflags, mode);
416 emul_write_status(processor, status, errno);
421 do_close(os_emul_data *emul,
427 int d = (int)cpu_registers(processor)->gpr[arg0];
430 if (WITH_TRACE && ppc_trace[trace_os_emul])
431 printf_filtered ("%d", d);
435 /* Can't combine these statements, cuz close sets errno. */
437 emul_write_status(processor, status, errno);
442 do_break(os_emul_data *emul,
448 /* just pass this onto the `vm' device */
449 unsigned_word new_break = cpu_registers(processor)->gpr[arg0];
452 if (WITH_TRACE && ppc_trace[trace_os_emul])
453 printf_filtered ("0x%lx", (long)cpu_registers(processor)->gpr[arg0]);
456 status = device_ioctl(emul->vm,
460 new_break); /*ioctl-data*/
461 emul_write_status(processor, 0, status);
469 do_getpid(os_emul_data *emul,
476 emul_write_status(processor, (int)getpid(), 0);
484 do_getuid(os_emul_data *emul,
491 emul_write_status(processor, (int)getuid(), 0);
499 do_geteuid(os_emul_data *emul,
506 emul_write_status(processor, (int)geteuid(), 0);
514 do_kill(os_emul_data *emul,
520 pid_t pid = cpu_registers(processor)->gpr[arg0];
521 int sig = cpu_registers(processor)->gpr[arg0+1];
523 if (WITH_TRACE && ppc_trace[trace_os_emul])
524 printf_filtered ("%d, %d", (int)pid, sig);
527 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
529 cpu_halt(processor, cia, was_signalled, sig);
537 do_dup(os_emul_data *emul,
543 int oldd = cpu_registers(processor)->gpr[arg0];
544 int status = dup(oldd);
547 if (WITH_TRACE && ppc_trace[trace_os_emul])
548 printf_filtered ("%d", oldd);
551 emul_write_status(processor, status, err);
559 do_getegid(os_emul_data *emul,
566 emul_write_status(processor, (int)getegid(), 0);
574 do_getgid(os_emul_data *emul,
581 emul_write_status(processor, (int)getgid(), 0);
585 #ifndef HAVE_SIGPROCMASK
586 #define do_sigprocmask 0
589 do_sigprocmask(os_emul_data *emul,
595 natural_word how = cpu_registers(processor)->gpr[arg0];
596 unsigned_word set = cpu_registers(processor)->gpr[arg0+1];
597 unsigned_word oset = cpu_registers(processor)->gpr[arg0+2];
600 if (WITH_TRACE && ppc_trace[trace_os_emul])
601 printf_filtered ("%ld, 0x%ld, 0x%ld", (long)how, (long)set, (long)oset);
603 emul_write_status(processor, 0, 0);
604 cpu_registers(processor)->gpr[4] = set;
612 do_ioctl(os_emul_data *emul,
618 int d = cpu_registers(processor)->gpr[arg0];
619 unsigned request = cpu_registers(processor)->gpr[arg0+1];
620 unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
622 #if !WITH_NetBSD_HOST
623 cpu_registers(processor)->gpr[arg0] = 0; /* just succeed */
625 unsigned dir = request & IOC_DIRMASK;
628 /* what we haven't done */
629 if (dir & IOC_IN /* write into the io device */
631 || !(dir & IOC_VOID))
632 error("do_ioctl() read or write of parameter not implemented\n");
633 status = ioctl(d, request, NULL);
634 emul_write_status(processor, status, errno);
637 if (WITH_TRACE && ppc_trace[trace_os_emul])
638 printf_filtered ("%d, 0x%x, 0x%lx", d, request, (long)argp_addr);
646 do_umask(os_emul_data *emul,
652 int mask = cpu_registers(processor)->gpr[arg0];
654 if (WITH_TRACE && ppc_trace[trace_os_emul])
655 printf_filtered ("0%o", mask);
658 emul_write_status(processor, umask(mask), 0);
666 do_dup2(os_emul_data *emul,
672 int oldd = cpu_registers(processor)->gpr[arg0];
673 int newd = cpu_registers(processor)->gpr[arg0+1];
674 int status = dup2(oldd, newd);
677 if (WITH_TRACE && ppc_trace[trace_os_emul])
678 printf_filtered ("%d, %d", oldd, newd);
681 emul_write_status(processor, status, err);
689 do_fcntl(os_emul_data *emul,
695 int fd = cpu_registers(processor)->gpr[arg0];
696 int cmd = cpu_registers(processor)->gpr[arg0+1];
697 int arg = cpu_registers(processor)->gpr[arg0+2];
700 if (WITH_TRACE && ppc_trace[trace_os_emul])
701 printf_filtered ("%d, %d, %d", fd, cmd, arg);
704 status = fcntl(fd, cmd, arg);
705 emul_write_status(processor, status, errno);
709 #ifndef HAVE_GETTIMEOFDAY
710 #define do_gettimeofday 0
713 do_gettimeofday(os_emul_data *emul,
719 unsigned_word t_addr = cpu_registers(processor)->gpr[arg0];
720 unsigned_word tz_addr = cpu_registers(processor)->gpr[arg0+1];
723 int status = gettimeofday((t_addr != 0 ? &t : NULL),
724 (tz_addr != 0 ? &tz : NULL));
727 if (WITH_TRACE && ppc_trace[trace_os_emul])
728 printf_filtered ("0x%lx, 0x%lx", (long)t_addr, (long)tz_addr);
731 emul_write_status(processor, status, err);
734 write_timeval(t_addr, t, processor, cia);
736 write_timezone(tz_addr, tz, processor, cia);
741 #ifndef HAVE_GETRUSAGE
742 #define do_getrusage 0
745 do_getrusage(os_emul_data *emul,
751 int who = cpu_registers(processor)->gpr[arg0];
752 unsigned_word rusage_addr = cpu_registers(processor)->gpr[arg0+1];
753 struct rusage rusage;
754 int status = getrusage(who, (rusage_addr != 0 ? &rusage : NULL));
757 if (WITH_TRACE && ppc_trace[trace_os_emul])
758 printf_filtered ("%d, 0x%lx", who, (long)rusage_addr);
761 emul_write_status(processor, status, err);
763 if (rusage_addr != 0)
764 write_rusage(rusage_addr, rusage, processor, cia);
774 do_fstatfs(os_emul_data *emul,
780 int fd = cpu_registers(processor)->gpr[arg0];
781 unsigned_word buf_addr = cpu_registers(processor)->gpr[arg0+1];
785 if (WITH_TRACE && ppc_trace[trace_os_emul])
786 printf_filtered ("%d, 0x%lx", fd, (long)buf_addr);
789 status = fstatfs(fd, (buf_addr == 0 ? NULL : &buf));
790 emul_write_status(processor, status, errno);
793 write_statfs(buf_addr, buf, processor, cia);
802 do_stat(os_emul_data *emul,
808 char path_buf[PATH_MAX];
809 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
810 unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
811 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
815 status = stat(path, &buf);
816 emul_write_status(processor, status, errno);
818 write_stat(stat_buf_addr, buf, processor, cia);
826 do_fstat(os_emul_data *emul,
832 int fd = cpu_registers(processor)->gpr[arg0];
833 unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
837 /* Can't combine these statements, cuz fstat sets errno. */
838 status = fstat(fd, &buf);
839 emul_write_status(processor, status, errno);
840 write_stat(stat_buf_addr, buf, processor, cia);
848 do_lstat(os_emul_data *emul,
854 char path_buf[PATH_MAX];
855 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
856 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
857 unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
861 /* Can't combine these statements, cuz lstat sets errno. */
862 status = lstat(path, &buf);
863 emul_write_status(processor, status, errno);
864 write_stat(stat_buf_addr, buf, processor, cia);
868 #ifndef HAVE_GETDIRENTRIES
869 #define do_getdirentries 0
872 do_getdirentries(os_emul_data *emul,
878 int fd = cpu_registers(processor)->gpr[arg0];
879 unsigned_word buf_addr = cpu_registers(processor)->gpr[arg0+1];
881 int nbytes = cpu_registers(processor)->gpr[arg0+2];
882 unsigned_word basep_addr = cpu_registers(processor)->gpr[arg0+3];
886 if (buf_addr != 0 && nbytes >= 0)
887 buf = zalloc(nbytes);
890 status = getdirentries(fd,
891 (buf_addr == 0 ? NULL : buf),
893 (basep_addr == 0 ? NULL : &basep));
894 emul_write_status(processor, status, errno);
896 emul_write_word(basep_addr, basep, processor, cia);
898 write_direntries(buf_addr, buf, status, processor, cia);
906 do___syscall(os_emul_data *emul,
913 emul_do_system_call(emul,
915 cpu_registers(processor)->gpr[arg0],
925 do_lseek(os_emul_data *emul,
931 int fildes = cpu_registers(processor)->gpr[arg0];
932 off_t offset = emul_read_gpr64(processor, arg0+2);
933 int whence = cpu_registers(processor)->gpr[arg0+4];
936 status = lseek(fildes, offset, whence);
938 emul_write_status(processor, -1, errno);
940 emul_write_status(processor, 0, 0); /* success */
941 emul_write_gpr64(processor, 3, status);
947 do___sysctl(os_emul_data *emul,
953 /* call the arguments by their real name */
954 unsigned_word name = cpu_registers(processor)->gpr[arg0];
955 natural_word namelen = cpu_registers(processor)->gpr[arg0+1];
956 unsigned_word oldp = cpu_registers(processor)->gpr[arg0+2];
957 unsigned_word oldlenp = cpu_registers(processor)->gpr[arg0+3];
960 natural_word int_val;
963 /* pluck out the management information base id */
965 error("system_call()SYS___sysctl bad name[0]\n");
966 mib = vm_data_map_read_word(cpu_data_map(processor),
972 /* see what to do with it ... */
975 #if WITH_NetBSD_HOST && (CTL_HW != 6)
979 error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
980 mib = vm_data_map_read_word(cpu_data_map(processor),
986 case 7/*HW_PAGESIZE*/:
987 #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
988 # error "HW_PAGESIZE"
990 oldlen = vm_data_map_read_word(cpu_data_map(processor),
994 if (sizeof(natural_word) > oldlen)
995 error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
997 oldlen = sizeof(int_val);
998 emul_write_word(oldp, int_val, processor, cia);
999 emul_write_word(oldlenp, oldlen, processor, cia);
1002 error("sysctl() CTL_HW.%d unknown\n", mib);
1007 error("sysctl() name[0]=%d unknown\n", (int)mib);
1010 emul_write_status(processor, 0, 0); /* always succeed */
1015 static emul_syscall_descriptor netbsd_descriptors[] = {
1016 /* 0 */ { 0, "syscall" },
1017 /* 1 */ { do_exit, "exit" },
1018 /* 2 */ { 0, "fork" },
1019 /* 3 */ { do_read, "read" },
1020 /* 4 */ { do_write, "write" },
1021 /* 5 */ { do_open, "open" },
1022 /* 6 */ { do_close, "close" },
1023 /* 7 */ { 0, "wait4" },
1024 { 0, }, /* 8 is old creat */
1025 /* 9 */ { 0, "link" },
1026 /* 10 */ { 0, "unlink" },
1027 { 0, }, /* 11 is obsolete execv */
1028 /* 12 */ { 0, "chdir" },
1029 /* 13 */ { 0, "fchdir" },
1030 /* 14 */ { 0, "mknod" },
1031 /* 15 */ { 0, "chmod" },
1032 /* 16 */ { 0, "chown" },
1033 /* 17 */ { do_break, "break" },
1034 /* 18 */ { 0, "getfsstat" },
1035 { 0, }, /* 19 is old lseek */
1036 /* 20 */ { do_getpid, "getpid" },
1037 /* 21 */ { 0, "mount" },
1038 /* 22 */ { 0, "unmount" },
1039 /* 23 */ { 0, "setuid" },
1040 /* 24 */ { do_getuid, "getuid" },
1041 /* 25 */ { do_geteuid, "geteuid" },
1042 /* 26 */ { 0, "ptrace" },
1043 /* 27 */ { 0, "recvmsg" },
1044 /* 28 */ { 0, "sendmsg" },
1045 /* 29 */ { 0, "recvfrom" },
1046 /* 30 */ { 0, "accept" },
1047 /* 31 */ { 0, "getpeername" },
1048 /* 32 */ { 0, "getsockname" },
1049 /* 33 */ { 0, "access" },
1050 /* 34 */ { 0, "chflags" },
1051 /* 35 */ { 0, "fchflags" },
1052 /* 36 */ { 0, "sync" },
1053 /* 37 */ { do_kill, "kill" },
1054 { 0, }, /* 38 is old stat */
1055 /* 39 */ { 0, "getppid" },
1056 { 0, }, /* 40 is old lstat */
1057 /* 41 */ { do_dup, "dup" },
1058 /* 42 */ { 0, "pipe" },
1059 /* 43 */ { do_getegid, "getegid" },
1060 /* 44 */ { 0, "profil" },
1061 /* 45 */ { 0, "ktrace" },
1062 /* 46 */ { 0, "sigaction" },
1063 /* 47 */ { do_getgid, "getgid" },
1064 /* 48 */ { do_sigprocmask, "sigprocmask" },
1065 /* 49 */ { 0, "getlogin" },
1066 /* 50 */ { 0, "setlogin" },
1067 /* 51 */ { 0, "acct" },
1068 /* 52 */ { 0, "sigpending" },
1069 /* 53 */ { 0, "sigaltstack" },
1070 /* 54 */ { do_ioctl, "ioctl" },
1071 /* 55 */ { 0, "reboot" },
1072 /* 56 */ { 0, "revoke" },
1073 /* 57 */ { 0, "symlink" },
1074 /* 58 */ { 0, "readlink" },
1075 /* 59 */ { 0, "execve" },
1076 /* 60 */ { do_umask, "umask" },
1077 /* 61 */ { 0, "chroot" },
1078 { 0, }, /* 62 is old fstat */
1079 { 0, }, /* 63 is old getkerninfo */
1080 { 0, }, /* 64 is old getpagesize */
1081 /* 65 */ { 0, "msync" },
1082 /* 66 */ { 0, "vfork" },
1083 { 0, }, /* 67 is obsolete vread */
1084 { 0, }, /* 68 is obsolete vwrite */
1085 /* 69 */ { 0, "sbrk" },
1086 /* 70 */ { 0, "sstk" },
1087 { 0, }, /* 71 is old mmap */
1088 /* 72 */ { 0, "vadvise" },
1089 /* 73 */ { 0, "munmap" },
1090 /* 74 */ { 0, "mprotect" },
1091 /* 75 */ { 0, "madvise" },
1092 { 0, }, /* 76 is obsolete vhangup */
1093 { 0, }, /* 77 is obsolete vlimit */
1094 /* 78 */ { 0, "mincore" },
1095 /* 79 */ { 0, "getgroups" },
1096 /* 80 */ { 0, "setgroups" },
1097 /* 81 */ { 0, "getpgrp" },
1098 /* 82 */ { 0, "setpgid" },
1099 /* 83 */ { 0, "setitimer" },
1100 { 0, }, /* 84 is old wait */
1101 /* 85 */ { 0, "swapon" },
1102 /* 86 */ { 0, "getitimer" },
1103 { 0, }, /* 87 is old gethostname */
1104 { 0, }, /* 88 is old sethostname */
1105 { 0, }, /* 89 is old getdtablesize */
1106 { do_dup2, "dup2" },
1108 /* 92 */ { do_fcntl, "fcntl" },
1109 /* 93 */ { 0, "select" },
1111 /* 95 */ { 0, "fsync" },
1112 /* 96 */ { 0, "setpriority" },
1113 /* 97 */ { 0, "socket" },
1114 /* 98 */ { 0, "connect" },
1115 { 0, }, /* 99 is old accept */
1116 /* 100 */ { 0, "getpriority" },
1117 { 0, }, /* 101 is old send */
1118 { 0, }, /* 102 is old recv */
1119 /* 103 */ { 0, "sigreturn" },
1120 /* 104 */ { 0, "bind" },
1121 /* 105 */ { 0, "setsockopt" },
1122 /* 106 */ { 0, "listen" },
1123 { 0, }, /* 107 is obsolete vtimes */
1124 { 0, }, /* 108 is old sigvec */
1125 { 0, }, /* 109 is old sigblock */
1126 { 0, }, /* 110 is old sigsetmask */
1127 /* 111 */ { 0, "sigsuspend" },
1128 { 0, }, /* 112 is old sigstack */
1129 { 0, }, /* 113 is old recvmsg */
1130 { 0, }, /* 114 is old sendmsg */
1131 /* - is obsolete vtrace */ { 0, "vtrace 115" },
1132 /* 116 */ { do_gettimeofday, "gettimeofday" },
1133 /* 117 */ { do_getrusage, "getrusage" },
1134 /* 118 */ { 0, "getsockopt" },
1135 /* 119 */ { 0, "resuba" },
1136 /* 120 */ { 0, "readv" },
1137 /* 121 */ { 0, "writev" },
1138 /* 122 */ { 0, "settimeofday" },
1139 /* 123 */ { 0, "fchown" },
1140 /* 124 */ { 0, "fchmod" },
1141 { 0, }, /* 125 is old recvfrom */
1142 { 0, }, /* 126 is old setreuid */
1143 { 0, }, /* 127 is old setregid */
1144 /* 128 */ { 0, "rename" },
1145 { 0, }, /* 129 is old truncate */
1146 { 0, }, /* 130 is old ftruncate */
1147 /* 131 */ { 0, "flock" },
1148 /* 132 */ { 0, "mkfifo" },
1149 /* 133 */ { 0, "sendto" },
1150 /* 134 */ { 0, "shutdown" },
1151 /* 135 */ { 0, "socketpair" },
1152 /* 136 */ { 0, "mkdir" },
1153 /* 137 */ { 0, "rmdir" },
1154 /* 138 */ { 0, "utimes" },
1155 { 0, }, /* 139 is obsolete 4.2 sigreturn */
1156 /* 140 */ { 0, "adjtime" },
1157 { 0, }, /* 141 is old getpeername */
1158 { 0, }, /* 142 is old gethostid */
1159 { 0, }, /* 143 is old sethostid */
1160 { 0, }, /* 144 is old getrlimit */
1161 { 0, }, /* 145 is old setrlimit */
1162 { 0, }, /* 146 is old killpg */
1163 /* 147 */ { 0, "setsid" },
1164 /* 148 */ { 0, "quotactl" },
1165 { 0, }, /* 149 is old quota */
1166 { 0, }, /* 150 is old getsockname */
1171 /* 155 */ { 0, "nfssvc" },
1172 { 0, }, /* 156 is old getdirentries */
1173 /* 157 */ { 0, "statfs" },
1174 /* 158 */ { do_fstatfs, "fstatfs" },
1177 /* 161 */ { 0, "getfh" },
1178 { 0, }, /* 162 is old getdomainname */
1179 { 0, }, /* 163 is old setdomainname */
1180 { 0, }, /* 164 is old uname */
1181 /* 165 */ { 0, "sysarch" },
1185 /* 169 */ { 0, "semsys" },
1186 /* 170 */ { 0, "msgsys" },
1187 /* 171 */ { 0, "shmsys" },
1197 /* 181 */ { 0, "setgid" },
1198 /* 182 */ { 0, "setegid" },
1199 /* 183 */ { 0, "seteuid" },
1200 /* 184 */ { 0, "lfs_bmapv" },
1201 /* 185 */ { 0, "lfs_markv" },
1202 /* 186 */ { 0, "lfs_segclean" },
1203 /* 187 */ { 0, "lfs_segwait" },
1204 /* 188 */ { do_stat, "stat" },
1205 /* 189 */ { do_fstat, "fstat" },
1206 /* 190 */ { do_lstat, "lstat" },
1207 /* 191 */ { 0, "pathconf" },
1208 /* 192 */ { 0, "fpathconf" },
1210 /* 194 */ { 0, "getrlimit" },
1211 /* 195 */ { 0, "setrlimit" },
1212 /* 196 */ { do_getdirentries, "getdirentries" },
1213 /* 197 */ { 0, "mmap" },
1214 /* 198 */ { do___syscall, "__syscall" },
1215 /* 199 */ { do_lseek, "lseek" },
1216 /* 200 */ { 0, "truncate" },
1217 /* 201 */ { 0, "ftruncate" },
1218 /* 202 */ { do___sysctl, "__sysctl" },
1219 /* 203 */ { 0, "mlock" },
1220 /* 204 */ { 0, "munlock" },
1223 static char *(netbsd_error_names[]) = {
1260 /* 36 */ "EINPROGRESS",
1261 /* 37 */ "EALREADY",
1262 /* 38 */ "ENOTSOCK",
1263 /* 39 */ "EDESTADDRREQ",
1264 /* 40 */ "EMSGSIZE",
1265 /* 41 */ "EPROTOTYPE",
1266 /* 42 */ "ENOPROTOOPT",
1267 /* 43 */ "EPROTONOSUPPORT",
1268 /* 44 */ "ESOCKTNOSUPPORT",
1269 /* 45 */ "EOPNOTSUPP",
1270 /* 46 */ "EPFNOSUPPORT",
1271 /* 47 */ "EAFNOSUPPORT",
1272 /* 48 */ "EADDRINUSE",
1273 /* 49 */ "EADDRNOTAVAIL",
1274 /* 50 */ "ENETDOWN",
1275 /* 51 */ "ENETUNREACH",
1276 /* 52 */ "ENETRESET",
1277 /* 53 */ "ECONNABORTED",
1278 /* 54 */ "ECONNRESET",
1281 /* 57 */ "ENOTCONN",
1282 /* 58 */ "ESHUTDOWN",
1283 /* 59 */ "ETOOMANYREFS",
1284 /* 60 */ "ETIMEDOUT",
1285 /* 61 */ "ECONNREFUSED",
1287 /* 63 */ "ENAMETOOLONG",
1288 /* 64 */ "EHOSTDOWN",
1289 /* 65 */ "EHOSTUNREACH",
1290 /* 66 */ "ENOTEMPTY",
1291 /* 67 */ "EPROCLIM",
1297 /* 73 */ "ERPCMISMATCH",
1298 /* 74 */ "EPROGUNAVAIL",
1299 /* 75 */ "EPROGMISMATCH",
1300 /* 76 */ "EPROCUNAVAIL",
1305 /* 81 */ "ENEEDAUTH",
1309 static char *(netbsd_signal_names[]) = {
1336 /* 26 */ "SIGVTALRM",
1338 /* 28 */ "SIGWINCH",
1344 static emul_syscall emul_netbsd_syscalls = {
1346 sizeof(netbsd_descriptors) / sizeof(netbsd_descriptors[0]),
1348 sizeof(netbsd_error_names) / sizeof(netbsd_error_names[0]),
1349 netbsd_signal_names,
1350 sizeof(netbsd_signal_names) / sizeof(netbsd_signal_names[0]),
1354 /* NetBSD's os_emul interface, most are just passed on to the generic
1357 static os_emul_data *
1358 emul_netbsd_create(device *root,
1362 unsigned_word top_of_stack;
1363 unsigned stack_size;
1365 os_emul_data *bsd_data;
1368 /* check that this emulation is really for us */
1369 if (name != NULL && strcmp(name, "netbsd") != 0)
1375 /* merge any emulation specific entries into the device tree */
1377 /* establish a few defaults */
1378 if (image->xvec->flavour == bfd_target_elf_flavour) {
1380 top_of_stack = 0xe0000000;
1381 stack_size = 0x00100000;
1385 top_of_stack = 0x20000000;
1386 stack_size = 0x00100000;
1390 emul_add_tree_options(root, image, "netbsd",
1391 (WITH_ENVIRONMENT == USER_ENVIRONMENT
1392 ? "user" : "virtual"),
1393 0 /*oea-interrupt-prefix*/);
1395 /* virtual memory - handles growth of stack/heap */
1396 vm = tree_parse(root, "/openprom/vm");
1397 tree_parse(vm, "./stack-base 0x%lx",
1398 (unsigned long)(top_of_stack - stack_size));
1399 tree_parse(vm, "./nr-bytes 0x%x", stack_size);
1401 tree_parse(root, "/openprom/vm/map-binary/file-name %s",
1402 bfd_get_filename(image));
1404 /* finish the init */
1405 tree_parse(root, "/openprom/init/register/pc 0x%lx",
1406 (unsigned long)bfd_get_start_address(image));
1407 tree_parse(root, "/openprom/init/register/sp 0x%lx",
1408 (unsigned long)top_of_stack);
1409 tree_parse(root, "/openprom/init/register/msr 0x%x",
1410 ((tree_find_boolean_property(root, "/options/little-endian?")
1411 ? msr_little_endian_mode
1413 | (tree_find_boolean_property(root, "/openprom/options/floating-point?")
1414 ? (msr_floating_point_available
1415 | msr_floating_point_exception_mode_0
1416 | msr_floating_point_exception_mode_1)
1418 tree_parse(root, "/openprom/init/stack/stack-type %s",
1419 (elf_binary ? "ppc-elf" : "ppc-xcoff"));
1421 /* finally our emulation data */
1422 bsd_data = ZALLOC(os_emul_data);
1424 bsd_data->syscalls = &emul_netbsd_syscalls;
1429 emul_netbsd_init(os_emul_data *emul_data,
1436 emul_netbsd_system_call(cpu *processor,
1438 os_emul_data *emul_data)
1440 emul_do_system_call(emul_data,
1441 emul_data->syscalls,
1442 cpu_registers(processor)->gpr[0],
1443 3, /*r3 contains arg0*/
1448 const os_emul emul_netbsd = {
1452 emul_netbsd_system_call,
1453 0, /*instruction_call*/
1457 #endif _EMUL_NETBSD_C_