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>
56 #ifdef HAVE_SYS_TIME_H
60 #ifndef HAVE_TERMIOS_STRUCTURE
61 #undef HAVE_SYS_TERMIOS_H
64 #ifndef HAVE_SYS_TERMIOS_H
65 #undef HAVE_TERMIOS_STRUCTURE
69 #ifdef HAVE_TERMIOS_STRUCTURE
70 #include <sys/termios.h>
72 /* If we have TERMIOS, use that for the termio structure, since some systems
73 don't like including both sys/termios.h and sys/termio.h at the same
75 #undef HAVE_TERMIO_STRUCTURE
78 #define termio termios
81 #ifndef HAVE_TERMIO_STRUCTURE
82 #undef HAVE_SYS_TERMIO_H
84 #ifndef HAVE_SYS_TERMIO_H
85 #undef HAVE_TERMIO_STRUCTURE
89 #ifdef HAVE_TERMIO_STRUCTURE
90 #include <sys/termio.h>
94 #ifndef HAVE_SYS_RESOURCE_H
100 #include <sys/resource.h>
106 # define NAMLEN(dirent) strlen((dirent)->d_name)
108 # define dirent direct
109 # define NAMLEN(dirent) (dirent)->d_namlen
111 # include <sys/ndir.h>
114 # include <sys/dir.h>
122 #undef MAXPATHLEN /* sys/param.h might define this also */
128 #if defined(BSD) && !defined(errno) && (BSD < 199306) /* here BSD as just a bug */
132 #ifndef STATIC_INLINE_EMUL_UNIX
133 #define STATIC_INLINE_EMUL_UNIX STATIC_INLINE
137 #define PATH_MAX 1024
144 /* UNIX's idea of what is needed to implement emulations */
146 struct _os_emul_data
{
148 emul_syscall
*syscalls
;
152 /* Emulation of simple UNIX system calls that are common on all systems. */
154 /* Structures that are common agmonst the UNIX varients */
155 struct unix_timeval
{
156 signed32 tv_sec
; /* seconds */
157 signed32 tv_usec
; /* microseconds */
160 struct unix_timezone
{
161 signed32 tz_minuteswest
; /* minutes west of Greenwich */
162 signed32 tz_dsttime
; /* type of dst correction */
165 #define UNIX_RUSAGE_SELF 0
166 #define UNIX_RUSAGE_CHILDREN (-1)
167 #define UNIX_RUSAGE_BOTH (-2) /* sys_wait4() uses this */
170 struct unix_timeval ru_utime
; /* user time used */
171 struct unix_timeval ru_stime
; /* system time used */
172 signed32 ru_maxrss
; /* maximum resident set size */
173 signed32 ru_ixrss
; /* integral shared memory size */
174 signed32 ru_idrss
; /* integral unshared data size */
175 signed32 ru_isrss
; /* integral unshared stack size */
176 signed32 ru_minflt
; /* any page faults not requiring I/O */
177 signed32 ru_majflt
; /* any page faults requiring I/O */
178 signed32 ru_nswap
; /* swaps */
179 signed32 ru_inblock
; /* block input operations */
180 signed32 ru_oublock
; /* block output operations */
181 signed32 ru_msgsnd
; /* messages sent */
182 signed32 ru_msgrcv
; /* messages received */
183 signed32 ru_nsignals
; /* signals received */
184 signed32 ru_nvcsw
; /* voluntary context switches */
185 signed32 ru_nivcsw
; /* involuntary " */
189 /* File descriptors 0, 1, and 2 should not be closed. fd_closed[]
190 tracks whether these descriptors have been closed in do_close()
193 static int fd_closed
[3];
195 /* Check for some occurrences of bad file descriptors. We only check
196 whether fd 0, 1, or 2 are "closed". By "closed" we mean that these
197 descriptors aren't actually closed, but are considered to be closed
200 Other checks are performed by the underlying OS call. */
205 if (fd
>=0 && fd
<= 2 && fd_closed
[fd
])
214 do_unix_exit(os_emul_data
*emul
,
220 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
221 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
222 printf_filtered ("%d)\n", status
);
224 cpu_halt(processor
, cia
, was_exited
, status
);
229 do_unix_read(os_emul_data
*emul
,
235 void *scratch_buffer
;
236 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
237 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
238 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
241 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
242 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
244 /* get a tempoary bufer */
245 scratch_buffer
= zalloc(nbytes
);
247 /* check if buffer exists by reading it */
248 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
253 status
= read (d
, scratch_buffer
, nbytes
);
255 emul_write_status(processor
, status
, errno
);
257 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
259 free(scratch_buffer
);
264 do_unix_write(os_emul_data
*emul
,
270 void *scratch_buffer
= NULL
;
271 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
272 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
273 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
276 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
277 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
279 /* get a tempoary bufer */
280 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
283 emul_read_buffer(scratch_buffer
, buf
, nbytes
,
289 status
= write(d
, scratch_buffer
, nbytes
);
290 emul_write_status(processor
, status
, errno
);
291 free(scratch_buffer
);
298 do_unix_open(os_emul_data
*emul
,
304 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
305 char path_buf
[PATH_MAX
];
306 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
307 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
308 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
311 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
312 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
314 status
= open(path
, flags
, mode
);
315 emul_write_status(processor
, status
, errno
);
320 do_unix_close(os_emul_data
*emul
,
326 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
329 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
330 printf_filtered ("%d", d
);
335 /* Do not close stdin, stdout, or stderr. GDB may still need access to
336 these descriptors. */
337 if (d
== 0 || d
== 1 || d
== 2)
346 emul_write_status(processor
, status
, errno
);
351 do_unix_break(os_emul_data
*emul
,
357 /* just pass this onto the `vm' device */
358 unsigned_word new_break
= cpu_registers(processor
)->gpr
[arg0
];
361 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
362 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
364 status
= device_ioctl(emul
->vm
,
368 new_break
); /*ioctl-data*/
370 emul_write_status(processor
, 0, status
);
374 #define do_unix_access 0
377 do_unix_access(os_emul_data
*emul
,
383 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
384 char path_buf
[PATH_MAX
];
385 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
386 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
389 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
390 printf_filtered ("0x%lx [%s], 0x%x [0%o]", (long)path_addr
, path
, mode
, mode
);
392 status
= access(path
, mode
);
393 emul_write_status(processor
, status
, errno
);
398 #define do_unix_getpid 0
401 do_unix_getpid(os_emul_data
*emul
,
407 pid_t status
= getpid();
408 emul_write_status(processor
, (int)status
, errno
);
413 #define do_unix_getppid 0
416 do_unix_getppid(os_emul_data
*emul
,
422 pid_t status
= getppid();
423 emul_write_status(processor
, (int)status
, errno
);
427 #if !defined(HAVE_GETPID) || !defined(HAVE_GETPPID)
428 #define do_unix_getpid2 0
431 do_unix_getpid2(os_emul_data
*emul
,
437 int pid
= (int)getpid();
438 int ppid
= (int)getppid();
439 emul_write2_status(processor
, pid
, ppid
, errno
);
443 #if !defined(HAVE_GETUID) || !defined(HAVE_GETEUID)
444 #define do_unix_getuid2 0
447 do_unix_getuid2(os_emul_data
*emul
,
453 uid_t uid
= getuid();
454 uid_t euid
= geteuid();
455 emul_write2_status(processor
, (int)uid
, (int)euid
, errno
);
460 #define do_unix_getuid 0
463 do_unix_getuid(os_emul_data
*emul
,
469 uid_t status
= getuid();
470 emul_write_status(processor
, (int)status
, errno
);
475 #define do_unix_geteuid 0
478 do_unix_geteuid(os_emul_data
*emul
,
484 uid_t status
= geteuid();
485 emul_write_status(processor
, (int)status
, errno
);
491 #define do_unix_kill 0
494 do_unix_kill(os_emul_data
*emul
,
500 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
501 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
503 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
504 printf_filtered ("%d, %d", (int)pid
, sig
);
506 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
509 cpu_halt(processor
, cia
, was_signalled
, sig
);
515 #define do_unix_dup 0
518 do_unix_dup(os_emul_data
*emul
,
524 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
525 int status
= (fdbad (oldd
) < 0) ? -1 : dup(oldd
);
528 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
529 printf_filtered ("%d", oldd
);
531 emul_write_status(processor
, status
, err
);
536 #define do_unix_dup2 0
539 do_unix_dup2(os_emul_data
*emul
,
545 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
546 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
547 int status
= (fdbad (oldd
) < 0) ? -1 : dup2(oldd
, newd
);
550 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
551 printf_filtered ("%d, %d", oldd
, newd
);
553 emul_write_status(processor
, status
, err
);
558 #define do_unix_lseek 0
561 do_unix_lseek(os_emul_data
*emul
,
567 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
568 off_t offset
= (off_t
)cpu_registers(processor
)->gpr
[arg0
+1];
569 int whence
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
572 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
573 printf_filtered ("%d %ld %d", fildes
, (long)offset
, whence
);
575 status
= fdbad (fildes
);
577 status
= lseek(fildes
, offset
, whence
);
578 emul_write_status(processor
, (int)status
, errno
);
583 #if !defined(HAVE_GETGID) || !defined(HAVE_GETEGID)
584 #define do_unix_getgid2 0
587 do_unix_getgid2(os_emul_data
*emul
,
593 gid_t gid
= getgid();
594 gid_t egid
= getegid();
595 emul_write2_status(processor
, (int)gid
, (int)egid
, errno
);
600 #define do_unix_getgid 0
603 do_unix_getgid(os_emul_data
*emul
,
609 gid_t status
= getgid();
610 emul_write_status(processor
, (int)status
, errno
);
615 #define do_unix_getegid 0
618 do_unix_getegid(os_emul_data
*emul
,
624 gid_t status
= getegid();
625 emul_write_status(processor
, (int)status
, errno
);
630 #define do_unix_umask 0
633 do_unix_umask(os_emul_data
*emul
,
639 mode_t mask
= (mode_t
)cpu_registers(processor
)->gpr
[arg0
];
640 int status
= umask(mask
);
642 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
643 printf_filtered ("0%o", (unsigned int)mask
);
645 emul_write_status(processor
, status
, errno
);
650 #define do_unix_chdir 0
653 do_unix_chdir(os_emul_data
*emul
,
659 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
660 char path_buf
[PATH_MAX
];
661 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
664 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
665 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
667 status
= chdir(path
);
668 emul_write_status(processor
, status
, errno
);
673 #define do_unix_link 0
676 do_unix_link(os_emul_data
*emul
,
682 unsigned_word path1_addr
= cpu_registers(processor
)->gpr
[arg0
];
683 char path1_buf
[PATH_MAX
];
684 char *path1
= emul_read_string(path1_buf
, path1_addr
, PATH_MAX
, processor
, cia
);
685 unsigned_word path2_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
686 char path2_buf
[PATH_MAX
];
687 char *path2
= emul_read_string(path2_buf
, path2_addr
, PATH_MAX
, processor
, cia
);
690 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
691 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr
, path1
, (long)path2_addr
, path2
);
693 status
= link(path1
, path2
);
694 emul_write_status(processor
, status
, errno
);
699 #define do_unix_symlink 0
702 do_unix_symlink(os_emul_data
*emul
,
708 unsigned_word path1_addr
= cpu_registers(processor
)->gpr
[arg0
];
709 char path1_buf
[PATH_MAX
];
710 char *path1
= emul_read_string(path1_buf
, path1_addr
, PATH_MAX
, processor
, cia
);
711 unsigned_word path2_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
712 char path2_buf
[PATH_MAX
];
713 char *path2
= emul_read_string(path2_buf
, path2_addr
, PATH_MAX
, processor
, cia
);
716 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
717 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr
, path1
, (long)path2_addr
, path2
);
719 status
= symlink(path1
, path2
);
720 emul_write_status(processor
, status
, errno
);
725 #define do_unix_unlink 0
728 do_unix_unlink(os_emul_data
*emul
,
734 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
735 char path_buf
[PATH_MAX
];
736 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
739 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
740 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
742 status
= unlink(path
);
743 emul_write_status(processor
, status
, errno
);
748 #define do_unix_mkdir 0
751 do_unix_mkdir(os_emul_data
*emul
,
757 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
758 char path_buf
[PATH_MAX
];
759 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
760 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
763 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
764 printf_filtered ("0x%lx [%s], 0%3o", (long)path_addr
, path
, mode
);
767 status
= mkdir(path
);
769 status
= mkdir(path
, mode
);
771 emul_write_status(processor
, status
, errno
);
776 #define do_unix_rmdir 0
779 do_unix_rmdir(os_emul_data
*emul
,
785 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
786 char path_buf
[PATH_MAX
];
787 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
790 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
791 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
793 status
= rmdir(path
);
794 emul_write_status(processor
, status
, errno
);
799 #define do_unix_time 0
802 do_unix_time(os_emul_data
*emul
,
808 unsigned_word tp
= cpu_registers(processor
)->gpr
[arg0
];
809 time_t now
= time ((time_t *)0);
810 unsigned_word status
= H2T_4(now
);
812 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
813 printf_filtered ("0x%lx", (long)tp
);
815 emul_write_status(processor
, (int)status
, errno
);
818 emul_write_buffer(&status
, tp
, sizeof(status
), processor
, cia
);
822 #if !defined(HAVE_GETTIMEOFDAY) || !defined(HAVE_SYS_TIME_H)
823 #define do_unix_gettimeofday 0
826 do_unix_gettimeofday(os_emul_data
*emul
,
832 unsigned_word tv
= cpu_registers(processor
)->gpr
[arg0
];
833 unsigned_word tz
= cpu_registers(processor
)->gpr
[arg0
+1];
834 struct unix_timeval target_timeval
;
835 struct timeval host_timeval
;
836 struct unix_timezone target_timezone
;
837 struct timezone host_timezone
;
840 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
841 printf_filtered ("0x%lx, 0x%lx", (long)tv
, (long)tz
);
843 /* Just in case the system doesn't set the timezone structure */
844 host_timezone
.tz_minuteswest
= 0;
845 host_timezone
.tz_dsttime
= 0;
847 status
= gettimeofday(&host_timeval
, &host_timezone
);
850 target_timeval
.tv_sec
= H2T_4(host_timeval
.tv_sec
);
851 target_timeval
.tv_usec
= H2T_4(host_timeval
.tv_usec
);
852 emul_write_buffer((void *) &target_timeval
, tv
, sizeof(target_timeval
), processor
, cia
);
856 target_timezone
.tz_minuteswest
= H2T_4(host_timezone
.tz_minuteswest
);
857 target_timezone
.tz_dsttime
= H2T_4(host_timezone
.tz_dsttime
);
858 emul_write_buffer((void *) &target_timezone
, tv
, sizeof(target_timezone
), processor
, cia
);
862 emul_write_status(processor
, (int)status
, errno
);
867 #ifndef HAVE_GETRUSAGE
868 #define do_unix_getrusage 0
871 do_unix_getrusage(os_emul_data
*emul
,
877 signed_word who
= (signed_word
)cpu_registers(processor
)->gpr
[arg0
];
878 unsigned_word usage
= cpu_registers(processor
)->gpr
[arg0
+1];
879 struct rusage host_rusage
, host_rusage2
;
880 struct unix_rusage target_rusage
;
883 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
884 printf_filtered ("%ld, 0x%lx", (long)who
, (long)usage
);
892 case UNIX_RUSAGE_SELF
:
893 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
896 case UNIX_RUSAGE_CHILDREN
:
897 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage
);
900 case UNIX_RUSAGE_BOTH
:
901 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
903 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage2
);
905 host_rusage
.ru_utime
.tv_sec
+= host_rusage2
.ru_utime
.tv_sec
;
906 host_rusage
.ru_utime
.tv_usec
+= host_rusage2
.ru_utime
.tv_usec
;
907 host_rusage
.ru_stime
.tv_sec
+= host_rusage2
.ru_stime
.tv_sec
;
908 host_rusage
.ru_stime
.tv_usec
+= host_rusage2
.ru_stime
.tv_usec
;
909 host_rusage
.ru_maxrss
+= host_rusage2
.ru_maxrss
;
910 host_rusage
.ru_ixrss
+= host_rusage2
.ru_ixrss
;
911 host_rusage
.ru_idrss
+= host_rusage2
.ru_idrss
;
912 host_rusage
.ru_isrss
+= host_rusage2
.ru_isrss
;
913 host_rusage
.ru_minflt
+= host_rusage2
.ru_minflt
;
914 host_rusage
.ru_majflt
+= host_rusage2
.ru_majflt
;
915 host_rusage
.ru_nswap
+= host_rusage2
.ru_nswap
;
916 host_rusage
.ru_inblock
+= host_rusage2
.ru_inblock
;
917 host_rusage
.ru_oublock
+= host_rusage2
.ru_oublock
;
918 host_rusage
.ru_msgsnd
+= host_rusage2
.ru_msgsnd
;
919 host_rusage
.ru_msgrcv
+= host_rusage2
.ru_msgrcv
;
920 host_rusage
.ru_nsignals
+= host_rusage2
.ru_nsignals
;
921 host_rusage
.ru_nvcsw
+= host_rusage2
.ru_nvcsw
;
922 host_rusage
.ru_nivcsw
+= host_rusage2
.ru_nivcsw
;
928 target_rusage
.ru_utime
.tv_sec
= H2T_4(host_rusage2
.ru_utime
.tv_sec
);
929 target_rusage
.ru_utime
.tv_usec
= H2T_4(host_rusage2
.ru_utime
.tv_usec
);
930 target_rusage
.ru_stime
.tv_sec
= H2T_4(host_rusage2
.ru_stime
.tv_sec
);
931 target_rusage
.ru_stime
.tv_usec
= H2T_4(host_rusage2
.ru_stime
.tv_usec
);
932 target_rusage
.ru_maxrss
= H2T_4(host_rusage2
.ru_maxrss
);
933 target_rusage
.ru_ixrss
= H2T_4(host_rusage2
.ru_ixrss
);
934 target_rusage
.ru_idrss
= H2T_4(host_rusage2
.ru_idrss
);
935 target_rusage
.ru_isrss
= H2T_4(host_rusage2
.ru_isrss
);
936 target_rusage
.ru_minflt
= H2T_4(host_rusage2
.ru_minflt
);
937 target_rusage
.ru_majflt
= H2T_4(host_rusage2
.ru_majflt
);
938 target_rusage
.ru_nswap
= H2T_4(host_rusage2
.ru_nswap
);
939 target_rusage
.ru_inblock
= H2T_4(host_rusage2
.ru_inblock
);
940 target_rusage
.ru_oublock
= H2T_4(host_rusage2
.ru_oublock
);
941 target_rusage
.ru_msgsnd
= H2T_4(host_rusage2
.ru_msgsnd
);
942 target_rusage
.ru_msgrcv
= H2T_4(host_rusage2
.ru_msgrcv
);
943 target_rusage
.ru_nsignals
= H2T_4(host_rusage2
.ru_nsignals
);
944 target_rusage
.ru_nvcsw
= H2T_4(host_rusage2
.ru_nvcsw
);
945 target_rusage
.ru_nivcsw
= H2T_4(host_rusage2
.ru_nivcsw
);
946 emul_write_buffer((void *) &target_rusage
, usage
, sizeof(target_rusage
), processor
, cia
);
949 emul_write_status(processor
, status
, errno
);
955 do_unix_nop(os_emul_data
*emul
,
961 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
962 printf_filtered ("0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
963 (long)cpu_registers(processor
)->gpr
[arg0
],
964 (long)cpu_registers(processor
)->gpr
[arg0
+1],
965 (long)cpu_registers(processor
)->gpr
[arg0
+2],
966 (long)cpu_registers(processor
)->gpr
[arg0
+3],
967 (long)cpu_registers(processor
)->gpr
[arg0
+4],
968 (long)cpu_registers(processor
)->gpr
[arg0
+5]);
970 emul_write_status(processor
, 0, errno
);
974 /* Common code for initializing the system call stuff */
976 static os_emul_data
*
977 emul_unix_create(device
*root
,
980 emul_syscall
*syscall
)
982 unsigned_word top_of_stack
;
989 /* merge any emulation specific entries into the device tree */
991 /* establish a few defaults */
992 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
994 top_of_stack
= 0xe0000000;
995 stack_size
= 0x00100000;
999 top_of_stack
= 0x20000000;
1000 stack_size
= 0x00100000;
1004 emul_add_tree_options(root
, image
, name
,
1005 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
1006 ? "user" : "virtual"),
1007 0 /*oea-interrupt-prefix*/);
1009 /* virtual memory - handles growth of stack/heap */
1010 vm
= tree_parse(root
, "/openprom/vm@0x%lx",
1011 (unsigned long)(top_of_stack
- stack_size
));
1012 tree_parse(vm
, "./stack-base 0x%lx",
1013 (unsigned long)(top_of_stack
- stack_size
));
1014 tree_parse(vm
, "./nr-bytes 0x%x", stack_size
);
1016 filename
= tree_quote_property (bfd_get_filename(image
));
1017 tree_parse(root
, "/openprom/vm/map-binary/file-name %s",
1021 /* finish the init */
1022 tree_parse(root
, "/openprom/init/register/pc 0x%lx",
1023 (unsigned long)bfd_get_start_address(image
));
1024 tree_parse(root
, "/openprom/init/register/sp 0x%lx",
1025 (unsigned long)top_of_stack
);
1026 tree_parse(root
, "/openprom/init/register/msr 0x%x",
1027 ((tree_find_boolean_property(root
, "/options/little-endian?")
1028 ? msr_little_endian_mode
1030 | (tree_find_boolean_property(root
, "/openprom/options/floating-point?")
1031 ? (msr_floating_point_available
1032 | msr_floating_point_exception_mode_0
1033 | msr_floating_point_exception_mode_1
)
1035 tree_parse(root
, "/openprom/init/stack/stack-type %s",
1036 (elf_binary
? "ppc-elf" : "ppc-xcoff"));
1038 /* finally our emulation data */
1039 data
= ZALLOC(os_emul_data
);
1041 data
->syscalls
= syscall
;
1048 Solaris - Emulation of user programs for Solaris/PPC
1055 /* Solaris specific implementation */
1057 typedef signed32 solaris_uid_t
;
1058 typedef signed32 solaris_gid_t
;
1059 typedef signed32 solaris_off_t
;
1060 typedef signed32 solaris_pid_t
;
1061 typedef signed32 solaris_time_t
;
1062 typedef unsigned32 solaris_dev_t
;
1063 typedef unsigned32 solaris_ino_t
;
1064 typedef unsigned32 solaris_mode_t
;
1065 typedef unsigned32 solaris_nlink_t
;
1067 #ifdef HAVE_SYS_STAT_H
1068 #define SOLARIS_ST_FSTYPSZ 16 /* array size for file system type name */
1070 /* AIX 7.1 defines st_pad[123] to st_[amc]tim.tv_pad, respectively */
1075 struct solaris_stat
{
1076 solaris_dev_t st_dev
;
1077 signed32 st_pad1
[3]; /* reserved for network id */
1078 solaris_ino_t st_ino
;
1079 solaris_mode_t st_mode
;
1080 solaris_nlink_t st_nlink
;
1081 solaris_uid_t st_uid
;
1082 solaris_gid_t st_gid
;
1083 solaris_dev_t st_rdev
;
1084 signed32 st_pad2
[2];
1085 solaris_off_t st_size
;
1086 signed32 st_pad3
; /* future off_t expansion */
1087 struct unix_timeval st_atim
;
1088 struct unix_timeval st_mtim
;
1089 struct unix_timeval st_ctim
;
1090 signed32 st_blksize
;
1092 char st_fstype
[SOLARIS_ST_FSTYPSZ
];
1093 signed32 st_pad4
[8]; /* expansion area */
1096 /* Convert from host stat structure to solaris stat structure */
1097 STATIC_INLINE_EMUL_UNIX
void
1098 convert_to_solaris_stat(unsigned_word addr
,
1103 struct solaris_stat target
;
1106 target
.st_dev
= H2T_4(host
->st_dev
);
1107 target
.st_ino
= H2T_4(host
->st_ino
);
1108 target
.st_mode
= H2T_4(host
->st_mode
);
1109 target
.st_nlink
= H2T_4(host
->st_nlink
);
1110 target
.st_uid
= H2T_4(host
->st_uid
);
1111 target
.st_gid
= H2T_4(host
->st_gid
);
1112 target
.st_size
= H2T_4(host
->st_size
);
1115 target
.st_rdev
= H2T_4(host
->st_rdev
);
1120 #ifdef HAVE_ST_BLKSIZE
1121 target
.st_blksize
= H2T_4(host
->st_blksize
);
1123 target
.st_blksize
= 0;
1126 #ifdef HAVE_ST_BLOCKS
1127 target
.st_blocks
= H2T_4(host
->st_blocks
);
1129 target
.st_blocks
= 0;
1132 target
.st_atim
.tv_sec
= H2T_4(host
->st_atime
);
1133 target
.st_atim
.tv_usec
= 0;
1135 target
.st_ctim
.tv_sec
= H2T_4(host
->st_ctime
);
1136 target
.st_ctim
.tv_usec
= 0;
1138 target
.st_mtim
.tv_sec
= H2T_4(host
->st_mtime
);
1139 target
.st_mtim
.tv_usec
= 0;
1141 for (i
= 0; i
< ARRAY_SIZE (target
.st_pad1
); i
++)
1142 target
.st_pad1
[i
] = 0;
1144 for (i
= 0; i
< ARRAY_SIZE (target
.st_pad2
); i
++)
1145 target
.st_pad2
[i
] = 0;
1149 for (i
= 0; i
< ARRAY_SIZE (target
.st_pad4
); i
++)
1150 target
.st_pad4
[i
] = 0;
1152 /* For now, just punt and always say it is a ufs file */
1153 strcpy (target
.st_fstype
, "ufs");
1155 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1157 #endif /* HAVE_SYS_STAT_H */
1160 #define do_solaris_stat 0
1163 do_solaris_stat(os_emul_data
*emul
,
1169 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1170 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1171 char path_buf
[PATH_MAX
];
1173 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1176 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1177 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1179 status
= stat (path
, &buf
);
1181 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1183 emul_write_status(processor
, status
, errno
);
1188 #define do_solaris_lstat 0
1191 do_solaris_lstat(os_emul_data
*emul
,
1197 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1198 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1199 char path_buf
[PATH_MAX
];
1201 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1204 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1205 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1207 status
= lstat (path
, &buf
);
1209 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1211 emul_write_status(processor
, status
, errno
);
1216 #define do_solaris_fstat 0
1219 do_solaris_fstat(os_emul_data
*emul
,
1225 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
1226 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1230 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1231 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
1233 status
= fdbad (fildes
);
1235 status
= fstat (fildes
, &buf
);
1237 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1239 emul_write_status(processor
, status
, errno
);
1243 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1244 #define SOLARIS_TIOC ('T'<<8)
1245 #define SOLARIS_NCC 8
1246 #define SOLARIS_NCCS 19
1248 #define SOLARIS_VINTR 0
1249 #define SOLARIS_VQUIT 1
1250 #define SOLARIS_VERASE 2
1251 #define SOLARIS_VKILL 3
1252 #define SOLARIS_VEOF 4
1253 #define SOLARIS_VEOL 5
1254 #define SOLARIS_VEOL2 6
1255 #define SOLARIS_VSWTCH 7
1256 #define SOLARIS_VSTART 8
1257 #define SOLARIS_VSTOP 9
1258 #define SOLARIS_VSUSP 10
1259 #define SOLARIS_VDSUSP 11
1260 #define SOLARIS_VREPRINT 12
1261 #define SOLARIS_VDISCARD 13
1262 #define SOLARIS_VWERASE 14
1263 #define SOLARIS_VLNEXT 15
1266 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1267 /* Convert to/from host termio structure */
1269 struct solaris_termio
{
1270 unsigned16 c_iflag
; /* input modes */
1271 unsigned16 c_oflag
; /* output modes */
1272 unsigned16 c_cflag
; /* control modes */
1273 unsigned16 c_lflag
; /* line discipline modes */
1274 unsigned8 c_line
; /* line discipline */
1275 unsigned8 c_cc
[SOLARIS_NCC
]; /* control chars */
1278 STATIC_INLINE_EMUL_UNIX
void
1279 convert_to_solaris_termio(unsigned_word addr
,
1280 struct termio
*host
,
1284 struct solaris_termio target
;
1287 target
.c_iflag
= H2T_2 (host
->c_iflag
);
1288 target
.c_oflag
= H2T_2 (host
->c_oflag
);
1289 target
.c_cflag
= H2T_2 (host
->c_cflag
);
1290 target
.c_lflag
= H2T_2 (host
->c_lflag
);
1292 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
1293 target
.c_line
= host
->c_line
;
1298 for (i
= 0; i
< SOLARIS_NCC
; i
++)
1302 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1306 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1310 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1314 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1318 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1322 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1326 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1330 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1334 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1338 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1340 #endif /* HAVE_TERMIO_STRUCTURE || HAVE_TERMIOS_STRUCTURE */
1342 #ifdef HAVE_TERMIOS_STRUCTURE
1343 /* Convert to/from host termios structure */
1345 typedef unsigned32 solaris_tcflag_t
;
1346 typedef unsigned8 solaris_cc_t
;
1347 typedef unsigned32 solaris_speed_t
;
1349 struct solaris_termios
{
1350 solaris_tcflag_t c_iflag
;
1351 solaris_tcflag_t c_oflag
;
1352 solaris_tcflag_t c_cflag
;
1353 solaris_tcflag_t c_lflag
;
1354 solaris_cc_t c_cc
[SOLARIS_NCCS
];
1357 STATIC_INLINE_EMUL_UNIX
void
1358 convert_to_solaris_termios(unsigned_word addr
,
1359 struct termios
*host
,
1363 struct solaris_termios target
;
1366 target
.c_iflag
= H2T_4 (host
->c_iflag
);
1367 target
.c_oflag
= H2T_4 (host
->c_oflag
);
1368 target
.c_cflag
= H2T_4 (host
->c_cflag
);
1369 target
.c_lflag
= H2T_4 (host
->c_lflag
);
1371 for (i
= 0; i
< SOLARIS_NCCS
; i
++)
1375 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1379 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1383 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1387 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1391 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1395 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1399 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1403 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1407 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1412 target
.c_cc
[SOLARIS_VSTART
] = host
->c_cc
[VSTART
];
1416 target
.c_cc
[SOLARIS_VSTOP
] = host
->c_cc
[VSTOP
];
1420 target
.c_cc
[SOLARIS_VSUSP
] = host
->c_cc
[VSUSP
];
1424 target
.c_cc
[SOLARIS_VDSUSP
] = host
->c_cc
[VDSUSP
];
1428 target
.c_cc
[SOLARIS_VREPRINT
] = host
->c_cc
[VREPRINT
];
1432 target
.c_cc
[SOLARIS_VDISCARD
] = host
->c_cc
[VDISCARD
];
1436 target
.c_cc
[SOLARIS_VWERASE
] = host
->c_cc
[VWERASE
];
1440 target
.c_cc
[SOLARIS_VLNEXT
] = host
->c_cc
[VLNEXT
];
1443 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1445 #endif /* HAVE_TERMIOS_STRUCTURE */
1448 #define do_solaris_ioctl 0
1451 do_solaris_ioctl(os_emul_data
*emul
,
1457 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
1458 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
1459 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
1461 const char *name
= "<unknown>";
1463 #ifdef HAVE_TERMIOS_STRUCTURE
1464 struct termios host_termio
;
1467 #ifdef HAVE_TERMIO_STRUCTURE
1468 struct termio host_termio
;
1472 status
= fdbad (fildes
);
1478 case 0: /* make sure we have at least one case */
1484 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1485 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
1486 case SOLARIS_TIOC
| 1: /* TCGETA */
1488 #ifdef HAVE_TCGETATTR
1489 status
= tcgetattr(fildes
, &host_termio
);
1490 #elif defined(TCGETS)
1491 status
= ioctl (fildes
, TCGETS
, &host_termio
);
1493 status
= ioctl (fildes
, TCGETA
, &host_termio
);
1496 convert_to_solaris_termio (argp_addr
, &host_termio
, processor
, cia
);
1499 #endif /* HAVE_TERMIO_STRUCTURE */
1501 #ifdef HAVE_TERMIOS_STRUCTURE
1502 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
1503 case SOLARIS_TIOC
| 13: /* TCGETS */
1505 #ifdef HAVE_TCGETATTR
1506 status
= tcgetattr(fildes
, &host_termio
);
1508 status
= ioctl (fildes
, TCGETS
, &host_termio
);
1511 convert_to_solaris_termios (argp_addr
, &host_termio
, processor
, cia
);
1514 #endif /* HAVE_TERMIOS_STRUCTURE */
1518 emul_write_status(processor
, status
, errno
);
1520 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1521 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
1523 #endif /* HAVE_IOCTL */
1525 static emul_syscall_descriptor solaris_descriptors
[] = {
1526 /* 0 */ { 0, "syscall" },
1527 /* 1 */ { do_unix_exit
, "exit" },
1528 /* 2 */ { 0, "fork" },
1529 /* 3 */ { do_unix_read
, "read" },
1530 /* 4 */ { do_unix_write
, "write" },
1531 /* 5 */ { do_unix_open
, "open" },
1532 /* 6 */ { do_unix_close
, "close" },
1533 /* 7 */ { 0, "wait" },
1534 /* 8 */ { 0, "creat" },
1535 /* 9 */ { do_unix_link
, "link" },
1536 /* 10 */ { do_unix_unlink
, "unlink" },
1537 /* 11 */ { 0, "exec" },
1538 /* 12 */ { do_unix_chdir
, "chdir" },
1539 /* 13 */ { do_unix_time
, "time" },
1540 /* 14 */ { 0, "mknod" },
1541 /* 15 */ { 0, "chmod" },
1542 /* 16 */ { 0, "chown" },
1543 /* 17 */ { do_unix_break
, "brk" },
1544 /* 18 */ { do_solaris_stat
, "stat" },
1545 /* 19 */ { do_unix_lseek
, "lseek" },
1546 /* 20 */ { do_unix_getpid2
, "getpid" },
1547 /* 21 */ { 0, "mount" },
1548 /* 22 */ { 0, "umount" },
1549 /* 23 */ { 0, "setuid" },
1550 /* 24 */ { do_unix_getuid2
, "getuid" },
1551 /* 25 */ { 0, "stime" },
1552 /* 26 */ { 0, "ptrace" },
1553 /* 27 */ { 0, "alarm" },
1554 /* 28 */ { do_solaris_fstat
, "fstat" },
1555 /* 29 */ { 0, "pause" },
1556 /* 30 */ { 0, "utime" },
1557 /* 31 */ { 0, "stty" },
1558 /* 32 */ { 0, "gtty" },
1559 /* 33 */ { do_unix_access
, "access" },
1560 /* 34 */ { 0, "nice" },
1561 /* 35 */ { 0, "statfs" },
1562 /* 36 */ { 0, "sync" },
1563 /* 37 */ { 0, "kill" },
1564 /* 38 */ { 0, "fstatfs" },
1565 /* 39 */ { 0, "pgrpsys" },
1566 /* 40 */ { 0, "xenix" },
1567 /* 41 */ { do_unix_dup
, "dup" },
1568 /* 42 */ { 0, "pipe" },
1569 /* 43 */ { 0, "times" },
1570 /* 44 */ { 0, "profil" },
1571 /* 45 */ { 0, "plock" },
1572 /* 46 */ { 0, "setgid" },
1573 /* 47 */ { do_unix_getgid2
, "getgid" },
1574 /* 48 */ { 0, "signal" },
1575 /* 49 */ { 0, "msgsys" },
1576 /* 50 */ { 0, "syssun" },
1577 /* 51 */ { 0, "acct" },
1578 /* 52 */ { 0, "shmsys" },
1579 /* 53 */ { 0, "semsys" },
1580 /* 54 */ { do_solaris_ioctl
, "ioctl" },
1581 /* 55 */ { 0, "uadmin" },
1582 /* 56 */ { 0, 0 /* reserved for exch */ },
1583 /* 57 */ { 0, "utssys" },
1584 /* 58 */ { 0, "fdsync" },
1585 /* 59 */ { 0, "execve" },
1586 /* 60 */ { do_unix_umask
, "umask" },
1587 /* 61 */ { 0, "chroot" },
1588 /* 62 */ { 0, "fcntl" },
1589 /* 63 */ { 0, "ulimit" },
1590 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1591 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1592 /* 65 */ { 0, 0 /* reserved for UNIX PC */ },
1593 /* 66 */ { 0, 0 /* reserved for UNIX PC */ },
1594 /* 67 */ { 0, 0 /* reserved for UNIX PC */ },
1595 /* 68 */ { 0, 0 /* reserved for UNIX PC */ },
1596 /* 69 */ { 0, 0 /* reserved for UNIX PC */ },
1597 /* 70 */ { 0, 0 /* was advfs */ },
1598 /* 71 */ { 0, 0 /* was unadvfs */ },
1599 /* 72 */ { 0, 0 /* was rmount */ },
1600 /* 73 */ { 0, 0 /* was rumount */ },
1601 /* 74 */ { 0, 0 /* was rfstart */ },
1602 /* 75 */ { 0, 0 /* was sigret */ },
1603 /* 76 */ { 0, 0 /* was rdebug */ },
1604 /* 77 */ { 0, 0 /* was rfstop */ },
1605 /* 78 */ { 0, 0 /* was rfsys */ },
1606 /* 79 */ { do_unix_rmdir
, "rmdir" },
1607 /* 80 */ { do_unix_mkdir
, "mkdir" },
1608 /* 81 */ { 0, "getdents" },
1609 /* 82 */ { 0, 0 /* was libattach */ },
1610 /* 83 */ { 0, 0 /* was libdetach */ },
1611 /* 84 */ { 0, "sysfs" },
1612 /* 85 */ { 0, "getmsg" },
1613 /* 86 */ { 0, "putmsg" },
1614 /* 87 */ { 0, "poll" },
1615 /* 88 */ { do_solaris_lstat
, "lstat" },
1616 /* 89 */ { do_unix_symlink
, "symlink" },
1617 /* 90 */ { 0, "readlink" },
1618 /* 91 */ { 0, "setgroups" },
1619 /* 92 */ { 0, "getgroups" },
1620 /* 93 */ { 0, "fchmod" },
1621 /* 94 */ { 0, "fchown" },
1622 /* 95 */ { 0, "sigprocmask" },
1623 /* 96 */ { 0, "sigsuspend" },
1624 /* 97 */ { do_unix_nop
, "sigaltstack" },
1625 /* 98 */ { do_unix_nop
, "sigaction" },
1626 /* 99 */ { 0, "sigpending" },
1627 /* 100 */ { 0, "context" },
1628 /* 101 */ { 0, "evsys" },
1629 /* 102 */ { 0, "evtrapret" },
1630 /* 103 */ { 0, "statvfs" },
1631 /* 104 */ { 0, "fstatvfs" },
1632 /* 105 */ { 0, 0 /* reserved */ },
1633 /* 106 */ { 0, "nfssys" },
1634 /* 107 */ { 0, "waitsys" },
1635 /* 108 */ { 0, "sigsendsys" },
1636 /* 109 */ { 0, "hrtsys" },
1637 /* 110 */ { 0, "acancel" },
1638 /* 111 */ { 0, "async" },
1639 /* 112 */ { 0, "priocntlsys" },
1640 /* 113 */ { 0, "pathconf" },
1641 /* 114 */ { 0, "mincore" },
1642 /* 115 */ { 0, "mmap" },
1643 /* 116 */ { 0, "mprotect" },
1644 /* 117 */ { 0, "munmap" },
1645 /* 118 */ { 0, "fpathconf" },
1646 /* 119 */ { 0, "vfork" },
1647 /* 120 */ { 0, "fchdir" },
1648 /* 121 */ { 0, "readv" },
1649 /* 122 */ { 0, "writev" },
1650 /* 123 */ { 0, "xstat" },
1651 /* 124 */ { 0, "lxstat" },
1652 /* 125 */ { 0, "fxstat" },
1653 /* 126 */ { 0, "xmknod" },
1654 /* 127 */ { 0, "clocal" },
1655 /* 128 */ { 0, "setrlimit" },
1656 /* 129 */ { 0, "getrlimit" },
1657 /* 130 */ { 0, "lchown" },
1658 /* 131 */ { 0, "memcntl" },
1659 /* 132 */ { 0, "getpmsg" },
1660 /* 133 */ { 0, "putpmsg" },
1661 /* 134 */ { 0, "rename" },
1662 /* 135 */ { 0, "uname" },
1663 /* 136 */ { 0, "setegid" },
1664 /* 137 */ { 0, "sysconfig" },
1665 /* 138 */ { 0, "adjtime" },
1666 /* 139 */ { 0, "systeminfo" },
1667 /* 140 */ { 0, 0 /* reserved */ },
1668 /* 141 */ { 0, "seteuid" },
1669 /* 142 */ { 0, "vtrace" },
1670 /* 143 */ { 0, "fork1" },
1671 /* 144 */ { 0, "sigtimedwait" },
1672 /* 145 */ { 0, "lwp_info" },
1673 /* 146 */ { 0, "yield" },
1674 /* 147 */ { 0, "lwp_sema_wait" },
1675 /* 148 */ { 0, "lwp_sema_post" },
1676 /* 149 */ { 0, 0 /* reserved */ },
1677 /* 150 */ { 0, 0 /* reserved */ },
1678 /* 151 */ { 0, 0 /* reserved */ },
1679 /* 152 */ { 0, "modctl" },
1680 /* 153 */ { 0, "fchroot" },
1681 /* 154 */ { 0, "utimes" },
1682 /* 155 */ { 0, "vhangup" },
1683 /* 156 */ { do_unix_gettimeofday
, "gettimeofday" },
1684 /* 157 */ { 0, "getitimer" },
1685 /* 158 */ { 0, "setitimer" },
1686 /* 159 */ { 0, "lwp_create" },
1687 /* 160 */ { 0, "lwp_exit" },
1688 /* 161 */ { 0, "lwp_suspend" },
1689 /* 162 */ { 0, "lwp_continue" },
1690 /* 163 */ { 0, "lwp_kill" },
1691 /* 164 */ { 0, "lwp_self" },
1692 /* 165 */ { 0, "lwp_setprivate" },
1693 /* 166 */ { 0, "lwp_getprivate" },
1694 /* 167 */ { 0, "lwp_wait" },
1695 /* 168 */ { 0, "lwp_mutex_unlock" },
1696 /* 169 */ { 0, "lwp_mutex_lock" },
1697 /* 170 */ { 0, "lwp_cond_wait" },
1698 /* 171 */ { 0, "lwp_cond_signal" },
1699 /* 172 */ { 0, "lwp_cond_broadcast" },
1700 /* 173 */ { 0, "pread" },
1701 /* 174 */ { 0, "pwrite" },
1702 /* 175 */ { 0, "llseek" },
1703 /* 176 */ { 0, "inst_sync" },
1704 /* 177 */ { 0, 0 /* reserved */ },
1705 /* 178 */ { 0, "kaio" },
1706 /* 179 */ { 0, 0 /* reserved */ },
1707 /* 180 */ { 0, 0 /* reserved */ },
1708 /* 181 */ { 0, 0 /* reserved */ },
1709 /* 182 */ { 0, 0 /* reserved */ },
1710 /* 183 */ { 0, 0 /* reserved */ },
1711 /* 184 */ { 0, "tsolsys" },
1712 /* 185 */ { 0, "acl" },
1713 /* 186 */ { 0, "auditsys" },
1714 /* 187 */ { 0, "processor_bind" },
1715 /* 188 */ { 0, "processor_info" },
1716 /* 189 */ { 0, "p_online" },
1717 /* 190 */ { 0, "sigqueue" },
1718 /* 191 */ { 0, "clock_gettime" },
1719 /* 192 */ { 0, "clock_settime" },
1720 /* 193 */ { 0, "clock_getres" },
1721 /* 194 */ { 0, "timer_create" },
1722 /* 195 */ { 0, "timer_delete" },
1723 /* 196 */ { 0, "timer_settime" },
1724 /* 197 */ { 0, "timer_gettime" },
1725 /* 198 */ { 0, "timer_getoverrun" },
1726 /* 199 */ { 0, "nanosleep" },
1727 /* 200 */ { 0, "facl" },
1728 /* 201 */ { 0, "door" },
1729 /* 202 */ { 0, "setreuid" },
1730 /* 203 */ { 0, "setregid" },
1731 /* 204 */ { 0, "install_utrap" },
1732 /* 205 */ { 0, 0 /* reserved */ },
1733 /* 206 */ { 0, 0 /* reserved */ },
1734 /* 207 */ { 0, 0 /* reserved */ },
1735 /* 208 */ { 0, 0 /* reserved */ },
1736 /* 209 */ { 0, 0 /* reserved */ },
1737 /* 210 */ { 0, "signotifywait" },
1738 /* 211 */ { 0, "lwp_sigredirect" },
1739 /* 212 */ { 0, "lwp_alarm" },
1742 static char *(solaris_error_names
[]) = {
1781 /* 38 */ "EL2NSYNC",
1790 /* 47 */ "ECANCELED",
1799 /* 56 */ "EDEADLOCK",
1801 /* 58 */ "Error code 58",
1802 /* 59 */ "Error code 59",
1815 /* 72 */ "Error code 72",
1816 /* 73 */ "Error code 73",
1817 /* 74 */ "EMULTIHOP",
1818 /* 75 */ "Error code 75",
1819 /* 76 */ "Error code 76",
1821 /* 78 */ "ENAMETOOLONG",
1822 /* 79 */ "EOVERFLOW",
1823 /* 80 */ "ENOTUNIQ",
1830 /* 87 */ "ELIBEXEC",
1834 /* 91 */ "ERESTART",
1835 /* 92 */ "ESTRPIPE",
1836 /* 93 */ "ENOTEMPTY",
1838 /* 95 */ "ENOTSOCK",
1839 /* 96 */ "EDESTADDRREQ",
1840 /* 97 */ "EMSGSIZE",
1841 /* 98 */ "EPROTOTYPE",
1842 /* 99 */ "ENOPROTOOPT",
1843 /* 100 */ "Error code 100",
1844 /* 101 */ "Error code 101",
1845 /* 102 */ "Error code 102",
1846 /* 103 */ "Error code 103",
1847 /* 104 */ "Error code 104",
1848 /* 105 */ "Error code 105",
1849 /* 106 */ "Error code 106",
1850 /* 107 */ "Error code 107",
1851 /* 108 */ "Error code 108",
1852 /* 109 */ "Error code 109",
1853 /* 110 */ "Error code 110",
1854 /* 111 */ "Error code 111",
1855 /* 112 */ "Error code 112",
1856 /* 113 */ "Error code 113",
1857 /* 114 */ "Error code 114",
1858 /* 115 */ "Error code 115",
1859 /* 116 */ "Error code 116",
1860 /* 117 */ "Error code 117",
1861 /* 118 */ "Error code 118",
1862 /* 119 */ "Error code 119",
1863 /* 120 */ "EPROTONOSUPPORT",
1864 /* 121 */ "ESOCKTNOSUPPORT",
1865 /* 122 */ "EOPNOTSUPP",
1866 /* 123 */ "EPFNOSUPPORT",
1867 /* 124 */ "EAFNOSUPPORT",
1868 /* 125 */ "EADDRINUSE",
1869 /* 126 */ "EADDRNOTAVAIL",
1870 /* 127 */ "ENETDOWN",
1871 /* 128 */ "ENETUNREACH",
1872 /* 129 */ "ENETRESET",
1873 /* 130 */ "ECONNABORTED",
1874 /* 131 */ "ECONNRESET",
1875 /* 132 */ "ENOBUFS",
1876 /* 133 */ "EISCONN",
1877 /* 134 */ "ENOTCONN",
1878 /* 135 */ "Error code 135", /* XENIX has 135 - 142 */
1879 /* 136 */ "Error code 136",
1880 /* 137 */ "Error code 137",
1881 /* 138 */ "Error code 138",
1882 /* 139 */ "Error code 139",
1883 /* 140 */ "Error code 140",
1884 /* 141 */ "Error code 141",
1885 /* 142 */ "Error code 142",
1886 /* 143 */ "ESHUTDOWN",
1887 /* 144 */ "ETOOMANYREFS",
1888 /* 145 */ "ETIMEDOUT",
1889 /* 146 */ "ECONNREFUSED",
1890 /* 147 */ "EHOSTDOWN",
1891 /* 148 */ "EHOSTUNREACH",
1892 /* 149 */ "EALREADY",
1893 /* 150 */ "EINPROGRESS",
1897 static char *(solaris_signal_names
[]) = {
1918 /* 20 */ "SIGWINCH",
1926 /* 28 */ "SIGVTALRM",
1930 /* 32 */ "SIGWAITING",
1932 /* 34 */ "SIGFREEZE",
1934 /* 36 */ "SIGCANCEL",
1937 static emul_syscall emul_solaris_syscalls
= {
1938 solaris_descriptors
,
1939 ARRAY_SIZE (solaris_descriptors
),
1940 solaris_error_names
,
1941 ARRAY_SIZE (solaris_error_names
),
1942 solaris_signal_names
,
1943 ARRAY_SIZE (solaris_signal_names
),
1947 /* Solaris's os_emul interface, most are just passed on to the generic
1950 static os_emul_data
*
1951 emul_solaris_create(device
*root
,
1955 /* check that this emulation is really for us */
1956 if (name
!= NULL
&& strcmp(name
, "solaris") != 0)
1962 return emul_unix_create(root
, image
, "solaris", &emul_solaris_syscalls
);
1966 emul_solaris_init(os_emul_data
*emul_data
,
1975 emul_solaris_system_call(cpu
*processor
,
1977 os_emul_data
*emul_data
)
1979 emul_do_system_call(emul_data
,
1980 emul_data
->syscalls
,
1981 cpu_registers(processor
)->gpr
[0],
1982 3, /*r3 contains arg0*/
1987 const os_emul emul_solaris
= {
1989 emul_solaris_create
,
1991 emul_solaris_system_call
,
1992 0, /*instruction_call*/
1999 Linux - Emulation of user programs for Linux/PPC
2006 /* Linux specific implementation */
2008 typedef unsigned32 linux_dev_t
;
2009 typedef unsigned32 linux_ino_t
;
2010 typedef unsigned32 linux_mode_t
;
2011 typedef unsigned16 linux_nlink_t
;
2012 typedef signed32 linux_off_t
;
2013 typedef signed32 linux_pid_t
;
2014 typedef unsigned32 linux_uid_t
;
2015 typedef unsigned32 linux_gid_t
;
2016 typedef unsigned32 linux_size_t
;
2017 typedef signed32 linux_ssize_t
;
2018 typedef signed32 linux_ptrdiff_t
;
2019 typedef signed32 linux_time_t
;
2020 typedef signed32 linux_clock_t
;
2021 typedef signed32 linux_daddr_t
;
2023 #ifdef HAVE_SYS_STAT_H
2024 /* For the PowerPC, don't both with the 'old' stat structure, since there
2025 should be no extant binaries with that structure. */
2030 linux_mode_t st_mode
;
2031 linux_nlink_t st_nlink
;
2034 linux_dev_t st_rdev
;
2035 linux_off_t st_size
;
2036 unsigned32 st_blksize
;
2037 unsigned32 st_blocks
;
2038 unsigned32 st_atimx
; /* don't use st_{a,c,m}time, that might a macro */
2039 unsigned32 __unused1
; /* defined by the host's stat.h */
2040 unsigned32 st_mtimx
;
2041 unsigned32 __unused2
;
2042 unsigned32 st_ctimx
;
2043 unsigned32 __unused3
;
2044 unsigned32 __unused4
;
2045 unsigned32 __unused5
;
2048 /* Convert from host stat structure to solaris stat structure */
2049 STATIC_INLINE_EMUL_UNIX
void
2050 convert_to_linux_stat(unsigned_word addr
,
2055 struct linux_stat target
;
2057 target
.st_dev
= H2T_4(host
->st_dev
);
2058 target
.st_ino
= H2T_4(host
->st_ino
);
2059 target
.st_mode
= H2T_4(host
->st_mode
);
2060 target
.st_nlink
= H2T_2(host
->st_nlink
);
2061 target
.st_uid
= H2T_4(host
->st_uid
);
2062 target
.st_gid
= H2T_4(host
->st_gid
);
2063 target
.st_size
= H2T_4(host
->st_size
);
2066 target
.st_rdev
= H2T_4(host
->st_rdev
);
2071 #ifdef HAVE_ST_BLKSIZE
2072 target
.st_blksize
= H2T_4(host
->st_blksize
);
2074 target
.st_blksize
= 0;
2077 #ifdef HAVE_ST_BLOCKS
2078 target
.st_blocks
= H2T_4(host
->st_blocks
);
2080 target
.st_blocks
= 0;
2083 target
.st_atimx
= H2T_4(host
->st_atime
);
2084 target
.st_ctimx
= H2T_4(host
->st_ctime
);
2085 target
.st_mtimx
= H2T_4(host
->st_mtime
);
2086 target
.__unused1
= 0;
2087 target
.__unused2
= 0;
2088 target
.__unused3
= 0;
2089 target
.__unused4
= 0;
2090 target
.__unused5
= 0;
2092 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2094 #endif /* HAVE_SYS_STAT_H */
2097 #define do_linux_stat 0
2100 do_linux_stat(os_emul_data
*emul
,
2106 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
2107 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2108 char path_buf
[PATH_MAX
];
2110 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
2113 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2114 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2116 status
= stat (path
, &buf
);
2118 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2120 emul_write_status(processor
, status
, errno
);
2125 #define do_linux_lstat 0
2128 do_linux_lstat(os_emul_data
*emul
,
2134 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
2135 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2136 char path_buf
[PATH_MAX
];
2138 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
2141 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2142 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2144 status
= lstat (path
, &buf
);
2146 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2148 emul_write_status(processor
, status
, errno
);
2153 #define do_linux_fstat 0
2156 do_linux_fstat(os_emul_data
*emul
,
2162 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
2163 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2167 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2168 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
2170 status
= fdbad (fildes
);
2172 status
= fstat (fildes
, &buf
);
2174 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2176 emul_write_status(processor
, status
, errno
);
2180 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2181 #define LINUX_NCC 10
2182 #define LINUX_NCCS 19
2184 #define LINUX_VINTR 0
2185 #define LINUX_VQUIT 1
2186 #define LINUX_VERASE 2
2187 #define LINUX_VKILL 3
2188 #define LINUX_VEOF 4
2189 #define LINUX_VMIN 5
2190 #define LINUX_VEOL 6
2191 #define LINUX_VTIME 7
2192 #define LINUX_VEOL2 8
2193 #define LINUX_VSWTC 9
2194 #define LINUX_VWERASE 10
2195 #define LINUX_VREPRINT 11
2196 #define LINUX_VSUSP 12
2197 #define LINUX_VSTART 13
2198 #define LINUX_VSTOP 14
2199 #define LINUX_VLNEXT 15
2200 #define LINUX_VDISCARD 16
2202 #define LINUX_IOC_NRBITS 8
2203 #define LINUX_IOC_TYPEBITS 8
2204 #define LINUX_IOC_SIZEBITS 13
2205 #define LINUX_IOC_DIRBITS 3
2207 #define LINUX_IOC_NRMASK ((1 << LINUX_IOC_NRBITS)-1)
2208 #define LINUX_IOC_TYPEMASK ((1 << LINUX_IOC_TYPEBITS)-1)
2209 #define LINUX_IOC_SIZEMASK ((1 << LINUX_IOC_SIZEBITS)-1)
2210 #define LINUX_IOC_DIRMASK ((1 << LINUX_IOC_DIRBITS)-1)
2212 #define LINUX_IOC_NRSHIFT 0
2213 #define LINUX_IOC_TYPESHIFT (LINUX_IOC_NRSHIFT+LINUX_IOC_NRBITS)
2214 #define LINUX_IOC_SIZESHIFT (LINUX_IOC_TYPESHIFT+LINUX_IOC_TYPEBITS)
2215 #define LINUX_IOC_DIRSHIFT (LINUX_IOC_SIZESHIFT+LINUX_IOC_SIZEBITS)
2218 * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
2219 * And this turns out useful to catch old ioctl numbers in header
2222 #define LINUX_IOC_NONE 1U
2223 #define LINUX_IOC_READ 2U
2224 #define LINUX_IOC_WRITE 4U
2226 #define LINUX_IOC(dir,type,nr,size) \
2227 (((dir) << LINUX_IOC_DIRSHIFT) | \
2228 ((type) << LINUX_IOC_TYPESHIFT) | \
2229 ((nr) << LINUX_IOC_NRSHIFT) | \
2230 ((size) << LINUX_IOC_SIZESHIFT))
2232 /* used to create numbers */
2233 #define LINUX_IO(type,nr) LINUX_IOC(LINUX_IOC_NONE,(type),(nr),0)
2234 #define LINUX_IOR(type,nr,size) LINUX_IOC(LINUX_IOC_READ,(type),(nr),sizeof(size))
2235 #define LINUX_IOW(type,nr,size) LINUX_IOC(LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2236 #define LINUX_IOWR(type,nr,size) LINUX_IOC(LINUX_IOC_READ|LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2239 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2240 /* Convert to/from host termio structure */
2242 struct linux_termio
{
2243 unsigned16 c_iflag
; /* input modes */
2244 unsigned16 c_oflag
; /* output modes */
2245 unsigned16 c_cflag
; /* control modes */
2246 unsigned16 c_lflag
; /* line discipline modes */
2247 unsigned8 c_line
; /* line discipline */
2248 unsigned8 c_cc
[LINUX_NCC
]; /* control chars */
2251 STATIC_INLINE_EMUL_UNIX
void
2252 convert_to_linux_termio(unsigned_word addr
,
2253 struct termio
*host
,
2257 struct linux_termio target
;
2260 target
.c_iflag
= H2T_2 (host
->c_iflag
);
2261 target
.c_oflag
= H2T_2 (host
->c_oflag
);
2262 target
.c_cflag
= H2T_2 (host
->c_cflag
);
2263 target
.c_lflag
= H2T_2 (host
->c_lflag
);
2265 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
2266 target
.c_line
= host
->c_line
;
2271 for (i
= 0; i
< LINUX_NCC
; i
++)
2275 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2279 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2283 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2287 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2291 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2295 target
.c_cc
[LINUX_VMIN
] = host
->c_cc
[VMIN
];
2299 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2303 target
.c_cc
[LINUX_VTIME
] = host
->c_cc
[VTIME
];
2307 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2311 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTC
];
2315 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2318 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2320 #endif /* HAVE_TERMIO_STRUCTURE */
2322 #ifdef HAVE_TERMIOS_STRUCTURE
2323 /* Convert to/from host termios structure */
2325 typedef unsigned32 linux_tcflag_t
;
2326 typedef unsigned8 linux_cc_t
;
2327 typedef unsigned32 linux_speed_t
;
2329 struct linux_termios
{
2330 linux_tcflag_t c_iflag
;
2331 linux_tcflag_t c_oflag
;
2332 linux_tcflag_t c_cflag
;
2333 linux_tcflag_t c_lflag
;
2334 linux_cc_t c_cc
[LINUX_NCCS
];
2340 STATIC_INLINE_EMUL_UNIX
void
2341 convert_to_linux_termios(unsigned_word addr
,
2342 struct termios
*host
,
2346 struct linux_termios target
;
2349 target
.c_iflag
= H2T_4 (host
->c_iflag
);
2350 target
.c_oflag
= H2T_4 (host
->c_oflag
);
2351 target
.c_cflag
= H2T_4 (host
->c_cflag
);
2352 target
.c_lflag
= H2T_4 (host
->c_lflag
);
2354 for (i
= 0; i
< LINUX_NCCS
; i
++)
2358 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2362 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2366 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2370 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2374 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2378 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2382 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2386 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2389 #ifdef HAVE_TERMIOS_CLINE
2390 target
.c_line
= host
->c_line
;
2395 #ifdef HAVE_CFGETISPEED
2396 target
.c_ispeed
= cfgetispeed (host
);
2398 target
.c_ispeed
= 0;
2401 #ifdef HAVE_CFGETOSPEED
2402 target
.c_ospeed
= cfgetospeed (host
);
2404 target
.c_ospeed
= 0;
2407 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2409 #endif /* HAVE_TERMIOS_STRUCTURE */
2412 #define do_linux_ioctl 0
2415 do_linux_ioctl(os_emul_data
*emul
,
2421 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
2422 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
2423 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
2425 const char *name
= "<unknown>";
2427 #ifdef HAVE_TERMIOS_STRUCTURE
2428 struct termios host_termio
;
2431 #ifdef HAVE_TERMIO_STRUCTURE
2432 struct termio host_termio
;
2436 status
= fdbad (fildes
);
2442 case 0: /* make sure we have at least one case */
2448 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2449 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
2450 case LINUX_IOR('t', 23, struct linux_termio
): /* TCGETA */
2452 #ifdef HAVE_TCGETATTR
2453 status
= tcgetattr(fildes
, &host_termio
);
2454 #elif defined(TCGETS)
2455 status
= ioctl (fildes
, TCGETS
, &host_termio
);
2457 status
= ioctl (fildes
, TCGETA
, &host_termio
);
2460 convert_to_linux_termio (argp_addr
, &host_termio
, processor
, cia
);
2463 #endif /* HAVE_TERMIO_STRUCTURE */
2465 #ifdef HAVE_TERMIOS_STRUCTURE
2466 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
2467 case LINUX_IOR('t', 19, struct linux_termios
): /* TCGETS */
2469 #ifdef HAVE_TCGETATTR
2470 status
= tcgetattr(fildes
, &host_termio
);
2472 status
= ioctl (fildes
, TCGETS
, &host_termio
);
2475 convert_to_linux_termios (argp_addr
, &host_termio
, processor
, cia
);
2478 #endif /* HAVE_TERMIOS_STRUCTURE */
2482 emul_write_status(processor
, status
, errno
);
2484 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2485 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
2487 #endif /* HAVE_IOCTL */
2489 static emul_syscall_descriptor linux_descriptors
[] = {
2490 /* 0 */ { 0, "setup" },
2491 /* 1 */ { do_unix_exit
, "exit" },
2492 /* 2 */ { 0, "fork" },
2493 /* 3 */ { do_unix_read
, "read" },
2494 /* 4 */ { do_unix_write
, "write" },
2495 /* 5 */ { do_unix_open
, "open" },
2496 /* 6 */ { do_unix_close
, "close" },
2497 /* 7 */ { 0, "waitpid" },
2498 /* 8 */ { 0, "creat" },
2499 /* 9 */ { do_unix_link
, "link" },
2500 /* 10 */ { do_unix_unlink
, "unlink" },
2501 /* 11 */ { 0, "execve" },
2502 /* 12 */ { do_unix_chdir
, "chdir" },
2503 /* 13 */ { do_unix_time
, "time" },
2504 /* 14 */ { 0, "mknod" },
2505 /* 15 */ { 0, "chmod" },
2506 /* 16 */ { 0, "chown" },
2507 /* 17 */ { 0, "break" },
2508 /* 18 */ { 0, "stat" },
2509 /* 19 */ { do_unix_lseek
, "lseek" },
2510 /* 20 */ { do_unix_getpid
, "getpid" },
2511 /* 21 */ { 0, "mount" },
2512 /* 22 */ { 0, "umount" },
2513 /* 23 */ { 0, "setuid" },
2514 /* 24 */ { do_unix_getuid
, "getuid" },
2515 /* 25 */ { 0, "stime" },
2516 /* 26 */ { 0, "ptrace" },
2517 /* 27 */ { 0, "alarm" },
2518 /* 28 */ { 0, "fstat" },
2519 /* 29 */ { 0, "pause" },
2520 /* 30 */ { 0, "utime" },
2521 /* 31 */ { 0, "stty" },
2522 /* 32 */ { 0, "gtty" },
2523 /* 33 */ { do_unix_access
, "access" },
2524 /* 34 */ { 0, "nice" },
2525 /* 35 */ { 0, "ftime" },
2526 /* 36 */ { 0, "sync" },
2527 /* 37 */ { 0, "kill" },
2528 /* 38 */ { 0, "rename" },
2529 /* 39 */ { do_unix_mkdir
, "mkdir" },
2530 /* 40 */ { do_unix_rmdir
, "rmdir" },
2531 /* 41 */ { do_unix_dup
, "dup" },
2532 /* 42 */ { 0, "pipe" },
2533 /* 43 */ { 0, "times" },
2534 /* 44 */ { 0, "prof" },
2535 /* 45 */ { do_unix_break
, "brk" },
2536 /* 46 */ { 0, "setgid" },
2537 /* 47 */ { do_unix_getgid
, "getgid" },
2538 /* 48 */ { 0, "signal" },
2539 /* 49 */ { do_unix_geteuid
, "geteuid" },
2540 /* 50 */ { do_unix_getegid
, "getegid" },
2541 /* 51 */ { 0, "acct" },
2542 /* 52 */ { 0, "phys" },
2543 /* 53 */ { 0, "lock" },
2544 /* 54 */ { do_linux_ioctl
, "ioctl" },
2545 /* 55 */ { 0, "fcntl" },
2546 /* 56 */ { 0, "mpx" },
2547 /* 57 */ { 0, "setpgid" },
2548 /* 58 */ { 0, "ulimit" },
2549 /* 59 */ { 0, "olduname" },
2550 /* 60 */ { do_unix_umask
, "umask" },
2551 /* 61 */ { 0, "chroot" },
2552 /* 62 */ { 0, "ustat" },
2553 /* 63 */ { do_unix_dup2
, "dup2" },
2554 /* 64 */ { do_unix_getppid
, "getppid" },
2555 /* 65 */ { 0, "getpgrp" },
2556 /* 66 */ { 0, "setsid" },
2557 /* 67 */ { 0, "sigaction" },
2558 /* 68 */ { 0, "sgetmask" },
2559 /* 69 */ { 0, "ssetmask" },
2560 /* 70 */ { 0, "setreuid" },
2561 /* 71 */ { 0, "setregid" },
2562 /* 72 */ { 0, "sigsuspend" },
2563 /* 73 */ { 0, "sigpending" },
2564 /* 74 */ { 0, "sethostname" },
2565 /* 75 */ { 0, "setrlimit" },
2566 /* 76 */ { 0, "getrlimit" },
2567 /* 77 */ { do_unix_getrusage
, "getrusage" },
2568 /* 78 */ { do_unix_gettimeofday
, "gettimeofday" },
2569 /* 79 */ { 0, "settimeofday" },
2570 /* 80 */ { 0, "getgroups" },
2571 /* 81 */ { 0, "setgroups" },
2572 /* 82 */ { 0, "select" },
2573 /* 83 */ { do_unix_symlink
, "symlink" },
2574 /* 84 */ { 0, "lstat" },
2575 /* 85 */ { 0, "readlink" },
2576 /* 86 */ { 0, "uselib" },
2577 /* 87 */ { 0, "swapon" },
2578 /* 88 */ { 0, "reboot" },
2579 /* 89 */ { 0, "readdir" },
2580 /* 90 */ { 0, "mmap" },
2581 /* 91 */ { 0, "munmap" },
2582 /* 92 */ { 0, "truncate" },
2583 /* 93 */ { 0, "ftruncate" },
2584 /* 94 */ { 0, "fchmod" },
2585 /* 95 */ { 0, "fchown" },
2586 /* 96 */ { 0, "getpriority" },
2587 /* 97 */ { 0, "setpriority" },
2588 /* 98 */ { 0, "profil" },
2589 /* 99 */ { 0, "statfs" },
2590 /* 100 */ { 0, "fstatfs" },
2591 /* 101 */ { 0, "ioperm" },
2592 /* 102 */ { 0, "socketcall" },
2593 /* 103 */ { 0, "syslog" },
2594 /* 104 */ { 0, "setitimer" },
2595 /* 105 */ { 0, "getitimer" },
2596 /* 106 */ { do_linux_stat
, "newstat" },
2597 /* 107 */ { do_linux_lstat
, "newlstat" },
2598 /* 108 */ { do_linux_fstat
, "newfstat" },
2599 /* 109 */ { 0, "uname" },
2600 /* 110 */ { 0, "iopl" },
2601 /* 111 */ { 0, "vhangup" },
2602 /* 112 */ { 0, "idle" },
2603 /* 113 */ { 0, "vm86" },
2604 /* 114 */ { 0, "wait4" },
2605 /* 115 */ { 0, "swapoff" },
2606 /* 116 */ { 0, "sysinfo" },
2607 /* 117 */ { 0, "ipc" },
2608 /* 118 */ { 0, "fsync" },
2609 /* 119 */ { 0, "sigreturn" },
2610 /* 120 */ { 0, "clone" },
2611 /* 121 */ { 0, "setdomainname" },
2612 /* 122 */ { 0, "newuname" },
2613 /* 123 */ { 0, "modify_ldt" },
2614 /* 124 */ { 0, "adjtimex" },
2615 /* 125 */ { 0, "mprotect" },
2616 /* 126 */ { 0, "sigprocmask" },
2617 /* 127 */ { 0, "create_module" },
2618 /* 128 */ { 0, "init_module" },
2619 /* 129 */ { 0, "delete_module" },
2620 /* 130 */ { 0, "get_kernel_syms" },
2621 /* 131 */ { 0, "quotactl" },
2622 /* 132 */ { 0, "getpgid" },
2623 /* 133 */ { 0, "fchdir" },
2624 /* 134 */ { 0, "bdflush" },
2625 /* 135 */ { 0, "sysfs" },
2626 /* 136 */ { 0, "personality" },
2627 /* 137 */ { 0, "afs_syscall" },
2628 /* 138 */ { 0, "setfsuid" },
2629 /* 139 */ { 0, "setfsgid" },
2630 /* 140 */ { 0, "llseek" },
2631 /* 141 */ { 0, "getdents" },
2632 /* 142 */ { 0, "newselect" },
2633 /* 143 */ { 0, "flock" },
2634 /* 144 */ { 0, "msync" },
2635 /* 145 */ { 0, "readv" },
2636 /* 146 */ { 0, "writev" },
2637 /* 147 */ { 0, "getsid" },
2638 /* 148 */ { 0, "fdatasync" },
2639 /* 149 */ { 0, "sysctl" },
2640 /* 150 */ { 0, "mlock" },
2641 /* 151 */ { 0, "munlock" },
2642 /* 152 */ { 0, "mlockall" },
2643 /* 153 */ { 0, "munlockall" },
2644 /* 154 */ { 0, "sched_setparam" },
2645 /* 155 */ { 0, "sched_getparam" },
2646 /* 156 */ { 0, "sched_setscheduler" },
2647 /* 157 */ { 0, "sched_getscheduler" },
2648 /* 158 */ { 0, "sched_yield" },
2649 /* 159 */ { 0, "sched_get_priority_max" },
2650 /* 160 */ { 0, "sched_get_priority_min" },
2651 /* 161 */ { 0, "sched_rr_get_interval" },
2654 static char *(linux_error_names
[]) = {
2691 /* 36 */ "ENAMETOOLONG",
2694 /* 39 */ "ENOTEMPTY",
2700 /* 45 */ "EL2NSYNC",
2713 /* 58 */ "EDEADLOCK",
2727 /* 72 */ "EMULTIHOP",
2730 /* 75 */ "EOVERFLOW",
2731 /* 76 */ "ENOTUNIQ",
2738 /* 83 */ "ELIBEXEC",
2740 /* 85 */ "ERESTART",
2741 /* 86 */ "ESTRPIPE",
2743 /* 88 */ "ENOTSOCK",
2744 /* 89 */ "EDESTADDRREQ",
2745 /* 90 */ "EMSGSIZE",
2746 /* 91 */ "EPROTOTYPE",
2747 /* 92 */ "ENOPROTOOPT",
2748 /* 93 */ "EPROTONOSUPPORT",
2749 /* 94 */ "ESOCKTNOSUPPORT",
2750 /* 95 */ "EOPNOTSUPP",
2751 /* 96 */ "EPFNOSUPPORT",
2752 /* 97 */ "EAFNOSUPPORT",
2753 /* 98 */ "EADDRINUSE",
2754 /* 99 */ "EADDRNOTAVAIL",
2755 /* 100 */ "ENETDOWN",
2756 /* 101 */ "ENETUNREACH",
2757 /* 102 */ "ENETRESET",
2758 /* 103 */ "ECONNABORTED",
2759 /* 104 */ "ECONNRESET",
2760 /* 105 */ "ENOBUFS",
2761 /* 106 */ "EISCONN",
2762 /* 107 */ "ENOTCONN",
2763 /* 108 */ "ESHUTDOWN",
2764 /* 109 */ "ETOOMANYREFS",
2765 /* 110 */ "ETIMEDOUT",
2766 /* 111 */ "ECONNREFUSED",
2767 /* 112 */ "EHOSTDOWN",
2768 /* 113 */ "EHOSTUNREACH",
2769 /* 114 */ "EALREADY",
2770 /* 115 */ "EINPROGRESS",
2772 /* 117 */ "EUCLEAN",
2773 /* 118 */ "ENOTNAM",
2774 /* 119 */ "ENAVAIL",
2776 /* 121 */ "EREMOTEIO",
2780 static char *(linux_signal_names
[]) = {
2798 /* 16 */ "SIGSTKFLT",
2808 /* 26 */ "SIGVTALRM",
2810 /* 28 */ "SIGWINCH",
2813 /* 31 */ "SIGUNUSED",
2816 static emul_syscall emul_linux_syscalls
= {
2818 ARRAY_SIZE (linux_descriptors
),
2820 ARRAY_SIZE (linux_error_names
),
2822 ARRAY_SIZE (linux_signal_names
),
2826 /* Linux's os_emul interface, most are just passed on to the generic
2829 static os_emul_data
*
2830 emul_linux_create(device
*root
,
2834 /* check that this emulation is really for us */
2835 if (name
!= NULL
&& strcmp(name
, "linux") != 0)
2841 return emul_unix_create(root
, image
, "linux", &emul_linux_syscalls
);
2845 emul_linux_init(os_emul_data
*emul_data
,
2854 emul_linux_system_call(cpu
*processor
,
2856 os_emul_data
*emul_data
)
2858 emul_do_system_call(emul_data
,
2859 emul_data
->syscalls
,
2860 cpu_registers(processor
)->gpr
[0],
2861 3, /*r3 contains arg0*/
2866 const os_emul emul_linux
= {
2870 emul_linux_system_call
,
2871 0, /*instruction_call*/
2875 #endif /* _EMUL_UNIX_C_ */