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>
46 #include <sys/errno.h>
47 #include <sys/param.h>
51 #ifndef HAVE_SYS_RESOURCE_H
57 #include <sys/resource.h>
62 #include <sys/ioctl.h>
67 # define NAMLEN(dirent) strlen((dirent)->d_name)
69 # define dirent direct
70 # define NAMLEN(dirent) (dirent)->d_namlen
72 # include <sys/ndir.h>
83 #undef MAXPATHLEN /* sys/param.h might define this also */
91 #define WITH_NetBSD_HOST (NetBSD >= 199306)
92 #if WITH_NetBSD_HOST /* here NetBSD as that is what we're emulating */
93 #include <sys/syscall.h> /* FIXME - should not be including this one */
94 #include <sys/sysctl.h>
95 #include <sys/mount.h>
96 extern int getdirentries(int fd
, char *buf
, int nbytes
, long *basep
);
99 /* If this is not netbsd, don't allow fstatfs or getdirentries at this time */
101 #undef HAVE_GETDIRENTRIES
104 #if (BSD < 199306) /* here BSD as just a bug */
108 #ifndef STATIC_INLINE_EMUL_NETBSD
109 #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE
114 #define SYS(X) ASSERT(call == (SYS_##X))
119 #if WITH_NetBSD_HOST && (PATH_MAX != 1024)
120 #error "PATH_MAX not 1024"
121 #elif !defined(PATH_MAX)
122 #define PATH_MAX 1024
128 NetBSD - Emulation of user programs for NetBSD/PPC
135 /* NetBSD's idea of what is needed to implement emulations */
137 struct _os_emul_data
{
139 emul_syscall
*syscalls
;
144 STATIC_INLINE_EMUL_NETBSD
void
145 write_stat(unsigned_word addr
,
158 /* H2T(buf.st_spare1); */
160 /* H2T(buf.st_spare2); */
162 /* H2T(buf.st_spare3); */
163 #ifdef AC_STRUCT_ST_RDEV
166 #ifdef AC_STRUCT_ST_BLKSIZE
169 #ifdef AC_STRUCT_ST_BLOCKS
176 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
181 STATIC_INLINE_EMUL_NETBSD
void
182 write_statfs(unsigned_word addr
,
196 H2T(buf
.f_fsid
.val
[0]);
197 H2T(buf
.f_fsid
.val
[1]);
200 /* f_fstypename[MFSNAMELEN]; */
201 /* f_mntonname[MNAMELEN]; */
202 /* f_mntfromname[MNAMELEN]; */
203 emul_write_buffer(&buf
, addr
, sizeof(buf
), processor
, cia
);
208 STATIC_INLINE_EMUL_NETBSD
void
209 write_timeval(unsigned_word addr
,
216 emul_write_buffer(&t
, addr
, sizeof(t
), processor
, cia
);
220 STATIC_INLINE_EMUL_NETBSD
void
221 write_timezone(unsigned_word addr
,
226 H2T(tz
.tz_minuteswest
);
228 emul_write_buffer(&tz
, addr
, sizeof(tz
), processor
, cia
);
232 #ifdef HAVE_GETDIRENTRIES
233 STATIC_INLINE_EMUL_NETBSD
void
234 write_direntries(unsigned_word addr
,
242 struct dirent
*in
= (struct dirent
*)buf
;
243 ASSERT(in
->d_reclen
<= nbytes
);
244 out
= (struct dirent
*)zalloc(in
->d_reclen
);
245 memcpy(out
/*dest*/, in
/*src*/, in
->d_reclen
);
250 emul_write_buffer(out
, addr
, in
->d_reclen
, processor
, cia
);
251 nbytes
-= in
->d_reclen
;
252 addr
+= in
->d_reclen
;
260 #ifdef HAVE_GETRUSAGE
261 STATIC_INLINE_EMUL_NETBSD
void
262 write_rusage(unsigned_word addr
,
263 struct rusage rusage
,
267 H2T(rusage
.ru_utime
.tv_sec
); /* user time used */
268 H2T(rusage
.ru_utime
.tv_usec
);
269 H2T(rusage
.ru_stime
.tv_sec
); /* system time used */
270 H2T(rusage
.ru_stime
.tv_usec
);
271 H2T(rusage
.ru_maxrss
); /* integral max resident set size */
272 H2T(rusage
.ru_ixrss
); /* integral shared text memory size */
273 H2T(rusage
.ru_idrss
); /* integral unshared data size */
274 H2T(rusage
.ru_isrss
); /* integral unshared stack size */
275 H2T(rusage
.ru_minflt
); /* page reclaims */
276 H2T(rusage
.ru_majflt
); /* page faults */
277 H2T(rusage
.ru_nswap
); /* swaps */
278 H2T(rusage
.ru_inblock
); /* block input operations */
279 H2T(rusage
.ru_oublock
); /* block output operations */
280 H2T(rusage
.ru_msgsnd
); /* messages sent */
281 H2T(rusage
.ru_msgrcv
); /* messages received */
282 H2T(rusage
.ru_nsignals
); /* signals received */
283 H2T(rusage
.ru_nvcsw
); /* voluntary context switches */
284 H2T(rusage
.ru_nivcsw
); /* involuntary context switches */
285 emul_write_buffer(&rusage
, addr
, sizeof(rusage
), processor
, cia
);
290 do_exit(os_emul_data
*emul
,
296 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
298 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
299 printf_filtered ("%d)\n", status
);
301 cpu_halt(processor
, cia
, was_exited
, status
);
306 do_read(os_emul_data
*emul
,
312 void *scratch_buffer
;
313 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
314 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
315 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
319 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
320 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
322 /* get a tempoary bufer */
323 scratch_buffer
= zalloc(nbytes
);
325 /* check if buffer exists by reading it */
326 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
331 status
= fread (scratch_buffer
, 1, nbytes
, stdin
);
332 if (status
== 0 && ferror (stdin
))
336 status
= read (d
, scratch_buffer
, nbytes
);
338 emul_write_status(processor
, status
, errno
);
340 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
342 zfree(scratch_buffer
);
347 do_write(os_emul_data
*emul
,
353 void *scratch_buffer
= NULL
;
354 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
355 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
356 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
360 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
361 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
363 /* get a tempoary bufer */
364 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
367 emul_read_buffer(scratch_buffer
, buf
, nbytes
,
371 status
= write(d
, scratch_buffer
, nbytes
);
372 emul_write_status(processor
, status
, errno
);
373 zfree(scratch_buffer
);
380 do_open(os_emul_data
*emul
,
386 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
387 char path_buf
[PATH_MAX
];
388 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
389 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
390 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
394 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
395 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
399 /* Do some translation on 'flags' to match it to the host's version. */
400 /* These flag values were taken from the NetBSD 1.4 header files. */
401 if ((flags
& 3) == 0)
402 hostflags
= O_RDONLY
;
403 else if ((flags
& 3) == 1)
404 hostflags
= O_WRONLY
;
407 if (flags
& 0x00000008)
408 hostflags
|= O_APPEND
;
409 if (flags
& 0x00000200)
410 hostflags
|= O_CREAT
;
411 if (flags
& 0x00000400)
412 hostflags
|= O_TRUNC
;
413 if (flags
& 0x00000800)
416 /* Can't combine these statements, cuz open sets errno. */
417 status
= open(path
, hostflags
, mode
);
418 emul_write_status(processor
, status
, errno
);
423 do_close(os_emul_data
*emul
,
429 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
432 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
433 printf_filtered ("%d", d
);
437 /* Can't combine these statements, cuz close sets errno. */
439 emul_write_status(processor
, status
, errno
);
444 do_break(os_emul_data
*emul
,
450 /* just pass this onto the `vm' device */
451 unsigned_word new_break
= cpu_registers(processor
)->gpr
[arg0
];
454 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
455 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
458 status
= device_ioctl(emul
->vm
,
462 new_break
); /*ioctl-data*/
463 emul_write_status(processor
, 0, status
);
471 do_getpid(os_emul_data
*emul
,
478 emul_write_status(processor
, (int)getpid(), 0);
486 do_getuid(os_emul_data
*emul
,
493 emul_write_status(processor
, (int)getuid(), 0);
501 do_geteuid(os_emul_data
*emul
,
508 emul_write_status(processor
, (int)geteuid(), 0);
516 do_kill(os_emul_data
*emul
,
522 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
523 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
525 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
526 printf_filtered ("%d, %d", (int)pid
, sig
);
529 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
531 cpu_halt(processor
, cia
, was_signalled
, sig
);
539 do_dup(os_emul_data
*emul
,
545 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
546 int status
= dup(oldd
);
549 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
550 printf_filtered ("%d", oldd
);
553 emul_write_status(processor
, status
, err
);
561 do_getegid(os_emul_data
*emul
,
568 emul_write_status(processor
, (int)getegid(), 0);
576 do_getgid(os_emul_data
*emul
,
583 emul_write_status(processor
, (int)getgid(), 0);
587 #ifndef HAVE_SIGPROCMASK
588 #define do_sigprocmask 0
591 do_sigprocmask(os_emul_data
*emul
,
597 natural_word how
= cpu_registers(processor
)->gpr
[arg0
];
598 unsigned_word set
= cpu_registers(processor
)->gpr
[arg0
+1];
599 unsigned_word oset
= cpu_registers(processor
)->gpr
[arg0
+2];
600 #ifdef SYS_sigprocmask
604 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
605 printf_filtered ("%ld, 0x%ld, 0x%ld", (long)how
, (long)set
, (long)oset
);
607 emul_write_status(processor
, 0, 0);
608 cpu_registers(processor
)->gpr
[4] = set
;
616 do_ioctl(os_emul_data
*emul
,
622 int d
= cpu_registers(processor
)->gpr
[arg0
];
623 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
624 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
626 #if !WITH_NetBSD_HOST
627 cpu_registers(processor
)->gpr
[arg0
] = 0; /* just succeed */
629 unsigned dir
= request
& IOC_DIRMASK
;
632 /* what we haven't done */
633 if (dir
& IOC_IN
/* write into the io device */
635 || !(dir
& IOC_VOID
))
636 error("do_ioctl() read or write of parameter not implemented\n");
637 status
= ioctl(d
, request
, NULL
);
638 emul_write_status(processor
, status
, errno
);
641 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
642 printf_filtered ("%d, 0x%x, 0x%lx", d
, request
, (long)argp_addr
);
650 do_umask(os_emul_data
*emul
,
656 int mask
= cpu_registers(processor
)->gpr
[arg0
];
658 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
659 printf_filtered ("0%o", mask
);
662 emul_write_status(processor
, umask(mask
), 0);
670 do_dup2(os_emul_data
*emul
,
676 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
677 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
678 int status
= dup2(oldd
, newd
);
681 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
682 printf_filtered ("%d, %d", oldd
, newd
);
685 emul_write_status(processor
, status
, err
);
693 do_fcntl(os_emul_data
*emul
,
699 int fd
= cpu_registers(processor
)->gpr
[arg0
];
700 int cmd
= cpu_registers(processor
)->gpr
[arg0
+1];
701 int arg
= cpu_registers(processor
)->gpr
[arg0
+2];
704 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
705 printf_filtered ("%d, %d, %d", fd
, cmd
, arg
);
708 status
= fcntl(fd
, cmd
, arg
);
709 emul_write_status(processor
, status
, errno
);
713 #ifndef HAVE_GETTIMEOFDAY
714 #define do_gettimeofday 0
717 do_gettimeofday(os_emul_data
*emul
,
723 unsigned_word t_addr
= cpu_registers(processor
)->gpr
[arg0
];
724 unsigned_word tz_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
727 int status
= gettimeofday((t_addr
!= 0 ? &t
: NULL
),
728 (tz_addr
!= 0 ? &tz
: NULL
));
731 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
732 printf_filtered ("0x%lx, 0x%lx", (long)t_addr
, (long)tz_addr
);
735 emul_write_status(processor
, status
, err
);
738 write_timeval(t_addr
, t
, processor
, cia
);
740 write_timezone(tz_addr
, tz
, processor
, cia
);
745 #ifndef HAVE_GETRUSAGE
746 #define do_getrusage 0
749 do_getrusage(os_emul_data
*emul
,
755 int who
= cpu_registers(processor
)->gpr
[arg0
];
756 unsigned_word rusage_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
757 struct rusage rusage
;
758 int status
= getrusage(who
, (rusage_addr
!= 0 ? &rusage
: NULL
));
761 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
762 printf_filtered ("%d, 0x%lx", who
, (long)rusage_addr
);
765 emul_write_status(processor
, status
, err
);
767 if (rusage_addr
!= 0)
768 write_rusage(rusage_addr
, rusage
, processor
, cia
);
778 do_fstatfs(os_emul_data
*emul
,
784 int fd
= cpu_registers(processor
)->gpr
[arg0
];
785 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
789 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
790 printf_filtered ("%d, 0x%lx", fd
, (long)buf_addr
);
793 status
= fstatfs(fd
, (buf_addr
== 0 ? NULL
: &buf
));
794 emul_write_status(processor
, status
, errno
);
797 write_statfs(buf_addr
, buf
, processor
, cia
);
806 do_stat(os_emul_data
*emul
,
812 char path_buf
[PATH_MAX
];
813 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
814 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
815 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
821 status
= stat(path
, &buf
);
822 emul_write_status(processor
, status
, errno
);
824 write_stat(stat_buf_addr
, buf
, processor
, cia
);
832 do_fstat(os_emul_data
*emul
,
838 int fd
= cpu_registers(processor
)->gpr
[arg0
];
839 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
845 /* Can't combine these statements, cuz fstat sets errno. */
846 status
= fstat(fd
, &buf
);
847 emul_write_status(processor
, status
, errno
);
848 write_stat(stat_buf_addr
, buf
, processor
, cia
);
856 do_lstat(os_emul_data
*emul
,
862 char path_buf
[PATH_MAX
];
863 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
864 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
865 unsigned_word stat_buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
871 /* Can't combine these statements, cuz lstat sets errno. */
872 status
= lstat(path
, &buf
);
873 emul_write_status(processor
, status
, errno
);
874 write_stat(stat_buf_addr
, buf
, processor
, cia
);
878 #ifndef HAVE_GETDIRENTRIES
879 #define do_getdirentries 0
882 do_getdirentries(os_emul_data
*emul
,
888 int fd
= cpu_registers(processor
)->gpr
[arg0
];
889 unsigned_word buf_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
891 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
892 unsigned_word basep_addr
= cpu_registers(processor
)->gpr
[arg0
+3];
895 #ifdef SYS_getdirentries
898 if (buf_addr
!= 0 && nbytes
>= 0)
899 buf
= zalloc(nbytes
);
902 status
= getdirentries(fd
,
903 (buf_addr
== 0 ? NULL
: buf
),
905 (basep_addr
== 0 ? NULL
: &basep
));
906 emul_write_status(processor
, status
, errno
);
908 emul_write_word(basep_addr
, basep
, processor
, cia
);
910 write_direntries(buf_addr
, buf
, status
, processor
, cia
);
918 do___syscall(os_emul_data
*emul
,
925 emul_do_system_call(emul
,
927 cpu_registers(processor
)->gpr
[arg0
],
937 do_lseek(os_emul_data
*emul
,
943 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
944 off_t offset
= emul_read_gpr64(processor
, arg0
+2);
945 int whence
= cpu_registers(processor
)->gpr
[arg0
+4];
948 status
= lseek(fildes
, offset
, whence
);
950 emul_write_status(processor
, -1, errno
);
952 emul_write_status(processor
, 0, 0); /* success */
953 emul_write_gpr64(processor
, 3, status
);
959 do___sysctl(os_emul_data
*emul
,
965 /* call the arguments by their real name */
966 unsigned_word name
= cpu_registers(processor
)->gpr
[arg0
];
967 natural_word namelen
= cpu_registers(processor
)->gpr
[arg0
+1];
968 unsigned_word oldp
= cpu_registers(processor
)->gpr
[arg0
+2];
969 unsigned_word oldlenp
= cpu_registers(processor
)->gpr
[arg0
+3];
972 natural_word int_val
;
975 /* pluck out the management information base id */
977 error("system_call()SYS___sysctl bad name[0]\n");
978 mib
= vm_data_map_read_word(cpu_data_map(processor
),
984 /* see what to do with it ... */
987 #if WITH_NetBSD_HOST && (CTL_HW != 6)
991 error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
992 mib
= vm_data_map_read_word(cpu_data_map(processor
),
998 case 7/*HW_PAGESIZE*/:
999 #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7)
1000 # error "HW_PAGESIZE"
1002 oldlen
= vm_data_map_read_word(cpu_data_map(processor
),
1006 if (sizeof(natural_word
) > oldlen
)
1007 error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
1009 oldlen
= sizeof(int_val
);
1010 emul_write_word(oldp
, int_val
, processor
, cia
);
1011 emul_write_word(oldlenp
, oldlen
, processor
, cia
);
1014 error("sysctl() CTL_HW.%d unknown\n", mib
);
1019 error("sysctl() name[0]=%d unknown\n", (int)mib
);
1022 emul_write_status(processor
, 0, 0); /* always succeed */
1027 static emul_syscall_descriptor netbsd_descriptors
[] = {
1028 /* 0 */ { 0, "syscall" },
1029 /* 1 */ { do_exit
, "exit" },
1030 /* 2 */ { 0, "fork" },
1031 /* 3 */ { do_read
, "read" },
1032 /* 4 */ { do_write
, "write" },
1033 /* 5 */ { do_open
, "open" },
1034 /* 6 */ { do_close
, "close" },
1035 /* 7 */ { 0, "wait4" },
1036 { 0, }, /* 8 is old creat */
1037 /* 9 */ { 0, "link" },
1038 /* 10 */ { 0, "unlink" },
1039 { 0, }, /* 11 is obsolete execv */
1040 /* 12 */ { 0, "chdir" },
1041 /* 13 */ { 0, "fchdir" },
1042 /* 14 */ { 0, "mknod" },
1043 /* 15 */ { 0, "chmod" },
1044 /* 16 */ { 0, "chown" },
1045 /* 17 */ { do_break
, "break" },
1046 /* 18 */ { 0, "getfsstat" },
1047 { 0, }, /* 19 is old lseek */
1048 /* 20 */ { do_getpid
, "getpid" },
1049 /* 21 */ { 0, "mount" },
1050 /* 22 */ { 0, "unmount" },
1051 /* 23 */ { 0, "setuid" },
1052 /* 24 */ { do_getuid
, "getuid" },
1053 /* 25 */ { do_geteuid
, "geteuid" },
1054 /* 26 */ { 0, "ptrace" },
1055 /* 27 */ { 0, "recvmsg" },
1056 /* 28 */ { 0, "sendmsg" },
1057 /* 29 */ { 0, "recvfrom" },
1058 /* 30 */ { 0, "accept" },
1059 /* 31 */ { 0, "getpeername" },
1060 /* 32 */ { 0, "getsockname" },
1061 /* 33 */ { 0, "access" },
1062 /* 34 */ { 0, "chflags" },
1063 /* 35 */ { 0, "fchflags" },
1064 /* 36 */ { 0, "sync" },
1065 /* 37 */ { do_kill
, "kill" },
1066 { 0, }, /* 38 is old stat */
1067 /* 39 */ { 0, "getppid" },
1068 { 0, }, /* 40 is old lstat */
1069 /* 41 */ { do_dup
, "dup" },
1070 /* 42 */ { 0, "pipe" },
1071 /* 43 */ { do_getegid
, "getegid" },
1072 /* 44 */ { 0, "profil" },
1073 /* 45 */ { 0, "ktrace" },
1074 /* 46 */ { 0, "sigaction" },
1075 /* 47 */ { do_getgid
, "getgid" },
1076 /* 48 */ { do_sigprocmask
, "sigprocmask" },
1077 /* 49 */ { 0, "getlogin" },
1078 /* 50 */ { 0, "setlogin" },
1079 /* 51 */ { 0, "acct" },
1080 /* 52 */ { 0, "sigpending" },
1081 /* 53 */ { 0, "sigaltstack" },
1082 /* 54 */ { do_ioctl
, "ioctl" },
1083 /* 55 */ { 0, "reboot" },
1084 /* 56 */ { 0, "revoke" },
1085 /* 57 */ { 0, "symlink" },
1086 /* 58 */ { 0, "readlink" },
1087 /* 59 */ { 0, "execve" },
1088 /* 60 */ { do_umask
, "umask" },
1089 /* 61 */ { 0, "chroot" },
1090 { 0, }, /* 62 is old fstat */
1091 { 0, }, /* 63 is old getkerninfo */
1092 { 0, }, /* 64 is old getpagesize */
1093 /* 65 */ { 0, "msync" },
1094 /* 66 */ { 0, "vfork" },
1095 { 0, }, /* 67 is obsolete vread */
1096 { 0, }, /* 68 is obsolete vwrite */
1097 /* 69 */ { 0, "sbrk" },
1098 /* 70 */ { 0, "sstk" },
1099 { 0, }, /* 71 is old mmap */
1100 /* 72 */ { 0, "vadvise" },
1101 /* 73 */ { 0, "munmap" },
1102 /* 74 */ { 0, "mprotect" },
1103 /* 75 */ { 0, "madvise" },
1104 { 0, }, /* 76 is obsolete vhangup */
1105 { 0, }, /* 77 is obsolete vlimit */
1106 /* 78 */ { 0, "mincore" },
1107 /* 79 */ { 0, "getgroups" },
1108 /* 80 */ { 0, "setgroups" },
1109 /* 81 */ { 0, "getpgrp" },
1110 /* 82 */ { 0, "setpgid" },
1111 /* 83 */ { 0, "setitimer" },
1112 { 0, }, /* 84 is old wait */
1113 /* 85 */ { 0, "swapon" },
1114 /* 86 */ { 0, "getitimer" },
1115 { 0, }, /* 87 is old gethostname */
1116 { 0, }, /* 88 is old sethostname */
1117 { 0, }, /* 89 is old getdtablesize */
1118 { do_dup2
, "dup2" },
1120 /* 92 */ { do_fcntl
, "fcntl" },
1121 /* 93 */ { 0, "select" },
1123 /* 95 */ { 0, "fsync" },
1124 /* 96 */ { 0, "setpriority" },
1125 /* 97 */ { 0, "socket" },
1126 /* 98 */ { 0, "connect" },
1127 { 0, }, /* 99 is old accept */
1128 /* 100 */ { 0, "getpriority" },
1129 { 0, }, /* 101 is old send */
1130 { 0, }, /* 102 is old recv */
1131 /* 103 */ { 0, "sigreturn" },
1132 /* 104 */ { 0, "bind" },
1133 /* 105 */ { 0, "setsockopt" },
1134 /* 106 */ { 0, "listen" },
1135 { 0, }, /* 107 is obsolete vtimes */
1136 { 0, }, /* 108 is old sigvec */
1137 { 0, }, /* 109 is old sigblock */
1138 { 0, }, /* 110 is old sigsetmask */
1139 /* 111 */ { 0, "sigsuspend" },
1140 { 0, }, /* 112 is old sigstack */
1141 { 0, }, /* 113 is old recvmsg */
1142 { 0, }, /* 114 is old sendmsg */
1143 /* - is obsolete vtrace */ { 0, "vtrace 115" },
1144 /* 116 */ { do_gettimeofday
, "gettimeofday" },
1145 /* 117 */ { do_getrusage
, "getrusage" },
1146 /* 118 */ { 0, "getsockopt" },
1147 /* 119 */ { 0, "resuba" },
1148 /* 120 */ { 0, "readv" },
1149 /* 121 */ { 0, "writev" },
1150 /* 122 */ { 0, "settimeofday" },
1151 /* 123 */ { 0, "fchown" },
1152 /* 124 */ { 0, "fchmod" },
1153 { 0, }, /* 125 is old recvfrom */
1154 { 0, }, /* 126 is old setreuid */
1155 { 0, }, /* 127 is old setregid */
1156 /* 128 */ { 0, "rename" },
1157 { 0, }, /* 129 is old truncate */
1158 { 0, }, /* 130 is old ftruncate */
1159 /* 131 */ { 0, "flock" },
1160 /* 132 */ { 0, "mkfifo" },
1161 /* 133 */ { 0, "sendto" },
1162 /* 134 */ { 0, "shutdown" },
1163 /* 135 */ { 0, "socketpair" },
1164 /* 136 */ { 0, "mkdir" },
1165 /* 137 */ { 0, "rmdir" },
1166 /* 138 */ { 0, "utimes" },
1167 { 0, }, /* 139 is obsolete 4.2 sigreturn */
1168 /* 140 */ { 0, "adjtime" },
1169 { 0, }, /* 141 is old getpeername */
1170 { 0, }, /* 142 is old gethostid */
1171 { 0, }, /* 143 is old sethostid */
1172 { 0, }, /* 144 is old getrlimit */
1173 { 0, }, /* 145 is old setrlimit */
1174 { 0, }, /* 146 is old killpg */
1175 /* 147 */ { 0, "setsid" },
1176 /* 148 */ { 0, "quotactl" },
1177 { 0, }, /* 149 is old quota */
1178 { 0, }, /* 150 is old getsockname */
1183 /* 155 */ { 0, "nfssvc" },
1184 { 0, }, /* 156 is old getdirentries */
1185 /* 157 */ { 0, "statfs" },
1186 /* 158 */ { do_fstatfs
, "fstatfs" },
1189 /* 161 */ { 0, "getfh" },
1190 { 0, }, /* 162 is old getdomainname */
1191 { 0, }, /* 163 is old setdomainname */
1192 { 0, }, /* 164 is old uname */
1193 /* 165 */ { 0, "sysarch" },
1197 /* 169 */ { 0, "semsys" },
1198 /* 170 */ { 0, "msgsys" },
1199 /* 171 */ { 0, "shmsys" },
1209 /* 181 */ { 0, "setgid" },
1210 /* 182 */ { 0, "setegid" },
1211 /* 183 */ { 0, "seteuid" },
1212 /* 184 */ { 0, "lfs_bmapv" },
1213 /* 185 */ { 0, "lfs_markv" },
1214 /* 186 */ { 0, "lfs_segclean" },
1215 /* 187 */ { 0, "lfs_segwait" },
1216 /* 188 */ { do_stat
, "stat" },
1217 /* 189 */ { do_fstat
, "fstat" },
1218 /* 190 */ { do_lstat
, "lstat" },
1219 /* 191 */ { 0, "pathconf" },
1220 /* 192 */ { 0, "fpathconf" },
1222 /* 194 */ { 0, "getrlimit" },
1223 /* 195 */ { 0, "setrlimit" },
1224 /* 196 */ { do_getdirentries
, "getdirentries" },
1225 /* 197 */ { 0, "mmap" },
1226 /* 198 */ { do___syscall
, "__syscall" },
1227 /* 199 */ { do_lseek
, "lseek" },
1228 /* 200 */ { 0, "truncate" },
1229 /* 201 */ { 0, "ftruncate" },
1230 /* 202 */ { do___sysctl
, "__sysctl" },
1231 /* 203 */ { 0, "mlock" },
1232 /* 204 */ { 0, "munlock" },
1235 static char *(netbsd_error_names
[]) = {
1272 /* 36 */ "EINPROGRESS",
1273 /* 37 */ "EALREADY",
1274 /* 38 */ "ENOTSOCK",
1275 /* 39 */ "EDESTADDRREQ",
1276 /* 40 */ "EMSGSIZE",
1277 /* 41 */ "EPROTOTYPE",
1278 /* 42 */ "ENOPROTOOPT",
1279 /* 43 */ "EPROTONOSUPPORT",
1280 /* 44 */ "ESOCKTNOSUPPORT",
1281 /* 45 */ "EOPNOTSUPP",
1282 /* 46 */ "EPFNOSUPPORT",
1283 /* 47 */ "EAFNOSUPPORT",
1284 /* 48 */ "EADDRINUSE",
1285 /* 49 */ "EADDRNOTAVAIL",
1286 /* 50 */ "ENETDOWN",
1287 /* 51 */ "ENETUNREACH",
1288 /* 52 */ "ENETRESET",
1289 /* 53 */ "ECONNABORTED",
1290 /* 54 */ "ECONNRESET",
1293 /* 57 */ "ENOTCONN",
1294 /* 58 */ "ESHUTDOWN",
1295 /* 59 */ "ETOOMANYREFS",
1296 /* 60 */ "ETIMEDOUT",
1297 /* 61 */ "ECONNREFUSED",
1299 /* 63 */ "ENAMETOOLONG",
1300 /* 64 */ "EHOSTDOWN",
1301 /* 65 */ "EHOSTUNREACH",
1302 /* 66 */ "ENOTEMPTY",
1303 /* 67 */ "EPROCLIM",
1309 /* 73 */ "ERPCMISMATCH",
1310 /* 74 */ "EPROGUNAVAIL",
1311 /* 75 */ "EPROGMISMATCH",
1312 /* 76 */ "EPROCUNAVAIL",
1317 /* 81 */ "ENEEDAUTH",
1321 static char *(netbsd_signal_names
[]) = {
1348 /* 26 */ "SIGVTALRM",
1350 /* 28 */ "SIGWINCH",
1356 static emul_syscall emul_netbsd_syscalls
= {
1358 sizeof(netbsd_descriptors
) / sizeof(netbsd_descriptors
[0]),
1360 sizeof(netbsd_error_names
) / sizeof(netbsd_error_names
[0]),
1361 netbsd_signal_names
,
1362 sizeof(netbsd_signal_names
) / sizeof(netbsd_signal_names
[0]),
1366 /* NetBSD's os_emul interface, most are just passed on to the generic
1369 static os_emul_data
*
1370 emul_netbsd_create(device
*root
,
1374 unsigned_word top_of_stack
;
1375 unsigned stack_size
;
1377 os_emul_data
*bsd_data
;
1380 /* check that this emulation is really for us */
1381 if (name
!= NULL
&& strcmp(name
, "netbsd") != 0)
1387 /* merge any emulation specific entries into the device tree */
1389 /* establish a few defaults */
1390 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
1392 top_of_stack
= 0xe0000000;
1393 stack_size
= 0x00100000;
1397 top_of_stack
= 0x20000000;
1398 stack_size
= 0x00100000;
1402 emul_add_tree_options(root
, image
, "netbsd",
1403 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
1404 ? "user" : "virtual"),
1405 0 /*oea-interrupt-prefix*/);
1407 /* virtual memory - handles growth of stack/heap */
1408 vm
= tree_parse(root
, "/openprom/vm");
1409 tree_parse(vm
, "./stack-base 0x%lx",
1410 (unsigned long)(top_of_stack
- stack_size
));
1411 tree_parse(vm
, "./nr-bytes 0x%x", stack_size
);
1413 tree_parse(root
, "/openprom/vm/map-binary/file-name %s",
1414 bfd_get_filename(image
));
1416 /* finish the init */
1417 tree_parse(root
, "/openprom/init/register/pc 0x%lx",
1418 (unsigned long)bfd_get_start_address(image
));
1419 tree_parse(root
, "/openprom/init/register/sp 0x%lx",
1420 (unsigned long)top_of_stack
);
1421 tree_parse(root
, "/openprom/init/register/msr 0x%x",
1422 ((tree_find_boolean_property(root
, "/options/little-endian?")
1423 ? msr_little_endian_mode
1425 | (tree_find_boolean_property(root
, "/openprom/options/floating-point?")
1426 ? (msr_floating_point_available
1427 | msr_floating_point_exception_mode_0
1428 | msr_floating_point_exception_mode_1
)
1430 tree_parse(root
, "/openprom/init/stack/stack-type %s",
1431 (elf_binary
? "ppc-elf" : "ppc-xcoff"));
1433 /* finally our emulation data */
1434 bsd_data
= ZALLOC(os_emul_data
);
1436 bsd_data
->syscalls
= &emul_netbsd_syscalls
;
1441 emul_netbsd_init(os_emul_data
*emul_data
,
1448 emul_netbsd_system_call(cpu
*processor
,
1450 os_emul_data
*emul_data
)
1452 emul_do_system_call(emul_data
,
1453 emul_data
->syscalls
,
1454 cpu_registers(processor
)->gpr
[0],
1455 3, /*r3 contains arg0*/
1460 const os_emul emul_netbsd
= {
1464 emul_netbsd_system_call
,
1465 0, /*instruction_call*/
1469 #endif _EMUL_NETBSD_C_