1 /* This file is part of the program psim.
3 Copyright (C) 1996-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.
26 /* Note: this module is called via a table. There is no benefit in
29 #include "emul_generic.h"
30 #include "emul_unix.h"
40 #ifdef HAVE_SYS_TYPES_H
41 #include <sys/types.h>
44 #ifdef HAVE_SYS_TYPES_H
60 #ifdef HAVE_SYS_PARAM_H
61 #include <sys/param.h>
64 #ifdef HAVE_SYS_TIME_H
68 #ifndef HAVE_TERMIOS_STRUCTURE
69 #undef HAVE_SYS_TERMIOS_H
72 #ifndef HAVE_SYS_TERMIOS_H
73 #undef HAVE_TERMIOS_STRUCTURE
77 #ifdef HAVE_TERMIOS_STRUCTURE
78 #include <sys/termios.h>
80 /* If we have TERMIOS, use that for the termio structure, since some systems
81 don't like including both sys/termios.h and sys/termio.h at the same
83 #undef HAVE_TERMIO_STRUCTURE
86 #define termio termios
89 #ifndef HAVE_TERMIO_STRUCTURE
90 #undef HAVE_SYS_TERMIO_H
92 #ifndef HAVE_SYS_TERMIO_H
93 #undef HAVE_TERMIO_STRUCTURE
97 #ifdef HAVE_TERMIO_STRUCTURE
98 #include <sys/termio.h>
101 #ifdef HAVE_GETRUSAGE
102 #ifndef HAVE_SYS_RESOURCE_H
103 #undef HAVE_GETRUSAGE
107 #ifdef HAVE_GETRUSAGE
108 #include <sys/resource.h>
114 # define NAMLEN(dirent) strlen((dirent)->d_name)
116 # define dirent direct
117 # define NAMLEN(dirent) (dirent)->d_namlen
119 # include <sys/ndir.h>
122 # include <sys/dir.h>
130 #undef MAXPATHLEN /* sys/param.h might define this also */
138 #if defined(BSD) && !defined(errno) && (BSD < 199306) /* here BSD as just a bug */
142 #ifndef STATIC_INLINE_EMUL_UNIX
143 #define STATIC_INLINE_EMUL_UNIX STATIC_INLINE
147 #define PATH_MAX 1024
154 /* UNIX's idea of what is needed to implement emulations */
156 struct _os_emul_data {
158 emul_syscall *syscalls;
162 /* Emulation of simple UNIX system calls that are common on all systems. */
164 /* Structures that are common agmonst the UNIX varients */
165 struct unix_timeval {
166 signed32 tv_sec; /* seconds */
167 signed32 tv_usec; /* microseconds */
170 struct unix_timezone {
171 signed32 tz_minuteswest; /* minutes west of Greenwich */
172 signed32 tz_dsttime; /* type of dst correction */
175 #define UNIX_RUSAGE_SELF 0
176 #define UNIX_RUSAGE_CHILDREN (-1)
177 #define UNIX_RUSAGE_BOTH (-2) /* sys_wait4() uses this */
180 struct unix_timeval ru_utime; /* user time used */
181 struct unix_timeval ru_stime; /* system time used */
182 signed32 ru_maxrss; /* maximum resident set size */
183 signed32 ru_ixrss; /* integral shared memory size */
184 signed32 ru_idrss; /* integral unshared data size */
185 signed32 ru_isrss; /* integral unshared stack size */
186 signed32 ru_minflt; /* any page faults not requiring I/O */
187 signed32 ru_majflt; /* any page faults requiring I/O */
188 signed32 ru_nswap; /* swaps */
189 signed32 ru_inblock; /* block input operations */
190 signed32 ru_oublock; /* block output operations */
191 signed32 ru_msgsnd; /* messages sent */
192 signed32 ru_msgrcv; /* messages received */
193 signed32 ru_nsignals; /* signals received */
194 signed32 ru_nvcsw; /* voluntary context switches */
195 signed32 ru_nivcsw; /* involuntary " */
200 do_unix_exit(os_emul_data *emul,
206 int status = (int)cpu_registers(processor)->gpr[arg0];
207 if (WITH_TRACE && ppc_trace[trace_os_emul])
208 printf_filtered ("%d)\n", status);
210 cpu_halt(processor, cia, was_exited, status);
215 do_unix_read(os_emul_data *emul,
221 void *scratch_buffer;
222 int d = (int)cpu_registers(processor)->gpr[arg0];
223 unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
224 int nbytes = cpu_registers(processor)->gpr[arg0+2];
227 if (WITH_TRACE && ppc_trace[trace_os_emul])
228 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
230 /* get a tempoary bufer */
231 scratch_buffer = zalloc(nbytes);
233 /* check if buffer exists by reading it */
234 emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia);
237 status = read (d, scratch_buffer, nbytes);
239 emul_write_status(processor, status, errno);
241 emul_write_buffer(scratch_buffer, buf, status, processor, cia);
243 zfree(scratch_buffer);
248 do_unix_write(os_emul_data *emul,
254 void *scratch_buffer = NULL;
255 int d = (int)cpu_registers(processor)->gpr[arg0];
256 unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
257 int nbytes = cpu_registers(processor)->gpr[arg0+2];
260 if (WITH_TRACE && ppc_trace[trace_os_emul])
261 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
263 /* get a tempoary bufer */
264 scratch_buffer = zalloc(nbytes); /* FIXME - nbytes == 0 */
267 emul_read_buffer(scratch_buffer, buf, nbytes,
271 status = write(d, scratch_buffer, nbytes);
272 emul_write_status(processor, status, errno);
273 zfree(scratch_buffer);
280 do_unix_open(os_emul_data *emul,
286 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
287 char path_buf[PATH_MAX];
288 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
289 int flags = (int)cpu_registers(processor)->gpr[arg0+1];
290 int mode = (int)cpu_registers(processor)->gpr[arg0+2];
293 if (WITH_TRACE && ppc_trace[trace_os_emul])
294 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr, path, flags, mode);
296 status = open(path, flags, mode);
297 emul_write_status(processor, status, errno);
302 do_unix_close(os_emul_data *emul,
308 int d = (int)cpu_registers(processor)->gpr[arg0];
311 if (WITH_TRACE && ppc_trace[trace_os_emul])
312 printf_filtered ("%d", d);
315 emul_write_status(processor, status, errno);
320 do_unix_break(os_emul_data *emul,
326 /* just pass this onto the `vm' device */
327 unsigned_word new_break = cpu_registers(processor)->gpr[arg0];
330 if (WITH_TRACE && ppc_trace[trace_os_emul])
331 printf_filtered ("0x%lx", (long)cpu_registers(processor)->gpr[arg0]);
333 status = device_ioctl(emul->vm,
337 new_break); /*ioctl-data*/
339 emul_write_status(processor, 0, status);
343 #define do_unix_access 0
346 do_unix_access(os_emul_data *emul,
352 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
353 char path_buf[PATH_MAX];
354 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
355 int mode = (int)cpu_registers(processor)->gpr[arg0+1];
358 if (WITH_TRACE && ppc_trace[trace_os_emul])
359 printf_filtered ("0x%lx [%s], 0x%x [0%o]", (long)path_addr, path, mode, mode);
361 status = access(path, mode);
362 emul_write_status(processor, status, errno);
367 #define do_unix_getpid 0
370 do_unix_getpid(os_emul_data *emul,
376 pid_t status = getpid();
377 emul_write_status(processor, (int)status, errno);
382 #define do_unix_getppid 0
385 do_unix_getppid(os_emul_data *emul,
391 pid_t status = getppid();
392 emul_write_status(processor, (int)status, errno);
396 #if !defined(HAVE_GETPID) || !defined(HAVE_GETPPID)
397 #define do_unix_getpid2 0
400 do_unix_getpid2(os_emul_data *emul,
406 int pid = (int)getpid();
407 int ppid = (int)getppid();
408 emul_write2_status(processor, pid, ppid, errno);
412 #if !defined(HAVE_GETUID) || !defined(HAVE_GETEUID)
413 #define do_unix_getuid2 0
416 do_unix_getuid2(os_emul_data *emul,
422 uid_t uid = getuid();
423 uid_t euid = geteuid();
424 emul_write2_status(processor, (int)uid, (int)euid, errno);
429 #define do_unix_getuid 0
432 do_unix_getuid(os_emul_data *emul,
438 uid_t status = getuid();
439 emul_write_status(processor, (int)status, errno);
444 #define do_unix_geteuid 0
447 do_unix_geteuid(os_emul_data *emul,
453 uid_t status = geteuid();
454 emul_write_status(processor, (int)status, errno);
460 #define do_unix_kill 0
463 do_unix_kill(os_emul_data *emul,
469 pid_t pid = cpu_registers(processor)->gpr[arg0];
470 int sig = cpu_registers(processor)->gpr[arg0+1];
472 if (WITH_TRACE && ppc_trace[trace_os_emul])
473 printf_filtered ("%d, %d", (int)pid, sig);
475 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
478 cpu_halt(processor, cia, was_signalled, sig);
484 #define do_unix_dup 0
487 do_unix_dup(os_emul_data *emul,
493 int oldd = cpu_registers(processor)->gpr[arg0];
494 int status = dup(oldd);
497 if (WITH_TRACE && ppc_trace[trace_os_emul])
498 printf_filtered ("%d", oldd);
500 emul_write_status(processor, status, err);
505 #define do_unix_dup2 0
508 do_unix_dup2(os_emul_data *emul,
514 int oldd = cpu_registers(processor)->gpr[arg0];
515 int newd = cpu_registers(processor)->gpr[arg0+1];
516 int status = dup2(oldd, newd);
519 if (WITH_TRACE && ppc_trace[trace_os_emul])
520 printf_filtered ("%d, %d", oldd, newd);
522 emul_write_status(processor, status, err);
527 #define do_unix_lseek 0
530 do_unix_lseek(os_emul_data *emul,
536 int fildes = (int)cpu_registers(processor)->gpr[arg0];
537 off_t offset = (off_t)cpu_registers(processor)->gpr[arg0+1];
538 int whence = (int)cpu_registers(processor)->gpr[arg0+2];
541 if (WITH_TRACE && ppc_trace[trace_os_emul])
542 printf_filtered ("%d %ld %d", fildes, (long)offset, whence);
544 status = lseek(fildes, offset, whence);
545 emul_write_status(processor, (int)status, errno);
550 #if !defined(HAVE_GETGID) || !defined(HAVE_GETEGID)
551 #define do_unix_getgid2 0
554 do_unix_getgid2(os_emul_data *emul,
560 gid_t gid = getgid();
561 gid_t egid = getegid();
562 emul_write2_status(processor, (int)gid, (int)egid, errno);
567 #define do_unix_getgid 0
570 do_unix_getgid(os_emul_data *emul,
576 gid_t status = getgid();
577 emul_write_status(processor, (int)status, errno);
582 #define do_unix_getegid 0
585 do_unix_getegid(os_emul_data *emul,
591 gid_t status = getegid();
592 emul_write_status(processor, (int)status, errno);
597 #define do_unix_umask 0
600 do_unix_umask(os_emul_data *emul,
606 mode_t mask = (mode_t)cpu_registers(processor)->gpr[arg0];
607 int status = umask(mask);
609 if (WITH_TRACE && ppc_trace[trace_os_emul])
610 printf_filtered ("0%o", (unsigned int)mask);
612 emul_write_status(processor, status, errno);
617 #define do_unix_chdir 0
620 do_unix_chdir(os_emul_data *emul,
626 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
627 char path_buf[PATH_MAX];
628 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
631 if (WITH_TRACE && ppc_trace[trace_os_emul])
632 printf_filtered ("0x%lx [%s]", (long)path_addr, path);
634 status = chdir(path);
635 emul_write_status(processor, status, errno);
640 #define do_unix_link 0
643 do_unix_link(os_emul_data *emul,
649 unsigned_word path1_addr = cpu_registers(processor)->gpr[arg0];
650 char path1_buf[PATH_MAX];
651 char *path1 = emul_read_string(path1_buf, path1_addr, PATH_MAX, processor, cia);
652 unsigned_word path2_addr = cpu_registers(processor)->gpr[arg0+1];
653 char path2_buf[PATH_MAX];
654 char *path2 = emul_read_string(path2_buf, path2_addr, PATH_MAX, processor, cia);
657 if (WITH_TRACE && ppc_trace[trace_os_emul])
658 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr, path1, (long)path2_addr, path2);
660 status = link(path1, path2);
661 emul_write_status(processor, status, errno);
666 #define do_unix_symlink 0
669 do_unix_symlink(os_emul_data *emul,
675 unsigned_word path1_addr = cpu_registers(processor)->gpr[arg0];
676 char path1_buf[PATH_MAX];
677 char *path1 = emul_read_string(path1_buf, path1_addr, PATH_MAX, processor, cia);
678 unsigned_word path2_addr = cpu_registers(processor)->gpr[arg0+1];
679 char path2_buf[PATH_MAX];
680 char *path2 = emul_read_string(path2_buf, path2_addr, PATH_MAX, processor, cia);
683 if (WITH_TRACE && ppc_trace[trace_os_emul])
684 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr, path1, (long)path2_addr, path2);
686 status = symlink(path1, path2);
687 emul_write_status(processor, status, errno);
692 #define do_unix_unlink 0
695 do_unix_unlink(os_emul_data *emul,
701 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
702 char path_buf[PATH_MAX];
703 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
706 if (WITH_TRACE && ppc_trace[trace_os_emul])
707 printf_filtered ("0x%lx [%s]", (long)path_addr, path);
709 status = unlink(path);
710 emul_write_status(processor, status, errno);
715 #define do_unix_mkdir 0
718 do_unix_mkdir(os_emul_data *emul,
724 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
725 char path_buf[PATH_MAX];
726 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
727 int mode = (int)cpu_registers(processor)->gpr[arg0+1];
730 if (WITH_TRACE && ppc_trace[trace_os_emul])
731 printf_filtered ("0x%lx [%s], 0%3o", (long)path_addr, path, mode);
733 status = mkdir(path, mode);
734 emul_write_status(processor, status, errno);
739 #define do_unix_rmdir 0
742 do_unix_rmdir(os_emul_data *emul,
748 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
749 char path_buf[PATH_MAX];
750 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
753 if (WITH_TRACE && ppc_trace[trace_os_emul])
754 printf_filtered ("0x%lx [%s]", (long)path_addr, path);
756 status = rmdir(path);
757 emul_write_status(processor, status, errno);
762 #define do_unix_time 0
765 do_unix_time(os_emul_data *emul,
771 unsigned_word tp = cpu_registers(processor)->gpr[arg0];
772 time_t now = time ((time_t *)0);
773 unsigned_word status = H2T_4(now);
775 if (WITH_TRACE && ppc_trace[trace_os_emul])
776 printf_filtered ("0x%lx", (long)tp);
778 emul_write_status(processor, (int)status, errno);
781 emul_write_buffer(&status, tp, sizeof(status), processor, cia);
785 #if !defined(HAVE_GETTIMEOFDAY) || !defined(HAVE_SYS_TIME_H)
786 #define do_unix_gettimeofday 0
789 do_unix_gettimeofday(os_emul_data *emul,
795 unsigned_word tv = cpu_registers(processor)->gpr[arg0];
796 unsigned_word tz = cpu_registers(processor)->gpr[arg0+1];
797 struct unix_timeval target_timeval;
798 struct timeval host_timeval;
799 struct unix_timezone target_timezone;
800 struct timezone host_timezone;
803 if (WITH_TRACE && ppc_trace[trace_os_emul])
804 printf_filtered ("0x%lx, 0x%lx", (long)tv, (long)tz);
806 /* Just in case the system doesn't set the timezone structure */
807 host_timezone.tz_minuteswest = 0;
808 host_timezone.tz_dsttime = 0;
810 status = gettimeofday(&host_timeval, &host_timezone);
813 target_timeval.tv_sec = H2T_4(host_timeval.tv_sec);
814 target_timeval.tv_usec = H2T_4(host_timeval.tv_usec);
815 emul_write_buffer((void *) &target_timeval, tv, sizeof(target_timeval), processor, cia);
819 target_timezone.tz_minuteswest = H2T_4(host_timezone.tz_minuteswest);
820 target_timezone.tz_dsttime = H2T_4(host_timezone.tz_dsttime);
821 emul_write_buffer((void *) &target_timezone, tv, sizeof(target_timezone), processor, cia);
825 emul_write_status(processor, (int)status, errno);
830 #ifndef HAVE_GETRUSAGE
831 #define do_unix_getrusage 0
834 do_unix_getrusage(os_emul_data *emul,
840 signed_word who = (signed_word)cpu_registers(processor)->gpr[arg0];
841 unsigned_word usage = cpu_registers(processor)->gpr[arg0+1];
842 struct rusage host_rusage, host_rusage2;
843 struct unix_rusage target_rusage;
846 if (WITH_TRACE && ppc_trace[trace_os_emul])
847 printf_filtered ("%ld, 0x%lx", (long)who, (long)usage);
855 case UNIX_RUSAGE_SELF:
856 status = getrusage(RUSAGE_SELF, &host_rusage);
859 case UNIX_RUSAGE_CHILDREN:
860 status = getrusage(RUSAGE_CHILDREN, &host_rusage);
863 case UNIX_RUSAGE_BOTH:
864 status = getrusage(RUSAGE_SELF, &host_rusage);
866 status = getrusage(RUSAGE_CHILDREN, &host_rusage2);
868 host_rusage.ru_utime.tv_sec += host_rusage2.ru_utime.tv_sec;
869 host_rusage.ru_utime.tv_usec += host_rusage2.ru_utime.tv_usec;
870 host_rusage.ru_stime.tv_sec += host_rusage2.ru_stime.tv_sec;
871 host_rusage.ru_stime.tv_usec += host_rusage2.ru_stime.tv_usec;
872 host_rusage.ru_maxrss += host_rusage2.ru_maxrss;
873 host_rusage.ru_ixrss += host_rusage2.ru_ixrss;
874 host_rusage.ru_idrss += host_rusage2.ru_idrss;
875 host_rusage.ru_isrss += host_rusage2.ru_isrss;
876 host_rusage.ru_minflt += host_rusage2.ru_minflt;
877 host_rusage.ru_majflt += host_rusage2.ru_majflt;
878 host_rusage.ru_nswap += host_rusage2.ru_nswap;
879 host_rusage.ru_inblock += host_rusage2.ru_inblock;
880 host_rusage.ru_oublock += host_rusage2.ru_oublock;
881 host_rusage.ru_msgsnd += host_rusage2.ru_msgsnd;
882 host_rusage.ru_msgrcv += host_rusage2.ru_msgrcv;
883 host_rusage.ru_nsignals += host_rusage2.ru_nsignals;
884 host_rusage.ru_nvcsw += host_rusage2.ru_nvcsw;
885 host_rusage.ru_nivcsw += host_rusage2.ru_nivcsw;
891 target_rusage.ru_utime.tv_sec = H2T_4(host_rusage2.ru_utime.tv_sec);
892 target_rusage.ru_utime.tv_usec = H2T_4(host_rusage2.ru_utime.tv_usec);
893 target_rusage.ru_stime.tv_sec = H2T_4(host_rusage2.ru_stime.tv_sec);
894 target_rusage.ru_stime.tv_usec = H2T_4(host_rusage2.ru_stime.tv_usec);
895 target_rusage.ru_maxrss = H2T_4(host_rusage2.ru_maxrss);
896 target_rusage.ru_ixrss = H2T_4(host_rusage2.ru_ixrss);
897 target_rusage.ru_idrss = H2T_4(host_rusage2.ru_idrss);
898 target_rusage.ru_isrss = H2T_4(host_rusage2.ru_isrss);
899 target_rusage.ru_minflt = H2T_4(host_rusage2.ru_minflt);
900 target_rusage.ru_majflt = H2T_4(host_rusage2.ru_majflt);
901 target_rusage.ru_nswap = H2T_4(host_rusage2.ru_nswap);
902 target_rusage.ru_inblock = H2T_4(host_rusage2.ru_inblock);
903 target_rusage.ru_oublock = H2T_4(host_rusage2.ru_oublock);
904 target_rusage.ru_msgsnd = H2T_4(host_rusage2.ru_msgsnd);
905 target_rusage.ru_msgrcv = H2T_4(host_rusage2.ru_msgrcv);
906 target_rusage.ru_nsignals = H2T_4(host_rusage2.ru_nsignals);
907 target_rusage.ru_nvcsw = H2T_4(host_rusage2.ru_nvcsw);
908 target_rusage.ru_nivcsw = H2T_4(host_rusage2.ru_nivcsw);
909 emul_write_buffer((void *) &target_rusage, usage, sizeof(target_rusage), processor, cia);
912 emul_write_status(processor, status, errno);
918 do_unix_nop(os_emul_data *emul,
924 if (WITH_TRACE && ppc_trace[trace_os_emul])
925 printf_filtered ("0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
926 (long)cpu_registers(processor)->gpr[arg0],
927 (long)cpu_registers(processor)->gpr[arg0+1],
928 (long)cpu_registers(processor)->gpr[arg0+2],
929 (long)cpu_registers(processor)->gpr[arg0+3],
930 (long)cpu_registers(processor)->gpr[arg0+4],
931 (long)cpu_registers(processor)->gpr[arg0+5]);
933 emul_write_status(processor, 0, errno);
937 /* Common code for initializing the system call stuff */
939 static os_emul_data *
940 emul_unix_create(device *root,
943 emul_syscall *syscall)
945 unsigned_word top_of_stack;
951 /* merge any emulation specific entries into the device tree */
953 /* establish a few defaults */
954 if (image->xvec->flavour == bfd_target_elf_flavour) {
956 top_of_stack = 0xe0000000;
957 stack_size = 0x00100000;
961 top_of_stack = 0x20000000;
962 stack_size = 0x00100000;
966 emul_add_tree_options(root, image, name,
967 (WITH_ENVIRONMENT == USER_ENVIRONMENT
968 ? "user" : "virtual"),
969 0 /*oea-interrupt-prefix*/);
971 /* virtual memory - handles growth of stack/heap */
972 vm = tree_parse(root, "/openprom/vm@0x%lx",
973 (unsigned long)(top_of_stack - stack_size));
974 tree_parse(vm, "./stack-base 0x%lx",
975 (unsigned long)(top_of_stack - stack_size));
976 tree_parse(vm, "./nr-bytes 0x%x", stack_size);
978 tree_parse(root, "/openprom/vm/map-binary/file-name %s",
979 bfd_get_filename(image));
981 /* finish the init */
982 tree_parse(root, "/openprom/init/register/pc 0x%lx",
983 (unsigned long)bfd_get_start_address(image));
984 tree_parse(root, "/openprom/init/register/sp 0x%lx",
985 (unsigned long)top_of_stack);
986 tree_parse(root, "/openprom/init/register/msr 0x%x",
987 ((tree_find_boolean_property(root, "/options/little-endian?")
988 ? msr_little_endian_mode
990 | (tree_find_boolean_property(root, "/openprom/options/floating-point?")
991 ? (msr_floating_point_available
992 | msr_floating_point_exception_mode_0
993 | msr_floating_point_exception_mode_1)
995 tree_parse(root, "/openprom/init/stack/stack-type %s",
996 (elf_binary ? "ppc-elf" : "ppc-xcoff"));
998 /* finally our emulation data */
999 data = ZALLOC(os_emul_data);
1001 data->syscalls = syscall;
1008 Solaris - Emulation of user programs for Solaris/PPC
1015 /* Solaris specific implementation */
1017 typedef signed32 solaris_uid_t;
1018 typedef signed32 solaris_gid_t;
1019 typedef signed32 solaris_off_t;
1020 typedef signed32 solaris_pid_t;
1021 typedef signed32 solaris_time_t;
1022 typedef unsigned32 solaris_dev_t;
1023 typedef unsigned32 solaris_ino_t;
1024 typedef unsigned32 solaris_mode_t;
1025 typedef unsigned32 solaris_nlink_t;
1027 #ifdef HAVE_SYS_STAT_H
1028 #define SOLARIS_ST_FSTYPSZ 16 /* array size for file system type name */
1030 struct solaris_stat {
1031 solaris_dev_t st_dev;
1032 signed32 st_pad1[3]; /* reserved for network id */
1033 solaris_ino_t st_ino;
1034 solaris_mode_t st_mode;
1035 solaris_nlink_t st_nlink;
1036 solaris_uid_t st_uid;
1037 solaris_gid_t st_gid;
1038 solaris_dev_t st_rdev;
1039 signed32 st_pad2[2];
1040 solaris_off_t st_size;
1041 signed32 st_pad3; /* future off_t expansion */
1042 struct unix_timeval st_atim;
1043 struct unix_timeval st_mtim;
1044 struct unix_timeval st_ctim;
1045 signed32 st_blksize;
1047 char st_fstype[SOLARIS_ST_FSTYPSZ];
1048 signed32 st_pad4[8]; /* expansion area */
1051 /* Convert from host stat structure to solaris stat structure */
1052 STATIC_INLINE_EMUL_UNIX void
1053 convert_to_solaris_stat(unsigned_word addr,
1058 struct solaris_stat target;
1061 target.st_dev = H2T_4(host->st_dev);
1062 target.st_ino = H2T_4(host->st_ino);
1063 target.st_mode = H2T_4(host->st_mode);
1064 target.st_nlink = H2T_4(host->st_nlink);
1065 target.st_uid = H2T_4(host->st_uid);
1066 target.st_gid = H2T_4(host->st_gid);
1067 target.st_size = H2T_4(host->st_size);
1070 target.st_rdev = H2T_4(host->st_rdev);
1075 #ifdef HAVE_ST_BLKSIZE
1076 target.st_blksize = H2T_4(host->st_blksize);
1078 target.st_blksize = 0;
1081 #ifdef HAVE_ST_BLOCKS
1082 target.st_blocks = H2T_4(host->st_blocks);
1084 target.st_blocks = 0;
1087 target.st_atim.tv_sec = H2T_4(host->st_atime);
1088 target.st_atim.tv_usec = 0;
1090 target.st_ctim.tv_sec = H2T_4(host->st_ctime);
1091 target.st_ctim.tv_usec = 0;
1093 target.st_mtim.tv_sec = H2T_4(host->st_mtime);
1094 target.st_mtim.tv_usec = 0;
1096 for (i = 0; i < sizeof (target.st_pad1) / sizeof (target.st_pad1[0]); i++)
1097 target.st_pad1[i] = 0;
1099 for (i = 0; i < sizeof (target.st_pad2) / sizeof (target.st_pad2[0]); i++)
1100 target.st_pad2[i] = 0;
1104 for (i = 0; i < sizeof (target.st_pad4) / sizeof (target.st_pad4[0]); i++)
1105 target.st_pad4[i] = 0;
1107 /* For now, just punt and always say it is a ufs file */
1108 strcpy (target.st_fstype, "ufs");
1110 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
1112 #endif /* HAVE_SYS_STAT_H */
1115 #define do_solaris_stat 0
1118 do_solaris_stat(os_emul_data *emul,
1124 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
1125 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
1126 char path_buf[PATH_MAX];
1128 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
1131 if (WITH_TRACE && ppc_trace[trace_os_emul])
1132 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
1134 status = stat (path, &buf);
1136 convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
1138 emul_write_status(processor, status, errno);
1143 #define do_solaris_lstat 0
1146 do_solaris_lstat(os_emul_data *emul,
1152 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
1153 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
1154 char path_buf[PATH_MAX];
1156 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
1159 if (WITH_TRACE && ppc_trace[trace_os_emul])
1160 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
1162 status = lstat (path, &buf);
1164 convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
1166 emul_write_status(processor, status, errno);
1171 #define do_solaris_fstat 0
1174 do_solaris_fstat(os_emul_data *emul,
1180 int fildes = (int)cpu_registers(processor)->gpr[arg0];
1181 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
1185 if (WITH_TRACE && ppc_trace[trace_os_emul])
1186 printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt);
1188 status = fstat (fildes, &buf);
1190 convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
1192 emul_write_status(processor, status, errno);
1196 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1197 #define SOLARIS_TIOC ('T'<<8)
1198 #define SOLARIS_NCC 8
1199 #define SOLARIS_NCCS 19
1201 #define SOLARIS_VINTR 0
1202 #define SOLARIS_VQUIT 1
1203 #define SOLARIS_VERASE 2
1204 #define SOLARIS_VKILL 3
1205 #define SOLARIS_VEOF 4
1206 #define SOLARIS_VEOL 5
1207 #define SOLARIS_VEOL2 6
1208 #define SOLARIS_VSWTCH 7
1209 #define SOLARIS_VSTART 8
1210 #define SOLARIS_VSTOP 9
1211 #define SOLARIS_VSUSP 10
1212 #define SOLARIS_VDSUSP 11
1213 #define SOLARIS_VREPRINT 12
1214 #define SOLARIS_VDISCARD 13
1215 #define SOLARIS_VWERASE 14
1216 #define SOLARIS_VLNEXT 15
1219 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1220 /* Convert to/from host termio structure */
1222 struct solaris_termio {
1223 unsigned16 c_iflag; /* input modes */
1224 unsigned16 c_oflag; /* output modes */
1225 unsigned16 c_cflag; /* control modes */
1226 unsigned16 c_lflag; /* line discipline modes */
1227 unsigned8 c_line; /* line discipline */
1228 unsigned8 c_cc[SOLARIS_NCC]; /* control chars */
1231 STATIC_INLINE_EMUL_UNIX void
1232 convert_to_solaris_termio(unsigned_word addr,
1233 struct termio *host,
1237 struct solaris_termio target;
1240 target.c_iflag = H2T_2 (host->c_iflag);
1241 target.c_oflag = H2T_2 (host->c_oflag);
1242 target.c_cflag = H2T_2 (host->c_cflag);
1243 target.c_lflag = H2T_2 (host->c_lflag);
1245 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
1246 target.c_line = host->c_line;
1251 for (i = 0; i < SOLARIS_NCC; i++)
1255 target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];
1259 target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];
1263 target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];
1267 target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];
1271 target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];
1275 target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];
1279 target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];
1283 target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];
1287 target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];
1291 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
1293 #endif /* HAVE_TERMIO_STRUCTURE || HAVE_TERMIOS_STRUCTURE */
1295 #ifdef HAVE_TERMIOS_STRUCTURE
1296 /* Convert to/from host termios structure */
1298 typedef unsigned32 solaris_tcflag_t;
1299 typedef unsigned8 solaris_cc_t;
1300 typedef unsigned32 solaris_speed_t;
1302 struct solaris_termios {
1303 solaris_tcflag_t c_iflag;
1304 solaris_tcflag_t c_oflag;
1305 solaris_tcflag_t c_cflag;
1306 solaris_tcflag_t c_lflag;
1307 solaris_cc_t c_cc[SOLARIS_NCCS];
1310 STATIC_INLINE_EMUL_UNIX void
1311 convert_to_solaris_termios(unsigned_word addr,
1312 struct termios *host,
1316 struct solaris_termios target;
1319 target.c_iflag = H2T_4 (host->c_iflag);
1320 target.c_oflag = H2T_4 (host->c_oflag);
1321 target.c_cflag = H2T_4 (host->c_cflag);
1322 target.c_lflag = H2T_4 (host->c_lflag);
1324 for (i = 0; i < SOLARIS_NCCS; i++)
1328 target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];
1332 target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];
1336 target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];
1340 target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];
1344 target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];
1348 target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];
1352 target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];
1356 target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];
1360 target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];
1365 target.c_cc[SOLARIS_VSTART] = host->c_cc[VSTART];
1369 target.c_cc[SOLARIS_VSTOP] = host->c_cc[VSTOP];
1373 target.c_cc[SOLARIS_VSUSP] = host->c_cc[VSUSP];
1377 target.c_cc[SOLARIS_VDSUSP] = host->c_cc[VDSUSP];
1381 target.c_cc[SOLARIS_VREPRINT] = host->c_cc[VREPRINT];
1385 target.c_cc[SOLARIS_VDISCARD] = host->c_cc[VDISCARD];
1389 target.c_cc[SOLARIS_VWERASE] = host->c_cc[VWERASE];
1393 target.c_cc[SOLARIS_VLNEXT] = host->c_cc[VLNEXT];
1396 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
1398 #endif /* HAVE_TERMIOS_STRUCTURE */
1401 #define do_solaris_ioctl 0
1404 do_solaris_ioctl(os_emul_data *emul,
1410 int fildes = cpu_registers(processor)->gpr[arg0];
1411 unsigned request = cpu_registers(processor)->gpr[arg0+1];
1412 unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
1414 const char *name = "<unknown>";
1416 #ifdef HAVE_TERMIOS_STRUCTURE
1417 struct termios host_termio;
1420 #ifdef HAVE_TERMIO_STRUCTURE
1421 struct termio host_termio;
1427 case 0: /* make sure we have at least one case */
1433 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1434 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
1435 case SOLARIS_TIOC | 1: /* TCGETA */
1437 #ifdef HAVE_TCGETATTR
1438 status = tcgetattr(fildes, &host_termio);
1439 #elif defined(TCGETS)
1440 status = ioctl (fildes, TCGETS, &host_termio);
1442 status = ioctl (fildes, TCGETA, &host_termio);
1445 convert_to_solaris_termio (argp_addr, &host_termio, processor, cia);
1448 #endif /* HAVE_TERMIO_STRUCTURE */
1450 #ifdef HAVE_TERMIOS_STRUCTURE
1451 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
1452 case SOLARIS_TIOC | 13: /* TCGETS */
1454 #ifdef HAVE_TCGETATTR
1455 status = tcgetattr(fildes, &host_termio);
1457 status = ioctl (fildes, TCGETS, &host_termio);
1460 convert_to_solaris_termios (argp_addr, &host_termio, processor, cia);
1463 #endif /* HAVE_TERMIOS_STRUCTURE */
1466 emul_write_status(processor, status, errno);
1468 if (WITH_TRACE && ppc_trace[trace_os_emul])
1469 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);
1471 #endif /* HAVE_IOCTL */
1473 static emul_syscall_descriptor solaris_descriptors[] = {
1474 /* 0 */ { 0, "syscall" },
1475 /* 1 */ { do_unix_exit, "exit" },
1476 /* 2 */ { 0, "fork" },
1477 /* 3 */ { do_unix_read, "read" },
1478 /* 4 */ { do_unix_write, "write" },
1479 /* 5 */ { do_unix_open, "open" },
1480 /* 6 */ { do_unix_close, "close" },
1481 /* 7 */ { 0, "wait" },
1482 /* 8 */ { 0, "creat" },
1483 /* 9 */ { do_unix_link, "link" },
1484 /* 10 */ { do_unix_unlink, "unlink" },
1485 /* 11 */ { 0, "exec" },
1486 /* 12 */ { do_unix_chdir, "chdir" },
1487 /* 13 */ { do_unix_time, "time" },
1488 /* 14 */ { 0, "mknod" },
1489 /* 15 */ { 0, "chmod" },
1490 /* 16 */ { 0, "chown" },
1491 /* 17 */ { do_unix_break, "brk" },
1492 /* 18 */ { do_solaris_stat, "stat" },
1493 /* 19 */ { do_unix_lseek, "lseek" },
1494 /* 20 */ { do_unix_getpid2, "getpid" },
1495 /* 21 */ { 0, "mount" },
1496 /* 22 */ { 0, "umount" },
1497 /* 23 */ { 0, "setuid" },
1498 /* 24 */ { do_unix_getuid2, "getuid" },
1499 /* 25 */ { 0, "stime" },
1500 /* 26 */ { 0, "ptrace" },
1501 /* 27 */ { 0, "alarm" },
1502 /* 28 */ { do_solaris_fstat, "fstat" },
1503 /* 29 */ { 0, "pause" },
1504 /* 30 */ { 0, "utime" },
1505 /* 31 */ { 0, "stty" },
1506 /* 32 */ { 0, "gtty" },
1507 /* 33 */ { do_unix_access, "access" },
1508 /* 34 */ { 0, "nice" },
1509 /* 35 */ { 0, "statfs" },
1510 /* 36 */ { 0, "sync" },
1511 /* 37 */ { 0, "kill" },
1512 /* 38 */ { 0, "fstatfs" },
1513 /* 39 */ { 0, "pgrpsys" },
1514 /* 40 */ { 0, "xenix" },
1515 /* 41 */ { do_unix_dup, "dup" },
1516 /* 42 */ { 0, "pipe" },
1517 /* 43 */ { 0, "times" },
1518 /* 44 */ { 0, "profil" },
1519 /* 45 */ { 0, "plock" },
1520 /* 46 */ { 0, "setgid" },
1521 /* 47 */ { do_unix_getgid2, "getgid" },
1522 /* 48 */ { 0, "signal" },
1523 /* 49 */ { 0, "msgsys" },
1524 /* 50 */ { 0, "syssun" },
1525 /* 51 */ { 0, "acct" },
1526 /* 52 */ { 0, "shmsys" },
1527 /* 53 */ { 0, "semsys" },
1528 /* 54 */ { do_solaris_ioctl, "ioctl" },
1529 /* 55 */ { 0, "uadmin" },
1530 /* 56 */ { 0, 0 /* reserved for exch */ },
1531 /* 57 */ { 0, "utssys" },
1532 /* 58 */ { 0, "fdsync" },
1533 /* 59 */ { 0, "execve" },
1534 /* 60 */ { do_unix_umask, "umask" },
1535 /* 61 */ { 0, "chroot" },
1536 /* 62 */ { 0, "fcntl" },
1537 /* 63 */ { 0, "ulimit" },
1538 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1539 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1540 /* 65 */ { 0, 0 /* reserved for UNIX PC */ },
1541 /* 66 */ { 0, 0 /* reserved for UNIX PC */ },
1542 /* 67 */ { 0, 0 /* reserved for UNIX PC */ },
1543 /* 68 */ { 0, 0 /* reserved for UNIX PC */ },
1544 /* 69 */ { 0, 0 /* reserved for UNIX PC */ },
1545 /* 70 */ { 0, 0 /* was advfs */ },
1546 /* 71 */ { 0, 0 /* was unadvfs */ },
1547 /* 72 */ { 0, 0 /* was rmount */ },
1548 /* 73 */ { 0, 0 /* was rumount */ },
1549 /* 74 */ { 0, 0 /* was rfstart */ },
1550 /* 75 */ { 0, 0 /* was sigret */ },
1551 /* 76 */ { 0, 0 /* was rdebug */ },
1552 /* 77 */ { 0, 0 /* was rfstop */ },
1553 /* 78 */ { 0, 0 /* was rfsys */ },
1554 /* 79 */ { do_unix_rmdir, "rmdir" },
1555 /* 80 */ { do_unix_mkdir, "mkdir" },
1556 /* 81 */ { 0, "getdents" },
1557 /* 82 */ { 0, 0 /* was libattach */ },
1558 /* 83 */ { 0, 0 /* was libdetach */ },
1559 /* 84 */ { 0, "sysfs" },
1560 /* 85 */ { 0, "getmsg" },
1561 /* 86 */ { 0, "putmsg" },
1562 /* 87 */ { 0, "poll" },
1563 /* 88 */ { do_solaris_lstat, "lstat" },
1564 /* 89 */ { do_unix_symlink, "symlink" },
1565 /* 90 */ { 0, "readlink" },
1566 /* 91 */ { 0, "setgroups" },
1567 /* 92 */ { 0, "getgroups" },
1568 /* 93 */ { 0, "fchmod" },
1569 /* 94 */ { 0, "fchown" },
1570 /* 95 */ { 0, "sigprocmask" },
1571 /* 96 */ { 0, "sigsuspend" },
1572 /* 97 */ { do_unix_nop, "sigaltstack" },
1573 /* 98 */ { do_unix_nop, "sigaction" },
1574 /* 99 */ { 0, "sigpending" },
1575 /* 100 */ { 0, "context" },
1576 /* 101 */ { 0, "evsys" },
1577 /* 102 */ { 0, "evtrapret" },
1578 /* 103 */ { 0, "statvfs" },
1579 /* 104 */ { 0, "fstatvfs" },
1580 /* 105 */ { 0, 0 /* reserved */ },
1581 /* 106 */ { 0, "nfssys" },
1582 /* 107 */ { 0, "waitsys" },
1583 /* 108 */ { 0, "sigsendsys" },
1584 /* 109 */ { 0, "hrtsys" },
1585 /* 110 */ { 0, "acancel" },
1586 /* 111 */ { 0, "async" },
1587 /* 112 */ { 0, "priocntlsys" },
1588 /* 113 */ { 0, "pathconf" },
1589 /* 114 */ { 0, "mincore" },
1590 /* 115 */ { 0, "mmap" },
1591 /* 116 */ { 0, "mprotect" },
1592 /* 117 */ { 0, "munmap" },
1593 /* 118 */ { 0, "fpathconf" },
1594 /* 119 */ { 0, "vfork" },
1595 /* 120 */ { 0, "fchdir" },
1596 /* 121 */ { 0, "readv" },
1597 /* 122 */ { 0, "writev" },
1598 /* 123 */ { 0, "xstat" },
1599 /* 124 */ { 0, "lxstat" },
1600 /* 125 */ { 0, "fxstat" },
1601 /* 126 */ { 0, "xmknod" },
1602 /* 127 */ { 0, "clocal" },
1603 /* 128 */ { 0, "setrlimit" },
1604 /* 129 */ { 0, "getrlimit" },
1605 /* 130 */ { 0, "lchown" },
1606 /* 131 */ { 0, "memcntl" },
1607 /* 132 */ { 0, "getpmsg" },
1608 /* 133 */ { 0, "putpmsg" },
1609 /* 134 */ { 0, "rename" },
1610 /* 135 */ { 0, "uname" },
1611 /* 136 */ { 0, "setegid" },
1612 /* 137 */ { 0, "sysconfig" },
1613 /* 138 */ { 0, "adjtime" },
1614 /* 139 */ { 0, "systeminfo" },
1615 /* 140 */ { 0, 0 /* reserved */ },
1616 /* 141 */ { 0, "seteuid" },
1617 /* 142 */ { 0, "vtrace" },
1618 /* 143 */ { 0, "fork1" },
1619 /* 144 */ { 0, "sigtimedwait" },
1620 /* 145 */ { 0, "lwp_info" },
1621 /* 146 */ { 0, "yield" },
1622 /* 147 */ { 0, "lwp_sema_wait" },
1623 /* 148 */ { 0, "lwp_sema_post" },
1624 /* 149 */ { 0, 0 /* reserved */ },
1625 /* 150 */ { 0, 0 /* reserved */ },
1626 /* 151 */ { 0, 0 /* reserved */ },
1627 /* 152 */ { 0, "modctl" },
1628 /* 153 */ { 0, "fchroot" },
1629 /* 154 */ { 0, "utimes" },
1630 /* 155 */ { 0, "vhangup" },
1631 /* 156 */ { do_unix_gettimeofday, "gettimeofday" },
1632 /* 157 */ { 0, "getitimer" },
1633 /* 158 */ { 0, "setitimer" },
1634 /* 159 */ { 0, "lwp_create" },
1635 /* 160 */ { 0, "lwp_exit" },
1636 /* 161 */ { 0, "lwp_suspend" },
1637 /* 162 */ { 0, "lwp_continue" },
1638 /* 163 */ { 0, "lwp_kill" },
1639 /* 164 */ { 0, "lwp_self" },
1640 /* 165 */ { 0, "lwp_setprivate" },
1641 /* 166 */ { 0, "lwp_getprivate" },
1642 /* 167 */ { 0, "lwp_wait" },
1643 /* 168 */ { 0, "lwp_mutex_unlock" },
1644 /* 169 */ { 0, "lwp_mutex_lock" },
1645 /* 170 */ { 0, "lwp_cond_wait" },
1646 /* 171 */ { 0, "lwp_cond_signal" },
1647 /* 172 */ { 0, "lwp_cond_broadcast" },
1648 /* 173 */ { 0, "pread" },
1649 /* 174 */ { 0, "pwrite" },
1650 /* 175 */ { 0, "llseek" },
1651 /* 176 */ { 0, "inst_sync" },
1652 /* 177 */ { 0, 0 /* reserved */ },
1653 /* 178 */ { 0, "kaio" },
1654 /* 179 */ { 0, 0 /* reserved */ },
1655 /* 180 */ { 0, 0 /* reserved */ },
1656 /* 181 */ { 0, 0 /* reserved */ },
1657 /* 182 */ { 0, 0 /* reserved */ },
1658 /* 183 */ { 0, 0 /* reserved */ },
1659 /* 184 */ { 0, "tsolsys" },
1660 /* 185 */ { 0, "acl" },
1661 /* 186 */ { 0, "auditsys" },
1662 /* 187 */ { 0, "processor_bind" },
1663 /* 188 */ { 0, "processor_info" },
1664 /* 189 */ { 0, "p_online" },
1665 /* 190 */ { 0, "sigqueue" },
1666 /* 191 */ { 0, "clock_gettime" },
1667 /* 192 */ { 0, "clock_settime" },
1668 /* 193 */ { 0, "clock_getres" },
1669 /* 194 */ { 0, "timer_create" },
1670 /* 195 */ { 0, "timer_delete" },
1671 /* 196 */ { 0, "timer_settime" },
1672 /* 197 */ { 0, "timer_gettime" },
1673 /* 198 */ { 0, "timer_getoverrun" },
1674 /* 199 */ { 0, "nanosleep" },
1675 /* 200 */ { 0, "facl" },
1676 /* 201 */ { 0, "door" },
1677 /* 202 */ { 0, "setreuid" },
1678 /* 203 */ { 0, "setregid" },
1679 /* 204 */ { 0, "install_utrap" },
1680 /* 205 */ { 0, 0 /* reserved */ },
1681 /* 206 */ { 0, 0 /* reserved */ },
1682 /* 207 */ { 0, 0 /* reserved */ },
1683 /* 208 */ { 0, 0 /* reserved */ },
1684 /* 209 */ { 0, 0 /* reserved */ },
1685 /* 210 */ { 0, "signotifywait" },
1686 /* 211 */ { 0, "lwp_sigredirect" },
1687 /* 212 */ { 0, "lwp_alarm" },
1690 static char *(solaris_error_names[]) = {
1729 /* 38 */ "EL2NSYNC",
1738 /* 47 */ "ECANCELED",
1747 /* 56 */ "EDEADLOCK",
1749 /* 58 */ "Error code 58",
1750 /* 59 */ "Error code 59",
1763 /* 72 */ "Error code 72",
1764 /* 73 */ "Error code 73",
1765 /* 74 */ "EMULTIHOP",
1766 /* 75 */ "Error code 75",
1767 /* 76 */ "Error code 76",
1769 /* 78 */ "ENAMETOOLONG",
1770 /* 79 */ "EOVERFLOW",
1771 /* 80 */ "ENOTUNIQ",
1778 /* 87 */ "ELIBEXEC",
1782 /* 91 */ "ERESTART",
1783 /* 92 */ "ESTRPIPE",
1784 /* 93 */ "ENOTEMPTY",
1786 /* 95 */ "ENOTSOCK",
1787 /* 96 */ "EDESTADDRREQ",
1788 /* 97 */ "EMSGSIZE",
1789 /* 98 */ "EPROTOTYPE",
1790 /* 99 */ "ENOPROTOOPT",
1791 /* 100 */ "Error code 100",
1792 /* 101 */ "Error code 101",
1793 /* 102 */ "Error code 102",
1794 /* 103 */ "Error code 103",
1795 /* 104 */ "Error code 104",
1796 /* 105 */ "Error code 105",
1797 /* 106 */ "Error code 106",
1798 /* 107 */ "Error code 107",
1799 /* 108 */ "Error code 108",
1800 /* 109 */ "Error code 109",
1801 /* 110 */ "Error code 110",
1802 /* 111 */ "Error code 111",
1803 /* 112 */ "Error code 112",
1804 /* 113 */ "Error code 113",
1805 /* 114 */ "Error code 114",
1806 /* 115 */ "Error code 115",
1807 /* 116 */ "Error code 116",
1808 /* 117 */ "Error code 117",
1809 /* 118 */ "Error code 118",
1810 /* 119 */ "Error code 119",
1811 /* 120 */ "EPROTONOSUPPORT",
1812 /* 121 */ "ESOCKTNOSUPPORT",
1813 /* 122 */ "EOPNOTSUPP",
1814 /* 123 */ "EPFNOSUPPORT",
1815 /* 124 */ "EAFNOSUPPORT",
1816 /* 125 */ "EADDRINUSE",
1817 /* 126 */ "EADDRNOTAVAIL",
1818 /* 127 */ "ENETDOWN",
1819 /* 128 */ "ENETUNREACH",
1820 /* 129 */ "ENETRESET",
1821 /* 130 */ "ECONNABORTED",
1822 /* 131 */ "ECONNRESET",
1823 /* 132 */ "ENOBUFS",
1824 /* 133 */ "EISCONN",
1825 /* 134 */ "ENOTCONN",
1826 /* 135 */ "Error code 135", /* XENIX has 135 - 142 */
1827 /* 136 */ "Error code 136",
1828 /* 137 */ "Error code 137",
1829 /* 138 */ "Error code 138",
1830 /* 139 */ "Error code 139",
1831 /* 140 */ "Error code 140",
1832 /* 141 */ "Error code 141",
1833 /* 142 */ "Error code 142",
1834 /* 143 */ "ESHUTDOWN",
1835 /* 144 */ "ETOOMANYREFS",
1836 /* 145 */ "ETIMEDOUT",
1837 /* 146 */ "ECONNREFUSED",
1838 /* 147 */ "EHOSTDOWN",
1839 /* 148 */ "EHOSTUNREACH",
1840 /* 149 */ "EALREADY",
1841 /* 150 */ "EINPROGRESS",
1845 static char *(solaris_signal_names[]) = {
1866 /* 20 */ "SIGWINCH",
1874 /* 28 */ "SIGVTALRM",
1878 /* 32 */ "SIGWAITING",
1880 /* 34 */ "SIGFREEZE",
1882 /* 36 */ "SIGCANCEL",
1885 static emul_syscall emul_solaris_syscalls = {
1886 solaris_descriptors,
1887 sizeof(solaris_descriptors) / sizeof(solaris_descriptors[0]),
1888 solaris_error_names,
1889 sizeof(solaris_error_names) / sizeof(solaris_error_names[0]),
1890 solaris_signal_names,
1891 sizeof(solaris_signal_names) / sizeof(solaris_signal_names[0]),
1895 /* Solaris's os_emul interface, most are just passed on to the generic
1898 static os_emul_data *
1899 emul_solaris_create(device *root,
1903 /* check that this emulation is really for us */
1904 if (name != NULL && strcmp(name, "solaris") != 0)
1910 return emul_unix_create(root, image, "solaris", &emul_solaris_syscalls);
1914 emul_solaris_init(os_emul_data *emul_data,
1921 emul_solaris_system_call(cpu *processor,
1923 os_emul_data *emul_data)
1925 emul_do_system_call(emul_data,
1926 emul_data->syscalls,
1927 cpu_registers(processor)->gpr[0],
1928 3, /*r3 contains arg0*/
1933 const os_emul emul_solaris = {
1935 emul_solaris_create,
1937 emul_solaris_system_call,
1938 0, /*instruction_call*/
1945 Linux - Emulation of user programs for Linux/PPC
1952 /* Linux specific implementation */
1954 typedef unsigned32 linux_dev_t;
1955 typedef unsigned32 linux_ino_t;
1956 typedef unsigned32 linux_mode_t;
1957 typedef unsigned16 linux_nlink_t;
1958 typedef signed32 linux_off_t;
1959 typedef signed32 linux_pid_t;
1960 typedef unsigned32 linux_uid_t;
1961 typedef unsigned32 linux_gid_t;
1962 typedef unsigned32 linux_size_t;
1963 typedef signed32 linux_ssize_t;
1964 typedef signed32 linux_ptrdiff_t;
1965 typedef signed32 linux_time_t;
1966 typedef signed32 linux_clock_t;
1967 typedef signed32 linux_daddr_t;
1969 #ifdef HAVE_SYS_STAT_H
1970 /* For the PowerPC, don't both with the 'old' stat structure, since there
1971 should be no extant binaries with that structure. */
1976 linux_mode_t st_mode;
1977 linux_nlink_t st_nlink;
1980 linux_dev_t st_rdev;
1981 linux_off_t st_size;
1982 unsigned32 st_blksize;
1983 unsigned32 st_blocks;
1984 unsigned32 st_atimx; /* don't use st_{a,c,m}time, that might a macro */
1985 unsigned32 __unused1; /* defined by the host's stat.h */
1986 unsigned32 st_mtimx;
1987 unsigned32 __unused2;
1988 unsigned32 st_ctimx;
1989 unsigned32 __unused3;
1990 unsigned32 __unused4;
1991 unsigned32 __unused5;
1994 /* Convert from host stat structure to solaris stat structure */
1995 STATIC_INLINE_EMUL_UNIX void
1996 convert_to_linux_stat(unsigned_word addr,
2001 struct linux_stat target;
2003 target.st_dev = H2T_4(host->st_dev);
2004 target.st_ino = H2T_4(host->st_ino);
2005 target.st_mode = H2T_4(host->st_mode);
2006 target.st_nlink = H2T_2(host->st_nlink);
2007 target.st_uid = H2T_4(host->st_uid);
2008 target.st_gid = H2T_4(host->st_gid);
2009 target.st_size = H2T_4(host->st_size);
2012 target.st_rdev = H2T_4(host->st_rdev);
2017 #ifdef HAVE_ST_BLKSIZE
2018 target.st_blksize = H2T_4(host->st_blksize);
2020 target.st_blksize = 0;
2023 #ifdef HAVE_ST_BLOCKS
2024 target.st_blocks = H2T_4(host->st_blocks);
2026 target.st_blocks = 0;
2029 target.st_atimx = H2T_4(host->st_atime);
2030 target.st_ctimx = H2T_4(host->st_ctime);
2031 target.st_mtimx = H2T_4(host->st_mtime);
2032 target.__unused1 = 0;
2033 target.__unused2 = 0;
2034 target.__unused3 = 0;
2035 target.__unused4 = 0;
2036 target.__unused5 = 0;
2038 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
2040 #endif /* HAVE_SYS_STAT_H */
2043 #define do_linux_stat 0
2046 do_linux_stat(os_emul_data *emul,
2052 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
2053 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
2054 char path_buf[PATH_MAX];
2056 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
2059 if (WITH_TRACE && ppc_trace[trace_os_emul])
2060 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
2062 status = stat (path, &buf);
2064 convert_to_linux_stat (stat_pkt, &buf, processor, cia);
2066 emul_write_status(processor, status, errno);
2071 #define do_linux_lstat 0
2074 do_linux_lstat(os_emul_data *emul,
2080 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
2081 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
2082 char path_buf[PATH_MAX];
2084 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
2087 if (WITH_TRACE && ppc_trace[trace_os_emul])
2088 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
2090 status = lstat (path, &buf);
2092 convert_to_linux_stat (stat_pkt, &buf, processor, cia);
2094 emul_write_status(processor, status, errno);
2099 #define do_linux_fstat 0
2102 do_linux_fstat(os_emul_data *emul,
2108 int fildes = (int)cpu_registers(processor)->gpr[arg0];
2109 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
2113 if (WITH_TRACE && ppc_trace[trace_os_emul])
2114 printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt);
2116 status = fstat (fildes, &buf);
2118 convert_to_linux_stat (stat_pkt, &buf, processor, cia);
2120 emul_write_status(processor, status, errno);
2124 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2125 #define LINUX_NCC 10
2126 #define LINUX_NCCS 19
2128 #define LINUX_VINTR 0
2129 #define LINUX_VQUIT 1
2130 #define LINUX_VERASE 2
2131 #define LINUX_VKILL 3
2132 #define LINUX_VEOF 4
2133 #define LINUX_VMIN 5
2134 #define LINUX_VEOL 6
2135 #define LINUX_VTIME 7
2136 #define LINUX_VEOL2 8
2137 #define LINUX_VSWTC 9
2138 #define LINUX_VWERASE 10
2139 #define LINUX_VREPRINT 11
2140 #define LINUX_VSUSP 12
2141 #define LINUX_VSTART 13
2142 #define LINUX_VSTOP 14
2143 #define LINUX_VLNEXT 15
2144 #define LINUX_VDISCARD 16
2146 #define LINUX_IOC_NRBITS 8
2147 #define LINUX_IOC_TYPEBITS 8
2148 #define LINUX_IOC_SIZEBITS 13
2149 #define LINUX_IOC_DIRBITS 3
2151 #define LINUX_IOC_NRMASK ((1 << LINUX_IOC_NRBITS)-1)
2152 #define LINUX_IOC_TYPEMASK ((1 << LINUX_IOC_TYPEBITS)-1)
2153 #define LINUX_IOC_SIZEMASK ((1 << LINUX_IOC_SIZEBITS)-1)
2154 #define LINUX_IOC_DIRMASK ((1 << LINUX_IOC_DIRBITS)-1)
2156 #define LINUX_IOC_NRSHIFT 0
2157 #define LINUX_IOC_TYPESHIFT (LINUX_IOC_NRSHIFT+LINUX_IOC_NRBITS)
2158 #define LINUX_IOC_SIZESHIFT (LINUX_IOC_TYPESHIFT+LINUX_IOC_TYPEBITS)
2159 #define LINUX_IOC_DIRSHIFT (LINUX_IOC_SIZESHIFT+LINUX_IOC_SIZEBITS)
2162 * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
2163 * And this turns out useful to catch old ioctl numbers in header
2166 #define LINUX_IOC_NONE 1U
2167 #define LINUX_IOC_READ 2U
2168 #define LINUX_IOC_WRITE 4U
2170 #define LINUX_IOC(dir,type,nr,size) \
2171 (((dir) << LINUX_IOC_DIRSHIFT) | \
2172 ((type) << LINUX_IOC_TYPESHIFT) | \
2173 ((nr) << LINUX_IOC_NRSHIFT) | \
2174 ((size) << LINUX_IOC_SIZESHIFT))
2176 /* used to create numbers */
2177 #define LINUX_IO(type,nr) LINUX_IOC(LINUX_IOC_NONE,(type),(nr),0)
2178 #define LINUX_IOR(type,nr,size) LINUX_IOC(LINUX_IOC_READ,(type),(nr),sizeof(size))
2179 #define LINUX_IOW(type,nr,size) LINUX_IOC(LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2180 #define LINUX_IOWR(type,nr,size) LINUX_IOC(LINUX_IOC_READ|LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2183 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2184 /* Convert to/from host termio structure */
2186 struct linux_termio {
2187 unsigned16 c_iflag; /* input modes */
2188 unsigned16 c_oflag; /* output modes */
2189 unsigned16 c_cflag; /* control modes */
2190 unsigned16 c_lflag; /* line discipline modes */
2191 unsigned8 c_line; /* line discipline */
2192 unsigned8 c_cc[LINUX_NCC]; /* control chars */
2195 STATIC_INLINE_EMUL_UNIX void
2196 convert_to_linux_termio(unsigned_word addr,
2197 struct termio *host,
2201 struct linux_termio target;
2204 target.c_iflag = H2T_2 (host->c_iflag);
2205 target.c_oflag = H2T_2 (host->c_oflag);
2206 target.c_cflag = H2T_2 (host->c_cflag);
2207 target.c_lflag = H2T_2 (host->c_lflag);
2209 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
2210 target.c_line = host->c_line;
2215 for (i = 0; i < LINUX_NCC; i++)
2219 target.c_cc[LINUX_VINTR] = host->c_cc[VINTR];
2223 target.c_cc[LINUX_VQUIT] = host->c_cc[VQUIT];
2227 target.c_cc[LINUX_VERASE] = host->c_cc[VERASE];
2231 target.c_cc[LINUX_VKILL] = host->c_cc[VKILL];
2235 target.c_cc[LINUX_VEOF] = host->c_cc[VEOF];
2239 target.c_cc[LINUX_VMIN] = host->c_cc[VMIN];
2243 target.c_cc[LINUX_VEOL] = host->c_cc[VEOL];
2247 target.c_cc[LINUX_VTIME] = host->c_cc[VTIME];
2251 target.c_cc[LINUX_VEOL2] = host->c_cc[VEOL2];
2255 target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTC];
2259 target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTCH];
2262 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
2264 #endif /* HAVE_TERMIO_STRUCTURE */
2266 #ifdef HAVE_TERMIOS_STRUCTURE
2267 /* Convert to/from host termios structure */
2269 typedef unsigned32 linux_tcflag_t;
2270 typedef unsigned8 linux_cc_t;
2271 typedef unsigned32 linux_speed_t;
2273 struct linux_termios {
2274 linux_tcflag_t c_iflag;
2275 linux_tcflag_t c_oflag;
2276 linux_tcflag_t c_cflag;
2277 linux_tcflag_t c_lflag;
2278 linux_cc_t c_cc[LINUX_NCCS];
2284 STATIC_INLINE_EMUL_UNIX void
2285 convert_to_linux_termios(unsigned_word addr,
2286 struct termios *host,
2290 struct linux_termios target;
2293 target.c_iflag = H2T_4 (host->c_iflag);
2294 target.c_oflag = H2T_4 (host->c_oflag);
2295 target.c_cflag = H2T_4 (host->c_cflag);
2296 target.c_lflag = H2T_4 (host->c_lflag);
2298 for (i = 0; i < LINUX_NCCS; i++)
2302 target.c_cc[LINUX_VINTR] = host->c_cc[VINTR];
2306 target.c_cc[LINUX_VQUIT] = host->c_cc[VQUIT];
2310 target.c_cc[LINUX_VERASE] = host->c_cc[VERASE];
2314 target.c_cc[LINUX_VKILL] = host->c_cc[VKILL];
2318 target.c_cc[LINUX_VEOF] = host->c_cc[VEOF];
2322 target.c_cc[LINUX_VEOL] = host->c_cc[VEOL];
2326 target.c_cc[LINUX_VEOL2] = host->c_cc[VEOL2];
2330 target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTCH];
2333 #ifdef HAVE_TERMIOS_CLINE
2334 target.c_line = host->c_line;
2339 #ifdef HAVE_CFGETISPEED
2340 target.c_ispeed = cfgetispeed (host);
2342 target.c_ispeed = 0;
2345 #ifdef HAVE_CFGETOSPEED
2346 target.c_ospeed = cfgetospeed (host);
2348 target.c_ospeed = 0;
2351 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
2353 #endif /* HAVE_TERMIOS_STRUCTURE */
2356 #define do_linux_ioctl 0
2359 do_linux_ioctl(os_emul_data *emul,
2365 int fildes = cpu_registers(processor)->gpr[arg0];
2366 unsigned request = cpu_registers(processor)->gpr[arg0+1];
2367 unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
2369 const char *name = "<unknown>";
2371 #ifdef HAVE_TERMIOS_STRUCTURE
2372 struct termios host_termio;
2375 #ifdef HAVE_TERMIO_STRUCTURE
2376 struct termio host_termio;
2382 case 0: /* make sure we have at least one case */
2388 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2389 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
2390 case LINUX_IOR('t', 23, struct linux_termio): /* TCGETA */
2392 #ifdef HAVE_TCGETATTR
2393 status = tcgetattr(fildes, &host_termio);
2394 #elif defined(TCGETS)
2395 status = ioctl (fildes, TCGETS, &host_termio);
2397 status = ioctl (fildes, TCGETA, &host_termio);
2400 convert_to_linux_termio (argp_addr, &host_termio, processor, cia);
2403 #endif /* HAVE_TERMIO_STRUCTURE */
2405 #ifdef HAVE_TERMIOS_STRUCTURE
2406 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
2407 case LINUX_IOR('t', 19, struct linux_termios): /* TCGETS */
2409 #ifdef HAVE_TCGETATTR
2410 status = tcgetattr(fildes, &host_termio);
2412 status = ioctl (fildes, TCGETS, &host_termio);
2415 convert_to_linux_termios (argp_addr, &host_termio, processor, cia);
2418 #endif /* HAVE_TERMIOS_STRUCTURE */
2421 emul_write_status(processor, status, errno);
2423 if (WITH_TRACE && ppc_trace[trace_os_emul])
2424 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);
2426 #endif /* HAVE_IOCTL */
2428 static emul_syscall_descriptor linux_descriptors[] = {
2429 /* 0 */ { 0, "setup" },
2430 /* 1 */ { do_unix_exit, "exit" },
2431 /* 2 */ { 0, "fork" },
2432 /* 3 */ { do_unix_read, "read" },
2433 /* 4 */ { do_unix_write, "write" },
2434 /* 5 */ { do_unix_open, "open" },
2435 /* 6 */ { do_unix_close, "close" },
2436 /* 7 */ { 0, "waitpid" },
2437 /* 8 */ { 0, "creat" },
2438 /* 9 */ { do_unix_link, "link" },
2439 /* 10 */ { do_unix_unlink, "unlink" },
2440 /* 11 */ { 0, "execve" },
2441 /* 12 */ { do_unix_chdir, "chdir" },
2442 /* 13 */ { do_unix_time, "time" },
2443 /* 14 */ { 0, "mknod" },
2444 /* 15 */ { 0, "chmod" },
2445 /* 16 */ { 0, "chown" },
2446 /* 17 */ { 0, "break" },
2447 /* 18 */ { 0, "stat" },
2448 /* 19 */ { do_unix_lseek, "lseek" },
2449 /* 20 */ { do_unix_getpid, "getpid" },
2450 /* 21 */ { 0, "mount" },
2451 /* 22 */ { 0, "umount" },
2452 /* 23 */ { 0, "setuid" },
2453 /* 24 */ { do_unix_getuid, "getuid" },
2454 /* 25 */ { 0, "stime" },
2455 /* 26 */ { 0, "ptrace" },
2456 /* 27 */ { 0, "alarm" },
2457 /* 28 */ { 0, "fstat" },
2458 /* 29 */ { 0, "pause" },
2459 /* 30 */ { 0, "utime" },
2460 /* 31 */ { 0, "stty" },
2461 /* 32 */ { 0, "gtty" },
2462 /* 33 */ { do_unix_access, "access" },
2463 /* 34 */ { 0, "nice" },
2464 /* 35 */ { 0, "ftime" },
2465 /* 36 */ { 0, "sync" },
2466 /* 37 */ { 0, "kill" },
2467 /* 38 */ { 0, "rename" },
2468 /* 39 */ { do_unix_mkdir, "mkdir" },
2469 /* 40 */ { do_unix_rmdir, "rmdir" },
2470 /* 41 */ { do_unix_dup, "dup" },
2471 /* 42 */ { 0, "pipe" },
2472 /* 43 */ { 0, "times" },
2473 /* 44 */ { 0, "prof" },
2474 /* 45 */ { do_unix_break, "brk" },
2475 /* 46 */ { 0, "setgid" },
2476 /* 47 */ { do_unix_getgid, "getgid" },
2477 /* 48 */ { 0, "signal" },
2478 /* 49 */ { do_unix_geteuid, "geteuid" },
2479 /* 50 */ { do_unix_getegid, "getegid" },
2480 /* 51 */ { 0, "acct" },
2481 /* 52 */ { 0, "phys" },
2482 /* 53 */ { 0, "lock" },
2483 /* 54 */ { do_linux_ioctl, "ioctl" },
2484 /* 55 */ { 0, "fcntl" },
2485 /* 56 */ { 0, "mpx" },
2486 /* 57 */ { 0, "setpgid" },
2487 /* 58 */ { 0, "ulimit" },
2488 /* 59 */ { 0, "olduname" },
2489 /* 60 */ { do_unix_umask, "umask" },
2490 /* 61 */ { 0, "chroot" },
2491 /* 62 */ { 0, "ustat" },
2492 /* 63 */ { do_unix_dup2, "dup2" },
2493 /* 64 */ { do_unix_getppid, "getppid" },
2494 /* 65 */ { 0, "getpgrp" },
2495 /* 66 */ { 0, "setsid" },
2496 /* 67 */ { 0, "sigaction" },
2497 /* 68 */ { 0, "sgetmask" },
2498 /* 69 */ { 0, "ssetmask" },
2499 /* 70 */ { 0, "setreuid" },
2500 /* 71 */ { 0, "setregid" },
2501 /* 72 */ { 0, "sigsuspend" },
2502 /* 73 */ { 0, "sigpending" },
2503 /* 74 */ { 0, "sethostname" },
2504 /* 75 */ { 0, "setrlimit" },
2505 /* 76 */ { 0, "getrlimit" },
2506 /* 77 */ { do_unix_getrusage, "getrusage" },
2507 /* 78 */ { do_unix_gettimeofday, "gettimeofday" },
2508 /* 79 */ { 0, "settimeofday" },
2509 /* 80 */ { 0, "getgroups" },
2510 /* 81 */ { 0, "setgroups" },
2511 /* 82 */ { 0, "select" },
2512 /* 83 */ { do_unix_symlink, "symlink" },
2513 /* 84 */ { 0, "lstat" },
2514 /* 85 */ { 0, "readlink" },
2515 /* 86 */ { 0, "uselib" },
2516 /* 87 */ { 0, "swapon" },
2517 /* 88 */ { 0, "reboot" },
2518 /* 89 */ { 0, "readdir" },
2519 /* 90 */ { 0, "mmap" },
2520 /* 91 */ { 0, "munmap" },
2521 /* 92 */ { 0, "truncate" },
2522 /* 93 */ { 0, "ftruncate" },
2523 /* 94 */ { 0, "fchmod" },
2524 /* 95 */ { 0, "fchown" },
2525 /* 96 */ { 0, "getpriority" },
2526 /* 97 */ { 0, "setpriority" },
2527 /* 98 */ { 0, "profil" },
2528 /* 99 */ { 0, "statfs" },
2529 /* 100 */ { 0, "fstatfs" },
2530 /* 101 */ { 0, "ioperm" },
2531 /* 102 */ { 0, "socketcall" },
2532 /* 103 */ { 0, "syslog" },
2533 /* 104 */ { 0, "setitimer" },
2534 /* 105 */ { 0, "getitimer" },
2535 /* 106 */ { do_linux_stat, "newstat" },
2536 /* 107 */ { do_linux_lstat, "newlstat" },
2537 /* 108 */ { do_linux_fstat, "newfstat" },
2538 /* 109 */ { 0, "uname" },
2539 /* 110 */ { 0, "iopl" },
2540 /* 111 */ { 0, "vhangup" },
2541 /* 112 */ { 0, "idle" },
2542 /* 113 */ { 0, "vm86" },
2543 /* 114 */ { 0, "wait4" },
2544 /* 115 */ { 0, "swapoff" },
2545 /* 116 */ { 0, "sysinfo" },
2546 /* 117 */ { 0, "ipc" },
2547 /* 118 */ { 0, "fsync" },
2548 /* 119 */ { 0, "sigreturn" },
2549 /* 120 */ { 0, "clone" },
2550 /* 121 */ { 0, "setdomainname" },
2551 /* 122 */ { 0, "newuname" },
2552 /* 123 */ { 0, "modify_ldt" },
2553 /* 124 */ { 0, "adjtimex" },
2554 /* 125 */ { 0, "mprotect" },
2555 /* 126 */ { 0, "sigprocmask" },
2556 /* 127 */ { 0, "create_module" },
2557 /* 128 */ { 0, "init_module" },
2558 /* 129 */ { 0, "delete_module" },
2559 /* 130 */ { 0, "get_kernel_syms" },
2560 /* 131 */ { 0, "quotactl" },
2561 /* 132 */ { 0, "getpgid" },
2562 /* 133 */ { 0, "fchdir" },
2563 /* 134 */ { 0, "bdflush" },
2564 /* 135 */ { 0, "sysfs" },
2565 /* 136 */ { 0, "personality" },
2566 /* 137 */ { 0, "afs_syscall" },
2567 /* 138 */ { 0, "setfsuid" },
2568 /* 139 */ { 0, "setfsgid" },
2569 /* 140 */ { 0, "llseek" },
2570 /* 141 */ { 0, "getdents" },
2571 /* 142 */ { 0, "newselect" },
2572 /* 143 */ { 0, "flock" },
2573 /* 144 */ { 0, "msync" },
2574 /* 145 */ { 0, "readv" },
2575 /* 146 */ { 0, "writev" },
2576 /* 147 */ { 0, "getsid" },
2577 /* 148 */ { 0, "fdatasync" },
2578 /* 149 */ { 0, "sysctl" },
2579 /* 150 */ { 0, "mlock" },
2580 /* 151 */ { 0, "munlock" },
2581 /* 152 */ { 0, "mlockall" },
2582 /* 153 */ { 0, "munlockall" },
2583 /* 154 */ { 0, "sched_setparam" },
2584 /* 155 */ { 0, "sched_getparam" },
2585 /* 156 */ { 0, "sched_setscheduler" },
2586 /* 157 */ { 0, "sched_getscheduler" },
2587 /* 158 */ { 0, "sched_yield" },
2588 /* 159 */ { 0, "sched_get_priority_max" },
2589 /* 160 */ { 0, "sched_get_priority_min" },
2590 /* 161 */ { 0, "sched_rr_get_interval" },
2593 static char *(linux_error_names[]) = {
2630 /* 36 */ "ENAMETOOLONG",
2633 /* 39 */ "ENOTEMPTY",
2639 /* 45 */ "EL2NSYNC",
2652 /* 58 */ "EDEADLOCK",
2666 /* 72 */ "EMULTIHOP",
2669 /* 75 */ "EOVERFLOW",
2670 /* 76 */ "ENOTUNIQ",
2677 /* 83 */ "ELIBEXEC",
2679 /* 85 */ "ERESTART",
2680 /* 86 */ "ESTRPIPE",
2682 /* 88 */ "ENOTSOCK",
2683 /* 89 */ "EDESTADDRREQ",
2684 /* 90 */ "EMSGSIZE",
2685 /* 91 */ "EPROTOTYPE",
2686 /* 92 */ "ENOPROTOOPT",
2687 /* 93 */ "EPROTONOSUPPORT",
2688 /* 94 */ "ESOCKTNOSUPPORT",
2689 /* 95 */ "EOPNOTSUPP",
2690 /* 96 */ "EPFNOSUPPORT",
2691 /* 97 */ "EAFNOSUPPORT",
2692 /* 98 */ "EADDRINUSE",
2693 /* 99 */ "EADDRNOTAVAIL",
2694 /* 100 */ "ENETDOWN",
2695 /* 101 */ "ENETUNREACH",
2696 /* 102 */ "ENETRESET",
2697 /* 103 */ "ECONNABORTED",
2698 /* 104 */ "ECONNRESET",
2699 /* 105 */ "ENOBUFS",
2700 /* 106 */ "EISCONN",
2701 /* 107 */ "ENOTCONN",
2702 /* 108 */ "ESHUTDOWN",
2703 /* 109 */ "ETOOMANYREFS",
2704 /* 110 */ "ETIMEDOUT",
2705 /* 111 */ "ECONNREFUSED",
2706 /* 112 */ "EHOSTDOWN",
2707 /* 113 */ "EHOSTUNREACH",
2708 /* 114 */ "EALREADY",
2709 /* 115 */ "EINPROGRESS",
2711 /* 117 */ "EUCLEAN",
2712 /* 118 */ "ENOTNAM",
2713 /* 119 */ "ENAVAIL",
2715 /* 121 */ "EREMOTEIO",
2719 static char *(linux_signal_names[]) = {
2737 /* 16 */ "SIGSTKFLT",
2747 /* 26 */ "SIGVTALRM",
2749 /* 28 */ "SIGWINCH",
2752 /* 31 */ "SIGUNUSED",
2755 static emul_syscall emul_linux_syscalls = {
2757 sizeof(linux_descriptors) / sizeof(linux_descriptors[0]),
2759 sizeof(linux_error_names) / sizeof(linux_error_names[0]),
2761 sizeof(linux_signal_names) / sizeof(linux_signal_names[0]),
2765 /* Linux's os_emul interface, most are just passed on to the generic
2768 static os_emul_data *
2769 emul_linux_create(device *root,
2773 /* check that this emulation is really for us */
2774 if (name != NULL && strcmp(name, "linux") != 0)
2780 return emul_unix_create(root, image, "linux", &emul_linux_syscalls);
2784 emul_linux_init(os_emul_data *emul_data,
2791 emul_linux_system_call(cpu *processor,
2793 os_emul_data *emul_data)
2795 emul_do_system_call(emul_data,
2796 emul_data->syscalls,
2797 cpu_registers(processor)->gpr[0],
2798 3, /*r3 contains arg0*/
2803 const os_emul emul_linux = {
2807 emul_linux_system_call,
2808 0, /*instruction_call*/
2812 #endif /* _EMUL_UNIX_C_ */