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>
48 #include <sys/resource.h>
51 #include <sys/ioctl.h>
52 #include <sys/mount.h>
56 # define NAMLEN(dirent) strlen((dirent)->d_name)
58 # define dirent direct
59 # define NAMLEN(dirent) (dirent)->d_namlen
61 # include <sys/ndir.h>
79 #define WITH_NetBSD_HOST (NetBSD >= 199306)
80 #if WITH_NetBSD_HOST /* here NetBSD as that is what we're emulating */
81 #include <sys/syscall.h> /* FIXME - should not be including this one */
82 #include <sys/sysctl.h>
83 extern int getdirentries(int fd
, char *buf
, int nbytes
, long *basep
);
86 #if (BSD < 199306) /* here BSD as just a bug */
90 #ifndef STATIC_INLINE_EMUL_NETBSD
91 #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
96 #define SYS(X) ASSERT(call == (SYS_##X))
101 #if WITH_NetBSD_HOST && (PATH_MAX != 1024)
102 #error "PATH_MAX not 1024"
103 #elif !defined(PATH_MAX)
104 #define PATH_MAX 1024
108 /* NetBSD's idea of what is needed to implement emulations */
110 struct _os_emul_data
{
112 emul_syscall
*syscalls
;
117 STATIC_INLINE_EMUL_NETBSD
void
118 write_stat(unsigned_word addr
,
132 /* H2T(buf.st_spare1); */
134 /* H2T(buf.st_spare2); */
136 /* H2T(buf.st_spare3); */
143 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
148 STATIC_INLINE_EMUL_NETBSD
void
149 write_statfs(unsigned_word addr
,
163 H2T(buf
.f_fsid
.val
[0]);
164 H2T(buf
.f_fsid
.val
[1]);
167 /* f_fstypename[MFSNAMELEN]; */
168 /* f_mntonname[MNAMELEN]; */
169 /* f_mntfromname[MNAMELEN]; */
170 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
175 STATIC_INLINE_EMUL_NETBSD
void
176 write_timeval(unsigned_word addr
,
183 emul_write_buffer(&t
, addr
, sizeof(t
), processor
, cia
);
187 STATIC_INLINE_EMUL_NETBSD
void
188 write_timezone(unsigned_word addr
,
193 H2T(tz
.tz_minuteswest
);
195 emul_write_buffer(&tz
, addr
, sizeof(tz
), processor
, cia
);
200 STATIC_INLINE_EMUL_NETBSD
void
201 write_direntries(unsigned_word addr
,
209 struct dirent
*in
= (struct dirent
*)buf
;
210 ASSERT(in
->d_reclen
<= nbytes
);
211 out
= (struct dirent
*)zalloc(in
->d_reclen
);
212 memcpy(out
/*dest*/, in
/*src*/, in
->d_reclen
);
217 emul_write_buffer(out
, addr
, in
->d_reclen
, processor
, cia
);
218 nbytes
-= in
->d_reclen
;
219 addr
+= in
->d_reclen
;
227 STATIC_INLINE_EMUL_NETBSD
void
228 write_rusage(unsigned_word addr
,
229 struct rusage rusage
,
233 H2T(rusage
.ru_utime
.tv_sec
); /* user time used */
234 H2T(rusage
.ru_utime
.tv_usec
);
235 H2T(rusage
.ru_stime
.tv_sec
); /* system time used */
236 H2T(rusage
.ru_stime
.tv_usec
);
237 H2T(rusage
.ru_maxrss
); /* integral max resident set size */
238 H2T(rusage
.ru_ixrss
); /* integral shared text memory size */
239 H2T(rusage
.ru_idrss
); /* integral unshared data size */
240 H2T(rusage
.ru_isrss
); /* integral unshared stack size */
241 H2T(rusage
.ru_minflt
); /* page reclaims */
242 H2T(rusage
.ru_majflt
); /* page faults */
243 H2T(rusage
.ru_nswap
); /* swaps */
244 H2T(rusage
.ru_inblock
); /* block input operations */
245 H2T(rusage
.ru_oublock
); /* block output operations */
246 H2T(rusage
.ru_msgsnd
); /* messages sent */
247 H2T(rusage
.ru_msgrcv
); /* messages received */
248 H2T(rusage
.ru_nsignals
); /* signals received */
249 H2T(rusage
.ru_nvcsw
); /* voluntary context switches */
250 H2T(rusage
.ru_nivcsw
); /* involuntary context switches */
251 emul_write_buffer(&rusage
, addr
, sizeof(rusage
), processor
, cia
);
256 do_exit(os_emul_data
*emul
,
262 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
264 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
265 printf_filtered ("%d)\n", status
);
267 cpu_halt(processor
, cia
, was_exited
, status
);
272 do_read(os_emul_data
*emul
,
278 void *scratch_buffer
;
279 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
280 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
281 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
285 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
286 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
288 /* get a tempoary bufer */
289 scratch_buffer
= zalloc(nbytes
);
291 /* check if buffer exists by reading it */
292 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
297 status
= fread (scratch_buffer
, 1, nbytes
, stdin
);
298 if (status
== 0 && ferror (stdin
))
302 status
= read (d
, scratch_buffer
, nbytes
);
305 cpu_registers(processor
)->gpr
[0] = errno
;
307 cpu_registers(processor
)->gpr
[3] = status
;
310 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
313 zfree(scratch_buffer
);
318 do_write(os_emul_data
*emul
,
324 void *scratch_buffer
= NULL
;
326 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
327 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
328 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
332 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
333 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
335 /* get a tempoary bufer */
336 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
339 nr_moved
= vm_data_map_read_buffer(cpu_data_map(processor
),
343 if (nr_moved
!= nbytes
) {
344 /* FIXME - should handle better */
345 error("system_call()write copy failed (nr_moved=%d != nbytes=%d)\n",
350 status
= write(d
, scratch_buffer
, nbytes
);
351 emul_write_status(processor
, status
, errno
);
352 zfree(scratch_buffer
);
357 do_open(os_emul_data
*emul
,
363 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
364 char path_buf
[PATH_MAX
];
365 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
366 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
367 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
369 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
370 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
373 emul_write_status(processor
, open(path
, flags
, mode
), errno
);
378 do_close(os_emul_data
*emul
,
384 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
386 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
387 printf_filtered ("%d", d
);
390 emul_write_status(processor
, close(d
), errno
);
395 do_break(os_emul_data
*emul
,
401 /* just pass this onto the `vm' device */
402 psim
*system
= cpu_system(processor
);
404 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
405 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
408 device_ioctl(emul
->vm
,
413 NULL
); /*ioctl-data*/
418 do_getpid(os_emul_data
*emul
,
425 cpu_registers(processor
)->gpr
[3] = (int)getpid();
430 do_getuid(os_emul_data
*emul
,
437 cpu_registers(processor
)->gpr
[3] = (int)getuid();
442 do_geteuid(os_emul_data
*emul
,
449 cpu_registers(processor
)->gpr
[3] = (int)geteuid();
454 do_kill(os_emul_data
*emul
,
460 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
461 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
463 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
464 printf_filtered ("%d, %d", (int)pid
, sig
);
467 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
469 cpu_halt(processor
, cia
, was_signalled
, sig
);
474 do_dup(os_emul_data
*emul
,
480 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
481 int status
= dup(oldd
);
483 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
484 printf_filtered ("%d", oldd
);
487 emul_write_status(processor
, status
, errno
);
492 do_getegid(os_emul_data
*emul
,
499 cpu_registers(processor
)->gpr
[3] = (int)getegid();
504 do_getgid(os_emul_data
*emul
,
511 cpu_registers(processor
)->gpr
[3] = (int)getgid();
516 do_sigprocmask(os_emul_data
*emul
,
522 natural_word how
= cpu_registers(processor
)->gpr
[arg0
];
523 unsigned_word set
= cpu_registers(processor
)->gpr
[arg0
+1];
524 unsigned_word oset
= cpu_registers(processor
)->gpr
[arg0
+2];
527 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
528 printf_filtered ("%ld, 0x%ld, 0x%ld", (long)how
, (long)set
, (long)oset
);
530 cpu_registers(processor
)->gpr
[3] = 0;
531 cpu_registers(processor
)->gpr
[4] = set
;
536 do_ioctl(os_emul_data
*emul
,
542 int d
= cpu_registers(processor
)->gpr
[arg0
];
543 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
544 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
546 #if !WITH_NetBSD_HOST
547 cpu_registers(processor
)->gpr
[arg0
] = 0; /* just succeed */
549 unsigned dir
= request
& IOC_DIRMASK
;
552 /* what we haven't done */
553 if (dir
& IOC_IN
/* write into the io device */
555 || !(dir
& IOC_VOID
))
556 error("do_ioctl() read or write of parameter not implemented\n");
557 status
= ioctl(d
, request
, NULL
);
558 emul_write_status(processor
, status
, errno
);
561 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
562 printf_filtered ("%d, 0x%x, 0x%lx", d
, request
, (long)argp_addr
);
567 do_umask(os_emul_data
*emul
,
573 int mask
= cpu_registers(processor
)->gpr
[arg0
];
575 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
576 printf_filtered ("0%o", mask
);
579 cpu_registers(processor
)->gpr
[3] = umask(mask
);
584 do_dup2(os_emul_data
*emul
,
590 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
591 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
592 int status
= dup2(oldd
, newd
);
594 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
595 printf_filtered ("%d, %d", oldd
, newd
);
598 emul_write_status(processor
, status
, errno
);
603 do_fcntl(os_emul_data
*emul
,
609 int fd
= cpu_registers(processor
)->gpr
[arg0
];
610 int cmd
= cpu_registers(processor
)->gpr
[arg0
+1];
611 int arg
= cpu_registers(processor
)->gpr
[arg0
+2];
614 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
615 printf_filtered ("%d, %d, %d", fd
, cmd
, arg
);
618 status
= fcntl(fd
, cmd
, arg
);
619 emul_write_status(processor
, status
, errno
);
624 do_gettimeofday(os_emul_data
*emul
,
630 unsigned_word t_addr
= cpu_registers(processor
)->gpr
[arg0
];
631 unsigned_word tz_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
634 int status
= gettimeofday((t_addr
!= 0 ? &t
: NULL
),
635 (tz_addr
!= 0 ? &tz
: NULL
));
637 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
638 printf_filtered ("0x%lx, 0x%lx", (long)t_addr
, (long)tz_addr
);
641 emul_write_status(processor
, status
, errno
);
644 write_timeval(t_addr
, t
, processor
, cia
);
646 write_timezone(tz_addr
, tz
, processor
, cia
);
652 do_getrusage(os_emul_data
*emul
,
658 int who
= cpu_registers(processor
)->gpr
[arg0
];
659 unsigned_word rusage_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
660 struct rusage rusage
;
661 int status
= getrusage(who
, (rusage_addr
!= 0 ? &rusage
: NULL
));
663 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
664 printf_filtered ("%d, 0x%lx", who
, (long)rusage_addr
);
667 emul_write_status(processor
, status
, errno
);
669 if (rusage_addr
!= 0)
670 write_rusage(rusage_addr
, rusage
, processor
, cia
);
675 #if !WITH_NetBSD_HOST
679 do_fstatfs(os_emul_data
*emul
,
685 int fd
= cpu_registers(processor
)->gpr
[arg0
];
686 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
690 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
691 printf_filtered ("%d, 0x%lx", fd
, (long)buf_addr
);
694 status
= fstatfs(fd
, (buf_addr
== 0 ? NULL
: &buf
));
695 emul_write_status(processor
, status
, errno
);
698 write_statfs(buf_addr
, buf
, processor
, cia
);
705 do_stat(os_emul_data
*emul
,
711 char path_buf
[PATH_MAX
];
712 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
713 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
714 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
718 status
= stat(path
, &buf
);
719 emul_write_status(processor
, status
, errno
);
721 write_stat(stat_buf_addr
, buf
, processor
, cia
);
726 do_fstat(os_emul_data
*emul
,
732 int fd
= cpu_registers(processor
)->gpr
[arg0
];
733 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
736 emul_write_status(processor
, fstat(fd
, &buf
), errno
);
737 write_stat(stat_buf_addr
, buf
, processor
, cia
);
742 do_lstat(os_emul_data
*emul
,
748 char path_buf
[PATH_MAX
];
749 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
750 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
751 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
754 emul_write_status(processor
, stat(path
, &buf
), errno
);
755 write_stat(stat_buf_addr
, buf
, processor
, cia
);
759 #if !WITH_NetBSD_HOST
760 #define do_getdirentries 0
763 do_getdirentries(os_emul_data
*emul
,
769 int fd
= cpu_registers(processor
)->gpr
[arg0
];
770 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
772 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
773 unsigned_word basep_addr
= cpu_registers(processor
)->gpr
[arg0
+3];
777 if (buf_addr
!= 0 && nbytes
>= 0)
778 buf
= zalloc(nbytes
);
781 status
= getdirentries(fd
,
782 (buf_addr
== 0 ? NULL
: buf
),
784 (basep_addr
== 0 ? NULL
: &basep
));
785 emul_write_status(processor
, status
, errno
);
787 emul_write_word(basep_addr
, basep
, processor
, cia
);
789 write_direntries(buf_addr
, buf
, status
, processor
, cia
);
797 do___syscall(os_emul_data
*emul
,
804 emul_do_system_call(emul
,
806 cpu_registers(processor
)->gpr
[arg0
],
814 do_lseek(os_emul_data
*emul
,
820 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
821 off_t offset
= emul_read_gpr64(processor
, arg0
+2);
822 int whence
= cpu_registers(processor
)->gpr
[arg0
+4];
825 status
= lseek(fildes
, offset
, whence
);
827 emul_write_status(processor
, -1, errno
);
829 emul_write_gpr64(processor
, 3, status
);
835 do___sysctl(os_emul_data
*emul
,
841 /* call the arguments by their real name */
842 unsigned_word name
= cpu_registers(processor
)->gpr
[arg0
];
843 natural_word namelen
= cpu_registers(processor
)->gpr
[arg0
+1];
844 unsigned_word oldp
= cpu_registers(processor
)->gpr
[arg0
+2];
845 unsigned_word oldlenp
= cpu_registers(processor
)->gpr
[arg0
+3];
848 natural_word int_val
;
851 /* pluck out the management information base id */
853 error("system_call()SYS___sysctl bad name[0]\n");
854 mib
= vm_data_map_read_word(cpu_data_map(processor
),
860 /* see what to do with it ... */
863 #if WITH_NetBSD_HOST && (CTL_HW != 6)
867 error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
868 mib
= vm_data_map_read_word(cpu_data_map(processor
),
874 case 7/*HW_PAGESIZE*/:
875 #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
876 # error "HW_PAGESIZE"
878 oldlen
= vm_data_map_read_word(cpu_data_map(processor
),
882 if (sizeof(natural_word
) > oldlen
)
883 error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
885 oldlen
= sizeof(int_val
);
886 emul_write_word(oldp
, int_val
, processor
, cia
);
887 emul_write_word(oldlenp
, oldlen
, processor
, cia
);
890 error("sysctl() CTL_HW.%d unknown\n", mib
);
895 error("sysctl() name[0]=%d unknown\n", (int)mib
);
898 cpu_registers(processor
)->gpr
[3] = 0;
903 static emul_syscall_descriptor netbsd_descriptors
[] = {
904 /* 0 */ { 0, "syscall" },
905 /* 1 */ { do_exit
, "exit" },
906 /* 2 */ { 0, "fork" },
907 /* 3 */ { do_read
, "read" },
908 /* 4 */ { do_write
, "write" },
909 /* 5 */ { do_open
, "open" },
910 /* 6 */ { do_close
, "close" },
911 /* 7 */ { 0, "wait4" },
912 { 0, }, /* 8 is old creat */
913 /* 9 */ { 0, "link" },
914 /* 10 */ { 0, "unlink" },
915 { 0, }, /* 11 is obsolete execv */
916 /* 12 */ { 0, "chdir" },
917 /* 13 */ { 0, "fchdir" },
918 /* 14 */ { 0, "mknod" },
919 /* 15 */ { 0, "chmod" },
920 /* 16 */ { 0, "chown" },
921 /* 17 */ { do_break
, "break" },
922 /* 18 */ { 0, "getfsstat" },
923 { 0, }, /* 19 is old lseek */
924 /* 20 */ { do_getpid
, "getpid" },
925 /* 21 */ { 0, "mount" },
926 /* 22 */ { 0, "unmount" },
927 /* 23 */ { 0, "setuid" },
928 /* 24 */ { do_getuid
, "getuid" },
929 /* 25 */ { do_geteuid
, "geteuid" },
930 /* 26 */ { 0, "ptrace" },
931 /* 27 */ { 0, "recvmsg" },
932 /* 28 */ { 0, "sendmsg" },
933 /* 29 */ { 0, "recvfrom" },
934 /* 30 */ { 0, "accept" },
935 /* 31 */ { 0, "getpeername" },
936 /* 32 */ { 0, "getsockname" },
937 /* 33 */ { 0, "access" },
938 /* 34 */ { 0, "chflags" },
939 /* 35 */ { 0, "fchflags" },
940 /* 36 */ { 0, "sync" },
941 /* 37 */ { do_kill
, "kill" },
942 { 0, }, /* 38 is old stat */
943 /* 39 */ { 0, "getppid" },
944 { 0, }, /* 40 is old lstat */
945 /* 41 */ { do_dup
, "dup" },
946 /* 42 */ { 0, "pipe" },
947 /* 43 */ { do_getegid
, "getegid" },
948 /* 44 */ { 0, "profil" },
949 /* 45 */ { 0, "ktrace" },
950 /* 46 */ { 0, "sigaction" },
951 /* 47 */ { do_getgid
, "getgid" },
952 /* 48 */ { do_sigprocmask
, "sigprocmask" },
953 /* 49 */ { 0, "getlogin" },
954 /* 50 */ { 0, "setlogin" },
955 /* 51 */ { 0, "acct" },
956 /* 52 */ { 0, "sigpending" },
957 /* 53 */ { 0, "sigaltstack" },
958 /* 54 */ { do_ioctl
, "ioctl" },
959 /* 55 */ { 0, "reboot" },
960 /* 56 */ { 0, "revoke" },
961 /* 57 */ { 0, "symlink" },
962 /* 58 */ { 0, "readlink" },
963 /* 59 */ { 0, "execve" },
964 /* 60 */ { do_umask
, "umask" },
965 /* 61 */ { 0, "chroot" },
966 { 0, }, /* 62 is old fstat */
967 { 0, }, /* 63 is old getkerninfo */
968 { 0, }, /* 64 is old getpagesize */
969 /* 65 */ { 0, "msync" },
970 /* 66 */ { 0, "vfork" },
971 { 0, }, /* 67 is obsolete vread */
972 { 0, }, /* 68 is obsolete vwrite */
973 /* 69 */ { 0, "sbrk" },
974 /* 70 */ { 0, "sstk" },
975 { 0, }, /* 71 is old mmap */
976 /* 72 */ { 0, "vadvise" },
977 /* 73 */ { 0, "munmap" },
978 /* 74 */ { 0, "mprotect" },
979 /* 75 */ { 0, "madvise" },
980 { 0, }, /* 76 is obsolete vhangup */
981 { 0, }, /* 77 is obsolete vlimit */
982 /* 78 */ { 0, "mincore" },
983 /* 79 */ { 0, "getgroups" },
984 /* 80 */ { 0, "setgroups" },
985 /* 81 */ { 0, "getpgrp" },
986 /* 82 */ { 0, "setpgid" },
987 /* 83 */ { 0, "setitimer" },
988 { 0, }, /* 84 is old wait */
989 /* 85 */ { 0, "swapon" },
990 /* 86 */ { 0, "getitimer" },
991 { 0, }, /* 87 is old gethostname */
992 { 0, }, /* 88 is old sethostname */
993 { 0, }, /* 89 is old getdtablesize */
996 /* 92 */ { do_fcntl
, "fcntl" },
997 /* 93 */ { 0, "select" },
999 /* 95 */ { 0, "fsync" },
1000 /* 96 */ { 0, "setpriority" },
1001 /* 97 */ { 0, "socket" },
1002 /* 98 */ { 0, "connect" },
1003 { 0, }, /* 99 is old accept */
1004 /* 100 */ { 0, "getpriority" },
1005 { 0, }, /* 101 is old send */
1006 { 0, }, /* 102 is old recv */
1007 /* 103 */ { 0, "sigreturn" },
1008 /* 104 */ { 0, "bind" },
1009 /* 105 */ { 0, "setsockopt" },
1010 /* 106 */ { 0, "listen" },
1011 { 0, }, /* 107 is obsolete vtimes */
1012 { 0, }, /* 108 is old sigvec */
1013 { 0, }, /* 109 is old sigblock */
1014 { 0, }, /* 110 is old sigsetmask */
1015 /* 111 */ { 0, "sigsuspend" },
1016 { 0, }, /* 112 is old sigstack */
1017 { 0, }, /* 113 is old recvmsg */
1018 { 0, }, /* 114 is old sendmsg */
1019 /* - is obsolete vtrace */ { 0, "vtrace 115" },
1020 /* 116 */ { do_gettimeofday
, "gettimeofday" },
1021 /* 117 */ { do_getrusage
, "getrusage" },
1022 /* 118 */ { 0, "getsockopt" },
1023 /* 119 */ { 0, "resuba" },
1024 /* 120 */ { 0, "readv" },
1025 /* 121 */ { 0, "writev" },
1026 /* 122 */ { 0, "settimeofday" },
1027 /* 123 */ { 0, "fchown" },
1028 /* 124 */ { 0, "fchmod" },
1029 { 0, }, /* 125 is old recvfrom */
1030 { 0, }, /* 126 is old setreuid */
1031 { 0, }, /* 127 is old setregid */
1032 /* 128 */ { 0, "rename" },
1033 { 0, }, /* 129 is old truncate */
1034 { 0, }, /* 130 is old ftruncate */
1035 /* 131 */ { 0, "flock" },
1036 /* 132 */ { 0, "mkfifo" },
1037 /* 133 */ { 0, "sendto" },
1038 /* 134 */ { 0, "shutdown" },
1039 /* 135 */ { 0, "socketpair" },
1040 /* 136 */ { 0, "mkdir" },
1041 /* 137 */ { 0, "rmdir" },
1042 /* 138 */ { 0, "utimes" },
1043 { 0, }, /* 139 is obsolete 4.2 sigreturn */
1044 /* 140 */ { 0, "adjtime" },
1045 { 0, }, /* 141 is old getpeername */
1046 { 0, }, /* 142 is old gethostid */
1047 { 0, }, /* 143 is old sethostid */
1048 { 0, }, /* 144 is old getrlimit */
1049 { 0, }, /* 145 is old setrlimit */
1050 { 0, }, /* 146 is old killpg */
1051 /* 147 */ { 0, "setsid" },
1052 /* 148 */ { 0, "quotactl" },
1053 { 0, }, /* 149 is old quota */
1054 { 0, }, /* 150 is old getsockname */
1059 /* 155 */ { 0, "nfssvc" },
1060 { 0, }, /* 156 is old getdirentries */
1061 /* 157 */ { 0, "statfs" },
1062 /* 158 */ { do_fstatfs
, "fstatfs" },
1065 /* 161 */ { 0, "getfh" },
1066 { 0, }, /* 162 is old getdomainname */
1067 { 0, }, /* 163 is old setdomainname */
1068 { 0, }, /* 164 is old uname */
1069 /* 165 */ { 0, "sysarch" },
1073 /* 169 */ { 0, "semsys" },
1074 /* 170 */ { 0, "msgsys" },
1075 /* 171 */ { 0, "shmsys" },
1085 /* 181 */ { 0, "setgid" },
1086 /* 182 */ { 0, "setegid" },
1087 /* 183 */ { 0, "seteuid" },
1088 /* 184 */ { 0, "lfs_bmapv" },
1089 /* 185 */ { 0, "lfs_markv" },
1090 /* 186 */ { 0, "lfs_segclean" },
1091 /* 187 */ { 0, "lfs_segwait" },
1092 /* 188 */ { do_stat
, "stat" },
1093 /* 189 */ { do_fstat
, "fstat" },
1094 /* 190 */ { do_lstat
, "lstat" },
1095 /* 191 */ { 0, "pathconf" },
1096 /* 192 */ { 0, "fpathconf" },
1098 /* 194 */ { 0, "getrlimit" },
1099 /* 195 */ { 0, "setrlimit" },
1100 /* 196 */ { do_getdirentries
, "getdirentries" },
1101 /* 197 */ { 0, "mmap" },
1102 /* 198 */ { do___syscall
, "__syscall" },
1103 /* 199 */ { do_lseek
, "lseek" },
1104 /* 200 */ { 0, "truncate" },
1105 /* 201 */ { 0, "ftruncate" },
1106 /* 202 */ { do___sysctl
, "__sysctl" },
1107 /* 203 */ { 0, "mlock" },
1108 /* 204 */ { 0, "munlock" },
1111 static char *(netbsd_error_names
[]) = {
1148 /* 36 */ "EINPROGRESS",
1149 /* 37 */ "EALREADY",
1150 /* 38 */ "ENOTSOCK",
1151 /* 39 */ "EDESTADDRREQ",
1152 /* 40 */ "EMSGSIZE",
1153 /* 41 */ "EPROTOTYPE",
1154 /* 42 */ "ENOPROTOOPT",
1155 /* 43 */ "EPROTONOSUPPORT",
1156 /* 44 */ "ESOCKTNOSUPPORT",
1157 /* 45 */ "EOPNOTSUPP",
1158 /* 46 */ "EPFNOSUPPORT",
1159 /* 47 */ "EAFNOSUPPORT",
1160 /* 48 */ "EADDRINUSE",
1161 /* 49 */ "EADDRNOTAVAIL",
1162 /* 50 */ "ENETDOWN",
1163 /* 51 */ "ENETUNREACH",
1164 /* 52 */ "ENETRESET",
1165 /* 53 */ "ECONNABORTED",
1166 /* 54 */ "ECONNRESET",
1169 /* 57 */ "ENOTCONN",
1170 /* 58 */ "ESHUTDOWN",
1171 /* 59 */ "ETOOMANYREFS",
1172 /* 60 */ "ETIMEDOUT",
1173 /* 61 */ "ECONNREFUSED",
1175 /* 63 */ "ENAMETOOLONG",
1176 /* 64 */ "EHOSTDOWN",
1177 /* 65 */ "EHOSTUNREACH",
1178 /* 66 */ "ENOTEMPTY",
1179 /* 67 */ "EPROCLIM",
1185 /* 73 */ "ERPCMISMATCH",
1186 /* 74 */ "EPROGUNAVAIL",
1187 /* 75 */ "EPROGMISMATCH",
1188 /* 76 */ "EPROCUNAVAIL",
1193 /* 81 */ "ENEEDAUTH",
1197 static char *(netbsd_signal_names
[]) = {
1224 /* 26 */ "SIGVTALRM",
1226 /* 28 */ "SIGWINCH",
1232 static emul_syscall emul_netbsd_syscalls
= {
1234 sizeof(netbsd_descriptors
) / sizeof(netbsd_descriptors
[0]),
1236 sizeof(netbsd_error_names
) / sizeof(netbsd_error_names
[0]),
1237 netbsd_signal_names
,
1238 sizeof(netbsd_signal_names
) / sizeof(netbsd_signal_names
[0]),
1242 /* NetBSD's os_emul interface, most are just passed on to the generic
1245 static os_emul_data
*
1246 emul_netbsd_create(device
*root
,
1250 unsigned_word top_of_stack
;
1251 unsigned stack_size
;
1253 os_emul_data
*bsd_data
;
1256 /* check that this emulation is really for us */
1257 if (name
!= NULL
&& strcmp(name
, "netbsd") != 0)
1263 /* merge any emulation specific entries into the device tree */
1265 /* establish a few defaults */
1266 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
1268 top_of_stack
= 0xe0000000;
1269 stack_size
= 0x00100000;
1273 top_of_stack
= 0x20000000;
1274 stack_size
= 0x00100000;
1278 emul_add_tree_options(root
, image
, "netbsd",
1279 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
1280 ? "user" : "virtual"));
1282 /* virtual memory - handles growth of stack/heap */
1283 vm
= device_tree_add_parsed(root
, "/openprom/vm@0x%lx",
1284 (unsigned long)(top_of_stack
- stack_size
));
1285 device_tree_add_parsed(vm
, "./stack-base 0x%lx",
1286 (unsigned long)(top_of_stack
- stack_size
));
1287 device_tree_add_parsed(vm
, "./nr-bytes 0x%x", stack_size
);
1289 device_tree_add_parsed(root
, "/openprom/vm/map-binary/file-name %s",
1290 bfd_get_filename(image
));
1292 /* finish the init */
1293 device_tree_add_parsed(root
, "/openprom/init/register/pc 0x%lx",
1294 (unsigned long)bfd_get_start_address(image
));
1295 device_tree_add_parsed(root
, "/openprom/init/register/sp 0x%lx",
1296 (unsigned long)top_of_stack
);
1297 device_tree_add_parsed(root
, "/openprom/init/register/msr 0x%x",
1298 (device_find_boolean_property(root
, "/options/little-endian?")
1299 ? msr_little_endian_mode
1301 device_tree_add_parsed(root
, "/openprom/init/stack/stack-type %s",
1302 (elf_binary
? "elf" : "xcoff"));
1304 /* finally our emulation data */
1305 bsd_data
= ZALLOC(os_emul_data
);
1307 bsd_data
->syscalls
= &emul_netbsd_syscalls
;
1312 emul_netbsd_init(os_emul_data
*emul_data
,
1319 emul_netbsd_system_call(cpu
*processor
,
1321 os_emul_data
*emul_data
)
1323 emul_do_system_call(emul_data
,
1324 emul_data
->syscalls
,
1325 cpu_registers(processor
)->gpr
[0],
1326 3, /*r3 contains arg0*/
1331 const os_emul emul_netbsd
= {
1335 emul_netbsd_system_call
,
1336 0, /*instruction_call*/
1340 #endif _EMUL_NETBSD_C_