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"
39 #ifdef HAVE_SYS_TYPES_H
40 #include <sys/types.h>
43 #ifdef HAVE_SYS_TYPES_H
59 #ifdef HAVE_SYS_PARAM_H
60 #include <sys/param.h>
63 #ifdef HAVE_SYS_TIME_H
67 #ifndef HAVE_TERMIOS_STRUCTURE
68 #undef HAVE_SYS_TERMIOS_H
71 #ifndef HAVE_SYS_TERMIOS_H
72 #undef HAVE_TERMIOS_STRUCTURE
76 #ifdef HAVE_TERMIOS_STRUCTURE
77 #include <sys/termios.h>
79 /* If we have TERMIOS, use that for the termio structure, since some systems
80 don't like including both sys/termios.h and sys/termio.h at the same
82 #undef HAVE_TERMIO_STRUCTURE
85 #define termio termios
88 #ifndef HAVE_TERMIO_STRUCTURE
89 #undef HAVE_SYS_TERMIO_H
91 #ifndef HAVE_SYS_TERMIO_H
92 #undef HAVE_TERMIO_STRUCTURE
96 #ifdef HAVE_TERMIO_STRUCTURE
97 #include <sys/termio.h>
100 #ifdef HAVE_GETRUSAGE
101 #ifndef HAVE_SYS_RESOURCE_H
102 #undef HAVE_GETRUSAGE
106 #ifdef HAVE_GETRUSAGE
107 #include <sys/resource.h>
113 # define NAMLEN(dirent) strlen((dirent)->d_name)
115 # define dirent direct
116 # define NAMLEN(dirent) (dirent)->d_namlen
118 # include <sys/ndir.h>
121 # include <sys/dir.h>
129 #undef MAXPATHLEN /* sys/param.h might define this also */
137 #if defined(BSD) && !defined(errno) && (BSD < 199306) /* here BSD as just a bug */
141 #ifndef STATIC_INLINE_EMUL_UNIX
142 #define STATIC_INLINE_EMUL_UNIX STATIC_INLINE
146 #define PATH_MAX 1024
153 /* UNIX's idea of what is needed to implement emulations */
155 struct _os_emul_data
{
157 emul_syscall
*syscalls
;
161 /* Emulation of simple UNIX system calls that are common on all systems. */
163 /* Structures that are common agmonst the UNIX varients */
164 struct unix_timeval
{
165 signed32 tv_sec
; /* seconds */
166 signed32 tv_usec
; /* microseconds */
169 struct unix_timezone
{
170 signed32 tz_minuteswest
; /* minutes west of Greenwich */
171 signed32 tz_dsttime
; /* type of dst correction */
174 #define UNIX_RUSAGE_SELF 0
175 #define UNIX_RUSAGE_CHILDREN (-1)
176 #define UNIX_RUSAGE_BOTH (-2) /* sys_wait4() uses this */
179 struct unix_timeval ru_utime
; /* user time used */
180 struct unix_timeval ru_stime
; /* system time used */
181 signed32 ru_maxrss
; /* maximum resident set size */
182 signed32 ru_ixrss
; /* integral shared memory size */
183 signed32 ru_idrss
; /* integral unshared data size */
184 signed32 ru_isrss
; /* integral unshared stack size */
185 signed32 ru_minflt
; /* any page faults not requiring I/O */
186 signed32 ru_majflt
; /* any page faults requiring I/O */
187 signed32 ru_nswap
; /* swaps */
188 signed32 ru_inblock
; /* block input operations */
189 signed32 ru_oublock
; /* block output operations */
190 signed32 ru_msgsnd
; /* messages sent */
191 signed32 ru_msgrcv
; /* messages received */
192 signed32 ru_nsignals
; /* signals received */
193 signed32 ru_nvcsw
; /* voluntary context switches */
194 signed32 ru_nivcsw
; /* involuntary " */
198 /* File descriptors 0, 1, and 2 should not be closed. fd_closed[]
199 tracks whether these descriptors have been closed in do_close()
202 static int fd_closed
[3];
204 /* Check for some occurrences of bad file descriptors. We only check
205 whether fd 0, 1, or 2 are "closed". By "closed" we mean that these
206 descriptors aren't actually closed, but are considered to be closed
209 Other checks are performed by the underlying OS call. */
214 if (fd
>=0 && fd
<= 2 && fd_closed
[fd
])
223 do_unix_exit(os_emul_data
*emul
,
229 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
230 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
231 printf_filtered ("%d)\n", status
);
233 cpu_halt(processor
, cia
, was_exited
, status
);
238 do_unix_read(os_emul_data
*emul
,
244 void *scratch_buffer
;
245 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
246 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
247 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
250 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
251 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
253 /* get a tempoary bufer */
254 scratch_buffer
= zalloc(nbytes
);
256 /* check if buffer exists by reading it */
257 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
262 status
= read (d
, scratch_buffer
, nbytes
);
264 emul_write_status(processor
, status
, errno
);
266 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
268 free(scratch_buffer
);
273 do_unix_write(os_emul_data
*emul
,
279 void *scratch_buffer
= NULL
;
280 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
281 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
282 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
285 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
286 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
288 /* get a tempoary bufer */
289 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
292 emul_read_buffer(scratch_buffer
, buf
, nbytes
,
298 status
= write(d
, scratch_buffer
, nbytes
);
299 emul_write_status(processor
, status
, errno
);
300 free(scratch_buffer
);
307 do_unix_open(os_emul_data
*emul
,
313 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
314 char path_buf
[PATH_MAX
];
315 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
316 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
317 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
320 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
321 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
323 status
= open(path
, flags
, mode
);
324 emul_write_status(processor
, status
, errno
);
329 do_unix_close(os_emul_data
*emul
,
335 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
338 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
339 printf_filtered ("%d", d
);
344 /* Do not close stdin, stdout, or stderr. GDB may still need access to
345 these descriptors. */
346 if (d
== 0 || d
== 1 || d
== 2)
355 emul_write_status(processor
, status
, errno
);
360 do_unix_break(os_emul_data
*emul
,
366 /* just pass this onto the `vm' device */
367 unsigned_word new_break
= cpu_registers(processor
)->gpr
[arg0
];
370 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
371 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
373 status
= device_ioctl(emul
->vm
,
377 new_break
); /*ioctl-data*/
379 emul_write_status(processor
, 0, status
);
383 #define do_unix_access 0
386 do_unix_access(os_emul_data
*emul
,
392 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
393 char path_buf
[PATH_MAX
];
394 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
395 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
398 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
399 printf_filtered ("0x%lx [%s], 0x%x [0%o]", (long)path_addr
, path
, mode
, mode
);
401 status
= access(path
, mode
);
402 emul_write_status(processor
, status
, errno
);
407 #define do_unix_getpid 0
410 do_unix_getpid(os_emul_data
*emul
,
416 pid_t status
= getpid();
417 emul_write_status(processor
, (int)status
, errno
);
422 #define do_unix_getppid 0
425 do_unix_getppid(os_emul_data
*emul
,
431 pid_t status
= getppid();
432 emul_write_status(processor
, (int)status
, errno
);
436 #if !defined(HAVE_GETPID) || !defined(HAVE_GETPPID)
437 #define do_unix_getpid2 0
440 do_unix_getpid2(os_emul_data
*emul
,
446 int pid
= (int)getpid();
447 int ppid
= (int)getppid();
448 emul_write2_status(processor
, pid
, ppid
, errno
);
452 #if !defined(HAVE_GETUID) || !defined(HAVE_GETEUID)
453 #define do_unix_getuid2 0
456 do_unix_getuid2(os_emul_data
*emul
,
462 uid_t uid
= getuid();
463 uid_t euid
= geteuid();
464 emul_write2_status(processor
, (int)uid
, (int)euid
, errno
);
469 #define do_unix_getuid 0
472 do_unix_getuid(os_emul_data
*emul
,
478 uid_t status
= getuid();
479 emul_write_status(processor
, (int)status
, errno
);
484 #define do_unix_geteuid 0
487 do_unix_geteuid(os_emul_data
*emul
,
493 uid_t status
= geteuid();
494 emul_write_status(processor
, (int)status
, errno
);
500 #define do_unix_kill 0
503 do_unix_kill(os_emul_data
*emul
,
509 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
510 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
512 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
513 printf_filtered ("%d, %d", (int)pid
, sig
);
515 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
518 cpu_halt(processor
, cia
, was_signalled
, sig
);
524 #define do_unix_dup 0
527 do_unix_dup(os_emul_data
*emul
,
533 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
534 int status
= (fdbad (oldd
) < 0) ? -1 : dup(oldd
);
537 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
538 printf_filtered ("%d", oldd
);
540 emul_write_status(processor
, status
, err
);
545 #define do_unix_dup2 0
548 do_unix_dup2(os_emul_data
*emul
,
554 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
555 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
556 int status
= (fdbad (oldd
) < 0) ? -1 : dup2(oldd
, newd
);
559 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
560 printf_filtered ("%d, %d", oldd
, newd
);
562 emul_write_status(processor
, status
, err
);
567 #define do_unix_lseek 0
570 do_unix_lseek(os_emul_data
*emul
,
576 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
577 off_t offset
= (off_t
)cpu_registers(processor
)->gpr
[arg0
+1];
578 int whence
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
581 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
582 printf_filtered ("%d %ld %d", fildes
, (long)offset
, whence
);
584 status
= fdbad (fildes
);
586 status
= lseek(fildes
, offset
, whence
);
587 emul_write_status(processor
, (int)status
, errno
);
592 #if !defined(HAVE_GETGID) || !defined(HAVE_GETEGID)
593 #define do_unix_getgid2 0
596 do_unix_getgid2(os_emul_data
*emul
,
602 gid_t gid
= getgid();
603 gid_t egid
= getegid();
604 emul_write2_status(processor
, (int)gid
, (int)egid
, errno
);
609 #define do_unix_getgid 0
612 do_unix_getgid(os_emul_data
*emul
,
618 gid_t status
= getgid();
619 emul_write_status(processor
, (int)status
, errno
);
624 #define do_unix_getegid 0
627 do_unix_getegid(os_emul_data
*emul
,
633 gid_t status
= getegid();
634 emul_write_status(processor
, (int)status
, errno
);
639 #define do_unix_umask 0
642 do_unix_umask(os_emul_data
*emul
,
648 mode_t mask
= (mode_t
)cpu_registers(processor
)->gpr
[arg0
];
649 int status
= umask(mask
);
651 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
652 printf_filtered ("0%o", (unsigned int)mask
);
654 emul_write_status(processor
, status
, errno
);
659 #define do_unix_chdir 0
662 do_unix_chdir(os_emul_data
*emul
,
668 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
669 char path_buf
[PATH_MAX
];
670 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
673 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
674 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
676 status
= chdir(path
);
677 emul_write_status(processor
, status
, errno
);
682 #define do_unix_link 0
685 do_unix_link(os_emul_data
*emul
,
691 unsigned_word path1_addr
= cpu_registers(processor
)->gpr
[arg0
];
692 char path1_buf
[PATH_MAX
];
693 char *path1
= emul_read_string(path1_buf
, path1_addr
, PATH_MAX
, processor
, cia
);
694 unsigned_word path2_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
695 char path2_buf
[PATH_MAX
];
696 char *path2
= emul_read_string(path2_buf
, path2_addr
, PATH_MAX
, processor
, cia
);
699 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
700 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr
, path1
, (long)path2_addr
, path2
);
702 status
= link(path1
, path2
);
703 emul_write_status(processor
, status
, errno
);
708 #define do_unix_symlink 0
711 do_unix_symlink(os_emul_data
*emul
,
717 unsigned_word path1_addr
= cpu_registers(processor
)->gpr
[arg0
];
718 char path1_buf
[PATH_MAX
];
719 char *path1
= emul_read_string(path1_buf
, path1_addr
, PATH_MAX
, processor
, cia
);
720 unsigned_word path2_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
721 char path2_buf
[PATH_MAX
];
722 char *path2
= emul_read_string(path2_buf
, path2_addr
, PATH_MAX
, processor
, cia
);
725 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
726 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr
, path1
, (long)path2_addr
, path2
);
728 status
= symlink(path1
, path2
);
729 emul_write_status(processor
, status
, errno
);
734 #define do_unix_unlink 0
737 do_unix_unlink(os_emul_data
*emul
,
743 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
744 char path_buf
[PATH_MAX
];
745 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
748 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
749 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
751 status
= unlink(path
);
752 emul_write_status(processor
, status
, errno
);
757 #define do_unix_mkdir 0
760 do_unix_mkdir(os_emul_data
*emul
,
766 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
767 char path_buf
[PATH_MAX
];
768 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
769 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
772 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
773 printf_filtered ("0x%lx [%s], 0%3o", (long)path_addr
, path
, mode
);
776 status
= mkdir(path
);
778 status
= mkdir(path
, mode
);
780 emul_write_status(processor
, status
, errno
);
785 #define do_unix_rmdir 0
788 do_unix_rmdir(os_emul_data
*emul
,
794 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
795 char path_buf
[PATH_MAX
];
796 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
799 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
800 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
802 status
= rmdir(path
);
803 emul_write_status(processor
, status
, errno
);
808 #define do_unix_time 0
811 do_unix_time(os_emul_data
*emul
,
817 unsigned_word tp
= cpu_registers(processor
)->gpr
[arg0
];
818 time_t now
= time ((time_t *)0);
819 unsigned_word status
= H2T_4(now
);
821 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
822 printf_filtered ("0x%lx", (long)tp
);
824 emul_write_status(processor
, (int)status
, errno
);
827 emul_write_buffer(&status
, tp
, sizeof(status
), processor
, cia
);
831 #if !defined(HAVE_GETTIMEOFDAY) || !defined(HAVE_SYS_TIME_H)
832 #define do_unix_gettimeofday 0
835 do_unix_gettimeofday(os_emul_data
*emul
,
841 unsigned_word tv
= cpu_registers(processor
)->gpr
[arg0
];
842 unsigned_word tz
= cpu_registers(processor
)->gpr
[arg0
+1];
843 struct unix_timeval target_timeval
;
844 struct timeval host_timeval
;
845 struct unix_timezone target_timezone
;
846 struct timezone host_timezone
;
849 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
850 printf_filtered ("0x%lx, 0x%lx", (long)tv
, (long)tz
);
852 /* Just in case the system doesn't set the timezone structure */
853 host_timezone
.tz_minuteswest
= 0;
854 host_timezone
.tz_dsttime
= 0;
856 status
= gettimeofday(&host_timeval
, &host_timezone
);
859 target_timeval
.tv_sec
= H2T_4(host_timeval
.tv_sec
);
860 target_timeval
.tv_usec
= H2T_4(host_timeval
.tv_usec
);
861 emul_write_buffer((void *) &target_timeval
, tv
, sizeof(target_timeval
), processor
, cia
);
865 target_timezone
.tz_minuteswest
= H2T_4(host_timezone
.tz_minuteswest
);
866 target_timezone
.tz_dsttime
= H2T_4(host_timezone
.tz_dsttime
);
867 emul_write_buffer((void *) &target_timezone
, tv
, sizeof(target_timezone
), processor
, cia
);
871 emul_write_status(processor
, (int)status
, errno
);
876 #ifndef HAVE_GETRUSAGE
877 #define do_unix_getrusage 0
880 do_unix_getrusage(os_emul_data
*emul
,
886 signed_word who
= (signed_word
)cpu_registers(processor
)->gpr
[arg0
];
887 unsigned_word usage
= cpu_registers(processor
)->gpr
[arg0
+1];
888 struct rusage host_rusage
, host_rusage2
;
889 struct unix_rusage target_rusage
;
892 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
893 printf_filtered ("%ld, 0x%lx", (long)who
, (long)usage
);
901 case UNIX_RUSAGE_SELF
:
902 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
905 case UNIX_RUSAGE_CHILDREN
:
906 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage
);
909 case UNIX_RUSAGE_BOTH
:
910 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
912 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage2
);
914 host_rusage
.ru_utime
.tv_sec
+= host_rusage2
.ru_utime
.tv_sec
;
915 host_rusage
.ru_utime
.tv_usec
+= host_rusage2
.ru_utime
.tv_usec
;
916 host_rusage
.ru_stime
.tv_sec
+= host_rusage2
.ru_stime
.tv_sec
;
917 host_rusage
.ru_stime
.tv_usec
+= host_rusage2
.ru_stime
.tv_usec
;
918 host_rusage
.ru_maxrss
+= host_rusage2
.ru_maxrss
;
919 host_rusage
.ru_ixrss
+= host_rusage2
.ru_ixrss
;
920 host_rusage
.ru_idrss
+= host_rusage2
.ru_idrss
;
921 host_rusage
.ru_isrss
+= host_rusage2
.ru_isrss
;
922 host_rusage
.ru_minflt
+= host_rusage2
.ru_minflt
;
923 host_rusage
.ru_majflt
+= host_rusage2
.ru_majflt
;
924 host_rusage
.ru_nswap
+= host_rusage2
.ru_nswap
;
925 host_rusage
.ru_inblock
+= host_rusage2
.ru_inblock
;
926 host_rusage
.ru_oublock
+= host_rusage2
.ru_oublock
;
927 host_rusage
.ru_msgsnd
+= host_rusage2
.ru_msgsnd
;
928 host_rusage
.ru_msgrcv
+= host_rusage2
.ru_msgrcv
;
929 host_rusage
.ru_nsignals
+= host_rusage2
.ru_nsignals
;
930 host_rusage
.ru_nvcsw
+= host_rusage2
.ru_nvcsw
;
931 host_rusage
.ru_nivcsw
+= host_rusage2
.ru_nivcsw
;
937 target_rusage
.ru_utime
.tv_sec
= H2T_4(host_rusage2
.ru_utime
.tv_sec
);
938 target_rusage
.ru_utime
.tv_usec
= H2T_4(host_rusage2
.ru_utime
.tv_usec
);
939 target_rusage
.ru_stime
.tv_sec
= H2T_4(host_rusage2
.ru_stime
.tv_sec
);
940 target_rusage
.ru_stime
.tv_usec
= H2T_4(host_rusage2
.ru_stime
.tv_usec
);
941 target_rusage
.ru_maxrss
= H2T_4(host_rusage2
.ru_maxrss
);
942 target_rusage
.ru_ixrss
= H2T_4(host_rusage2
.ru_ixrss
);
943 target_rusage
.ru_idrss
= H2T_4(host_rusage2
.ru_idrss
);
944 target_rusage
.ru_isrss
= H2T_4(host_rusage2
.ru_isrss
);
945 target_rusage
.ru_minflt
= H2T_4(host_rusage2
.ru_minflt
);
946 target_rusage
.ru_majflt
= H2T_4(host_rusage2
.ru_majflt
);
947 target_rusage
.ru_nswap
= H2T_4(host_rusage2
.ru_nswap
);
948 target_rusage
.ru_inblock
= H2T_4(host_rusage2
.ru_inblock
);
949 target_rusage
.ru_oublock
= H2T_4(host_rusage2
.ru_oublock
);
950 target_rusage
.ru_msgsnd
= H2T_4(host_rusage2
.ru_msgsnd
);
951 target_rusage
.ru_msgrcv
= H2T_4(host_rusage2
.ru_msgrcv
);
952 target_rusage
.ru_nsignals
= H2T_4(host_rusage2
.ru_nsignals
);
953 target_rusage
.ru_nvcsw
= H2T_4(host_rusage2
.ru_nvcsw
);
954 target_rusage
.ru_nivcsw
= H2T_4(host_rusage2
.ru_nivcsw
);
955 emul_write_buffer((void *) &target_rusage
, usage
, sizeof(target_rusage
), processor
, cia
);
958 emul_write_status(processor
, status
, errno
);
964 do_unix_nop(os_emul_data
*emul
,
970 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
971 printf_filtered ("0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
972 (long)cpu_registers(processor
)->gpr
[arg0
],
973 (long)cpu_registers(processor
)->gpr
[arg0
+1],
974 (long)cpu_registers(processor
)->gpr
[arg0
+2],
975 (long)cpu_registers(processor
)->gpr
[arg0
+3],
976 (long)cpu_registers(processor
)->gpr
[arg0
+4],
977 (long)cpu_registers(processor
)->gpr
[arg0
+5]);
979 emul_write_status(processor
, 0, errno
);
983 /* Common code for initializing the system call stuff */
985 static os_emul_data
*
986 emul_unix_create(device
*root
,
989 emul_syscall
*syscall
)
991 unsigned_word top_of_stack
;
998 /* merge any emulation specific entries into the device tree */
1000 /* establish a few defaults */
1001 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
1003 top_of_stack
= 0xe0000000;
1004 stack_size
= 0x00100000;
1008 top_of_stack
= 0x20000000;
1009 stack_size
= 0x00100000;
1013 emul_add_tree_options(root
, image
, name
,
1014 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
1015 ? "user" : "virtual"),
1016 0 /*oea-interrupt-prefix*/);
1018 /* virtual memory - handles growth of stack/heap */
1019 vm
= tree_parse(root
, "/openprom/vm@0x%lx",
1020 (unsigned long)(top_of_stack
- stack_size
));
1021 tree_parse(vm
, "./stack-base 0x%lx",
1022 (unsigned long)(top_of_stack
- stack_size
));
1023 tree_parse(vm
, "./nr-bytes 0x%x", stack_size
);
1025 filename
= tree_quote_property (bfd_get_filename(image
));
1026 tree_parse(root
, "/openprom/vm/map-binary/file-name %s",
1030 /* finish the init */
1031 tree_parse(root
, "/openprom/init/register/pc 0x%lx",
1032 (unsigned long)bfd_get_start_address(image
));
1033 tree_parse(root
, "/openprom/init/register/sp 0x%lx",
1034 (unsigned long)top_of_stack
);
1035 tree_parse(root
, "/openprom/init/register/msr 0x%x",
1036 ((tree_find_boolean_property(root
, "/options/little-endian?")
1037 ? msr_little_endian_mode
1039 | (tree_find_boolean_property(root
, "/openprom/options/floating-point?")
1040 ? (msr_floating_point_available
1041 | msr_floating_point_exception_mode_0
1042 | msr_floating_point_exception_mode_1
)
1044 tree_parse(root
, "/openprom/init/stack/stack-type %s",
1045 (elf_binary
? "ppc-elf" : "ppc-xcoff"));
1047 /* finally our emulation data */
1048 data
= ZALLOC(os_emul_data
);
1050 data
->syscalls
= syscall
;
1057 Solaris - Emulation of user programs for Solaris/PPC
1064 /* Solaris specific implementation */
1066 typedef signed32 solaris_uid_t
;
1067 typedef signed32 solaris_gid_t
;
1068 typedef signed32 solaris_off_t
;
1069 typedef signed32 solaris_pid_t
;
1070 typedef signed32 solaris_time_t
;
1071 typedef unsigned32 solaris_dev_t
;
1072 typedef unsigned32 solaris_ino_t
;
1073 typedef unsigned32 solaris_mode_t
;
1074 typedef unsigned32 solaris_nlink_t
;
1076 #ifdef HAVE_SYS_STAT_H
1077 #define SOLARIS_ST_FSTYPSZ 16 /* array size for file system type name */
1079 /* AIX 7.1 defines st_pad[123] to st_[amc]tim.tv_pad, respectively */
1084 struct solaris_stat
{
1085 solaris_dev_t st_dev
;
1086 signed32 st_pad1
[3]; /* reserved for network id */
1087 solaris_ino_t st_ino
;
1088 solaris_mode_t st_mode
;
1089 solaris_nlink_t st_nlink
;
1090 solaris_uid_t st_uid
;
1091 solaris_gid_t st_gid
;
1092 solaris_dev_t st_rdev
;
1093 signed32 st_pad2
[2];
1094 solaris_off_t st_size
;
1095 signed32 st_pad3
; /* future off_t expansion */
1096 struct unix_timeval st_atim
;
1097 struct unix_timeval st_mtim
;
1098 struct unix_timeval st_ctim
;
1099 signed32 st_blksize
;
1101 char st_fstype
[SOLARIS_ST_FSTYPSZ
];
1102 signed32 st_pad4
[8]; /* expansion area */
1105 /* Convert from host stat structure to solaris stat structure */
1106 STATIC_INLINE_EMUL_UNIX
void
1107 convert_to_solaris_stat(unsigned_word addr
,
1112 struct solaris_stat target
;
1115 target
.st_dev
= H2T_4(host
->st_dev
);
1116 target
.st_ino
= H2T_4(host
->st_ino
);
1117 target
.st_mode
= H2T_4(host
->st_mode
);
1118 target
.st_nlink
= H2T_4(host
->st_nlink
);
1119 target
.st_uid
= H2T_4(host
->st_uid
);
1120 target
.st_gid
= H2T_4(host
->st_gid
);
1121 target
.st_size
= H2T_4(host
->st_size
);
1124 target
.st_rdev
= H2T_4(host
->st_rdev
);
1129 #ifdef HAVE_ST_BLKSIZE
1130 target
.st_blksize
= H2T_4(host
->st_blksize
);
1132 target
.st_blksize
= 0;
1135 #ifdef HAVE_ST_BLOCKS
1136 target
.st_blocks
= H2T_4(host
->st_blocks
);
1138 target
.st_blocks
= 0;
1141 target
.st_atim
.tv_sec
= H2T_4(host
->st_atime
);
1142 target
.st_atim
.tv_usec
= 0;
1144 target
.st_ctim
.tv_sec
= H2T_4(host
->st_ctime
);
1145 target
.st_ctim
.tv_usec
= 0;
1147 target
.st_mtim
.tv_sec
= H2T_4(host
->st_mtime
);
1148 target
.st_mtim
.tv_usec
= 0;
1150 for (i
= 0; i
< ARRAY_SIZE (target
.st_pad1
); i
++)
1151 target
.st_pad1
[i
] = 0;
1153 for (i
= 0; i
< ARRAY_SIZE (target
.st_pad2
); i
++)
1154 target
.st_pad2
[i
] = 0;
1158 for (i
= 0; i
< ARRAY_SIZE (target
.st_pad4
); i
++)
1159 target
.st_pad4
[i
] = 0;
1161 /* For now, just punt and always say it is a ufs file */
1162 strcpy (target
.st_fstype
, "ufs");
1164 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1166 #endif /* HAVE_SYS_STAT_H */
1169 #define do_solaris_stat 0
1172 do_solaris_stat(os_emul_data
*emul
,
1178 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1179 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1180 char path_buf
[PATH_MAX
];
1182 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1185 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1186 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1188 status
= stat (path
, &buf
);
1190 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1192 emul_write_status(processor
, status
, errno
);
1197 #define do_solaris_lstat 0
1200 do_solaris_lstat(os_emul_data
*emul
,
1206 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1207 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1208 char path_buf
[PATH_MAX
];
1210 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1213 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1214 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1216 status
= lstat (path
, &buf
);
1218 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1220 emul_write_status(processor
, status
, errno
);
1225 #define do_solaris_fstat 0
1228 do_solaris_fstat(os_emul_data
*emul
,
1234 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
1235 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1239 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1240 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
1242 status
= fdbad (fildes
);
1244 status
= fstat (fildes
, &buf
);
1246 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1248 emul_write_status(processor
, status
, errno
);
1252 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1253 #define SOLARIS_TIOC ('T'<<8)
1254 #define SOLARIS_NCC 8
1255 #define SOLARIS_NCCS 19
1257 #define SOLARIS_VINTR 0
1258 #define SOLARIS_VQUIT 1
1259 #define SOLARIS_VERASE 2
1260 #define SOLARIS_VKILL 3
1261 #define SOLARIS_VEOF 4
1262 #define SOLARIS_VEOL 5
1263 #define SOLARIS_VEOL2 6
1264 #define SOLARIS_VSWTCH 7
1265 #define SOLARIS_VSTART 8
1266 #define SOLARIS_VSTOP 9
1267 #define SOLARIS_VSUSP 10
1268 #define SOLARIS_VDSUSP 11
1269 #define SOLARIS_VREPRINT 12
1270 #define SOLARIS_VDISCARD 13
1271 #define SOLARIS_VWERASE 14
1272 #define SOLARIS_VLNEXT 15
1275 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1276 /* Convert to/from host termio structure */
1278 struct solaris_termio
{
1279 unsigned16 c_iflag
; /* input modes */
1280 unsigned16 c_oflag
; /* output modes */
1281 unsigned16 c_cflag
; /* control modes */
1282 unsigned16 c_lflag
; /* line discipline modes */
1283 unsigned8 c_line
; /* line discipline */
1284 unsigned8 c_cc
[SOLARIS_NCC
]; /* control chars */
1287 STATIC_INLINE_EMUL_UNIX
void
1288 convert_to_solaris_termio(unsigned_word addr
,
1289 struct termio
*host
,
1293 struct solaris_termio target
;
1296 target
.c_iflag
= H2T_2 (host
->c_iflag
);
1297 target
.c_oflag
= H2T_2 (host
->c_oflag
);
1298 target
.c_cflag
= H2T_2 (host
->c_cflag
);
1299 target
.c_lflag
= H2T_2 (host
->c_lflag
);
1301 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
1302 target
.c_line
= host
->c_line
;
1307 for (i
= 0; i
< SOLARIS_NCC
; i
++)
1311 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1315 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1319 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1323 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1327 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1331 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1335 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1339 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1343 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1347 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1349 #endif /* HAVE_TERMIO_STRUCTURE || HAVE_TERMIOS_STRUCTURE */
1351 #ifdef HAVE_TERMIOS_STRUCTURE
1352 /* Convert to/from host termios structure */
1354 typedef unsigned32 solaris_tcflag_t
;
1355 typedef unsigned8 solaris_cc_t
;
1356 typedef unsigned32 solaris_speed_t
;
1358 struct solaris_termios
{
1359 solaris_tcflag_t c_iflag
;
1360 solaris_tcflag_t c_oflag
;
1361 solaris_tcflag_t c_cflag
;
1362 solaris_tcflag_t c_lflag
;
1363 solaris_cc_t c_cc
[SOLARIS_NCCS
];
1366 STATIC_INLINE_EMUL_UNIX
void
1367 convert_to_solaris_termios(unsigned_word addr
,
1368 struct termios
*host
,
1372 struct solaris_termios target
;
1375 target
.c_iflag
= H2T_4 (host
->c_iflag
);
1376 target
.c_oflag
= H2T_4 (host
->c_oflag
);
1377 target
.c_cflag
= H2T_4 (host
->c_cflag
);
1378 target
.c_lflag
= H2T_4 (host
->c_lflag
);
1380 for (i
= 0; i
< SOLARIS_NCCS
; i
++)
1384 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1388 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1392 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1396 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1400 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1404 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1408 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1412 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1416 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1421 target
.c_cc
[SOLARIS_VSTART
] = host
->c_cc
[VSTART
];
1425 target
.c_cc
[SOLARIS_VSTOP
] = host
->c_cc
[VSTOP
];
1429 target
.c_cc
[SOLARIS_VSUSP
] = host
->c_cc
[VSUSP
];
1433 target
.c_cc
[SOLARIS_VDSUSP
] = host
->c_cc
[VDSUSP
];
1437 target
.c_cc
[SOLARIS_VREPRINT
] = host
->c_cc
[VREPRINT
];
1441 target
.c_cc
[SOLARIS_VDISCARD
] = host
->c_cc
[VDISCARD
];
1445 target
.c_cc
[SOLARIS_VWERASE
] = host
->c_cc
[VWERASE
];
1449 target
.c_cc
[SOLARIS_VLNEXT
] = host
->c_cc
[VLNEXT
];
1452 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1454 #endif /* HAVE_TERMIOS_STRUCTURE */
1457 #define do_solaris_ioctl 0
1460 do_solaris_ioctl(os_emul_data
*emul
,
1466 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
1467 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
1468 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
1470 const char *name
= "<unknown>";
1472 #ifdef HAVE_TERMIOS_STRUCTURE
1473 struct termios host_termio
;
1476 #ifdef HAVE_TERMIO_STRUCTURE
1477 struct termio host_termio
;
1481 status
= fdbad (fildes
);
1487 case 0: /* make sure we have at least one case */
1493 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1494 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
1495 case SOLARIS_TIOC
| 1: /* TCGETA */
1497 #ifdef HAVE_TCGETATTR
1498 status
= tcgetattr(fildes
, &host_termio
);
1499 #elif defined(TCGETS)
1500 status
= ioctl (fildes
, TCGETS
, &host_termio
);
1502 status
= ioctl (fildes
, TCGETA
, &host_termio
);
1505 convert_to_solaris_termio (argp_addr
, &host_termio
, processor
, cia
);
1508 #endif /* HAVE_TERMIO_STRUCTURE */
1510 #ifdef HAVE_TERMIOS_STRUCTURE
1511 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
1512 case SOLARIS_TIOC
| 13: /* TCGETS */
1514 #ifdef HAVE_TCGETATTR
1515 status
= tcgetattr(fildes
, &host_termio
);
1517 status
= ioctl (fildes
, TCGETS
, &host_termio
);
1520 convert_to_solaris_termios (argp_addr
, &host_termio
, processor
, cia
);
1523 #endif /* HAVE_TERMIOS_STRUCTURE */
1527 emul_write_status(processor
, status
, errno
);
1529 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1530 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
1532 #endif /* HAVE_IOCTL */
1534 static emul_syscall_descriptor solaris_descriptors
[] = {
1535 /* 0 */ { 0, "syscall" },
1536 /* 1 */ { do_unix_exit
, "exit" },
1537 /* 2 */ { 0, "fork" },
1538 /* 3 */ { do_unix_read
, "read" },
1539 /* 4 */ { do_unix_write
, "write" },
1540 /* 5 */ { do_unix_open
, "open" },
1541 /* 6 */ { do_unix_close
, "close" },
1542 /* 7 */ { 0, "wait" },
1543 /* 8 */ { 0, "creat" },
1544 /* 9 */ { do_unix_link
, "link" },
1545 /* 10 */ { do_unix_unlink
, "unlink" },
1546 /* 11 */ { 0, "exec" },
1547 /* 12 */ { do_unix_chdir
, "chdir" },
1548 /* 13 */ { do_unix_time
, "time" },
1549 /* 14 */ { 0, "mknod" },
1550 /* 15 */ { 0, "chmod" },
1551 /* 16 */ { 0, "chown" },
1552 /* 17 */ { do_unix_break
, "brk" },
1553 /* 18 */ { do_solaris_stat
, "stat" },
1554 /* 19 */ { do_unix_lseek
, "lseek" },
1555 /* 20 */ { do_unix_getpid2
, "getpid" },
1556 /* 21 */ { 0, "mount" },
1557 /* 22 */ { 0, "umount" },
1558 /* 23 */ { 0, "setuid" },
1559 /* 24 */ { do_unix_getuid2
, "getuid" },
1560 /* 25 */ { 0, "stime" },
1561 /* 26 */ { 0, "ptrace" },
1562 /* 27 */ { 0, "alarm" },
1563 /* 28 */ { do_solaris_fstat
, "fstat" },
1564 /* 29 */ { 0, "pause" },
1565 /* 30 */ { 0, "utime" },
1566 /* 31 */ { 0, "stty" },
1567 /* 32 */ { 0, "gtty" },
1568 /* 33 */ { do_unix_access
, "access" },
1569 /* 34 */ { 0, "nice" },
1570 /* 35 */ { 0, "statfs" },
1571 /* 36 */ { 0, "sync" },
1572 /* 37 */ { 0, "kill" },
1573 /* 38 */ { 0, "fstatfs" },
1574 /* 39 */ { 0, "pgrpsys" },
1575 /* 40 */ { 0, "xenix" },
1576 /* 41 */ { do_unix_dup
, "dup" },
1577 /* 42 */ { 0, "pipe" },
1578 /* 43 */ { 0, "times" },
1579 /* 44 */ { 0, "profil" },
1580 /* 45 */ { 0, "plock" },
1581 /* 46 */ { 0, "setgid" },
1582 /* 47 */ { do_unix_getgid2
, "getgid" },
1583 /* 48 */ { 0, "signal" },
1584 /* 49 */ { 0, "msgsys" },
1585 /* 50 */ { 0, "syssun" },
1586 /* 51 */ { 0, "acct" },
1587 /* 52 */ { 0, "shmsys" },
1588 /* 53 */ { 0, "semsys" },
1589 /* 54 */ { do_solaris_ioctl
, "ioctl" },
1590 /* 55 */ { 0, "uadmin" },
1591 /* 56 */ { 0, 0 /* reserved for exch */ },
1592 /* 57 */ { 0, "utssys" },
1593 /* 58 */ { 0, "fdsync" },
1594 /* 59 */ { 0, "execve" },
1595 /* 60 */ { do_unix_umask
, "umask" },
1596 /* 61 */ { 0, "chroot" },
1597 /* 62 */ { 0, "fcntl" },
1598 /* 63 */ { 0, "ulimit" },
1599 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1600 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1601 /* 65 */ { 0, 0 /* reserved for UNIX PC */ },
1602 /* 66 */ { 0, 0 /* reserved for UNIX PC */ },
1603 /* 67 */ { 0, 0 /* reserved for UNIX PC */ },
1604 /* 68 */ { 0, 0 /* reserved for UNIX PC */ },
1605 /* 69 */ { 0, 0 /* reserved for UNIX PC */ },
1606 /* 70 */ { 0, 0 /* was advfs */ },
1607 /* 71 */ { 0, 0 /* was unadvfs */ },
1608 /* 72 */ { 0, 0 /* was rmount */ },
1609 /* 73 */ { 0, 0 /* was rumount */ },
1610 /* 74 */ { 0, 0 /* was rfstart */ },
1611 /* 75 */ { 0, 0 /* was sigret */ },
1612 /* 76 */ { 0, 0 /* was rdebug */ },
1613 /* 77 */ { 0, 0 /* was rfstop */ },
1614 /* 78 */ { 0, 0 /* was rfsys */ },
1615 /* 79 */ { do_unix_rmdir
, "rmdir" },
1616 /* 80 */ { do_unix_mkdir
, "mkdir" },
1617 /* 81 */ { 0, "getdents" },
1618 /* 82 */ { 0, 0 /* was libattach */ },
1619 /* 83 */ { 0, 0 /* was libdetach */ },
1620 /* 84 */ { 0, "sysfs" },
1621 /* 85 */ { 0, "getmsg" },
1622 /* 86 */ { 0, "putmsg" },
1623 /* 87 */ { 0, "poll" },
1624 /* 88 */ { do_solaris_lstat
, "lstat" },
1625 /* 89 */ { do_unix_symlink
, "symlink" },
1626 /* 90 */ { 0, "readlink" },
1627 /* 91 */ { 0, "setgroups" },
1628 /* 92 */ { 0, "getgroups" },
1629 /* 93 */ { 0, "fchmod" },
1630 /* 94 */ { 0, "fchown" },
1631 /* 95 */ { 0, "sigprocmask" },
1632 /* 96 */ { 0, "sigsuspend" },
1633 /* 97 */ { do_unix_nop
, "sigaltstack" },
1634 /* 98 */ { do_unix_nop
, "sigaction" },
1635 /* 99 */ { 0, "sigpending" },
1636 /* 100 */ { 0, "context" },
1637 /* 101 */ { 0, "evsys" },
1638 /* 102 */ { 0, "evtrapret" },
1639 /* 103 */ { 0, "statvfs" },
1640 /* 104 */ { 0, "fstatvfs" },
1641 /* 105 */ { 0, 0 /* reserved */ },
1642 /* 106 */ { 0, "nfssys" },
1643 /* 107 */ { 0, "waitsys" },
1644 /* 108 */ { 0, "sigsendsys" },
1645 /* 109 */ { 0, "hrtsys" },
1646 /* 110 */ { 0, "acancel" },
1647 /* 111 */ { 0, "async" },
1648 /* 112 */ { 0, "priocntlsys" },
1649 /* 113 */ { 0, "pathconf" },
1650 /* 114 */ { 0, "mincore" },
1651 /* 115 */ { 0, "mmap" },
1652 /* 116 */ { 0, "mprotect" },
1653 /* 117 */ { 0, "munmap" },
1654 /* 118 */ { 0, "fpathconf" },
1655 /* 119 */ { 0, "vfork" },
1656 /* 120 */ { 0, "fchdir" },
1657 /* 121 */ { 0, "readv" },
1658 /* 122 */ { 0, "writev" },
1659 /* 123 */ { 0, "xstat" },
1660 /* 124 */ { 0, "lxstat" },
1661 /* 125 */ { 0, "fxstat" },
1662 /* 126 */ { 0, "xmknod" },
1663 /* 127 */ { 0, "clocal" },
1664 /* 128 */ { 0, "setrlimit" },
1665 /* 129 */ { 0, "getrlimit" },
1666 /* 130 */ { 0, "lchown" },
1667 /* 131 */ { 0, "memcntl" },
1668 /* 132 */ { 0, "getpmsg" },
1669 /* 133 */ { 0, "putpmsg" },
1670 /* 134 */ { 0, "rename" },
1671 /* 135 */ { 0, "uname" },
1672 /* 136 */ { 0, "setegid" },
1673 /* 137 */ { 0, "sysconfig" },
1674 /* 138 */ { 0, "adjtime" },
1675 /* 139 */ { 0, "systeminfo" },
1676 /* 140 */ { 0, 0 /* reserved */ },
1677 /* 141 */ { 0, "seteuid" },
1678 /* 142 */ { 0, "vtrace" },
1679 /* 143 */ { 0, "fork1" },
1680 /* 144 */ { 0, "sigtimedwait" },
1681 /* 145 */ { 0, "lwp_info" },
1682 /* 146 */ { 0, "yield" },
1683 /* 147 */ { 0, "lwp_sema_wait" },
1684 /* 148 */ { 0, "lwp_sema_post" },
1685 /* 149 */ { 0, 0 /* reserved */ },
1686 /* 150 */ { 0, 0 /* reserved */ },
1687 /* 151 */ { 0, 0 /* reserved */ },
1688 /* 152 */ { 0, "modctl" },
1689 /* 153 */ { 0, "fchroot" },
1690 /* 154 */ { 0, "utimes" },
1691 /* 155 */ { 0, "vhangup" },
1692 /* 156 */ { do_unix_gettimeofday
, "gettimeofday" },
1693 /* 157 */ { 0, "getitimer" },
1694 /* 158 */ { 0, "setitimer" },
1695 /* 159 */ { 0, "lwp_create" },
1696 /* 160 */ { 0, "lwp_exit" },
1697 /* 161 */ { 0, "lwp_suspend" },
1698 /* 162 */ { 0, "lwp_continue" },
1699 /* 163 */ { 0, "lwp_kill" },
1700 /* 164 */ { 0, "lwp_self" },
1701 /* 165 */ { 0, "lwp_setprivate" },
1702 /* 166 */ { 0, "lwp_getprivate" },
1703 /* 167 */ { 0, "lwp_wait" },
1704 /* 168 */ { 0, "lwp_mutex_unlock" },
1705 /* 169 */ { 0, "lwp_mutex_lock" },
1706 /* 170 */ { 0, "lwp_cond_wait" },
1707 /* 171 */ { 0, "lwp_cond_signal" },
1708 /* 172 */ { 0, "lwp_cond_broadcast" },
1709 /* 173 */ { 0, "pread" },
1710 /* 174 */ { 0, "pwrite" },
1711 /* 175 */ { 0, "llseek" },
1712 /* 176 */ { 0, "inst_sync" },
1713 /* 177 */ { 0, 0 /* reserved */ },
1714 /* 178 */ { 0, "kaio" },
1715 /* 179 */ { 0, 0 /* reserved */ },
1716 /* 180 */ { 0, 0 /* reserved */ },
1717 /* 181 */ { 0, 0 /* reserved */ },
1718 /* 182 */ { 0, 0 /* reserved */ },
1719 /* 183 */ { 0, 0 /* reserved */ },
1720 /* 184 */ { 0, "tsolsys" },
1721 /* 185 */ { 0, "acl" },
1722 /* 186 */ { 0, "auditsys" },
1723 /* 187 */ { 0, "processor_bind" },
1724 /* 188 */ { 0, "processor_info" },
1725 /* 189 */ { 0, "p_online" },
1726 /* 190 */ { 0, "sigqueue" },
1727 /* 191 */ { 0, "clock_gettime" },
1728 /* 192 */ { 0, "clock_settime" },
1729 /* 193 */ { 0, "clock_getres" },
1730 /* 194 */ { 0, "timer_create" },
1731 /* 195 */ { 0, "timer_delete" },
1732 /* 196 */ { 0, "timer_settime" },
1733 /* 197 */ { 0, "timer_gettime" },
1734 /* 198 */ { 0, "timer_getoverrun" },
1735 /* 199 */ { 0, "nanosleep" },
1736 /* 200 */ { 0, "facl" },
1737 /* 201 */ { 0, "door" },
1738 /* 202 */ { 0, "setreuid" },
1739 /* 203 */ { 0, "setregid" },
1740 /* 204 */ { 0, "install_utrap" },
1741 /* 205 */ { 0, 0 /* reserved */ },
1742 /* 206 */ { 0, 0 /* reserved */ },
1743 /* 207 */ { 0, 0 /* reserved */ },
1744 /* 208 */ { 0, 0 /* reserved */ },
1745 /* 209 */ { 0, 0 /* reserved */ },
1746 /* 210 */ { 0, "signotifywait" },
1747 /* 211 */ { 0, "lwp_sigredirect" },
1748 /* 212 */ { 0, "lwp_alarm" },
1751 static char *(solaris_error_names
[]) = {
1790 /* 38 */ "EL2NSYNC",
1799 /* 47 */ "ECANCELED",
1808 /* 56 */ "EDEADLOCK",
1810 /* 58 */ "Error code 58",
1811 /* 59 */ "Error code 59",
1824 /* 72 */ "Error code 72",
1825 /* 73 */ "Error code 73",
1826 /* 74 */ "EMULTIHOP",
1827 /* 75 */ "Error code 75",
1828 /* 76 */ "Error code 76",
1830 /* 78 */ "ENAMETOOLONG",
1831 /* 79 */ "EOVERFLOW",
1832 /* 80 */ "ENOTUNIQ",
1839 /* 87 */ "ELIBEXEC",
1843 /* 91 */ "ERESTART",
1844 /* 92 */ "ESTRPIPE",
1845 /* 93 */ "ENOTEMPTY",
1847 /* 95 */ "ENOTSOCK",
1848 /* 96 */ "EDESTADDRREQ",
1849 /* 97 */ "EMSGSIZE",
1850 /* 98 */ "EPROTOTYPE",
1851 /* 99 */ "ENOPROTOOPT",
1852 /* 100 */ "Error code 100",
1853 /* 101 */ "Error code 101",
1854 /* 102 */ "Error code 102",
1855 /* 103 */ "Error code 103",
1856 /* 104 */ "Error code 104",
1857 /* 105 */ "Error code 105",
1858 /* 106 */ "Error code 106",
1859 /* 107 */ "Error code 107",
1860 /* 108 */ "Error code 108",
1861 /* 109 */ "Error code 109",
1862 /* 110 */ "Error code 110",
1863 /* 111 */ "Error code 111",
1864 /* 112 */ "Error code 112",
1865 /* 113 */ "Error code 113",
1866 /* 114 */ "Error code 114",
1867 /* 115 */ "Error code 115",
1868 /* 116 */ "Error code 116",
1869 /* 117 */ "Error code 117",
1870 /* 118 */ "Error code 118",
1871 /* 119 */ "Error code 119",
1872 /* 120 */ "EPROTONOSUPPORT",
1873 /* 121 */ "ESOCKTNOSUPPORT",
1874 /* 122 */ "EOPNOTSUPP",
1875 /* 123 */ "EPFNOSUPPORT",
1876 /* 124 */ "EAFNOSUPPORT",
1877 /* 125 */ "EADDRINUSE",
1878 /* 126 */ "EADDRNOTAVAIL",
1879 /* 127 */ "ENETDOWN",
1880 /* 128 */ "ENETUNREACH",
1881 /* 129 */ "ENETRESET",
1882 /* 130 */ "ECONNABORTED",
1883 /* 131 */ "ECONNRESET",
1884 /* 132 */ "ENOBUFS",
1885 /* 133 */ "EISCONN",
1886 /* 134 */ "ENOTCONN",
1887 /* 135 */ "Error code 135", /* XENIX has 135 - 142 */
1888 /* 136 */ "Error code 136",
1889 /* 137 */ "Error code 137",
1890 /* 138 */ "Error code 138",
1891 /* 139 */ "Error code 139",
1892 /* 140 */ "Error code 140",
1893 /* 141 */ "Error code 141",
1894 /* 142 */ "Error code 142",
1895 /* 143 */ "ESHUTDOWN",
1896 /* 144 */ "ETOOMANYREFS",
1897 /* 145 */ "ETIMEDOUT",
1898 /* 146 */ "ECONNREFUSED",
1899 /* 147 */ "EHOSTDOWN",
1900 /* 148 */ "EHOSTUNREACH",
1901 /* 149 */ "EALREADY",
1902 /* 150 */ "EINPROGRESS",
1906 static char *(solaris_signal_names
[]) = {
1927 /* 20 */ "SIGWINCH",
1935 /* 28 */ "SIGVTALRM",
1939 /* 32 */ "SIGWAITING",
1941 /* 34 */ "SIGFREEZE",
1943 /* 36 */ "SIGCANCEL",
1946 static emul_syscall emul_solaris_syscalls
= {
1947 solaris_descriptors
,
1948 ARRAY_SIZE (solaris_descriptors
),
1949 solaris_error_names
,
1950 ARRAY_SIZE (solaris_error_names
),
1951 solaris_signal_names
,
1952 ARRAY_SIZE (solaris_signal_names
),
1956 /* Solaris's os_emul interface, most are just passed on to the generic
1959 static os_emul_data
*
1960 emul_solaris_create(device
*root
,
1964 /* check that this emulation is really for us */
1965 if (name
!= NULL
&& strcmp(name
, "solaris") != 0)
1971 return emul_unix_create(root
, image
, "solaris", &emul_solaris_syscalls
);
1975 emul_solaris_init(os_emul_data
*emul_data
,
1984 emul_solaris_system_call(cpu
*processor
,
1986 os_emul_data
*emul_data
)
1988 emul_do_system_call(emul_data
,
1989 emul_data
->syscalls
,
1990 cpu_registers(processor
)->gpr
[0],
1991 3, /*r3 contains arg0*/
1996 const os_emul emul_solaris
= {
1998 emul_solaris_create
,
2000 emul_solaris_system_call
,
2001 0, /*instruction_call*/
2008 Linux - Emulation of user programs for Linux/PPC
2015 /* Linux specific implementation */
2017 typedef unsigned32 linux_dev_t
;
2018 typedef unsigned32 linux_ino_t
;
2019 typedef unsigned32 linux_mode_t
;
2020 typedef unsigned16 linux_nlink_t
;
2021 typedef signed32 linux_off_t
;
2022 typedef signed32 linux_pid_t
;
2023 typedef unsigned32 linux_uid_t
;
2024 typedef unsigned32 linux_gid_t
;
2025 typedef unsigned32 linux_size_t
;
2026 typedef signed32 linux_ssize_t
;
2027 typedef signed32 linux_ptrdiff_t
;
2028 typedef signed32 linux_time_t
;
2029 typedef signed32 linux_clock_t
;
2030 typedef signed32 linux_daddr_t
;
2032 #ifdef HAVE_SYS_STAT_H
2033 /* For the PowerPC, don't both with the 'old' stat structure, since there
2034 should be no extant binaries with that structure. */
2039 linux_mode_t st_mode
;
2040 linux_nlink_t st_nlink
;
2043 linux_dev_t st_rdev
;
2044 linux_off_t st_size
;
2045 unsigned32 st_blksize
;
2046 unsigned32 st_blocks
;
2047 unsigned32 st_atimx
; /* don't use st_{a,c,m}time, that might a macro */
2048 unsigned32 __unused1
; /* defined by the host's stat.h */
2049 unsigned32 st_mtimx
;
2050 unsigned32 __unused2
;
2051 unsigned32 st_ctimx
;
2052 unsigned32 __unused3
;
2053 unsigned32 __unused4
;
2054 unsigned32 __unused5
;
2057 /* Convert from host stat structure to solaris stat structure */
2058 STATIC_INLINE_EMUL_UNIX
void
2059 convert_to_linux_stat(unsigned_word addr
,
2064 struct linux_stat target
;
2066 target
.st_dev
= H2T_4(host
->st_dev
);
2067 target
.st_ino
= H2T_4(host
->st_ino
);
2068 target
.st_mode
= H2T_4(host
->st_mode
);
2069 target
.st_nlink
= H2T_2(host
->st_nlink
);
2070 target
.st_uid
= H2T_4(host
->st_uid
);
2071 target
.st_gid
= H2T_4(host
->st_gid
);
2072 target
.st_size
= H2T_4(host
->st_size
);
2075 target
.st_rdev
= H2T_4(host
->st_rdev
);
2080 #ifdef HAVE_ST_BLKSIZE
2081 target
.st_blksize
= H2T_4(host
->st_blksize
);
2083 target
.st_blksize
= 0;
2086 #ifdef HAVE_ST_BLOCKS
2087 target
.st_blocks
= H2T_4(host
->st_blocks
);
2089 target
.st_blocks
= 0;
2092 target
.st_atimx
= H2T_4(host
->st_atime
);
2093 target
.st_ctimx
= H2T_4(host
->st_ctime
);
2094 target
.st_mtimx
= H2T_4(host
->st_mtime
);
2095 target
.__unused1
= 0;
2096 target
.__unused2
= 0;
2097 target
.__unused3
= 0;
2098 target
.__unused4
= 0;
2099 target
.__unused5
= 0;
2101 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2103 #endif /* HAVE_SYS_STAT_H */
2106 #define do_linux_stat 0
2109 do_linux_stat(os_emul_data
*emul
,
2115 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
2116 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2117 char path_buf
[PATH_MAX
];
2119 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
2122 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2123 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2125 status
= stat (path
, &buf
);
2127 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2129 emul_write_status(processor
, status
, errno
);
2134 #define do_linux_lstat 0
2137 do_linux_lstat(os_emul_data
*emul
,
2143 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
2144 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2145 char path_buf
[PATH_MAX
];
2147 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
2150 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2151 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2153 status
= lstat (path
, &buf
);
2155 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2157 emul_write_status(processor
, status
, errno
);
2162 #define do_linux_fstat 0
2165 do_linux_fstat(os_emul_data
*emul
,
2171 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
2172 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2176 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2177 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
2179 status
= fdbad (fildes
);
2181 status
= fstat (fildes
, &buf
);
2183 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2185 emul_write_status(processor
, status
, errno
);
2189 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2190 #define LINUX_NCC 10
2191 #define LINUX_NCCS 19
2193 #define LINUX_VINTR 0
2194 #define LINUX_VQUIT 1
2195 #define LINUX_VERASE 2
2196 #define LINUX_VKILL 3
2197 #define LINUX_VEOF 4
2198 #define LINUX_VMIN 5
2199 #define LINUX_VEOL 6
2200 #define LINUX_VTIME 7
2201 #define LINUX_VEOL2 8
2202 #define LINUX_VSWTC 9
2203 #define LINUX_VWERASE 10
2204 #define LINUX_VREPRINT 11
2205 #define LINUX_VSUSP 12
2206 #define LINUX_VSTART 13
2207 #define LINUX_VSTOP 14
2208 #define LINUX_VLNEXT 15
2209 #define LINUX_VDISCARD 16
2211 #define LINUX_IOC_NRBITS 8
2212 #define LINUX_IOC_TYPEBITS 8
2213 #define LINUX_IOC_SIZEBITS 13
2214 #define LINUX_IOC_DIRBITS 3
2216 #define LINUX_IOC_NRMASK ((1 << LINUX_IOC_NRBITS)-1)
2217 #define LINUX_IOC_TYPEMASK ((1 << LINUX_IOC_TYPEBITS)-1)
2218 #define LINUX_IOC_SIZEMASK ((1 << LINUX_IOC_SIZEBITS)-1)
2219 #define LINUX_IOC_DIRMASK ((1 << LINUX_IOC_DIRBITS)-1)
2221 #define LINUX_IOC_NRSHIFT 0
2222 #define LINUX_IOC_TYPESHIFT (LINUX_IOC_NRSHIFT+LINUX_IOC_NRBITS)
2223 #define LINUX_IOC_SIZESHIFT (LINUX_IOC_TYPESHIFT+LINUX_IOC_TYPEBITS)
2224 #define LINUX_IOC_DIRSHIFT (LINUX_IOC_SIZESHIFT+LINUX_IOC_SIZEBITS)
2227 * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
2228 * And this turns out useful to catch old ioctl numbers in header
2231 #define LINUX_IOC_NONE 1U
2232 #define LINUX_IOC_READ 2U
2233 #define LINUX_IOC_WRITE 4U
2235 #define LINUX_IOC(dir,type,nr,size) \
2236 (((dir) << LINUX_IOC_DIRSHIFT) | \
2237 ((type) << LINUX_IOC_TYPESHIFT) | \
2238 ((nr) << LINUX_IOC_NRSHIFT) | \
2239 ((size) << LINUX_IOC_SIZESHIFT))
2241 /* used to create numbers */
2242 #define LINUX_IO(type,nr) LINUX_IOC(LINUX_IOC_NONE,(type),(nr),0)
2243 #define LINUX_IOR(type,nr,size) LINUX_IOC(LINUX_IOC_READ,(type),(nr),sizeof(size))
2244 #define LINUX_IOW(type,nr,size) LINUX_IOC(LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2245 #define LINUX_IOWR(type,nr,size) LINUX_IOC(LINUX_IOC_READ|LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2248 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2249 /* Convert to/from host termio structure */
2251 struct linux_termio
{
2252 unsigned16 c_iflag
; /* input modes */
2253 unsigned16 c_oflag
; /* output modes */
2254 unsigned16 c_cflag
; /* control modes */
2255 unsigned16 c_lflag
; /* line discipline modes */
2256 unsigned8 c_line
; /* line discipline */
2257 unsigned8 c_cc
[LINUX_NCC
]; /* control chars */
2260 STATIC_INLINE_EMUL_UNIX
void
2261 convert_to_linux_termio(unsigned_word addr
,
2262 struct termio
*host
,
2266 struct linux_termio target
;
2269 target
.c_iflag
= H2T_2 (host
->c_iflag
);
2270 target
.c_oflag
= H2T_2 (host
->c_oflag
);
2271 target
.c_cflag
= H2T_2 (host
->c_cflag
);
2272 target
.c_lflag
= H2T_2 (host
->c_lflag
);
2274 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
2275 target
.c_line
= host
->c_line
;
2280 for (i
= 0; i
< LINUX_NCC
; i
++)
2284 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2288 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2292 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2296 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2300 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2304 target
.c_cc
[LINUX_VMIN
] = host
->c_cc
[VMIN
];
2308 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2312 target
.c_cc
[LINUX_VTIME
] = host
->c_cc
[VTIME
];
2316 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2320 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTC
];
2324 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2327 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2329 #endif /* HAVE_TERMIO_STRUCTURE */
2331 #ifdef HAVE_TERMIOS_STRUCTURE
2332 /* Convert to/from host termios structure */
2334 typedef unsigned32 linux_tcflag_t
;
2335 typedef unsigned8 linux_cc_t
;
2336 typedef unsigned32 linux_speed_t
;
2338 struct linux_termios
{
2339 linux_tcflag_t c_iflag
;
2340 linux_tcflag_t c_oflag
;
2341 linux_tcflag_t c_cflag
;
2342 linux_tcflag_t c_lflag
;
2343 linux_cc_t c_cc
[LINUX_NCCS
];
2349 STATIC_INLINE_EMUL_UNIX
void
2350 convert_to_linux_termios(unsigned_word addr
,
2351 struct termios
*host
,
2355 struct linux_termios target
;
2358 target
.c_iflag
= H2T_4 (host
->c_iflag
);
2359 target
.c_oflag
= H2T_4 (host
->c_oflag
);
2360 target
.c_cflag
= H2T_4 (host
->c_cflag
);
2361 target
.c_lflag
= H2T_4 (host
->c_lflag
);
2363 for (i
= 0; i
< LINUX_NCCS
; i
++)
2367 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2371 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2375 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2379 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2383 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2387 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2391 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2395 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2398 #ifdef HAVE_TERMIOS_CLINE
2399 target
.c_line
= host
->c_line
;
2404 #ifdef HAVE_CFGETISPEED
2405 target
.c_ispeed
= cfgetispeed (host
);
2407 target
.c_ispeed
= 0;
2410 #ifdef HAVE_CFGETOSPEED
2411 target
.c_ospeed
= cfgetospeed (host
);
2413 target
.c_ospeed
= 0;
2416 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2418 #endif /* HAVE_TERMIOS_STRUCTURE */
2421 #define do_linux_ioctl 0
2424 do_linux_ioctl(os_emul_data
*emul
,
2430 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
2431 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
2432 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
2434 const char *name
= "<unknown>";
2436 #ifdef HAVE_TERMIOS_STRUCTURE
2437 struct termios host_termio
;
2440 #ifdef HAVE_TERMIO_STRUCTURE
2441 struct termio host_termio
;
2445 status
= fdbad (fildes
);
2451 case 0: /* make sure we have at least one case */
2457 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2458 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
2459 case LINUX_IOR('t', 23, struct linux_termio
): /* TCGETA */
2461 #ifdef HAVE_TCGETATTR
2462 status
= tcgetattr(fildes
, &host_termio
);
2463 #elif defined(TCGETS)
2464 status
= ioctl (fildes
, TCGETS
, &host_termio
);
2466 status
= ioctl (fildes
, TCGETA
, &host_termio
);
2469 convert_to_linux_termio (argp_addr
, &host_termio
, processor
, cia
);
2472 #endif /* HAVE_TERMIO_STRUCTURE */
2474 #ifdef HAVE_TERMIOS_STRUCTURE
2475 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
2476 case LINUX_IOR('t', 19, struct linux_termios
): /* TCGETS */
2478 #ifdef HAVE_TCGETATTR
2479 status
= tcgetattr(fildes
, &host_termio
);
2481 status
= ioctl (fildes
, TCGETS
, &host_termio
);
2484 convert_to_linux_termios (argp_addr
, &host_termio
, processor
, cia
);
2487 #endif /* HAVE_TERMIOS_STRUCTURE */
2491 emul_write_status(processor
, status
, errno
);
2493 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2494 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
2496 #endif /* HAVE_IOCTL */
2498 static emul_syscall_descriptor linux_descriptors
[] = {
2499 /* 0 */ { 0, "setup" },
2500 /* 1 */ { do_unix_exit
, "exit" },
2501 /* 2 */ { 0, "fork" },
2502 /* 3 */ { do_unix_read
, "read" },
2503 /* 4 */ { do_unix_write
, "write" },
2504 /* 5 */ { do_unix_open
, "open" },
2505 /* 6 */ { do_unix_close
, "close" },
2506 /* 7 */ { 0, "waitpid" },
2507 /* 8 */ { 0, "creat" },
2508 /* 9 */ { do_unix_link
, "link" },
2509 /* 10 */ { do_unix_unlink
, "unlink" },
2510 /* 11 */ { 0, "execve" },
2511 /* 12 */ { do_unix_chdir
, "chdir" },
2512 /* 13 */ { do_unix_time
, "time" },
2513 /* 14 */ { 0, "mknod" },
2514 /* 15 */ { 0, "chmod" },
2515 /* 16 */ { 0, "chown" },
2516 /* 17 */ { 0, "break" },
2517 /* 18 */ { 0, "stat" },
2518 /* 19 */ { do_unix_lseek
, "lseek" },
2519 /* 20 */ { do_unix_getpid
, "getpid" },
2520 /* 21 */ { 0, "mount" },
2521 /* 22 */ { 0, "umount" },
2522 /* 23 */ { 0, "setuid" },
2523 /* 24 */ { do_unix_getuid
, "getuid" },
2524 /* 25 */ { 0, "stime" },
2525 /* 26 */ { 0, "ptrace" },
2526 /* 27 */ { 0, "alarm" },
2527 /* 28 */ { 0, "fstat" },
2528 /* 29 */ { 0, "pause" },
2529 /* 30 */ { 0, "utime" },
2530 /* 31 */ { 0, "stty" },
2531 /* 32 */ { 0, "gtty" },
2532 /* 33 */ { do_unix_access
, "access" },
2533 /* 34 */ { 0, "nice" },
2534 /* 35 */ { 0, "ftime" },
2535 /* 36 */ { 0, "sync" },
2536 /* 37 */ { 0, "kill" },
2537 /* 38 */ { 0, "rename" },
2538 /* 39 */ { do_unix_mkdir
, "mkdir" },
2539 /* 40 */ { do_unix_rmdir
, "rmdir" },
2540 /* 41 */ { do_unix_dup
, "dup" },
2541 /* 42 */ { 0, "pipe" },
2542 /* 43 */ { 0, "times" },
2543 /* 44 */ { 0, "prof" },
2544 /* 45 */ { do_unix_break
, "brk" },
2545 /* 46 */ { 0, "setgid" },
2546 /* 47 */ { do_unix_getgid
, "getgid" },
2547 /* 48 */ { 0, "signal" },
2548 /* 49 */ { do_unix_geteuid
, "geteuid" },
2549 /* 50 */ { do_unix_getegid
, "getegid" },
2550 /* 51 */ { 0, "acct" },
2551 /* 52 */ { 0, "phys" },
2552 /* 53 */ { 0, "lock" },
2553 /* 54 */ { do_linux_ioctl
, "ioctl" },
2554 /* 55 */ { 0, "fcntl" },
2555 /* 56 */ { 0, "mpx" },
2556 /* 57 */ { 0, "setpgid" },
2557 /* 58 */ { 0, "ulimit" },
2558 /* 59 */ { 0, "olduname" },
2559 /* 60 */ { do_unix_umask
, "umask" },
2560 /* 61 */ { 0, "chroot" },
2561 /* 62 */ { 0, "ustat" },
2562 /* 63 */ { do_unix_dup2
, "dup2" },
2563 /* 64 */ { do_unix_getppid
, "getppid" },
2564 /* 65 */ { 0, "getpgrp" },
2565 /* 66 */ { 0, "setsid" },
2566 /* 67 */ { 0, "sigaction" },
2567 /* 68 */ { 0, "sgetmask" },
2568 /* 69 */ { 0, "ssetmask" },
2569 /* 70 */ { 0, "setreuid" },
2570 /* 71 */ { 0, "setregid" },
2571 /* 72 */ { 0, "sigsuspend" },
2572 /* 73 */ { 0, "sigpending" },
2573 /* 74 */ { 0, "sethostname" },
2574 /* 75 */ { 0, "setrlimit" },
2575 /* 76 */ { 0, "getrlimit" },
2576 /* 77 */ { do_unix_getrusage
, "getrusage" },
2577 /* 78 */ { do_unix_gettimeofday
, "gettimeofday" },
2578 /* 79 */ { 0, "settimeofday" },
2579 /* 80 */ { 0, "getgroups" },
2580 /* 81 */ { 0, "setgroups" },
2581 /* 82 */ { 0, "select" },
2582 /* 83 */ { do_unix_symlink
, "symlink" },
2583 /* 84 */ { 0, "lstat" },
2584 /* 85 */ { 0, "readlink" },
2585 /* 86 */ { 0, "uselib" },
2586 /* 87 */ { 0, "swapon" },
2587 /* 88 */ { 0, "reboot" },
2588 /* 89 */ { 0, "readdir" },
2589 /* 90 */ { 0, "mmap" },
2590 /* 91 */ { 0, "munmap" },
2591 /* 92 */ { 0, "truncate" },
2592 /* 93 */ { 0, "ftruncate" },
2593 /* 94 */ { 0, "fchmod" },
2594 /* 95 */ { 0, "fchown" },
2595 /* 96 */ { 0, "getpriority" },
2596 /* 97 */ { 0, "setpriority" },
2597 /* 98 */ { 0, "profil" },
2598 /* 99 */ { 0, "statfs" },
2599 /* 100 */ { 0, "fstatfs" },
2600 /* 101 */ { 0, "ioperm" },
2601 /* 102 */ { 0, "socketcall" },
2602 /* 103 */ { 0, "syslog" },
2603 /* 104 */ { 0, "setitimer" },
2604 /* 105 */ { 0, "getitimer" },
2605 /* 106 */ { do_linux_stat
, "newstat" },
2606 /* 107 */ { do_linux_lstat
, "newlstat" },
2607 /* 108 */ { do_linux_fstat
, "newfstat" },
2608 /* 109 */ { 0, "uname" },
2609 /* 110 */ { 0, "iopl" },
2610 /* 111 */ { 0, "vhangup" },
2611 /* 112 */ { 0, "idle" },
2612 /* 113 */ { 0, "vm86" },
2613 /* 114 */ { 0, "wait4" },
2614 /* 115 */ { 0, "swapoff" },
2615 /* 116 */ { 0, "sysinfo" },
2616 /* 117 */ { 0, "ipc" },
2617 /* 118 */ { 0, "fsync" },
2618 /* 119 */ { 0, "sigreturn" },
2619 /* 120 */ { 0, "clone" },
2620 /* 121 */ { 0, "setdomainname" },
2621 /* 122 */ { 0, "newuname" },
2622 /* 123 */ { 0, "modify_ldt" },
2623 /* 124 */ { 0, "adjtimex" },
2624 /* 125 */ { 0, "mprotect" },
2625 /* 126 */ { 0, "sigprocmask" },
2626 /* 127 */ { 0, "create_module" },
2627 /* 128 */ { 0, "init_module" },
2628 /* 129 */ { 0, "delete_module" },
2629 /* 130 */ { 0, "get_kernel_syms" },
2630 /* 131 */ { 0, "quotactl" },
2631 /* 132 */ { 0, "getpgid" },
2632 /* 133 */ { 0, "fchdir" },
2633 /* 134 */ { 0, "bdflush" },
2634 /* 135 */ { 0, "sysfs" },
2635 /* 136 */ { 0, "personality" },
2636 /* 137 */ { 0, "afs_syscall" },
2637 /* 138 */ { 0, "setfsuid" },
2638 /* 139 */ { 0, "setfsgid" },
2639 /* 140 */ { 0, "llseek" },
2640 /* 141 */ { 0, "getdents" },
2641 /* 142 */ { 0, "newselect" },
2642 /* 143 */ { 0, "flock" },
2643 /* 144 */ { 0, "msync" },
2644 /* 145 */ { 0, "readv" },
2645 /* 146 */ { 0, "writev" },
2646 /* 147 */ { 0, "getsid" },
2647 /* 148 */ { 0, "fdatasync" },
2648 /* 149 */ { 0, "sysctl" },
2649 /* 150 */ { 0, "mlock" },
2650 /* 151 */ { 0, "munlock" },
2651 /* 152 */ { 0, "mlockall" },
2652 /* 153 */ { 0, "munlockall" },
2653 /* 154 */ { 0, "sched_setparam" },
2654 /* 155 */ { 0, "sched_getparam" },
2655 /* 156 */ { 0, "sched_setscheduler" },
2656 /* 157 */ { 0, "sched_getscheduler" },
2657 /* 158 */ { 0, "sched_yield" },
2658 /* 159 */ { 0, "sched_get_priority_max" },
2659 /* 160 */ { 0, "sched_get_priority_min" },
2660 /* 161 */ { 0, "sched_rr_get_interval" },
2663 static char *(linux_error_names
[]) = {
2700 /* 36 */ "ENAMETOOLONG",
2703 /* 39 */ "ENOTEMPTY",
2709 /* 45 */ "EL2NSYNC",
2722 /* 58 */ "EDEADLOCK",
2736 /* 72 */ "EMULTIHOP",
2739 /* 75 */ "EOVERFLOW",
2740 /* 76 */ "ENOTUNIQ",
2747 /* 83 */ "ELIBEXEC",
2749 /* 85 */ "ERESTART",
2750 /* 86 */ "ESTRPIPE",
2752 /* 88 */ "ENOTSOCK",
2753 /* 89 */ "EDESTADDRREQ",
2754 /* 90 */ "EMSGSIZE",
2755 /* 91 */ "EPROTOTYPE",
2756 /* 92 */ "ENOPROTOOPT",
2757 /* 93 */ "EPROTONOSUPPORT",
2758 /* 94 */ "ESOCKTNOSUPPORT",
2759 /* 95 */ "EOPNOTSUPP",
2760 /* 96 */ "EPFNOSUPPORT",
2761 /* 97 */ "EAFNOSUPPORT",
2762 /* 98 */ "EADDRINUSE",
2763 /* 99 */ "EADDRNOTAVAIL",
2764 /* 100 */ "ENETDOWN",
2765 /* 101 */ "ENETUNREACH",
2766 /* 102 */ "ENETRESET",
2767 /* 103 */ "ECONNABORTED",
2768 /* 104 */ "ECONNRESET",
2769 /* 105 */ "ENOBUFS",
2770 /* 106 */ "EISCONN",
2771 /* 107 */ "ENOTCONN",
2772 /* 108 */ "ESHUTDOWN",
2773 /* 109 */ "ETOOMANYREFS",
2774 /* 110 */ "ETIMEDOUT",
2775 /* 111 */ "ECONNREFUSED",
2776 /* 112 */ "EHOSTDOWN",
2777 /* 113 */ "EHOSTUNREACH",
2778 /* 114 */ "EALREADY",
2779 /* 115 */ "EINPROGRESS",
2781 /* 117 */ "EUCLEAN",
2782 /* 118 */ "ENOTNAM",
2783 /* 119 */ "ENAVAIL",
2785 /* 121 */ "EREMOTEIO",
2789 static char *(linux_signal_names
[]) = {
2807 /* 16 */ "SIGSTKFLT",
2817 /* 26 */ "SIGVTALRM",
2819 /* 28 */ "SIGWINCH",
2822 /* 31 */ "SIGUNUSED",
2825 static emul_syscall emul_linux_syscalls
= {
2827 ARRAY_SIZE (linux_descriptors
),
2829 ARRAY_SIZE (linux_error_names
),
2831 ARRAY_SIZE (linux_signal_names
),
2835 /* Linux's os_emul interface, most are just passed on to the generic
2838 static os_emul_data
*
2839 emul_linux_create(device
*root
,
2843 /* check that this emulation is really for us */
2844 if (name
!= NULL
&& strcmp(name
, "linux") != 0)
2850 return emul_unix_create(root
, image
, "linux", &emul_linux_syscalls
);
2854 emul_linux_init(os_emul_data
*emul_data
,
2863 emul_linux_system_call(cpu
*processor
,
2865 os_emul_data
*emul_data
)
2867 emul_do_system_call(emul_data
,
2868 emul_data
->syscalls
,
2869 cpu_registers(processor
)->gpr
[0],
2870 3, /*r3 contains arg0*/
2875 const os_emul emul_linux
= {
2879 emul_linux_system_call
,
2880 0, /*instruction_call*/
2884 #endif /* _EMUL_UNIX_C_ */