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 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>.
25 /* Note: this module is called via a table. There is no benefit in
28 #include "emul_generic.h"
29 #include "emul_unix.h"
32 #ifdef HAVE_SYS_TYPES_H
33 #include <sys/types.h>
36 #ifdef HAVE_SYS_TYPES_H
52 #ifdef HAVE_SYS_PARAM_H
53 #include <sys/param.h>
58 #ifndef HAVE_TERMIOS_STRUCTURE
59 #undef HAVE_SYS_TERMIOS_H
62 #ifndef HAVE_SYS_TERMIOS_H
63 #undef HAVE_TERMIOS_STRUCTURE
67 #ifdef HAVE_TERMIOS_STRUCTURE
68 #include <sys/termios.h>
70 /* If we have TERMIOS, use that for the termio structure, since some systems
71 don't like including both sys/termios.h and sys/termio.h at the same
73 #undef HAVE_TERMIO_STRUCTURE
76 #define termio termios
79 #ifndef HAVE_TERMIO_STRUCTURE
80 #undef HAVE_SYS_TERMIO_H
82 #ifndef HAVE_SYS_TERMIO_H
83 #undef HAVE_TERMIO_STRUCTURE
87 #ifdef HAVE_TERMIO_STRUCTURE
88 #include <sys/termio.h>
92 #ifndef HAVE_SYS_RESOURCE_H
98 #include <sys/resource.h>
104 # define NAMLEN(dirent) strlen((dirent)->d_name)
106 # define dirent direct
107 # define NAMLEN(dirent) (dirent)->d_namlen
109 # include <sys/ndir.h>
112 # include <sys/dir.h>
120 #undef MAXPATHLEN /* sys/param.h might define this also */
127 #ifndef STATIC_INLINE_EMUL_UNIX
128 #define STATIC_INLINE_EMUL_UNIX STATIC_INLINE
132 #define PATH_MAX 1024
139 /* UNIX's idea of what is needed to implement emulations */
141 struct _os_emul_data
{
143 emul_syscall
*syscalls
;
147 /* Emulation of simple UNIX system calls that are common on all systems. */
149 /* Structures that are common agmonst the UNIX varients */
150 struct unix_timeval
{
151 signed32 tv_sec
; /* seconds */
152 signed32 tv_usec
; /* microseconds */
155 struct unix_timezone
{
156 signed32 tz_minuteswest
; /* minutes west of Greenwich */
157 signed32 tz_dsttime
; /* type of dst correction */
160 #define UNIX_RUSAGE_SELF 0
161 #define UNIX_RUSAGE_CHILDREN (-1)
162 #define UNIX_RUSAGE_BOTH (-2) /* sys_wait4() uses this */
165 struct unix_timeval ru_utime
; /* user time used */
166 struct unix_timeval ru_stime
; /* system time used */
167 signed32 ru_maxrss
; /* maximum resident set size */
168 signed32 ru_ixrss
; /* integral shared memory size */
169 signed32 ru_idrss
; /* integral unshared data size */
170 signed32 ru_isrss
; /* integral unshared stack size */
171 signed32 ru_minflt
; /* any page faults not requiring I/O */
172 signed32 ru_majflt
; /* any page faults requiring I/O */
173 signed32 ru_nswap
; /* swaps */
174 signed32 ru_inblock
; /* block input operations */
175 signed32 ru_oublock
; /* block output operations */
176 signed32 ru_msgsnd
; /* messages sent */
177 signed32 ru_msgrcv
; /* messages received */
178 signed32 ru_nsignals
; /* signals received */
179 signed32 ru_nvcsw
; /* voluntary context switches */
180 signed32 ru_nivcsw
; /* involuntary " */
184 /* File descriptors 0, 1, and 2 should not be closed. fd_closed[]
185 tracks whether these descriptors have been closed in do_close()
188 static int fd_closed
[3];
190 /* Check for some occurrences of bad file descriptors. We only check
191 whether fd 0, 1, or 2 are "closed". By "closed" we mean that these
192 descriptors aren't actually closed, but are considered to be closed
195 Other checks are performed by the underlying OS call. */
200 if (fd
>=0 && fd
<= 2 && fd_closed
[fd
])
209 do_unix_exit(os_emul_data
*emul
,
215 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
216 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
217 printf_filtered ("%d)\n", status
);
219 cpu_halt(processor
, cia
, was_exited
, status
);
224 do_unix_read(os_emul_data
*emul
,
230 void *scratch_buffer
;
231 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
232 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
233 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
236 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
237 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
239 /* get a tempoary bufer */
240 scratch_buffer
= zalloc(nbytes
);
242 /* check if buffer exists by reading it */
243 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
248 status
= read (d
, scratch_buffer
, nbytes
);
250 emul_write_status(processor
, status
, errno
);
252 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
254 free(scratch_buffer
);
259 do_unix_write(os_emul_data
*emul
,
265 void *scratch_buffer
= NULL
;
266 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
267 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
268 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
271 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
272 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
274 /* get a tempoary bufer */
275 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
278 emul_read_buffer(scratch_buffer
, buf
, nbytes
,
284 status
= write(d
, scratch_buffer
, nbytes
);
285 emul_write_status(processor
, status
, errno
);
286 free(scratch_buffer
);
293 do_unix_open(os_emul_data
*emul
,
299 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
300 char path_buf
[PATH_MAX
];
301 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
302 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
303 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
306 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
307 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
309 status
= open(path
, flags
, mode
);
310 emul_write_status(processor
, status
, errno
);
315 do_unix_close(os_emul_data
*emul
,
321 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
324 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
325 printf_filtered ("%d", d
);
330 /* Do not close stdin, stdout, or stderr. GDB may still need access to
331 these descriptors. */
332 if (d
== 0 || d
== 1 || d
== 2)
341 emul_write_status(processor
, status
, errno
);
346 do_unix_break(os_emul_data
*emul
,
352 /* just pass this onto the `vm' device */
353 unsigned_word new_break
= cpu_registers(processor
)->gpr
[arg0
];
356 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
357 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
359 status
= device_ioctl(emul
->vm
,
363 new_break
); /*ioctl-data*/
365 emul_write_status(processor
, 0, status
);
369 #define do_unix_access 0
372 do_unix_access(os_emul_data
*emul
,
378 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
379 char path_buf
[PATH_MAX
];
380 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
381 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
384 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
385 printf_filtered ("0x%lx [%s], 0x%x [0%o]", (long)path_addr
, path
, mode
, mode
);
387 status
= access(path
, mode
);
388 emul_write_status(processor
, status
, errno
);
393 #define do_unix_getpid 0
396 do_unix_getpid(os_emul_data
*emul
,
402 pid_t status
= getpid();
403 emul_write_status(processor
, (int)status
, errno
);
408 #define do_unix_getppid 0
411 do_unix_getppid(os_emul_data
*emul
,
417 pid_t status
= getppid();
418 emul_write_status(processor
, (int)status
, errno
);
422 #if !defined(HAVE_GETPID) || !defined(HAVE_GETPPID)
423 #define do_unix_getpid2 0
426 do_unix_getpid2(os_emul_data
*emul
,
432 int pid
= (int)getpid();
433 int ppid
= (int)getppid();
434 emul_write2_status(processor
, pid
, ppid
, errno
);
438 #if !defined(HAVE_GETUID) || !defined(HAVE_GETEUID)
439 #define do_unix_getuid2 0
442 do_unix_getuid2(os_emul_data
*emul
,
448 uid_t uid
= getuid();
449 uid_t euid
= geteuid();
450 emul_write2_status(processor
, (int)uid
, (int)euid
, errno
);
455 #define do_unix_getuid 0
458 do_unix_getuid(os_emul_data
*emul
,
464 uid_t status
= getuid();
465 emul_write_status(processor
, (int)status
, errno
);
470 #define do_unix_geteuid 0
473 do_unix_geteuid(os_emul_data
*emul
,
479 uid_t status
= geteuid();
480 emul_write_status(processor
, (int)status
, errno
);
486 #define do_unix_kill 0
489 do_unix_kill(os_emul_data
*emul
,
495 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
496 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
498 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
499 printf_filtered ("%d, %d", (int)pid
, sig
);
501 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
504 cpu_halt(processor
, cia
, was_signalled
, sig
);
510 #define do_unix_dup 0
513 do_unix_dup(os_emul_data
*emul
,
519 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
520 int status
= (fdbad (oldd
) < 0) ? -1 : dup(oldd
);
523 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
524 printf_filtered ("%d", oldd
);
526 emul_write_status(processor
, status
, err
);
531 #define do_unix_dup2 0
534 do_unix_dup2(os_emul_data
*emul
,
540 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
541 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
542 int status
= (fdbad (oldd
) < 0) ? -1 : dup2(oldd
, newd
);
545 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
546 printf_filtered ("%d, %d", oldd
, newd
);
548 emul_write_status(processor
, status
, err
);
553 #define do_unix_lseek 0
556 do_unix_lseek(os_emul_data
*emul
,
562 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
563 off_t offset
= (off_t
)cpu_registers(processor
)->gpr
[arg0
+1];
564 int whence
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
567 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
568 printf_filtered ("%d %ld %d", fildes
, (long)offset
, whence
);
570 status
= fdbad (fildes
);
572 status
= lseek(fildes
, offset
, whence
);
573 emul_write_status(processor
, (int)status
, errno
);
578 #if !defined(HAVE_GETGID) || !defined(HAVE_GETEGID)
579 #define do_unix_getgid2 0
582 do_unix_getgid2(os_emul_data
*emul
,
588 gid_t gid
= getgid();
589 gid_t egid
= getegid();
590 emul_write2_status(processor
, (int)gid
, (int)egid
, errno
);
595 #define do_unix_getgid 0
598 do_unix_getgid(os_emul_data
*emul
,
604 gid_t status
= getgid();
605 emul_write_status(processor
, (int)status
, errno
);
610 #define do_unix_getegid 0
613 do_unix_getegid(os_emul_data
*emul
,
619 gid_t status
= getegid();
620 emul_write_status(processor
, (int)status
, errno
);
625 #define do_unix_umask 0
628 do_unix_umask(os_emul_data
*emul
,
634 mode_t mask
= (mode_t
)cpu_registers(processor
)->gpr
[arg0
];
635 int status
= umask(mask
);
637 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
638 printf_filtered ("0%o", (unsigned int)mask
);
640 emul_write_status(processor
, status
, errno
);
645 #define do_unix_chdir 0
648 do_unix_chdir(os_emul_data
*emul
,
654 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
655 char path_buf
[PATH_MAX
];
656 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
659 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
660 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
662 status
= chdir(path
);
663 emul_write_status(processor
, status
, errno
);
668 #define do_unix_link 0
671 do_unix_link(os_emul_data
*emul
,
677 unsigned_word path1_addr
= cpu_registers(processor
)->gpr
[arg0
];
678 char path1_buf
[PATH_MAX
];
679 char *path1
= emul_read_string(path1_buf
, path1_addr
, PATH_MAX
, processor
, cia
);
680 unsigned_word path2_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
681 char path2_buf
[PATH_MAX
];
682 char *path2
= emul_read_string(path2_buf
, path2_addr
, PATH_MAX
, processor
, cia
);
685 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
686 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr
, path1
, (long)path2_addr
, path2
);
688 status
= link(path1
, path2
);
689 emul_write_status(processor
, status
, errno
);
694 #define do_unix_symlink 0
697 do_unix_symlink(os_emul_data
*emul
,
703 unsigned_word path1_addr
= cpu_registers(processor
)->gpr
[arg0
];
704 char path1_buf
[PATH_MAX
];
705 char *path1
= emul_read_string(path1_buf
, path1_addr
, PATH_MAX
, processor
, cia
);
706 unsigned_word path2_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
707 char path2_buf
[PATH_MAX
];
708 char *path2
= emul_read_string(path2_buf
, path2_addr
, PATH_MAX
, processor
, cia
);
711 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
712 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr
, path1
, (long)path2_addr
, path2
);
714 status
= symlink(path1
, path2
);
715 emul_write_status(processor
, status
, errno
);
720 #define do_unix_unlink 0
723 do_unix_unlink(os_emul_data
*emul
,
729 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
730 char path_buf
[PATH_MAX
];
731 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
734 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
735 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
737 status
= unlink(path
);
738 emul_write_status(processor
, status
, errno
);
743 #define do_unix_mkdir 0
746 do_unix_mkdir(os_emul_data
*emul
,
752 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
753 char path_buf
[PATH_MAX
];
754 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
755 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
758 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
759 printf_filtered ("0x%lx [%s], 0%3o", (long)path_addr
, path
, mode
);
762 status
= mkdir(path
);
764 status
= mkdir(path
, mode
);
766 emul_write_status(processor
, status
, errno
);
771 #define do_unix_rmdir 0
774 do_unix_rmdir(os_emul_data
*emul
,
780 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
781 char path_buf
[PATH_MAX
];
782 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
785 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
786 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
788 status
= rmdir(path
);
789 emul_write_status(processor
, status
, errno
);
794 #define do_unix_time 0
797 do_unix_time(os_emul_data
*emul
,
803 unsigned_word tp
= cpu_registers(processor
)->gpr
[arg0
];
804 time_t now
= time ((time_t *)0);
805 unsigned_word status
= H2T_4(now
);
807 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
808 printf_filtered ("0x%lx", (long)tp
);
810 emul_write_status(processor
, (int)status
, errno
);
813 emul_write_buffer(&status
, tp
, sizeof(status
), processor
, cia
);
817 #if !defined(HAVE_GETTIMEOFDAY)
818 #define do_unix_gettimeofday 0
821 do_unix_gettimeofday(os_emul_data
*emul
,
827 unsigned_word tv
= cpu_registers(processor
)->gpr
[arg0
];
828 unsigned_word tz
= cpu_registers(processor
)->gpr
[arg0
+1];
829 struct unix_timeval target_timeval
;
830 struct timeval host_timeval
;
831 struct unix_timezone target_timezone
;
832 struct timezone host_timezone
;
835 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
836 printf_filtered ("0x%lx, 0x%lx", (long)tv
, (long)tz
);
838 /* Just in case the system doesn't set the timezone structure */
839 host_timezone
.tz_minuteswest
= 0;
840 host_timezone
.tz_dsttime
= 0;
842 status
= gettimeofday(&host_timeval
, &host_timezone
);
845 target_timeval
.tv_sec
= H2T_4(host_timeval
.tv_sec
);
846 target_timeval
.tv_usec
= H2T_4(host_timeval
.tv_usec
);
847 emul_write_buffer((void *) &target_timeval
, tv
, sizeof(target_timeval
), processor
, cia
);
851 target_timezone
.tz_minuteswest
= H2T_4(host_timezone
.tz_minuteswest
);
852 target_timezone
.tz_dsttime
= H2T_4(host_timezone
.tz_dsttime
);
853 emul_write_buffer((void *) &target_timezone
, tv
, sizeof(target_timezone
), processor
, cia
);
857 emul_write_status(processor
, (int)status
, errno
);
862 #ifndef HAVE_GETRUSAGE
863 #define do_unix_getrusage 0
866 do_unix_getrusage(os_emul_data
*emul
,
872 signed_word who
= (signed_word
)cpu_registers(processor
)->gpr
[arg0
];
873 unsigned_word usage
= cpu_registers(processor
)->gpr
[arg0
+1];
874 struct rusage host_rusage
, host_rusage2
;
875 struct unix_rusage target_rusage
;
878 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
879 printf_filtered ("%ld, 0x%lx", (long)who
, (long)usage
);
887 case UNIX_RUSAGE_SELF
:
888 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
891 case UNIX_RUSAGE_CHILDREN
:
892 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage
);
895 case UNIX_RUSAGE_BOTH
:
896 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
898 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage2
);
900 host_rusage
.ru_utime
.tv_sec
+= host_rusage2
.ru_utime
.tv_sec
;
901 host_rusage
.ru_utime
.tv_usec
+= host_rusage2
.ru_utime
.tv_usec
;
902 host_rusage
.ru_stime
.tv_sec
+= host_rusage2
.ru_stime
.tv_sec
;
903 host_rusage
.ru_stime
.tv_usec
+= host_rusage2
.ru_stime
.tv_usec
;
904 host_rusage
.ru_maxrss
+= host_rusage2
.ru_maxrss
;
905 host_rusage
.ru_ixrss
+= host_rusage2
.ru_ixrss
;
906 host_rusage
.ru_idrss
+= host_rusage2
.ru_idrss
;
907 host_rusage
.ru_isrss
+= host_rusage2
.ru_isrss
;
908 host_rusage
.ru_minflt
+= host_rusage2
.ru_minflt
;
909 host_rusage
.ru_majflt
+= host_rusage2
.ru_majflt
;
910 host_rusage
.ru_nswap
+= host_rusage2
.ru_nswap
;
911 host_rusage
.ru_inblock
+= host_rusage2
.ru_inblock
;
912 host_rusage
.ru_oublock
+= host_rusage2
.ru_oublock
;
913 host_rusage
.ru_msgsnd
+= host_rusage2
.ru_msgsnd
;
914 host_rusage
.ru_msgrcv
+= host_rusage2
.ru_msgrcv
;
915 host_rusage
.ru_nsignals
+= host_rusage2
.ru_nsignals
;
916 host_rusage
.ru_nvcsw
+= host_rusage2
.ru_nvcsw
;
917 host_rusage
.ru_nivcsw
+= host_rusage2
.ru_nivcsw
;
923 target_rusage
.ru_utime
.tv_sec
= H2T_4(host_rusage2
.ru_utime
.tv_sec
);
924 target_rusage
.ru_utime
.tv_usec
= H2T_4(host_rusage2
.ru_utime
.tv_usec
);
925 target_rusage
.ru_stime
.tv_sec
= H2T_4(host_rusage2
.ru_stime
.tv_sec
);
926 target_rusage
.ru_stime
.tv_usec
= H2T_4(host_rusage2
.ru_stime
.tv_usec
);
927 target_rusage
.ru_maxrss
= H2T_4(host_rusage2
.ru_maxrss
);
928 target_rusage
.ru_ixrss
= H2T_4(host_rusage2
.ru_ixrss
);
929 target_rusage
.ru_idrss
= H2T_4(host_rusage2
.ru_idrss
);
930 target_rusage
.ru_isrss
= H2T_4(host_rusage2
.ru_isrss
);
931 target_rusage
.ru_minflt
= H2T_4(host_rusage2
.ru_minflt
);
932 target_rusage
.ru_majflt
= H2T_4(host_rusage2
.ru_majflt
);
933 target_rusage
.ru_nswap
= H2T_4(host_rusage2
.ru_nswap
);
934 target_rusage
.ru_inblock
= H2T_4(host_rusage2
.ru_inblock
);
935 target_rusage
.ru_oublock
= H2T_4(host_rusage2
.ru_oublock
);
936 target_rusage
.ru_msgsnd
= H2T_4(host_rusage2
.ru_msgsnd
);
937 target_rusage
.ru_msgrcv
= H2T_4(host_rusage2
.ru_msgrcv
);
938 target_rusage
.ru_nsignals
= H2T_4(host_rusage2
.ru_nsignals
);
939 target_rusage
.ru_nvcsw
= H2T_4(host_rusage2
.ru_nvcsw
);
940 target_rusage
.ru_nivcsw
= H2T_4(host_rusage2
.ru_nivcsw
);
941 emul_write_buffer((void *) &target_rusage
, usage
, sizeof(target_rusage
), processor
, cia
);
944 emul_write_status(processor
, status
, errno
);
950 do_unix_nop(os_emul_data
*emul
,
956 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
957 printf_filtered ("0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
958 (long)cpu_registers(processor
)->gpr
[arg0
],
959 (long)cpu_registers(processor
)->gpr
[arg0
+1],
960 (long)cpu_registers(processor
)->gpr
[arg0
+2],
961 (long)cpu_registers(processor
)->gpr
[arg0
+3],
962 (long)cpu_registers(processor
)->gpr
[arg0
+4],
963 (long)cpu_registers(processor
)->gpr
[arg0
+5]);
965 emul_write_status(processor
, 0, errno
);
969 /* Common code for initializing the system call stuff */
971 static os_emul_data
*
972 emul_unix_create(device
*root
,
975 emul_syscall
*syscall
)
977 unsigned_word top_of_stack
;
984 /* merge any emulation specific entries into the device tree */
986 /* establish a few defaults */
987 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
989 top_of_stack
= 0xe0000000;
990 stack_size
= 0x00100000;
994 top_of_stack
= 0x20000000;
995 stack_size
= 0x00100000;
999 emul_add_tree_options(root
, image
, name
,
1000 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
1001 ? "user" : "virtual"),
1002 0 /*oea-interrupt-prefix*/);
1004 /* virtual memory - handles growth of stack/heap */
1005 vm
= tree_parse(root
, "/openprom/vm@0x%lx",
1006 (unsigned long)(top_of_stack
- stack_size
));
1007 tree_parse(vm
, "./stack-base 0x%lx",
1008 (unsigned long)(top_of_stack
- stack_size
));
1009 tree_parse(vm
, "./nr-bytes 0x%x", stack_size
);
1011 filename
= tree_quote_property (bfd_get_filename(image
));
1012 tree_parse(root
, "/openprom/vm/map-binary/file-name %s",
1016 /* finish the init */
1017 tree_parse(root
, "/openprom/init/register/pc 0x%lx",
1018 (unsigned long)bfd_get_start_address(image
));
1019 tree_parse(root
, "/openprom/init/register/sp 0x%lx",
1020 (unsigned long)top_of_stack
);
1021 tree_parse(root
, "/openprom/init/register/msr 0x%x",
1022 ((tree_find_boolean_property(root
, "/options/little-endian?")
1023 ? msr_little_endian_mode
1025 | (tree_find_boolean_property(root
, "/openprom/options/floating-point?")
1026 ? (msr_floating_point_available
1027 | msr_floating_point_exception_mode_0
1028 | msr_floating_point_exception_mode_1
)
1030 tree_parse(root
, "/openprom/init/stack/stack-type %s",
1031 (elf_binary
? "ppc-elf" : "ppc-xcoff"));
1033 /* finally our emulation data */
1034 data
= ZALLOC(os_emul_data
);
1036 data
->syscalls
= syscall
;
1043 Solaris - Emulation of user programs for Solaris/PPC
1050 /* Solaris specific implementation */
1052 typedef signed32 solaris_uid_t
;
1053 typedef signed32 solaris_gid_t
;
1054 typedef signed32 solaris_off_t
;
1055 typedef signed32 solaris_pid_t
;
1056 typedef signed32 solaris_time_t
;
1057 typedef unsigned32 solaris_dev_t
;
1058 typedef unsigned32 solaris_ino_t
;
1059 typedef unsigned32 solaris_mode_t
;
1060 typedef unsigned32 solaris_nlink_t
;
1062 #ifdef HAVE_SYS_STAT_H
1063 #define SOLARIS_ST_FSTYPSZ 16 /* array size for file system type name */
1065 /* AIX 7.1 defines st_pad[123] to st_[amc]tim.tv_pad, respectively */
1070 struct solaris_stat
{
1071 solaris_dev_t st_dev
;
1072 signed32 st_pad1
[3]; /* reserved for network id */
1073 solaris_ino_t st_ino
;
1074 solaris_mode_t st_mode
;
1075 solaris_nlink_t st_nlink
;
1076 solaris_uid_t st_uid
;
1077 solaris_gid_t st_gid
;
1078 solaris_dev_t st_rdev
;
1079 signed32 st_pad2
[2];
1080 solaris_off_t st_size
;
1081 signed32 st_pad3
; /* future off_t expansion */
1082 struct unix_timeval st_atim
;
1083 struct unix_timeval st_mtim
;
1084 struct unix_timeval st_ctim
;
1085 signed32 st_blksize
;
1087 char st_fstype
[SOLARIS_ST_FSTYPSZ
];
1088 signed32 st_pad4
[8]; /* expansion area */
1091 /* Convert from host stat structure to solaris stat structure */
1092 STATIC_INLINE_EMUL_UNIX
void
1093 convert_to_solaris_stat(unsigned_word addr
,
1098 struct solaris_stat target
;
1101 target
.st_dev
= H2T_4(host
->st_dev
);
1102 target
.st_ino
= H2T_4(host
->st_ino
);
1103 target
.st_mode
= H2T_4(host
->st_mode
);
1104 target
.st_nlink
= H2T_4(host
->st_nlink
);
1105 target
.st_uid
= H2T_4(host
->st_uid
);
1106 target
.st_gid
= H2T_4(host
->st_gid
);
1107 target
.st_size
= H2T_4(host
->st_size
);
1110 target
.st_rdev
= H2T_4(host
->st_rdev
);
1115 #ifdef HAVE_ST_BLKSIZE
1116 target
.st_blksize
= H2T_4(host
->st_blksize
);
1118 target
.st_blksize
= 0;
1121 #ifdef HAVE_ST_BLOCKS
1122 target
.st_blocks
= H2T_4(host
->st_blocks
);
1124 target
.st_blocks
= 0;
1127 target
.st_atim
.tv_sec
= H2T_4(host
->st_atime
);
1128 target
.st_atim
.tv_usec
= 0;
1130 target
.st_ctim
.tv_sec
= H2T_4(host
->st_ctime
);
1131 target
.st_ctim
.tv_usec
= 0;
1133 target
.st_mtim
.tv_sec
= H2T_4(host
->st_mtime
);
1134 target
.st_mtim
.tv_usec
= 0;
1136 for (i
= 0; i
< ARRAY_SIZE (target
.st_pad1
); i
++)
1137 target
.st_pad1
[i
] = 0;
1139 for (i
= 0; i
< ARRAY_SIZE (target
.st_pad2
); i
++)
1140 target
.st_pad2
[i
] = 0;
1144 for (i
= 0; i
< ARRAY_SIZE (target
.st_pad4
); i
++)
1145 target
.st_pad4
[i
] = 0;
1147 /* For now, just punt and always say it is a ufs file */
1148 strcpy (target
.st_fstype
, "ufs");
1150 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1152 #endif /* HAVE_SYS_STAT_H */
1155 #define do_solaris_stat 0
1158 do_solaris_stat(os_emul_data
*emul
,
1164 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1165 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1166 char path_buf
[PATH_MAX
];
1168 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1171 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1172 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1174 status
= stat (path
, &buf
);
1176 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1178 emul_write_status(processor
, status
, errno
);
1183 #define do_solaris_lstat 0
1186 do_solaris_lstat(os_emul_data
*emul
,
1192 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1193 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1194 char path_buf
[PATH_MAX
];
1196 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1199 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1200 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1202 status
= lstat (path
, &buf
);
1204 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1206 emul_write_status(processor
, status
, errno
);
1211 #define do_solaris_fstat 0
1214 do_solaris_fstat(os_emul_data
*emul
,
1220 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
1221 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1225 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1226 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
1228 status
= fdbad (fildes
);
1230 status
= fstat (fildes
, &buf
);
1232 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1234 emul_write_status(processor
, status
, errno
);
1238 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1239 #define SOLARIS_TIOC ('T'<<8)
1240 #define SOLARIS_NCC 8
1241 #define SOLARIS_NCCS 19
1243 #define SOLARIS_VINTR 0
1244 #define SOLARIS_VQUIT 1
1245 #define SOLARIS_VERASE 2
1246 #define SOLARIS_VKILL 3
1247 #define SOLARIS_VEOF 4
1248 #define SOLARIS_VEOL 5
1249 #define SOLARIS_VEOL2 6
1250 #define SOLARIS_VSWTCH 7
1251 #define SOLARIS_VSTART 8
1252 #define SOLARIS_VSTOP 9
1253 #define SOLARIS_VSUSP 10
1254 #define SOLARIS_VDSUSP 11
1255 #define SOLARIS_VREPRINT 12
1256 #define SOLARIS_VDISCARD 13
1257 #define SOLARIS_VWERASE 14
1258 #define SOLARIS_VLNEXT 15
1261 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1262 /* Convert to/from host termio structure */
1264 struct solaris_termio
{
1265 unsigned16 c_iflag
; /* input modes */
1266 unsigned16 c_oflag
; /* output modes */
1267 unsigned16 c_cflag
; /* control modes */
1268 unsigned16 c_lflag
; /* line discipline modes */
1269 unsigned8 c_line
; /* line discipline */
1270 unsigned8 c_cc
[SOLARIS_NCC
]; /* control chars */
1273 STATIC_INLINE_EMUL_UNIX
void
1274 convert_to_solaris_termio(unsigned_word addr
,
1275 struct termio
*host
,
1279 struct solaris_termio target
;
1282 target
.c_iflag
= H2T_2 (host
->c_iflag
);
1283 target
.c_oflag
= H2T_2 (host
->c_oflag
);
1284 target
.c_cflag
= H2T_2 (host
->c_cflag
);
1285 target
.c_lflag
= H2T_2 (host
->c_lflag
);
1287 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
1288 target
.c_line
= host
->c_line
;
1293 for (i
= 0; i
< SOLARIS_NCC
; i
++)
1297 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1301 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1305 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1309 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1313 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1317 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1321 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1325 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1329 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1333 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1335 #endif /* HAVE_TERMIO_STRUCTURE || HAVE_TERMIOS_STRUCTURE */
1337 #ifdef HAVE_TERMIOS_STRUCTURE
1338 /* Convert to/from host termios structure */
1340 typedef unsigned32 solaris_tcflag_t
;
1341 typedef unsigned8 solaris_cc_t
;
1342 typedef unsigned32 solaris_speed_t
;
1344 struct solaris_termios
{
1345 solaris_tcflag_t c_iflag
;
1346 solaris_tcflag_t c_oflag
;
1347 solaris_tcflag_t c_cflag
;
1348 solaris_tcflag_t c_lflag
;
1349 solaris_cc_t c_cc
[SOLARIS_NCCS
];
1352 STATIC_INLINE_EMUL_UNIX
void
1353 convert_to_solaris_termios(unsigned_word addr
,
1354 struct termios
*host
,
1358 struct solaris_termios target
;
1361 target
.c_iflag
= H2T_4 (host
->c_iflag
);
1362 target
.c_oflag
= H2T_4 (host
->c_oflag
);
1363 target
.c_cflag
= H2T_4 (host
->c_cflag
);
1364 target
.c_lflag
= H2T_4 (host
->c_lflag
);
1366 for (i
= 0; i
< SOLARIS_NCCS
; i
++)
1370 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1374 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1378 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1382 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1386 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1390 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1394 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1398 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1402 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1407 target
.c_cc
[SOLARIS_VSTART
] = host
->c_cc
[VSTART
];
1411 target
.c_cc
[SOLARIS_VSTOP
] = host
->c_cc
[VSTOP
];
1415 target
.c_cc
[SOLARIS_VSUSP
] = host
->c_cc
[VSUSP
];
1419 target
.c_cc
[SOLARIS_VDSUSP
] = host
->c_cc
[VDSUSP
];
1423 target
.c_cc
[SOLARIS_VREPRINT
] = host
->c_cc
[VREPRINT
];
1427 target
.c_cc
[SOLARIS_VDISCARD
] = host
->c_cc
[VDISCARD
];
1431 target
.c_cc
[SOLARIS_VWERASE
] = host
->c_cc
[VWERASE
];
1435 target
.c_cc
[SOLARIS_VLNEXT
] = host
->c_cc
[VLNEXT
];
1438 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1440 #endif /* HAVE_TERMIOS_STRUCTURE */
1443 #define do_solaris_ioctl 0
1446 do_solaris_ioctl(os_emul_data
*emul
,
1452 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
1453 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
1454 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
1456 const char *name
= "<unknown>";
1458 #ifdef HAVE_TERMIOS_STRUCTURE
1459 struct termios host_termio
;
1462 #ifdef HAVE_TERMIO_STRUCTURE
1463 struct termio host_termio
;
1467 status
= fdbad (fildes
);
1473 case 0: /* make sure we have at least one case */
1479 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1480 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
1481 case SOLARIS_TIOC
| 1: /* TCGETA */
1483 #ifdef HAVE_TCGETATTR
1484 status
= tcgetattr(fildes
, &host_termio
);
1485 #elif defined(TCGETS)
1486 status
= ioctl (fildes
, TCGETS
, &host_termio
);
1488 status
= ioctl (fildes
, TCGETA
, &host_termio
);
1491 convert_to_solaris_termio (argp_addr
, &host_termio
, processor
, cia
);
1494 #endif /* HAVE_TERMIO_STRUCTURE */
1496 #ifdef HAVE_TERMIOS_STRUCTURE
1497 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
1498 case SOLARIS_TIOC
| 13: /* TCGETS */
1500 #ifdef HAVE_TCGETATTR
1501 status
= tcgetattr(fildes
, &host_termio
);
1503 status
= ioctl (fildes
, TCGETS
, &host_termio
);
1506 convert_to_solaris_termios (argp_addr
, &host_termio
, processor
, cia
);
1509 #endif /* HAVE_TERMIOS_STRUCTURE */
1513 emul_write_status(processor
, status
, errno
);
1515 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1516 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
1518 #endif /* HAVE_IOCTL */
1520 static emul_syscall_descriptor solaris_descriptors
[] = {
1521 /* 0 */ { 0, "syscall" },
1522 /* 1 */ { do_unix_exit
, "exit" },
1523 /* 2 */ { 0, "fork" },
1524 /* 3 */ { do_unix_read
, "read" },
1525 /* 4 */ { do_unix_write
, "write" },
1526 /* 5 */ { do_unix_open
, "open" },
1527 /* 6 */ { do_unix_close
, "close" },
1528 /* 7 */ { 0, "wait" },
1529 /* 8 */ { 0, "creat" },
1530 /* 9 */ { do_unix_link
, "link" },
1531 /* 10 */ { do_unix_unlink
, "unlink" },
1532 /* 11 */ { 0, "exec" },
1533 /* 12 */ { do_unix_chdir
, "chdir" },
1534 /* 13 */ { do_unix_time
, "time" },
1535 /* 14 */ { 0, "mknod" },
1536 /* 15 */ { 0, "chmod" },
1537 /* 16 */ { 0, "chown" },
1538 /* 17 */ { do_unix_break
, "brk" },
1539 /* 18 */ { do_solaris_stat
, "stat" },
1540 /* 19 */ { do_unix_lseek
, "lseek" },
1541 /* 20 */ { do_unix_getpid2
, "getpid" },
1542 /* 21 */ { 0, "mount" },
1543 /* 22 */ { 0, "umount" },
1544 /* 23 */ { 0, "setuid" },
1545 /* 24 */ { do_unix_getuid2
, "getuid" },
1546 /* 25 */ { 0, "stime" },
1547 /* 26 */ { 0, "ptrace" },
1548 /* 27 */ { 0, "alarm" },
1549 /* 28 */ { do_solaris_fstat
, "fstat" },
1550 /* 29 */ { 0, "pause" },
1551 /* 30 */ { 0, "utime" },
1552 /* 31 */ { 0, "stty" },
1553 /* 32 */ { 0, "gtty" },
1554 /* 33 */ { do_unix_access
, "access" },
1555 /* 34 */ { 0, "nice" },
1556 /* 35 */ { 0, "statfs" },
1557 /* 36 */ { 0, "sync" },
1558 /* 37 */ { 0, "kill" },
1559 /* 38 */ { 0, "fstatfs" },
1560 /* 39 */ { 0, "pgrpsys" },
1561 /* 40 */ { 0, "xenix" },
1562 /* 41 */ { do_unix_dup
, "dup" },
1563 /* 42 */ { 0, "pipe" },
1564 /* 43 */ { 0, "times" },
1565 /* 44 */ { 0, "profil" },
1566 /* 45 */ { 0, "plock" },
1567 /* 46 */ { 0, "setgid" },
1568 /* 47 */ { do_unix_getgid2
, "getgid" },
1569 /* 48 */ { 0, "signal" },
1570 /* 49 */ { 0, "msgsys" },
1571 /* 50 */ { 0, "syssun" },
1572 /* 51 */ { 0, "acct" },
1573 /* 52 */ { 0, "shmsys" },
1574 /* 53 */ { 0, "semsys" },
1575 /* 54 */ { do_solaris_ioctl
, "ioctl" },
1576 /* 55 */ { 0, "uadmin" },
1577 /* 56 */ { 0, 0 /* reserved for exch */ },
1578 /* 57 */ { 0, "utssys" },
1579 /* 58 */ { 0, "fdsync" },
1580 /* 59 */ { 0, "execve" },
1581 /* 60 */ { do_unix_umask
, "umask" },
1582 /* 61 */ { 0, "chroot" },
1583 /* 62 */ { 0, "fcntl" },
1584 /* 63 */ { 0, "ulimit" },
1585 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1586 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1587 /* 65 */ { 0, 0 /* reserved for UNIX PC */ },
1588 /* 66 */ { 0, 0 /* reserved for UNIX PC */ },
1589 /* 67 */ { 0, 0 /* reserved for UNIX PC */ },
1590 /* 68 */ { 0, 0 /* reserved for UNIX PC */ },
1591 /* 69 */ { 0, 0 /* reserved for UNIX PC */ },
1592 /* 70 */ { 0, 0 /* was advfs */ },
1593 /* 71 */ { 0, 0 /* was unadvfs */ },
1594 /* 72 */ { 0, 0 /* was rmount */ },
1595 /* 73 */ { 0, 0 /* was rumount */ },
1596 /* 74 */ { 0, 0 /* was rfstart */ },
1597 /* 75 */ { 0, 0 /* was sigret */ },
1598 /* 76 */ { 0, 0 /* was rdebug */ },
1599 /* 77 */ { 0, 0 /* was rfstop */ },
1600 /* 78 */ { 0, 0 /* was rfsys */ },
1601 /* 79 */ { do_unix_rmdir
, "rmdir" },
1602 /* 80 */ { do_unix_mkdir
, "mkdir" },
1603 /* 81 */ { 0, "getdents" },
1604 /* 82 */ { 0, 0 /* was libattach */ },
1605 /* 83 */ { 0, 0 /* was libdetach */ },
1606 /* 84 */ { 0, "sysfs" },
1607 /* 85 */ { 0, "getmsg" },
1608 /* 86 */ { 0, "putmsg" },
1609 /* 87 */ { 0, "poll" },
1610 /* 88 */ { do_solaris_lstat
, "lstat" },
1611 /* 89 */ { do_unix_symlink
, "symlink" },
1612 /* 90 */ { 0, "readlink" },
1613 /* 91 */ { 0, "setgroups" },
1614 /* 92 */ { 0, "getgroups" },
1615 /* 93 */ { 0, "fchmod" },
1616 /* 94 */ { 0, "fchown" },
1617 /* 95 */ { 0, "sigprocmask" },
1618 /* 96 */ { 0, "sigsuspend" },
1619 /* 97 */ { do_unix_nop
, "sigaltstack" },
1620 /* 98 */ { do_unix_nop
, "sigaction" },
1621 /* 99 */ { 0, "sigpending" },
1622 /* 100 */ { 0, "context" },
1623 /* 101 */ { 0, "evsys" },
1624 /* 102 */ { 0, "evtrapret" },
1625 /* 103 */ { 0, "statvfs" },
1626 /* 104 */ { 0, "fstatvfs" },
1627 /* 105 */ { 0, 0 /* reserved */ },
1628 /* 106 */ { 0, "nfssys" },
1629 /* 107 */ { 0, "waitsys" },
1630 /* 108 */ { 0, "sigsendsys" },
1631 /* 109 */ { 0, "hrtsys" },
1632 /* 110 */ { 0, "acancel" },
1633 /* 111 */ { 0, "async" },
1634 /* 112 */ { 0, "priocntlsys" },
1635 /* 113 */ { 0, "pathconf" },
1636 /* 114 */ { 0, "mincore" },
1637 /* 115 */ { 0, "mmap" },
1638 /* 116 */ { 0, "mprotect" },
1639 /* 117 */ { 0, "munmap" },
1640 /* 118 */ { 0, "fpathconf" },
1641 /* 119 */ { 0, "vfork" },
1642 /* 120 */ { 0, "fchdir" },
1643 /* 121 */ { 0, "readv" },
1644 /* 122 */ { 0, "writev" },
1645 /* 123 */ { 0, "xstat" },
1646 /* 124 */ { 0, "lxstat" },
1647 /* 125 */ { 0, "fxstat" },
1648 /* 126 */ { 0, "xmknod" },
1649 /* 127 */ { 0, "clocal" },
1650 /* 128 */ { 0, "setrlimit" },
1651 /* 129 */ { 0, "getrlimit" },
1652 /* 130 */ { 0, "lchown" },
1653 /* 131 */ { 0, "memcntl" },
1654 /* 132 */ { 0, "getpmsg" },
1655 /* 133 */ { 0, "putpmsg" },
1656 /* 134 */ { 0, "rename" },
1657 /* 135 */ { 0, "uname" },
1658 /* 136 */ { 0, "setegid" },
1659 /* 137 */ { 0, "sysconfig" },
1660 /* 138 */ { 0, "adjtime" },
1661 /* 139 */ { 0, "systeminfo" },
1662 /* 140 */ { 0, 0 /* reserved */ },
1663 /* 141 */ { 0, "seteuid" },
1664 /* 142 */ { 0, "vtrace" },
1665 /* 143 */ { 0, "fork1" },
1666 /* 144 */ { 0, "sigtimedwait" },
1667 /* 145 */ { 0, "lwp_info" },
1668 /* 146 */ { 0, "yield" },
1669 /* 147 */ { 0, "lwp_sema_wait" },
1670 /* 148 */ { 0, "lwp_sema_post" },
1671 /* 149 */ { 0, 0 /* reserved */ },
1672 /* 150 */ { 0, 0 /* reserved */ },
1673 /* 151 */ { 0, 0 /* reserved */ },
1674 /* 152 */ { 0, "modctl" },
1675 /* 153 */ { 0, "fchroot" },
1676 /* 154 */ { 0, "utimes" },
1677 /* 155 */ { 0, "vhangup" },
1678 /* 156 */ { do_unix_gettimeofday
, "gettimeofday" },
1679 /* 157 */ { 0, "getitimer" },
1680 /* 158 */ { 0, "setitimer" },
1681 /* 159 */ { 0, "lwp_create" },
1682 /* 160 */ { 0, "lwp_exit" },
1683 /* 161 */ { 0, "lwp_suspend" },
1684 /* 162 */ { 0, "lwp_continue" },
1685 /* 163 */ { 0, "lwp_kill" },
1686 /* 164 */ { 0, "lwp_self" },
1687 /* 165 */ { 0, "lwp_setprivate" },
1688 /* 166 */ { 0, "lwp_getprivate" },
1689 /* 167 */ { 0, "lwp_wait" },
1690 /* 168 */ { 0, "lwp_mutex_unlock" },
1691 /* 169 */ { 0, "lwp_mutex_lock" },
1692 /* 170 */ { 0, "lwp_cond_wait" },
1693 /* 171 */ { 0, "lwp_cond_signal" },
1694 /* 172 */ { 0, "lwp_cond_broadcast" },
1695 /* 173 */ { 0, "pread" },
1696 /* 174 */ { 0, "pwrite" },
1697 /* 175 */ { 0, "llseek" },
1698 /* 176 */ { 0, "inst_sync" },
1699 /* 177 */ { 0, 0 /* reserved */ },
1700 /* 178 */ { 0, "kaio" },
1701 /* 179 */ { 0, 0 /* reserved */ },
1702 /* 180 */ { 0, 0 /* reserved */ },
1703 /* 181 */ { 0, 0 /* reserved */ },
1704 /* 182 */ { 0, 0 /* reserved */ },
1705 /* 183 */ { 0, 0 /* reserved */ },
1706 /* 184 */ { 0, "tsolsys" },
1707 /* 185 */ { 0, "acl" },
1708 /* 186 */ { 0, "auditsys" },
1709 /* 187 */ { 0, "processor_bind" },
1710 /* 188 */ { 0, "processor_info" },
1711 /* 189 */ { 0, "p_online" },
1712 /* 190 */ { 0, "sigqueue" },
1713 /* 191 */ { 0, "clock_gettime" },
1714 /* 192 */ { 0, "clock_settime" },
1715 /* 193 */ { 0, "clock_getres" },
1716 /* 194 */ { 0, "timer_create" },
1717 /* 195 */ { 0, "timer_delete" },
1718 /* 196 */ { 0, "timer_settime" },
1719 /* 197 */ { 0, "timer_gettime" },
1720 /* 198 */ { 0, "timer_getoverrun" },
1721 /* 199 */ { 0, "nanosleep" },
1722 /* 200 */ { 0, "facl" },
1723 /* 201 */ { 0, "door" },
1724 /* 202 */ { 0, "setreuid" },
1725 /* 203 */ { 0, "setregid" },
1726 /* 204 */ { 0, "install_utrap" },
1727 /* 205 */ { 0, 0 /* reserved */ },
1728 /* 206 */ { 0, 0 /* reserved */ },
1729 /* 207 */ { 0, 0 /* reserved */ },
1730 /* 208 */ { 0, 0 /* reserved */ },
1731 /* 209 */ { 0, 0 /* reserved */ },
1732 /* 210 */ { 0, "signotifywait" },
1733 /* 211 */ { 0, "lwp_sigredirect" },
1734 /* 212 */ { 0, "lwp_alarm" },
1737 static char *(solaris_error_names
[]) = {
1776 /* 38 */ "EL2NSYNC",
1785 /* 47 */ "ECANCELED",
1794 /* 56 */ "EDEADLOCK",
1796 /* 58 */ "Error code 58",
1797 /* 59 */ "Error code 59",
1810 /* 72 */ "Error code 72",
1811 /* 73 */ "Error code 73",
1812 /* 74 */ "EMULTIHOP",
1813 /* 75 */ "Error code 75",
1814 /* 76 */ "Error code 76",
1816 /* 78 */ "ENAMETOOLONG",
1817 /* 79 */ "EOVERFLOW",
1818 /* 80 */ "ENOTUNIQ",
1825 /* 87 */ "ELIBEXEC",
1829 /* 91 */ "ERESTART",
1830 /* 92 */ "ESTRPIPE",
1831 /* 93 */ "ENOTEMPTY",
1833 /* 95 */ "ENOTSOCK",
1834 /* 96 */ "EDESTADDRREQ",
1835 /* 97 */ "EMSGSIZE",
1836 /* 98 */ "EPROTOTYPE",
1837 /* 99 */ "ENOPROTOOPT",
1838 /* 100 */ "Error code 100",
1839 /* 101 */ "Error code 101",
1840 /* 102 */ "Error code 102",
1841 /* 103 */ "Error code 103",
1842 /* 104 */ "Error code 104",
1843 /* 105 */ "Error code 105",
1844 /* 106 */ "Error code 106",
1845 /* 107 */ "Error code 107",
1846 /* 108 */ "Error code 108",
1847 /* 109 */ "Error code 109",
1848 /* 110 */ "Error code 110",
1849 /* 111 */ "Error code 111",
1850 /* 112 */ "Error code 112",
1851 /* 113 */ "Error code 113",
1852 /* 114 */ "Error code 114",
1853 /* 115 */ "Error code 115",
1854 /* 116 */ "Error code 116",
1855 /* 117 */ "Error code 117",
1856 /* 118 */ "Error code 118",
1857 /* 119 */ "Error code 119",
1858 /* 120 */ "EPROTONOSUPPORT",
1859 /* 121 */ "ESOCKTNOSUPPORT",
1860 /* 122 */ "EOPNOTSUPP",
1861 /* 123 */ "EPFNOSUPPORT",
1862 /* 124 */ "EAFNOSUPPORT",
1863 /* 125 */ "EADDRINUSE",
1864 /* 126 */ "EADDRNOTAVAIL",
1865 /* 127 */ "ENETDOWN",
1866 /* 128 */ "ENETUNREACH",
1867 /* 129 */ "ENETRESET",
1868 /* 130 */ "ECONNABORTED",
1869 /* 131 */ "ECONNRESET",
1870 /* 132 */ "ENOBUFS",
1871 /* 133 */ "EISCONN",
1872 /* 134 */ "ENOTCONN",
1873 /* 135 */ "Error code 135", /* XENIX has 135 - 142 */
1874 /* 136 */ "Error code 136",
1875 /* 137 */ "Error code 137",
1876 /* 138 */ "Error code 138",
1877 /* 139 */ "Error code 139",
1878 /* 140 */ "Error code 140",
1879 /* 141 */ "Error code 141",
1880 /* 142 */ "Error code 142",
1881 /* 143 */ "ESHUTDOWN",
1882 /* 144 */ "ETOOMANYREFS",
1883 /* 145 */ "ETIMEDOUT",
1884 /* 146 */ "ECONNREFUSED",
1885 /* 147 */ "EHOSTDOWN",
1886 /* 148 */ "EHOSTUNREACH",
1887 /* 149 */ "EALREADY",
1888 /* 150 */ "EINPROGRESS",
1892 static char *(solaris_signal_names
[]) = {
1913 /* 20 */ "SIGWINCH",
1921 /* 28 */ "SIGVTALRM",
1925 /* 32 */ "SIGWAITING",
1927 /* 34 */ "SIGFREEZE",
1929 /* 36 */ "SIGCANCEL",
1932 static emul_syscall emul_solaris_syscalls
= {
1933 solaris_descriptors
,
1934 ARRAY_SIZE (solaris_descriptors
),
1935 solaris_error_names
,
1936 ARRAY_SIZE (solaris_error_names
),
1937 solaris_signal_names
,
1938 ARRAY_SIZE (solaris_signal_names
),
1942 /* Solaris's os_emul interface, most are just passed on to the generic
1945 static os_emul_data
*
1946 emul_solaris_create(device
*root
,
1950 /* check that this emulation is really for us */
1951 if (name
!= NULL
&& strcmp(name
, "solaris") != 0)
1957 return emul_unix_create(root
, image
, "solaris", &emul_solaris_syscalls
);
1961 emul_solaris_init(os_emul_data
*emul_data
,
1970 emul_solaris_system_call(cpu
*processor
,
1972 os_emul_data
*emul_data
)
1974 emul_do_system_call(emul_data
,
1975 emul_data
->syscalls
,
1976 cpu_registers(processor
)->gpr
[0],
1977 3, /*r3 contains arg0*/
1982 const os_emul emul_solaris
= {
1984 emul_solaris_create
,
1986 emul_solaris_system_call
,
1987 0, /*instruction_call*/
1994 Linux - Emulation of user programs for Linux/PPC
2001 /* Linux specific implementation */
2003 typedef unsigned32 linux_dev_t
;
2004 typedef unsigned32 linux_ino_t
;
2005 typedef unsigned32 linux_mode_t
;
2006 typedef unsigned16 linux_nlink_t
;
2007 typedef signed32 linux_off_t
;
2008 typedef signed32 linux_pid_t
;
2009 typedef unsigned32 linux_uid_t
;
2010 typedef unsigned32 linux_gid_t
;
2011 typedef unsigned32 linux_size_t
;
2012 typedef signed32 linux_ssize_t
;
2013 typedef signed32 linux_ptrdiff_t
;
2014 typedef signed32 linux_time_t
;
2015 typedef signed32 linux_clock_t
;
2016 typedef signed32 linux_daddr_t
;
2018 #ifdef HAVE_SYS_STAT_H
2019 /* For the PowerPC, don't both with the 'old' stat structure, since there
2020 should be no extant binaries with that structure. */
2025 linux_mode_t st_mode
;
2026 linux_nlink_t st_nlink
;
2029 linux_dev_t st_rdev
;
2030 linux_off_t st_size
;
2031 unsigned32 st_blksize
;
2032 unsigned32 st_blocks
;
2033 unsigned32 st_atimx
; /* don't use st_{a,c,m}time, that might a macro */
2034 unsigned32 __unused1
; /* defined by the host's stat.h */
2035 unsigned32 st_mtimx
;
2036 unsigned32 __unused2
;
2037 unsigned32 st_ctimx
;
2038 unsigned32 __unused3
;
2039 unsigned32 __unused4
;
2040 unsigned32 __unused5
;
2043 /* Convert from host stat structure to solaris stat structure */
2044 STATIC_INLINE_EMUL_UNIX
void
2045 convert_to_linux_stat(unsigned_word addr
,
2050 struct linux_stat target
;
2052 target
.st_dev
= H2T_4(host
->st_dev
);
2053 target
.st_ino
= H2T_4(host
->st_ino
);
2054 target
.st_mode
= H2T_4(host
->st_mode
);
2055 target
.st_nlink
= H2T_2(host
->st_nlink
);
2056 target
.st_uid
= H2T_4(host
->st_uid
);
2057 target
.st_gid
= H2T_4(host
->st_gid
);
2058 target
.st_size
= H2T_4(host
->st_size
);
2061 target
.st_rdev
= H2T_4(host
->st_rdev
);
2066 #ifdef HAVE_ST_BLKSIZE
2067 target
.st_blksize
= H2T_4(host
->st_blksize
);
2069 target
.st_blksize
= 0;
2072 #ifdef HAVE_ST_BLOCKS
2073 target
.st_blocks
= H2T_4(host
->st_blocks
);
2075 target
.st_blocks
= 0;
2078 target
.st_atimx
= H2T_4(host
->st_atime
);
2079 target
.st_ctimx
= H2T_4(host
->st_ctime
);
2080 target
.st_mtimx
= H2T_4(host
->st_mtime
);
2081 target
.__unused1
= 0;
2082 target
.__unused2
= 0;
2083 target
.__unused3
= 0;
2084 target
.__unused4
= 0;
2085 target
.__unused5
= 0;
2087 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2089 #endif /* HAVE_SYS_STAT_H */
2092 #define do_linux_stat 0
2095 do_linux_stat(os_emul_data
*emul
,
2101 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
2102 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2103 char path_buf
[PATH_MAX
];
2105 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
2108 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2109 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2111 status
= stat (path
, &buf
);
2113 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2115 emul_write_status(processor
, status
, errno
);
2120 #define do_linux_lstat 0
2123 do_linux_lstat(os_emul_data
*emul
,
2129 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
2130 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2131 char path_buf
[PATH_MAX
];
2133 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
2136 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2137 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2139 status
= lstat (path
, &buf
);
2141 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2143 emul_write_status(processor
, status
, errno
);
2148 #define do_linux_fstat 0
2151 do_linux_fstat(os_emul_data
*emul
,
2157 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
2158 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2162 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2163 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
2165 status
= fdbad (fildes
);
2167 status
= fstat (fildes
, &buf
);
2169 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2171 emul_write_status(processor
, status
, errno
);
2175 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2176 #define LINUX_NCC 10
2177 #define LINUX_NCCS 19
2179 #define LINUX_VINTR 0
2180 #define LINUX_VQUIT 1
2181 #define LINUX_VERASE 2
2182 #define LINUX_VKILL 3
2183 #define LINUX_VEOF 4
2184 #define LINUX_VMIN 5
2185 #define LINUX_VEOL 6
2186 #define LINUX_VTIME 7
2187 #define LINUX_VEOL2 8
2188 #define LINUX_VSWTC 9
2189 #define LINUX_VWERASE 10
2190 #define LINUX_VREPRINT 11
2191 #define LINUX_VSUSP 12
2192 #define LINUX_VSTART 13
2193 #define LINUX_VSTOP 14
2194 #define LINUX_VLNEXT 15
2195 #define LINUX_VDISCARD 16
2197 #define LINUX_IOC_NRBITS 8
2198 #define LINUX_IOC_TYPEBITS 8
2199 #define LINUX_IOC_SIZEBITS 13
2200 #define LINUX_IOC_DIRBITS 3
2202 #define LINUX_IOC_NRMASK ((1 << LINUX_IOC_NRBITS)-1)
2203 #define LINUX_IOC_TYPEMASK ((1 << LINUX_IOC_TYPEBITS)-1)
2204 #define LINUX_IOC_SIZEMASK ((1 << LINUX_IOC_SIZEBITS)-1)
2205 #define LINUX_IOC_DIRMASK ((1 << LINUX_IOC_DIRBITS)-1)
2207 #define LINUX_IOC_NRSHIFT 0
2208 #define LINUX_IOC_TYPESHIFT (LINUX_IOC_NRSHIFT+LINUX_IOC_NRBITS)
2209 #define LINUX_IOC_SIZESHIFT (LINUX_IOC_TYPESHIFT+LINUX_IOC_TYPEBITS)
2210 #define LINUX_IOC_DIRSHIFT (LINUX_IOC_SIZESHIFT+LINUX_IOC_SIZEBITS)
2213 * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
2214 * And this turns out useful to catch old ioctl numbers in header
2217 #define LINUX_IOC_NONE 1U
2218 #define LINUX_IOC_READ 2U
2219 #define LINUX_IOC_WRITE 4U
2221 #define LINUX_IOC(dir,type,nr,size) \
2222 (((dir) << LINUX_IOC_DIRSHIFT) | \
2223 ((type) << LINUX_IOC_TYPESHIFT) | \
2224 ((nr) << LINUX_IOC_NRSHIFT) | \
2225 ((size) << LINUX_IOC_SIZESHIFT))
2227 /* used to create numbers */
2228 #define LINUX_IO(type,nr) LINUX_IOC(LINUX_IOC_NONE,(type),(nr),0)
2229 #define LINUX_IOR(type,nr,size) LINUX_IOC(LINUX_IOC_READ,(type),(nr),sizeof(size))
2230 #define LINUX_IOW(type,nr,size) LINUX_IOC(LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2231 #define LINUX_IOWR(type,nr,size) LINUX_IOC(LINUX_IOC_READ|LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2234 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2235 /* Convert to/from host termio structure */
2237 struct linux_termio
{
2238 unsigned16 c_iflag
; /* input modes */
2239 unsigned16 c_oflag
; /* output modes */
2240 unsigned16 c_cflag
; /* control modes */
2241 unsigned16 c_lflag
; /* line discipline modes */
2242 unsigned8 c_line
; /* line discipline */
2243 unsigned8 c_cc
[LINUX_NCC
]; /* control chars */
2246 STATIC_INLINE_EMUL_UNIX
void
2247 convert_to_linux_termio(unsigned_word addr
,
2248 struct termio
*host
,
2252 struct linux_termio target
;
2255 target
.c_iflag
= H2T_2 (host
->c_iflag
);
2256 target
.c_oflag
= H2T_2 (host
->c_oflag
);
2257 target
.c_cflag
= H2T_2 (host
->c_cflag
);
2258 target
.c_lflag
= H2T_2 (host
->c_lflag
);
2260 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
2261 target
.c_line
= host
->c_line
;
2266 for (i
= 0; i
< LINUX_NCC
; i
++)
2270 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2274 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2278 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2282 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2286 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2290 target
.c_cc
[LINUX_VMIN
] = host
->c_cc
[VMIN
];
2294 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2298 target
.c_cc
[LINUX_VTIME
] = host
->c_cc
[VTIME
];
2302 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2306 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTC
];
2310 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2313 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2315 #endif /* HAVE_TERMIO_STRUCTURE */
2317 #ifdef HAVE_TERMIOS_STRUCTURE
2318 /* Convert to/from host termios structure */
2320 typedef unsigned32 linux_tcflag_t
;
2321 typedef unsigned8 linux_cc_t
;
2322 typedef unsigned32 linux_speed_t
;
2324 struct linux_termios
{
2325 linux_tcflag_t c_iflag
;
2326 linux_tcflag_t c_oflag
;
2327 linux_tcflag_t c_cflag
;
2328 linux_tcflag_t c_lflag
;
2329 linux_cc_t c_cc
[LINUX_NCCS
];
2335 STATIC_INLINE_EMUL_UNIX
void
2336 convert_to_linux_termios(unsigned_word addr
,
2337 struct termios
*host
,
2341 struct linux_termios target
;
2344 target
.c_iflag
= H2T_4 (host
->c_iflag
);
2345 target
.c_oflag
= H2T_4 (host
->c_oflag
);
2346 target
.c_cflag
= H2T_4 (host
->c_cflag
);
2347 target
.c_lflag
= H2T_4 (host
->c_lflag
);
2349 for (i
= 0; i
< LINUX_NCCS
; i
++)
2353 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2357 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2361 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2365 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2369 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2373 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2377 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2381 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2384 #ifdef HAVE_TERMIOS_CLINE
2385 target
.c_line
= host
->c_line
;
2390 #ifdef HAVE_CFGETISPEED
2391 target
.c_ispeed
= cfgetispeed (host
);
2393 target
.c_ispeed
= 0;
2396 #ifdef HAVE_CFGETOSPEED
2397 target
.c_ospeed
= cfgetospeed (host
);
2399 target
.c_ospeed
= 0;
2402 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2404 #endif /* HAVE_TERMIOS_STRUCTURE */
2407 #define do_linux_ioctl 0
2410 do_linux_ioctl(os_emul_data
*emul
,
2416 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
2417 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
2418 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
2420 const char *name
= "<unknown>";
2422 #ifdef HAVE_TERMIOS_STRUCTURE
2423 struct termios host_termio
;
2426 #ifdef HAVE_TERMIO_STRUCTURE
2427 struct termio host_termio
;
2431 status
= fdbad (fildes
);
2437 case 0: /* make sure we have at least one case */
2443 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2444 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
2445 case LINUX_IOR('t', 23, struct linux_termio
): /* TCGETA */
2447 #ifdef HAVE_TCGETATTR
2448 status
= tcgetattr(fildes
, &host_termio
);
2449 #elif defined(TCGETS)
2450 status
= ioctl (fildes
, TCGETS
, &host_termio
);
2452 status
= ioctl (fildes
, TCGETA
, &host_termio
);
2455 convert_to_linux_termio (argp_addr
, &host_termio
, processor
, cia
);
2458 #endif /* HAVE_TERMIO_STRUCTURE */
2460 #ifdef HAVE_TERMIOS_STRUCTURE
2461 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
2462 case LINUX_IOR('t', 19, struct linux_termios
): /* TCGETS */
2464 #ifdef HAVE_TCGETATTR
2465 status
= tcgetattr(fildes
, &host_termio
);
2467 status
= ioctl (fildes
, TCGETS
, &host_termio
);
2470 convert_to_linux_termios (argp_addr
, &host_termio
, processor
, cia
);
2473 #endif /* HAVE_TERMIOS_STRUCTURE */
2477 emul_write_status(processor
, status
, errno
);
2479 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2480 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
2482 #endif /* HAVE_IOCTL */
2484 static emul_syscall_descriptor linux_descriptors
[] = {
2485 /* 0 */ { 0, "setup" },
2486 /* 1 */ { do_unix_exit
, "exit" },
2487 /* 2 */ { 0, "fork" },
2488 /* 3 */ { do_unix_read
, "read" },
2489 /* 4 */ { do_unix_write
, "write" },
2490 /* 5 */ { do_unix_open
, "open" },
2491 /* 6 */ { do_unix_close
, "close" },
2492 /* 7 */ { 0, "waitpid" },
2493 /* 8 */ { 0, "creat" },
2494 /* 9 */ { do_unix_link
, "link" },
2495 /* 10 */ { do_unix_unlink
, "unlink" },
2496 /* 11 */ { 0, "execve" },
2497 /* 12 */ { do_unix_chdir
, "chdir" },
2498 /* 13 */ { do_unix_time
, "time" },
2499 /* 14 */ { 0, "mknod" },
2500 /* 15 */ { 0, "chmod" },
2501 /* 16 */ { 0, "chown" },
2502 /* 17 */ { 0, "break" },
2503 /* 18 */ { 0, "stat" },
2504 /* 19 */ { do_unix_lseek
, "lseek" },
2505 /* 20 */ { do_unix_getpid
, "getpid" },
2506 /* 21 */ { 0, "mount" },
2507 /* 22 */ { 0, "umount" },
2508 /* 23 */ { 0, "setuid" },
2509 /* 24 */ { do_unix_getuid
, "getuid" },
2510 /* 25 */ { 0, "stime" },
2511 /* 26 */ { 0, "ptrace" },
2512 /* 27 */ { 0, "alarm" },
2513 /* 28 */ { 0, "fstat" },
2514 /* 29 */ { 0, "pause" },
2515 /* 30 */ { 0, "utime" },
2516 /* 31 */ { 0, "stty" },
2517 /* 32 */ { 0, "gtty" },
2518 /* 33 */ { do_unix_access
, "access" },
2519 /* 34 */ { 0, "nice" },
2520 /* 35 */ { 0, "ftime" },
2521 /* 36 */ { 0, "sync" },
2522 /* 37 */ { 0, "kill" },
2523 /* 38 */ { 0, "rename" },
2524 /* 39 */ { do_unix_mkdir
, "mkdir" },
2525 /* 40 */ { do_unix_rmdir
, "rmdir" },
2526 /* 41 */ { do_unix_dup
, "dup" },
2527 /* 42 */ { 0, "pipe" },
2528 /* 43 */ { 0, "times" },
2529 /* 44 */ { 0, "prof" },
2530 /* 45 */ { do_unix_break
, "brk" },
2531 /* 46 */ { 0, "setgid" },
2532 /* 47 */ { do_unix_getgid
, "getgid" },
2533 /* 48 */ { 0, "signal" },
2534 /* 49 */ { do_unix_geteuid
, "geteuid" },
2535 /* 50 */ { do_unix_getegid
, "getegid" },
2536 /* 51 */ { 0, "acct" },
2537 /* 52 */ { 0, "phys" },
2538 /* 53 */ { 0, "lock" },
2539 /* 54 */ { do_linux_ioctl
, "ioctl" },
2540 /* 55 */ { 0, "fcntl" },
2541 /* 56 */ { 0, "mpx" },
2542 /* 57 */ { 0, "setpgid" },
2543 /* 58 */ { 0, "ulimit" },
2544 /* 59 */ { 0, "olduname" },
2545 /* 60 */ { do_unix_umask
, "umask" },
2546 /* 61 */ { 0, "chroot" },
2547 /* 62 */ { 0, "ustat" },
2548 /* 63 */ { do_unix_dup2
, "dup2" },
2549 /* 64 */ { do_unix_getppid
, "getppid" },
2550 /* 65 */ { 0, "getpgrp" },
2551 /* 66 */ { 0, "setsid" },
2552 /* 67 */ { 0, "sigaction" },
2553 /* 68 */ { 0, "sgetmask" },
2554 /* 69 */ { 0, "ssetmask" },
2555 /* 70 */ { 0, "setreuid" },
2556 /* 71 */ { 0, "setregid" },
2557 /* 72 */ { 0, "sigsuspend" },
2558 /* 73 */ { 0, "sigpending" },
2559 /* 74 */ { 0, "sethostname" },
2560 /* 75 */ { 0, "setrlimit" },
2561 /* 76 */ { 0, "getrlimit" },
2562 /* 77 */ { do_unix_getrusage
, "getrusage" },
2563 /* 78 */ { do_unix_gettimeofday
, "gettimeofday" },
2564 /* 79 */ { 0, "settimeofday" },
2565 /* 80 */ { 0, "getgroups" },
2566 /* 81 */ { 0, "setgroups" },
2567 /* 82 */ { 0, "select" },
2568 /* 83 */ { do_unix_symlink
, "symlink" },
2569 /* 84 */ { 0, "lstat" },
2570 /* 85 */ { 0, "readlink" },
2571 /* 86 */ { 0, "uselib" },
2572 /* 87 */ { 0, "swapon" },
2573 /* 88 */ { 0, "reboot" },
2574 /* 89 */ { 0, "readdir" },
2575 /* 90 */ { 0, "mmap" },
2576 /* 91 */ { 0, "munmap" },
2577 /* 92 */ { 0, "truncate" },
2578 /* 93 */ { 0, "ftruncate" },
2579 /* 94 */ { 0, "fchmod" },
2580 /* 95 */ { 0, "fchown" },
2581 /* 96 */ { 0, "getpriority" },
2582 /* 97 */ { 0, "setpriority" },
2583 /* 98 */ { 0, "profil" },
2584 /* 99 */ { 0, "statfs" },
2585 /* 100 */ { 0, "fstatfs" },
2586 /* 101 */ { 0, "ioperm" },
2587 /* 102 */ { 0, "socketcall" },
2588 /* 103 */ { 0, "syslog" },
2589 /* 104 */ { 0, "setitimer" },
2590 /* 105 */ { 0, "getitimer" },
2591 /* 106 */ { do_linux_stat
, "newstat" },
2592 /* 107 */ { do_linux_lstat
, "newlstat" },
2593 /* 108 */ { do_linux_fstat
, "newfstat" },
2594 /* 109 */ { 0, "uname" },
2595 /* 110 */ { 0, "iopl" },
2596 /* 111 */ { 0, "vhangup" },
2597 /* 112 */ { 0, "idle" },
2598 /* 113 */ { 0, "vm86" },
2599 /* 114 */ { 0, "wait4" },
2600 /* 115 */ { 0, "swapoff" },
2601 /* 116 */ { 0, "sysinfo" },
2602 /* 117 */ { 0, "ipc" },
2603 /* 118 */ { 0, "fsync" },
2604 /* 119 */ { 0, "sigreturn" },
2605 /* 120 */ { 0, "clone" },
2606 /* 121 */ { 0, "setdomainname" },
2607 /* 122 */ { 0, "newuname" },
2608 /* 123 */ { 0, "modify_ldt" },
2609 /* 124 */ { 0, "adjtimex" },
2610 /* 125 */ { 0, "mprotect" },
2611 /* 126 */ { 0, "sigprocmask" },
2612 /* 127 */ { 0, "create_module" },
2613 /* 128 */ { 0, "init_module" },
2614 /* 129 */ { 0, "delete_module" },
2615 /* 130 */ { 0, "get_kernel_syms" },
2616 /* 131 */ { 0, "quotactl" },
2617 /* 132 */ { 0, "getpgid" },
2618 /* 133 */ { 0, "fchdir" },
2619 /* 134 */ { 0, "bdflush" },
2620 /* 135 */ { 0, "sysfs" },
2621 /* 136 */ { 0, "personality" },
2622 /* 137 */ { 0, "afs_syscall" },
2623 /* 138 */ { 0, "setfsuid" },
2624 /* 139 */ { 0, "setfsgid" },
2625 /* 140 */ { 0, "llseek" },
2626 /* 141 */ { 0, "getdents" },
2627 /* 142 */ { 0, "newselect" },
2628 /* 143 */ { 0, "flock" },
2629 /* 144 */ { 0, "msync" },
2630 /* 145 */ { 0, "readv" },
2631 /* 146 */ { 0, "writev" },
2632 /* 147 */ { 0, "getsid" },
2633 /* 148 */ { 0, "fdatasync" },
2634 /* 149 */ { 0, "sysctl" },
2635 /* 150 */ { 0, "mlock" },
2636 /* 151 */ { 0, "munlock" },
2637 /* 152 */ { 0, "mlockall" },
2638 /* 153 */ { 0, "munlockall" },
2639 /* 154 */ { 0, "sched_setparam" },
2640 /* 155 */ { 0, "sched_getparam" },
2641 /* 156 */ { 0, "sched_setscheduler" },
2642 /* 157 */ { 0, "sched_getscheduler" },
2643 /* 158 */ { 0, "sched_yield" },
2644 /* 159 */ { 0, "sched_get_priority_max" },
2645 /* 160 */ { 0, "sched_get_priority_min" },
2646 /* 161 */ { 0, "sched_rr_get_interval" },
2649 static char *(linux_error_names
[]) = {
2686 /* 36 */ "ENAMETOOLONG",
2689 /* 39 */ "ENOTEMPTY",
2695 /* 45 */ "EL2NSYNC",
2708 /* 58 */ "EDEADLOCK",
2722 /* 72 */ "EMULTIHOP",
2725 /* 75 */ "EOVERFLOW",
2726 /* 76 */ "ENOTUNIQ",
2733 /* 83 */ "ELIBEXEC",
2735 /* 85 */ "ERESTART",
2736 /* 86 */ "ESTRPIPE",
2738 /* 88 */ "ENOTSOCK",
2739 /* 89 */ "EDESTADDRREQ",
2740 /* 90 */ "EMSGSIZE",
2741 /* 91 */ "EPROTOTYPE",
2742 /* 92 */ "ENOPROTOOPT",
2743 /* 93 */ "EPROTONOSUPPORT",
2744 /* 94 */ "ESOCKTNOSUPPORT",
2745 /* 95 */ "EOPNOTSUPP",
2746 /* 96 */ "EPFNOSUPPORT",
2747 /* 97 */ "EAFNOSUPPORT",
2748 /* 98 */ "EADDRINUSE",
2749 /* 99 */ "EADDRNOTAVAIL",
2750 /* 100 */ "ENETDOWN",
2751 /* 101 */ "ENETUNREACH",
2752 /* 102 */ "ENETRESET",
2753 /* 103 */ "ECONNABORTED",
2754 /* 104 */ "ECONNRESET",
2755 /* 105 */ "ENOBUFS",
2756 /* 106 */ "EISCONN",
2757 /* 107 */ "ENOTCONN",
2758 /* 108 */ "ESHUTDOWN",
2759 /* 109 */ "ETOOMANYREFS",
2760 /* 110 */ "ETIMEDOUT",
2761 /* 111 */ "ECONNREFUSED",
2762 /* 112 */ "EHOSTDOWN",
2763 /* 113 */ "EHOSTUNREACH",
2764 /* 114 */ "EALREADY",
2765 /* 115 */ "EINPROGRESS",
2767 /* 117 */ "EUCLEAN",
2768 /* 118 */ "ENOTNAM",
2769 /* 119 */ "ENAVAIL",
2771 /* 121 */ "EREMOTEIO",
2775 static char *(linux_signal_names
[]) = {
2793 /* 16 */ "SIGSTKFLT",
2803 /* 26 */ "SIGVTALRM",
2805 /* 28 */ "SIGWINCH",
2808 /* 31 */ "SIGUNUSED",
2811 static emul_syscall emul_linux_syscalls
= {
2813 ARRAY_SIZE (linux_descriptors
),
2815 ARRAY_SIZE (linux_error_names
),
2817 ARRAY_SIZE (linux_signal_names
),
2821 /* Linux's os_emul interface, most are just passed on to the generic
2824 static os_emul_data
*
2825 emul_linux_create(device
*root
,
2829 /* check that this emulation is really for us */
2830 if (name
!= NULL
&& strcmp(name
, "linux") != 0)
2836 return emul_unix_create(root
, image
, "linux", &emul_linux_syscalls
);
2840 emul_linux_init(os_emul_data
*emul_data
,
2849 emul_linux_system_call(cpu
*processor
,
2851 os_emul_data
*emul_data
)
2853 emul_do_system_call(emul_data
,
2854 emul_data
->syscalls
,
2855 cpu_registers(processor
)->gpr
[0],
2856 3, /*r3 contains arg0*/
2861 const os_emul emul_linux
= {
2865 emul_linux_system_call
,
2866 0, /*instruction_call*/
2870 #endif /* _EMUL_UNIX_C_ */