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 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>
66 # define NAMLEN(dirent) strlen((dirent)->d_name)
68 # define dirent direct
69 # define NAMLEN(dirent) (dirent)->d_namlen
71 # include <sys/ndir.h>
82 #undef MAXPATHLEN /* sys/param.h might define this also */
90 #define WITH_NetBSD_HOST (NetBSD >= 199306)
91 #if WITH_NetBSD_HOST /* here NetBSD as that is what we're emulating */
92 #include <sys/syscall.h> /* FIXME - should not be including this one */
93 #include <sys/sysctl.h>
94 extern int getdirentries(int fd
, char *buf
, int nbytes
, long *basep
);
97 /* If this is not netbsd, don't allow fstatfs or getdirentries at this time */
99 #undef HAVE_GETDIRENTRIES
102 #if (BSD < 199306) /* here BSD as just a bug */
106 #ifndef STATIC_INLINE_EMUL_NETBSD
107 #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
112 #define SYS(X) ASSERT(call == (SYS_##X))
117 #if WITH_NetBSD_HOST && (PATH_MAX != 1024)
118 #error "PATH_MAX not 1024"
119 #elif !defined(PATH_MAX)
120 #define PATH_MAX 1024
126 NetBSD - Emulation of user programs for NetBSD/PPC
133 /* NetBSD's idea of what is needed to implement emulations */
135 struct _os_emul_data
{
137 emul_syscall
*syscalls
;
142 STATIC_INLINE_EMUL_NETBSD
void
143 write_stat(unsigned_word addr
,
156 /* H2T(buf.st_spare1); */
158 /* H2T(buf.st_spare2); */
160 /* H2T(buf.st_spare3); */
161 #ifdef AC_STRUCT_ST_RDEV
164 #ifdef AC_STRUCT_ST_BLKSIZE
167 #ifdef AC_STRUCT_ST_BLOCKS
174 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
179 STATIC_INLINE_EMUL_NETBSD
void
180 write_statfs(unsigned_word addr
,
194 H2T(buf
.f_fsid
.val
[0]);
195 H2T(buf
.f_fsid
.val
[1]);
198 /* f_fstypename[MFSNAMELEN]; */
199 /* f_mntonname[MNAMELEN]; */
200 /* f_mntfromname[MNAMELEN]; */
201 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
206 STATIC_INLINE_EMUL_NETBSD
void
207 write_timeval(unsigned_word addr
,
214 emul_write_buffer(&t
, addr
, sizeof(t
), processor
, cia
);
218 STATIC_INLINE_EMUL_NETBSD
void
219 write_timezone(unsigned_word addr
,
224 H2T(tz
.tz_minuteswest
);
226 emul_write_buffer(&tz
, addr
, sizeof(tz
), processor
, cia
);
230 #ifdef HAVE_GETDIRENTRIES
231 STATIC_INLINE_EMUL_NETBSD
void
232 write_direntries(unsigned_word addr
,
240 struct dirent
*in
= (struct dirent
*)buf
;
241 ASSERT(in
->d_reclen
<= nbytes
);
242 out
= (struct dirent
*)zalloc(in
->d_reclen
);
243 memcpy(out
/*dest*/, in
/*src*/, in
->d_reclen
);
248 emul_write_buffer(out
, addr
, in
->d_reclen
, processor
, cia
);
249 nbytes
-= in
->d_reclen
;
250 addr
+= in
->d_reclen
;
258 #ifdef HAVE_GETRUSAGE
259 STATIC_INLINE_EMUL_NETBSD
void
260 write_rusage(unsigned_word addr
,
261 struct rusage rusage
,
265 H2T(rusage
.ru_utime
.tv_sec
); /* user time used */
266 H2T(rusage
.ru_utime
.tv_usec
);
267 H2T(rusage
.ru_stime
.tv_sec
); /* system time used */
268 H2T(rusage
.ru_stime
.tv_usec
);
269 H2T(rusage
.ru_maxrss
); /* integral max resident set size */
270 H2T(rusage
.ru_ixrss
); /* integral shared text memory size */
271 H2T(rusage
.ru_idrss
); /* integral unshared data size */
272 H2T(rusage
.ru_isrss
); /* integral unshared stack size */
273 H2T(rusage
.ru_minflt
); /* page reclaims */
274 H2T(rusage
.ru_majflt
); /* page faults */
275 H2T(rusage
.ru_nswap
); /* swaps */
276 H2T(rusage
.ru_inblock
); /* block input operations */
277 H2T(rusage
.ru_oublock
); /* block output operations */
278 H2T(rusage
.ru_msgsnd
); /* messages sent */
279 H2T(rusage
.ru_msgrcv
); /* messages received */
280 H2T(rusage
.ru_nsignals
); /* signals received */
281 H2T(rusage
.ru_nvcsw
); /* voluntary context switches */
282 H2T(rusage
.ru_nivcsw
); /* involuntary context switches */
283 emul_write_buffer(&rusage
, addr
, sizeof(rusage
), processor
, cia
);
288 do_exit(os_emul_data
*emul
,
294 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
296 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
297 printf_filtered ("%d)\n", status
);
299 cpu_halt(processor
, cia
, was_exited
, status
);
304 do_read(os_emul_data
*emul
,
310 void *scratch_buffer
;
311 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
312 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
313 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
317 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
318 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
320 /* get a tempoary bufer */
321 scratch_buffer
= zalloc(nbytes
);
323 /* check if buffer exists by reading it */
324 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
329 status
= fread (scratch_buffer
, 1, nbytes
, stdin
);
330 if (status
== 0 && ferror (stdin
))
334 status
= read (d
, scratch_buffer
, nbytes
);
336 emul_write_status(processor
, status
, errno
);
338 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
340 zfree(scratch_buffer
);
345 do_write(os_emul_data
*emul
,
351 void *scratch_buffer
= NULL
;
352 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
353 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
354 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
358 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
359 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
361 /* get a tempoary bufer */
362 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
365 emul_read_buffer(scratch_buffer
, buf
, nbytes
,
369 status
= write(d
, scratch_buffer
, nbytes
);
370 emul_write_status(processor
, status
, errno
);
371 zfree(scratch_buffer
);
378 do_open(os_emul_data
*emul
,
384 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
385 char path_buf
[PATH_MAX
];
386 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
387 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
388 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
391 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
392 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
396 /* Can't combine these statements, cuz open sets errno. */
397 status
= open(path
, flags
, mode
);
398 emul_write_status(processor
, status
, errno
);
403 do_close(os_emul_data
*emul
,
409 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
412 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
413 printf_filtered ("%d", d
);
417 /* Can't combine these statements, cuz close sets errno. */
419 emul_write_status(processor
, status
, errno
);
424 do_break(os_emul_data
*emul
,
430 /* just pass this onto the `vm' device */
431 unsigned_word new_break
= cpu_registers(processor
)->gpr
[arg0
];
434 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
435 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
438 status
= device_ioctl(emul
->vm
,
442 new_break
); /*ioctl-data*/
443 emul_write_status(processor
, 0, status
);
451 do_getpid(os_emul_data
*emul
,
458 emul_write_status(processor
, (int)getpid(), 0);
466 do_getuid(os_emul_data
*emul
,
473 emul_write_status(processor
, (int)getuid(), 0);
481 do_geteuid(os_emul_data
*emul
,
488 emul_write_status(processor
, (int)geteuid(), 0);
496 do_kill(os_emul_data
*emul
,
502 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
503 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
505 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
506 printf_filtered ("%d, %d", (int)pid
, sig
);
509 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
511 cpu_halt(processor
, cia
, was_signalled
, sig
);
519 do_dup(os_emul_data
*emul
,
525 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
526 int status
= dup(oldd
);
529 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
530 printf_filtered ("%d", oldd
);
533 emul_write_status(processor
, status
, err
);
541 do_getegid(os_emul_data
*emul
,
548 emul_write_status(processor
, (int)getegid(), 0);
556 do_getgid(os_emul_data
*emul
,
563 emul_write_status(processor
, (int)getgid(), 0);
567 #ifndef HAVE_SIGPROCMASK
568 #define do_sigprocmask 0
571 do_sigprocmask(os_emul_data
*emul
,
577 natural_word how
= cpu_registers(processor
)->gpr
[arg0
];
578 unsigned_word set
= cpu_registers(processor
)->gpr
[arg0
+1];
579 unsigned_word oset
= cpu_registers(processor
)->gpr
[arg0
+2];
582 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
583 printf_filtered ("%ld, 0x%ld, 0x%ld", (long)how
, (long)set
, (long)oset
);
585 emul_write_status(processor
, 0, 0);
586 cpu_registers(processor
)->gpr
[4] = set
;
594 do_ioctl(os_emul_data
*emul
,
600 int d
= cpu_registers(processor
)->gpr
[arg0
];
601 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
602 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
604 #if !WITH_NetBSD_HOST
605 cpu_registers(processor
)->gpr
[arg0
] = 0; /* just succeed */
607 unsigned dir
= request
& IOC_DIRMASK
;
610 /* what we haven't done */
611 if (dir
& IOC_IN
/* write into the io device */
613 || !(dir
& IOC_VOID
))
614 error("do_ioctl() read or write of parameter not implemented\n");
615 status
= ioctl(d
, request
, NULL
);
616 emul_write_status(processor
, status
, errno
);
619 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
620 printf_filtered ("%d, 0x%x, 0x%lx", d
, request
, (long)argp_addr
);
628 do_umask(os_emul_data
*emul
,
634 int mask
= cpu_registers(processor
)->gpr
[arg0
];
636 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
637 printf_filtered ("0%o", mask
);
640 emul_write_status(processor
, umask(mask
), 0);
648 do_dup2(os_emul_data
*emul
,
654 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
655 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
656 int status
= dup2(oldd
, newd
);
659 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
660 printf_filtered ("%d, %d", oldd
, newd
);
663 emul_write_status(processor
, status
, err
);
671 do_fcntl(os_emul_data
*emul
,
677 int fd
= cpu_registers(processor
)->gpr
[arg0
];
678 int cmd
= cpu_registers(processor
)->gpr
[arg0
+1];
679 int arg
= cpu_registers(processor
)->gpr
[arg0
+2];
682 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
683 printf_filtered ("%d, %d, %d", fd
, cmd
, arg
);
686 status
= fcntl(fd
, cmd
, arg
);
687 emul_write_status(processor
, status
, errno
);
691 #ifndef HAVE_GETTIMEOFDAY
692 #define do_gettimeofday 0
695 do_gettimeofday(os_emul_data
*emul
,
701 unsigned_word t_addr
= cpu_registers(processor
)->gpr
[arg0
];
702 unsigned_word tz_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
705 int status
= gettimeofday((t_addr
!= 0 ? &t
: NULL
),
706 (tz_addr
!= 0 ? &tz
: NULL
));
709 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
710 printf_filtered ("0x%lx, 0x%lx", (long)t_addr
, (long)tz_addr
);
713 emul_write_status(processor
, status
, err
);
716 write_timeval(t_addr
, t
, processor
, cia
);
718 write_timezone(tz_addr
, tz
, processor
, cia
);
723 #ifndef HAVE_GETRUSAGE
724 #define do_getrusage 0
727 do_getrusage(os_emul_data
*emul
,
733 int who
= cpu_registers(processor
)->gpr
[arg0
];
734 unsigned_word rusage_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
735 struct rusage rusage
;
736 int status
= getrusage(who
, (rusage_addr
!= 0 ? &rusage
: NULL
));
739 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
740 printf_filtered ("%d, 0x%lx", who
, (long)rusage_addr
);
743 emul_write_status(processor
, status
, err
);
745 if (rusage_addr
!= 0)
746 write_rusage(rusage_addr
, rusage
, processor
, cia
);
756 do_fstatfs(os_emul_data
*emul
,
762 int fd
= cpu_registers(processor
)->gpr
[arg0
];
763 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
767 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
768 printf_filtered ("%d, 0x%lx", fd
, (long)buf_addr
);
771 status
= fstatfs(fd
, (buf_addr
== 0 ? NULL
: &buf
));
772 emul_write_status(processor
, status
, errno
);
775 write_statfs(buf_addr
, buf
, processor
, cia
);
784 do_stat(os_emul_data
*emul
,
790 char path_buf
[PATH_MAX
];
791 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
792 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
793 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
797 status
= stat(path
, &buf
);
798 emul_write_status(processor
, status
, errno
);
800 write_stat(stat_buf_addr
, buf
, processor
, cia
);
808 do_fstat(os_emul_data
*emul
,
814 int fd
= cpu_registers(processor
)->gpr
[arg0
];
815 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
819 /* Can't combine these statements, cuz fstat sets errno. */
820 status
= fstat(fd
, &buf
);
821 emul_write_status(processor
, status
, errno
);
822 write_stat(stat_buf_addr
, buf
, processor
, cia
);
830 do_lstat(os_emul_data
*emul
,
836 char path_buf
[PATH_MAX
];
837 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
838 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
839 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
843 /* Can't combine these statements, cuz lstat sets errno. */
844 status
= lstat(path
, &buf
);
845 emul_write_status(processor
, status
, errno
);
846 write_stat(stat_buf_addr
, buf
, processor
, cia
);
850 #ifndef HAVE_GETDIRENTRIES
851 #define do_getdirentries 0
854 do_getdirentries(os_emul_data
*emul
,
860 int fd
= cpu_registers(processor
)->gpr
[arg0
];
861 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
863 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
864 unsigned_word basep_addr
= cpu_registers(processor
)->gpr
[arg0
+3];
868 if (buf_addr
!= 0 && nbytes
>= 0)
869 buf
= zalloc(nbytes
);
872 status
= getdirentries(fd
,
873 (buf_addr
== 0 ? NULL
: buf
),
875 (basep_addr
== 0 ? NULL
: &basep
));
876 emul_write_status(processor
, status
, errno
);
878 emul_write_word(basep_addr
, basep
, processor
, cia
);
880 write_direntries(buf_addr
, buf
, status
, processor
, cia
);
888 do___syscall(os_emul_data
*emul
,
895 emul_do_system_call(emul
,
897 cpu_registers(processor
)->gpr
[arg0
],
907 do_lseek(os_emul_data
*emul
,
913 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
914 off_t offset
= emul_read_gpr64(processor
, arg0
+2);
915 int whence
= cpu_registers(processor
)->gpr
[arg0
+4];
918 status
= lseek(fildes
, offset
, whence
);
920 emul_write_status(processor
, -1, errno
);
922 emul_write_status(processor
, 0, 0); /* success */
923 emul_write_gpr64(processor
, 3, status
);
929 do___sysctl(os_emul_data
*emul
,
935 /* call the arguments by their real name */
936 unsigned_word name
= cpu_registers(processor
)->gpr
[arg0
];
937 natural_word namelen
= cpu_registers(processor
)->gpr
[arg0
+1];
938 unsigned_word oldp
= cpu_registers(processor
)->gpr
[arg0
+2];
939 unsigned_word oldlenp
= cpu_registers(processor
)->gpr
[arg0
+3];
942 natural_word int_val
;
945 /* pluck out the management information base id */
947 error("system_call()SYS___sysctl bad name[0]\n");
948 mib
= vm_data_map_read_word(cpu_data_map(processor
),
954 /* see what to do with it ... */
957 #if WITH_NetBSD_HOST && (CTL_HW != 6)
961 error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
962 mib
= vm_data_map_read_word(cpu_data_map(processor
),
968 case 7/*HW_PAGESIZE*/:
969 #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
970 # error "HW_PAGESIZE"
972 oldlen
= vm_data_map_read_word(cpu_data_map(processor
),
976 if (sizeof(natural_word
) > oldlen
)
977 error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
979 oldlen
= sizeof(int_val
);
980 emul_write_word(oldp
, int_val
, processor
, cia
);
981 emul_write_word(oldlenp
, oldlen
, processor
, cia
);
984 error("sysctl() CTL_HW.%d unknown\n", mib
);
989 error("sysctl() name[0]=%d unknown\n", (int)mib
);
992 emul_write_status(processor
, 0, 0); /* always succeed */
997 static emul_syscall_descriptor netbsd_descriptors
[] = {
998 /* 0 */ { 0, "syscall" },
999 /* 1 */ { do_exit
, "exit" },
1000 /* 2 */ { 0, "fork" },
1001 /* 3 */ { do_read
, "read" },
1002 /* 4 */ { do_write
, "write" },
1003 /* 5 */ { do_open
, "open" },
1004 /* 6 */ { do_close
, "close" },
1005 /* 7 */ { 0, "wait4" },
1006 { 0, }, /* 8 is old creat */
1007 /* 9 */ { 0, "link" },
1008 /* 10 */ { 0, "unlink" },
1009 { 0, }, /* 11 is obsolete execv */
1010 /* 12 */ { 0, "chdir" },
1011 /* 13 */ { 0, "fchdir" },
1012 /* 14 */ { 0, "mknod" },
1013 /* 15 */ { 0, "chmod" },
1014 /* 16 */ { 0, "chown" },
1015 /* 17 */ { do_break
, "break" },
1016 /* 18 */ { 0, "getfsstat" },
1017 { 0, }, /* 19 is old lseek */
1018 /* 20 */ { do_getpid
, "getpid" },
1019 /* 21 */ { 0, "mount" },
1020 /* 22 */ { 0, "unmount" },
1021 /* 23 */ { 0, "setuid" },
1022 /* 24 */ { do_getuid
, "getuid" },
1023 /* 25 */ { do_geteuid
, "geteuid" },
1024 /* 26 */ { 0, "ptrace" },
1025 /* 27 */ { 0, "recvmsg" },
1026 /* 28 */ { 0, "sendmsg" },
1027 /* 29 */ { 0, "recvfrom" },
1028 /* 30 */ { 0, "accept" },
1029 /* 31 */ { 0, "getpeername" },
1030 /* 32 */ { 0, "getsockname" },
1031 /* 33 */ { 0, "access" },
1032 /* 34 */ { 0, "chflags" },
1033 /* 35 */ { 0, "fchflags" },
1034 /* 36 */ { 0, "sync" },
1035 /* 37 */ { do_kill
, "kill" },
1036 { 0, }, /* 38 is old stat */
1037 /* 39 */ { 0, "getppid" },
1038 { 0, }, /* 40 is old lstat */
1039 /* 41 */ { do_dup
, "dup" },
1040 /* 42 */ { 0, "pipe" },
1041 /* 43 */ { do_getegid
, "getegid" },
1042 /* 44 */ { 0, "profil" },
1043 /* 45 */ { 0, "ktrace" },
1044 /* 46 */ { 0, "sigaction" },
1045 /* 47 */ { do_getgid
, "getgid" },
1046 /* 48 */ { do_sigprocmask
, "sigprocmask" },
1047 /* 49 */ { 0, "getlogin" },
1048 /* 50 */ { 0, "setlogin" },
1049 /* 51 */ { 0, "acct" },
1050 /* 52 */ { 0, "sigpending" },
1051 /* 53 */ { 0, "sigaltstack" },
1052 /* 54 */ { do_ioctl
, "ioctl" },
1053 /* 55 */ { 0, "reboot" },
1054 /* 56 */ { 0, "revoke" },
1055 /* 57 */ { 0, "symlink" },
1056 /* 58 */ { 0, "readlink" },
1057 /* 59 */ { 0, "execve" },
1058 /* 60 */ { do_umask
, "umask" },
1059 /* 61 */ { 0, "chroot" },
1060 { 0, }, /* 62 is old fstat */
1061 { 0, }, /* 63 is old getkerninfo */
1062 { 0, }, /* 64 is old getpagesize */
1063 /* 65 */ { 0, "msync" },
1064 /* 66 */ { 0, "vfork" },
1065 { 0, }, /* 67 is obsolete vread */
1066 { 0, }, /* 68 is obsolete vwrite */
1067 /* 69 */ { 0, "sbrk" },
1068 /* 70 */ { 0, "sstk" },
1069 { 0, }, /* 71 is old mmap */
1070 /* 72 */ { 0, "vadvise" },
1071 /* 73 */ { 0, "munmap" },
1072 /* 74 */ { 0, "mprotect" },
1073 /* 75 */ { 0, "madvise" },
1074 { 0, }, /* 76 is obsolete vhangup */
1075 { 0, }, /* 77 is obsolete vlimit */
1076 /* 78 */ { 0, "mincore" },
1077 /* 79 */ { 0, "getgroups" },
1078 /* 80 */ { 0, "setgroups" },
1079 /* 81 */ { 0, "getpgrp" },
1080 /* 82 */ { 0, "setpgid" },
1081 /* 83 */ { 0, "setitimer" },
1082 { 0, }, /* 84 is old wait */
1083 /* 85 */ { 0, "swapon" },
1084 /* 86 */ { 0, "getitimer" },
1085 { 0, }, /* 87 is old gethostname */
1086 { 0, }, /* 88 is old sethostname */
1087 { 0, }, /* 89 is old getdtablesize */
1088 { do_dup2
, "dup2" },
1090 /* 92 */ { do_fcntl
, "fcntl" },
1091 /* 93 */ { 0, "select" },
1093 /* 95 */ { 0, "fsync" },
1094 /* 96 */ { 0, "setpriority" },
1095 /* 97 */ { 0, "socket" },
1096 /* 98 */ { 0, "connect" },
1097 { 0, }, /* 99 is old accept */
1098 /* 100 */ { 0, "getpriority" },
1099 { 0, }, /* 101 is old send */
1100 { 0, }, /* 102 is old recv */
1101 /* 103 */ { 0, "sigreturn" },
1102 /* 104 */ { 0, "bind" },
1103 /* 105 */ { 0, "setsockopt" },
1104 /* 106 */ { 0, "listen" },
1105 { 0, }, /* 107 is obsolete vtimes */
1106 { 0, }, /* 108 is old sigvec */
1107 { 0, }, /* 109 is old sigblock */
1108 { 0, }, /* 110 is old sigsetmask */
1109 /* 111 */ { 0, "sigsuspend" },
1110 { 0, }, /* 112 is old sigstack */
1111 { 0, }, /* 113 is old recvmsg */
1112 { 0, }, /* 114 is old sendmsg */
1113 /* - is obsolete vtrace */ { 0, "vtrace 115" },
1114 /* 116 */ { do_gettimeofday
, "gettimeofday" },
1115 /* 117 */ { do_getrusage
, "getrusage" },
1116 /* 118 */ { 0, "getsockopt" },
1117 /* 119 */ { 0, "resuba" },
1118 /* 120 */ { 0, "readv" },
1119 /* 121 */ { 0, "writev" },
1120 /* 122 */ { 0, "settimeofday" },
1121 /* 123 */ { 0, "fchown" },
1122 /* 124 */ { 0, "fchmod" },
1123 { 0, }, /* 125 is old recvfrom */
1124 { 0, }, /* 126 is old setreuid */
1125 { 0, }, /* 127 is old setregid */
1126 /* 128 */ { 0, "rename" },
1127 { 0, }, /* 129 is old truncate */
1128 { 0, }, /* 130 is old ftruncate */
1129 /* 131 */ { 0, "flock" },
1130 /* 132 */ { 0, "mkfifo" },
1131 /* 133 */ { 0, "sendto" },
1132 /* 134 */ { 0, "shutdown" },
1133 /* 135 */ { 0, "socketpair" },
1134 /* 136 */ { 0, "mkdir" },
1135 /* 137 */ { 0, "rmdir" },
1136 /* 138 */ { 0, "utimes" },
1137 { 0, }, /* 139 is obsolete 4.2 sigreturn */
1138 /* 140 */ { 0, "adjtime" },
1139 { 0, }, /* 141 is old getpeername */
1140 { 0, }, /* 142 is old gethostid */
1141 { 0, }, /* 143 is old sethostid */
1142 { 0, }, /* 144 is old getrlimit */
1143 { 0, }, /* 145 is old setrlimit */
1144 { 0, }, /* 146 is old killpg */
1145 /* 147 */ { 0, "setsid" },
1146 /* 148 */ { 0, "quotactl" },
1147 { 0, }, /* 149 is old quota */
1148 { 0, }, /* 150 is old getsockname */
1153 /* 155 */ { 0, "nfssvc" },
1154 { 0, }, /* 156 is old getdirentries */
1155 /* 157 */ { 0, "statfs" },
1156 /* 158 */ { do_fstatfs
, "fstatfs" },
1159 /* 161 */ { 0, "getfh" },
1160 { 0, }, /* 162 is old getdomainname */
1161 { 0, }, /* 163 is old setdomainname */
1162 { 0, }, /* 164 is old uname */
1163 /* 165 */ { 0, "sysarch" },
1167 /* 169 */ { 0, "semsys" },
1168 /* 170 */ { 0, "msgsys" },
1169 /* 171 */ { 0, "shmsys" },
1179 /* 181 */ { 0, "setgid" },
1180 /* 182 */ { 0, "setegid" },
1181 /* 183 */ { 0, "seteuid" },
1182 /* 184 */ { 0, "lfs_bmapv" },
1183 /* 185 */ { 0, "lfs_markv" },
1184 /* 186 */ { 0, "lfs_segclean" },
1185 /* 187 */ { 0, "lfs_segwait" },
1186 /* 188 */ { do_stat
, "stat" },
1187 /* 189 */ { do_fstat
, "fstat" },
1188 /* 190 */ { do_lstat
, "lstat" },
1189 /* 191 */ { 0, "pathconf" },
1190 /* 192 */ { 0, "fpathconf" },
1192 /* 194 */ { 0, "getrlimit" },
1193 /* 195 */ { 0, "setrlimit" },
1194 /* 196 */ { do_getdirentries
, "getdirentries" },
1195 /* 197 */ { 0, "mmap" },
1196 /* 198 */ { do___syscall
, "__syscall" },
1197 /* 199 */ { do_lseek
, "lseek" },
1198 /* 200 */ { 0, "truncate" },
1199 /* 201 */ { 0, "ftruncate" },
1200 /* 202 */ { do___sysctl
, "__sysctl" },
1201 /* 203 */ { 0, "mlock" },
1202 /* 204 */ { 0, "munlock" },
1205 static char *(netbsd_error_names
[]) = {
1242 /* 36 */ "EINPROGRESS",
1243 /* 37 */ "EALREADY",
1244 /* 38 */ "ENOTSOCK",
1245 /* 39 */ "EDESTADDRREQ",
1246 /* 40 */ "EMSGSIZE",
1247 /* 41 */ "EPROTOTYPE",
1248 /* 42 */ "ENOPROTOOPT",
1249 /* 43 */ "EPROTONOSUPPORT",
1250 /* 44 */ "ESOCKTNOSUPPORT",
1251 /* 45 */ "EOPNOTSUPP",
1252 /* 46 */ "EPFNOSUPPORT",
1253 /* 47 */ "EAFNOSUPPORT",
1254 /* 48 */ "EADDRINUSE",
1255 /* 49 */ "EADDRNOTAVAIL",
1256 /* 50 */ "ENETDOWN",
1257 /* 51 */ "ENETUNREACH",
1258 /* 52 */ "ENETRESET",
1259 /* 53 */ "ECONNABORTED",
1260 /* 54 */ "ECONNRESET",
1263 /* 57 */ "ENOTCONN",
1264 /* 58 */ "ESHUTDOWN",
1265 /* 59 */ "ETOOMANYREFS",
1266 /* 60 */ "ETIMEDOUT",
1267 /* 61 */ "ECONNREFUSED",
1269 /* 63 */ "ENAMETOOLONG",
1270 /* 64 */ "EHOSTDOWN",
1271 /* 65 */ "EHOSTUNREACH",
1272 /* 66 */ "ENOTEMPTY",
1273 /* 67 */ "EPROCLIM",
1279 /* 73 */ "ERPCMISMATCH",
1280 /* 74 */ "EPROGUNAVAIL",
1281 /* 75 */ "EPROGMISMATCH",
1282 /* 76 */ "EPROCUNAVAIL",
1287 /* 81 */ "ENEEDAUTH",
1291 static char *(netbsd_signal_names
[]) = {
1318 /* 26 */ "SIGVTALRM",
1320 /* 28 */ "SIGWINCH",
1326 static emul_syscall emul_netbsd_syscalls
= {
1328 sizeof(netbsd_descriptors
) / sizeof(netbsd_descriptors
[0]),
1330 sizeof(netbsd_error_names
) / sizeof(netbsd_error_names
[0]),
1331 netbsd_signal_names
,
1332 sizeof(netbsd_signal_names
) / sizeof(netbsd_signal_names
[0]),
1336 /* NetBSD's os_emul interface, most are just passed on to the generic
1339 static os_emul_data
*
1340 emul_netbsd_create(device
*root
,
1344 unsigned_word top_of_stack
;
1345 unsigned stack_size
;
1347 os_emul_data
*bsd_data
;
1350 /* check that this emulation is really for us */
1351 if (name
!= NULL
&& strcmp(name
, "netbsd") != 0)
1357 /* merge any emulation specific entries into the device tree */
1359 /* establish a few defaults */
1360 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
1362 top_of_stack
= 0xe0000000;
1363 stack_size
= 0x00100000;
1367 top_of_stack
= 0x20000000;
1368 stack_size
= 0x00100000;
1372 emul_add_tree_options(root
, image
, "netbsd",
1373 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
1374 ? "user" : "virtual"),
1375 0 /*oea-interrupt-prefix*/);
1377 /* virtual memory - handles growth of stack/heap */
1378 vm
= tree_parse(root
, "/openprom/vm");
1379 tree_parse(vm
, "./stack-base 0x%lx",
1380 (unsigned long)(top_of_stack
- stack_size
));
1381 tree_parse(vm
, "./nr-bytes 0x%x", stack_size
);
1383 tree_parse(root
, "/openprom/vm/map-binary/file-name %s",
1384 bfd_get_filename(image
));
1386 /* finish the init */
1387 tree_parse(root
, "/openprom/init/register/pc 0x%lx",
1388 (unsigned long)bfd_get_start_address(image
));
1389 tree_parse(root
, "/openprom/init/register/sp 0x%lx",
1390 (unsigned long)top_of_stack
);
1391 tree_parse(root
, "/openprom/init/register/msr 0x%x",
1392 ((tree_find_boolean_property(root
, "/options/little-endian?")
1393 ? msr_little_endian_mode
1395 | (tree_find_boolean_property(root
, "/openprom/options/floating-point?")
1396 ? (msr_floating_point_available
1397 | msr_floating_point_exception_mode_0
1398 | msr_floating_point_exception_mode_1
)
1400 tree_parse(root
, "/openprom/init/stack/stack-type %s",
1401 (elf_binary
? "ppc-elf" : "ppc-xcoff"));
1403 /* finally our emulation data */
1404 bsd_data
= ZALLOC(os_emul_data
);
1406 bsd_data
->syscalls
= &emul_netbsd_syscalls
;
1411 emul_netbsd_init(os_emul_data
*emul_data
,
1418 emul_netbsd_system_call(cpu
*processor
,
1420 os_emul_data
*emul_data
)
1422 emul_do_system_call(emul_data
,
1423 emul_data
->syscalls
,
1424 cpu_registers(processor
)->gpr
[0],
1425 3, /*r3 contains arg0*/
1430 const os_emul emul_netbsd
= {
1434 emul_netbsd_system_call
,
1435 0, /*instruction_call*/
1439 #endif _EMUL_NETBSD_C_