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"
32 #include <sys/types.h>
38 #include <sys/param.h>
42 #ifndef HAVE_SYS_RESOURCE_H
48 #include <sys/resource.h>
53 #include <sys/ioctl.h>
58 # define NAMLEN(dirent) strlen((dirent)->d_name)
60 # define dirent direct
61 # define NAMLEN(dirent) (dirent)->d_namlen
63 # include <sys/ndir.h>
74 #undef MAXPATHLEN /* sys/param.h might define this also */
80 #define WITH_NetBSD_HOST (NetBSD >= 199306)
81 #if WITH_NetBSD_HOST /* here NetBSD as that is what we're emulating */
82 #include <sys/syscall.h> /* FIXME - should not be including this one */
83 #include <sys/sysctl.h>
84 #include <sys/mount.h>
85 extern int getdirentries(int fd
, char *buf
, int nbytes
, long *basep
);
87 /* NetBSD post 2.0 has the statfs system call (if COMPAT_20), but does
88 not have struct statfs. In this case don't implement fstatfs.
89 FIXME: Should implement fstatvfs. */
90 #ifndef HAVE_STRUCT_STATFS
96 /* If this is not netbsd, don't allow fstatfs or getdirentries at this time */
98 #undef HAVE_GETDIRENTRIES
101 #if (BSD < 199306) /* here BSD as just a bug */
105 #ifndef STATIC_INLINE_EMUL_NETBSD
106 #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
111 #define SYS(X) ASSERT(call == (SYS_##X))
116 #if WITH_NetBSD_HOST && (PATH_MAX != 1024)
117 #error "PATH_MAX not 1024"
118 #elif !defined(PATH_MAX)
119 #define PATH_MAX 1024
125 NetBSD - Emulation of user programs for NetBSD/PPC
132 /* NetBSD's idea of what is needed to implement emulations */
134 struct _os_emul_data
{
136 emul_syscall
*syscalls
;
141 STATIC_INLINE_EMUL_NETBSD
void
142 write_stat(unsigned_word addr
,
155 /* H2T(buf.st_spare1); */
157 /* H2T(buf.st_spare2); */
159 /* H2T(buf.st_spare3); */
160 #ifdef AC_STRUCT_ST_RDEV
163 #ifdef AC_STRUCT_ST_BLKSIZE
166 #ifdef AC_STRUCT_ST_BLOCKS
173 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
178 STATIC_INLINE_EMUL_NETBSD
void
179 write_statfs(unsigned_word addr
,
193 H2T(buf
.f_fsid
.val
[0]);
194 H2T(buf
.f_fsid
.val
[1]);
197 /* f_fstypename[MFSNAMELEN]; */
198 /* f_mntonname[MNAMELEN]; */
199 /* f_mntfromname[MNAMELEN]; */
200 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
205 STATIC_INLINE_EMUL_NETBSD
void
206 write_timeval(unsigned_word addr
,
213 emul_write_buffer(&t
, addr
, sizeof(t
), processor
, cia
);
216 #ifdef HAVE_GETTIMEOFDAY
217 STATIC_INLINE_EMUL_NETBSD
void
218 write_timezone(unsigned_word addr
,
223 H2T(tz
.tz_minuteswest
);
225 emul_write_buffer(&tz
, addr
, sizeof(tz
), processor
, cia
);
229 #ifdef HAVE_GETDIRENTRIES
230 STATIC_INLINE_EMUL_NETBSD
void
231 write_direntries(unsigned_word addr
,
239 struct dirent
*in
= (struct dirent
*)buf
;
240 ASSERT(in
->d_reclen
<= nbytes
);
241 out
= (struct dirent
*)zalloc(in
->d_reclen
);
242 memcpy(out
/*dest*/, in
/*src*/, in
->d_reclen
);
247 emul_write_buffer(out
, addr
, in
->d_reclen
, processor
, cia
);
248 nbytes
-= in
->d_reclen
;
249 addr
+= in
->d_reclen
;
257 #ifdef HAVE_GETRUSAGE
258 STATIC_INLINE_EMUL_NETBSD
void
259 write_rusage(unsigned_word addr
,
260 struct rusage rusage
,
264 H2T(rusage
.ru_utime
.tv_sec
); /* user time used */
265 H2T(rusage
.ru_utime
.tv_usec
);
266 H2T(rusage
.ru_stime
.tv_sec
); /* system time used */
267 H2T(rusage
.ru_stime
.tv_usec
);
268 H2T(rusage
.ru_maxrss
); /* integral max resident set size */
269 H2T(rusage
.ru_ixrss
); /* integral shared text memory size */
270 H2T(rusage
.ru_idrss
); /* integral unshared data size */
271 H2T(rusage
.ru_isrss
); /* integral unshared stack size */
272 H2T(rusage
.ru_minflt
); /* page reclaims */
273 H2T(rusage
.ru_majflt
); /* page faults */
274 H2T(rusage
.ru_nswap
); /* swaps */
275 H2T(rusage
.ru_inblock
); /* block input operations */
276 H2T(rusage
.ru_oublock
); /* block output operations */
277 H2T(rusage
.ru_msgsnd
); /* messages sent */
278 H2T(rusage
.ru_msgrcv
); /* messages received */
279 H2T(rusage
.ru_nsignals
); /* signals received */
280 H2T(rusage
.ru_nvcsw
); /* voluntary context switches */
281 H2T(rusage
.ru_nivcsw
); /* involuntary context switches */
282 emul_write_buffer(&rusage
, addr
, sizeof(rusage
), processor
, cia
);
287 /* File descriptors 0, 1, and 2 should not be closed. fd_closed[]
288 tracks whether these descriptors have been closed in do_close()
291 static int fd_closed
[3];
293 /* Check for some occurrences of bad file descriptors. We only check
294 whether fd 0, 1, or 2 are "closed". By "closed" we mean that these
295 descriptors aren't actually closed, but are considered to be closed
298 Other checks are performed by the underlying OS call. */
303 if (fd
>=0 && fd
<= 2 && fd_closed
[fd
])
312 do_exit(os_emul_data
*emul
,
318 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
320 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
321 printf_filtered ("%d)\n", status
);
323 cpu_halt(processor
, cia
, was_exited
, status
);
328 do_read(os_emul_data
*emul
,
334 void *scratch_buffer
;
335 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
336 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
337 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
341 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
342 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
344 /* get a tempoary bufer */
345 scratch_buffer
= zalloc(nbytes
);
347 /* check if buffer exists by reading it */
348 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
353 status
= fread (scratch_buffer
, 1, nbytes
, stdin
);
354 if (status
== 0 && ferror (stdin
))
360 status
= read (d
, scratch_buffer
, nbytes
);
362 emul_write_status(processor
, status
, errno
);
364 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
366 free(scratch_buffer
);
371 do_write(os_emul_data
*emul
,
377 void *scratch_buffer
= NULL
;
378 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
379 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
380 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
384 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
385 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
387 /* get a tempoary bufer */
388 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
391 emul_read_buffer(scratch_buffer
, buf
, nbytes
,
397 status
= write(d
, scratch_buffer
, nbytes
);
399 emul_write_status(processor
, status
, errno
);
400 free(scratch_buffer
);
407 do_open(os_emul_data
*emul
,
413 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
414 char path_buf
[PATH_MAX
];
415 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
416 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
417 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
421 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
422 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
426 /* Do some translation on 'flags' to match it to the host's version. */
427 /* These flag values were taken from the NetBSD 1.4 header files. */
428 if ((flags
& 3) == 0)
429 hostflags
= O_RDONLY
;
430 else if ((flags
& 3) == 1)
431 hostflags
= O_WRONLY
;
434 if (flags
& 0x00000008)
435 hostflags
|= O_APPEND
;
436 if (flags
& 0x00000200)
437 hostflags
|= O_CREAT
;
438 if (flags
& 0x00000400)
439 hostflags
|= O_TRUNC
;
440 if (flags
& 0x00000800)
443 /* Can't combine these statements, cuz open sets errno. */
444 status
= open(path
, hostflags
, mode
);
445 emul_write_status(processor
, status
, errno
);
450 do_close(os_emul_data
*emul
,
456 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
459 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
460 printf_filtered ("%d", d
);
467 /* Do not close stdin, stdout, or stderr. GDB may still need access to
468 these descriptors. */
469 if (d
== 0 || d
== 1 || d
== 2)
478 emul_write_status(processor
, status
, errno
);
483 do_break(os_emul_data
*emul
,
489 /* just pass this onto the `vm' device */
490 unsigned_word new_break
= cpu_registers(processor
)->gpr
[arg0
];
493 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
494 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
497 status
= device_ioctl(emul
->vm
,
501 new_break
); /*ioctl-data*/
502 emul_write_status(processor
, 0, status
);
510 do_getpid(os_emul_data
*emul
,
517 emul_write_status(processor
, (int)getpid(), 0);
525 do_getuid(os_emul_data
*emul
,
532 emul_write_status(processor
, (int)getuid(), 0);
540 do_geteuid(os_emul_data
*emul
,
547 emul_write_status(processor
, (int)geteuid(), 0);
555 do_kill(os_emul_data
*emul
,
561 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
562 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
564 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
565 printf_filtered ("%d, %d", (int)pid
, sig
);
568 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
570 cpu_halt(processor
, cia
, was_signalled
, sig
);
578 do_dup(os_emul_data
*emul
,
584 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
585 int status
= (fdbad (oldd
) < 0) ? -1 : dup(oldd
);
588 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
589 printf_filtered ("%d", oldd
);
592 emul_write_status(processor
, status
, err
);
600 do_getegid(os_emul_data
*emul
,
607 emul_write_status(processor
, (int)getegid(), 0);
615 do_getgid(os_emul_data
*emul
,
622 emul_write_status(processor
, (int)getgid(), 0);
626 #ifndef HAVE_SIGPROCMASK
627 #define do_sigprocmask 0
630 do_sigprocmask(os_emul_data
*emul
,
636 natural_word how
= cpu_registers(processor
)->gpr
[arg0
];
637 unsigned_word set
= cpu_registers(processor
)->gpr
[arg0
+1];
638 unsigned_word oset
= cpu_registers(processor
)->gpr
[arg0
+2];
639 #ifdef SYS_sigprocmask
643 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
644 printf_filtered ("%ld, 0x%lx, 0x%lx", (long)how
, (long)set
, (long)oset
);
646 emul_write_status(processor
, 0, 0);
647 cpu_registers(processor
)->gpr
[4] = set
;
655 do_ioctl(os_emul_data
*emul
,
661 int d
= cpu_registers(processor
)->gpr
[arg0
];
662 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
663 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
665 #if !WITH_NetBSD_HOST
666 cpu_registers(processor
)->gpr
[arg0
] = 0; /* just succeed */
668 unsigned dir
= request
& IOC_DIRMASK
;
671 /* what we haven't done */
672 if (dir
& IOC_IN
/* write into the io device */
674 || !(dir
& IOC_VOID
))
675 error("do_ioctl() read or write of parameter not implemented\n");
678 status
= ioctl(d
, request
, NULL
);
679 emul_write_status(processor
, status
, errno
);
682 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
683 printf_filtered ("%d, 0x%x, 0x%lx", d
, request
, (long)argp_addr
);
691 do_umask(os_emul_data
*emul
,
697 int mask
= cpu_registers(processor
)->gpr
[arg0
];
699 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
700 printf_filtered ("0%o", mask
);
703 emul_write_status(processor
, umask(mask
), 0);
711 do_dup2(os_emul_data
*emul
,
717 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
718 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
719 int status
= (fdbad (oldd
) < 0) ? -1 : dup2(oldd
, newd
);
722 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
723 printf_filtered ("%d, %d", oldd
, newd
);
726 emul_write_status(processor
, status
, err
);
734 do_fcntl(os_emul_data
*emul
,
740 int fd
= cpu_registers(processor
)->gpr
[arg0
];
741 int cmd
= cpu_registers(processor
)->gpr
[arg0
+1];
742 int arg
= cpu_registers(processor
)->gpr
[arg0
+2];
745 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
746 printf_filtered ("%d, %d, %d", fd
, cmd
, arg
);
751 status
= fcntl(fd
, cmd
, arg
);
752 emul_write_status(processor
, status
, errno
);
756 #ifndef HAVE_GETTIMEOFDAY
757 #define do_gettimeofday 0
760 do_gettimeofday(os_emul_data
*emul
,
766 unsigned_word t_addr
= cpu_registers(processor
)->gpr
[arg0
];
767 unsigned_word tz_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
770 int status
= gettimeofday((t_addr
!= 0 ? &t
: NULL
),
771 (tz_addr
!= 0 ? &tz
: NULL
));
774 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
775 printf_filtered ("0x%lx, 0x%lx", (long)t_addr
, (long)tz_addr
);
778 emul_write_status(processor
, status
, err
);
781 write_timeval(t_addr
, t
, processor
, cia
);
783 write_timezone(tz_addr
, tz
, processor
, cia
);
788 #ifndef HAVE_GETRUSAGE
789 #define do_getrusage 0
792 do_getrusage(os_emul_data
*emul
,
798 int who
= cpu_registers(processor
)->gpr
[arg0
];
799 unsigned_word rusage_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
800 struct rusage rusage
;
801 int status
= getrusage(who
, (rusage_addr
!= 0 ? &rusage
: NULL
));
804 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
805 printf_filtered ("%d, 0x%lx", who
, (long)rusage_addr
);
808 emul_write_status(processor
, status
, err
);
810 if (rusage_addr
!= 0)
811 write_rusage(rusage_addr
, rusage
, processor
, cia
);
821 do_fstatfs(os_emul_data
*emul
,
827 int fd
= cpu_registers(processor
)->gpr
[arg0
];
828 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
832 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
833 printf_filtered ("%d, 0x%lx", fd
, (long)buf_addr
);
838 status
= fstatfs(fd
, (buf_addr
== 0 ? NULL
: &buf
));
839 emul_write_status(processor
, status
, errno
);
842 write_statfs(buf_addr
, buf
, processor
, cia
);
851 do_stat(os_emul_data
*emul
,
857 char path_buf
[PATH_MAX
];
858 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
859 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
860 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
866 status
= stat(path
, &buf
);
867 emul_write_status(processor
, status
, errno
);
869 write_stat(stat_buf_addr
, buf
, processor
, cia
);
877 do_fstat(os_emul_data
*emul
,
883 int fd
= cpu_registers(processor
)->gpr
[arg0
];
884 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
890 /* Can't combine these statements, cuz fstat sets errno. */
893 status
= fstat(fd
, &buf
);
894 emul_write_status(processor
, status
, errno
);
895 write_stat(stat_buf_addr
, buf
, processor
, cia
);
903 do_lstat(os_emul_data
*emul
,
909 char path_buf
[PATH_MAX
];
910 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
911 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
912 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
918 /* Can't combine these statements, cuz lstat sets errno. */
919 status
= lstat(path
, &buf
);
920 emul_write_status(processor
, status
, errno
);
921 write_stat(stat_buf_addr
, buf
, processor
, cia
);
925 #ifndef HAVE_GETDIRENTRIES
926 #define do_getdirentries 0
929 do_getdirentries(os_emul_data
*emul
,
935 int fd
= cpu_registers(processor
)->gpr
[arg0
];
936 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
938 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
939 unsigned_word basep_addr
= cpu_registers(processor
)->gpr
[arg0
+3];
942 #ifdef SYS_getdirentries
945 if (buf_addr
!= 0 && nbytes
>= 0)
946 buf
= zalloc(nbytes
);
949 status
= getdirentries(fd
,
950 (buf_addr
== 0 ? NULL
: buf
),
952 (basep_addr
== 0 ? NULL
: &basep
));
953 emul_write_status(processor
, status
, errno
);
955 emul_write_word(basep_addr
, basep
, processor
, cia
);
957 write_direntries(buf_addr
, buf
, status
, processor
, cia
);
965 do___syscall(os_emul_data
*emul
,
972 emul_do_system_call(emul
,
974 cpu_registers(processor
)->gpr
[arg0
],
984 do_lseek(os_emul_data
*emul
,
990 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
991 off_t offset
= emul_read_gpr64(processor
, arg0
+2);
992 int whence
= cpu_registers(processor
)->gpr
[arg0
+4];
995 status
= fdbad (fildes
);
997 status
= lseek(fildes
, offset
, whence
);
999 emul_write_status(processor
, -1, errno
);
1001 emul_write_status(processor
, 0, 0); /* success */
1002 emul_write_gpr64(processor
, 3, status
);
1008 do___sysctl(os_emul_data
*emul
,
1014 /* call the arguments by their real name */
1015 unsigned_word name
= cpu_registers(processor
)->gpr
[arg0
];
1016 natural_word namelen
= cpu_registers(processor
)->gpr
[arg0
+1];
1017 unsigned_word oldp
= cpu_registers(processor
)->gpr
[arg0
+2];
1018 unsigned_word oldlenp
= cpu_registers(processor
)->gpr
[arg0
+3];
1019 natural_word oldlen
;
1021 natural_word int_val
;
1024 /* pluck out the management information base id */
1026 error("system_call()SYS___sysctl bad name[0]\n");
1027 mib
= vm_data_map_read_word(cpu_data_map(processor
),
1031 name
+= sizeof(mib
);
1033 /* see what to do with it ... */
1036 #if WITH_NetBSD_HOST && (CTL_HW != 6)
1040 error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
1041 mib
= vm_data_map_read_word(cpu_data_map(processor
),
1045 name
+= sizeof(mib
);
1047 case 7/*HW_PAGESIZE*/:
1048 #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
1049 # error "HW_PAGESIZE"
1051 oldlen
= vm_data_map_read_word(cpu_data_map(processor
),
1055 if (sizeof(natural_word
) > oldlen
)
1056 error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
1058 oldlen
= sizeof(int_val
);
1059 emul_write_word(oldp
, int_val
, processor
, cia
);
1060 emul_write_word(oldlenp
, oldlen
, processor
, cia
);
1063 error("sysctl() CTL_HW.%d unknown\n", mib
);
1068 error("sysctl() name[0]=%d unknown\n", (int)mib
);
1071 emul_write_status(processor
, 0, 0); /* always succeed */
1076 static emul_syscall_descriptor netbsd_descriptors
[] = {
1077 /* 0 */ { 0, "syscall" },
1078 /* 1 */ { do_exit
, "exit" },
1079 /* 2 */ { 0, "fork" },
1080 /* 3 */ { do_read
, "read" },
1081 /* 4 */ { do_write
, "write" },
1082 /* 5 */ { do_open
, "open" },
1083 /* 6 */ { do_close
, "close" },
1084 /* 7 */ { 0, "wait4" },
1085 { 0, }, /* 8 is old creat */
1086 /* 9 */ { 0, "link" },
1087 /* 10 */ { 0, "unlink" },
1088 { 0, }, /* 11 is obsolete execv */
1089 /* 12 */ { 0, "chdir" },
1090 /* 13 */ { 0, "fchdir" },
1091 /* 14 */ { 0, "mknod" },
1092 /* 15 */ { 0, "chmod" },
1093 /* 16 */ { 0, "chown" },
1094 /* 17 */ { do_break
, "break" },
1095 /* 18 */ { 0, "getfsstat" },
1096 { 0, }, /* 19 is old lseek */
1097 /* 20 */ { do_getpid
, "getpid" },
1098 /* 21 */ { 0, "mount" },
1099 /* 22 */ { 0, "unmount" },
1100 /* 23 */ { 0, "setuid" },
1101 /* 24 */ { do_getuid
, "getuid" },
1102 /* 25 */ { do_geteuid
, "geteuid" },
1103 /* 26 */ { 0, "ptrace" },
1104 /* 27 */ { 0, "recvmsg" },
1105 /* 28 */ { 0, "sendmsg" },
1106 /* 29 */ { 0, "recvfrom" },
1107 /* 30 */ { 0, "accept" },
1108 /* 31 */ { 0, "getpeername" },
1109 /* 32 */ { 0, "getsockname" },
1110 /* 33 */ { 0, "access" },
1111 /* 34 */ { 0, "chflags" },
1112 /* 35 */ { 0, "fchflags" },
1113 /* 36 */ { 0, "sync" },
1114 /* 37 */ { do_kill
, "kill" },
1115 { 0, }, /* 38 is old stat */
1116 /* 39 */ { 0, "getppid" },
1117 { 0, }, /* 40 is old lstat */
1118 /* 41 */ { do_dup
, "dup" },
1119 /* 42 */ { 0, "pipe" },
1120 /* 43 */ { do_getegid
, "getegid" },
1121 /* 44 */ { 0, "profil" },
1122 /* 45 */ { 0, "ktrace" },
1123 /* 46 */ { 0, "sigaction" },
1124 /* 47 */ { do_getgid
, "getgid" },
1125 /* 48 */ { do_sigprocmask
, "sigprocmask" },
1126 /* 49 */ { 0, "getlogin" },
1127 /* 50 */ { 0, "setlogin" },
1128 /* 51 */ { 0, "acct" },
1129 /* 52 */ { 0, "sigpending" },
1130 /* 53 */ { 0, "sigaltstack" },
1131 /* 54 */ { do_ioctl
, "ioctl" },
1132 /* 55 */ { 0, "reboot" },
1133 /* 56 */ { 0, "revoke" },
1134 /* 57 */ { 0, "symlink" },
1135 /* 58 */ { 0, "readlink" },
1136 /* 59 */ { 0, "execve" },
1137 /* 60 */ { do_umask
, "umask" },
1138 /* 61 */ { 0, "chroot" },
1139 { 0, }, /* 62 is old fstat */
1140 { 0, }, /* 63 is old getkerninfo */
1141 { 0, }, /* 64 is old getpagesize */
1142 /* 65 */ { 0, "msync" },
1143 /* 66 */ { 0, "vfork" },
1144 { 0, }, /* 67 is obsolete vread */
1145 { 0, }, /* 68 is obsolete vwrite */
1146 /* 69 */ { 0, "sbrk" },
1147 /* 70 */ { 0, "sstk" },
1148 { 0, }, /* 71 is old mmap */
1149 /* 72 */ { 0, "vadvise" },
1150 /* 73 */ { 0, "munmap" },
1151 /* 74 */ { 0, "mprotect" },
1152 /* 75 */ { 0, "madvise" },
1153 { 0, }, /* 76 is obsolete vhangup */
1154 { 0, }, /* 77 is obsolete vlimit */
1155 /* 78 */ { 0, "mincore" },
1156 /* 79 */ { 0, "getgroups" },
1157 /* 80 */ { 0, "setgroups" },
1158 /* 81 */ { 0, "getpgrp" },
1159 /* 82 */ { 0, "setpgid" },
1160 /* 83 */ { 0, "setitimer" },
1161 { 0, }, /* 84 is old wait */
1162 /* 85 */ { 0, "swapon" },
1163 /* 86 */ { 0, "getitimer" },
1164 { 0, }, /* 87 is old gethostname */
1165 { 0, }, /* 88 is old sethostname */
1166 { 0, }, /* 89 is old getdtablesize */
1167 { do_dup2
, "dup2" },
1169 /* 92 */ { do_fcntl
, "fcntl" },
1170 /* 93 */ { 0, "select" },
1172 /* 95 */ { 0, "fsync" },
1173 /* 96 */ { 0, "setpriority" },
1174 /* 97 */ { 0, "socket" },
1175 /* 98 */ { 0, "connect" },
1176 { 0, }, /* 99 is old accept */
1177 /* 100 */ { 0, "getpriority" },
1178 { 0, }, /* 101 is old send */
1179 { 0, }, /* 102 is old recv */
1180 /* 103 */ { 0, "sigreturn" },
1181 /* 104 */ { 0, "bind" },
1182 /* 105 */ { 0, "setsockopt" },
1183 /* 106 */ { 0, "listen" },
1184 { 0, }, /* 107 is obsolete vtimes */
1185 { 0, }, /* 108 is old sigvec */
1186 { 0, }, /* 109 is old sigblock */
1187 { 0, }, /* 110 is old sigsetmask */
1188 /* 111 */ { 0, "sigsuspend" },
1189 { 0, }, /* 112 is old sigstack */
1190 { 0, }, /* 113 is old recvmsg */
1191 { 0, }, /* 114 is old sendmsg */
1192 /* - is obsolete vtrace */ { 0, "vtrace 115" },
1193 /* 116 */ { do_gettimeofday
, "gettimeofday" },
1194 /* 117 */ { do_getrusage
, "getrusage" },
1195 /* 118 */ { 0, "getsockopt" },
1196 /* 119 */ { 0, "resuba" },
1197 /* 120 */ { 0, "readv" },
1198 /* 121 */ { 0, "writev" },
1199 /* 122 */ { 0, "settimeofday" },
1200 /* 123 */ { 0, "fchown" },
1201 /* 124 */ { 0, "fchmod" },
1202 { 0, }, /* 125 is old recvfrom */
1203 { 0, }, /* 126 is old setreuid */
1204 { 0, }, /* 127 is old setregid */
1205 /* 128 */ { 0, "rename" },
1206 { 0, }, /* 129 is old truncate */
1207 { 0, }, /* 130 is old ftruncate */
1208 /* 131 */ { 0, "flock" },
1209 /* 132 */ { 0, "mkfifo" },
1210 /* 133 */ { 0, "sendto" },
1211 /* 134 */ { 0, "shutdown" },
1212 /* 135 */ { 0, "socketpair" },
1213 /* 136 */ { 0, "mkdir" },
1214 /* 137 */ { 0, "rmdir" },
1215 /* 138 */ { 0, "utimes" },
1216 { 0, }, /* 139 is obsolete 4.2 sigreturn */
1217 /* 140 */ { 0, "adjtime" },
1218 { 0, }, /* 141 is old getpeername */
1219 { 0, }, /* 142 is old gethostid */
1220 { 0, }, /* 143 is old sethostid */
1221 { 0, }, /* 144 is old getrlimit */
1222 { 0, }, /* 145 is old setrlimit */
1223 { 0, }, /* 146 is old killpg */
1224 /* 147 */ { 0, "setsid" },
1225 /* 148 */ { 0, "quotactl" },
1226 { 0, }, /* 149 is old quota */
1227 { 0, }, /* 150 is old getsockname */
1232 /* 155 */ { 0, "nfssvc" },
1233 { 0, }, /* 156 is old getdirentries */
1234 /* 157 */ { 0, "statfs" },
1235 /* 158 */ { do_fstatfs
, "fstatfs" },
1238 /* 161 */ { 0, "getfh" },
1239 { 0, }, /* 162 is old getdomainname */
1240 { 0, }, /* 163 is old setdomainname */
1241 { 0, }, /* 164 is old uname */
1242 /* 165 */ { 0, "sysarch" },
1246 /* 169 */ { 0, "semsys" },
1247 /* 170 */ { 0, "msgsys" },
1248 /* 171 */ { 0, "shmsys" },
1258 /* 181 */ { 0, "setgid" },
1259 /* 182 */ { 0, "setegid" },
1260 /* 183 */ { 0, "seteuid" },
1261 /* 184 */ { 0, "lfs_bmapv" },
1262 /* 185 */ { 0, "lfs_markv" },
1263 /* 186 */ { 0, "lfs_segclean" },
1264 /* 187 */ { 0, "lfs_segwait" },
1265 /* 188 */ { do_stat
, "stat" },
1266 /* 189 */ { do_fstat
, "fstat" },
1267 /* 190 */ { do_lstat
, "lstat" },
1268 /* 191 */ { 0, "pathconf" },
1269 /* 192 */ { 0, "fpathconf" },
1271 /* 194 */ { 0, "getrlimit" },
1272 /* 195 */ { 0, "setrlimit" },
1273 /* 196 */ { do_getdirentries
, "getdirentries" },
1274 /* 197 */ { 0, "mmap" },
1275 /* 198 */ { do___syscall
, "__syscall" },
1276 /* 199 */ { do_lseek
, "lseek" },
1277 /* 200 */ { 0, "truncate" },
1278 /* 201 */ { 0, "ftruncate" },
1279 /* 202 */ { do___sysctl
, "__sysctl" },
1280 /* 203 */ { 0, "mlock" },
1281 /* 204 */ { 0, "munlock" },
1284 static char *(netbsd_error_names
[]) = {
1321 /* 36 */ "EINPROGRESS",
1322 /* 37 */ "EALREADY",
1323 /* 38 */ "ENOTSOCK",
1324 /* 39 */ "EDESTADDRREQ",
1325 /* 40 */ "EMSGSIZE",
1326 /* 41 */ "EPROTOTYPE",
1327 /* 42 */ "ENOPROTOOPT",
1328 /* 43 */ "EPROTONOSUPPORT",
1329 /* 44 */ "ESOCKTNOSUPPORT",
1330 /* 45 */ "EOPNOTSUPP",
1331 /* 46 */ "EPFNOSUPPORT",
1332 /* 47 */ "EAFNOSUPPORT",
1333 /* 48 */ "EADDRINUSE",
1334 /* 49 */ "EADDRNOTAVAIL",
1335 /* 50 */ "ENETDOWN",
1336 /* 51 */ "ENETUNREACH",
1337 /* 52 */ "ENETRESET",
1338 /* 53 */ "ECONNABORTED",
1339 /* 54 */ "ECONNRESET",
1342 /* 57 */ "ENOTCONN",
1343 /* 58 */ "ESHUTDOWN",
1344 /* 59 */ "ETOOMANYREFS",
1345 /* 60 */ "ETIMEDOUT",
1346 /* 61 */ "ECONNREFUSED",
1348 /* 63 */ "ENAMETOOLONG",
1349 /* 64 */ "EHOSTDOWN",
1350 /* 65 */ "EHOSTUNREACH",
1351 /* 66 */ "ENOTEMPTY",
1352 /* 67 */ "EPROCLIM",
1358 /* 73 */ "ERPCMISMATCH",
1359 /* 74 */ "EPROGUNAVAIL",
1360 /* 75 */ "EPROGMISMATCH",
1361 /* 76 */ "EPROCUNAVAIL",
1366 /* 81 */ "ENEEDAUTH",
1369 /* 84 */ "EOVERFLOW",
1372 /* 87 */ "ECANCELED",
1379 /* 94 */ "EMULTIHOP",
1382 /* 97 */ "EOWNERDEAD",
1383 /* 98 */ "ENOTRECOVERABLE",
1387 static char *(netbsd_signal_names
[]) = {
1414 /* 26 */ "SIGVTALRM",
1416 /* 28 */ "SIGWINCH",
1421 /* 33 */ "SIGRTMIN",
1422 /* 34 */ "SIGRTMIN+1",
1423 /* 35 */ "SIGRTMIN+2",
1424 /* 36 */ "SIGRTMIN+3",
1425 /* 37 */ "SIGRTMIN+4",
1426 /* 38 */ "SIGRTMIN+5",
1427 /* 39 */ "SIGRTMIN+6",
1428 /* 40 */ "SIGRTMIN+7",
1429 /* 41 */ "SIGRTMIN+8",
1430 /* 42 */ "SIGRTMIN+9",
1431 /* 43 */ "SIGRTMIN+10",
1432 /* 44 */ "SIGRTMIN+11",
1433 /* 45 */ "SIGRTMIN+12",
1434 /* 46 */ "SIGRTMIN+13",
1435 /* 47 */ "SIGRTMIN+14",
1436 /* 48 */ "SIGRTMIN+15",
1437 /* 49 */ "SIGRTMIN+16",
1438 /* 50 */ "SIGRTMIN+17",
1439 /* 51 */ "SIGRTMIN+18",
1440 /* 52 */ "SIGRTMIN+19",
1441 /* 53 */ "SIGRTMIN+20",
1442 /* 54 */ "SIGRTMIN+21",
1443 /* 55 */ "SIGRTMIN+22",
1444 /* 56 */ "SIGRTMIN+23",
1445 /* 57 */ "SIGRTMIN+24",
1446 /* 58 */ "SIGRTMIN+25",
1447 /* 59 */ "SIGRTMIN+26",
1448 /* 60 */ "SIGRTMIN+27",
1449 /* 61 */ "SIGRTMIN+28",
1450 /* 62 */ "SIGRTMIN+29",
1451 /* 63 */ "SIGRTMAX",
1454 static emul_syscall emul_netbsd_syscalls
= {
1456 ARRAY_SIZE (netbsd_descriptors
),
1458 ARRAY_SIZE (netbsd_error_names
),
1459 netbsd_signal_names
,
1460 ARRAY_SIZE (netbsd_signal_names
),
1464 /* NetBSD's os_emul interface, most are just passed on to the generic
1467 static os_emul_data
*
1468 emul_netbsd_create(device
*root
,
1472 unsigned_word top_of_stack
;
1473 unsigned stack_size
;
1475 os_emul_data
*bsd_data
;
1479 /* check that this emulation is really for us */
1480 if (name
!= NULL
&& strcmp(name
, "netbsd") != 0)
1486 /* merge any emulation specific entries into the device tree */
1488 /* establish a few defaults */
1489 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
1491 top_of_stack
= 0xe0000000;
1492 stack_size
= 0x00100000;
1496 top_of_stack
= 0x20000000;
1497 stack_size
= 0x00100000;
1501 emul_add_tree_options(root
, image
, "netbsd",
1502 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
1503 ? "user" : "virtual"),
1504 0 /*oea-interrupt-prefix*/);
1506 /* virtual memory - handles growth of stack/heap */
1507 vm
= tree_parse(root
, "/openprom/vm");
1508 tree_parse(vm
, "./stack-base 0x%lx",
1509 (unsigned long)(top_of_stack
- stack_size
));
1510 tree_parse(vm
, "./nr-bytes 0x%x", stack_size
);
1512 filename
= tree_quote_property (bfd_get_filename(image
));
1513 tree_parse(root
, "/openprom/vm/map-binary/file-name %s",
1517 /* finish the init */
1518 tree_parse(root
, "/openprom/init/register/pc 0x%lx",
1519 (unsigned long)bfd_get_start_address(image
));
1520 tree_parse(root
, "/openprom/init/register/sp 0x%lx",
1521 (unsigned long)top_of_stack
);
1522 tree_parse(root
, "/openprom/init/register/msr 0x%x",
1523 ((tree_find_boolean_property(root
, "/options/little-endian?")
1524 ? msr_little_endian_mode
1526 | (tree_find_boolean_property(root
, "/openprom/options/floating-point?")
1527 ? (msr_floating_point_available
1528 | msr_floating_point_exception_mode_0
1529 | msr_floating_point_exception_mode_1
)
1531 tree_parse(root
, "/openprom/init/stack/stack-type %s",
1532 (elf_binary
? "ppc-elf" : "ppc-xcoff"));
1534 /* finally our emulation data */
1535 bsd_data
= ZALLOC(os_emul_data
);
1537 bsd_data
->syscalls
= &emul_netbsd_syscalls
;
1542 emul_netbsd_init(os_emul_data
*emul_data
,
1551 emul_netbsd_system_call(cpu
*processor
,
1553 os_emul_data
*emul_data
)
1555 emul_do_system_call(emul_data
,
1556 emul_data
->syscalls
,
1557 cpu_registers(processor
)->gpr
[0],
1558 3, /*r3 contains arg0*/
1563 const os_emul emul_netbsd
= {
1567 emul_netbsd_system_call
,
1568 0, /*instruction_call*/
1572 #endif /* _EMUL_NETBSD_C_ */