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 3 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, see <http://www.gnu.org/licenses/>.
21 #ifndef _EMUL_NETBSD_C_
22 #define _EMUL_NETBSD_C_
25 /* Note: this module is called via a table. There is no benefit in
28 #include "emul_generic.h"
29 #include "emul_netbsd.h"
39 #include <sys/types.h>
45 #include <sys/param.h>
49 #ifndef HAVE_SYS_RESOURCE_H
55 #include <sys/resource.h>
60 #include <sys/ioctl.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>
81 #undef MAXPATHLEN /* sys/param.h might define this also */
89 #define WITH_NetBSD_HOST (NetBSD >= 199306)
90 #if WITH_NetBSD_HOST /* here NetBSD as that is what we're emulating */
91 #include <sys/syscall.h> /* FIXME - should not be including this one */
92 #include <sys/sysctl.h>
93 #include <sys/mount.h>
94 extern int getdirentries(int fd
, char *buf
, int nbytes
, long *basep
);
96 /* NetBSD post 2.0 has the statfs system call (if COMPAT_20), but does
97 not have struct statfs. In this case don't implement fstatfs.
98 FIXME: Should implement fstatvfs. */
99 #ifndef HAVE_STRUCT_STATFS
105 /* If this is not netbsd, don't allow fstatfs or getdirentries at this time */
107 #undef HAVE_GETDIRENTRIES
110 #if (BSD < 199306) /* here BSD as just a bug */
114 #ifndef STATIC_INLINE_EMUL_NETBSD
115 #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
120 #define SYS(X) ASSERT(call == (SYS_##X))
125 #if WITH_NetBSD_HOST && (PATH_MAX != 1024)
126 #error "PATH_MAX not 1024"
127 #elif !defined(PATH_MAX)
128 #define PATH_MAX 1024
134 NetBSD - Emulation of user programs for NetBSD/PPC
141 /* NetBSD's idea of what is needed to implement emulations */
143 struct _os_emul_data
{
145 emul_syscall
*syscalls
;
150 STATIC_INLINE_EMUL_NETBSD
void
151 write_stat(unsigned_word addr
,
164 /* H2T(buf.st_spare1); */
166 /* H2T(buf.st_spare2); */
168 /* H2T(buf.st_spare3); */
169 #ifdef AC_STRUCT_ST_RDEV
172 #ifdef AC_STRUCT_ST_BLKSIZE
175 #ifdef AC_STRUCT_ST_BLOCKS
182 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
187 STATIC_INLINE_EMUL_NETBSD
void
188 write_statfs(unsigned_word addr
,
202 H2T(buf
.f_fsid
.val
[0]);
203 H2T(buf
.f_fsid
.val
[1]);
206 /* f_fstypename[MFSNAMELEN]; */
207 /* f_mntonname[MNAMELEN]; */
208 /* f_mntfromname[MNAMELEN]; */
209 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
214 STATIC_INLINE_EMUL_NETBSD
void
215 write_timeval(unsigned_word addr
,
222 emul_write_buffer(&t
, addr
, sizeof(t
), processor
, cia
);
225 #ifdef HAVE_GETTIMEOFDAY
226 STATIC_INLINE_EMUL_NETBSD
void
227 write_timezone(unsigned_word addr
,
232 H2T(tz
.tz_minuteswest
);
234 emul_write_buffer(&tz
, addr
, sizeof(tz
), processor
, cia
);
238 #ifdef HAVE_GETDIRENTRIES
239 STATIC_INLINE_EMUL_NETBSD
void
240 write_direntries(unsigned_word addr
,
248 struct dirent
*in
= (struct dirent
*)buf
;
249 ASSERT(in
->d_reclen
<= nbytes
);
250 out
= (struct dirent
*)zalloc(in
->d_reclen
);
251 memcpy(out
/*dest*/, in
/*src*/, in
->d_reclen
);
256 emul_write_buffer(out
, addr
, in
->d_reclen
, processor
, cia
);
257 nbytes
-= in
->d_reclen
;
258 addr
+= in
->d_reclen
;
266 #ifdef HAVE_GETRUSAGE
267 STATIC_INLINE_EMUL_NETBSD
void
268 write_rusage(unsigned_word addr
,
269 struct rusage rusage
,
273 H2T(rusage
.ru_utime
.tv_sec
); /* user time used */
274 H2T(rusage
.ru_utime
.tv_usec
);
275 H2T(rusage
.ru_stime
.tv_sec
); /* system time used */
276 H2T(rusage
.ru_stime
.tv_usec
);
277 H2T(rusage
.ru_maxrss
); /* integral max resident set size */
278 H2T(rusage
.ru_ixrss
); /* integral shared text memory size */
279 H2T(rusage
.ru_idrss
); /* integral unshared data size */
280 H2T(rusage
.ru_isrss
); /* integral unshared stack size */
281 H2T(rusage
.ru_minflt
); /* page reclaims */
282 H2T(rusage
.ru_majflt
); /* page faults */
283 H2T(rusage
.ru_nswap
); /* swaps */
284 H2T(rusage
.ru_inblock
); /* block input operations */
285 H2T(rusage
.ru_oublock
); /* block output operations */
286 H2T(rusage
.ru_msgsnd
); /* messages sent */
287 H2T(rusage
.ru_msgrcv
); /* messages received */
288 H2T(rusage
.ru_nsignals
); /* signals received */
289 H2T(rusage
.ru_nvcsw
); /* voluntary context switches */
290 H2T(rusage
.ru_nivcsw
); /* involuntary context switches */
291 emul_write_buffer(&rusage
, addr
, sizeof(rusage
), processor
, cia
);
296 /* File descriptors 0, 1, and 2 should not be closed. fd_closed[]
297 tracks whether these descriptors have been closed in do_close()
300 static int fd_closed
[3];
302 /* Check for some occurrences of bad file descriptors. We only check
303 whether fd 0, 1, or 2 are "closed". By "closed" we mean that these
304 descriptors aren't actually closed, but are considered to be closed
307 Other checks are performed by the underlying OS call. */
312 if (fd
>=0 && fd
<= 2 && fd_closed
[fd
])
321 do_exit(os_emul_data
*emul
,
327 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
329 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
330 printf_filtered ("%d)\n", status
);
332 cpu_halt(processor
, cia
, was_exited
, status
);
337 do_read(os_emul_data
*emul
,
343 void *scratch_buffer
;
344 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
345 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
346 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
350 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
351 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
353 /* get a tempoary bufer */
354 scratch_buffer
= zalloc(nbytes
);
356 /* check if buffer exists by reading it */
357 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
362 status
= fread (scratch_buffer
, 1, nbytes
, stdin
);
363 if (status
== 0 && ferror (stdin
))
369 status
= read (d
, scratch_buffer
, nbytes
);
371 emul_write_status(processor
, status
, errno
);
373 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
375 free(scratch_buffer
);
380 do_write(os_emul_data
*emul
,
386 void *scratch_buffer
= NULL
;
387 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
388 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
389 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
393 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
394 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
396 /* get a tempoary bufer */
397 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
400 emul_read_buffer(scratch_buffer
, buf
, nbytes
,
406 status
= write(d
, scratch_buffer
, nbytes
);
408 emul_write_status(processor
, status
, errno
);
409 free(scratch_buffer
);
416 do_open(os_emul_data
*emul
,
422 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
423 char path_buf
[PATH_MAX
];
424 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
425 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
426 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
430 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
431 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
435 /* Do some translation on 'flags' to match it to the host's version. */
436 /* These flag values were taken from the NetBSD 1.4 header files. */
437 if ((flags
& 3) == 0)
438 hostflags
= O_RDONLY
;
439 else if ((flags
& 3) == 1)
440 hostflags
= O_WRONLY
;
443 if (flags
& 0x00000008)
444 hostflags
|= O_APPEND
;
445 if (flags
& 0x00000200)
446 hostflags
|= O_CREAT
;
447 if (flags
& 0x00000400)
448 hostflags
|= O_TRUNC
;
449 if (flags
& 0x00000800)
452 /* Can't combine these statements, cuz open sets errno. */
453 status
= open(path
, hostflags
, mode
);
454 emul_write_status(processor
, status
, errno
);
459 do_close(os_emul_data
*emul
,
465 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
468 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
469 printf_filtered ("%d", d
);
476 /* Do not close stdin, stdout, or stderr. GDB may still need access to
477 these descriptors. */
478 if (d
== 0 || d
== 1 || d
== 2)
487 emul_write_status(processor
, status
, errno
);
492 do_break(os_emul_data
*emul
,
498 /* just pass this onto the `vm' device */
499 unsigned_word new_break
= cpu_registers(processor
)->gpr
[arg0
];
502 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
503 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
506 status
= device_ioctl(emul
->vm
,
510 new_break
); /*ioctl-data*/
511 emul_write_status(processor
, 0, status
);
519 do_getpid(os_emul_data
*emul
,
526 emul_write_status(processor
, (int)getpid(), 0);
534 do_getuid(os_emul_data
*emul
,
541 emul_write_status(processor
, (int)getuid(), 0);
549 do_geteuid(os_emul_data
*emul
,
556 emul_write_status(processor
, (int)geteuid(), 0);
564 do_kill(os_emul_data
*emul
,
570 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
571 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
573 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
574 printf_filtered ("%d, %d", (int)pid
, sig
);
577 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
579 cpu_halt(processor
, cia
, was_signalled
, sig
);
587 do_dup(os_emul_data
*emul
,
593 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
594 int status
= (fdbad (oldd
) < 0) ? -1 : dup(oldd
);
597 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
598 printf_filtered ("%d", oldd
);
601 emul_write_status(processor
, status
, err
);
609 do_getegid(os_emul_data
*emul
,
616 emul_write_status(processor
, (int)getegid(), 0);
624 do_getgid(os_emul_data
*emul
,
631 emul_write_status(processor
, (int)getgid(), 0);
635 #ifndef HAVE_SIGPROCMASK
636 #define do_sigprocmask 0
639 do_sigprocmask(os_emul_data
*emul
,
645 natural_word how
= cpu_registers(processor
)->gpr
[arg0
];
646 unsigned_word set
= cpu_registers(processor
)->gpr
[arg0
+1];
647 unsigned_word oset
= cpu_registers(processor
)->gpr
[arg0
+2];
648 #ifdef SYS_sigprocmask
652 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
653 printf_filtered ("%ld, 0x%ld, 0x%ld", (long)how
, (long)set
, (long)oset
);
655 emul_write_status(processor
, 0, 0);
656 cpu_registers(processor
)->gpr
[4] = set
;
664 do_ioctl(os_emul_data
*emul
,
670 int d
= cpu_registers(processor
)->gpr
[arg0
];
671 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
672 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
674 #if !WITH_NetBSD_HOST
675 cpu_registers(processor
)->gpr
[arg0
] = 0; /* just succeed */
677 unsigned dir
= request
& IOC_DIRMASK
;
680 /* what we haven't done */
681 if (dir
& IOC_IN
/* write into the io device */
683 || !(dir
& IOC_VOID
))
684 error("do_ioctl() read or write of parameter not implemented\n");
687 status
= ioctl(d
, request
, NULL
);
688 emul_write_status(processor
, status
, errno
);
691 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
692 printf_filtered ("%d, 0x%x, 0x%lx", d
, request
, (long)argp_addr
);
700 do_umask(os_emul_data
*emul
,
706 int mask
= cpu_registers(processor
)->gpr
[arg0
];
708 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
709 printf_filtered ("0%o", mask
);
712 emul_write_status(processor
, umask(mask
), 0);
720 do_dup2(os_emul_data
*emul
,
726 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
727 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
728 int status
= (fdbad (oldd
) < 0) ? -1 : dup2(oldd
, newd
);
731 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
732 printf_filtered ("%d, %d", oldd
, newd
);
735 emul_write_status(processor
, status
, err
);
743 do_fcntl(os_emul_data
*emul
,
749 int fd
= cpu_registers(processor
)->gpr
[arg0
];
750 int cmd
= cpu_registers(processor
)->gpr
[arg0
+1];
751 int arg
= cpu_registers(processor
)->gpr
[arg0
+2];
754 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
755 printf_filtered ("%d, %d, %d", fd
, cmd
, arg
);
760 status
= fcntl(fd
, cmd
, arg
);
761 emul_write_status(processor
, status
, errno
);
765 #ifndef HAVE_GETTIMEOFDAY
766 #define do_gettimeofday 0
769 do_gettimeofday(os_emul_data
*emul
,
775 unsigned_word t_addr
= cpu_registers(processor
)->gpr
[arg0
];
776 unsigned_word tz_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
779 int status
= gettimeofday((t_addr
!= 0 ? &t
: NULL
),
780 (tz_addr
!= 0 ? &tz
: NULL
));
783 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
784 printf_filtered ("0x%lx, 0x%lx", (long)t_addr
, (long)tz_addr
);
787 emul_write_status(processor
, status
, err
);
790 write_timeval(t_addr
, t
, processor
, cia
);
792 write_timezone(tz_addr
, tz
, processor
, cia
);
797 #ifndef HAVE_GETRUSAGE
798 #define do_getrusage 0
801 do_getrusage(os_emul_data
*emul
,
807 int who
= cpu_registers(processor
)->gpr
[arg0
];
808 unsigned_word rusage_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
809 struct rusage rusage
;
810 int status
= getrusage(who
, (rusage_addr
!= 0 ? &rusage
: NULL
));
813 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
814 printf_filtered ("%d, 0x%lx", who
, (long)rusage_addr
);
817 emul_write_status(processor
, status
, err
);
819 if (rusage_addr
!= 0)
820 write_rusage(rusage_addr
, rusage
, processor
, cia
);
830 do_fstatfs(os_emul_data
*emul
,
836 int fd
= cpu_registers(processor
)->gpr
[arg0
];
837 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
841 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
842 printf_filtered ("%d, 0x%lx", fd
, (long)buf_addr
);
847 status
= fstatfs(fd
, (buf_addr
== 0 ? NULL
: &buf
));
848 emul_write_status(processor
, status
, errno
);
851 write_statfs(buf_addr
, buf
, processor
, cia
);
860 do_stat(os_emul_data
*emul
,
866 char path_buf
[PATH_MAX
];
867 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
868 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
869 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
875 status
= stat(path
, &buf
);
876 emul_write_status(processor
, status
, errno
);
878 write_stat(stat_buf_addr
, buf
, processor
, cia
);
886 do_fstat(os_emul_data
*emul
,
892 int fd
= cpu_registers(processor
)->gpr
[arg0
];
893 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
899 /* Can't combine these statements, cuz fstat sets errno. */
902 status
= fstat(fd
, &buf
);
903 emul_write_status(processor
, status
, errno
);
904 write_stat(stat_buf_addr
, buf
, processor
, cia
);
912 do_lstat(os_emul_data
*emul
,
918 char path_buf
[PATH_MAX
];
919 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
920 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
921 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
927 /* Can't combine these statements, cuz lstat sets errno. */
928 status
= lstat(path
, &buf
);
929 emul_write_status(processor
, status
, errno
);
930 write_stat(stat_buf_addr
, buf
, processor
, cia
);
934 #ifndef HAVE_GETDIRENTRIES
935 #define do_getdirentries 0
938 do_getdirentries(os_emul_data
*emul
,
944 int fd
= cpu_registers(processor
)->gpr
[arg0
];
945 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
947 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
948 unsigned_word basep_addr
= cpu_registers(processor
)->gpr
[arg0
+3];
951 #ifdef SYS_getdirentries
954 if (buf_addr
!= 0 && nbytes
>= 0)
955 buf
= zalloc(nbytes
);
958 status
= getdirentries(fd
,
959 (buf_addr
== 0 ? NULL
: buf
),
961 (basep_addr
== 0 ? NULL
: &basep
));
962 emul_write_status(processor
, status
, errno
);
964 emul_write_word(basep_addr
, basep
, processor
, cia
);
966 write_direntries(buf_addr
, buf
, status
, processor
, cia
);
974 do___syscall(os_emul_data
*emul
,
981 emul_do_system_call(emul
,
983 cpu_registers(processor
)->gpr
[arg0
],
993 do_lseek(os_emul_data
*emul
,
999 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
1000 off_t offset
= emul_read_gpr64(processor
, arg0
+2);
1001 int whence
= cpu_registers(processor
)->gpr
[arg0
+4];
1004 status
= fdbad (fildes
);
1006 status
= lseek(fildes
, offset
, whence
);
1008 emul_write_status(processor
, -1, errno
);
1010 emul_write_status(processor
, 0, 0); /* success */
1011 emul_write_gpr64(processor
, 3, status
);
1017 do___sysctl(os_emul_data
*emul
,
1023 /* call the arguments by their real name */
1024 unsigned_word name
= cpu_registers(processor
)->gpr
[arg0
];
1025 natural_word namelen
= cpu_registers(processor
)->gpr
[arg0
+1];
1026 unsigned_word oldp
= cpu_registers(processor
)->gpr
[arg0
+2];
1027 unsigned_word oldlenp
= cpu_registers(processor
)->gpr
[arg0
+3];
1028 natural_word oldlen
;
1030 natural_word int_val
;
1033 /* pluck out the management information base id */
1035 error("system_call()SYS___sysctl bad name[0]\n");
1036 mib
= vm_data_map_read_word(cpu_data_map(processor
),
1040 name
+= sizeof(mib
);
1042 /* see what to do with it ... */
1045 #if WITH_NetBSD_HOST && (CTL_HW != 6)
1049 error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
1050 mib
= vm_data_map_read_word(cpu_data_map(processor
),
1054 name
+= sizeof(mib
);
1056 case 7/*HW_PAGESIZE*/:
1057 #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
1058 # error "HW_PAGESIZE"
1060 oldlen
= vm_data_map_read_word(cpu_data_map(processor
),
1064 if (sizeof(natural_word
) > oldlen
)
1065 error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
1067 oldlen
= sizeof(int_val
);
1068 emul_write_word(oldp
, int_val
, processor
, cia
);
1069 emul_write_word(oldlenp
, oldlen
, processor
, cia
);
1072 error("sysctl() CTL_HW.%d unknown\n", mib
);
1077 error("sysctl() name[0]=%d unknown\n", (int)mib
);
1080 emul_write_status(processor
, 0, 0); /* always succeed */
1085 static emul_syscall_descriptor netbsd_descriptors
[] = {
1086 /* 0 */ { 0, "syscall" },
1087 /* 1 */ { do_exit
, "exit" },
1088 /* 2 */ { 0, "fork" },
1089 /* 3 */ { do_read
, "read" },
1090 /* 4 */ { do_write
, "write" },
1091 /* 5 */ { do_open
, "open" },
1092 /* 6 */ { do_close
, "close" },
1093 /* 7 */ { 0, "wait4" },
1094 { 0, }, /* 8 is old creat */
1095 /* 9 */ { 0, "link" },
1096 /* 10 */ { 0, "unlink" },
1097 { 0, }, /* 11 is obsolete execv */
1098 /* 12 */ { 0, "chdir" },
1099 /* 13 */ { 0, "fchdir" },
1100 /* 14 */ { 0, "mknod" },
1101 /* 15 */ { 0, "chmod" },
1102 /* 16 */ { 0, "chown" },
1103 /* 17 */ { do_break
, "break" },
1104 /* 18 */ { 0, "getfsstat" },
1105 { 0, }, /* 19 is old lseek */
1106 /* 20 */ { do_getpid
, "getpid" },
1107 /* 21 */ { 0, "mount" },
1108 /* 22 */ { 0, "unmount" },
1109 /* 23 */ { 0, "setuid" },
1110 /* 24 */ { do_getuid
, "getuid" },
1111 /* 25 */ { do_geteuid
, "geteuid" },
1112 /* 26 */ { 0, "ptrace" },
1113 /* 27 */ { 0, "recvmsg" },
1114 /* 28 */ { 0, "sendmsg" },
1115 /* 29 */ { 0, "recvfrom" },
1116 /* 30 */ { 0, "accept" },
1117 /* 31 */ { 0, "getpeername" },
1118 /* 32 */ { 0, "getsockname" },
1119 /* 33 */ { 0, "access" },
1120 /* 34 */ { 0, "chflags" },
1121 /* 35 */ { 0, "fchflags" },
1122 /* 36 */ { 0, "sync" },
1123 /* 37 */ { do_kill
, "kill" },
1124 { 0, }, /* 38 is old stat */
1125 /* 39 */ { 0, "getppid" },
1126 { 0, }, /* 40 is old lstat */
1127 /* 41 */ { do_dup
, "dup" },
1128 /* 42 */ { 0, "pipe" },
1129 /* 43 */ { do_getegid
, "getegid" },
1130 /* 44 */ { 0, "profil" },
1131 /* 45 */ { 0, "ktrace" },
1132 /* 46 */ { 0, "sigaction" },
1133 /* 47 */ { do_getgid
, "getgid" },
1134 /* 48 */ { do_sigprocmask
, "sigprocmask" },
1135 /* 49 */ { 0, "getlogin" },
1136 /* 50 */ { 0, "setlogin" },
1137 /* 51 */ { 0, "acct" },
1138 /* 52 */ { 0, "sigpending" },
1139 /* 53 */ { 0, "sigaltstack" },
1140 /* 54 */ { do_ioctl
, "ioctl" },
1141 /* 55 */ { 0, "reboot" },
1142 /* 56 */ { 0, "revoke" },
1143 /* 57 */ { 0, "symlink" },
1144 /* 58 */ { 0, "readlink" },
1145 /* 59 */ { 0, "execve" },
1146 /* 60 */ { do_umask
, "umask" },
1147 /* 61 */ { 0, "chroot" },
1148 { 0, }, /* 62 is old fstat */
1149 { 0, }, /* 63 is old getkerninfo */
1150 { 0, }, /* 64 is old getpagesize */
1151 /* 65 */ { 0, "msync" },
1152 /* 66 */ { 0, "vfork" },
1153 { 0, }, /* 67 is obsolete vread */
1154 { 0, }, /* 68 is obsolete vwrite */
1155 /* 69 */ { 0, "sbrk" },
1156 /* 70 */ { 0, "sstk" },
1157 { 0, }, /* 71 is old mmap */
1158 /* 72 */ { 0, "vadvise" },
1159 /* 73 */ { 0, "munmap" },
1160 /* 74 */ { 0, "mprotect" },
1161 /* 75 */ { 0, "madvise" },
1162 { 0, }, /* 76 is obsolete vhangup */
1163 { 0, }, /* 77 is obsolete vlimit */
1164 /* 78 */ { 0, "mincore" },
1165 /* 79 */ { 0, "getgroups" },
1166 /* 80 */ { 0, "setgroups" },
1167 /* 81 */ { 0, "getpgrp" },
1168 /* 82 */ { 0, "setpgid" },
1169 /* 83 */ { 0, "setitimer" },
1170 { 0, }, /* 84 is old wait */
1171 /* 85 */ { 0, "swapon" },
1172 /* 86 */ { 0, "getitimer" },
1173 { 0, }, /* 87 is old gethostname */
1174 { 0, }, /* 88 is old sethostname */
1175 { 0, }, /* 89 is old getdtablesize */
1176 { do_dup2
, "dup2" },
1178 /* 92 */ { do_fcntl
, "fcntl" },
1179 /* 93 */ { 0, "select" },
1181 /* 95 */ { 0, "fsync" },
1182 /* 96 */ { 0, "setpriority" },
1183 /* 97 */ { 0, "socket" },
1184 /* 98 */ { 0, "connect" },
1185 { 0, }, /* 99 is old accept */
1186 /* 100 */ { 0, "getpriority" },
1187 { 0, }, /* 101 is old send */
1188 { 0, }, /* 102 is old recv */
1189 /* 103 */ { 0, "sigreturn" },
1190 /* 104 */ { 0, "bind" },
1191 /* 105 */ { 0, "setsockopt" },
1192 /* 106 */ { 0, "listen" },
1193 { 0, }, /* 107 is obsolete vtimes */
1194 { 0, }, /* 108 is old sigvec */
1195 { 0, }, /* 109 is old sigblock */
1196 { 0, }, /* 110 is old sigsetmask */
1197 /* 111 */ { 0, "sigsuspend" },
1198 { 0, }, /* 112 is old sigstack */
1199 { 0, }, /* 113 is old recvmsg */
1200 { 0, }, /* 114 is old sendmsg */
1201 /* - is obsolete vtrace */ { 0, "vtrace 115" },
1202 /* 116 */ { do_gettimeofday
, "gettimeofday" },
1203 /* 117 */ { do_getrusage
, "getrusage" },
1204 /* 118 */ { 0, "getsockopt" },
1205 /* 119 */ { 0, "resuba" },
1206 /* 120 */ { 0, "readv" },
1207 /* 121 */ { 0, "writev" },
1208 /* 122 */ { 0, "settimeofday" },
1209 /* 123 */ { 0, "fchown" },
1210 /* 124 */ { 0, "fchmod" },
1211 { 0, }, /* 125 is old recvfrom */
1212 { 0, }, /* 126 is old setreuid */
1213 { 0, }, /* 127 is old setregid */
1214 /* 128 */ { 0, "rename" },
1215 { 0, }, /* 129 is old truncate */
1216 { 0, }, /* 130 is old ftruncate */
1217 /* 131 */ { 0, "flock" },
1218 /* 132 */ { 0, "mkfifo" },
1219 /* 133 */ { 0, "sendto" },
1220 /* 134 */ { 0, "shutdown" },
1221 /* 135 */ { 0, "socketpair" },
1222 /* 136 */ { 0, "mkdir" },
1223 /* 137 */ { 0, "rmdir" },
1224 /* 138 */ { 0, "utimes" },
1225 { 0, }, /* 139 is obsolete 4.2 sigreturn */
1226 /* 140 */ { 0, "adjtime" },
1227 { 0, }, /* 141 is old getpeername */
1228 { 0, }, /* 142 is old gethostid */
1229 { 0, }, /* 143 is old sethostid */
1230 { 0, }, /* 144 is old getrlimit */
1231 { 0, }, /* 145 is old setrlimit */
1232 { 0, }, /* 146 is old killpg */
1233 /* 147 */ { 0, "setsid" },
1234 /* 148 */ { 0, "quotactl" },
1235 { 0, }, /* 149 is old quota */
1236 { 0, }, /* 150 is old getsockname */
1241 /* 155 */ { 0, "nfssvc" },
1242 { 0, }, /* 156 is old getdirentries */
1243 /* 157 */ { 0, "statfs" },
1244 /* 158 */ { do_fstatfs
, "fstatfs" },
1247 /* 161 */ { 0, "getfh" },
1248 { 0, }, /* 162 is old getdomainname */
1249 { 0, }, /* 163 is old setdomainname */
1250 { 0, }, /* 164 is old uname */
1251 /* 165 */ { 0, "sysarch" },
1255 /* 169 */ { 0, "semsys" },
1256 /* 170 */ { 0, "msgsys" },
1257 /* 171 */ { 0, "shmsys" },
1267 /* 181 */ { 0, "setgid" },
1268 /* 182 */ { 0, "setegid" },
1269 /* 183 */ { 0, "seteuid" },
1270 /* 184 */ { 0, "lfs_bmapv" },
1271 /* 185 */ { 0, "lfs_markv" },
1272 /* 186 */ { 0, "lfs_segclean" },
1273 /* 187 */ { 0, "lfs_segwait" },
1274 /* 188 */ { do_stat
, "stat" },
1275 /* 189 */ { do_fstat
, "fstat" },
1276 /* 190 */ { do_lstat
, "lstat" },
1277 /* 191 */ { 0, "pathconf" },
1278 /* 192 */ { 0, "fpathconf" },
1280 /* 194 */ { 0, "getrlimit" },
1281 /* 195 */ { 0, "setrlimit" },
1282 /* 196 */ { do_getdirentries
, "getdirentries" },
1283 /* 197 */ { 0, "mmap" },
1284 /* 198 */ { do___syscall
, "__syscall" },
1285 /* 199 */ { do_lseek
, "lseek" },
1286 /* 200 */ { 0, "truncate" },
1287 /* 201 */ { 0, "ftruncate" },
1288 /* 202 */ { do___sysctl
, "__sysctl" },
1289 /* 203 */ { 0, "mlock" },
1290 /* 204 */ { 0, "munlock" },
1293 static char *(netbsd_error_names
[]) = {
1330 /* 36 */ "EINPROGRESS",
1331 /* 37 */ "EALREADY",
1332 /* 38 */ "ENOTSOCK",
1333 /* 39 */ "EDESTADDRREQ",
1334 /* 40 */ "EMSGSIZE",
1335 /* 41 */ "EPROTOTYPE",
1336 /* 42 */ "ENOPROTOOPT",
1337 /* 43 */ "EPROTONOSUPPORT",
1338 /* 44 */ "ESOCKTNOSUPPORT",
1339 /* 45 */ "EOPNOTSUPP",
1340 /* 46 */ "EPFNOSUPPORT",
1341 /* 47 */ "EAFNOSUPPORT",
1342 /* 48 */ "EADDRINUSE",
1343 /* 49 */ "EADDRNOTAVAIL",
1344 /* 50 */ "ENETDOWN",
1345 /* 51 */ "ENETUNREACH",
1346 /* 52 */ "ENETRESET",
1347 /* 53 */ "ECONNABORTED",
1348 /* 54 */ "ECONNRESET",
1351 /* 57 */ "ENOTCONN",
1352 /* 58 */ "ESHUTDOWN",
1353 /* 59 */ "ETOOMANYREFS",
1354 /* 60 */ "ETIMEDOUT",
1355 /* 61 */ "ECONNREFUSED",
1357 /* 63 */ "ENAMETOOLONG",
1358 /* 64 */ "EHOSTDOWN",
1359 /* 65 */ "EHOSTUNREACH",
1360 /* 66 */ "ENOTEMPTY",
1361 /* 67 */ "EPROCLIM",
1367 /* 73 */ "ERPCMISMATCH",
1368 /* 74 */ "EPROGUNAVAIL",
1369 /* 75 */ "EPROGMISMATCH",
1370 /* 76 */ "EPROCUNAVAIL",
1375 /* 81 */ "ENEEDAUTH",
1379 static char *(netbsd_signal_names
[]) = {
1406 /* 26 */ "SIGVTALRM",
1408 /* 28 */ "SIGWINCH",
1414 static emul_syscall emul_netbsd_syscalls
= {
1416 ARRAY_SIZE (netbsd_descriptors
),
1418 ARRAY_SIZE (netbsd_error_names
),
1419 netbsd_signal_names
,
1420 ARRAY_SIZE (netbsd_signal_names
),
1424 /* NetBSD's os_emul interface, most are just passed on to the generic
1427 static os_emul_data
*
1428 emul_netbsd_create(device
*root
,
1432 unsigned_word top_of_stack
;
1433 unsigned stack_size
;
1435 os_emul_data
*bsd_data
;
1439 /* check that this emulation is really for us */
1440 if (name
!= NULL
&& strcmp(name
, "netbsd") != 0)
1446 /* merge any emulation specific entries into the device tree */
1448 /* establish a few defaults */
1449 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
1451 top_of_stack
= 0xe0000000;
1452 stack_size
= 0x00100000;
1456 top_of_stack
= 0x20000000;
1457 stack_size
= 0x00100000;
1461 emul_add_tree_options(root
, image
, "netbsd",
1462 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
1463 ? "user" : "virtual"),
1464 0 /*oea-interrupt-prefix*/);
1466 /* virtual memory - handles growth of stack/heap */
1467 vm
= tree_parse(root
, "/openprom/vm");
1468 tree_parse(vm
, "./stack-base 0x%lx",
1469 (unsigned long)(top_of_stack
- stack_size
));
1470 tree_parse(vm
, "./nr-bytes 0x%x", stack_size
);
1472 filename
= tree_quote_property (bfd_get_filename(image
));
1473 tree_parse(root
, "/openprom/vm/map-binary/file-name %s",
1477 /* finish the init */
1478 tree_parse(root
, "/openprom/init/register/pc 0x%lx",
1479 (unsigned long)bfd_get_start_address(image
));
1480 tree_parse(root
, "/openprom/init/register/sp 0x%lx",
1481 (unsigned long)top_of_stack
);
1482 tree_parse(root
, "/openprom/init/register/msr 0x%x",
1483 ((tree_find_boolean_property(root
, "/options/little-endian?")
1484 ? msr_little_endian_mode
1486 | (tree_find_boolean_property(root
, "/openprom/options/floating-point?")
1487 ? (msr_floating_point_available
1488 | msr_floating_point_exception_mode_0
1489 | msr_floating_point_exception_mode_1
)
1491 tree_parse(root
, "/openprom/init/stack/stack-type %s",
1492 (elf_binary
? "ppc-elf" : "ppc-xcoff"));
1494 /* finally our emulation data */
1495 bsd_data
= ZALLOC(os_emul_data
);
1497 bsd_data
->syscalls
= &emul_netbsd_syscalls
;
1502 emul_netbsd_init(os_emul_data
*emul_data
,
1511 emul_netbsd_system_call(cpu
*processor
,
1513 os_emul_data
*emul_data
)
1515 emul_do_system_call(emul_data
,
1516 emul_data
->syscalls
,
1517 cpu_registers(processor
)->gpr
[0],
1518 3, /*r3 contains arg0*/
1523 const os_emul emul_netbsd
= {
1527 emul_netbsd_system_call
,
1528 0, /*instruction_call*/
1532 #endif /* _EMUL_NETBSD_C_ */