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>
61 #include <sys/ioctl.h>
65 #include <sys/mount.h>
70 # define NAMLEN(dirent) strlen((dirent)->d_name)
72 # define dirent direct
73 # define NAMLEN(dirent) (dirent)->d_namlen
75 # include <sys/ndir.h>
86 #undef MAXPATHLEN /* sys/param.h might define this also */
94 #define WITH_NetBSD_HOST (NetBSD >= 199306)
95 #if WITH_NetBSD_HOST /* here NetBSD as that is what we're emulating */
96 #include <sys/syscall.h> /* FIXME - should not be including this one */
97 #include <sys/sysctl.h>
98 extern int getdirentries(int fd
, char *buf
, int nbytes
, long *basep
);
101 /* If this is not netbsd, don't allow fstatfs or getdirentries at this time */
103 #undef HAVE_GETDIRENTRIES
106 #if (BSD < 199306) /* here BSD as just a bug */
110 #ifndef STATIC_INLINE_EMUL_NETBSD
111 #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
116 #define SYS(X) ASSERT(call == (SYS_##X))
121 #if WITH_NetBSD_HOST && (PATH_MAX != 1024)
122 #error "PATH_MAX not 1024"
123 #elif !defined(PATH_MAX)
124 #define PATH_MAX 1024
128 /* NetBSD's idea of what is needed to implement emulations */
130 struct _os_emul_data
{
132 emul_syscall
*syscalls
;
137 STATIC_INLINE_EMUL_NETBSD
void
138 write_stat(unsigned_word addr
,
151 /* H2T(buf.st_spare1); */
153 /* H2T(buf.st_spare2); */
155 /* H2T(buf.st_spare3); */
156 #ifdef AC_STRUCT_ST_RDEV
159 #ifdef AC_STRUCT_ST_BLKSIZE
162 #ifdef AC_STRUCT_ST_BLOCKS
169 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
174 STATIC_INLINE_EMUL_NETBSD
void
175 write_statfs(unsigned_word addr
,
189 H2T(buf
.f_fsid
.val
[0]);
190 H2T(buf
.f_fsid
.val
[1]);
193 /* f_fstypename[MFSNAMELEN]; */
194 /* f_mntonname[MNAMELEN]; */
195 /* f_mntfromname[MNAMELEN]; */
196 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
201 STATIC_INLINE_EMUL_NETBSD
void
202 write_timeval(unsigned_word addr
,
209 emul_write_buffer(&t
, addr
, sizeof(t
), processor
, cia
);
213 STATIC_INLINE_EMUL_NETBSD
void
214 write_timezone(unsigned_word addr
,
219 H2T(tz
.tz_minuteswest
);
221 emul_write_buffer(&tz
, addr
, sizeof(tz
), processor
, cia
);
225 #ifdef HAVE_GETDIRENTRIES
226 STATIC_INLINE_EMUL_NETBSD
void
227 write_direntries(unsigned_word addr
,
235 struct dirent
*in
= (struct dirent
*)buf
;
236 ASSERT(in
->d_reclen
<= nbytes
);
237 out
= (struct dirent
*)zalloc(in
->d_reclen
);
238 memcpy(out
/*dest*/, in
/*src*/, in
->d_reclen
);
243 emul_write_buffer(out
, addr
, in
->d_reclen
, processor
, cia
);
244 nbytes
-= in
->d_reclen
;
245 addr
+= in
->d_reclen
;
253 #ifdef HAVE_GETRUSAGE
254 STATIC_INLINE_EMUL_NETBSD
void
255 write_rusage(unsigned_word addr
,
256 struct rusage rusage
,
260 H2T(rusage
.ru_utime
.tv_sec
); /* user time used */
261 H2T(rusage
.ru_utime
.tv_usec
);
262 H2T(rusage
.ru_stime
.tv_sec
); /* system time used */
263 H2T(rusage
.ru_stime
.tv_usec
);
264 H2T(rusage
.ru_maxrss
); /* integral max resident set size */
265 H2T(rusage
.ru_ixrss
); /* integral shared text memory size */
266 H2T(rusage
.ru_idrss
); /* integral unshared data size */
267 H2T(rusage
.ru_isrss
); /* integral unshared stack size */
268 H2T(rusage
.ru_minflt
); /* page reclaims */
269 H2T(rusage
.ru_majflt
); /* page faults */
270 H2T(rusage
.ru_nswap
); /* swaps */
271 H2T(rusage
.ru_inblock
); /* block input operations */
272 H2T(rusage
.ru_oublock
); /* block output operations */
273 H2T(rusage
.ru_msgsnd
); /* messages sent */
274 H2T(rusage
.ru_msgrcv
); /* messages received */
275 H2T(rusage
.ru_nsignals
); /* signals received */
276 H2T(rusage
.ru_nvcsw
); /* voluntary context switches */
277 H2T(rusage
.ru_nivcsw
); /* involuntary context switches */
278 emul_write_buffer(&rusage
, addr
, sizeof(rusage
), processor
, cia
);
283 do_exit(os_emul_data
*emul
,
289 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
291 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
292 printf_filtered ("%d)\n", status
);
294 cpu_halt(processor
, cia
, was_exited
, status
);
299 do_read(os_emul_data
*emul
,
305 void *scratch_buffer
;
306 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
307 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
308 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
312 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
313 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
315 /* get a tempoary bufer */
316 scratch_buffer
= zalloc(nbytes
);
318 /* check if buffer exists by reading it */
319 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
324 status
= fread (scratch_buffer
, 1, nbytes
, stdin
);
325 if (status
== 0 && ferror (stdin
))
329 status
= read (d
, scratch_buffer
, nbytes
);
331 emul_write_status(processor
, status
, errno
);
333 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
335 zfree(scratch_buffer
);
340 do_write(os_emul_data
*emul
,
346 void *scratch_buffer
= NULL
;
348 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
349 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
350 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
354 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
355 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
357 /* get a tempoary bufer */
358 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
361 nr_moved
= vm_data_map_read_buffer(cpu_data_map(processor
),
365 if (nr_moved
!= nbytes
) {
366 /* FIXME - should handle better */
367 error("system_call()write copy failed (nr_moved=%d != nbytes=%d)\n",
372 status
= write(d
, scratch_buffer
, nbytes
);
373 emul_write_status(processor
, status
, errno
);
374 zfree(scratch_buffer
);
381 do_open(os_emul_data
*emul
,
387 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
388 char path_buf
[PATH_MAX
];
389 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
390 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
391 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
393 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
394 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
397 emul_write_status(processor
, open(path
, flags
, mode
), errno
);
402 do_close(os_emul_data
*emul
,
408 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
410 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
411 printf_filtered ("%d", d
);
414 emul_write_status(processor
, close(d
), errno
);
419 do_break(os_emul_data
*emul
,
425 /* just pass this onto the `vm' device */
426 psim
*system
= cpu_system(processor
);
427 unsigned_word new_break
= cpu_registers(processor
)->gpr
[arg0
];
430 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
431 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
434 status
= device_ioctl(emul
->vm
,
438 new_break
); /*ioctl-data*/
439 emul_write_status(processor
, 0, status
);
447 do_getpid(os_emul_data
*emul
,
454 emul_write_status(processor
, (int)getpid(), 0);
462 do_getuid(os_emul_data
*emul
,
469 emul_write_status(processor
, (int)getuid(), 0);
477 do_geteuid(os_emul_data
*emul
,
484 emul_write_status(processor
, (int)geteuid(), 0);
492 do_kill(os_emul_data
*emul
,
498 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
499 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
501 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
502 printf_filtered ("%d, %d", (int)pid
, sig
);
505 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
507 cpu_halt(processor
, cia
, was_signalled
, sig
);
515 do_dup(os_emul_data
*emul
,
521 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
522 int status
= dup(oldd
);
525 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
526 printf_filtered ("%d", oldd
);
529 emul_write_status(processor
, status
, err
);
537 do_getegid(os_emul_data
*emul
,
544 emul_write_status(processor
, (int)getegid(), 0);
552 do_getgid(os_emul_data
*emul
,
559 emul_write_status(processor
, (int)getgid(), 0);
563 #ifndef HAVE_SIGPROCMASK
564 #define do_sigprocmask 0
567 do_sigprocmask(os_emul_data
*emul
,
573 natural_word how
= cpu_registers(processor
)->gpr
[arg0
];
574 unsigned_word set
= cpu_registers(processor
)->gpr
[arg0
+1];
575 unsigned_word oset
= cpu_registers(processor
)->gpr
[arg0
+2];
578 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
579 printf_filtered ("%ld, 0x%ld, 0x%ld", (long)how
, (long)set
, (long)oset
);
581 emul_write_status(processor
, 0, 0);
582 cpu_registers(processor
)->gpr
[4] = set
;
590 do_ioctl(os_emul_data
*emul
,
596 int d
= cpu_registers(processor
)->gpr
[arg0
];
597 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
598 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
600 #if !WITH_NetBSD_HOST
601 cpu_registers(processor
)->gpr
[arg0
] = 0; /* just succeed */
603 unsigned dir
= request
& IOC_DIRMASK
;
606 /* what we haven't done */
607 if (dir
& IOC_IN
/* write into the io device */
609 || !(dir
& IOC_VOID
))
610 error("do_ioctl() read or write of parameter not implemented\n");
611 status
= ioctl(d
, request
, NULL
);
612 emul_write_status(processor
, status
, errno
);
615 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
616 printf_filtered ("%d, 0x%x, 0x%lx", d
, request
, (long)argp_addr
);
624 do_umask(os_emul_data
*emul
,
630 int mask
= cpu_registers(processor
)->gpr
[arg0
];
632 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
633 printf_filtered ("0%o", mask
);
636 emul_write_status(processor
, umask(mask
), 0);
644 do_dup2(os_emul_data
*emul
,
650 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
651 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
652 int status
= dup2(oldd
, newd
);
655 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
656 printf_filtered ("%d, %d", oldd
, newd
);
659 emul_write_status(processor
, status
, err
);
667 do_fcntl(os_emul_data
*emul
,
673 int fd
= cpu_registers(processor
)->gpr
[arg0
];
674 int cmd
= cpu_registers(processor
)->gpr
[arg0
+1];
675 int arg
= cpu_registers(processor
)->gpr
[arg0
+2];
678 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
679 printf_filtered ("%d, %d, %d", fd
, cmd
, arg
);
682 status
= fcntl(fd
, cmd
, arg
);
683 emul_write_status(processor
, status
, errno
);
687 #ifndef HAVE_GETTIMEOFDAY
688 #define do_gettimeofday 0
691 do_gettimeofday(os_emul_data
*emul
,
697 unsigned_word t_addr
= cpu_registers(processor
)->gpr
[arg0
];
698 unsigned_word tz_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
701 int status
= gettimeofday((t_addr
!= 0 ? &t
: NULL
),
702 (tz_addr
!= 0 ? &tz
: NULL
));
705 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
706 printf_filtered ("0x%lx, 0x%lx", (long)t_addr
, (long)tz_addr
);
709 emul_write_status(processor
, status
, err
);
712 write_timeval(t_addr
, t
, processor
, cia
);
714 write_timezone(tz_addr
, tz
, processor
, cia
);
719 #ifndef HAVE_GETRUSAGE
720 #define do_getrusage 0
723 do_getrusage(os_emul_data
*emul
,
729 int who
= cpu_registers(processor
)->gpr
[arg0
];
730 unsigned_word rusage_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
731 struct rusage rusage
;
732 int status
= getrusage(who
, (rusage_addr
!= 0 ? &rusage
: NULL
));
735 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
736 printf_filtered ("%d, 0x%lx", who
, (long)rusage_addr
);
739 emul_write_status(processor
, status
, err
);
741 if (rusage_addr
!= 0)
742 write_rusage(rusage_addr
, rusage
, processor
, cia
);
752 do_fstatfs(os_emul_data
*emul
,
758 int fd
= cpu_registers(processor
)->gpr
[arg0
];
759 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
763 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
764 printf_filtered ("%d, 0x%lx", fd
, (long)buf_addr
);
767 status
= fstatfs(fd
, (buf_addr
== 0 ? NULL
: &buf
));
768 emul_write_status(processor
, status
, errno
);
771 write_statfs(buf_addr
, buf
, processor
, cia
);
780 do_stat(os_emul_data
*emul
,
786 char path_buf
[PATH_MAX
];
787 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
788 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
789 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
793 status
= stat(path
, &buf
);
794 emul_write_status(processor
, status
, errno
);
796 write_stat(stat_buf_addr
, buf
, processor
, cia
);
804 do_fstat(os_emul_data
*emul
,
810 int fd
= cpu_registers(processor
)->gpr
[arg0
];
811 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
814 emul_write_status(processor
, fstat(fd
, &buf
), errno
);
815 write_stat(stat_buf_addr
, buf
, processor
, cia
);
823 do_lstat(os_emul_data
*emul
,
829 char path_buf
[PATH_MAX
];
830 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
831 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
832 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
835 emul_write_status(processor
, stat(path
, &buf
), errno
);
836 write_stat(stat_buf_addr
, buf
, processor
, cia
);
840 #ifndef HAVE_GETDIRENTRIES
841 #define do_getdirentries 0
844 do_getdirentries(os_emul_data
*emul
,
850 int fd
= cpu_registers(processor
)->gpr
[arg0
];
851 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
853 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
854 unsigned_word basep_addr
= cpu_registers(processor
)->gpr
[arg0
+3];
858 if (buf_addr
!= 0 && nbytes
>= 0)
859 buf
= zalloc(nbytes
);
862 status
= getdirentries(fd
,
863 (buf_addr
== 0 ? NULL
: buf
),
865 (basep_addr
== 0 ? NULL
: &basep
));
866 emul_write_status(processor
, status
, errno
);
868 emul_write_word(basep_addr
, basep
, processor
, cia
);
870 write_direntries(buf_addr
, buf
, status
, processor
, cia
);
878 do___syscall(os_emul_data
*emul
,
885 emul_do_system_call(emul
,
887 cpu_registers(processor
)->gpr
[arg0
],
897 do_lseek(os_emul_data
*emul
,
903 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
904 off_t offset
= emul_read_gpr64(processor
, arg0
+2);
905 int whence
= cpu_registers(processor
)->gpr
[arg0
+4];
908 status
= lseek(fildes
, offset
, whence
);
910 emul_write_status(processor
, -1, errno
);
912 emul_write_status(processor
, 0, 0); /* success */
913 emul_write_gpr64(processor
, 3, status
);
919 do___sysctl(os_emul_data
*emul
,
925 /* call the arguments by their real name */
926 unsigned_word name
= cpu_registers(processor
)->gpr
[arg0
];
927 natural_word namelen
= cpu_registers(processor
)->gpr
[arg0
+1];
928 unsigned_word oldp
= cpu_registers(processor
)->gpr
[arg0
+2];
929 unsigned_word oldlenp
= cpu_registers(processor
)->gpr
[arg0
+3];
932 natural_word int_val
;
935 /* pluck out the management information base id */
937 error("system_call()SYS___sysctl bad name[0]\n");
938 mib
= vm_data_map_read_word(cpu_data_map(processor
),
944 /* see what to do with it ... */
947 #if WITH_NetBSD_HOST && (CTL_HW != 6)
951 error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
952 mib
= vm_data_map_read_word(cpu_data_map(processor
),
958 case 7/*HW_PAGESIZE*/:
959 #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
960 # error "HW_PAGESIZE"
962 oldlen
= vm_data_map_read_word(cpu_data_map(processor
),
966 if (sizeof(natural_word
) > oldlen
)
967 error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
969 oldlen
= sizeof(int_val
);
970 emul_write_word(oldp
, int_val
, processor
, cia
);
971 emul_write_word(oldlenp
, oldlen
, processor
, cia
);
974 error("sysctl() CTL_HW.%d unknown\n", mib
);
979 error("sysctl() name[0]=%d unknown\n", (int)mib
);
982 emul_write_status(processor
, 0, 0); /* always succeed */
987 static emul_syscall_descriptor netbsd_descriptors
[] = {
988 /* 0 */ { 0, "syscall" },
989 /* 1 */ { do_exit
, "exit" },
990 /* 2 */ { 0, "fork" },
991 /* 3 */ { do_read
, "read" },
992 /* 4 */ { do_write
, "write" },
993 /* 5 */ { do_open
, "open" },
994 /* 6 */ { do_close
, "close" },
995 /* 7 */ { 0, "wait4" },
996 { 0, }, /* 8 is old creat */
997 /* 9 */ { 0, "link" },
998 /* 10 */ { 0, "unlink" },
999 { 0, }, /* 11 is obsolete execv */
1000 /* 12 */ { 0, "chdir" },
1001 /* 13 */ { 0, "fchdir" },
1002 /* 14 */ { 0, "mknod" },
1003 /* 15 */ { 0, "chmod" },
1004 /* 16 */ { 0, "chown" },
1005 /* 17 */ { do_break
, "break" },
1006 /* 18 */ { 0, "getfsstat" },
1007 { 0, }, /* 19 is old lseek */
1008 /* 20 */ { do_getpid
, "getpid" },
1009 /* 21 */ { 0, "mount" },
1010 /* 22 */ { 0, "unmount" },
1011 /* 23 */ { 0, "setuid" },
1012 /* 24 */ { do_getuid
, "getuid" },
1013 /* 25 */ { do_geteuid
, "geteuid" },
1014 /* 26 */ { 0, "ptrace" },
1015 /* 27 */ { 0, "recvmsg" },
1016 /* 28 */ { 0, "sendmsg" },
1017 /* 29 */ { 0, "recvfrom" },
1018 /* 30 */ { 0, "accept" },
1019 /* 31 */ { 0, "getpeername" },
1020 /* 32 */ { 0, "getsockname" },
1021 /* 33 */ { 0, "access" },
1022 /* 34 */ { 0, "chflags" },
1023 /* 35 */ { 0, "fchflags" },
1024 /* 36 */ { 0, "sync" },
1025 /* 37 */ { do_kill
, "kill" },
1026 { 0, }, /* 38 is old stat */
1027 /* 39 */ { 0, "getppid" },
1028 { 0, }, /* 40 is old lstat */
1029 /* 41 */ { do_dup
, "dup" },
1030 /* 42 */ { 0, "pipe" },
1031 /* 43 */ { do_getegid
, "getegid" },
1032 /* 44 */ { 0, "profil" },
1033 /* 45 */ { 0, "ktrace" },
1034 /* 46 */ { 0, "sigaction" },
1035 /* 47 */ { do_getgid
, "getgid" },
1036 /* 48 */ { do_sigprocmask
, "sigprocmask" },
1037 /* 49 */ { 0, "getlogin" },
1038 /* 50 */ { 0, "setlogin" },
1039 /* 51 */ { 0, "acct" },
1040 /* 52 */ { 0, "sigpending" },
1041 /* 53 */ { 0, "sigaltstack" },
1042 /* 54 */ { do_ioctl
, "ioctl" },
1043 /* 55 */ { 0, "reboot" },
1044 /* 56 */ { 0, "revoke" },
1045 /* 57 */ { 0, "symlink" },
1046 /* 58 */ { 0, "readlink" },
1047 /* 59 */ { 0, "execve" },
1048 /* 60 */ { do_umask
, "umask" },
1049 /* 61 */ { 0, "chroot" },
1050 { 0, }, /* 62 is old fstat */
1051 { 0, }, /* 63 is old getkerninfo */
1052 { 0, }, /* 64 is old getpagesize */
1053 /* 65 */ { 0, "msync" },
1054 /* 66 */ { 0, "vfork" },
1055 { 0, }, /* 67 is obsolete vread */
1056 { 0, }, /* 68 is obsolete vwrite */
1057 /* 69 */ { 0, "sbrk" },
1058 /* 70 */ { 0, "sstk" },
1059 { 0, }, /* 71 is old mmap */
1060 /* 72 */ { 0, "vadvise" },
1061 /* 73 */ { 0, "munmap" },
1062 /* 74 */ { 0, "mprotect" },
1063 /* 75 */ { 0, "madvise" },
1064 { 0, }, /* 76 is obsolete vhangup */
1065 { 0, }, /* 77 is obsolete vlimit */
1066 /* 78 */ { 0, "mincore" },
1067 /* 79 */ { 0, "getgroups" },
1068 /* 80 */ { 0, "setgroups" },
1069 /* 81 */ { 0, "getpgrp" },
1070 /* 82 */ { 0, "setpgid" },
1071 /* 83 */ { 0, "setitimer" },
1072 { 0, }, /* 84 is old wait */
1073 /* 85 */ { 0, "swapon" },
1074 /* 86 */ { 0, "getitimer" },
1075 { 0, }, /* 87 is old gethostname */
1076 { 0, }, /* 88 is old sethostname */
1077 { 0, }, /* 89 is old getdtablesize */
1078 { do_dup2
, "dup2" },
1080 /* 92 */ { do_fcntl
, "fcntl" },
1081 /* 93 */ { 0, "select" },
1083 /* 95 */ { 0, "fsync" },
1084 /* 96 */ { 0, "setpriority" },
1085 /* 97 */ { 0, "socket" },
1086 /* 98 */ { 0, "connect" },
1087 { 0, }, /* 99 is old accept */
1088 /* 100 */ { 0, "getpriority" },
1089 { 0, }, /* 101 is old send */
1090 { 0, }, /* 102 is old recv */
1091 /* 103 */ { 0, "sigreturn" },
1092 /* 104 */ { 0, "bind" },
1093 /* 105 */ { 0, "setsockopt" },
1094 /* 106 */ { 0, "listen" },
1095 { 0, }, /* 107 is obsolete vtimes */
1096 { 0, }, /* 108 is old sigvec */
1097 { 0, }, /* 109 is old sigblock */
1098 { 0, }, /* 110 is old sigsetmask */
1099 /* 111 */ { 0, "sigsuspend" },
1100 { 0, }, /* 112 is old sigstack */
1101 { 0, }, /* 113 is old recvmsg */
1102 { 0, }, /* 114 is old sendmsg */
1103 /* - is obsolete vtrace */ { 0, "vtrace 115" },
1104 /* 116 */ { do_gettimeofday
, "gettimeofday" },
1105 /* 117 */ { do_getrusage
, "getrusage" },
1106 /* 118 */ { 0, "getsockopt" },
1107 /* 119 */ { 0, "resuba" },
1108 /* 120 */ { 0, "readv" },
1109 /* 121 */ { 0, "writev" },
1110 /* 122 */ { 0, "settimeofday" },
1111 /* 123 */ { 0, "fchown" },
1112 /* 124 */ { 0, "fchmod" },
1113 { 0, }, /* 125 is old recvfrom */
1114 { 0, }, /* 126 is old setreuid */
1115 { 0, }, /* 127 is old setregid */
1116 /* 128 */ { 0, "rename" },
1117 { 0, }, /* 129 is old truncate */
1118 { 0, }, /* 130 is old ftruncate */
1119 /* 131 */ { 0, "flock" },
1120 /* 132 */ { 0, "mkfifo" },
1121 /* 133 */ { 0, "sendto" },
1122 /* 134 */ { 0, "shutdown" },
1123 /* 135 */ { 0, "socketpair" },
1124 /* 136 */ { 0, "mkdir" },
1125 /* 137 */ { 0, "rmdir" },
1126 /* 138 */ { 0, "utimes" },
1127 { 0, }, /* 139 is obsolete 4.2 sigreturn */
1128 /* 140 */ { 0, "adjtime" },
1129 { 0, }, /* 141 is old getpeername */
1130 { 0, }, /* 142 is old gethostid */
1131 { 0, }, /* 143 is old sethostid */
1132 { 0, }, /* 144 is old getrlimit */
1133 { 0, }, /* 145 is old setrlimit */
1134 { 0, }, /* 146 is old killpg */
1135 /* 147 */ { 0, "setsid" },
1136 /* 148 */ { 0, "quotactl" },
1137 { 0, }, /* 149 is old quota */
1138 { 0, }, /* 150 is old getsockname */
1143 /* 155 */ { 0, "nfssvc" },
1144 { 0, }, /* 156 is old getdirentries */
1145 /* 157 */ { 0, "statfs" },
1146 /* 158 */ { do_fstatfs
, "fstatfs" },
1149 /* 161 */ { 0, "getfh" },
1150 { 0, }, /* 162 is old getdomainname */
1151 { 0, }, /* 163 is old setdomainname */
1152 { 0, }, /* 164 is old uname */
1153 /* 165 */ { 0, "sysarch" },
1157 /* 169 */ { 0, "semsys" },
1158 /* 170 */ { 0, "msgsys" },
1159 /* 171 */ { 0, "shmsys" },
1169 /* 181 */ { 0, "setgid" },
1170 /* 182 */ { 0, "setegid" },
1171 /* 183 */ { 0, "seteuid" },
1172 /* 184 */ { 0, "lfs_bmapv" },
1173 /* 185 */ { 0, "lfs_markv" },
1174 /* 186 */ { 0, "lfs_segclean" },
1175 /* 187 */ { 0, "lfs_segwait" },
1176 /* 188 */ { do_stat
, "stat" },
1177 /* 189 */ { do_fstat
, "fstat" },
1178 /* 190 */ { do_lstat
, "lstat" },
1179 /* 191 */ { 0, "pathconf" },
1180 /* 192 */ { 0, "fpathconf" },
1182 /* 194 */ { 0, "getrlimit" },
1183 /* 195 */ { 0, "setrlimit" },
1184 /* 196 */ { do_getdirentries
, "getdirentries" },
1185 /* 197 */ { 0, "mmap" },
1186 /* 198 */ { do___syscall
, "__syscall" },
1187 /* 199 */ { do_lseek
, "lseek" },
1188 /* 200 */ { 0, "truncate" },
1189 /* 201 */ { 0, "ftruncate" },
1190 /* 202 */ { do___sysctl
, "__sysctl" },
1191 /* 203 */ { 0, "mlock" },
1192 /* 204 */ { 0, "munlock" },
1195 static char *(netbsd_error_names
[]) = {
1232 /* 36 */ "EINPROGRESS",
1233 /* 37 */ "EALREADY",
1234 /* 38 */ "ENOTSOCK",
1235 /* 39 */ "EDESTADDRREQ",
1236 /* 40 */ "EMSGSIZE",
1237 /* 41 */ "EPROTOTYPE",
1238 /* 42 */ "ENOPROTOOPT",
1239 /* 43 */ "EPROTONOSUPPORT",
1240 /* 44 */ "ESOCKTNOSUPPORT",
1241 /* 45 */ "EOPNOTSUPP",
1242 /* 46 */ "EPFNOSUPPORT",
1243 /* 47 */ "EAFNOSUPPORT",
1244 /* 48 */ "EADDRINUSE",
1245 /* 49 */ "EADDRNOTAVAIL",
1246 /* 50 */ "ENETDOWN",
1247 /* 51 */ "ENETUNREACH",
1248 /* 52 */ "ENETRESET",
1249 /* 53 */ "ECONNABORTED",
1250 /* 54 */ "ECONNRESET",
1253 /* 57 */ "ENOTCONN",
1254 /* 58 */ "ESHUTDOWN",
1255 /* 59 */ "ETOOMANYREFS",
1256 /* 60 */ "ETIMEDOUT",
1257 /* 61 */ "ECONNREFUSED",
1259 /* 63 */ "ENAMETOOLONG",
1260 /* 64 */ "EHOSTDOWN",
1261 /* 65 */ "EHOSTUNREACH",
1262 /* 66 */ "ENOTEMPTY",
1263 /* 67 */ "EPROCLIM",
1269 /* 73 */ "ERPCMISMATCH",
1270 /* 74 */ "EPROGUNAVAIL",
1271 /* 75 */ "EPROGMISMATCH",
1272 /* 76 */ "EPROCUNAVAIL",
1277 /* 81 */ "ENEEDAUTH",
1281 static char *(netbsd_signal_names
[]) = {
1308 /* 26 */ "SIGVTALRM",
1310 /* 28 */ "SIGWINCH",
1316 static emul_syscall emul_netbsd_syscalls
= {
1318 sizeof(netbsd_descriptors
) / sizeof(netbsd_descriptors
[0]),
1320 sizeof(netbsd_error_names
) / sizeof(netbsd_error_names
[0]),
1321 netbsd_signal_names
,
1322 sizeof(netbsd_signal_names
) / sizeof(netbsd_signal_names
[0]),
1326 /* NetBSD's os_emul interface, most are just passed on to the generic
1329 static os_emul_data
*
1330 emul_netbsd_create(device
*root
,
1334 unsigned_word top_of_stack
;
1335 unsigned stack_size
;
1337 os_emul_data
*bsd_data
;
1340 /* check that this emulation is really for us */
1341 if (name
!= NULL
&& strcmp(name
, "netbsd") != 0)
1347 /* merge any emulation specific entries into the device tree */
1349 /* establish a few defaults */
1350 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
1352 top_of_stack
= 0xe0000000;
1353 stack_size
= 0x00100000;
1357 top_of_stack
= 0x20000000;
1358 stack_size
= 0x00100000;
1362 emul_add_tree_options(root
, image
, "netbsd",
1363 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
1364 ? "user" : "virtual"),
1365 0 /*oea-interrupt-prefix*/);
1367 /* virtual memory - handles growth of stack/heap */
1368 vm
= device_tree_add_parsed(root
, "/openprom/vm@0x%lx",
1369 (unsigned long)(top_of_stack
- stack_size
));
1370 device_tree_add_parsed(vm
, "./stack-base 0x%lx",
1371 (unsigned long)(top_of_stack
- stack_size
));
1372 device_tree_add_parsed(vm
, "./nr-bytes 0x%x", stack_size
);
1374 device_tree_add_parsed(root
, "/openprom/vm/map-binary/file-name %s",
1375 bfd_get_filename(image
));
1377 /* finish the init */
1378 device_tree_add_parsed(root
, "/openprom/init/register/pc 0x%lx",
1379 (unsigned long)bfd_get_start_address(image
));
1380 device_tree_add_parsed(root
, "/openprom/init/register/sp 0x%lx",
1381 (unsigned long)top_of_stack
);
1382 device_tree_add_parsed(root
, "/openprom/init/register/msr 0x%x",
1383 (device_find_boolean_property(root
, "/options/little-endian?")
1384 ? msr_little_endian_mode
1386 device_tree_add_parsed(root
, "/openprom/init/stack/stack-type %s",
1387 (elf_binary
? "elf" : "xcoff"));
1389 /* finally our emulation data */
1390 bsd_data
= ZALLOC(os_emul_data
);
1392 bsd_data
->syscalls
= &emul_netbsd_syscalls
;
1397 emul_netbsd_init(os_emul_data
*emul_data
,
1404 emul_netbsd_system_call(cpu
*processor
,
1406 os_emul_data
*emul_data
)
1408 emul_do_system_call(emul_data
,
1409 emul_data
->syscalls
,
1410 cpu_registers(processor
)->gpr
[0],
1411 3, /*r3 contains arg0*/
1416 const os_emul emul_netbsd
= {
1420 emul_netbsd_system_call
,
1421 0, /*instruction_call*/
1425 #endif /* _EMUL_NETBSD_C_ */