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
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
35 #ifdef HAVE_SYS_TYPES_H
51 #ifdef HAVE_SYS_PARAM_H
52 #include <sys/param.h>
57 #ifndef HAVE_TERMIOS_STRUCTURE
58 #undef HAVE_SYS_TERMIOS_H
61 #ifndef HAVE_SYS_TERMIOS_H
62 #undef HAVE_TERMIOS_STRUCTURE
66 #ifdef HAVE_TERMIOS_STRUCTURE
67 #include <sys/termios.h>
69 /* If we have TERMIOS, use that for the termio structure, since some systems
70 don't like including both sys/termios.h and sys/termio.h at the same
72 #undef HAVE_TERMIO_STRUCTURE
75 #define termio termios
78 #ifndef HAVE_TERMIO_STRUCTURE
79 #undef HAVE_SYS_TERMIO_H
81 #ifndef HAVE_SYS_TERMIO_H
82 #undef HAVE_TERMIO_STRUCTURE
86 #ifdef HAVE_TERMIO_STRUCTURE
87 #include <sys/termio.h>
91 #ifndef HAVE_SYS_RESOURCE_H
97 #include <sys/resource.h>
103 # define NAMLEN(dirent) strlen((dirent)->d_name)
105 # define dirent direct
106 # define NAMLEN(dirent) (dirent)->d_namlen
108 # include <sys/ndir.h>
111 # include <sys/dir.h>
118 #undef MAXPATHLEN /* sys/param.h might define this also */
124 #include "emul_generic.h"
125 #include "emul_unix.h"
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 int32_t tv_sec
; /* seconds */
152 int32_t tv_usec
; /* microseconds */
155 struct unix_timezone
{
156 int32_t tz_minuteswest
; /* minutes west of Greenwich */
157 int32_t 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 int32_t ru_maxrss
; /* maximum resident set size */
168 int32_t ru_ixrss
; /* integral shared memory size */
169 int32_t ru_idrss
; /* integral unshared data size */
170 int32_t ru_isrss
; /* integral unshared stack size */
171 int32_t ru_minflt
; /* any page faults not requiring I/O */
172 int32_t ru_majflt
; /* any page faults requiring I/O */
173 int32_t ru_nswap
; /* swaps */
174 int32_t ru_inblock
; /* block input operations */
175 int32_t ru_oublock
; /* block output operations */
176 int32_t ru_msgsnd
; /* messages sent */
177 int32_t ru_msgrcv
; /* messages received */
178 int32_t ru_nsignals
; /* signals received */
179 int32_t ru_nvcsw
; /* voluntary context switches */
180 int32_t 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
);
761 status
= mkdir(path
, mode
);
762 emul_write_status(processor
, status
, errno
);
767 #define do_unix_rmdir 0
770 do_unix_rmdir(os_emul_data
*emul
,
776 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
777 char path_buf
[PATH_MAX
];
778 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
781 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
782 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
784 status
= rmdir(path
);
785 emul_write_status(processor
, status
, errno
);
790 #define do_unix_time 0
793 do_unix_time(os_emul_data
*emul
,
799 unsigned_word tp
= cpu_registers(processor
)->gpr
[arg0
];
800 time_t now
= time ((time_t *)0);
801 unsigned_word status
= H2T_4(now
);
803 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
804 printf_filtered ("0x%lx", (long)tp
);
806 emul_write_status(processor
, (int)status
, errno
);
809 emul_write_buffer(&status
, tp
, sizeof(status
), processor
, cia
);
813 #if !defined(HAVE_GETTIMEOFDAY)
814 #define do_unix_gettimeofday 0
817 do_unix_gettimeofday(os_emul_data
*emul
,
823 unsigned_word tv
= cpu_registers(processor
)->gpr
[arg0
];
824 unsigned_word tz
= cpu_registers(processor
)->gpr
[arg0
+1];
825 struct unix_timeval target_timeval
;
826 struct timeval host_timeval
;
827 struct unix_timezone target_timezone
;
828 struct timezone host_timezone
;
831 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
832 printf_filtered ("0x%lx, 0x%lx", (long)tv
, (long)tz
);
834 /* Just in case the system doesn't set the timezone structure */
835 host_timezone
.tz_minuteswest
= 0;
836 host_timezone
.tz_dsttime
= 0;
838 status
= gettimeofday(&host_timeval
, &host_timezone
);
841 target_timeval
.tv_sec
= H2T_4(host_timeval
.tv_sec
);
842 target_timeval
.tv_usec
= H2T_4(host_timeval
.tv_usec
);
843 emul_write_buffer((void *) &target_timeval
, tv
, sizeof(target_timeval
), processor
, cia
);
847 target_timezone
.tz_minuteswest
= H2T_4(host_timezone
.tz_minuteswest
);
848 target_timezone
.tz_dsttime
= H2T_4(host_timezone
.tz_dsttime
);
849 emul_write_buffer((void *) &target_timezone
, tv
, sizeof(target_timezone
), processor
, cia
);
853 emul_write_status(processor
, (int)status
, errno
);
858 #ifndef HAVE_GETRUSAGE
859 #define do_unix_getrusage 0
862 do_unix_getrusage(os_emul_data
*emul
,
868 signed_word who
= (signed_word
)cpu_registers(processor
)->gpr
[arg0
];
869 unsigned_word usage
= cpu_registers(processor
)->gpr
[arg0
+1];
870 struct rusage host_rusage
, host_rusage2
;
871 struct unix_rusage target_rusage
;
874 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
875 printf_filtered ("%ld, 0x%lx", (long)who
, (long)usage
);
883 case UNIX_RUSAGE_SELF
:
884 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
887 case UNIX_RUSAGE_CHILDREN
:
888 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage
);
891 case UNIX_RUSAGE_BOTH
:
892 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
894 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage2
);
896 host_rusage
.ru_utime
.tv_sec
+= host_rusage2
.ru_utime
.tv_sec
;
897 host_rusage
.ru_utime
.tv_usec
+= host_rusage2
.ru_utime
.tv_usec
;
898 host_rusage
.ru_stime
.tv_sec
+= host_rusage2
.ru_stime
.tv_sec
;
899 host_rusage
.ru_stime
.tv_usec
+= host_rusage2
.ru_stime
.tv_usec
;
900 host_rusage
.ru_maxrss
+= host_rusage2
.ru_maxrss
;
901 host_rusage
.ru_ixrss
+= host_rusage2
.ru_ixrss
;
902 host_rusage
.ru_idrss
+= host_rusage2
.ru_idrss
;
903 host_rusage
.ru_isrss
+= host_rusage2
.ru_isrss
;
904 host_rusage
.ru_minflt
+= host_rusage2
.ru_minflt
;
905 host_rusage
.ru_majflt
+= host_rusage2
.ru_majflt
;
906 host_rusage
.ru_nswap
+= host_rusage2
.ru_nswap
;
907 host_rusage
.ru_inblock
+= host_rusage2
.ru_inblock
;
908 host_rusage
.ru_oublock
+= host_rusage2
.ru_oublock
;
909 host_rusage
.ru_msgsnd
+= host_rusage2
.ru_msgsnd
;
910 host_rusage
.ru_msgrcv
+= host_rusage2
.ru_msgrcv
;
911 host_rusage
.ru_nsignals
+= host_rusage2
.ru_nsignals
;
912 host_rusage
.ru_nvcsw
+= host_rusage2
.ru_nvcsw
;
913 host_rusage
.ru_nivcsw
+= host_rusage2
.ru_nivcsw
;
919 target_rusage
.ru_utime
.tv_sec
= H2T_4(host_rusage2
.ru_utime
.tv_sec
);
920 target_rusage
.ru_utime
.tv_usec
= H2T_4(host_rusage2
.ru_utime
.tv_usec
);
921 target_rusage
.ru_stime
.tv_sec
= H2T_4(host_rusage2
.ru_stime
.tv_sec
);
922 target_rusage
.ru_stime
.tv_usec
= H2T_4(host_rusage2
.ru_stime
.tv_usec
);
923 target_rusage
.ru_maxrss
= H2T_4(host_rusage2
.ru_maxrss
);
924 target_rusage
.ru_ixrss
= H2T_4(host_rusage2
.ru_ixrss
);
925 target_rusage
.ru_idrss
= H2T_4(host_rusage2
.ru_idrss
);
926 target_rusage
.ru_isrss
= H2T_4(host_rusage2
.ru_isrss
);
927 target_rusage
.ru_minflt
= H2T_4(host_rusage2
.ru_minflt
);
928 target_rusage
.ru_majflt
= H2T_4(host_rusage2
.ru_majflt
);
929 target_rusage
.ru_nswap
= H2T_4(host_rusage2
.ru_nswap
);
930 target_rusage
.ru_inblock
= H2T_4(host_rusage2
.ru_inblock
);
931 target_rusage
.ru_oublock
= H2T_4(host_rusage2
.ru_oublock
);
932 target_rusage
.ru_msgsnd
= H2T_4(host_rusage2
.ru_msgsnd
);
933 target_rusage
.ru_msgrcv
= H2T_4(host_rusage2
.ru_msgrcv
);
934 target_rusage
.ru_nsignals
= H2T_4(host_rusage2
.ru_nsignals
);
935 target_rusage
.ru_nvcsw
= H2T_4(host_rusage2
.ru_nvcsw
);
936 target_rusage
.ru_nivcsw
= H2T_4(host_rusage2
.ru_nivcsw
);
937 emul_write_buffer((void *) &target_rusage
, usage
, sizeof(target_rusage
), processor
, cia
);
940 emul_write_status(processor
, status
, errno
);
946 do_unix_nop(os_emul_data
*emul
,
952 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
953 printf_filtered ("0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
954 (long)cpu_registers(processor
)->gpr
[arg0
],
955 (long)cpu_registers(processor
)->gpr
[arg0
+1],
956 (long)cpu_registers(processor
)->gpr
[arg0
+2],
957 (long)cpu_registers(processor
)->gpr
[arg0
+3],
958 (long)cpu_registers(processor
)->gpr
[arg0
+4],
959 (long)cpu_registers(processor
)->gpr
[arg0
+5]);
961 emul_write_status(processor
, 0, errno
);
965 /* Common code for initializing the system call stuff */
967 static os_emul_data
*
968 emul_unix_create(device
*root
,
971 emul_syscall
*syscall
)
973 unsigned_word top_of_stack
;
980 /* merge any emulation specific entries into the device tree */
982 /* establish a few defaults */
983 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
985 top_of_stack
= 0xe0000000;
986 stack_size
= 0x00100000;
990 top_of_stack
= 0x20000000;
991 stack_size
= 0x00100000;
995 emul_add_tree_options(root
, image
, name
,
996 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
997 ? "user" : "virtual"),
998 0 /*oea-interrupt-prefix*/);
1000 /* virtual memory - handles growth of stack/heap */
1001 vm
= tree_parse(root
, "/openprom/vm@0x%lx",
1002 (unsigned long)(top_of_stack
- stack_size
));
1003 tree_parse(vm
, "./stack-base 0x%lx",
1004 (unsigned long)(top_of_stack
- stack_size
));
1005 tree_parse(vm
, "./nr-bytes 0x%x", stack_size
);
1007 filename
= tree_quote_property (bfd_get_filename(image
));
1008 tree_parse(root
, "/openprom/vm/map-binary/file-name %s",
1012 /* finish the init */
1013 tree_parse(root
, "/openprom/init/register/pc 0x%lx",
1014 (unsigned long)bfd_get_start_address(image
));
1015 tree_parse(root
, "/openprom/init/register/sp 0x%lx",
1016 (unsigned long)top_of_stack
);
1017 tree_parse(root
, "/openprom/init/register/msr 0x%x",
1018 ((tree_find_boolean_property(root
, "/options/little-endian?")
1019 ? msr_little_endian_mode
1021 | (tree_find_boolean_property(root
, "/openprom/options/floating-point?")
1022 ? (msr_floating_point_available
1023 | msr_floating_point_exception_mode_0
1024 | msr_floating_point_exception_mode_1
)
1026 tree_parse(root
, "/openprom/init/stack/stack-type %s",
1027 (elf_binary
? "ppc-elf" : "ppc-xcoff"));
1029 /* finally our emulation data */
1030 data
= ZALLOC(os_emul_data
);
1032 data
->syscalls
= syscall
;
1039 Solaris - Emulation of user programs for Solaris/PPC
1046 /* Solaris specific implementation */
1048 typedef int32_t solaris_uid_t
;
1049 typedef int32_t solaris_gid_t
;
1050 typedef int32_t solaris_off_t
;
1051 typedef int32_t solaris_pid_t
;
1052 typedef int32_t solaris_time_t
;
1053 typedef uint32_t solaris_dev_t
;
1054 typedef uint32_t solaris_ino_t
;
1055 typedef uint32_t solaris_mode_t
;
1056 typedef uint32_t solaris_nlink_t
;
1058 #ifdef HAVE_SYS_STAT_H
1059 #define SOLARIS_ST_FSTYPSZ 16 /* array size for file system type name */
1061 /* AIX 7.1 defines st_pad[123] to st_[amc]tim.tv_pad, respectively */
1066 struct solaris_stat
{
1067 solaris_dev_t st_dev
;
1068 int32_t st_pad1
[3]; /* reserved for network id */
1069 solaris_ino_t st_ino
;
1070 solaris_mode_t st_mode
;
1071 solaris_nlink_t st_nlink
;
1072 solaris_uid_t st_uid
;
1073 solaris_gid_t st_gid
;
1074 solaris_dev_t st_rdev
;
1076 solaris_off_t st_size
;
1077 int32_t st_pad3
; /* future off_t expansion */
1078 struct unix_timeval st_atim
;
1079 struct unix_timeval st_mtim
;
1080 struct unix_timeval st_ctim
;
1083 char st_fstype
[SOLARIS_ST_FSTYPSZ
];
1084 int32_t st_pad4
[8]; /* expansion area */
1087 /* Convert from host stat structure to solaris stat structure */
1088 STATIC_INLINE_EMUL_UNIX
void
1089 convert_to_solaris_stat(unsigned_word addr
,
1094 struct solaris_stat target
;
1097 target
.st_dev
= H2T_4(host
->st_dev
);
1098 target
.st_ino
= H2T_4(host
->st_ino
);
1099 target
.st_mode
= H2T_4(host
->st_mode
);
1100 target
.st_nlink
= H2T_4(host
->st_nlink
);
1101 target
.st_uid
= H2T_4(host
->st_uid
);
1102 target
.st_gid
= H2T_4(host
->st_gid
);
1103 target
.st_size
= H2T_4(host
->st_size
);
1106 target
.st_rdev
= H2T_4(host
->st_rdev
);
1111 #ifdef HAVE_ST_BLKSIZE
1112 target
.st_blksize
= H2T_4(host
->st_blksize
);
1114 target
.st_blksize
= 0;
1117 #ifdef HAVE_ST_BLOCKS
1118 target
.st_blocks
= H2T_4(host
->st_blocks
);
1120 target
.st_blocks
= 0;
1123 target
.st_atim
.tv_sec
= H2T_4(host
->st_atime
);
1124 target
.st_atim
.tv_usec
= 0;
1126 target
.st_ctim
.tv_sec
= H2T_4(host
->st_ctime
);
1127 target
.st_ctim
.tv_usec
= 0;
1129 target
.st_mtim
.tv_sec
= H2T_4(host
->st_mtime
);
1130 target
.st_mtim
.tv_usec
= 0;
1132 for (i
= 0; i
< ARRAY_SIZE (target
.st_pad1
); i
++)
1133 target
.st_pad1
[i
] = 0;
1135 for (i
= 0; i
< ARRAY_SIZE (target
.st_pad2
); i
++)
1136 target
.st_pad2
[i
] = 0;
1140 for (i
= 0; i
< ARRAY_SIZE (target
.st_pad4
); i
++)
1141 target
.st_pad4
[i
] = 0;
1143 /* For now, just punt and always say it is a ufs file */
1144 strcpy (target
.st_fstype
, "ufs");
1146 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1148 #endif /* HAVE_SYS_STAT_H */
1151 #define do_solaris_stat 0
1154 do_solaris_stat(os_emul_data
*emul
,
1160 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1161 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1162 char path_buf
[PATH_MAX
];
1164 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1167 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1168 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1170 status
= stat (path
, &buf
);
1172 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1174 emul_write_status(processor
, status
, errno
);
1179 #define do_solaris_lstat 0
1182 do_solaris_lstat(os_emul_data
*emul
,
1188 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1189 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1190 char path_buf
[PATH_MAX
];
1192 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1195 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1196 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1198 status
= lstat (path
, &buf
);
1200 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1202 emul_write_status(processor
, status
, errno
);
1207 #define do_solaris_fstat 0
1210 do_solaris_fstat(os_emul_data
*emul
,
1216 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
1217 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1221 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1222 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
1224 status
= fdbad (fildes
);
1226 status
= fstat (fildes
, &buf
);
1228 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1230 emul_write_status(processor
, status
, errno
);
1234 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1235 #define SOLARIS_TIOC ('T'<<8)
1236 #define SOLARIS_NCC 8
1237 #define SOLARIS_NCCS 19
1239 #define SOLARIS_VINTR 0
1240 #define SOLARIS_VQUIT 1
1241 #define SOLARIS_VERASE 2
1242 #define SOLARIS_VKILL 3
1243 #define SOLARIS_VEOF 4
1244 #define SOLARIS_VEOL 5
1245 #define SOLARIS_VEOL2 6
1246 #define SOLARIS_VSWTCH 7
1247 #define SOLARIS_VSTART 8
1248 #define SOLARIS_VSTOP 9
1249 #define SOLARIS_VSUSP 10
1250 #define SOLARIS_VDSUSP 11
1251 #define SOLARIS_VREPRINT 12
1252 #define SOLARIS_VDISCARD 13
1253 #define SOLARIS_VWERASE 14
1254 #define SOLARIS_VLNEXT 15
1257 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1258 /* Convert to/from host termio structure */
1260 struct solaris_termio
{
1261 uint16_t c_iflag
; /* input modes */
1262 uint16_t c_oflag
; /* output modes */
1263 uint16_t c_cflag
; /* control modes */
1264 uint16_t c_lflag
; /* line discipline modes */
1265 uint8_t c_line
; /* line discipline */
1266 uint8_t c_cc
[SOLARIS_NCC
]; /* control chars */
1269 STATIC_INLINE_EMUL_UNIX
void
1270 convert_to_solaris_termio(unsigned_word addr
,
1271 struct termio
*host
,
1275 struct solaris_termio target
;
1278 target
.c_iflag
= H2T_2 (host
->c_iflag
);
1279 target
.c_oflag
= H2T_2 (host
->c_oflag
);
1280 target
.c_cflag
= H2T_2 (host
->c_cflag
);
1281 target
.c_lflag
= H2T_2 (host
->c_lflag
);
1283 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
1284 target
.c_line
= host
->c_line
;
1289 for (i
= 0; i
< SOLARIS_NCC
; i
++)
1293 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1297 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1301 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1305 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1309 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1313 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1317 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1321 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1325 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1329 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1331 #endif /* HAVE_TERMIO_STRUCTURE || HAVE_TERMIOS_STRUCTURE */
1333 #ifdef HAVE_TERMIOS_STRUCTURE
1334 /* Convert to/from host termios structure */
1336 typedef uint32_t solaris_tcflag_t
;
1337 typedef uint8_t solaris_cc_t
;
1338 typedef uint32_t solaris_speed_t
;
1340 struct solaris_termios
{
1341 solaris_tcflag_t c_iflag
;
1342 solaris_tcflag_t c_oflag
;
1343 solaris_tcflag_t c_cflag
;
1344 solaris_tcflag_t c_lflag
;
1345 solaris_cc_t c_cc
[SOLARIS_NCCS
];
1348 STATIC_INLINE_EMUL_UNIX
void
1349 convert_to_solaris_termios(unsigned_word addr
,
1350 struct termios
*host
,
1354 struct solaris_termios target
;
1357 target
.c_iflag
= H2T_4 (host
->c_iflag
);
1358 target
.c_oflag
= H2T_4 (host
->c_oflag
);
1359 target
.c_cflag
= H2T_4 (host
->c_cflag
);
1360 target
.c_lflag
= H2T_4 (host
->c_lflag
);
1362 for (i
= 0; i
< SOLARIS_NCCS
; i
++)
1366 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1370 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1374 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1378 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1382 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1386 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1390 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1394 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1398 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1403 target
.c_cc
[SOLARIS_VSTART
] = host
->c_cc
[VSTART
];
1407 target
.c_cc
[SOLARIS_VSTOP
] = host
->c_cc
[VSTOP
];
1411 target
.c_cc
[SOLARIS_VSUSP
] = host
->c_cc
[VSUSP
];
1415 target
.c_cc
[SOLARIS_VDSUSP
] = host
->c_cc
[VDSUSP
];
1419 target
.c_cc
[SOLARIS_VREPRINT
] = host
->c_cc
[VREPRINT
];
1423 target
.c_cc
[SOLARIS_VDISCARD
] = host
->c_cc
[VDISCARD
];
1427 target
.c_cc
[SOLARIS_VWERASE
] = host
->c_cc
[VWERASE
];
1431 target
.c_cc
[SOLARIS_VLNEXT
] = host
->c_cc
[VLNEXT
];
1434 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1436 #endif /* HAVE_TERMIOS_STRUCTURE */
1439 #define do_solaris_ioctl 0
1442 do_solaris_ioctl(os_emul_data
*emul
,
1448 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
1449 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
1450 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
1452 const char *name
= "<unknown>";
1454 #ifdef HAVE_TERMIOS_STRUCTURE
1455 struct termios host_termio
;
1458 #ifdef HAVE_TERMIO_STRUCTURE
1459 struct termio host_termio
;
1463 status
= fdbad (fildes
);
1469 case 0: /* make sure we have at least one case */
1475 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1476 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
1477 case SOLARIS_TIOC
| 1: /* TCGETA */
1479 #ifdef HAVE_TCGETATTR
1480 status
= tcgetattr(fildes
, &host_termio
);
1481 #elif defined(TCGETS)
1482 status
= ioctl (fildes
, TCGETS
, &host_termio
);
1484 status
= ioctl (fildes
, TCGETA
, &host_termio
);
1487 convert_to_solaris_termio (argp_addr
, &host_termio
, processor
, cia
);
1490 #endif /* HAVE_TERMIO_STRUCTURE */
1492 #ifdef HAVE_TERMIOS_STRUCTURE
1493 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
1494 case SOLARIS_TIOC
| 13: /* TCGETS */
1496 #ifdef HAVE_TCGETATTR
1497 status
= tcgetattr(fildes
, &host_termio
);
1499 status
= ioctl (fildes
, TCGETS
, &host_termio
);
1502 convert_to_solaris_termios (argp_addr
, &host_termio
, processor
, cia
);
1505 #endif /* HAVE_TERMIOS_STRUCTURE */
1509 emul_write_status(processor
, status
, errno
);
1511 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1512 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
1514 #endif /* HAVE_IOCTL */
1516 static emul_syscall_descriptor solaris_descriptors
[] = {
1517 /* 0 */ { 0, "syscall" },
1518 /* 1 */ { do_unix_exit
, "exit" },
1519 /* 2 */ { 0, "fork" },
1520 /* 3 */ { do_unix_read
, "read" },
1521 /* 4 */ { do_unix_write
, "write" },
1522 /* 5 */ { do_unix_open
, "open" },
1523 /* 6 */ { do_unix_close
, "close" },
1524 /* 7 */ { 0, "wait" },
1525 /* 8 */ { 0, "creat" },
1526 /* 9 */ { do_unix_link
, "link" },
1527 /* 10 */ { do_unix_unlink
, "unlink" },
1528 /* 11 */ { 0, "exec" },
1529 /* 12 */ { do_unix_chdir
, "chdir" },
1530 /* 13 */ { do_unix_time
, "time" },
1531 /* 14 */ { 0, "mknod" },
1532 /* 15 */ { 0, "chmod" },
1533 /* 16 */ { 0, "chown" },
1534 /* 17 */ { do_unix_break
, "brk" },
1535 /* 18 */ { do_solaris_stat
, "stat" },
1536 /* 19 */ { do_unix_lseek
, "lseek" },
1537 /* 20 */ { do_unix_getpid2
, "getpid" },
1538 /* 21 */ { 0, "mount" },
1539 /* 22 */ { 0, "umount" },
1540 /* 23 */ { 0, "setuid" },
1541 /* 24 */ { do_unix_getuid2
, "getuid" },
1542 /* 25 */ { 0, "stime" },
1543 /* 26 */ { 0, "ptrace" },
1544 /* 27 */ { 0, "alarm" },
1545 /* 28 */ { do_solaris_fstat
, "fstat" },
1546 /* 29 */ { 0, "pause" },
1547 /* 30 */ { 0, "utime" },
1548 /* 31 */ { 0, "stty" },
1549 /* 32 */ { 0, "gtty" },
1550 /* 33 */ { do_unix_access
, "access" },
1551 /* 34 */ { 0, "nice" },
1552 /* 35 */ { 0, "statfs" },
1553 /* 36 */ { 0, "sync" },
1554 /* 37 */ { 0, "kill" },
1555 /* 38 */ { 0, "fstatfs" },
1556 /* 39 */ { 0, "pgrpsys" },
1557 /* 40 */ { 0, "xenix" },
1558 /* 41 */ { do_unix_dup
, "dup" },
1559 /* 42 */ { 0, "pipe" },
1560 /* 43 */ { 0, "times" },
1561 /* 44 */ { 0, "profil" },
1562 /* 45 */ { 0, "plock" },
1563 /* 46 */ { 0, "setgid" },
1564 /* 47 */ { do_unix_getgid2
, "getgid" },
1565 /* 48 */ { 0, "signal" },
1566 /* 49 */ { 0, "msgsys" },
1567 /* 50 */ { 0, "syssun" },
1568 /* 51 */ { 0, "acct" },
1569 /* 52 */ { 0, "shmsys" },
1570 /* 53 */ { 0, "semsys" },
1571 /* 54 */ { do_solaris_ioctl
, "ioctl" },
1572 /* 55 */ { 0, "uadmin" },
1573 /* 56 */ { 0, 0 /* reserved for exch */ },
1574 /* 57 */ { 0, "utssys" },
1575 /* 58 */ { 0, "fdsync" },
1576 /* 59 */ { 0, "execve" },
1577 /* 60 */ { do_unix_umask
, "umask" },
1578 /* 61 */ { 0, "chroot" },
1579 /* 62 */ { 0, "fcntl" },
1580 /* 63 */ { 0, "ulimit" },
1581 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1582 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1583 /* 65 */ { 0, 0 /* reserved for UNIX PC */ },
1584 /* 66 */ { 0, 0 /* reserved for UNIX PC */ },
1585 /* 67 */ { 0, 0 /* reserved for UNIX PC */ },
1586 /* 68 */ { 0, 0 /* reserved for UNIX PC */ },
1587 /* 69 */ { 0, 0 /* reserved for UNIX PC */ },
1588 /* 70 */ { 0, 0 /* was advfs */ },
1589 /* 71 */ { 0, 0 /* was unadvfs */ },
1590 /* 72 */ { 0, 0 /* was rmount */ },
1591 /* 73 */ { 0, 0 /* was rumount */ },
1592 /* 74 */ { 0, 0 /* was rfstart */ },
1593 /* 75 */ { 0, 0 /* was sigret */ },
1594 /* 76 */ { 0, 0 /* was rdebug */ },
1595 /* 77 */ { 0, 0 /* was rfstop */ },
1596 /* 78 */ { 0, 0 /* was rfsys */ },
1597 /* 79 */ { do_unix_rmdir
, "rmdir" },
1598 /* 80 */ { do_unix_mkdir
, "mkdir" },
1599 /* 81 */ { 0, "getdents" },
1600 /* 82 */ { 0, 0 /* was libattach */ },
1601 /* 83 */ { 0, 0 /* was libdetach */ },
1602 /* 84 */ { 0, "sysfs" },
1603 /* 85 */ { 0, "getmsg" },
1604 /* 86 */ { 0, "putmsg" },
1605 /* 87 */ { 0, "poll" },
1606 /* 88 */ { do_solaris_lstat
, "lstat" },
1607 /* 89 */ { do_unix_symlink
, "symlink" },
1608 /* 90 */ { 0, "readlink" },
1609 /* 91 */ { 0, "setgroups" },
1610 /* 92 */ { 0, "getgroups" },
1611 /* 93 */ { 0, "fchmod" },
1612 /* 94 */ { 0, "fchown" },
1613 /* 95 */ { 0, "sigprocmask" },
1614 /* 96 */ { 0, "sigsuspend" },
1615 /* 97 */ { do_unix_nop
, "sigaltstack" },
1616 /* 98 */ { do_unix_nop
, "sigaction" },
1617 /* 99 */ { 0, "sigpending" },
1618 /* 100 */ { 0, "context" },
1619 /* 101 */ { 0, "evsys" },
1620 /* 102 */ { 0, "evtrapret" },
1621 /* 103 */ { 0, "statvfs" },
1622 /* 104 */ { 0, "fstatvfs" },
1623 /* 105 */ { 0, 0 /* reserved */ },
1624 /* 106 */ { 0, "nfssys" },
1625 /* 107 */ { 0, "waitsys" },
1626 /* 108 */ { 0, "sigsendsys" },
1627 /* 109 */ { 0, "hrtsys" },
1628 /* 110 */ { 0, "acancel" },
1629 /* 111 */ { 0, "async" },
1630 /* 112 */ { 0, "priocntlsys" },
1631 /* 113 */ { 0, "pathconf" },
1632 /* 114 */ { 0, "mincore" },
1633 /* 115 */ { 0, "mmap" },
1634 /* 116 */ { 0, "mprotect" },
1635 /* 117 */ { 0, "munmap" },
1636 /* 118 */ { 0, "fpathconf" },
1637 /* 119 */ { 0, "vfork" },
1638 /* 120 */ { 0, "fchdir" },
1639 /* 121 */ { 0, "readv" },
1640 /* 122 */ { 0, "writev" },
1641 /* 123 */ { 0, "xstat" },
1642 /* 124 */ { 0, "lxstat" },
1643 /* 125 */ { 0, "fxstat" },
1644 /* 126 */ { 0, "xmknod" },
1645 /* 127 */ { 0, "clocal" },
1646 /* 128 */ { 0, "setrlimit" },
1647 /* 129 */ { 0, "getrlimit" },
1648 /* 130 */ { 0, "lchown" },
1649 /* 131 */ { 0, "memcntl" },
1650 /* 132 */ { 0, "getpmsg" },
1651 /* 133 */ { 0, "putpmsg" },
1652 /* 134 */ { 0, "rename" },
1653 /* 135 */ { 0, "uname" },
1654 /* 136 */ { 0, "setegid" },
1655 /* 137 */ { 0, "sysconfig" },
1656 /* 138 */ { 0, "adjtime" },
1657 /* 139 */ { 0, "systeminfo" },
1658 /* 140 */ { 0, 0 /* reserved */ },
1659 /* 141 */ { 0, "seteuid" },
1660 /* 142 */ { 0, "vtrace" },
1661 /* 143 */ { 0, "fork1" },
1662 /* 144 */ { 0, "sigtimedwait" },
1663 /* 145 */ { 0, "lwp_info" },
1664 /* 146 */ { 0, "yield" },
1665 /* 147 */ { 0, "lwp_sema_wait" },
1666 /* 148 */ { 0, "lwp_sema_post" },
1667 /* 149 */ { 0, 0 /* reserved */ },
1668 /* 150 */ { 0, 0 /* reserved */ },
1669 /* 151 */ { 0, 0 /* reserved */ },
1670 /* 152 */ { 0, "modctl" },
1671 /* 153 */ { 0, "fchroot" },
1672 /* 154 */ { 0, "utimes" },
1673 /* 155 */ { 0, "vhangup" },
1674 /* 156 */ { do_unix_gettimeofday
, "gettimeofday" },
1675 /* 157 */ { 0, "getitimer" },
1676 /* 158 */ { 0, "setitimer" },
1677 /* 159 */ { 0, "lwp_create" },
1678 /* 160 */ { 0, "lwp_exit" },
1679 /* 161 */ { 0, "lwp_suspend" },
1680 /* 162 */ { 0, "lwp_continue" },
1681 /* 163 */ { 0, "lwp_kill" },
1682 /* 164 */ { 0, "lwp_self" },
1683 /* 165 */ { 0, "lwp_setprivate" },
1684 /* 166 */ { 0, "lwp_getprivate" },
1685 /* 167 */ { 0, "lwp_wait" },
1686 /* 168 */ { 0, "lwp_mutex_unlock" },
1687 /* 169 */ { 0, "lwp_mutex_lock" },
1688 /* 170 */ { 0, "lwp_cond_wait" },
1689 /* 171 */ { 0, "lwp_cond_signal" },
1690 /* 172 */ { 0, "lwp_cond_broadcast" },
1691 /* 173 */ { 0, "pread" },
1692 /* 174 */ { 0, "pwrite" },
1693 /* 175 */ { 0, "llseek" },
1694 /* 176 */ { 0, "inst_sync" },
1695 /* 177 */ { 0, 0 /* reserved */ },
1696 /* 178 */ { 0, "kaio" },
1697 /* 179 */ { 0, 0 /* reserved */ },
1698 /* 180 */ { 0, 0 /* reserved */ },
1699 /* 181 */ { 0, 0 /* reserved */ },
1700 /* 182 */ { 0, 0 /* reserved */ },
1701 /* 183 */ { 0, 0 /* reserved */ },
1702 /* 184 */ { 0, "tsolsys" },
1703 /* 185 */ { 0, "acl" },
1704 /* 186 */ { 0, "auditsys" },
1705 /* 187 */ { 0, "processor_bind" },
1706 /* 188 */ { 0, "processor_info" },
1707 /* 189 */ { 0, "p_online" },
1708 /* 190 */ { 0, "sigqueue" },
1709 /* 191 */ { 0, "clock_gettime" },
1710 /* 192 */ { 0, "clock_settime" },
1711 /* 193 */ { 0, "clock_getres" },
1712 /* 194 */ { 0, "timer_create" },
1713 /* 195 */ { 0, "timer_delete" },
1714 /* 196 */ { 0, "timer_settime" },
1715 /* 197 */ { 0, "timer_gettime" },
1716 /* 198 */ { 0, "timer_getoverrun" },
1717 /* 199 */ { 0, "nanosleep" },
1718 /* 200 */ { 0, "facl" },
1719 /* 201 */ { 0, "door" },
1720 /* 202 */ { 0, "setreuid" },
1721 /* 203 */ { 0, "setregid" },
1722 /* 204 */ { 0, "install_utrap" },
1723 /* 205 */ { 0, 0 /* reserved */ },
1724 /* 206 */ { 0, 0 /* reserved */ },
1725 /* 207 */ { 0, 0 /* reserved */ },
1726 /* 208 */ { 0, 0 /* reserved */ },
1727 /* 209 */ { 0, 0 /* reserved */ },
1728 /* 210 */ { 0, "signotifywait" },
1729 /* 211 */ { 0, "lwp_sigredirect" },
1730 /* 212 */ { 0, "lwp_alarm" },
1733 static char *(solaris_error_names
[]) = {
1772 /* 38 */ "EL2NSYNC",
1781 /* 47 */ "ECANCELED",
1790 /* 56 */ "EDEADLOCK",
1792 /* 58 */ "Error code 58",
1793 /* 59 */ "Error code 59",
1806 /* 72 */ "Error code 72",
1807 /* 73 */ "Error code 73",
1808 /* 74 */ "EMULTIHOP",
1809 /* 75 */ "Error code 75",
1810 /* 76 */ "Error code 76",
1812 /* 78 */ "ENAMETOOLONG",
1813 /* 79 */ "EOVERFLOW",
1814 /* 80 */ "ENOTUNIQ",
1821 /* 87 */ "ELIBEXEC",
1825 /* 91 */ "ERESTART",
1826 /* 92 */ "ESTRPIPE",
1827 /* 93 */ "ENOTEMPTY",
1829 /* 95 */ "ENOTSOCK",
1830 /* 96 */ "EDESTADDRREQ",
1831 /* 97 */ "EMSGSIZE",
1832 /* 98 */ "EPROTOTYPE",
1833 /* 99 */ "ENOPROTOOPT",
1834 /* 100 */ "Error code 100",
1835 /* 101 */ "Error code 101",
1836 /* 102 */ "Error code 102",
1837 /* 103 */ "Error code 103",
1838 /* 104 */ "Error code 104",
1839 /* 105 */ "Error code 105",
1840 /* 106 */ "Error code 106",
1841 /* 107 */ "Error code 107",
1842 /* 108 */ "Error code 108",
1843 /* 109 */ "Error code 109",
1844 /* 110 */ "Error code 110",
1845 /* 111 */ "Error code 111",
1846 /* 112 */ "Error code 112",
1847 /* 113 */ "Error code 113",
1848 /* 114 */ "Error code 114",
1849 /* 115 */ "Error code 115",
1850 /* 116 */ "Error code 116",
1851 /* 117 */ "Error code 117",
1852 /* 118 */ "Error code 118",
1853 /* 119 */ "Error code 119",
1854 /* 120 */ "EPROTONOSUPPORT",
1855 /* 121 */ "ESOCKTNOSUPPORT",
1856 /* 122 */ "EOPNOTSUPP",
1857 /* 123 */ "EPFNOSUPPORT",
1858 /* 124 */ "EAFNOSUPPORT",
1859 /* 125 */ "EADDRINUSE",
1860 /* 126 */ "EADDRNOTAVAIL",
1861 /* 127 */ "ENETDOWN",
1862 /* 128 */ "ENETUNREACH",
1863 /* 129 */ "ENETRESET",
1864 /* 130 */ "ECONNABORTED",
1865 /* 131 */ "ECONNRESET",
1866 /* 132 */ "ENOBUFS",
1867 /* 133 */ "EISCONN",
1868 /* 134 */ "ENOTCONN",
1869 /* 135 */ "Error code 135", /* XENIX has 135 - 142 */
1870 /* 136 */ "Error code 136",
1871 /* 137 */ "Error code 137",
1872 /* 138 */ "Error code 138",
1873 /* 139 */ "Error code 139",
1874 /* 140 */ "Error code 140",
1875 /* 141 */ "Error code 141",
1876 /* 142 */ "Error code 142",
1877 /* 143 */ "ESHUTDOWN",
1878 /* 144 */ "ETOOMANYREFS",
1879 /* 145 */ "ETIMEDOUT",
1880 /* 146 */ "ECONNREFUSED",
1881 /* 147 */ "EHOSTDOWN",
1882 /* 148 */ "EHOSTUNREACH",
1883 /* 149 */ "EALREADY",
1884 /* 150 */ "EINPROGRESS",
1888 static char *(solaris_signal_names
[]) = {
1909 /* 20 */ "SIGWINCH",
1917 /* 28 */ "SIGVTALRM",
1921 /* 32 */ "SIGWAITING",
1923 /* 34 */ "SIGFREEZE",
1925 /* 36 */ "SIGCANCEL",
1928 static emul_syscall emul_solaris_syscalls
= {
1929 solaris_descriptors
,
1930 ARRAY_SIZE (solaris_descriptors
),
1931 solaris_error_names
,
1932 ARRAY_SIZE (solaris_error_names
),
1933 solaris_signal_names
,
1934 ARRAY_SIZE (solaris_signal_names
),
1938 /* Solaris's os_emul interface, most are just passed on to the generic
1941 static os_emul_data
*
1942 emul_solaris_create(device
*root
,
1946 /* check that this emulation is really for us */
1947 if (name
!= NULL
&& strcmp(name
, "solaris") != 0)
1953 return emul_unix_create(root
, image
, "solaris", &emul_solaris_syscalls
);
1957 emul_solaris_init(os_emul_data
*emul_data
,
1966 emul_solaris_system_call(cpu
*processor
,
1968 os_emul_data
*emul_data
)
1970 emul_do_system_call(emul_data
,
1971 emul_data
->syscalls
,
1972 cpu_registers(processor
)->gpr
[0],
1973 3, /*r3 contains arg0*/
1978 const os_emul emul_solaris
= {
1980 emul_solaris_create
,
1982 emul_solaris_system_call
,
1983 0, /*instruction_call*/
1990 Linux - Emulation of user programs for Linux/PPC
1997 /* Linux specific implementation */
1999 typedef uint32_t linux_dev_t
;
2000 typedef uint32_t linux_ino_t
;
2001 typedef uint32_t linux_mode_t
;
2002 typedef uint16_t linux_nlink_t
;
2003 typedef int32_t linux_off_t
;
2004 typedef int32_t linux_pid_t
;
2005 typedef uint32_t linux_uid_t
;
2006 typedef uint32_t linux_gid_t
;
2007 typedef uint32_t linux_size_t
;
2008 typedef int32_t linux_ssize_t
;
2009 typedef int32_t linux_ptrdiff_t
;
2010 typedef int32_t linux_time_t
;
2011 typedef int32_t linux_clock_t
;
2012 typedef int32_t linux_daddr_t
;
2014 #ifdef HAVE_SYS_STAT_H
2015 /* For the PowerPC, don't both with the 'old' stat structure, since there
2016 should be no extant binaries with that structure. */
2021 linux_mode_t st_mode
;
2022 linux_nlink_t st_nlink
;
2025 linux_dev_t st_rdev
;
2026 linux_off_t st_size
;
2027 uint32_t st_blksize
;
2029 uint32_t st_atimx
; /* don't use st_{a,c,m}time, that might a macro */
2030 uint32_t __unused1
; /* defined by the host's stat.h */
2039 /* Convert from host stat structure to solaris stat structure */
2040 STATIC_INLINE_EMUL_UNIX
void
2041 convert_to_linux_stat(unsigned_word addr
,
2046 struct linux_stat target
;
2048 target
.st_dev
= H2T_4(host
->st_dev
);
2049 target
.st_ino
= H2T_4(host
->st_ino
);
2050 target
.st_mode
= H2T_4(host
->st_mode
);
2051 target
.st_nlink
= H2T_2(host
->st_nlink
);
2052 target
.st_uid
= H2T_4(host
->st_uid
);
2053 target
.st_gid
= H2T_4(host
->st_gid
);
2054 target
.st_size
= H2T_4(host
->st_size
);
2057 target
.st_rdev
= H2T_4(host
->st_rdev
);
2062 #ifdef HAVE_ST_BLKSIZE
2063 target
.st_blksize
= H2T_4(host
->st_blksize
);
2065 target
.st_blksize
= 0;
2068 #ifdef HAVE_ST_BLOCKS
2069 target
.st_blocks
= H2T_4(host
->st_blocks
);
2071 target
.st_blocks
= 0;
2074 target
.st_atimx
= H2T_4(host
->st_atime
);
2075 target
.st_ctimx
= H2T_4(host
->st_ctime
);
2076 target
.st_mtimx
= H2T_4(host
->st_mtime
);
2077 target
.__unused1
= 0;
2078 target
.__unused2
= 0;
2079 target
.__unused3
= 0;
2080 target
.__unused4
= 0;
2081 target
.__unused5
= 0;
2083 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2085 #endif /* HAVE_SYS_STAT_H */
2088 #define do_linux_stat 0
2091 do_linux_stat(os_emul_data
*emul
,
2097 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
2098 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2099 char path_buf
[PATH_MAX
];
2101 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
2104 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2105 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2107 status
= stat (path
, &buf
);
2109 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2111 emul_write_status(processor
, status
, errno
);
2116 #define do_linux_lstat 0
2119 do_linux_lstat(os_emul_data
*emul
,
2125 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
2126 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2127 char path_buf
[PATH_MAX
];
2129 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
2132 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2133 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2135 status
= lstat (path
, &buf
);
2137 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2139 emul_write_status(processor
, status
, errno
);
2144 #define do_linux_fstat 0
2147 do_linux_fstat(os_emul_data
*emul
,
2153 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
2154 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2158 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2159 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
2161 status
= fdbad (fildes
);
2163 status
= fstat (fildes
, &buf
);
2165 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2167 emul_write_status(processor
, status
, errno
);
2171 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2172 #define LINUX_NCC 10
2173 #define LINUX_NCCS 19
2175 #define LINUX_VINTR 0
2176 #define LINUX_VQUIT 1
2177 #define LINUX_VERASE 2
2178 #define LINUX_VKILL 3
2179 #define LINUX_VEOF 4
2180 #define LINUX_VMIN 5
2181 #define LINUX_VEOL 6
2182 #define LINUX_VTIME 7
2183 #define LINUX_VEOL2 8
2184 #define LINUX_VSWTC 9
2185 #define LINUX_VWERASE 10
2186 #define LINUX_VREPRINT 11
2187 #define LINUX_VSUSP 12
2188 #define LINUX_VSTART 13
2189 #define LINUX_VSTOP 14
2190 #define LINUX_VLNEXT 15
2191 #define LINUX_VDISCARD 16
2193 #define LINUX_IOC_NRBITS 8
2194 #define LINUX_IOC_TYPEBITS 8
2195 #define LINUX_IOC_SIZEBITS 13
2196 #define LINUX_IOC_DIRBITS 3
2198 #define LINUX_IOC_NRMASK ((1 << LINUX_IOC_NRBITS)-1)
2199 #define LINUX_IOC_TYPEMASK ((1 << LINUX_IOC_TYPEBITS)-1)
2200 #define LINUX_IOC_SIZEMASK ((1 << LINUX_IOC_SIZEBITS)-1)
2201 #define LINUX_IOC_DIRMASK ((1 << LINUX_IOC_DIRBITS)-1)
2203 #define LINUX_IOC_NRSHIFT 0
2204 #define LINUX_IOC_TYPESHIFT (LINUX_IOC_NRSHIFT+LINUX_IOC_NRBITS)
2205 #define LINUX_IOC_SIZESHIFT (LINUX_IOC_TYPESHIFT+LINUX_IOC_TYPEBITS)
2206 #define LINUX_IOC_DIRSHIFT (LINUX_IOC_SIZESHIFT+LINUX_IOC_SIZEBITS)
2209 * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
2210 * And this turns out useful to catch old ioctl numbers in header
2213 #define LINUX_IOC_NONE 1U
2214 #define LINUX_IOC_READ 2U
2215 #define LINUX_IOC_WRITE 4U
2217 #define LINUX_IOC(dir,type,nr,size) \
2218 (((dir) << LINUX_IOC_DIRSHIFT) | \
2219 ((type) << LINUX_IOC_TYPESHIFT) | \
2220 ((nr) << LINUX_IOC_NRSHIFT) | \
2221 ((size) << LINUX_IOC_SIZESHIFT))
2223 /* used to create numbers */
2224 #define LINUX_IO(type,nr) LINUX_IOC(LINUX_IOC_NONE,(type),(nr),0)
2225 #define LINUX_IOR(type,nr,size) LINUX_IOC(LINUX_IOC_READ,(type),(nr),sizeof(size))
2226 #define LINUX_IOW(type,nr,size) LINUX_IOC(LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2227 #define LINUX_IOWR(type,nr,size) LINUX_IOC(LINUX_IOC_READ|LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2230 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2231 /* Convert to/from host termio structure */
2233 struct linux_termio
{
2234 uint16_t c_iflag
; /* input modes */
2235 uint16_t c_oflag
; /* output modes */
2236 uint16_t c_cflag
; /* control modes */
2237 uint16_t c_lflag
; /* line discipline modes */
2238 uint8_t c_line
; /* line discipline */
2239 uint8_t c_cc
[LINUX_NCC
]; /* control chars */
2242 STATIC_INLINE_EMUL_UNIX
void
2243 convert_to_linux_termio(unsigned_word addr
,
2244 struct termio
*host
,
2248 struct linux_termio target
;
2251 target
.c_iflag
= H2T_2 (host
->c_iflag
);
2252 target
.c_oflag
= H2T_2 (host
->c_oflag
);
2253 target
.c_cflag
= H2T_2 (host
->c_cflag
);
2254 target
.c_lflag
= H2T_2 (host
->c_lflag
);
2256 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
2257 target
.c_line
= host
->c_line
;
2262 for (i
= 0; i
< LINUX_NCC
; i
++)
2266 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2270 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2274 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2278 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2282 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2286 target
.c_cc
[LINUX_VMIN
] = host
->c_cc
[VMIN
];
2290 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2294 target
.c_cc
[LINUX_VTIME
] = host
->c_cc
[VTIME
];
2298 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2302 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTC
];
2306 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2309 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2311 #endif /* HAVE_TERMIO_STRUCTURE */
2313 #ifdef HAVE_TERMIOS_STRUCTURE
2314 /* Convert to/from host termios structure */
2316 typedef uint32_t linux_tcflag_t
;
2317 typedef uint8_t linux_cc_t
;
2318 typedef uint32_t linux_speed_t
;
2320 struct linux_termios
{
2321 linux_tcflag_t c_iflag
;
2322 linux_tcflag_t c_oflag
;
2323 linux_tcflag_t c_cflag
;
2324 linux_tcflag_t c_lflag
;
2325 linux_cc_t c_cc
[LINUX_NCCS
];
2331 STATIC_INLINE_EMUL_UNIX
void
2332 convert_to_linux_termios(unsigned_word addr
,
2333 struct termios
*host
,
2337 struct linux_termios target
;
2340 target
.c_iflag
= H2T_4 (host
->c_iflag
);
2341 target
.c_oflag
= H2T_4 (host
->c_oflag
);
2342 target
.c_cflag
= H2T_4 (host
->c_cflag
);
2343 target
.c_lflag
= H2T_4 (host
->c_lflag
);
2345 for (i
= 0; i
< LINUX_NCCS
; i
++)
2349 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2353 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2357 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2361 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2365 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2369 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2373 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2377 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2380 #ifdef HAVE_TERMIOS_CLINE
2381 target
.c_line
= host
->c_line
;
2386 #ifdef HAVE_CFGETISPEED
2387 target
.c_ispeed
= cfgetispeed (host
);
2389 target
.c_ispeed
= 0;
2392 #ifdef HAVE_CFGETOSPEED
2393 target
.c_ospeed
= cfgetospeed (host
);
2395 target
.c_ospeed
= 0;
2398 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2400 #endif /* HAVE_TERMIOS_STRUCTURE */
2403 #define do_linux_ioctl 0
2406 do_linux_ioctl(os_emul_data
*emul
,
2412 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
2413 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
2414 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
2416 const char *name
= "<unknown>";
2418 #ifdef HAVE_TERMIOS_STRUCTURE
2419 struct termios host_termio
;
2422 #ifdef HAVE_TERMIO_STRUCTURE
2423 struct termio host_termio
;
2427 status
= fdbad (fildes
);
2433 case 0: /* make sure we have at least one case */
2439 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2440 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
2441 case LINUX_IOR('t', 23, struct linux_termio
): /* TCGETA */
2443 #ifdef HAVE_TCGETATTR
2444 status
= tcgetattr(fildes
, &host_termio
);
2445 #elif defined(TCGETS)
2446 status
= ioctl (fildes
, TCGETS
, &host_termio
);
2448 status
= ioctl (fildes
, TCGETA
, &host_termio
);
2451 convert_to_linux_termio (argp_addr
, &host_termio
, processor
, cia
);
2454 #endif /* HAVE_TERMIO_STRUCTURE */
2456 #ifdef HAVE_TERMIOS_STRUCTURE
2457 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
2458 case LINUX_IOR('t', 19, struct linux_termios
): /* TCGETS */
2460 #ifdef HAVE_TCGETATTR
2461 status
= tcgetattr(fildes
, &host_termio
);
2463 status
= ioctl (fildes
, TCGETS
, &host_termio
);
2466 convert_to_linux_termios (argp_addr
, &host_termio
, processor
, cia
);
2469 #endif /* HAVE_TERMIOS_STRUCTURE */
2473 emul_write_status(processor
, status
, errno
);
2475 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2476 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
2478 #endif /* HAVE_IOCTL */
2480 static emul_syscall_descriptor linux_descriptors
[] = {
2481 /* 0 */ { 0, "setup" },
2482 /* 1 */ { do_unix_exit
, "exit" },
2483 /* 2 */ { 0, "fork" },
2484 /* 3 */ { do_unix_read
, "read" },
2485 /* 4 */ { do_unix_write
, "write" },
2486 /* 5 */ { do_unix_open
, "open" },
2487 /* 6 */ { do_unix_close
, "close" },
2488 /* 7 */ { 0, "waitpid" },
2489 /* 8 */ { 0, "creat" },
2490 /* 9 */ { do_unix_link
, "link" },
2491 /* 10 */ { do_unix_unlink
, "unlink" },
2492 /* 11 */ { 0, "execve" },
2493 /* 12 */ { do_unix_chdir
, "chdir" },
2494 /* 13 */ { do_unix_time
, "time" },
2495 /* 14 */ { 0, "mknod" },
2496 /* 15 */ { 0, "chmod" },
2497 /* 16 */ { 0, "chown" },
2498 /* 17 */ { 0, "break" },
2499 /* 18 */ { 0, "stat" },
2500 /* 19 */ { do_unix_lseek
, "lseek" },
2501 /* 20 */ { do_unix_getpid
, "getpid" },
2502 /* 21 */ { 0, "mount" },
2503 /* 22 */ { 0, "umount" },
2504 /* 23 */ { 0, "setuid" },
2505 /* 24 */ { do_unix_getuid
, "getuid" },
2506 /* 25 */ { 0, "stime" },
2507 /* 26 */ { 0, "ptrace" },
2508 /* 27 */ { 0, "alarm" },
2509 /* 28 */ { 0, "fstat" },
2510 /* 29 */ { 0, "pause" },
2511 /* 30 */ { 0, "utime" },
2512 /* 31 */ { 0, "stty" },
2513 /* 32 */ { 0, "gtty" },
2514 /* 33 */ { do_unix_access
, "access" },
2515 /* 34 */ { 0, "nice" },
2516 /* 35 */ { 0, "ftime" },
2517 /* 36 */ { 0, "sync" },
2518 /* 37 */ { 0, "kill" },
2519 /* 38 */ { 0, "rename" },
2520 /* 39 */ { do_unix_mkdir
, "mkdir" },
2521 /* 40 */ { do_unix_rmdir
, "rmdir" },
2522 /* 41 */ { do_unix_dup
, "dup" },
2523 /* 42 */ { 0, "pipe" },
2524 /* 43 */ { 0, "times" },
2525 /* 44 */ { 0, "prof" },
2526 /* 45 */ { do_unix_break
, "brk" },
2527 /* 46 */ { 0, "setgid" },
2528 /* 47 */ { do_unix_getgid
, "getgid" },
2529 /* 48 */ { 0, "signal" },
2530 /* 49 */ { do_unix_geteuid
, "geteuid" },
2531 /* 50 */ { do_unix_getegid
, "getegid" },
2532 /* 51 */ { 0, "acct" },
2533 /* 52 */ { 0, "phys" },
2534 /* 53 */ { 0, "lock" },
2535 /* 54 */ { do_linux_ioctl
, "ioctl" },
2536 /* 55 */ { 0, "fcntl" },
2537 /* 56 */ { 0, "mpx" },
2538 /* 57 */ { 0, "setpgid" },
2539 /* 58 */ { 0, "ulimit" },
2540 /* 59 */ { 0, "olduname" },
2541 /* 60 */ { do_unix_umask
, "umask" },
2542 /* 61 */ { 0, "chroot" },
2543 /* 62 */ { 0, "ustat" },
2544 /* 63 */ { do_unix_dup2
, "dup2" },
2545 /* 64 */ { do_unix_getppid
, "getppid" },
2546 /* 65 */ { 0, "getpgrp" },
2547 /* 66 */ { 0, "setsid" },
2548 /* 67 */ { 0, "sigaction" },
2549 /* 68 */ { 0, "sgetmask" },
2550 /* 69 */ { 0, "ssetmask" },
2551 /* 70 */ { 0, "setreuid" },
2552 /* 71 */ { 0, "setregid" },
2553 /* 72 */ { 0, "sigsuspend" },
2554 /* 73 */ { 0, "sigpending" },
2555 /* 74 */ { 0, "sethostname" },
2556 /* 75 */ { 0, "setrlimit" },
2557 /* 76 */ { 0, "getrlimit" },
2558 /* 77 */ { do_unix_getrusage
, "getrusage" },
2559 /* 78 */ { do_unix_gettimeofday
, "gettimeofday" },
2560 /* 79 */ { 0, "settimeofday" },
2561 /* 80 */ { 0, "getgroups" },
2562 /* 81 */ { 0, "setgroups" },
2563 /* 82 */ { 0, "select" },
2564 /* 83 */ { do_unix_symlink
, "symlink" },
2565 /* 84 */ { 0, "lstat" },
2566 /* 85 */ { 0, "readlink" },
2567 /* 86 */ { 0, "uselib" },
2568 /* 87 */ { 0, "swapon" },
2569 /* 88 */ { 0, "reboot" },
2570 /* 89 */ { 0, "readdir" },
2571 /* 90 */ { 0, "mmap" },
2572 /* 91 */ { 0, "munmap" },
2573 /* 92 */ { 0, "truncate" },
2574 /* 93 */ { 0, "ftruncate" },
2575 /* 94 */ { 0, "fchmod" },
2576 /* 95 */ { 0, "fchown" },
2577 /* 96 */ { 0, "getpriority" },
2578 /* 97 */ { 0, "setpriority" },
2579 /* 98 */ { 0, "profil" },
2580 /* 99 */ { 0, "statfs" },
2581 /* 100 */ { 0, "fstatfs" },
2582 /* 101 */ { 0, "ioperm" },
2583 /* 102 */ { 0, "socketcall" },
2584 /* 103 */ { 0, "syslog" },
2585 /* 104 */ { 0, "setitimer" },
2586 /* 105 */ { 0, "getitimer" },
2587 /* 106 */ { do_linux_stat
, "newstat" },
2588 /* 107 */ { do_linux_lstat
, "newlstat" },
2589 /* 108 */ { do_linux_fstat
, "newfstat" },
2590 /* 109 */ { 0, "uname" },
2591 /* 110 */ { 0, "iopl" },
2592 /* 111 */ { 0, "vhangup" },
2593 /* 112 */ { 0, "idle" },
2594 /* 113 */ { 0, "vm86" },
2595 /* 114 */ { 0, "wait4" },
2596 /* 115 */ { 0, "swapoff" },
2597 /* 116 */ { 0, "sysinfo" },
2598 /* 117 */ { 0, "ipc" },
2599 /* 118 */ { 0, "fsync" },
2600 /* 119 */ { 0, "sigreturn" },
2601 /* 120 */ { 0, "clone" },
2602 /* 121 */ { 0, "setdomainname" },
2603 /* 122 */ { 0, "newuname" },
2604 /* 123 */ { 0, "modify_ldt" },
2605 /* 124 */ { 0, "adjtimex" },
2606 /* 125 */ { 0, "mprotect" },
2607 /* 126 */ { 0, "sigprocmask" },
2608 /* 127 */ { 0, "create_module" },
2609 /* 128 */ { 0, "init_module" },
2610 /* 129 */ { 0, "delete_module" },
2611 /* 130 */ { 0, "get_kernel_syms" },
2612 /* 131 */ { 0, "quotactl" },
2613 /* 132 */ { 0, "getpgid" },
2614 /* 133 */ { 0, "fchdir" },
2615 /* 134 */ { 0, "bdflush" },
2616 /* 135 */ { 0, "sysfs" },
2617 /* 136 */ { 0, "personality" },
2618 /* 137 */ { 0, "afs_syscall" },
2619 /* 138 */ { 0, "setfsuid" },
2620 /* 139 */ { 0, "setfsgid" },
2621 /* 140 */ { 0, "llseek" },
2622 /* 141 */ { 0, "getdents" },
2623 /* 142 */ { 0, "newselect" },
2624 /* 143 */ { 0, "flock" },
2625 /* 144 */ { 0, "msync" },
2626 /* 145 */ { 0, "readv" },
2627 /* 146 */ { 0, "writev" },
2628 /* 147 */ { 0, "getsid" },
2629 /* 148 */ { 0, "fdatasync" },
2630 /* 149 */ { 0, "sysctl" },
2631 /* 150 */ { 0, "mlock" },
2632 /* 151 */ { 0, "munlock" },
2633 /* 152 */ { 0, "mlockall" },
2634 /* 153 */ { 0, "munlockall" },
2635 /* 154 */ { 0, "sched_setparam" },
2636 /* 155 */ { 0, "sched_getparam" },
2637 /* 156 */ { 0, "sched_setscheduler" },
2638 /* 157 */ { 0, "sched_getscheduler" },
2639 /* 158 */ { 0, "sched_yield" },
2640 /* 159 */ { 0, "sched_get_priority_max" },
2641 /* 160 */ { 0, "sched_get_priority_min" },
2642 /* 161 */ { 0, "sched_rr_get_interval" },
2645 static char *(linux_error_names
[]) = {
2682 /* 36 */ "ENAMETOOLONG",
2685 /* 39 */ "ENOTEMPTY",
2691 /* 45 */ "EL2NSYNC",
2704 /* 58 */ "EDEADLOCK",
2718 /* 72 */ "EMULTIHOP",
2721 /* 75 */ "EOVERFLOW",
2722 /* 76 */ "ENOTUNIQ",
2729 /* 83 */ "ELIBEXEC",
2731 /* 85 */ "ERESTART",
2732 /* 86 */ "ESTRPIPE",
2734 /* 88 */ "ENOTSOCK",
2735 /* 89 */ "EDESTADDRREQ",
2736 /* 90 */ "EMSGSIZE",
2737 /* 91 */ "EPROTOTYPE",
2738 /* 92 */ "ENOPROTOOPT",
2739 /* 93 */ "EPROTONOSUPPORT",
2740 /* 94 */ "ESOCKTNOSUPPORT",
2741 /* 95 */ "EOPNOTSUPP",
2742 /* 96 */ "EPFNOSUPPORT",
2743 /* 97 */ "EAFNOSUPPORT",
2744 /* 98 */ "EADDRINUSE",
2745 /* 99 */ "EADDRNOTAVAIL",
2746 /* 100 */ "ENETDOWN",
2747 /* 101 */ "ENETUNREACH",
2748 /* 102 */ "ENETRESET",
2749 /* 103 */ "ECONNABORTED",
2750 /* 104 */ "ECONNRESET",
2751 /* 105 */ "ENOBUFS",
2752 /* 106 */ "EISCONN",
2753 /* 107 */ "ENOTCONN",
2754 /* 108 */ "ESHUTDOWN",
2755 /* 109 */ "ETOOMANYREFS",
2756 /* 110 */ "ETIMEDOUT",
2757 /* 111 */ "ECONNREFUSED",
2758 /* 112 */ "EHOSTDOWN",
2759 /* 113 */ "EHOSTUNREACH",
2760 /* 114 */ "EALREADY",
2761 /* 115 */ "EINPROGRESS",
2763 /* 117 */ "EUCLEAN",
2764 /* 118 */ "ENOTNAM",
2765 /* 119 */ "ENAVAIL",
2767 /* 121 */ "EREMOTEIO",
2771 static char *(linux_signal_names
[]) = {
2789 /* 16 */ "SIGSTKFLT",
2799 /* 26 */ "SIGVTALRM",
2801 /* 28 */ "SIGWINCH",
2804 /* 31 */ "SIGUNUSED",
2807 static emul_syscall emul_linux_syscalls
= {
2809 ARRAY_SIZE (linux_descriptors
),
2811 ARRAY_SIZE (linux_error_names
),
2813 ARRAY_SIZE (linux_signal_names
),
2817 /* Linux's os_emul interface, most are just passed on to the generic
2820 static os_emul_data
*
2821 emul_linux_create(device
*root
,
2825 /* check that this emulation is really for us */
2826 if (name
!= NULL
&& strcmp(name
, "linux") != 0)
2832 return emul_unix_create(root
, image
, "linux", &emul_linux_syscalls
);
2836 emul_linux_init(os_emul_data
*emul_data
,
2845 emul_linux_system_call(cpu
*processor
,
2847 os_emul_data
*emul_data
)
2849 emul_do_system_call(emul_data
,
2850 emul_data
->syscalls
,
2851 cpu_registers(processor
)->gpr
[0],
2852 3, /*r3 contains arg0*/
2857 const os_emul emul_linux
= {
2861 emul_linux_system_call
,
2862 0, /*instruction_call*/
2866 #endif /* _EMUL_UNIX_C_ */