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 " */
199 do_unix_exit(os_emul_data
*emul
,
205 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
206 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
207 printf_filtered ("%d)\n", status
);
209 cpu_halt(processor
, cia
, was_exited
, status
);
214 do_unix_read(os_emul_data
*emul
,
220 void *scratch_buffer
;
221 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
222 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
223 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
226 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
227 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
229 /* get a tempoary bufer */
230 scratch_buffer
= zalloc(nbytes
);
232 /* check if buffer exists by reading it */
233 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
236 status
= read (d
, scratch_buffer
, nbytes
);
238 emul_write_status(processor
, status
, errno
);
240 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
242 free(scratch_buffer
);
247 do_unix_write(os_emul_data
*emul
,
253 void *scratch_buffer
= NULL
;
254 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
255 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
256 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
259 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
260 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
262 /* get a tempoary bufer */
263 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
266 emul_read_buffer(scratch_buffer
, buf
, nbytes
,
270 status
= write(d
, scratch_buffer
, nbytes
);
271 emul_write_status(processor
, status
, errno
);
272 free(scratch_buffer
);
279 do_unix_open(os_emul_data
*emul
,
285 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
286 char path_buf
[PATH_MAX
];
287 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
288 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
289 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
292 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
293 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
295 status
= open(path
, flags
, mode
);
296 emul_write_status(processor
, status
, errno
);
301 do_unix_close(os_emul_data
*emul
,
307 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
310 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
311 printf_filtered ("%d", d
);
314 emul_write_status(processor
, status
, errno
);
319 do_unix_break(os_emul_data
*emul
,
325 /* just pass this onto the `vm' device */
326 unsigned_word new_break
= cpu_registers(processor
)->gpr
[arg0
];
329 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
330 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
332 status
= device_ioctl(emul
->vm
,
336 new_break
); /*ioctl-data*/
338 emul_write_status(processor
, 0, status
);
342 #define do_unix_access 0
345 do_unix_access(os_emul_data
*emul
,
351 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
352 char path_buf
[PATH_MAX
];
353 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
354 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
357 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
358 printf_filtered ("0x%lx [%s], 0x%x [0%o]", (long)path_addr
, path
, mode
, mode
);
360 status
= access(path
, mode
);
361 emul_write_status(processor
, status
, errno
);
366 #define do_unix_getpid 0
369 do_unix_getpid(os_emul_data
*emul
,
375 pid_t status
= getpid();
376 emul_write_status(processor
, (int)status
, errno
);
381 #define do_unix_getppid 0
384 do_unix_getppid(os_emul_data
*emul
,
390 pid_t status
= getppid();
391 emul_write_status(processor
, (int)status
, errno
);
395 #if !defined(HAVE_GETPID) || !defined(HAVE_GETPPID)
396 #define do_unix_getpid2 0
399 do_unix_getpid2(os_emul_data
*emul
,
405 int pid
= (int)getpid();
406 int ppid
= (int)getppid();
407 emul_write2_status(processor
, pid
, ppid
, errno
);
411 #if !defined(HAVE_GETUID) || !defined(HAVE_GETEUID)
412 #define do_unix_getuid2 0
415 do_unix_getuid2(os_emul_data
*emul
,
421 uid_t uid
= getuid();
422 uid_t euid
= geteuid();
423 emul_write2_status(processor
, (int)uid
, (int)euid
, errno
);
428 #define do_unix_getuid 0
431 do_unix_getuid(os_emul_data
*emul
,
437 uid_t status
= getuid();
438 emul_write_status(processor
, (int)status
, errno
);
443 #define do_unix_geteuid 0
446 do_unix_geteuid(os_emul_data
*emul
,
452 uid_t status
= geteuid();
453 emul_write_status(processor
, (int)status
, errno
);
459 #define do_unix_kill 0
462 do_unix_kill(os_emul_data
*emul
,
468 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
469 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
471 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
472 printf_filtered ("%d, %d", (int)pid
, sig
);
474 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
477 cpu_halt(processor
, cia
, was_signalled
, sig
);
483 #define do_unix_dup 0
486 do_unix_dup(os_emul_data
*emul
,
492 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
493 int status
= dup(oldd
);
496 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
497 printf_filtered ("%d", oldd
);
499 emul_write_status(processor
, status
, err
);
504 #define do_unix_dup2 0
507 do_unix_dup2(os_emul_data
*emul
,
513 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
514 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
515 int status
= dup2(oldd
, newd
);
518 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
519 printf_filtered ("%d, %d", oldd
, newd
);
521 emul_write_status(processor
, status
, err
);
526 #define do_unix_lseek 0
529 do_unix_lseek(os_emul_data
*emul
,
535 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
536 off_t offset
= (off_t
)cpu_registers(processor
)->gpr
[arg0
+1];
537 int whence
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
540 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
541 printf_filtered ("%d %ld %d", fildes
, (long)offset
, whence
);
543 status
= lseek(fildes
, offset
, whence
);
544 emul_write_status(processor
, (int)status
, errno
);
549 #if !defined(HAVE_GETGID) || !defined(HAVE_GETEGID)
550 #define do_unix_getgid2 0
553 do_unix_getgid2(os_emul_data
*emul
,
559 gid_t gid
= getgid();
560 gid_t egid
= getegid();
561 emul_write2_status(processor
, (int)gid
, (int)egid
, errno
);
566 #define do_unix_getgid 0
569 do_unix_getgid(os_emul_data
*emul
,
575 gid_t status
= getgid();
576 emul_write_status(processor
, (int)status
, errno
);
581 #define do_unix_getegid 0
584 do_unix_getegid(os_emul_data
*emul
,
590 gid_t status
= getegid();
591 emul_write_status(processor
, (int)status
, errno
);
596 #define do_unix_umask 0
599 do_unix_umask(os_emul_data
*emul
,
605 mode_t mask
= (mode_t
)cpu_registers(processor
)->gpr
[arg0
];
606 int status
= umask(mask
);
608 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
609 printf_filtered ("0%o", (unsigned int)mask
);
611 emul_write_status(processor
, status
, errno
);
616 #define do_unix_chdir 0
619 do_unix_chdir(os_emul_data
*emul
,
625 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
626 char path_buf
[PATH_MAX
];
627 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
630 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
631 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
633 status
= chdir(path
);
634 emul_write_status(processor
, status
, errno
);
639 #define do_unix_link 0
642 do_unix_link(os_emul_data
*emul
,
648 unsigned_word path1_addr
= cpu_registers(processor
)->gpr
[arg0
];
649 char path1_buf
[PATH_MAX
];
650 char *path1
= emul_read_string(path1_buf
, path1_addr
, PATH_MAX
, processor
, cia
);
651 unsigned_word path2_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
652 char path2_buf
[PATH_MAX
];
653 char *path2
= emul_read_string(path2_buf
, path2_addr
, PATH_MAX
, processor
, cia
);
656 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
657 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr
, path1
, (long)path2_addr
, path2
);
659 status
= link(path1
, path2
);
660 emul_write_status(processor
, status
, errno
);
665 #define do_unix_symlink 0
668 do_unix_symlink(os_emul_data
*emul
,
674 unsigned_word path1_addr
= cpu_registers(processor
)->gpr
[arg0
];
675 char path1_buf
[PATH_MAX
];
676 char *path1
= emul_read_string(path1_buf
, path1_addr
, PATH_MAX
, processor
, cia
);
677 unsigned_word path2_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
678 char path2_buf
[PATH_MAX
];
679 char *path2
= emul_read_string(path2_buf
, path2_addr
, PATH_MAX
, processor
, cia
);
682 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
683 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr
, path1
, (long)path2_addr
, path2
);
685 status
= symlink(path1
, path2
);
686 emul_write_status(processor
, status
, errno
);
691 #define do_unix_unlink 0
694 do_unix_unlink(os_emul_data
*emul
,
700 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
701 char path_buf
[PATH_MAX
];
702 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
705 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
706 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
708 status
= unlink(path
);
709 emul_write_status(processor
, status
, errno
);
714 #define do_unix_mkdir 0
717 do_unix_mkdir(os_emul_data
*emul
,
723 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
724 char path_buf
[PATH_MAX
];
725 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
726 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
729 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
730 printf_filtered ("0x%lx [%s], 0%3o", (long)path_addr
, path
, mode
);
733 status
= mkdir(path
);
735 status
= mkdir(path
, mode
);
737 emul_write_status(processor
, status
, errno
);
742 #define do_unix_rmdir 0
745 do_unix_rmdir(os_emul_data
*emul
,
751 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
752 char path_buf
[PATH_MAX
];
753 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
756 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
757 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
759 status
= rmdir(path
);
760 emul_write_status(processor
, status
, errno
);
765 #define do_unix_time 0
768 do_unix_time(os_emul_data
*emul
,
774 unsigned_word tp
= cpu_registers(processor
)->gpr
[arg0
];
775 time_t now
= time ((time_t *)0);
776 unsigned_word status
= H2T_4(now
);
778 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
779 printf_filtered ("0x%lx", (long)tp
);
781 emul_write_status(processor
, (int)status
, errno
);
784 emul_write_buffer(&status
, tp
, sizeof(status
), processor
, cia
);
788 #if !defined(HAVE_GETTIMEOFDAY) || !defined(HAVE_SYS_TIME_H)
789 #define do_unix_gettimeofday 0
792 do_unix_gettimeofday(os_emul_data
*emul
,
798 unsigned_word tv
= cpu_registers(processor
)->gpr
[arg0
];
799 unsigned_word tz
= cpu_registers(processor
)->gpr
[arg0
+1];
800 struct unix_timeval target_timeval
;
801 struct timeval host_timeval
;
802 struct unix_timezone target_timezone
;
803 struct timezone host_timezone
;
806 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
807 printf_filtered ("0x%lx, 0x%lx", (long)tv
, (long)tz
);
809 /* Just in case the system doesn't set the timezone structure */
810 host_timezone
.tz_minuteswest
= 0;
811 host_timezone
.tz_dsttime
= 0;
813 status
= gettimeofday(&host_timeval
, &host_timezone
);
816 target_timeval
.tv_sec
= H2T_4(host_timeval
.tv_sec
);
817 target_timeval
.tv_usec
= H2T_4(host_timeval
.tv_usec
);
818 emul_write_buffer((void *) &target_timeval
, tv
, sizeof(target_timeval
), processor
, cia
);
822 target_timezone
.tz_minuteswest
= H2T_4(host_timezone
.tz_minuteswest
);
823 target_timezone
.tz_dsttime
= H2T_4(host_timezone
.tz_dsttime
);
824 emul_write_buffer((void *) &target_timezone
, tv
, sizeof(target_timezone
), processor
, cia
);
828 emul_write_status(processor
, (int)status
, errno
);
833 #ifndef HAVE_GETRUSAGE
834 #define do_unix_getrusage 0
837 do_unix_getrusage(os_emul_data
*emul
,
843 signed_word who
= (signed_word
)cpu_registers(processor
)->gpr
[arg0
];
844 unsigned_word usage
= cpu_registers(processor
)->gpr
[arg0
+1];
845 struct rusage host_rusage
, host_rusage2
;
846 struct unix_rusage target_rusage
;
849 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
850 printf_filtered ("%ld, 0x%lx", (long)who
, (long)usage
);
858 case UNIX_RUSAGE_SELF
:
859 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
862 case UNIX_RUSAGE_CHILDREN
:
863 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage
);
866 case UNIX_RUSAGE_BOTH
:
867 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
869 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage2
);
871 host_rusage
.ru_utime
.tv_sec
+= host_rusage2
.ru_utime
.tv_sec
;
872 host_rusage
.ru_utime
.tv_usec
+= host_rusage2
.ru_utime
.tv_usec
;
873 host_rusage
.ru_stime
.tv_sec
+= host_rusage2
.ru_stime
.tv_sec
;
874 host_rusage
.ru_stime
.tv_usec
+= host_rusage2
.ru_stime
.tv_usec
;
875 host_rusage
.ru_maxrss
+= host_rusage2
.ru_maxrss
;
876 host_rusage
.ru_ixrss
+= host_rusage2
.ru_ixrss
;
877 host_rusage
.ru_idrss
+= host_rusage2
.ru_idrss
;
878 host_rusage
.ru_isrss
+= host_rusage2
.ru_isrss
;
879 host_rusage
.ru_minflt
+= host_rusage2
.ru_minflt
;
880 host_rusage
.ru_majflt
+= host_rusage2
.ru_majflt
;
881 host_rusage
.ru_nswap
+= host_rusage2
.ru_nswap
;
882 host_rusage
.ru_inblock
+= host_rusage2
.ru_inblock
;
883 host_rusage
.ru_oublock
+= host_rusage2
.ru_oublock
;
884 host_rusage
.ru_msgsnd
+= host_rusage2
.ru_msgsnd
;
885 host_rusage
.ru_msgrcv
+= host_rusage2
.ru_msgrcv
;
886 host_rusage
.ru_nsignals
+= host_rusage2
.ru_nsignals
;
887 host_rusage
.ru_nvcsw
+= host_rusage2
.ru_nvcsw
;
888 host_rusage
.ru_nivcsw
+= host_rusage2
.ru_nivcsw
;
894 target_rusage
.ru_utime
.tv_sec
= H2T_4(host_rusage2
.ru_utime
.tv_sec
);
895 target_rusage
.ru_utime
.tv_usec
= H2T_4(host_rusage2
.ru_utime
.tv_usec
);
896 target_rusage
.ru_stime
.tv_sec
= H2T_4(host_rusage2
.ru_stime
.tv_sec
);
897 target_rusage
.ru_stime
.tv_usec
= H2T_4(host_rusage2
.ru_stime
.tv_usec
);
898 target_rusage
.ru_maxrss
= H2T_4(host_rusage2
.ru_maxrss
);
899 target_rusage
.ru_ixrss
= H2T_4(host_rusage2
.ru_ixrss
);
900 target_rusage
.ru_idrss
= H2T_4(host_rusage2
.ru_idrss
);
901 target_rusage
.ru_isrss
= H2T_4(host_rusage2
.ru_isrss
);
902 target_rusage
.ru_minflt
= H2T_4(host_rusage2
.ru_minflt
);
903 target_rusage
.ru_majflt
= H2T_4(host_rusage2
.ru_majflt
);
904 target_rusage
.ru_nswap
= H2T_4(host_rusage2
.ru_nswap
);
905 target_rusage
.ru_inblock
= H2T_4(host_rusage2
.ru_inblock
);
906 target_rusage
.ru_oublock
= H2T_4(host_rusage2
.ru_oublock
);
907 target_rusage
.ru_msgsnd
= H2T_4(host_rusage2
.ru_msgsnd
);
908 target_rusage
.ru_msgrcv
= H2T_4(host_rusage2
.ru_msgrcv
);
909 target_rusage
.ru_nsignals
= H2T_4(host_rusage2
.ru_nsignals
);
910 target_rusage
.ru_nvcsw
= H2T_4(host_rusage2
.ru_nvcsw
);
911 target_rusage
.ru_nivcsw
= H2T_4(host_rusage2
.ru_nivcsw
);
912 emul_write_buffer((void *) &target_rusage
, usage
, sizeof(target_rusage
), processor
, cia
);
915 emul_write_status(processor
, status
, errno
);
921 do_unix_nop(os_emul_data
*emul
,
927 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
928 printf_filtered ("0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
929 (long)cpu_registers(processor
)->gpr
[arg0
],
930 (long)cpu_registers(processor
)->gpr
[arg0
+1],
931 (long)cpu_registers(processor
)->gpr
[arg0
+2],
932 (long)cpu_registers(processor
)->gpr
[arg0
+3],
933 (long)cpu_registers(processor
)->gpr
[arg0
+4],
934 (long)cpu_registers(processor
)->gpr
[arg0
+5]);
936 emul_write_status(processor
, 0, errno
);
940 /* Common code for initializing the system call stuff */
942 static os_emul_data
*
943 emul_unix_create(device
*root
,
946 emul_syscall
*syscall
)
948 unsigned_word top_of_stack
;
955 /* merge any emulation specific entries into the device tree */
957 /* establish a few defaults */
958 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
960 top_of_stack
= 0xe0000000;
961 stack_size
= 0x00100000;
965 top_of_stack
= 0x20000000;
966 stack_size
= 0x00100000;
970 emul_add_tree_options(root
, image
, name
,
971 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
972 ? "user" : "virtual"),
973 0 /*oea-interrupt-prefix*/);
975 /* virtual memory - handles growth of stack/heap */
976 vm
= tree_parse(root
, "/openprom/vm@0x%lx",
977 (unsigned long)(top_of_stack
- stack_size
));
978 tree_parse(vm
, "./stack-base 0x%lx",
979 (unsigned long)(top_of_stack
- stack_size
));
980 tree_parse(vm
, "./nr-bytes 0x%x", stack_size
);
982 filename
= tree_quote_property (bfd_get_filename(image
));
983 tree_parse(root
, "/openprom/vm/map-binary/file-name %s",
987 /* finish the init */
988 tree_parse(root
, "/openprom/init/register/pc 0x%lx",
989 (unsigned long)bfd_get_start_address(image
));
990 tree_parse(root
, "/openprom/init/register/sp 0x%lx",
991 (unsigned long)top_of_stack
);
992 tree_parse(root
, "/openprom/init/register/msr 0x%x",
993 ((tree_find_boolean_property(root
, "/options/little-endian?")
994 ? msr_little_endian_mode
996 | (tree_find_boolean_property(root
, "/openprom/options/floating-point?")
997 ? (msr_floating_point_available
998 | msr_floating_point_exception_mode_0
999 | msr_floating_point_exception_mode_1
)
1001 tree_parse(root
, "/openprom/init/stack/stack-type %s",
1002 (elf_binary
? "ppc-elf" : "ppc-xcoff"));
1004 /* finally our emulation data */
1005 data
= ZALLOC(os_emul_data
);
1007 data
->syscalls
= syscall
;
1014 Solaris - Emulation of user programs for Solaris/PPC
1021 /* Solaris specific implementation */
1023 typedef signed32 solaris_uid_t
;
1024 typedef signed32 solaris_gid_t
;
1025 typedef signed32 solaris_off_t
;
1026 typedef signed32 solaris_pid_t
;
1027 typedef signed32 solaris_time_t
;
1028 typedef unsigned32 solaris_dev_t
;
1029 typedef unsigned32 solaris_ino_t
;
1030 typedef unsigned32 solaris_mode_t
;
1031 typedef unsigned32 solaris_nlink_t
;
1033 #ifdef HAVE_SYS_STAT_H
1034 #define SOLARIS_ST_FSTYPSZ 16 /* array size for file system type name */
1036 /* AIX 7.1 defines st_pad[123] to st_[amc]tim.tv_pad, respectively */
1041 struct solaris_stat
{
1042 solaris_dev_t st_dev
;
1043 signed32 st_pad1
[3]; /* reserved for network id */
1044 solaris_ino_t st_ino
;
1045 solaris_mode_t st_mode
;
1046 solaris_nlink_t st_nlink
;
1047 solaris_uid_t st_uid
;
1048 solaris_gid_t st_gid
;
1049 solaris_dev_t st_rdev
;
1050 signed32 st_pad2
[2];
1051 solaris_off_t st_size
;
1052 signed32 st_pad3
; /* future off_t expansion */
1053 struct unix_timeval st_atim
;
1054 struct unix_timeval st_mtim
;
1055 struct unix_timeval st_ctim
;
1056 signed32 st_blksize
;
1058 char st_fstype
[SOLARIS_ST_FSTYPSZ
];
1059 signed32 st_pad4
[8]; /* expansion area */
1062 /* Convert from host stat structure to solaris stat structure */
1063 STATIC_INLINE_EMUL_UNIX
void
1064 convert_to_solaris_stat(unsigned_word addr
,
1069 struct solaris_stat target
;
1072 target
.st_dev
= H2T_4(host
->st_dev
);
1073 target
.st_ino
= H2T_4(host
->st_ino
);
1074 target
.st_mode
= H2T_4(host
->st_mode
);
1075 target
.st_nlink
= H2T_4(host
->st_nlink
);
1076 target
.st_uid
= H2T_4(host
->st_uid
);
1077 target
.st_gid
= H2T_4(host
->st_gid
);
1078 target
.st_size
= H2T_4(host
->st_size
);
1081 target
.st_rdev
= H2T_4(host
->st_rdev
);
1086 #ifdef HAVE_ST_BLKSIZE
1087 target
.st_blksize
= H2T_4(host
->st_blksize
);
1089 target
.st_blksize
= 0;
1092 #ifdef HAVE_ST_BLOCKS
1093 target
.st_blocks
= H2T_4(host
->st_blocks
);
1095 target
.st_blocks
= 0;
1098 target
.st_atim
.tv_sec
= H2T_4(host
->st_atime
);
1099 target
.st_atim
.tv_usec
= 0;
1101 target
.st_ctim
.tv_sec
= H2T_4(host
->st_ctime
);
1102 target
.st_ctim
.tv_usec
= 0;
1104 target
.st_mtim
.tv_sec
= H2T_4(host
->st_mtime
);
1105 target
.st_mtim
.tv_usec
= 0;
1107 for (i
= 0; i
< sizeof (target
.st_pad1
) / sizeof (target
.st_pad1
[0]); i
++)
1108 target
.st_pad1
[i
] = 0;
1110 for (i
= 0; i
< sizeof (target
.st_pad2
) / sizeof (target
.st_pad2
[0]); i
++)
1111 target
.st_pad2
[i
] = 0;
1115 for (i
= 0; i
< sizeof (target
.st_pad4
) / sizeof (target
.st_pad4
[0]); i
++)
1116 target
.st_pad4
[i
] = 0;
1118 /* For now, just punt and always say it is a ufs file */
1119 strcpy (target
.st_fstype
, "ufs");
1121 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1123 #endif /* HAVE_SYS_STAT_H */
1126 #define do_solaris_stat 0
1129 do_solaris_stat(os_emul_data
*emul
,
1135 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1136 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1137 char path_buf
[PATH_MAX
];
1139 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1142 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1143 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1145 status
= stat (path
, &buf
);
1147 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1149 emul_write_status(processor
, status
, errno
);
1154 #define do_solaris_lstat 0
1157 do_solaris_lstat(os_emul_data
*emul
,
1163 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1164 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1165 char path_buf
[PATH_MAX
];
1167 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1170 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1171 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1173 status
= lstat (path
, &buf
);
1175 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1177 emul_write_status(processor
, status
, errno
);
1182 #define do_solaris_fstat 0
1185 do_solaris_fstat(os_emul_data
*emul
,
1191 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
1192 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1196 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1197 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
1199 status
= fstat (fildes
, &buf
);
1201 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1203 emul_write_status(processor
, status
, errno
);
1207 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1208 #define SOLARIS_TIOC ('T'<<8)
1209 #define SOLARIS_NCC 8
1210 #define SOLARIS_NCCS 19
1212 #define SOLARIS_VINTR 0
1213 #define SOLARIS_VQUIT 1
1214 #define SOLARIS_VERASE 2
1215 #define SOLARIS_VKILL 3
1216 #define SOLARIS_VEOF 4
1217 #define SOLARIS_VEOL 5
1218 #define SOLARIS_VEOL2 6
1219 #define SOLARIS_VSWTCH 7
1220 #define SOLARIS_VSTART 8
1221 #define SOLARIS_VSTOP 9
1222 #define SOLARIS_VSUSP 10
1223 #define SOLARIS_VDSUSP 11
1224 #define SOLARIS_VREPRINT 12
1225 #define SOLARIS_VDISCARD 13
1226 #define SOLARIS_VWERASE 14
1227 #define SOLARIS_VLNEXT 15
1230 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1231 /* Convert to/from host termio structure */
1233 struct solaris_termio
{
1234 unsigned16 c_iflag
; /* input modes */
1235 unsigned16 c_oflag
; /* output modes */
1236 unsigned16 c_cflag
; /* control modes */
1237 unsigned16 c_lflag
; /* line discipline modes */
1238 unsigned8 c_line
; /* line discipline */
1239 unsigned8 c_cc
[SOLARIS_NCC
]; /* control chars */
1242 STATIC_INLINE_EMUL_UNIX
void
1243 convert_to_solaris_termio(unsigned_word addr
,
1244 struct termio
*host
,
1248 struct solaris_termio target
;
1251 target
.c_iflag
= H2T_2 (host
->c_iflag
);
1252 target
.c_oflag
= H2T_2 (host
->c_oflag
);
1253 target
.c_cflag
= H2T_2 (host
->c_cflag
);
1254 target
.c_lflag
= H2T_2 (host
->c_lflag
);
1256 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
1257 target
.c_line
= host
->c_line
;
1262 for (i
= 0; i
< SOLARIS_NCC
; i
++)
1266 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1270 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1274 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1278 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1282 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1286 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1290 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1294 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1298 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1302 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1304 #endif /* HAVE_TERMIO_STRUCTURE || HAVE_TERMIOS_STRUCTURE */
1306 #ifdef HAVE_TERMIOS_STRUCTURE
1307 /* Convert to/from host termios structure */
1309 typedef unsigned32 solaris_tcflag_t
;
1310 typedef unsigned8 solaris_cc_t
;
1311 typedef unsigned32 solaris_speed_t
;
1313 struct solaris_termios
{
1314 solaris_tcflag_t c_iflag
;
1315 solaris_tcflag_t c_oflag
;
1316 solaris_tcflag_t c_cflag
;
1317 solaris_tcflag_t c_lflag
;
1318 solaris_cc_t c_cc
[SOLARIS_NCCS
];
1321 STATIC_INLINE_EMUL_UNIX
void
1322 convert_to_solaris_termios(unsigned_word addr
,
1323 struct termios
*host
,
1327 struct solaris_termios target
;
1330 target
.c_iflag
= H2T_4 (host
->c_iflag
);
1331 target
.c_oflag
= H2T_4 (host
->c_oflag
);
1332 target
.c_cflag
= H2T_4 (host
->c_cflag
);
1333 target
.c_lflag
= H2T_4 (host
->c_lflag
);
1335 for (i
= 0; i
< SOLARIS_NCCS
; i
++)
1339 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1343 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1347 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1351 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1355 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1359 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1363 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1367 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1371 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1376 target
.c_cc
[SOLARIS_VSTART
] = host
->c_cc
[VSTART
];
1380 target
.c_cc
[SOLARIS_VSTOP
] = host
->c_cc
[VSTOP
];
1384 target
.c_cc
[SOLARIS_VSUSP
] = host
->c_cc
[VSUSP
];
1388 target
.c_cc
[SOLARIS_VDSUSP
] = host
->c_cc
[VDSUSP
];
1392 target
.c_cc
[SOLARIS_VREPRINT
] = host
->c_cc
[VREPRINT
];
1396 target
.c_cc
[SOLARIS_VDISCARD
] = host
->c_cc
[VDISCARD
];
1400 target
.c_cc
[SOLARIS_VWERASE
] = host
->c_cc
[VWERASE
];
1404 target
.c_cc
[SOLARIS_VLNEXT
] = host
->c_cc
[VLNEXT
];
1407 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1409 #endif /* HAVE_TERMIOS_STRUCTURE */
1412 #define do_solaris_ioctl 0
1415 do_solaris_ioctl(os_emul_data
*emul
,
1421 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
1422 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
1423 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
1425 const char *name
= "<unknown>";
1427 #ifdef HAVE_TERMIOS_STRUCTURE
1428 struct termios host_termio
;
1431 #ifdef HAVE_TERMIO_STRUCTURE
1432 struct termio host_termio
;
1438 case 0: /* make sure we have at least one case */
1444 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1445 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
1446 case SOLARIS_TIOC
| 1: /* TCGETA */
1448 #ifdef HAVE_TCGETATTR
1449 status
= tcgetattr(fildes
, &host_termio
);
1450 #elif defined(TCGETS)
1451 status
= ioctl (fildes
, TCGETS
, &host_termio
);
1453 status
= ioctl (fildes
, TCGETA
, &host_termio
);
1456 convert_to_solaris_termio (argp_addr
, &host_termio
, processor
, cia
);
1459 #endif /* HAVE_TERMIO_STRUCTURE */
1461 #ifdef HAVE_TERMIOS_STRUCTURE
1462 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
1463 case SOLARIS_TIOC
| 13: /* TCGETS */
1465 #ifdef HAVE_TCGETATTR
1466 status
= tcgetattr(fildes
, &host_termio
);
1468 status
= ioctl (fildes
, TCGETS
, &host_termio
);
1471 convert_to_solaris_termios (argp_addr
, &host_termio
, processor
, cia
);
1474 #endif /* HAVE_TERMIOS_STRUCTURE */
1477 emul_write_status(processor
, status
, errno
);
1479 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1480 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
1482 #endif /* HAVE_IOCTL */
1484 static emul_syscall_descriptor solaris_descriptors
[] = {
1485 /* 0 */ { 0, "syscall" },
1486 /* 1 */ { do_unix_exit
, "exit" },
1487 /* 2 */ { 0, "fork" },
1488 /* 3 */ { do_unix_read
, "read" },
1489 /* 4 */ { do_unix_write
, "write" },
1490 /* 5 */ { do_unix_open
, "open" },
1491 /* 6 */ { do_unix_close
, "close" },
1492 /* 7 */ { 0, "wait" },
1493 /* 8 */ { 0, "creat" },
1494 /* 9 */ { do_unix_link
, "link" },
1495 /* 10 */ { do_unix_unlink
, "unlink" },
1496 /* 11 */ { 0, "exec" },
1497 /* 12 */ { do_unix_chdir
, "chdir" },
1498 /* 13 */ { do_unix_time
, "time" },
1499 /* 14 */ { 0, "mknod" },
1500 /* 15 */ { 0, "chmod" },
1501 /* 16 */ { 0, "chown" },
1502 /* 17 */ { do_unix_break
, "brk" },
1503 /* 18 */ { do_solaris_stat
, "stat" },
1504 /* 19 */ { do_unix_lseek
, "lseek" },
1505 /* 20 */ { do_unix_getpid2
, "getpid" },
1506 /* 21 */ { 0, "mount" },
1507 /* 22 */ { 0, "umount" },
1508 /* 23 */ { 0, "setuid" },
1509 /* 24 */ { do_unix_getuid2
, "getuid" },
1510 /* 25 */ { 0, "stime" },
1511 /* 26 */ { 0, "ptrace" },
1512 /* 27 */ { 0, "alarm" },
1513 /* 28 */ { do_solaris_fstat
, "fstat" },
1514 /* 29 */ { 0, "pause" },
1515 /* 30 */ { 0, "utime" },
1516 /* 31 */ { 0, "stty" },
1517 /* 32 */ { 0, "gtty" },
1518 /* 33 */ { do_unix_access
, "access" },
1519 /* 34 */ { 0, "nice" },
1520 /* 35 */ { 0, "statfs" },
1521 /* 36 */ { 0, "sync" },
1522 /* 37 */ { 0, "kill" },
1523 /* 38 */ { 0, "fstatfs" },
1524 /* 39 */ { 0, "pgrpsys" },
1525 /* 40 */ { 0, "xenix" },
1526 /* 41 */ { do_unix_dup
, "dup" },
1527 /* 42 */ { 0, "pipe" },
1528 /* 43 */ { 0, "times" },
1529 /* 44 */ { 0, "profil" },
1530 /* 45 */ { 0, "plock" },
1531 /* 46 */ { 0, "setgid" },
1532 /* 47 */ { do_unix_getgid2
, "getgid" },
1533 /* 48 */ { 0, "signal" },
1534 /* 49 */ { 0, "msgsys" },
1535 /* 50 */ { 0, "syssun" },
1536 /* 51 */ { 0, "acct" },
1537 /* 52 */ { 0, "shmsys" },
1538 /* 53 */ { 0, "semsys" },
1539 /* 54 */ { do_solaris_ioctl
, "ioctl" },
1540 /* 55 */ { 0, "uadmin" },
1541 /* 56 */ { 0, 0 /* reserved for exch */ },
1542 /* 57 */ { 0, "utssys" },
1543 /* 58 */ { 0, "fdsync" },
1544 /* 59 */ { 0, "execve" },
1545 /* 60 */ { do_unix_umask
, "umask" },
1546 /* 61 */ { 0, "chroot" },
1547 /* 62 */ { 0, "fcntl" },
1548 /* 63 */ { 0, "ulimit" },
1549 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1550 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1551 /* 65 */ { 0, 0 /* reserved for UNIX PC */ },
1552 /* 66 */ { 0, 0 /* reserved for UNIX PC */ },
1553 /* 67 */ { 0, 0 /* reserved for UNIX PC */ },
1554 /* 68 */ { 0, 0 /* reserved for UNIX PC */ },
1555 /* 69 */ { 0, 0 /* reserved for UNIX PC */ },
1556 /* 70 */ { 0, 0 /* was advfs */ },
1557 /* 71 */ { 0, 0 /* was unadvfs */ },
1558 /* 72 */ { 0, 0 /* was rmount */ },
1559 /* 73 */ { 0, 0 /* was rumount */ },
1560 /* 74 */ { 0, 0 /* was rfstart */ },
1561 /* 75 */ { 0, 0 /* was sigret */ },
1562 /* 76 */ { 0, 0 /* was rdebug */ },
1563 /* 77 */ { 0, 0 /* was rfstop */ },
1564 /* 78 */ { 0, 0 /* was rfsys */ },
1565 /* 79 */ { do_unix_rmdir
, "rmdir" },
1566 /* 80 */ { do_unix_mkdir
, "mkdir" },
1567 /* 81 */ { 0, "getdents" },
1568 /* 82 */ { 0, 0 /* was libattach */ },
1569 /* 83 */ { 0, 0 /* was libdetach */ },
1570 /* 84 */ { 0, "sysfs" },
1571 /* 85 */ { 0, "getmsg" },
1572 /* 86 */ { 0, "putmsg" },
1573 /* 87 */ { 0, "poll" },
1574 /* 88 */ { do_solaris_lstat
, "lstat" },
1575 /* 89 */ { do_unix_symlink
, "symlink" },
1576 /* 90 */ { 0, "readlink" },
1577 /* 91 */ { 0, "setgroups" },
1578 /* 92 */ { 0, "getgroups" },
1579 /* 93 */ { 0, "fchmod" },
1580 /* 94 */ { 0, "fchown" },
1581 /* 95 */ { 0, "sigprocmask" },
1582 /* 96 */ { 0, "sigsuspend" },
1583 /* 97 */ { do_unix_nop
, "sigaltstack" },
1584 /* 98 */ { do_unix_nop
, "sigaction" },
1585 /* 99 */ { 0, "sigpending" },
1586 /* 100 */ { 0, "context" },
1587 /* 101 */ { 0, "evsys" },
1588 /* 102 */ { 0, "evtrapret" },
1589 /* 103 */ { 0, "statvfs" },
1590 /* 104 */ { 0, "fstatvfs" },
1591 /* 105 */ { 0, 0 /* reserved */ },
1592 /* 106 */ { 0, "nfssys" },
1593 /* 107 */ { 0, "waitsys" },
1594 /* 108 */ { 0, "sigsendsys" },
1595 /* 109 */ { 0, "hrtsys" },
1596 /* 110 */ { 0, "acancel" },
1597 /* 111 */ { 0, "async" },
1598 /* 112 */ { 0, "priocntlsys" },
1599 /* 113 */ { 0, "pathconf" },
1600 /* 114 */ { 0, "mincore" },
1601 /* 115 */ { 0, "mmap" },
1602 /* 116 */ { 0, "mprotect" },
1603 /* 117 */ { 0, "munmap" },
1604 /* 118 */ { 0, "fpathconf" },
1605 /* 119 */ { 0, "vfork" },
1606 /* 120 */ { 0, "fchdir" },
1607 /* 121 */ { 0, "readv" },
1608 /* 122 */ { 0, "writev" },
1609 /* 123 */ { 0, "xstat" },
1610 /* 124 */ { 0, "lxstat" },
1611 /* 125 */ { 0, "fxstat" },
1612 /* 126 */ { 0, "xmknod" },
1613 /* 127 */ { 0, "clocal" },
1614 /* 128 */ { 0, "setrlimit" },
1615 /* 129 */ { 0, "getrlimit" },
1616 /* 130 */ { 0, "lchown" },
1617 /* 131 */ { 0, "memcntl" },
1618 /* 132 */ { 0, "getpmsg" },
1619 /* 133 */ { 0, "putpmsg" },
1620 /* 134 */ { 0, "rename" },
1621 /* 135 */ { 0, "uname" },
1622 /* 136 */ { 0, "setegid" },
1623 /* 137 */ { 0, "sysconfig" },
1624 /* 138 */ { 0, "adjtime" },
1625 /* 139 */ { 0, "systeminfo" },
1626 /* 140 */ { 0, 0 /* reserved */ },
1627 /* 141 */ { 0, "seteuid" },
1628 /* 142 */ { 0, "vtrace" },
1629 /* 143 */ { 0, "fork1" },
1630 /* 144 */ { 0, "sigtimedwait" },
1631 /* 145 */ { 0, "lwp_info" },
1632 /* 146 */ { 0, "yield" },
1633 /* 147 */ { 0, "lwp_sema_wait" },
1634 /* 148 */ { 0, "lwp_sema_post" },
1635 /* 149 */ { 0, 0 /* reserved */ },
1636 /* 150 */ { 0, 0 /* reserved */ },
1637 /* 151 */ { 0, 0 /* reserved */ },
1638 /* 152 */ { 0, "modctl" },
1639 /* 153 */ { 0, "fchroot" },
1640 /* 154 */ { 0, "utimes" },
1641 /* 155 */ { 0, "vhangup" },
1642 /* 156 */ { do_unix_gettimeofday
, "gettimeofday" },
1643 /* 157 */ { 0, "getitimer" },
1644 /* 158 */ { 0, "setitimer" },
1645 /* 159 */ { 0, "lwp_create" },
1646 /* 160 */ { 0, "lwp_exit" },
1647 /* 161 */ { 0, "lwp_suspend" },
1648 /* 162 */ { 0, "lwp_continue" },
1649 /* 163 */ { 0, "lwp_kill" },
1650 /* 164 */ { 0, "lwp_self" },
1651 /* 165 */ { 0, "lwp_setprivate" },
1652 /* 166 */ { 0, "lwp_getprivate" },
1653 /* 167 */ { 0, "lwp_wait" },
1654 /* 168 */ { 0, "lwp_mutex_unlock" },
1655 /* 169 */ { 0, "lwp_mutex_lock" },
1656 /* 170 */ { 0, "lwp_cond_wait" },
1657 /* 171 */ { 0, "lwp_cond_signal" },
1658 /* 172 */ { 0, "lwp_cond_broadcast" },
1659 /* 173 */ { 0, "pread" },
1660 /* 174 */ { 0, "pwrite" },
1661 /* 175 */ { 0, "llseek" },
1662 /* 176 */ { 0, "inst_sync" },
1663 /* 177 */ { 0, 0 /* reserved */ },
1664 /* 178 */ { 0, "kaio" },
1665 /* 179 */ { 0, 0 /* reserved */ },
1666 /* 180 */ { 0, 0 /* reserved */ },
1667 /* 181 */ { 0, 0 /* reserved */ },
1668 /* 182 */ { 0, 0 /* reserved */ },
1669 /* 183 */ { 0, 0 /* reserved */ },
1670 /* 184 */ { 0, "tsolsys" },
1671 /* 185 */ { 0, "acl" },
1672 /* 186 */ { 0, "auditsys" },
1673 /* 187 */ { 0, "processor_bind" },
1674 /* 188 */ { 0, "processor_info" },
1675 /* 189 */ { 0, "p_online" },
1676 /* 190 */ { 0, "sigqueue" },
1677 /* 191 */ { 0, "clock_gettime" },
1678 /* 192 */ { 0, "clock_settime" },
1679 /* 193 */ { 0, "clock_getres" },
1680 /* 194 */ { 0, "timer_create" },
1681 /* 195 */ { 0, "timer_delete" },
1682 /* 196 */ { 0, "timer_settime" },
1683 /* 197 */ { 0, "timer_gettime" },
1684 /* 198 */ { 0, "timer_getoverrun" },
1685 /* 199 */ { 0, "nanosleep" },
1686 /* 200 */ { 0, "facl" },
1687 /* 201 */ { 0, "door" },
1688 /* 202 */ { 0, "setreuid" },
1689 /* 203 */ { 0, "setregid" },
1690 /* 204 */ { 0, "install_utrap" },
1691 /* 205 */ { 0, 0 /* reserved */ },
1692 /* 206 */ { 0, 0 /* reserved */ },
1693 /* 207 */ { 0, 0 /* reserved */ },
1694 /* 208 */ { 0, 0 /* reserved */ },
1695 /* 209 */ { 0, 0 /* reserved */ },
1696 /* 210 */ { 0, "signotifywait" },
1697 /* 211 */ { 0, "lwp_sigredirect" },
1698 /* 212 */ { 0, "lwp_alarm" },
1701 static char *(solaris_error_names
[]) = {
1740 /* 38 */ "EL2NSYNC",
1749 /* 47 */ "ECANCELED",
1758 /* 56 */ "EDEADLOCK",
1760 /* 58 */ "Error code 58",
1761 /* 59 */ "Error code 59",
1774 /* 72 */ "Error code 72",
1775 /* 73 */ "Error code 73",
1776 /* 74 */ "EMULTIHOP",
1777 /* 75 */ "Error code 75",
1778 /* 76 */ "Error code 76",
1780 /* 78 */ "ENAMETOOLONG",
1781 /* 79 */ "EOVERFLOW",
1782 /* 80 */ "ENOTUNIQ",
1789 /* 87 */ "ELIBEXEC",
1793 /* 91 */ "ERESTART",
1794 /* 92 */ "ESTRPIPE",
1795 /* 93 */ "ENOTEMPTY",
1797 /* 95 */ "ENOTSOCK",
1798 /* 96 */ "EDESTADDRREQ",
1799 /* 97 */ "EMSGSIZE",
1800 /* 98 */ "EPROTOTYPE",
1801 /* 99 */ "ENOPROTOOPT",
1802 /* 100 */ "Error code 100",
1803 /* 101 */ "Error code 101",
1804 /* 102 */ "Error code 102",
1805 /* 103 */ "Error code 103",
1806 /* 104 */ "Error code 104",
1807 /* 105 */ "Error code 105",
1808 /* 106 */ "Error code 106",
1809 /* 107 */ "Error code 107",
1810 /* 108 */ "Error code 108",
1811 /* 109 */ "Error code 109",
1812 /* 110 */ "Error code 110",
1813 /* 111 */ "Error code 111",
1814 /* 112 */ "Error code 112",
1815 /* 113 */ "Error code 113",
1816 /* 114 */ "Error code 114",
1817 /* 115 */ "Error code 115",
1818 /* 116 */ "Error code 116",
1819 /* 117 */ "Error code 117",
1820 /* 118 */ "Error code 118",
1821 /* 119 */ "Error code 119",
1822 /* 120 */ "EPROTONOSUPPORT",
1823 /* 121 */ "ESOCKTNOSUPPORT",
1824 /* 122 */ "EOPNOTSUPP",
1825 /* 123 */ "EPFNOSUPPORT",
1826 /* 124 */ "EAFNOSUPPORT",
1827 /* 125 */ "EADDRINUSE",
1828 /* 126 */ "EADDRNOTAVAIL",
1829 /* 127 */ "ENETDOWN",
1830 /* 128 */ "ENETUNREACH",
1831 /* 129 */ "ENETRESET",
1832 /* 130 */ "ECONNABORTED",
1833 /* 131 */ "ECONNRESET",
1834 /* 132 */ "ENOBUFS",
1835 /* 133 */ "EISCONN",
1836 /* 134 */ "ENOTCONN",
1837 /* 135 */ "Error code 135", /* XENIX has 135 - 142 */
1838 /* 136 */ "Error code 136",
1839 /* 137 */ "Error code 137",
1840 /* 138 */ "Error code 138",
1841 /* 139 */ "Error code 139",
1842 /* 140 */ "Error code 140",
1843 /* 141 */ "Error code 141",
1844 /* 142 */ "Error code 142",
1845 /* 143 */ "ESHUTDOWN",
1846 /* 144 */ "ETOOMANYREFS",
1847 /* 145 */ "ETIMEDOUT",
1848 /* 146 */ "ECONNREFUSED",
1849 /* 147 */ "EHOSTDOWN",
1850 /* 148 */ "EHOSTUNREACH",
1851 /* 149 */ "EALREADY",
1852 /* 150 */ "EINPROGRESS",
1856 static char *(solaris_signal_names
[]) = {
1877 /* 20 */ "SIGWINCH",
1885 /* 28 */ "SIGVTALRM",
1889 /* 32 */ "SIGWAITING",
1891 /* 34 */ "SIGFREEZE",
1893 /* 36 */ "SIGCANCEL",
1896 static emul_syscall emul_solaris_syscalls
= {
1897 solaris_descriptors
,
1898 sizeof(solaris_descriptors
) / sizeof(solaris_descriptors
[0]),
1899 solaris_error_names
,
1900 sizeof(solaris_error_names
) / sizeof(solaris_error_names
[0]),
1901 solaris_signal_names
,
1902 sizeof(solaris_signal_names
) / sizeof(solaris_signal_names
[0]),
1906 /* Solaris's os_emul interface, most are just passed on to the generic
1909 static os_emul_data
*
1910 emul_solaris_create(device
*root
,
1914 /* check that this emulation is really for us */
1915 if (name
!= NULL
&& strcmp(name
, "solaris") != 0)
1921 return emul_unix_create(root
, image
, "solaris", &emul_solaris_syscalls
);
1925 emul_solaris_init(os_emul_data
*emul_data
,
1932 emul_solaris_system_call(cpu
*processor
,
1934 os_emul_data
*emul_data
)
1936 emul_do_system_call(emul_data
,
1937 emul_data
->syscalls
,
1938 cpu_registers(processor
)->gpr
[0],
1939 3, /*r3 contains arg0*/
1944 const os_emul emul_solaris
= {
1946 emul_solaris_create
,
1948 emul_solaris_system_call
,
1949 0, /*instruction_call*/
1956 Linux - Emulation of user programs for Linux/PPC
1963 /* Linux specific implementation */
1965 typedef unsigned32 linux_dev_t
;
1966 typedef unsigned32 linux_ino_t
;
1967 typedef unsigned32 linux_mode_t
;
1968 typedef unsigned16 linux_nlink_t
;
1969 typedef signed32 linux_off_t
;
1970 typedef signed32 linux_pid_t
;
1971 typedef unsigned32 linux_uid_t
;
1972 typedef unsigned32 linux_gid_t
;
1973 typedef unsigned32 linux_size_t
;
1974 typedef signed32 linux_ssize_t
;
1975 typedef signed32 linux_ptrdiff_t
;
1976 typedef signed32 linux_time_t
;
1977 typedef signed32 linux_clock_t
;
1978 typedef signed32 linux_daddr_t
;
1980 #ifdef HAVE_SYS_STAT_H
1981 /* For the PowerPC, don't both with the 'old' stat structure, since there
1982 should be no extant binaries with that structure. */
1987 linux_mode_t st_mode
;
1988 linux_nlink_t st_nlink
;
1991 linux_dev_t st_rdev
;
1992 linux_off_t st_size
;
1993 unsigned32 st_blksize
;
1994 unsigned32 st_blocks
;
1995 unsigned32 st_atimx
; /* don't use st_{a,c,m}time, that might a macro */
1996 unsigned32 __unused1
; /* defined by the host's stat.h */
1997 unsigned32 st_mtimx
;
1998 unsigned32 __unused2
;
1999 unsigned32 st_ctimx
;
2000 unsigned32 __unused3
;
2001 unsigned32 __unused4
;
2002 unsigned32 __unused5
;
2005 /* Convert from host stat structure to solaris stat structure */
2006 STATIC_INLINE_EMUL_UNIX
void
2007 convert_to_linux_stat(unsigned_word addr
,
2012 struct linux_stat target
;
2014 target
.st_dev
= H2T_4(host
->st_dev
);
2015 target
.st_ino
= H2T_4(host
->st_ino
);
2016 target
.st_mode
= H2T_4(host
->st_mode
);
2017 target
.st_nlink
= H2T_2(host
->st_nlink
);
2018 target
.st_uid
= H2T_4(host
->st_uid
);
2019 target
.st_gid
= H2T_4(host
->st_gid
);
2020 target
.st_size
= H2T_4(host
->st_size
);
2023 target
.st_rdev
= H2T_4(host
->st_rdev
);
2028 #ifdef HAVE_ST_BLKSIZE
2029 target
.st_blksize
= H2T_4(host
->st_blksize
);
2031 target
.st_blksize
= 0;
2034 #ifdef HAVE_ST_BLOCKS
2035 target
.st_blocks
= H2T_4(host
->st_blocks
);
2037 target
.st_blocks
= 0;
2040 target
.st_atimx
= H2T_4(host
->st_atime
);
2041 target
.st_ctimx
= H2T_4(host
->st_ctime
);
2042 target
.st_mtimx
= H2T_4(host
->st_mtime
);
2043 target
.__unused1
= 0;
2044 target
.__unused2
= 0;
2045 target
.__unused3
= 0;
2046 target
.__unused4
= 0;
2047 target
.__unused5
= 0;
2049 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2051 #endif /* HAVE_SYS_STAT_H */
2054 #define do_linux_stat 0
2057 do_linux_stat(os_emul_data
*emul
,
2063 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
2064 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2065 char path_buf
[PATH_MAX
];
2067 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
2070 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2071 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2073 status
= stat (path
, &buf
);
2075 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2077 emul_write_status(processor
, status
, errno
);
2082 #define do_linux_lstat 0
2085 do_linux_lstat(os_emul_data
*emul
,
2091 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
2092 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2093 char path_buf
[PATH_MAX
];
2095 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
2098 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2099 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2101 status
= lstat (path
, &buf
);
2103 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2105 emul_write_status(processor
, status
, errno
);
2110 #define do_linux_fstat 0
2113 do_linux_fstat(os_emul_data
*emul
,
2119 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
2120 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2124 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2125 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
2127 status
= fstat (fildes
, &buf
);
2129 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2131 emul_write_status(processor
, status
, errno
);
2135 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2136 #define LINUX_NCC 10
2137 #define LINUX_NCCS 19
2139 #define LINUX_VINTR 0
2140 #define LINUX_VQUIT 1
2141 #define LINUX_VERASE 2
2142 #define LINUX_VKILL 3
2143 #define LINUX_VEOF 4
2144 #define LINUX_VMIN 5
2145 #define LINUX_VEOL 6
2146 #define LINUX_VTIME 7
2147 #define LINUX_VEOL2 8
2148 #define LINUX_VSWTC 9
2149 #define LINUX_VWERASE 10
2150 #define LINUX_VREPRINT 11
2151 #define LINUX_VSUSP 12
2152 #define LINUX_VSTART 13
2153 #define LINUX_VSTOP 14
2154 #define LINUX_VLNEXT 15
2155 #define LINUX_VDISCARD 16
2157 #define LINUX_IOC_NRBITS 8
2158 #define LINUX_IOC_TYPEBITS 8
2159 #define LINUX_IOC_SIZEBITS 13
2160 #define LINUX_IOC_DIRBITS 3
2162 #define LINUX_IOC_NRMASK ((1 << LINUX_IOC_NRBITS)-1)
2163 #define LINUX_IOC_TYPEMASK ((1 << LINUX_IOC_TYPEBITS)-1)
2164 #define LINUX_IOC_SIZEMASK ((1 << LINUX_IOC_SIZEBITS)-1)
2165 #define LINUX_IOC_DIRMASK ((1 << LINUX_IOC_DIRBITS)-1)
2167 #define LINUX_IOC_NRSHIFT 0
2168 #define LINUX_IOC_TYPESHIFT (LINUX_IOC_NRSHIFT+LINUX_IOC_NRBITS)
2169 #define LINUX_IOC_SIZESHIFT (LINUX_IOC_TYPESHIFT+LINUX_IOC_TYPEBITS)
2170 #define LINUX_IOC_DIRSHIFT (LINUX_IOC_SIZESHIFT+LINUX_IOC_SIZEBITS)
2173 * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
2174 * And this turns out useful to catch old ioctl numbers in header
2177 #define LINUX_IOC_NONE 1U
2178 #define LINUX_IOC_READ 2U
2179 #define LINUX_IOC_WRITE 4U
2181 #define LINUX_IOC(dir,type,nr,size) \
2182 (((dir) << LINUX_IOC_DIRSHIFT) | \
2183 ((type) << LINUX_IOC_TYPESHIFT) | \
2184 ((nr) << LINUX_IOC_NRSHIFT) | \
2185 ((size) << LINUX_IOC_SIZESHIFT))
2187 /* used to create numbers */
2188 #define LINUX_IO(type,nr) LINUX_IOC(LINUX_IOC_NONE,(type),(nr),0)
2189 #define LINUX_IOR(type,nr,size) LINUX_IOC(LINUX_IOC_READ,(type),(nr),sizeof(size))
2190 #define LINUX_IOW(type,nr,size) LINUX_IOC(LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2191 #define LINUX_IOWR(type,nr,size) LINUX_IOC(LINUX_IOC_READ|LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2194 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2195 /* Convert to/from host termio structure */
2197 struct linux_termio
{
2198 unsigned16 c_iflag
; /* input modes */
2199 unsigned16 c_oflag
; /* output modes */
2200 unsigned16 c_cflag
; /* control modes */
2201 unsigned16 c_lflag
; /* line discipline modes */
2202 unsigned8 c_line
; /* line discipline */
2203 unsigned8 c_cc
[LINUX_NCC
]; /* control chars */
2206 STATIC_INLINE_EMUL_UNIX
void
2207 convert_to_linux_termio(unsigned_word addr
,
2208 struct termio
*host
,
2212 struct linux_termio target
;
2215 target
.c_iflag
= H2T_2 (host
->c_iflag
);
2216 target
.c_oflag
= H2T_2 (host
->c_oflag
);
2217 target
.c_cflag
= H2T_2 (host
->c_cflag
);
2218 target
.c_lflag
= H2T_2 (host
->c_lflag
);
2220 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
2221 target
.c_line
= host
->c_line
;
2226 for (i
= 0; i
< LINUX_NCC
; i
++)
2230 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2234 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2238 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2242 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2246 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2250 target
.c_cc
[LINUX_VMIN
] = host
->c_cc
[VMIN
];
2254 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2258 target
.c_cc
[LINUX_VTIME
] = host
->c_cc
[VTIME
];
2262 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2266 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTC
];
2270 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2273 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2275 #endif /* HAVE_TERMIO_STRUCTURE */
2277 #ifdef HAVE_TERMIOS_STRUCTURE
2278 /* Convert to/from host termios structure */
2280 typedef unsigned32 linux_tcflag_t
;
2281 typedef unsigned8 linux_cc_t
;
2282 typedef unsigned32 linux_speed_t
;
2284 struct linux_termios
{
2285 linux_tcflag_t c_iflag
;
2286 linux_tcflag_t c_oflag
;
2287 linux_tcflag_t c_cflag
;
2288 linux_tcflag_t c_lflag
;
2289 linux_cc_t c_cc
[LINUX_NCCS
];
2295 STATIC_INLINE_EMUL_UNIX
void
2296 convert_to_linux_termios(unsigned_word addr
,
2297 struct termios
*host
,
2301 struct linux_termios target
;
2304 target
.c_iflag
= H2T_4 (host
->c_iflag
);
2305 target
.c_oflag
= H2T_4 (host
->c_oflag
);
2306 target
.c_cflag
= H2T_4 (host
->c_cflag
);
2307 target
.c_lflag
= H2T_4 (host
->c_lflag
);
2309 for (i
= 0; i
< LINUX_NCCS
; i
++)
2313 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2317 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2321 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2325 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2329 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2333 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2337 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2341 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2344 #ifdef HAVE_TERMIOS_CLINE
2345 target
.c_line
= host
->c_line
;
2350 #ifdef HAVE_CFGETISPEED
2351 target
.c_ispeed
= cfgetispeed (host
);
2353 target
.c_ispeed
= 0;
2356 #ifdef HAVE_CFGETOSPEED
2357 target
.c_ospeed
= cfgetospeed (host
);
2359 target
.c_ospeed
= 0;
2362 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2364 #endif /* HAVE_TERMIOS_STRUCTURE */
2367 #define do_linux_ioctl 0
2370 do_linux_ioctl(os_emul_data
*emul
,
2376 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
2377 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
2378 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
2380 const char *name
= "<unknown>";
2382 #ifdef HAVE_TERMIOS_STRUCTURE
2383 struct termios host_termio
;
2386 #ifdef HAVE_TERMIO_STRUCTURE
2387 struct termio host_termio
;
2393 case 0: /* make sure we have at least one case */
2399 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2400 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
2401 case LINUX_IOR('t', 23, struct linux_termio
): /* TCGETA */
2403 #ifdef HAVE_TCGETATTR
2404 status
= tcgetattr(fildes
, &host_termio
);
2405 #elif defined(TCGETS)
2406 status
= ioctl (fildes
, TCGETS
, &host_termio
);
2408 status
= ioctl (fildes
, TCGETA
, &host_termio
);
2411 convert_to_linux_termio (argp_addr
, &host_termio
, processor
, cia
);
2414 #endif /* HAVE_TERMIO_STRUCTURE */
2416 #ifdef HAVE_TERMIOS_STRUCTURE
2417 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
2418 case LINUX_IOR('t', 19, struct linux_termios
): /* TCGETS */
2420 #ifdef HAVE_TCGETATTR
2421 status
= tcgetattr(fildes
, &host_termio
);
2423 status
= ioctl (fildes
, TCGETS
, &host_termio
);
2426 convert_to_linux_termios (argp_addr
, &host_termio
, processor
, cia
);
2429 #endif /* HAVE_TERMIOS_STRUCTURE */
2432 emul_write_status(processor
, status
, errno
);
2434 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2435 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
2437 #endif /* HAVE_IOCTL */
2439 static emul_syscall_descriptor linux_descriptors
[] = {
2440 /* 0 */ { 0, "setup" },
2441 /* 1 */ { do_unix_exit
, "exit" },
2442 /* 2 */ { 0, "fork" },
2443 /* 3 */ { do_unix_read
, "read" },
2444 /* 4 */ { do_unix_write
, "write" },
2445 /* 5 */ { do_unix_open
, "open" },
2446 /* 6 */ { do_unix_close
, "close" },
2447 /* 7 */ { 0, "waitpid" },
2448 /* 8 */ { 0, "creat" },
2449 /* 9 */ { do_unix_link
, "link" },
2450 /* 10 */ { do_unix_unlink
, "unlink" },
2451 /* 11 */ { 0, "execve" },
2452 /* 12 */ { do_unix_chdir
, "chdir" },
2453 /* 13 */ { do_unix_time
, "time" },
2454 /* 14 */ { 0, "mknod" },
2455 /* 15 */ { 0, "chmod" },
2456 /* 16 */ { 0, "chown" },
2457 /* 17 */ { 0, "break" },
2458 /* 18 */ { 0, "stat" },
2459 /* 19 */ { do_unix_lseek
, "lseek" },
2460 /* 20 */ { do_unix_getpid
, "getpid" },
2461 /* 21 */ { 0, "mount" },
2462 /* 22 */ { 0, "umount" },
2463 /* 23 */ { 0, "setuid" },
2464 /* 24 */ { do_unix_getuid
, "getuid" },
2465 /* 25 */ { 0, "stime" },
2466 /* 26 */ { 0, "ptrace" },
2467 /* 27 */ { 0, "alarm" },
2468 /* 28 */ { 0, "fstat" },
2469 /* 29 */ { 0, "pause" },
2470 /* 30 */ { 0, "utime" },
2471 /* 31 */ { 0, "stty" },
2472 /* 32 */ { 0, "gtty" },
2473 /* 33 */ { do_unix_access
, "access" },
2474 /* 34 */ { 0, "nice" },
2475 /* 35 */ { 0, "ftime" },
2476 /* 36 */ { 0, "sync" },
2477 /* 37 */ { 0, "kill" },
2478 /* 38 */ { 0, "rename" },
2479 /* 39 */ { do_unix_mkdir
, "mkdir" },
2480 /* 40 */ { do_unix_rmdir
, "rmdir" },
2481 /* 41 */ { do_unix_dup
, "dup" },
2482 /* 42 */ { 0, "pipe" },
2483 /* 43 */ { 0, "times" },
2484 /* 44 */ { 0, "prof" },
2485 /* 45 */ { do_unix_break
, "brk" },
2486 /* 46 */ { 0, "setgid" },
2487 /* 47 */ { do_unix_getgid
, "getgid" },
2488 /* 48 */ { 0, "signal" },
2489 /* 49 */ { do_unix_geteuid
, "geteuid" },
2490 /* 50 */ { do_unix_getegid
, "getegid" },
2491 /* 51 */ { 0, "acct" },
2492 /* 52 */ { 0, "phys" },
2493 /* 53 */ { 0, "lock" },
2494 /* 54 */ { do_linux_ioctl
, "ioctl" },
2495 /* 55 */ { 0, "fcntl" },
2496 /* 56 */ { 0, "mpx" },
2497 /* 57 */ { 0, "setpgid" },
2498 /* 58 */ { 0, "ulimit" },
2499 /* 59 */ { 0, "olduname" },
2500 /* 60 */ { do_unix_umask
, "umask" },
2501 /* 61 */ { 0, "chroot" },
2502 /* 62 */ { 0, "ustat" },
2503 /* 63 */ { do_unix_dup2
, "dup2" },
2504 /* 64 */ { do_unix_getppid
, "getppid" },
2505 /* 65 */ { 0, "getpgrp" },
2506 /* 66 */ { 0, "setsid" },
2507 /* 67 */ { 0, "sigaction" },
2508 /* 68 */ { 0, "sgetmask" },
2509 /* 69 */ { 0, "ssetmask" },
2510 /* 70 */ { 0, "setreuid" },
2511 /* 71 */ { 0, "setregid" },
2512 /* 72 */ { 0, "sigsuspend" },
2513 /* 73 */ { 0, "sigpending" },
2514 /* 74 */ { 0, "sethostname" },
2515 /* 75 */ { 0, "setrlimit" },
2516 /* 76 */ { 0, "getrlimit" },
2517 /* 77 */ { do_unix_getrusage
, "getrusage" },
2518 /* 78 */ { do_unix_gettimeofday
, "gettimeofday" },
2519 /* 79 */ { 0, "settimeofday" },
2520 /* 80 */ { 0, "getgroups" },
2521 /* 81 */ { 0, "setgroups" },
2522 /* 82 */ { 0, "select" },
2523 /* 83 */ { do_unix_symlink
, "symlink" },
2524 /* 84 */ { 0, "lstat" },
2525 /* 85 */ { 0, "readlink" },
2526 /* 86 */ { 0, "uselib" },
2527 /* 87 */ { 0, "swapon" },
2528 /* 88 */ { 0, "reboot" },
2529 /* 89 */ { 0, "readdir" },
2530 /* 90 */ { 0, "mmap" },
2531 /* 91 */ { 0, "munmap" },
2532 /* 92 */ { 0, "truncate" },
2533 /* 93 */ { 0, "ftruncate" },
2534 /* 94 */ { 0, "fchmod" },
2535 /* 95 */ { 0, "fchown" },
2536 /* 96 */ { 0, "getpriority" },
2537 /* 97 */ { 0, "setpriority" },
2538 /* 98 */ { 0, "profil" },
2539 /* 99 */ { 0, "statfs" },
2540 /* 100 */ { 0, "fstatfs" },
2541 /* 101 */ { 0, "ioperm" },
2542 /* 102 */ { 0, "socketcall" },
2543 /* 103 */ { 0, "syslog" },
2544 /* 104 */ { 0, "setitimer" },
2545 /* 105 */ { 0, "getitimer" },
2546 /* 106 */ { do_linux_stat
, "newstat" },
2547 /* 107 */ { do_linux_lstat
, "newlstat" },
2548 /* 108 */ { do_linux_fstat
, "newfstat" },
2549 /* 109 */ { 0, "uname" },
2550 /* 110 */ { 0, "iopl" },
2551 /* 111 */ { 0, "vhangup" },
2552 /* 112 */ { 0, "idle" },
2553 /* 113 */ { 0, "vm86" },
2554 /* 114 */ { 0, "wait4" },
2555 /* 115 */ { 0, "swapoff" },
2556 /* 116 */ { 0, "sysinfo" },
2557 /* 117 */ { 0, "ipc" },
2558 /* 118 */ { 0, "fsync" },
2559 /* 119 */ { 0, "sigreturn" },
2560 /* 120 */ { 0, "clone" },
2561 /* 121 */ { 0, "setdomainname" },
2562 /* 122 */ { 0, "newuname" },
2563 /* 123 */ { 0, "modify_ldt" },
2564 /* 124 */ { 0, "adjtimex" },
2565 /* 125 */ { 0, "mprotect" },
2566 /* 126 */ { 0, "sigprocmask" },
2567 /* 127 */ { 0, "create_module" },
2568 /* 128 */ { 0, "init_module" },
2569 /* 129 */ { 0, "delete_module" },
2570 /* 130 */ { 0, "get_kernel_syms" },
2571 /* 131 */ { 0, "quotactl" },
2572 /* 132 */ { 0, "getpgid" },
2573 /* 133 */ { 0, "fchdir" },
2574 /* 134 */ { 0, "bdflush" },
2575 /* 135 */ { 0, "sysfs" },
2576 /* 136 */ { 0, "personality" },
2577 /* 137 */ { 0, "afs_syscall" },
2578 /* 138 */ { 0, "setfsuid" },
2579 /* 139 */ { 0, "setfsgid" },
2580 /* 140 */ { 0, "llseek" },
2581 /* 141 */ { 0, "getdents" },
2582 /* 142 */ { 0, "newselect" },
2583 /* 143 */ { 0, "flock" },
2584 /* 144 */ { 0, "msync" },
2585 /* 145 */ { 0, "readv" },
2586 /* 146 */ { 0, "writev" },
2587 /* 147 */ { 0, "getsid" },
2588 /* 148 */ { 0, "fdatasync" },
2589 /* 149 */ { 0, "sysctl" },
2590 /* 150 */ { 0, "mlock" },
2591 /* 151 */ { 0, "munlock" },
2592 /* 152 */ { 0, "mlockall" },
2593 /* 153 */ { 0, "munlockall" },
2594 /* 154 */ { 0, "sched_setparam" },
2595 /* 155 */ { 0, "sched_getparam" },
2596 /* 156 */ { 0, "sched_setscheduler" },
2597 /* 157 */ { 0, "sched_getscheduler" },
2598 /* 158 */ { 0, "sched_yield" },
2599 /* 159 */ { 0, "sched_get_priority_max" },
2600 /* 160 */ { 0, "sched_get_priority_min" },
2601 /* 161 */ { 0, "sched_rr_get_interval" },
2604 static char *(linux_error_names
[]) = {
2641 /* 36 */ "ENAMETOOLONG",
2644 /* 39 */ "ENOTEMPTY",
2650 /* 45 */ "EL2NSYNC",
2663 /* 58 */ "EDEADLOCK",
2677 /* 72 */ "EMULTIHOP",
2680 /* 75 */ "EOVERFLOW",
2681 /* 76 */ "ENOTUNIQ",
2688 /* 83 */ "ELIBEXEC",
2690 /* 85 */ "ERESTART",
2691 /* 86 */ "ESTRPIPE",
2693 /* 88 */ "ENOTSOCK",
2694 /* 89 */ "EDESTADDRREQ",
2695 /* 90 */ "EMSGSIZE",
2696 /* 91 */ "EPROTOTYPE",
2697 /* 92 */ "ENOPROTOOPT",
2698 /* 93 */ "EPROTONOSUPPORT",
2699 /* 94 */ "ESOCKTNOSUPPORT",
2700 /* 95 */ "EOPNOTSUPP",
2701 /* 96 */ "EPFNOSUPPORT",
2702 /* 97 */ "EAFNOSUPPORT",
2703 /* 98 */ "EADDRINUSE",
2704 /* 99 */ "EADDRNOTAVAIL",
2705 /* 100 */ "ENETDOWN",
2706 /* 101 */ "ENETUNREACH",
2707 /* 102 */ "ENETRESET",
2708 /* 103 */ "ECONNABORTED",
2709 /* 104 */ "ECONNRESET",
2710 /* 105 */ "ENOBUFS",
2711 /* 106 */ "EISCONN",
2712 /* 107 */ "ENOTCONN",
2713 /* 108 */ "ESHUTDOWN",
2714 /* 109 */ "ETOOMANYREFS",
2715 /* 110 */ "ETIMEDOUT",
2716 /* 111 */ "ECONNREFUSED",
2717 /* 112 */ "EHOSTDOWN",
2718 /* 113 */ "EHOSTUNREACH",
2719 /* 114 */ "EALREADY",
2720 /* 115 */ "EINPROGRESS",
2722 /* 117 */ "EUCLEAN",
2723 /* 118 */ "ENOTNAM",
2724 /* 119 */ "ENAVAIL",
2726 /* 121 */ "EREMOTEIO",
2730 static char *(linux_signal_names
[]) = {
2748 /* 16 */ "SIGSTKFLT",
2758 /* 26 */ "SIGVTALRM",
2760 /* 28 */ "SIGWINCH",
2763 /* 31 */ "SIGUNUSED",
2766 static emul_syscall emul_linux_syscalls
= {
2768 sizeof(linux_descriptors
) / sizeof(linux_descriptors
[0]),
2770 sizeof(linux_error_names
) / sizeof(linux_error_names
[0]),
2772 sizeof(linux_signal_names
) / sizeof(linux_signal_names
[0]),
2776 /* Linux's os_emul interface, most are just passed on to the generic
2779 static os_emul_data
*
2780 emul_linux_create(device
*root
,
2784 /* check that this emulation is really for us */
2785 if (name
!= NULL
&& strcmp(name
, "linux") != 0)
2791 return emul_unix_create(root
, image
, "linux", &emul_linux_syscalls
);
2795 emul_linux_init(os_emul_data
*emul_data
,
2802 emul_linux_system_call(cpu
*processor
,
2804 os_emul_data
*emul_data
)
2806 emul_do_system_call(emul_data
,
2807 emul_data
->syscalls
,
2808 cpu_registers(processor
)->gpr
[0],
2809 3, /*r3 contains arg0*/
2814 const os_emul emul_linux
= {
2818 emul_linux_system_call
,
2819 0, /*instruction_call*/
2823 #endif /* _EMUL_UNIX_C_ */