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
31 #include <sys/types.h>
37 #include <sys/param.h>
40 #include "emul_generic.h"
41 #include "emul_netbsd.h"
44 #ifndef HAVE_SYS_RESOURCE_H
50 #include <sys/resource.h>
55 #include <sys/ioctl.h>
60 # define NAMLEN(dirent) strlen((dirent)->d_name)
62 # define dirent direct
63 # define NAMLEN(dirent) (dirent)->d_namlen
65 # include <sys/ndir.h>
76 #undef MAXPATHLEN /* sys/param.h might define this also */
82 #define WITH_NetBSD_HOST (NetBSD >= 199306)
83 #if WITH_NetBSD_HOST /* here NetBSD as that is what we're emulating */
84 #include <sys/syscall.h> /* FIXME - should not be including this one */
85 #include <sys/sysctl.h>
86 #include <sys/mount.h>
87 extern int getdirentries(int fd
, char *buf
, int nbytes
, long *basep
);
89 /* NetBSD post 2.0 has the statfs system call (if COMPAT_20), but does
90 not have struct statfs. In this case don't implement fstatfs.
91 FIXME: Should implement fstatvfs. */
92 #ifndef HAVE_STRUCT_STATFS
98 /* If this is not netbsd, don't allow fstatfs or getdirentries at this time */
100 #undef HAVE_GETDIRENTRIES
103 #ifndef STATIC_INLINE_EMUL_NETBSD
104 #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
109 #define SYS(X) ASSERT(call == (SYS_##X))
114 #if WITH_NetBSD_HOST && (PATH_MAX != 1024)
115 #error "PATH_MAX not 1024"
116 #elif !defined(PATH_MAX)
117 #define PATH_MAX 1024
123 NetBSD - Emulation of user programs for NetBSD/PPC
130 /* NetBSD's idea of what is needed to implement emulations */
132 struct _os_emul_data
{
134 emul_syscall
*syscalls
;
139 STATIC_INLINE_EMUL_NETBSD
void
140 write_stat(unsigned_word addr
,
153 /* H2T(buf.st_spare1); */
155 /* H2T(buf.st_spare2); */
157 /* H2T(buf.st_spare3); */
158 #ifdef AC_STRUCT_ST_RDEV
161 #ifdef AC_STRUCT_ST_BLKSIZE
164 #ifdef AC_STRUCT_ST_BLOCKS
171 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
176 STATIC_INLINE_EMUL_NETBSD
void
177 write_statfs(unsigned_word addr
,
191 H2T(buf
.f_fsid
.val
[0]);
192 H2T(buf
.f_fsid
.val
[1]);
195 /* f_fstypename[MFSNAMELEN]; */
196 /* f_mntonname[MNAMELEN]; */
197 /* f_mntfromname[MNAMELEN]; */
198 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
203 STATIC_INLINE_EMUL_NETBSD
void
204 write_timeval(unsigned_word addr
,
211 emul_write_buffer(&t
, addr
, sizeof(t
), processor
, cia
);
214 #ifdef HAVE_GETTIMEOFDAY
215 STATIC_INLINE_EMUL_NETBSD
void
216 write_timezone(unsigned_word addr
,
221 H2T(tz
.tz_minuteswest
);
223 emul_write_buffer(&tz
, addr
, sizeof(tz
), processor
, cia
);
227 #ifdef HAVE_GETDIRENTRIES
228 STATIC_INLINE_EMUL_NETBSD
void
229 write_direntries(unsigned_word addr
,
237 struct dirent
*in
= (struct dirent
*)buf
;
238 ASSERT(in
->d_reclen
<= nbytes
);
239 out
= (struct dirent
*)zalloc(in
->d_reclen
);
240 memcpy(out
/*dest*/, in
/*src*/, in
->d_reclen
);
245 emul_write_buffer(out
, addr
, in
->d_reclen
, processor
, cia
);
246 nbytes
-= in
->d_reclen
;
247 addr
+= in
->d_reclen
;
255 #ifdef HAVE_GETRUSAGE
256 STATIC_INLINE_EMUL_NETBSD
void
257 write_rusage(unsigned_word addr
,
258 struct rusage rusage
,
262 H2T(rusage
.ru_utime
.tv_sec
); /* user time used */
263 H2T(rusage
.ru_utime
.tv_usec
);
264 H2T(rusage
.ru_stime
.tv_sec
); /* system time used */
265 H2T(rusage
.ru_stime
.tv_usec
);
266 H2T(rusage
.ru_maxrss
); /* integral max resident set size */
267 H2T(rusage
.ru_ixrss
); /* integral shared text memory size */
268 H2T(rusage
.ru_idrss
); /* integral unshared data size */
269 H2T(rusage
.ru_isrss
); /* integral unshared stack size */
270 H2T(rusage
.ru_minflt
); /* page reclaims */
271 H2T(rusage
.ru_majflt
); /* page faults */
272 H2T(rusage
.ru_nswap
); /* swaps */
273 H2T(rusage
.ru_inblock
); /* block input operations */
274 H2T(rusage
.ru_oublock
); /* block output operations */
275 H2T(rusage
.ru_msgsnd
); /* messages sent */
276 H2T(rusage
.ru_msgrcv
); /* messages received */
277 H2T(rusage
.ru_nsignals
); /* signals received */
278 H2T(rusage
.ru_nvcsw
); /* voluntary context switches */
279 H2T(rusage
.ru_nivcsw
); /* involuntary context switches */
280 emul_write_buffer(&rusage
, addr
, sizeof(rusage
), processor
, cia
);
285 /* File descriptors 0, 1, and 2 should not be closed. fd_closed[]
286 tracks whether these descriptors have been closed in do_close()
289 static int fd_closed
[3];
291 /* Check for some occurrences of bad file descriptors. We only check
292 whether fd 0, 1, or 2 are "closed". By "closed" we mean that these
293 descriptors aren't actually closed, but are considered to be closed
296 Other checks are performed by the underlying OS call. */
301 if (fd
>=0 && fd
<= 2 && fd_closed
[fd
])
310 do_exit(os_emul_data
*emul
,
316 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
318 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
319 printf_filtered ("%d)\n", status
);
321 cpu_halt(processor
, cia
, was_exited
, status
);
326 do_read(os_emul_data
*emul
,
332 void *scratch_buffer
;
333 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
334 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
335 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
339 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
340 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
342 /* get a tempoary bufer */
343 scratch_buffer
= zalloc(nbytes
);
345 /* check if buffer exists by reading it */
346 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
351 status
= fread (scratch_buffer
, 1, nbytes
, stdin
);
352 if (status
== 0 && ferror (stdin
))
358 status
= read (d
, scratch_buffer
, nbytes
);
360 emul_write_status(processor
, status
, errno
);
362 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
364 free(scratch_buffer
);
369 do_write(os_emul_data
*emul
,
375 void *scratch_buffer
= NULL
;
376 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
377 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
378 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
382 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
383 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
385 /* get a tempoary bufer */
386 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
389 emul_read_buffer(scratch_buffer
, buf
, nbytes
,
395 status
= write(d
, scratch_buffer
, nbytes
);
397 emul_write_status(processor
, status
, errno
);
398 free(scratch_buffer
);
405 do_open(os_emul_data
*emul
,
411 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
412 char path_buf
[PATH_MAX
];
413 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
414 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
415 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
419 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
420 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
424 /* Do some translation on 'flags' to match it to the host's version. */
425 /* These flag values were taken from the NetBSD 1.4 header files. */
426 if ((flags
& 3) == 0)
427 hostflags
= O_RDONLY
;
428 else if ((flags
& 3) == 1)
429 hostflags
= O_WRONLY
;
432 if (flags
& 0x00000008)
433 hostflags
|= O_APPEND
;
434 if (flags
& 0x00000200)
435 hostflags
|= O_CREAT
;
436 if (flags
& 0x00000400)
437 hostflags
|= O_TRUNC
;
438 if (flags
& 0x00000800)
441 /* Can't combine these statements, cuz open sets errno. */
442 status
= open(path
, hostflags
, mode
);
443 emul_write_status(processor
, status
, errno
);
448 do_close(os_emul_data
*emul
,
454 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
457 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
458 printf_filtered ("%d", d
);
465 /* Do not close stdin, stdout, or stderr. GDB may still need access to
466 these descriptors. */
467 if (d
== 0 || d
== 1 || d
== 2)
476 emul_write_status(processor
, status
, errno
);
481 do_break(os_emul_data
*emul
,
487 /* just pass this onto the `vm' device */
488 unsigned_word new_break
= cpu_registers(processor
)->gpr
[arg0
];
491 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
492 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
495 status
= device_ioctl(emul
->vm
,
499 new_break
); /*ioctl-data*/
500 emul_write_status(processor
, 0, status
);
508 do_getpid(os_emul_data
*emul
,
515 emul_write_status(processor
, (int)getpid(), 0);
523 do_getuid(os_emul_data
*emul
,
530 emul_write_status(processor
, (int)getuid(), 0);
538 do_geteuid(os_emul_data
*emul
,
545 emul_write_status(processor
, (int)geteuid(), 0);
553 do_kill(os_emul_data
*emul
,
559 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
560 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
562 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
563 printf_filtered ("%d, %d", (int)pid
, sig
);
566 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
568 cpu_halt(processor
, cia
, was_signalled
, sig
);
576 do_dup(os_emul_data
*emul
,
582 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
583 int status
= (fdbad (oldd
) < 0) ? -1 : dup(oldd
);
586 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
587 printf_filtered ("%d", oldd
);
590 emul_write_status(processor
, status
, err
);
598 do_getegid(os_emul_data
*emul
,
605 emul_write_status(processor
, (int)getegid(), 0);
613 do_getgid(os_emul_data
*emul
,
620 emul_write_status(processor
, (int)getgid(), 0);
624 #ifndef HAVE_SIGPROCMASK
625 #define do_sigprocmask 0
628 do_sigprocmask(os_emul_data
*emul
,
634 signed_word how
= cpu_registers(processor
)->gpr
[arg0
];
635 unsigned_word set
= cpu_registers(processor
)->gpr
[arg0
+1];
636 unsigned_word oset
= cpu_registers(processor
)->gpr
[arg0
+2];
637 #ifdef SYS_sigprocmask
641 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
642 printf_filtered ("%ld, 0x%lx, 0x%lx", (long)how
, (long)set
, (long)oset
);
644 emul_write_status(processor
, 0, 0);
645 cpu_registers(processor
)->gpr
[4] = set
;
653 do_ioctl(os_emul_data
*emul
,
659 int d
= cpu_registers(processor
)->gpr
[arg0
];
660 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
661 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
663 #if !WITH_NetBSD_HOST
664 cpu_registers(processor
)->gpr
[arg0
] = 0; /* just succeed */
666 unsigned dir
= request
& IOC_DIRMASK
;
669 /* what we haven't done */
670 if (dir
& IOC_IN
/* write into the io device */
672 || !(dir
& IOC_VOID
))
673 error("do_ioctl() read or write of parameter not implemented\n");
676 status
= ioctl(d
, request
, NULL
);
677 emul_write_status(processor
, status
, errno
);
680 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
681 printf_filtered ("%d, 0x%x, 0x%lx", d
, request
, (long)argp_addr
);
689 do_umask(os_emul_data
*emul
,
695 int mask
= cpu_registers(processor
)->gpr
[arg0
];
697 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
698 printf_filtered ("0%o", mask
);
701 emul_write_status(processor
, umask(mask
), 0);
709 do_dup2(os_emul_data
*emul
,
715 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
716 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
717 int status
= (fdbad (oldd
) < 0) ? -1 : dup2(oldd
, newd
);
720 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
721 printf_filtered ("%d, %d", oldd
, newd
);
724 emul_write_status(processor
, status
, err
);
732 do_fcntl(os_emul_data
*emul
,
738 int fd
= cpu_registers(processor
)->gpr
[arg0
];
739 int cmd
= cpu_registers(processor
)->gpr
[arg0
+1];
740 int arg
= cpu_registers(processor
)->gpr
[arg0
+2];
743 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
744 printf_filtered ("%d, %d, %d", fd
, cmd
, arg
);
749 status
= fcntl(fd
, cmd
, arg
);
750 emul_write_status(processor
, status
, errno
);
754 #ifndef HAVE_GETTIMEOFDAY
755 #define do_gettimeofday 0
758 do_gettimeofday(os_emul_data
*emul
,
764 unsigned_word t_addr
= cpu_registers(processor
)->gpr
[arg0
];
765 unsigned_word tz_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
768 int status
= gettimeofday(&t
, (tz_addr
!= 0 ? &tz
: NULL
));
771 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
772 printf_filtered ("0x%lx, 0x%lx", (long)t_addr
, (long)tz_addr
);
775 emul_write_status(processor
, status
, err
);
778 write_timeval(t_addr
, t
, processor
, cia
);
780 write_timezone(tz_addr
, tz
, processor
, cia
);
785 #ifndef HAVE_GETRUSAGE
786 #define do_getrusage 0
789 do_getrusage(os_emul_data
*emul
,
795 int who
= cpu_registers(processor
)->gpr
[arg0
];
796 unsigned_word rusage_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
797 struct rusage rusage
;
798 int status
= getrusage(who
, (rusage_addr
!= 0 ? &rusage
: NULL
));
801 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
802 printf_filtered ("%d, 0x%lx", who
, (long)rusage_addr
);
805 emul_write_status(processor
, status
, err
);
807 if (rusage_addr
!= 0)
808 write_rusage(rusage_addr
, rusage
, processor
, cia
);
818 do_fstatfs(os_emul_data
*emul
,
824 int fd
= cpu_registers(processor
)->gpr
[arg0
];
825 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
829 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
830 printf_filtered ("%d, 0x%lx", fd
, (long)buf_addr
);
835 status
= fstatfs(fd
, (buf_addr
== 0 ? NULL
: &buf
));
836 emul_write_status(processor
, status
, errno
);
839 write_statfs(buf_addr
, buf
, processor
, cia
);
848 do_stat(os_emul_data
*emul
,
854 char path_buf
[PATH_MAX
];
855 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
856 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
857 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
863 status
= stat(path
, &buf
);
864 emul_write_status(processor
, status
, errno
);
866 write_stat(stat_buf_addr
, buf
, processor
, cia
);
874 do_fstat(os_emul_data
*emul
,
880 int fd
= cpu_registers(processor
)->gpr
[arg0
];
881 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
887 /* Can't combine these statements, cuz fstat sets errno. */
890 status
= fstat(fd
, &buf
);
891 emul_write_status(processor
, status
, errno
);
892 write_stat(stat_buf_addr
, buf
, processor
, cia
);
900 do_lstat(os_emul_data
*emul
,
906 char path_buf
[PATH_MAX
];
907 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
908 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
909 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
915 /* Can't combine these statements, cuz lstat sets errno. */
916 status
= lstat(path
, &buf
);
917 emul_write_status(processor
, status
, errno
);
918 write_stat(stat_buf_addr
, buf
, processor
, cia
);
922 #ifndef HAVE_GETDIRENTRIES
923 #define do_getdirentries 0
926 do_getdirentries(os_emul_data
*emul
,
932 int fd
= cpu_registers(processor
)->gpr
[arg0
];
933 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
935 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
936 unsigned_word basep_addr
= cpu_registers(processor
)->gpr
[arg0
+3];
939 #ifdef SYS_getdirentries
942 if (buf_addr
!= 0 && nbytes
>= 0)
943 buf
= zalloc(nbytes
);
946 status
= getdirentries(fd
,
947 (buf_addr
== 0 ? NULL
: buf
),
949 (basep_addr
== 0 ? NULL
: &basep
));
950 emul_write_status(processor
, status
, errno
);
952 emul_write_word(basep_addr
, basep
, processor
, cia
);
954 write_direntries(buf_addr
, buf
, status
, processor
, cia
);
962 do___syscall(os_emul_data
*emul
,
969 emul_do_system_call(emul
,
971 cpu_registers(processor
)->gpr
[arg0
],
981 do_lseek(os_emul_data
*emul
,
987 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
988 off_t offset
= emul_read_gpr64(processor
, arg0
+2);
989 int whence
= cpu_registers(processor
)->gpr
[arg0
+4];
992 status
= fdbad (fildes
);
994 status
= lseek(fildes
, offset
, whence
);
996 emul_write_status(processor
, -1, errno
);
998 emul_write_status(processor
, 0, 0); /* success */
999 emul_write_gpr64(processor
, 3, status
);
1005 do___sysctl(os_emul_data
*emul
,
1011 /* call the arguments by their real name */
1012 unsigned_word name
= cpu_registers(processor
)->gpr
[arg0
];
1013 signed_word namelen
= cpu_registers(processor
)->gpr
[arg0
+1];
1014 unsigned_word oldp
= cpu_registers(processor
)->gpr
[arg0
+2];
1015 unsigned_word oldlenp
= cpu_registers(processor
)->gpr
[arg0
+3];
1018 signed_word int_val
;
1021 /* pluck out the management information base id */
1023 error("system_call()SYS___sysctl bad name[0]\n");
1024 mib
= vm_data_map_read_word(cpu_data_map(processor
),
1028 name
+= sizeof(mib
);
1030 /* see what to do with it ... */
1033 #if WITH_NetBSD_HOST && (CTL_HW != 6)
1037 error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
1038 mib
= vm_data_map_read_word(cpu_data_map(processor
),
1042 name
+= sizeof(mib
);
1044 case 7/*HW_PAGESIZE*/:
1045 #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
1046 # error "HW_PAGESIZE"
1048 oldlen
= vm_data_map_read_word(cpu_data_map(processor
),
1052 if (sizeof(signed_word
) > oldlen
)
1053 error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
1055 oldlen
= sizeof(int_val
);
1056 emul_write_word(oldp
, int_val
, processor
, cia
);
1057 emul_write_word(oldlenp
, oldlen
, processor
, cia
);
1060 error("sysctl() CTL_HW.%d unknown\n", mib
);
1065 error("sysctl() name[0]=%d unknown\n", (int)mib
);
1068 emul_write_status(processor
, 0, 0); /* always succeed */
1073 static emul_syscall_descriptor netbsd_descriptors
[] = {
1074 /* 0 */ { 0, "syscall" },
1075 /* 1 */ { do_exit
, "exit" },
1076 /* 2 */ { 0, "fork" },
1077 /* 3 */ { do_read
, "read" },
1078 /* 4 */ { do_write
, "write" },
1079 /* 5 */ { do_open
, "open" },
1080 /* 6 */ { do_close
, "close" },
1081 /* 7 */ { 0, "wait4" },
1082 { 0, }, /* 8 is old creat */
1083 /* 9 */ { 0, "link" },
1084 /* 10 */ { 0, "unlink" },
1085 { 0, }, /* 11 is obsolete execv */
1086 /* 12 */ { 0, "chdir" },
1087 /* 13 */ { 0, "fchdir" },
1088 /* 14 */ { 0, "mknod" },
1089 /* 15 */ { 0, "chmod" },
1090 /* 16 */ { 0, "chown" },
1091 /* 17 */ { do_break
, "break" },
1092 /* 18 */ { 0, "getfsstat" },
1093 { 0, }, /* 19 is old lseek */
1094 /* 20 */ { do_getpid
, "getpid" },
1095 /* 21 */ { 0, "mount" },
1096 /* 22 */ { 0, "unmount" },
1097 /* 23 */ { 0, "setuid" },
1098 /* 24 */ { do_getuid
, "getuid" },
1099 /* 25 */ { do_geteuid
, "geteuid" },
1100 /* 26 */ { 0, "ptrace" },
1101 /* 27 */ { 0, "recvmsg" },
1102 /* 28 */ { 0, "sendmsg" },
1103 /* 29 */ { 0, "recvfrom" },
1104 /* 30 */ { 0, "accept" },
1105 /* 31 */ { 0, "getpeername" },
1106 /* 32 */ { 0, "getsockname" },
1107 /* 33 */ { 0, "access" },
1108 /* 34 */ { 0, "chflags" },
1109 /* 35 */ { 0, "fchflags" },
1110 /* 36 */ { 0, "sync" },
1111 /* 37 */ { do_kill
, "kill" },
1112 { 0, }, /* 38 is old stat */
1113 /* 39 */ { 0, "getppid" },
1114 { 0, }, /* 40 is old lstat */
1115 /* 41 */ { do_dup
, "dup" },
1116 /* 42 */ { 0, "pipe" },
1117 /* 43 */ { do_getegid
, "getegid" },
1118 /* 44 */ { 0, "profil" },
1119 /* 45 */ { 0, "ktrace" },
1120 /* 46 */ { 0, "sigaction" },
1121 /* 47 */ { do_getgid
, "getgid" },
1122 /* 48 */ { do_sigprocmask
, "sigprocmask" },
1123 /* 49 */ { 0, "getlogin" },
1124 /* 50 */ { 0, "setlogin" },
1125 /* 51 */ { 0, "acct" },
1126 /* 52 */ { 0, "sigpending" },
1127 /* 53 */ { 0, "sigaltstack" },
1128 /* 54 */ { do_ioctl
, "ioctl" },
1129 /* 55 */ { 0, "reboot" },
1130 /* 56 */ { 0, "revoke" },
1131 /* 57 */ { 0, "symlink" },
1132 /* 58 */ { 0, "readlink" },
1133 /* 59 */ { 0, "execve" },
1134 /* 60 */ { do_umask
, "umask" },
1135 /* 61 */ { 0, "chroot" },
1136 { 0, }, /* 62 is old fstat */
1137 { 0, }, /* 63 is old getkerninfo */
1138 { 0, }, /* 64 is old getpagesize */
1139 /* 65 */ { 0, "msync" },
1140 /* 66 */ { 0, "vfork" },
1141 { 0, }, /* 67 is obsolete vread */
1142 { 0, }, /* 68 is obsolete vwrite */
1143 /* 69 */ { 0, "sbrk" },
1144 /* 70 */ { 0, "sstk" },
1145 { 0, }, /* 71 is old mmap */
1146 /* 72 */ { 0, "vadvise" },
1147 /* 73 */ { 0, "munmap" },
1148 /* 74 */ { 0, "mprotect" },
1149 /* 75 */ { 0, "madvise" },
1150 { 0, }, /* 76 is obsolete vhangup */
1151 { 0, }, /* 77 is obsolete vlimit */
1152 /* 78 */ { 0, "mincore" },
1153 /* 79 */ { 0, "getgroups" },
1154 /* 80 */ { 0, "setgroups" },
1155 /* 81 */ { 0, "getpgrp" },
1156 /* 82 */ { 0, "setpgid" },
1157 /* 83 */ { 0, "setitimer" },
1158 { 0, }, /* 84 is old wait */
1159 /* 85 */ { 0, "swapon" },
1160 /* 86 */ { 0, "getitimer" },
1161 { 0, }, /* 87 is old gethostname */
1162 { 0, }, /* 88 is old sethostname */
1163 { 0, }, /* 89 is old getdtablesize */
1164 { do_dup2
, "dup2" },
1166 /* 92 */ { do_fcntl
, "fcntl" },
1167 /* 93 */ { 0, "select" },
1169 /* 95 */ { 0, "fsync" },
1170 /* 96 */ { 0, "setpriority" },
1171 /* 97 */ { 0, "socket" },
1172 /* 98 */ { 0, "connect" },
1173 { 0, }, /* 99 is old accept */
1174 /* 100 */ { 0, "getpriority" },
1175 { 0, }, /* 101 is old send */
1176 { 0, }, /* 102 is old recv */
1177 /* 103 */ { 0, "sigreturn" },
1178 /* 104 */ { 0, "bind" },
1179 /* 105 */ { 0, "setsockopt" },
1180 /* 106 */ { 0, "listen" },
1181 { 0, }, /* 107 is obsolete vtimes */
1182 { 0, }, /* 108 is old sigvec */
1183 { 0, }, /* 109 is old sigblock */
1184 { 0, }, /* 110 is old sigsetmask */
1185 /* 111 */ { 0, "sigsuspend" },
1186 { 0, }, /* 112 is old sigstack */
1187 { 0, }, /* 113 is old recvmsg */
1188 { 0, }, /* 114 is old sendmsg */
1189 /* - is obsolete vtrace */ { 0, "vtrace 115" },
1190 /* 116 */ { do_gettimeofday
, "gettimeofday" },
1191 /* 117 */ { do_getrusage
, "getrusage" },
1192 /* 118 */ { 0, "getsockopt" },
1193 /* 119 */ { 0, "resuba" },
1194 /* 120 */ { 0, "readv" },
1195 /* 121 */ { 0, "writev" },
1196 /* 122 */ { 0, "settimeofday" },
1197 /* 123 */ { 0, "fchown" },
1198 /* 124 */ { 0, "fchmod" },
1199 { 0, }, /* 125 is old recvfrom */
1200 { 0, }, /* 126 is old setreuid */
1201 { 0, }, /* 127 is old setregid */
1202 /* 128 */ { 0, "rename" },
1203 { 0, }, /* 129 is old truncate */
1204 { 0, }, /* 130 is old ftruncate */
1205 /* 131 */ { 0, "flock" },
1206 /* 132 */ { 0, "mkfifo" },
1207 /* 133 */ { 0, "sendto" },
1208 /* 134 */ { 0, "shutdown" },
1209 /* 135 */ { 0, "socketpair" },
1210 /* 136 */ { 0, "mkdir" },
1211 /* 137 */ { 0, "rmdir" },
1212 /* 138 */ { 0, "utimes" },
1213 { 0, }, /* 139 is obsolete 4.2 sigreturn */
1214 /* 140 */ { 0, "adjtime" },
1215 { 0, }, /* 141 is old getpeername */
1216 { 0, }, /* 142 is old gethostid */
1217 { 0, }, /* 143 is old sethostid */
1218 { 0, }, /* 144 is old getrlimit */
1219 { 0, }, /* 145 is old setrlimit */
1220 { 0, }, /* 146 is old killpg */
1221 /* 147 */ { 0, "setsid" },
1222 /* 148 */ { 0, "quotactl" },
1223 { 0, }, /* 149 is old quota */
1224 { 0, }, /* 150 is old getsockname */
1229 /* 155 */ { 0, "nfssvc" },
1230 { 0, }, /* 156 is old getdirentries */
1231 /* 157 */ { 0, "statfs" },
1232 /* 158 */ { do_fstatfs
, "fstatfs" },
1235 /* 161 */ { 0, "getfh" },
1236 { 0, }, /* 162 is old getdomainname */
1237 { 0, }, /* 163 is old setdomainname */
1238 { 0, }, /* 164 is old uname */
1239 /* 165 */ { 0, "sysarch" },
1243 /* 169 */ { 0, "semsys" },
1244 /* 170 */ { 0, "msgsys" },
1245 /* 171 */ { 0, "shmsys" },
1255 /* 181 */ { 0, "setgid" },
1256 /* 182 */ { 0, "setegid" },
1257 /* 183 */ { 0, "seteuid" },
1258 /* 184 */ { 0, "lfs_bmapv" },
1259 /* 185 */ { 0, "lfs_markv" },
1260 /* 186 */ { 0, "lfs_segclean" },
1261 /* 187 */ { 0, "lfs_segwait" },
1262 /* 188 */ { do_stat
, "stat" },
1263 /* 189 */ { do_fstat
, "fstat" },
1264 /* 190 */ { do_lstat
, "lstat" },
1265 /* 191 */ { 0, "pathconf" },
1266 /* 192 */ { 0, "fpathconf" },
1268 /* 194 */ { 0, "getrlimit" },
1269 /* 195 */ { 0, "setrlimit" },
1270 /* 196 */ { do_getdirentries
, "getdirentries" },
1271 /* 197 */ { 0, "mmap" },
1272 /* 198 */ { do___syscall
, "__syscall" },
1273 /* 199 */ { do_lseek
, "lseek" },
1274 /* 200 */ { 0, "truncate" },
1275 /* 201 */ { 0, "ftruncate" },
1276 /* 202 */ { do___sysctl
, "__sysctl" },
1277 /* 203 */ { 0, "mlock" },
1278 /* 204 */ { 0, "munlock" },
1281 static char *(netbsd_error_names
[]) = {
1318 /* 36 */ "EINPROGRESS",
1319 /* 37 */ "EALREADY",
1320 /* 38 */ "ENOTSOCK",
1321 /* 39 */ "EDESTADDRREQ",
1322 /* 40 */ "EMSGSIZE",
1323 /* 41 */ "EPROTOTYPE",
1324 /* 42 */ "ENOPROTOOPT",
1325 /* 43 */ "EPROTONOSUPPORT",
1326 /* 44 */ "ESOCKTNOSUPPORT",
1327 /* 45 */ "EOPNOTSUPP",
1328 /* 46 */ "EPFNOSUPPORT",
1329 /* 47 */ "EAFNOSUPPORT",
1330 /* 48 */ "EADDRINUSE",
1331 /* 49 */ "EADDRNOTAVAIL",
1332 /* 50 */ "ENETDOWN",
1333 /* 51 */ "ENETUNREACH",
1334 /* 52 */ "ENETRESET",
1335 /* 53 */ "ECONNABORTED",
1336 /* 54 */ "ECONNRESET",
1339 /* 57 */ "ENOTCONN",
1340 /* 58 */ "ESHUTDOWN",
1341 /* 59 */ "ETOOMANYREFS",
1342 /* 60 */ "ETIMEDOUT",
1343 /* 61 */ "ECONNREFUSED",
1345 /* 63 */ "ENAMETOOLONG",
1346 /* 64 */ "EHOSTDOWN",
1347 /* 65 */ "EHOSTUNREACH",
1348 /* 66 */ "ENOTEMPTY",
1349 /* 67 */ "EPROCLIM",
1355 /* 73 */ "ERPCMISMATCH",
1356 /* 74 */ "EPROGUNAVAIL",
1357 /* 75 */ "EPROGMISMATCH",
1358 /* 76 */ "EPROCUNAVAIL",
1363 /* 81 */ "ENEEDAUTH",
1366 /* 84 */ "EOVERFLOW",
1369 /* 87 */ "ECANCELED",
1376 /* 94 */ "EMULTIHOP",
1379 /* 97 */ "EOWNERDEAD",
1380 /* 98 */ "ENOTRECOVERABLE",
1384 static char *(netbsd_signal_names
[]) = {
1411 /* 26 */ "SIGVTALRM",
1413 /* 28 */ "SIGWINCH",
1418 /* 33 */ "SIGRTMIN",
1419 /* 34 */ "SIGRTMIN+1",
1420 /* 35 */ "SIGRTMIN+2",
1421 /* 36 */ "SIGRTMIN+3",
1422 /* 37 */ "SIGRTMIN+4",
1423 /* 38 */ "SIGRTMIN+5",
1424 /* 39 */ "SIGRTMIN+6",
1425 /* 40 */ "SIGRTMIN+7",
1426 /* 41 */ "SIGRTMIN+8",
1427 /* 42 */ "SIGRTMIN+9",
1428 /* 43 */ "SIGRTMIN+10",
1429 /* 44 */ "SIGRTMIN+11",
1430 /* 45 */ "SIGRTMIN+12",
1431 /* 46 */ "SIGRTMIN+13",
1432 /* 47 */ "SIGRTMIN+14",
1433 /* 48 */ "SIGRTMIN+15",
1434 /* 49 */ "SIGRTMIN+16",
1435 /* 50 */ "SIGRTMIN+17",
1436 /* 51 */ "SIGRTMIN+18",
1437 /* 52 */ "SIGRTMIN+19",
1438 /* 53 */ "SIGRTMIN+20",
1439 /* 54 */ "SIGRTMIN+21",
1440 /* 55 */ "SIGRTMIN+22",
1441 /* 56 */ "SIGRTMIN+23",
1442 /* 57 */ "SIGRTMIN+24",
1443 /* 58 */ "SIGRTMIN+25",
1444 /* 59 */ "SIGRTMIN+26",
1445 /* 60 */ "SIGRTMIN+27",
1446 /* 61 */ "SIGRTMIN+28",
1447 /* 62 */ "SIGRTMIN+29",
1448 /* 63 */ "SIGRTMAX",
1451 static emul_syscall emul_netbsd_syscalls
= {
1453 ARRAY_SIZE (netbsd_descriptors
),
1455 ARRAY_SIZE (netbsd_error_names
),
1456 netbsd_signal_names
,
1457 ARRAY_SIZE (netbsd_signal_names
),
1461 /* NetBSD's os_emul interface, most are just passed on to the generic
1464 static os_emul_data
*
1465 emul_netbsd_create(device
*root
,
1469 unsigned_word top_of_stack
;
1470 unsigned stack_size
;
1472 os_emul_data
*bsd_data
;
1476 /* check that this emulation is really for us */
1477 if (name
!= NULL
&& strcmp(name
, "netbsd") != 0)
1483 /* merge any emulation specific entries into the device tree */
1485 /* establish a few defaults */
1486 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
1488 top_of_stack
= 0xe0000000;
1489 stack_size
= 0x00100000;
1493 top_of_stack
= 0x20000000;
1494 stack_size
= 0x00100000;
1498 emul_add_tree_options(root
, image
, "netbsd",
1499 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
1500 ? "user" : "virtual"),
1501 0 /*oea-interrupt-prefix*/);
1503 /* virtual memory - handles growth of stack/heap */
1504 vm
= tree_parse(root
, "/openprom/vm");
1505 tree_parse(vm
, "./stack-base 0x%lx",
1506 (unsigned long)(top_of_stack
- stack_size
));
1507 tree_parse(vm
, "./nr-bytes 0x%x", stack_size
);
1509 filename
= tree_quote_property (bfd_get_filename(image
));
1510 tree_parse(root
, "/openprom/vm/map-binary/file-name %s",
1514 /* finish the init */
1515 tree_parse(root
, "/openprom/init/register/pc 0x%lx",
1516 (unsigned long)bfd_get_start_address(image
));
1517 tree_parse(root
, "/openprom/init/register/sp 0x%lx",
1518 (unsigned long)top_of_stack
);
1519 tree_parse(root
, "/openprom/init/register/msr 0x%x",
1520 ((tree_find_boolean_property(root
, "/options/little-endian?")
1521 ? msr_little_endian_mode
1523 | (tree_find_boolean_property(root
, "/openprom/options/floating-point?")
1524 ? (msr_floating_point_available
1525 | msr_floating_point_exception_mode_0
1526 | msr_floating_point_exception_mode_1
)
1528 tree_parse(root
, "/openprom/init/stack/stack-type %s",
1529 (elf_binary
? "ppc-elf" : "ppc-xcoff"));
1531 /* finally our emulation data */
1532 bsd_data
= ZALLOC(os_emul_data
);
1534 bsd_data
->syscalls
= &emul_netbsd_syscalls
;
1539 emul_netbsd_init(os_emul_data
*emul_data
,
1548 emul_netbsd_system_call(cpu
*processor
,
1550 os_emul_data
*emul_data
)
1552 emul_do_system_call(emul_data
,
1553 emul_data
->syscalls
,
1554 cpu_registers(processor
)->gpr
[0],
1555 3, /*r3 contains arg0*/
1560 const os_emul emul_netbsd
= {
1564 emul_netbsd_system_call
,
1565 0, /*instruction_call*/
1569 #endif /* _EMUL_NETBSD_C_ */