1 /* This file is part of the program psim.
3 Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef _EMUL_NETBSD_C_
23 #define _EMUL_NETBSD_C_
26 /* Note: this module is called via a table. There is no benefit in
29 #include "emul_generic.h"
30 #include "emul_netbsd.h"
40 #include <sys/types.h>
45 #include <sys/errno.h>
46 #include <sys/param.h>
50 #ifndef HAVE_SYS_RESOURCE_H
56 #include <sys/resource.h>
60 #include <sys/ioctl.h>
61 #include <sys/mount.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>
88 #define WITH_NetBSD_HOST (NetBSD >= 199306)
89 #if WITH_NetBSD_HOST /* here NetBSD as that is what we're emulating */
90 #include <sys/syscall.h> /* FIXME - should not be including this one */
91 #include <sys/sysctl.h>
92 extern int getdirentries(int fd
, char *buf
, int nbytes
, long *basep
);
95 #if (BSD < 199306) /* here BSD as just a bug */
99 #ifndef STATIC_INLINE_EMUL_NETBSD
100 #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
105 #define SYS(X) ASSERT(call == (SYS_##X))
110 #if WITH_NetBSD_HOST && (PATH_MAX != 1024)
111 #error "PATH_MAX not 1024"
112 #elif !defined(PATH_MAX)
113 #define PATH_MAX 1024
117 /* NetBSD's idea of what is needed to implement emulations */
119 struct _os_emul_data
{
121 emul_syscall
*syscalls
;
126 STATIC_INLINE_EMUL_NETBSD
void
127 write_stat(unsigned_word addr
,
141 /* H2T(buf.st_spare1); */
143 /* H2T(buf.st_spare2); */
145 /* H2T(buf.st_spare3); */
152 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
157 STATIC_INLINE_EMUL_NETBSD
void
158 write_statfs(unsigned_word addr
,
172 H2T(buf
.f_fsid
.val
[0]);
173 H2T(buf
.f_fsid
.val
[1]);
176 /* f_fstypename[MFSNAMELEN]; */
177 /* f_mntonname[MNAMELEN]; */
178 /* f_mntfromname[MNAMELEN]; */
179 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
184 STATIC_INLINE_EMUL_NETBSD
void
185 write_timeval(unsigned_word addr
,
192 emul_write_buffer(&t
, addr
, sizeof(t
), processor
, cia
);
196 STATIC_INLINE_EMUL_NETBSD
void
197 write_timezone(unsigned_word addr
,
202 H2T(tz
.tz_minuteswest
);
204 emul_write_buffer(&tz
, addr
, sizeof(tz
), processor
, cia
);
209 STATIC_INLINE_EMUL_NETBSD
void
210 write_direntries(unsigned_word addr
,
218 struct dirent
*in
= (struct dirent
*)buf
;
219 ASSERT(in
->d_reclen
<= nbytes
);
220 out
= (struct dirent
*)zalloc(in
->d_reclen
);
221 memcpy(out
/*dest*/, in
/*src*/, in
->d_reclen
);
226 emul_write_buffer(out
, addr
, in
->d_reclen
, processor
, cia
);
227 nbytes
-= in
->d_reclen
;
228 addr
+= in
->d_reclen
;
236 #ifdef HAVE_GETRUSAGE
237 STATIC_INLINE_EMUL_NETBSD
void
238 write_rusage(unsigned_word addr
,
239 struct rusage rusage
,
243 H2T(rusage
.ru_utime
.tv_sec
); /* user time used */
244 H2T(rusage
.ru_utime
.tv_usec
);
245 H2T(rusage
.ru_stime
.tv_sec
); /* system time used */
246 H2T(rusage
.ru_stime
.tv_usec
);
247 H2T(rusage
.ru_maxrss
); /* integral max resident set size */
248 H2T(rusage
.ru_ixrss
); /* integral shared text memory size */
249 H2T(rusage
.ru_idrss
); /* integral unshared data size */
250 H2T(rusage
.ru_isrss
); /* integral unshared stack size */
251 H2T(rusage
.ru_minflt
); /* page reclaims */
252 H2T(rusage
.ru_majflt
); /* page faults */
253 H2T(rusage
.ru_nswap
); /* swaps */
254 H2T(rusage
.ru_inblock
); /* block input operations */
255 H2T(rusage
.ru_oublock
); /* block output operations */
256 H2T(rusage
.ru_msgsnd
); /* messages sent */
257 H2T(rusage
.ru_msgrcv
); /* messages received */
258 H2T(rusage
.ru_nsignals
); /* signals received */
259 H2T(rusage
.ru_nvcsw
); /* voluntary context switches */
260 H2T(rusage
.ru_nivcsw
); /* involuntary context switches */
261 emul_write_buffer(&rusage
, addr
, sizeof(rusage
), processor
, cia
);
266 do_exit(os_emul_data
*emul
,
272 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
274 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
275 printf_filtered ("%d)\n", status
);
277 cpu_halt(processor
, cia
, was_exited
, status
);
282 do_read(os_emul_data
*emul
,
288 void *scratch_buffer
;
289 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
290 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
291 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
295 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
296 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
298 /* get a tempoary bufer */
299 scratch_buffer
= zalloc(nbytes
);
301 /* check if buffer exists by reading it */
302 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
307 status
= fread (scratch_buffer
, 1, nbytes
, stdin
);
308 if (status
== 0 && ferror (stdin
))
312 status
= read (d
, scratch_buffer
, nbytes
);
315 cpu_registers(processor
)->gpr
[0] = errno
;
317 cpu_registers(processor
)->gpr
[3] = status
;
320 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
323 zfree(scratch_buffer
);
328 do_write(os_emul_data
*emul
,
334 void *scratch_buffer
= NULL
;
336 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
337 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
338 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
342 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
343 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
345 /* get a tempoary bufer */
346 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
349 nr_moved
= vm_data_map_read_buffer(cpu_data_map(processor
),
353 if (nr_moved
!= nbytes
) {
354 /* FIXME - should handle better */
355 error("system_call()write copy failed (nr_moved=%d != nbytes=%d)\n",
360 status
= write(d
, scratch_buffer
, nbytes
);
361 emul_write_status(processor
, status
, errno
);
362 zfree(scratch_buffer
);
369 do_open(os_emul_data
*emul
,
375 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
376 char path_buf
[PATH_MAX
];
377 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
378 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
379 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
381 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
382 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
385 emul_write_status(processor
, open(path
, flags
, mode
), errno
);
390 do_close(os_emul_data
*emul
,
396 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
398 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
399 printf_filtered ("%d", d
);
402 emul_write_status(processor
, close(d
), errno
);
407 do_break(os_emul_data
*emul
,
413 /* just pass this onto the `vm' device */
414 psim
*system
= cpu_system(processor
);
416 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
417 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
420 device_ioctl(emul
->vm
,
425 NULL
); /*ioctl-data*/
430 do_getpid(os_emul_data
*emul
,
437 cpu_registers(processor
)->gpr
[3] = (int)getpid();
442 do_getuid(os_emul_data
*emul
,
449 cpu_registers(processor
)->gpr
[3] = (int)getuid();
454 do_geteuid(os_emul_data
*emul
,
461 cpu_registers(processor
)->gpr
[3] = (int)geteuid();
466 do_kill(os_emul_data
*emul
,
472 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
473 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
475 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
476 printf_filtered ("%d, %d", (int)pid
, sig
);
479 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
481 cpu_halt(processor
, cia
, was_signalled
, sig
);
486 do_dup(os_emul_data
*emul
,
492 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
493 int status
= dup(oldd
);
495 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
496 printf_filtered ("%d", oldd
);
499 emul_write_status(processor
, status
, errno
);
504 do_getegid(os_emul_data
*emul
,
511 cpu_registers(processor
)->gpr
[3] = (int)getegid();
516 do_getgid(os_emul_data
*emul
,
523 cpu_registers(processor
)->gpr
[3] = (int)getgid();
528 do_sigprocmask(os_emul_data
*emul
,
534 natural_word how
= cpu_registers(processor
)->gpr
[arg0
];
535 unsigned_word set
= cpu_registers(processor
)->gpr
[arg0
+1];
536 unsigned_word oset
= cpu_registers(processor
)->gpr
[arg0
+2];
539 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
540 printf_filtered ("%ld, 0x%ld, 0x%ld", (long)how
, (long)set
, (long)oset
);
542 cpu_registers(processor
)->gpr
[3] = 0;
543 cpu_registers(processor
)->gpr
[4] = set
;
548 do_ioctl(os_emul_data
*emul
,
554 int d
= cpu_registers(processor
)->gpr
[arg0
];
555 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
556 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
558 #if !WITH_NetBSD_HOST
559 cpu_registers(processor
)->gpr
[arg0
] = 0; /* just succeed */
561 unsigned dir
= request
& IOC_DIRMASK
;
564 /* what we haven't done */
565 if (dir
& IOC_IN
/* write into the io device */
567 || !(dir
& IOC_VOID
))
568 error("do_ioctl() read or write of parameter not implemented\n");
569 status
= ioctl(d
, request
, NULL
);
570 emul_write_status(processor
, status
, errno
);
573 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
574 printf_filtered ("%d, 0x%x, 0x%lx", d
, request
, (long)argp_addr
);
579 do_umask(os_emul_data
*emul
,
585 int mask
= cpu_registers(processor
)->gpr
[arg0
];
587 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
588 printf_filtered ("0%o", mask
);
591 cpu_registers(processor
)->gpr
[3] = umask(mask
);
596 do_dup2(os_emul_data
*emul
,
602 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
603 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
604 int status
= dup2(oldd
, newd
);
606 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
607 printf_filtered ("%d, %d", oldd
, newd
);
610 emul_write_status(processor
, status
, errno
);
615 do_fcntl(os_emul_data
*emul
,
621 int fd
= cpu_registers(processor
)->gpr
[arg0
];
622 int cmd
= cpu_registers(processor
)->gpr
[arg0
+1];
623 int arg
= cpu_registers(processor
)->gpr
[arg0
+2];
626 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
627 printf_filtered ("%d, %d, %d", fd
, cmd
, arg
);
630 status
= fcntl(fd
, cmd
, arg
);
631 emul_write_status(processor
, status
, errno
);
636 do_gettimeofday(os_emul_data
*emul
,
642 unsigned_word t_addr
= cpu_registers(processor
)->gpr
[arg0
];
643 unsigned_word tz_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
646 int status
= gettimeofday((t_addr
!= 0 ? &t
: NULL
),
647 (tz_addr
!= 0 ? &tz
: NULL
));
649 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
650 printf_filtered ("0x%lx, 0x%lx", (long)t_addr
, (long)tz_addr
);
653 emul_write_status(processor
, status
, errno
);
656 write_timeval(t_addr
, t
, processor
, cia
);
658 write_timezone(tz_addr
, tz
, processor
, cia
);
663 #ifndef HAVE_GETRUSAGE
664 #define do_getrusage 0
667 do_getrusage(os_emul_data
*emul
,
673 int who
= cpu_registers(processor
)->gpr
[arg0
];
674 unsigned_word rusage_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
675 struct rusage rusage
;
676 int status
= getrusage(who
, (rusage_addr
!= 0 ? &rusage
: NULL
));
678 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
679 printf_filtered ("%d, 0x%lx", who
, (long)rusage_addr
);
682 emul_write_status(processor
, status
, errno
);
684 if (rusage_addr
!= 0)
685 write_rusage(rusage_addr
, rusage
, processor
, cia
);
691 #if !WITH_NetBSD_HOST
695 do_fstatfs(os_emul_data
*emul
,
701 int fd
= cpu_registers(processor
)->gpr
[arg0
];
702 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
706 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
707 printf_filtered ("%d, 0x%lx", fd
, (long)buf_addr
);
710 status
= fstatfs(fd
, (buf_addr
== 0 ? NULL
: &buf
));
711 emul_write_status(processor
, status
, errno
);
714 write_statfs(buf_addr
, buf
, processor
, cia
);
721 do_stat(os_emul_data
*emul
,
727 char path_buf
[PATH_MAX
];
728 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
729 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
730 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
734 status
= stat(path
, &buf
);
735 emul_write_status(processor
, status
, errno
);
737 write_stat(stat_buf_addr
, buf
, processor
, cia
);
742 do_fstat(os_emul_data
*emul
,
748 int fd
= cpu_registers(processor
)->gpr
[arg0
];
749 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
752 emul_write_status(processor
, fstat(fd
, &buf
), errno
);
753 write_stat(stat_buf_addr
, buf
, processor
, cia
);
758 do_lstat(os_emul_data
*emul
,
764 char path_buf
[PATH_MAX
];
765 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
766 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
767 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
770 emul_write_status(processor
, stat(path
, &buf
), errno
);
771 write_stat(stat_buf_addr
, buf
, processor
, cia
);
775 #if !WITH_NetBSD_HOST
776 #define do_getdirentries 0
779 do_getdirentries(os_emul_data
*emul
,
785 int fd
= cpu_registers(processor
)->gpr
[arg0
];
786 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
788 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
789 unsigned_word basep_addr
= cpu_registers(processor
)->gpr
[arg0
+3];
793 if (buf_addr
!= 0 && nbytes
>= 0)
794 buf
= zalloc(nbytes
);
797 status
= getdirentries(fd
,
798 (buf_addr
== 0 ? NULL
: buf
),
800 (basep_addr
== 0 ? NULL
: &basep
));
801 emul_write_status(processor
, status
, errno
);
803 emul_write_word(basep_addr
, basep
, processor
, cia
);
805 write_direntries(buf_addr
, buf
, status
, processor
, cia
);
813 do___syscall(os_emul_data
*emul
,
820 emul_do_system_call(emul
,
822 cpu_registers(processor
)->gpr
[arg0
],
830 do_lseek(os_emul_data
*emul
,
836 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
837 off_t offset
= emul_read_gpr64(processor
, arg0
+2);
838 int whence
= cpu_registers(processor
)->gpr
[arg0
+4];
841 status
= lseek(fildes
, offset
, whence
);
843 emul_write_status(processor
, -1, errno
);
845 emul_write_gpr64(processor
, 3, status
);
851 do___sysctl(os_emul_data
*emul
,
857 /* call the arguments by their real name */
858 unsigned_word name
= cpu_registers(processor
)->gpr
[arg0
];
859 natural_word namelen
= cpu_registers(processor
)->gpr
[arg0
+1];
860 unsigned_word oldp
= cpu_registers(processor
)->gpr
[arg0
+2];
861 unsigned_word oldlenp
= cpu_registers(processor
)->gpr
[arg0
+3];
864 natural_word int_val
;
867 /* pluck out the management information base id */
869 error("system_call()SYS___sysctl bad name[0]\n");
870 mib
= vm_data_map_read_word(cpu_data_map(processor
),
876 /* see what to do with it ... */
879 #if WITH_NetBSD_HOST && (CTL_HW != 6)
883 error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
884 mib
= vm_data_map_read_word(cpu_data_map(processor
),
890 case 7/*HW_PAGESIZE*/:
891 #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
892 # error "HW_PAGESIZE"
894 oldlen
= vm_data_map_read_word(cpu_data_map(processor
),
898 if (sizeof(natural_word
) > oldlen
)
899 error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
901 oldlen
= sizeof(int_val
);
902 emul_write_word(oldp
, int_val
, processor
, cia
);
903 emul_write_word(oldlenp
, oldlen
, processor
, cia
);
906 error("sysctl() CTL_HW.%d unknown\n", mib
);
911 error("sysctl() name[0]=%d unknown\n", (int)mib
);
914 cpu_registers(processor
)->gpr
[3] = 0;
919 static emul_syscall_descriptor netbsd_descriptors
[] = {
920 /* 0 */ { 0, "syscall" },
921 /* 1 */ { do_exit
, "exit" },
922 /* 2 */ { 0, "fork" },
923 /* 3 */ { do_read
, "read" },
924 /* 4 */ { do_write
, "write" },
925 /* 5 */ { do_open
, "open" },
926 /* 6 */ { do_close
, "close" },
927 /* 7 */ { 0, "wait4" },
928 { 0, }, /* 8 is old creat */
929 /* 9 */ { 0, "link" },
930 /* 10 */ { 0, "unlink" },
931 { 0, }, /* 11 is obsolete execv */
932 /* 12 */ { 0, "chdir" },
933 /* 13 */ { 0, "fchdir" },
934 /* 14 */ { 0, "mknod" },
935 /* 15 */ { 0, "chmod" },
936 /* 16 */ { 0, "chown" },
937 /* 17 */ { do_break
, "break" },
938 /* 18 */ { 0, "getfsstat" },
939 { 0, }, /* 19 is old lseek */
940 /* 20 */ { do_getpid
, "getpid" },
941 /* 21 */ { 0, "mount" },
942 /* 22 */ { 0, "unmount" },
943 /* 23 */ { 0, "setuid" },
944 /* 24 */ { do_getuid
, "getuid" },
945 /* 25 */ { do_geteuid
, "geteuid" },
946 /* 26 */ { 0, "ptrace" },
947 /* 27 */ { 0, "recvmsg" },
948 /* 28 */ { 0, "sendmsg" },
949 /* 29 */ { 0, "recvfrom" },
950 /* 30 */ { 0, "accept" },
951 /* 31 */ { 0, "getpeername" },
952 /* 32 */ { 0, "getsockname" },
953 /* 33 */ { 0, "access" },
954 /* 34 */ { 0, "chflags" },
955 /* 35 */ { 0, "fchflags" },
956 /* 36 */ { 0, "sync" },
957 /* 37 */ { do_kill
, "kill" },
958 { 0, }, /* 38 is old stat */
959 /* 39 */ { 0, "getppid" },
960 { 0, }, /* 40 is old lstat */
961 /* 41 */ { do_dup
, "dup" },
962 /* 42 */ { 0, "pipe" },
963 /* 43 */ { do_getegid
, "getegid" },
964 /* 44 */ { 0, "profil" },
965 /* 45 */ { 0, "ktrace" },
966 /* 46 */ { 0, "sigaction" },
967 /* 47 */ { do_getgid
, "getgid" },
968 /* 48 */ { do_sigprocmask
, "sigprocmask" },
969 /* 49 */ { 0, "getlogin" },
970 /* 50 */ { 0, "setlogin" },
971 /* 51 */ { 0, "acct" },
972 /* 52 */ { 0, "sigpending" },
973 /* 53 */ { 0, "sigaltstack" },
974 /* 54 */ { do_ioctl
, "ioctl" },
975 /* 55 */ { 0, "reboot" },
976 /* 56 */ { 0, "revoke" },
977 /* 57 */ { 0, "symlink" },
978 /* 58 */ { 0, "readlink" },
979 /* 59 */ { 0, "execve" },
980 /* 60 */ { do_umask
, "umask" },
981 /* 61 */ { 0, "chroot" },
982 { 0, }, /* 62 is old fstat */
983 { 0, }, /* 63 is old getkerninfo */
984 { 0, }, /* 64 is old getpagesize */
985 /* 65 */ { 0, "msync" },
986 /* 66 */ { 0, "vfork" },
987 { 0, }, /* 67 is obsolete vread */
988 { 0, }, /* 68 is obsolete vwrite */
989 /* 69 */ { 0, "sbrk" },
990 /* 70 */ { 0, "sstk" },
991 { 0, }, /* 71 is old mmap */
992 /* 72 */ { 0, "vadvise" },
993 /* 73 */ { 0, "munmap" },
994 /* 74 */ { 0, "mprotect" },
995 /* 75 */ { 0, "madvise" },
996 { 0, }, /* 76 is obsolete vhangup */
997 { 0, }, /* 77 is obsolete vlimit */
998 /* 78 */ { 0, "mincore" },
999 /* 79 */ { 0, "getgroups" },
1000 /* 80 */ { 0, "setgroups" },
1001 /* 81 */ { 0, "getpgrp" },
1002 /* 82 */ { 0, "setpgid" },
1003 /* 83 */ { 0, "setitimer" },
1004 { 0, }, /* 84 is old wait */
1005 /* 85 */ { 0, "swapon" },
1006 /* 86 */ { 0, "getitimer" },
1007 { 0, }, /* 87 is old gethostname */
1008 { 0, }, /* 88 is old sethostname */
1009 { 0, }, /* 89 is old getdtablesize */
1010 { do_dup2
, "dup2" },
1012 /* 92 */ { do_fcntl
, "fcntl" },
1013 /* 93 */ { 0, "select" },
1015 /* 95 */ { 0, "fsync" },
1016 /* 96 */ { 0, "setpriority" },
1017 /* 97 */ { 0, "socket" },
1018 /* 98 */ { 0, "connect" },
1019 { 0, }, /* 99 is old accept */
1020 /* 100 */ { 0, "getpriority" },
1021 { 0, }, /* 101 is old send */
1022 { 0, }, /* 102 is old recv */
1023 /* 103 */ { 0, "sigreturn" },
1024 /* 104 */ { 0, "bind" },
1025 /* 105 */ { 0, "setsockopt" },
1026 /* 106 */ { 0, "listen" },
1027 { 0, }, /* 107 is obsolete vtimes */
1028 { 0, }, /* 108 is old sigvec */
1029 { 0, }, /* 109 is old sigblock */
1030 { 0, }, /* 110 is old sigsetmask */
1031 /* 111 */ { 0, "sigsuspend" },
1032 { 0, }, /* 112 is old sigstack */
1033 { 0, }, /* 113 is old recvmsg */
1034 { 0, }, /* 114 is old sendmsg */
1035 /* - is obsolete vtrace */ { 0, "vtrace 115" },
1036 /* 116 */ { do_gettimeofday
, "gettimeofday" },
1037 /* 117 */ { do_getrusage
, "getrusage" },
1038 /* 118 */ { 0, "getsockopt" },
1039 /* 119 */ { 0, "resuba" },
1040 /* 120 */ { 0, "readv" },
1041 /* 121 */ { 0, "writev" },
1042 /* 122 */ { 0, "settimeofday" },
1043 /* 123 */ { 0, "fchown" },
1044 /* 124 */ { 0, "fchmod" },
1045 { 0, }, /* 125 is old recvfrom */
1046 { 0, }, /* 126 is old setreuid */
1047 { 0, }, /* 127 is old setregid */
1048 /* 128 */ { 0, "rename" },
1049 { 0, }, /* 129 is old truncate */
1050 { 0, }, /* 130 is old ftruncate */
1051 /* 131 */ { 0, "flock" },
1052 /* 132 */ { 0, "mkfifo" },
1053 /* 133 */ { 0, "sendto" },
1054 /* 134 */ { 0, "shutdown" },
1055 /* 135 */ { 0, "socketpair" },
1056 /* 136 */ { 0, "mkdir" },
1057 /* 137 */ { 0, "rmdir" },
1058 /* 138 */ { 0, "utimes" },
1059 { 0, }, /* 139 is obsolete 4.2 sigreturn */
1060 /* 140 */ { 0, "adjtime" },
1061 { 0, }, /* 141 is old getpeername */
1062 { 0, }, /* 142 is old gethostid */
1063 { 0, }, /* 143 is old sethostid */
1064 { 0, }, /* 144 is old getrlimit */
1065 { 0, }, /* 145 is old setrlimit */
1066 { 0, }, /* 146 is old killpg */
1067 /* 147 */ { 0, "setsid" },
1068 /* 148 */ { 0, "quotactl" },
1069 { 0, }, /* 149 is old quota */
1070 { 0, }, /* 150 is old getsockname */
1075 /* 155 */ { 0, "nfssvc" },
1076 { 0, }, /* 156 is old getdirentries */
1077 /* 157 */ { 0, "statfs" },
1078 /* 158 */ { do_fstatfs
, "fstatfs" },
1081 /* 161 */ { 0, "getfh" },
1082 { 0, }, /* 162 is old getdomainname */
1083 { 0, }, /* 163 is old setdomainname */
1084 { 0, }, /* 164 is old uname */
1085 /* 165 */ { 0, "sysarch" },
1089 /* 169 */ { 0, "semsys" },
1090 /* 170 */ { 0, "msgsys" },
1091 /* 171 */ { 0, "shmsys" },
1101 /* 181 */ { 0, "setgid" },
1102 /* 182 */ { 0, "setegid" },
1103 /* 183 */ { 0, "seteuid" },
1104 /* 184 */ { 0, "lfs_bmapv" },
1105 /* 185 */ { 0, "lfs_markv" },
1106 /* 186 */ { 0, "lfs_segclean" },
1107 /* 187 */ { 0, "lfs_segwait" },
1108 /* 188 */ { do_stat
, "stat" },
1109 /* 189 */ { do_fstat
, "fstat" },
1110 /* 190 */ { do_lstat
, "lstat" },
1111 /* 191 */ { 0, "pathconf" },
1112 /* 192 */ { 0, "fpathconf" },
1114 /* 194 */ { 0, "getrlimit" },
1115 /* 195 */ { 0, "setrlimit" },
1116 /* 196 */ { do_getdirentries
, "getdirentries" },
1117 /* 197 */ { 0, "mmap" },
1118 /* 198 */ { do___syscall
, "__syscall" },
1119 /* 199 */ { do_lseek
, "lseek" },
1120 /* 200 */ { 0, "truncate" },
1121 /* 201 */ { 0, "ftruncate" },
1122 /* 202 */ { do___sysctl
, "__sysctl" },
1123 /* 203 */ { 0, "mlock" },
1124 /* 204 */ { 0, "munlock" },
1127 static char *(netbsd_error_names
[]) = {
1164 /* 36 */ "EINPROGRESS",
1165 /* 37 */ "EALREADY",
1166 /* 38 */ "ENOTSOCK",
1167 /* 39 */ "EDESTADDRREQ",
1168 /* 40 */ "EMSGSIZE",
1169 /* 41 */ "EPROTOTYPE",
1170 /* 42 */ "ENOPROTOOPT",
1171 /* 43 */ "EPROTONOSUPPORT",
1172 /* 44 */ "ESOCKTNOSUPPORT",
1173 /* 45 */ "EOPNOTSUPP",
1174 /* 46 */ "EPFNOSUPPORT",
1175 /* 47 */ "EAFNOSUPPORT",
1176 /* 48 */ "EADDRINUSE",
1177 /* 49 */ "EADDRNOTAVAIL",
1178 /* 50 */ "ENETDOWN",
1179 /* 51 */ "ENETUNREACH",
1180 /* 52 */ "ENETRESET",
1181 /* 53 */ "ECONNABORTED",
1182 /* 54 */ "ECONNRESET",
1185 /* 57 */ "ENOTCONN",
1186 /* 58 */ "ESHUTDOWN",
1187 /* 59 */ "ETOOMANYREFS",
1188 /* 60 */ "ETIMEDOUT",
1189 /* 61 */ "ECONNREFUSED",
1191 /* 63 */ "ENAMETOOLONG",
1192 /* 64 */ "EHOSTDOWN",
1193 /* 65 */ "EHOSTUNREACH",
1194 /* 66 */ "ENOTEMPTY",
1195 /* 67 */ "EPROCLIM",
1201 /* 73 */ "ERPCMISMATCH",
1202 /* 74 */ "EPROGUNAVAIL",
1203 /* 75 */ "EPROGMISMATCH",
1204 /* 76 */ "EPROCUNAVAIL",
1209 /* 81 */ "ENEEDAUTH",
1213 static char *(netbsd_signal_names
[]) = {
1240 /* 26 */ "SIGVTALRM",
1242 /* 28 */ "SIGWINCH",
1248 static emul_syscall emul_netbsd_syscalls
= {
1250 sizeof(netbsd_descriptors
) / sizeof(netbsd_descriptors
[0]),
1252 sizeof(netbsd_error_names
) / sizeof(netbsd_error_names
[0]),
1253 netbsd_signal_names
,
1254 sizeof(netbsd_signal_names
) / sizeof(netbsd_signal_names
[0]),
1258 /* NetBSD's os_emul interface, most are just passed on to the generic
1261 static os_emul_data
*
1262 emul_netbsd_create(device
*root
,
1266 unsigned_word top_of_stack
;
1267 unsigned stack_size
;
1269 os_emul_data
*bsd_data
;
1272 /* check that this emulation is really for us */
1273 if (name
!= NULL
&& strcmp(name
, "netbsd") != 0)
1279 /* merge any emulation specific entries into the device tree */
1281 /* establish a few defaults */
1282 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
1284 top_of_stack
= 0xe0000000;
1285 stack_size
= 0x00100000;
1289 top_of_stack
= 0x20000000;
1290 stack_size
= 0x00100000;
1294 emul_add_tree_options(root
, image
, "netbsd",
1295 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
1296 ? "user" : "virtual"),
1297 0 /*oea-interrupt-prefix*/);
1299 /* virtual memory - handles growth of stack/heap */
1300 vm
= device_tree_add_parsed(root
, "/openprom/vm@0x%lx",
1301 (unsigned long)(top_of_stack
- stack_size
));
1302 device_tree_add_parsed(vm
, "./stack-base 0x%lx",
1303 (unsigned long)(top_of_stack
- stack_size
));
1304 device_tree_add_parsed(vm
, "./nr-bytes 0x%x", stack_size
);
1306 device_tree_add_parsed(root
, "/openprom/vm/map-binary/file-name %s",
1307 bfd_get_filename(image
));
1309 /* finish the init */
1310 device_tree_add_parsed(root
, "/openprom/init/register/pc 0x%lx",
1311 (unsigned long)bfd_get_start_address(image
));
1312 device_tree_add_parsed(root
, "/openprom/init/register/sp 0x%lx",
1313 (unsigned long)top_of_stack
);
1314 device_tree_add_parsed(root
, "/openprom/init/register/msr 0x%x",
1315 (device_find_boolean_property(root
, "/options/little-endian?")
1316 ? msr_little_endian_mode
1318 device_tree_add_parsed(root
, "/openprom/init/stack/stack-type %s",
1319 (elf_binary
? "elf" : "xcoff"));
1321 /* finally our emulation data */
1322 bsd_data
= ZALLOC(os_emul_data
);
1324 bsd_data
->syscalls
= &emul_netbsd_syscalls
;
1329 emul_netbsd_init(os_emul_data
*emul_data
,
1336 emul_netbsd_system_call(cpu
*processor
,
1338 os_emul_data
*emul_data
)
1340 emul_do_system_call(emul_data
,
1341 emul_data
->syscalls
,
1342 cpu_registers(processor
)->gpr
[0],
1343 3, /*r3 contains arg0*/
1348 const os_emul emul_netbsd
= {
1352 emul_netbsd_system_call
,
1353 0, /*instruction_call*/
1357 #endif _EMUL_NETBSD_C_