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 2 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, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 /* Note: this module is called via a table. There is no benefit in
29 #include "emul_generic.h"
30 #include "emul_unix.h"
40 #ifdef HAVE_SYS_TYPES_H
41 #include <sys/types.h>
44 #ifdef HAVE_SYS_TYPES_H
60 #ifdef HAVE_SYS_PARAM_H
61 #include <sys/param.h>
64 #ifdef HAVE_SYS_TIME_H
68 #ifndef HAVE_TERMIOS_STRUCTURE
69 #undef HAVE_SYS_TERMIOS_H
72 #ifndef HAVE_SYS_TERMIOS_H
73 #undef HAVE_TERMIOS_STRUCTURE
77 #ifdef HAVE_TERMIOS_STRUCTURE
78 #include <sys/termios.h>
80 /* If we have TERMIOS, use that for the termio structure, since some systems
81 don't like including both sys/termios.h and sys/termio.h at the same
83 #undef HAVE_TERMIO_STRUCTURE
86 #define termio termios
89 #ifndef HAVE_TERMIO_STRUCTURE
90 #undef HAVE_SYS_TERMIO_H
92 #ifndef HAVE_SYS_TERMIO_H
93 #undef HAVE_TERMIO_STRUCTURE
97 #ifdef HAVE_TERMIO_STRUCTURE
98 #include <sys/termio.h>
101 #ifdef HAVE_GETRUSAGE
102 #ifndef HAVE_SYS_RESOURCE_H
103 #undef HAVE_GETRUSAGE
107 #ifdef HAVE_GETRUSAGE
108 #include <sys/resource.h>
114 # define NAMLEN(dirent) strlen((dirent)->d_name)
116 # define dirent direct
117 # define NAMLEN(dirent) (dirent)->d_namlen
119 # include <sys/ndir.h>
122 # include <sys/dir.h>
130 #undef MAXPATHLEN /* sys/param.h might define this also */
138 #if defined(BSD) && !defined(errno) && (BSD < 199306) /* here BSD as just a bug */
142 #ifndef STATIC_INLINE_EMUL_UNIX
143 #define STATIC_INLINE_EMUL_UNIX STATIC_INLINE
147 #define PATH_MAX 1024
154 /* UNIX's idea of what is needed to implement emulations */
156 struct _os_emul_data
{
158 emul_syscall
*syscalls
;
162 /* Emulation of simple UNIX system calls that are common on all systems. */
164 /* Structures that are common agmonst the UNIX varients */
165 struct unix_timeval
{
166 signed32 tv_sec
; /* seconds */
167 signed32 tv_usec
; /* microseconds */
170 struct unix_timezone
{
171 signed32 tz_minuteswest
; /* minutes west of Greenwich */
172 signed32 tz_dsttime
; /* type of dst correction */
175 #define UNIX_RUSAGE_SELF 0
176 #define UNIX_RUSAGE_CHILDREN (-1)
177 #define UNIX_RUSAGE_BOTH (-2) /* sys_wait4() uses this */
180 struct unix_timeval ru_utime
; /* user time used */
181 struct unix_timeval ru_stime
; /* system time used */
182 signed32 ru_maxrss
; /* maximum resident set size */
183 signed32 ru_ixrss
; /* integral shared memory size */
184 signed32 ru_idrss
; /* integral unshared data size */
185 signed32 ru_isrss
; /* integral unshared stack size */
186 signed32 ru_minflt
; /* any page faults not requiring I/O */
187 signed32 ru_majflt
; /* any page faults requiring I/O */
188 signed32 ru_nswap
; /* swaps */
189 signed32 ru_inblock
; /* block input operations */
190 signed32 ru_oublock
; /* block output operations */
191 signed32 ru_msgsnd
; /* messages sent */
192 signed32 ru_msgrcv
; /* messages received */
193 signed32 ru_nsignals
; /* signals received */
194 signed32 ru_nvcsw
; /* voluntary context switches */
195 signed32 ru_nivcsw
; /* involuntary " */
200 do_unix_exit(os_emul_data
*emul
,
206 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
207 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
208 printf_filtered ("%d)\n", status
);
210 cpu_halt(processor
, cia
, was_exited
, status
);
215 do_unix_read(os_emul_data
*emul
,
221 void *scratch_buffer
;
222 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
223 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
224 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
227 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
228 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
230 /* get a tempoary bufer */
231 scratch_buffer
= zalloc(nbytes
);
233 /* check if buffer exists by reading it */
234 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
237 status
= read (d
, scratch_buffer
, nbytes
);
239 emul_write_status(processor
, status
, errno
);
241 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
243 zfree(scratch_buffer
);
248 do_unix_write(os_emul_data
*emul
,
254 void *scratch_buffer
= NULL
;
255 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
256 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
257 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
260 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
261 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
263 /* get a tempoary bufer */
264 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
267 emul_read_buffer(scratch_buffer
, buf
, nbytes
,
271 status
= write(d
, scratch_buffer
, nbytes
);
272 emul_write_status(processor
, status
, errno
);
273 zfree(scratch_buffer
);
280 do_unix_open(os_emul_data
*emul
,
286 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
287 char path_buf
[PATH_MAX
];
288 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
289 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
290 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
293 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
294 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
296 status
= open(path
, flags
, mode
);
297 emul_write_status(processor
, status
, errno
);
302 do_unix_close(os_emul_data
*emul
,
308 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
311 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
312 printf_filtered ("%d", d
);
315 emul_write_status(processor
, status
, errno
);
320 do_unix_break(os_emul_data
*emul
,
326 /* just pass this onto the `vm' device */
327 unsigned_word new_break
= cpu_registers(processor
)->gpr
[arg0
];
330 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
331 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
333 status
= device_ioctl(emul
->vm
,
337 new_break
); /*ioctl-data*/
339 emul_write_status(processor
, 0, status
);
343 #define do_unix_access 0
346 do_unix_access(os_emul_data
*emul
,
352 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
353 char path_buf
[PATH_MAX
];
354 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
355 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
358 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
359 printf_filtered ("0x%lx [%s], 0x%x [0%o]", (long)path_addr
, path
, mode
, mode
);
361 status
= access(path
, mode
);
362 emul_write_status(processor
, status
, errno
);
367 #define do_unix_getpid 0
370 do_unix_getpid(os_emul_data
*emul
,
376 pid_t status
= getpid();
377 emul_write_status(processor
, (int)status
, errno
);
382 #define do_unix_getppid 0
385 do_unix_getppid(os_emul_data
*emul
,
391 pid_t status
= getppid();
392 emul_write_status(processor
, (int)status
, errno
);
396 #if !defined(HAVE_GETPID) || !defined(HAVE_GETPPID)
397 #define do_unix_getpid2 0
400 do_unix_getpid2(os_emul_data
*emul
,
406 int pid
= (int)getpid();
407 int ppid
= (int)getppid();
408 emul_write2_status(processor
, pid
, ppid
, errno
);
412 #if !defined(HAVE_GETUID) || !defined(HAVE_GETEUID)
413 #define do_unix_getuid2 0
416 do_unix_getuid2(os_emul_data
*emul
,
422 uid_t uid
= getuid();
423 uid_t euid
= geteuid();
424 emul_write2_status(processor
, (int)uid
, (int)euid
, errno
);
429 #define do_unix_getuid 0
432 do_unix_getuid(os_emul_data
*emul
,
438 uid_t status
= getuid();
439 emul_write_status(processor
, (int)status
, errno
);
444 #define do_unix_geteuid 0
447 do_unix_geteuid(os_emul_data
*emul
,
453 uid_t status
= geteuid();
454 emul_write_status(processor
, (int)status
, errno
);
460 #define do_unix_kill 0
463 do_unix_kill(os_emul_data
*emul
,
469 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
470 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
472 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
473 printf_filtered ("%d, %d", (int)pid
, sig
);
475 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
478 cpu_halt(processor
, cia
, was_signalled
, sig
);
484 #define do_unix_dup 0
487 do_unix_dup(os_emul_data
*emul
,
493 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
494 int status
= dup(oldd
);
497 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
498 printf_filtered ("%d", oldd
);
500 emul_write_status(processor
, status
, err
);
505 #define do_unix_dup2 0
508 do_unix_dup2(os_emul_data
*emul
,
514 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
515 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
516 int status
= dup2(oldd
, newd
);
519 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
520 printf_filtered ("%d, %d", oldd
, newd
);
522 emul_write_status(processor
, status
, err
);
527 #define do_unix_lseek 0
530 do_unix_lseek(os_emul_data
*emul
,
536 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
537 off_t offset
= (off_t
)cpu_registers(processor
)->gpr
[arg0
+1];
538 int whence
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
541 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
542 printf_filtered ("%d %ld %d", fildes
, (long)offset
, whence
);
544 status
= lseek(fildes
, offset
, whence
);
545 emul_write_status(processor
, (int)status
, errno
);
550 #if !defined(HAVE_GETGID) || !defined(HAVE_GETEGID)
551 #define do_unix_getgid2 0
554 do_unix_getgid2(os_emul_data
*emul
,
560 gid_t gid
= getgid();
561 gid_t egid
= getegid();
562 emul_write2_status(processor
, (int)gid
, (int)egid
, errno
);
567 #define do_unix_getgid 0
570 do_unix_getgid(os_emul_data
*emul
,
576 gid_t status
= getgid();
577 emul_write_status(processor
, (int)status
, errno
);
582 #define do_unix_getegid 0
585 do_unix_getegid(os_emul_data
*emul
,
591 gid_t status
= getegid();
592 emul_write_status(processor
, (int)status
, errno
);
597 #define do_unix_umask 0
600 do_unix_umask(os_emul_data
*emul
,
606 mode_t mask
= (mode_t
)cpu_registers(processor
)->gpr
[arg0
];
607 int status
= umask(mask
);
609 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
610 printf_filtered ("0%o", (unsigned int)mask
);
612 emul_write_status(processor
, status
, errno
);
617 #define do_unix_chdir 0
620 do_unix_chdir(os_emul_data
*emul
,
626 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
627 char path_buf
[PATH_MAX
];
628 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
631 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
632 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
634 status
= chdir(path
);
635 emul_write_status(processor
, status
, errno
);
640 #define do_unix_link 0
643 do_unix_link(os_emul_data
*emul
,
649 unsigned_word path1_addr
= cpu_registers(processor
)->gpr
[arg0
];
650 char path1_buf
[PATH_MAX
];
651 char *path1
= emul_read_string(path1_buf
, path1_addr
, PATH_MAX
, processor
, cia
);
652 unsigned_word path2_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
653 char path2_buf
[PATH_MAX
];
654 char *path2
= emul_read_string(path2_buf
, path2_addr
, PATH_MAX
, processor
, cia
);
657 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
658 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr
, path1
, (long)path2_addr
, path2
);
660 status
= link(path1
, path2
);
661 emul_write_status(processor
, status
, errno
);
666 #define do_unix_symlink 0
669 do_unix_symlink(os_emul_data
*emul
,
675 unsigned_word path1_addr
= cpu_registers(processor
)->gpr
[arg0
];
676 char path1_buf
[PATH_MAX
];
677 char *path1
= emul_read_string(path1_buf
, path1_addr
, PATH_MAX
, processor
, cia
);
678 unsigned_word path2_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
679 char path2_buf
[PATH_MAX
];
680 char *path2
= emul_read_string(path2_buf
, path2_addr
, PATH_MAX
, processor
, cia
);
683 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
684 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr
, path1
, (long)path2_addr
, path2
);
686 status
= symlink(path1
, path2
);
687 emul_write_status(processor
, status
, errno
);
692 #define do_unix_unlink 0
695 do_unix_unlink(os_emul_data
*emul
,
701 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
702 char path_buf
[PATH_MAX
];
703 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
706 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
707 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
709 status
= unlink(path
);
710 emul_write_status(processor
, status
, errno
);
715 #define do_unix_mkdir 0
718 do_unix_mkdir(os_emul_data
*emul
,
724 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
725 char path_buf
[PATH_MAX
];
726 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
727 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
730 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
731 printf_filtered ("0x%lx [%s], 0%3o", (long)path_addr
, path
, mode
);
734 status
= mkdir(path
);
736 status
= mkdir(path
, mode
);
738 emul_write_status(processor
, status
, errno
);
743 #define do_unix_rmdir 0
746 do_unix_rmdir(os_emul_data
*emul
,
752 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
753 char path_buf
[PATH_MAX
];
754 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
757 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
758 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
760 status
= rmdir(path
);
761 emul_write_status(processor
, status
, errno
);
766 #define do_unix_time 0
769 do_unix_time(os_emul_data
*emul
,
775 unsigned_word tp
= cpu_registers(processor
)->gpr
[arg0
];
776 time_t now
= time ((time_t *)0);
777 unsigned_word status
= H2T_4(now
);
779 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
780 printf_filtered ("0x%lx", (long)tp
);
782 emul_write_status(processor
, (int)status
, errno
);
785 emul_write_buffer(&status
, tp
, sizeof(status
), processor
, cia
);
789 #if !defined(HAVE_GETTIMEOFDAY) || !defined(HAVE_SYS_TIME_H)
790 #define do_unix_gettimeofday 0
793 do_unix_gettimeofday(os_emul_data
*emul
,
799 unsigned_word tv
= cpu_registers(processor
)->gpr
[arg0
];
800 unsigned_word tz
= cpu_registers(processor
)->gpr
[arg0
+1];
801 struct unix_timeval target_timeval
;
802 struct timeval host_timeval
;
803 struct unix_timezone target_timezone
;
804 struct timezone host_timezone
;
807 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
808 printf_filtered ("0x%lx, 0x%lx", (long)tv
, (long)tz
);
810 /* Just in case the system doesn't set the timezone structure */
811 host_timezone
.tz_minuteswest
= 0;
812 host_timezone
.tz_dsttime
= 0;
814 status
= gettimeofday(&host_timeval
, &host_timezone
);
817 target_timeval
.tv_sec
= H2T_4(host_timeval
.tv_sec
);
818 target_timeval
.tv_usec
= H2T_4(host_timeval
.tv_usec
);
819 emul_write_buffer((void *) &target_timeval
, tv
, sizeof(target_timeval
), processor
, cia
);
823 target_timezone
.tz_minuteswest
= H2T_4(host_timezone
.tz_minuteswest
);
824 target_timezone
.tz_dsttime
= H2T_4(host_timezone
.tz_dsttime
);
825 emul_write_buffer((void *) &target_timezone
, tv
, sizeof(target_timezone
), processor
, cia
);
829 emul_write_status(processor
, (int)status
, errno
);
834 #ifndef HAVE_GETRUSAGE
835 #define do_unix_getrusage 0
838 do_unix_getrusage(os_emul_data
*emul
,
844 signed_word who
= (signed_word
)cpu_registers(processor
)->gpr
[arg0
];
845 unsigned_word usage
= cpu_registers(processor
)->gpr
[arg0
+1];
846 struct rusage host_rusage
, host_rusage2
;
847 struct unix_rusage target_rusage
;
850 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
851 printf_filtered ("%ld, 0x%lx", (long)who
, (long)usage
);
859 case UNIX_RUSAGE_SELF
:
860 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
863 case UNIX_RUSAGE_CHILDREN
:
864 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage
);
867 case UNIX_RUSAGE_BOTH
:
868 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
870 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage2
);
872 host_rusage
.ru_utime
.tv_sec
+= host_rusage2
.ru_utime
.tv_sec
;
873 host_rusage
.ru_utime
.tv_usec
+= host_rusage2
.ru_utime
.tv_usec
;
874 host_rusage
.ru_stime
.tv_sec
+= host_rusage2
.ru_stime
.tv_sec
;
875 host_rusage
.ru_stime
.tv_usec
+= host_rusage2
.ru_stime
.tv_usec
;
876 host_rusage
.ru_maxrss
+= host_rusage2
.ru_maxrss
;
877 host_rusage
.ru_ixrss
+= host_rusage2
.ru_ixrss
;
878 host_rusage
.ru_idrss
+= host_rusage2
.ru_idrss
;
879 host_rusage
.ru_isrss
+= host_rusage2
.ru_isrss
;
880 host_rusage
.ru_minflt
+= host_rusage2
.ru_minflt
;
881 host_rusage
.ru_majflt
+= host_rusage2
.ru_majflt
;
882 host_rusage
.ru_nswap
+= host_rusage2
.ru_nswap
;
883 host_rusage
.ru_inblock
+= host_rusage2
.ru_inblock
;
884 host_rusage
.ru_oublock
+= host_rusage2
.ru_oublock
;
885 host_rusage
.ru_msgsnd
+= host_rusage2
.ru_msgsnd
;
886 host_rusage
.ru_msgrcv
+= host_rusage2
.ru_msgrcv
;
887 host_rusage
.ru_nsignals
+= host_rusage2
.ru_nsignals
;
888 host_rusage
.ru_nvcsw
+= host_rusage2
.ru_nvcsw
;
889 host_rusage
.ru_nivcsw
+= host_rusage2
.ru_nivcsw
;
895 target_rusage
.ru_utime
.tv_sec
= H2T_4(host_rusage2
.ru_utime
.tv_sec
);
896 target_rusage
.ru_utime
.tv_usec
= H2T_4(host_rusage2
.ru_utime
.tv_usec
);
897 target_rusage
.ru_stime
.tv_sec
= H2T_4(host_rusage2
.ru_stime
.tv_sec
);
898 target_rusage
.ru_stime
.tv_usec
= H2T_4(host_rusage2
.ru_stime
.tv_usec
);
899 target_rusage
.ru_maxrss
= H2T_4(host_rusage2
.ru_maxrss
);
900 target_rusage
.ru_ixrss
= H2T_4(host_rusage2
.ru_ixrss
);
901 target_rusage
.ru_idrss
= H2T_4(host_rusage2
.ru_idrss
);
902 target_rusage
.ru_isrss
= H2T_4(host_rusage2
.ru_isrss
);
903 target_rusage
.ru_minflt
= H2T_4(host_rusage2
.ru_minflt
);
904 target_rusage
.ru_majflt
= H2T_4(host_rusage2
.ru_majflt
);
905 target_rusage
.ru_nswap
= H2T_4(host_rusage2
.ru_nswap
);
906 target_rusage
.ru_inblock
= H2T_4(host_rusage2
.ru_inblock
);
907 target_rusage
.ru_oublock
= H2T_4(host_rusage2
.ru_oublock
);
908 target_rusage
.ru_msgsnd
= H2T_4(host_rusage2
.ru_msgsnd
);
909 target_rusage
.ru_msgrcv
= H2T_4(host_rusage2
.ru_msgrcv
);
910 target_rusage
.ru_nsignals
= H2T_4(host_rusage2
.ru_nsignals
);
911 target_rusage
.ru_nvcsw
= H2T_4(host_rusage2
.ru_nvcsw
);
912 target_rusage
.ru_nivcsw
= H2T_4(host_rusage2
.ru_nivcsw
);
913 emul_write_buffer((void *) &target_rusage
, usage
, sizeof(target_rusage
), processor
, cia
);
916 emul_write_status(processor
, status
, errno
);
922 do_unix_nop(os_emul_data
*emul
,
928 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
929 printf_filtered ("0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
930 (long)cpu_registers(processor
)->gpr
[arg0
],
931 (long)cpu_registers(processor
)->gpr
[arg0
+1],
932 (long)cpu_registers(processor
)->gpr
[arg0
+2],
933 (long)cpu_registers(processor
)->gpr
[arg0
+3],
934 (long)cpu_registers(processor
)->gpr
[arg0
+4],
935 (long)cpu_registers(processor
)->gpr
[arg0
+5]);
937 emul_write_status(processor
, 0, errno
);
941 /* Common code for initializing the system call stuff */
943 static os_emul_data
*
944 emul_unix_create(device
*root
,
947 emul_syscall
*syscall
)
949 unsigned_word top_of_stack
;
956 /* merge any emulation specific entries into the device tree */
958 /* establish a few defaults */
959 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
961 top_of_stack
= 0xe0000000;
962 stack_size
= 0x00100000;
966 top_of_stack
= 0x20000000;
967 stack_size
= 0x00100000;
971 emul_add_tree_options(root
, image
, name
,
972 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
973 ? "user" : "virtual"),
974 0 /*oea-interrupt-prefix*/);
976 /* virtual memory - handles growth of stack/heap */
977 vm
= tree_parse(root
, "/openprom/vm@0x%lx",
978 (unsigned long)(top_of_stack
- stack_size
));
979 tree_parse(vm
, "./stack-base 0x%lx",
980 (unsigned long)(top_of_stack
- stack_size
));
981 tree_parse(vm
, "./nr-bytes 0x%x", stack_size
);
983 filename
= tree_quote_property (bfd_get_filename(image
));
984 tree_parse(root
, "/openprom/vm/map-binary/file-name %s",
988 /* finish the init */
989 tree_parse(root
, "/openprom/init/register/pc 0x%lx",
990 (unsigned long)bfd_get_start_address(image
));
991 tree_parse(root
, "/openprom/init/register/sp 0x%lx",
992 (unsigned long)top_of_stack
);
993 tree_parse(root
, "/openprom/init/register/msr 0x%x",
994 ((tree_find_boolean_property(root
, "/options/little-endian?")
995 ? msr_little_endian_mode
997 | (tree_find_boolean_property(root
, "/openprom/options/floating-point?")
998 ? (msr_floating_point_available
999 | msr_floating_point_exception_mode_0
1000 | msr_floating_point_exception_mode_1
)
1002 tree_parse(root
, "/openprom/init/stack/stack-type %s",
1003 (elf_binary
? "ppc-elf" : "ppc-xcoff"));
1005 /* finally our emulation data */
1006 data
= ZALLOC(os_emul_data
);
1008 data
->syscalls
= syscall
;
1015 Solaris - Emulation of user programs for Solaris/PPC
1022 /* Solaris specific implementation */
1024 typedef signed32 solaris_uid_t
;
1025 typedef signed32 solaris_gid_t
;
1026 typedef signed32 solaris_off_t
;
1027 typedef signed32 solaris_pid_t
;
1028 typedef signed32 solaris_time_t
;
1029 typedef unsigned32 solaris_dev_t
;
1030 typedef unsigned32 solaris_ino_t
;
1031 typedef unsigned32 solaris_mode_t
;
1032 typedef unsigned32 solaris_nlink_t
;
1034 #ifdef HAVE_SYS_STAT_H
1035 #define SOLARIS_ST_FSTYPSZ 16 /* array size for file system type name */
1037 struct solaris_stat
{
1038 solaris_dev_t st_dev
;
1039 signed32 st_pad1
[3]; /* reserved for network id */
1040 solaris_ino_t st_ino
;
1041 solaris_mode_t st_mode
;
1042 solaris_nlink_t st_nlink
;
1043 solaris_uid_t st_uid
;
1044 solaris_gid_t st_gid
;
1045 solaris_dev_t st_rdev
;
1046 signed32 st_pad2
[2];
1047 solaris_off_t st_size
;
1048 signed32 st_pad3
; /* future off_t expansion */
1049 struct unix_timeval st_atim
;
1050 struct unix_timeval st_mtim
;
1051 struct unix_timeval st_ctim
;
1052 signed32 st_blksize
;
1054 char st_fstype
[SOLARIS_ST_FSTYPSZ
];
1055 signed32 st_pad4
[8]; /* expansion area */
1058 /* Convert from host stat structure to solaris stat structure */
1059 STATIC_INLINE_EMUL_UNIX
void
1060 convert_to_solaris_stat(unsigned_word addr
,
1065 struct solaris_stat target
;
1068 target
.st_dev
= H2T_4(host
->st_dev
);
1069 target
.st_ino
= H2T_4(host
->st_ino
);
1070 target
.st_mode
= H2T_4(host
->st_mode
);
1071 target
.st_nlink
= H2T_4(host
->st_nlink
);
1072 target
.st_uid
= H2T_4(host
->st_uid
);
1073 target
.st_gid
= H2T_4(host
->st_gid
);
1074 target
.st_size
= H2T_4(host
->st_size
);
1077 target
.st_rdev
= H2T_4(host
->st_rdev
);
1082 #ifdef HAVE_ST_BLKSIZE
1083 target
.st_blksize
= H2T_4(host
->st_blksize
);
1085 target
.st_blksize
= 0;
1088 #ifdef HAVE_ST_BLOCKS
1089 target
.st_blocks
= H2T_4(host
->st_blocks
);
1091 target
.st_blocks
= 0;
1094 target
.st_atim
.tv_sec
= H2T_4(host
->st_atime
);
1095 target
.st_atim
.tv_usec
= 0;
1097 target
.st_ctim
.tv_sec
= H2T_4(host
->st_ctime
);
1098 target
.st_ctim
.tv_usec
= 0;
1100 target
.st_mtim
.tv_sec
= H2T_4(host
->st_mtime
);
1101 target
.st_mtim
.tv_usec
= 0;
1103 for (i
= 0; i
< sizeof (target
.st_pad1
) / sizeof (target
.st_pad1
[0]); i
++)
1104 target
.st_pad1
[i
] = 0;
1106 for (i
= 0; i
< sizeof (target
.st_pad2
) / sizeof (target
.st_pad2
[0]); i
++)
1107 target
.st_pad2
[i
] = 0;
1111 for (i
= 0; i
< sizeof (target
.st_pad4
) / sizeof (target
.st_pad4
[0]); i
++)
1112 target
.st_pad4
[i
] = 0;
1114 /* For now, just punt and always say it is a ufs file */
1115 strcpy (target
.st_fstype
, "ufs");
1117 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1119 #endif /* HAVE_SYS_STAT_H */
1122 #define do_solaris_stat 0
1125 do_solaris_stat(os_emul_data
*emul
,
1131 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1132 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1133 char path_buf
[PATH_MAX
];
1135 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1138 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1139 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1141 status
= stat (path
, &buf
);
1143 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1145 emul_write_status(processor
, status
, errno
);
1150 #define do_solaris_lstat 0
1153 do_solaris_lstat(os_emul_data
*emul
,
1159 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1160 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1161 char path_buf
[PATH_MAX
];
1163 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1166 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1167 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1169 status
= lstat (path
, &buf
);
1171 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1173 emul_write_status(processor
, status
, errno
);
1178 #define do_solaris_fstat 0
1181 do_solaris_fstat(os_emul_data
*emul
,
1187 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
1188 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1192 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1193 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
1195 status
= fstat (fildes
, &buf
);
1197 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1199 emul_write_status(processor
, status
, errno
);
1203 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1204 #define SOLARIS_TIOC ('T'<<8)
1205 #define SOLARIS_NCC 8
1206 #define SOLARIS_NCCS 19
1208 #define SOLARIS_VINTR 0
1209 #define SOLARIS_VQUIT 1
1210 #define SOLARIS_VERASE 2
1211 #define SOLARIS_VKILL 3
1212 #define SOLARIS_VEOF 4
1213 #define SOLARIS_VEOL 5
1214 #define SOLARIS_VEOL2 6
1215 #define SOLARIS_VSWTCH 7
1216 #define SOLARIS_VSTART 8
1217 #define SOLARIS_VSTOP 9
1218 #define SOLARIS_VSUSP 10
1219 #define SOLARIS_VDSUSP 11
1220 #define SOLARIS_VREPRINT 12
1221 #define SOLARIS_VDISCARD 13
1222 #define SOLARIS_VWERASE 14
1223 #define SOLARIS_VLNEXT 15
1226 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1227 /* Convert to/from host termio structure */
1229 struct solaris_termio
{
1230 unsigned16 c_iflag
; /* input modes */
1231 unsigned16 c_oflag
; /* output modes */
1232 unsigned16 c_cflag
; /* control modes */
1233 unsigned16 c_lflag
; /* line discipline modes */
1234 unsigned8 c_line
; /* line discipline */
1235 unsigned8 c_cc
[SOLARIS_NCC
]; /* control chars */
1238 STATIC_INLINE_EMUL_UNIX
void
1239 convert_to_solaris_termio(unsigned_word addr
,
1240 struct termio
*host
,
1244 struct solaris_termio target
;
1247 target
.c_iflag
= H2T_2 (host
->c_iflag
);
1248 target
.c_oflag
= H2T_2 (host
->c_oflag
);
1249 target
.c_cflag
= H2T_2 (host
->c_cflag
);
1250 target
.c_lflag
= H2T_2 (host
->c_lflag
);
1252 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
1253 target
.c_line
= host
->c_line
;
1258 for (i
= 0; i
< SOLARIS_NCC
; i
++)
1262 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1266 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1270 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1274 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1278 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1282 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1286 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1290 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1294 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1298 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1300 #endif /* HAVE_TERMIO_STRUCTURE || HAVE_TERMIOS_STRUCTURE */
1302 #ifdef HAVE_TERMIOS_STRUCTURE
1303 /* Convert to/from host termios structure */
1305 typedef unsigned32 solaris_tcflag_t
;
1306 typedef unsigned8 solaris_cc_t
;
1307 typedef unsigned32 solaris_speed_t
;
1309 struct solaris_termios
{
1310 solaris_tcflag_t c_iflag
;
1311 solaris_tcflag_t c_oflag
;
1312 solaris_tcflag_t c_cflag
;
1313 solaris_tcflag_t c_lflag
;
1314 solaris_cc_t c_cc
[SOLARIS_NCCS
];
1317 STATIC_INLINE_EMUL_UNIX
void
1318 convert_to_solaris_termios(unsigned_word addr
,
1319 struct termios
*host
,
1323 struct solaris_termios target
;
1326 target
.c_iflag
= H2T_4 (host
->c_iflag
);
1327 target
.c_oflag
= H2T_4 (host
->c_oflag
);
1328 target
.c_cflag
= H2T_4 (host
->c_cflag
);
1329 target
.c_lflag
= H2T_4 (host
->c_lflag
);
1331 for (i
= 0; i
< SOLARIS_NCCS
; i
++)
1335 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1339 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1343 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1347 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1351 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1355 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1359 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1363 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1367 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1372 target
.c_cc
[SOLARIS_VSTART
] = host
->c_cc
[VSTART
];
1376 target
.c_cc
[SOLARIS_VSTOP
] = host
->c_cc
[VSTOP
];
1380 target
.c_cc
[SOLARIS_VSUSP
] = host
->c_cc
[VSUSP
];
1384 target
.c_cc
[SOLARIS_VDSUSP
] = host
->c_cc
[VDSUSP
];
1388 target
.c_cc
[SOLARIS_VREPRINT
] = host
->c_cc
[VREPRINT
];
1392 target
.c_cc
[SOLARIS_VDISCARD
] = host
->c_cc
[VDISCARD
];
1396 target
.c_cc
[SOLARIS_VWERASE
] = host
->c_cc
[VWERASE
];
1400 target
.c_cc
[SOLARIS_VLNEXT
] = host
->c_cc
[VLNEXT
];
1403 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1405 #endif /* HAVE_TERMIOS_STRUCTURE */
1408 #define do_solaris_ioctl 0
1411 do_solaris_ioctl(os_emul_data
*emul
,
1417 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
1418 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
1419 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
1421 const char *name
= "<unknown>";
1423 #ifdef HAVE_TERMIOS_STRUCTURE
1424 struct termios host_termio
;
1427 #ifdef HAVE_TERMIO_STRUCTURE
1428 struct termio host_termio
;
1434 case 0: /* make sure we have at least one case */
1440 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1441 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
1442 case SOLARIS_TIOC
| 1: /* TCGETA */
1444 #ifdef HAVE_TCGETATTR
1445 status
= tcgetattr(fildes
, &host_termio
);
1446 #elif defined(TCGETS)
1447 status
= ioctl (fildes
, TCGETS
, &host_termio
);
1449 status
= ioctl (fildes
, TCGETA
, &host_termio
);
1452 convert_to_solaris_termio (argp_addr
, &host_termio
, processor
, cia
);
1455 #endif /* HAVE_TERMIO_STRUCTURE */
1457 #ifdef HAVE_TERMIOS_STRUCTURE
1458 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
1459 case SOLARIS_TIOC
| 13: /* TCGETS */
1461 #ifdef HAVE_TCGETATTR
1462 status
= tcgetattr(fildes
, &host_termio
);
1464 status
= ioctl (fildes
, TCGETS
, &host_termio
);
1467 convert_to_solaris_termios (argp_addr
, &host_termio
, processor
, cia
);
1470 #endif /* HAVE_TERMIOS_STRUCTURE */
1473 emul_write_status(processor
, status
, errno
);
1475 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1476 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
1478 #endif /* HAVE_IOCTL */
1480 static emul_syscall_descriptor solaris_descriptors
[] = {
1481 /* 0 */ { 0, "syscall" },
1482 /* 1 */ { do_unix_exit
, "exit" },
1483 /* 2 */ { 0, "fork" },
1484 /* 3 */ { do_unix_read
, "read" },
1485 /* 4 */ { do_unix_write
, "write" },
1486 /* 5 */ { do_unix_open
, "open" },
1487 /* 6 */ { do_unix_close
, "close" },
1488 /* 7 */ { 0, "wait" },
1489 /* 8 */ { 0, "creat" },
1490 /* 9 */ { do_unix_link
, "link" },
1491 /* 10 */ { do_unix_unlink
, "unlink" },
1492 /* 11 */ { 0, "exec" },
1493 /* 12 */ { do_unix_chdir
, "chdir" },
1494 /* 13 */ { do_unix_time
, "time" },
1495 /* 14 */ { 0, "mknod" },
1496 /* 15 */ { 0, "chmod" },
1497 /* 16 */ { 0, "chown" },
1498 /* 17 */ { do_unix_break
, "brk" },
1499 /* 18 */ { do_solaris_stat
, "stat" },
1500 /* 19 */ { do_unix_lseek
, "lseek" },
1501 /* 20 */ { do_unix_getpid2
, "getpid" },
1502 /* 21 */ { 0, "mount" },
1503 /* 22 */ { 0, "umount" },
1504 /* 23 */ { 0, "setuid" },
1505 /* 24 */ { do_unix_getuid2
, "getuid" },
1506 /* 25 */ { 0, "stime" },
1507 /* 26 */ { 0, "ptrace" },
1508 /* 27 */ { 0, "alarm" },
1509 /* 28 */ { do_solaris_fstat
, "fstat" },
1510 /* 29 */ { 0, "pause" },
1511 /* 30 */ { 0, "utime" },
1512 /* 31 */ { 0, "stty" },
1513 /* 32 */ { 0, "gtty" },
1514 /* 33 */ { do_unix_access
, "access" },
1515 /* 34 */ { 0, "nice" },
1516 /* 35 */ { 0, "statfs" },
1517 /* 36 */ { 0, "sync" },
1518 /* 37 */ { 0, "kill" },
1519 /* 38 */ { 0, "fstatfs" },
1520 /* 39 */ { 0, "pgrpsys" },
1521 /* 40 */ { 0, "xenix" },
1522 /* 41 */ { do_unix_dup
, "dup" },
1523 /* 42 */ { 0, "pipe" },
1524 /* 43 */ { 0, "times" },
1525 /* 44 */ { 0, "profil" },
1526 /* 45 */ { 0, "plock" },
1527 /* 46 */ { 0, "setgid" },
1528 /* 47 */ { do_unix_getgid2
, "getgid" },
1529 /* 48 */ { 0, "signal" },
1530 /* 49 */ { 0, "msgsys" },
1531 /* 50 */ { 0, "syssun" },
1532 /* 51 */ { 0, "acct" },
1533 /* 52 */ { 0, "shmsys" },
1534 /* 53 */ { 0, "semsys" },
1535 /* 54 */ { do_solaris_ioctl
, "ioctl" },
1536 /* 55 */ { 0, "uadmin" },
1537 /* 56 */ { 0, 0 /* reserved for exch */ },
1538 /* 57 */ { 0, "utssys" },
1539 /* 58 */ { 0, "fdsync" },
1540 /* 59 */ { 0, "execve" },
1541 /* 60 */ { do_unix_umask
, "umask" },
1542 /* 61 */ { 0, "chroot" },
1543 /* 62 */ { 0, "fcntl" },
1544 /* 63 */ { 0, "ulimit" },
1545 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1546 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1547 /* 65 */ { 0, 0 /* reserved for UNIX PC */ },
1548 /* 66 */ { 0, 0 /* reserved for UNIX PC */ },
1549 /* 67 */ { 0, 0 /* reserved for UNIX PC */ },
1550 /* 68 */ { 0, 0 /* reserved for UNIX PC */ },
1551 /* 69 */ { 0, 0 /* reserved for UNIX PC */ },
1552 /* 70 */ { 0, 0 /* was advfs */ },
1553 /* 71 */ { 0, 0 /* was unadvfs */ },
1554 /* 72 */ { 0, 0 /* was rmount */ },
1555 /* 73 */ { 0, 0 /* was rumount */ },
1556 /* 74 */ { 0, 0 /* was rfstart */ },
1557 /* 75 */ { 0, 0 /* was sigret */ },
1558 /* 76 */ { 0, 0 /* was rdebug */ },
1559 /* 77 */ { 0, 0 /* was rfstop */ },
1560 /* 78 */ { 0, 0 /* was rfsys */ },
1561 /* 79 */ { do_unix_rmdir
, "rmdir" },
1562 /* 80 */ { do_unix_mkdir
, "mkdir" },
1563 /* 81 */ { 0, "getdents" },
1564 /* 82 */ { 0, 0 /* was libattach */ },
1565 /* 83 */ { 0, 0 /* was libdetach */ },
1566 /* 84 */ { 0, "sysfs" },
1567 /* 85 */ { 0, "getmsg" },
1568 /* 86 */ { 0, "putmsg" },
1569 /* 87 */ { 0, "poll" },
1570 /* 88 */ { do_solaris_lstat
, "lstat" },
1571 /* 89 */ { do_unix_symlink
, "symlink" },
1572 /* 90 */ { 0, "readlink" },
1573 /* 91 */ { 0, "setgroups" },
1574 /* 92 */ { 0, "getgroups" },
1575 /* 93 */ { 0, "fchmod" },
1576 /* 94 */ { 0, "fchown" },
1577 /* 95 */ { 0, "sigprocmask" },
1578 /* 96 */ { 0, "sigsuspend" },
1579 /* 97 */ { do_unix_nop
, "sigaltstack" },
1580 /* 98 */ { do_unix_nop
, "sigaction" },
1581 /* 99 */ { 0, "sigpending" },
1582 /* 100 */ { 0, "context" },
1583 /* 101 */ { 0, "evsys" },
1584 /* 102 */ { 0, "evtrapret" },
1585 /* 103 */ { 0, "statvfs" },
1586 /* 104 */ { 0, "fstatvfs" },
1587 /* 105 */ { 0, 0 /* reserved */ },
1588 /* 106 */ { 0, "nfssys" },
1589 /* 107 */ { 0, "waitsys" },
1590 /* 108 */ { 0, "sigsendsys" },
1591 /* 109 */ { 0, "hrtsys" },
1592 /* 110 */ { 0, "acancel" },
1593 /* 111 */ { 0, "async" },
1594 /* 112 */ { 0, "priocntlsys" },
1595 /* 113 */ { 0, "pathconf" },
1596 /* 114 */ { 0, "mincore" },
1597 /* 115 */ { 0, "mmap" },
1598 /* 116 */ { 0, "mprotect" },
1599 /* 117 */ { 0, "munmap" },
1600 /* 118 */ { 0, "fpathconf" },
1601 /* 119 */ { 0, "vfork" },
1602 /* 120 */ { 0, "fchdir" },
1603 /* 121 */ { 0, "readv" },
1604 /* 122 */ { 0, "writev" },
1605 /* 123 */ { 0, "xstat" },
1606 /* 124 */ { 0, "lxstat" },
1607 /* 125 */ { 0, "fxstat" },
1608 /* 126 */ { 0, "xmknod" },
1609 /* 127 */ { 0, "clocal" },
1610 /* 128 */ { 0, "setrlimit" },
1611 /* 129 */ { 0, "getrlimit" },
1612 /* 130 */ { 0, "lchown" },
1613 /* 131 */ { 0, "memcntl" },
1614 /* 132 */ { 0, "getpmsg" },
1615 /* 133 */ { 0, "putpmsg" },
1616 /* 134 */ { 0, "rename" },
1617 /* 135 */ { 0, "uname" },
1618 /* 136 */ { 0, "setegid" },
1619 /* 137 */ { 0, "sysconfig" },
1620 /* 138 */ { 0, "adjtime" },
1621 /* 139 */ { 0, "systeminfo" },
1622 /* 140 */ { 0, 0 /* reserved */ },
1623 /* 141 */ { 0, "seteuid" },
1624 /* 142 */ { 0, "vtrace" },
1625 /* 143 */ { 0, "fork1" },
1626 /* 144 */ { 0, "sigtimedwait" },
1627 /* 145 */ { 0, "lwp_info" },
1628 /* 146 */ { 0, "yield" },
1629 /* 147 */ { 0, "lwp_sema_wait" },
1630 /* 148 */ { 0, "lwp_sema_post" },
1631 /* 149 */ { 0, 0 /* reserved */ },
1632 /* 150 */ { 0, 0 /* reserved */ },
1633 /* 151 */ { 0, 0 /* reserved */ },
1634 /* 152 */ { 0, "modctl" },
1635 /* 153 */ { 0, "fchroot" },
1636 /* 154 */ { 0, "utimes" },
1637 /* 155 */ { 0, "vhangup" },
1638 /* 156 */ { do_unix_gettimeofday
, "gettimeofday" },
1639 /* 157 */ { 0, "getitimer" },
1640 /* 158 */ { 0, "setitimer" },
1641 /* 159 */ { 0, "lwp_create" },
1642 /* 160 */ { 0, "lwp_exit" },
1643 /* 161 */ { 0, "lwp_suspend" },
1644 /* 162 */ { 0, "lwp_continue" },
1645 /* 163 */ { 0, "lwp_kill" },
1646 /* 164 */ { 0, "lwp_self" },
1647 /* 165 */ { 0, "lwp_setprivate" },
1648 /* 166 */ { 0, "lwp_getprivate" },
1649 /* 167 */ { 0, "lwp_wait" },
1650 /* 168 */ { 0, "lwp_mutex_unlock" },
1651 /* 169 */ { 0, "lwp_mutex_lock" },
1652 /* 170 */ { 0, "lwp_cond_wait" },
1653 /* 171 */ { 0, "lwp_cond_signal" },
1654 /* 172 */ { 0, "lwp_cond_broadcast" },
1655 /* 173 */ { 0, "pread" },
1656 /* 174 */ { 0, "pwrite" },
1657 /* 175 */ { 0, "llseek" },
1658 /* 176 */ { 0, "inst_sync" },
1659 /* 177 */ { 0, 0 /* reserved */ },
1660 /* 178 */ { 0, "kaio" },
1661 /* 179 */ { 0, 0 /* reserved */ },
1662 /* 180 */ { 0, 0 /* reserved */ },
1663 /* 181 */ { 0, 0 /* reserved */ },
1664 /* 182 */ { 0, 0 /* reserved */ },
1665 /* 183 */ { 0, 0 /* reserved */ },
1666 /* 184 */ { 0, "tsolsys" },
1667 /* 185 */ { 0, "acl" },
1668 /* 186 */ { 0, "auditsys" },
1669 /* 187 */ { 0, "processor_bind" },
1670 /* 188 */ { 0, "processor_info" },
1671 /* 189 */ { 0, "p_online" },
1672 /* 190 */ { 0, "sigqueue" },
1673 /* 191 */ { 0, "clock_gettime" },
1674 /* 192 */ { 0, "clock_settime" },
1675 /* 193 */ { 0, "clock_getres" },
1676 /* 194 */ { 0, "timer_create" },
1677 /* 195 */ { 0, "timer_delete" },
1678 /* 196 */ { 0, "timer_settime" },
1679 /* 197 */ { 0, "timer_gettime" },
1680 /* 198 */ { 0, "timer_getoverrun" },
1681 /* 199 */ { 0, "nanosleep" },
1682 /* 200 */ { 0, "facl" },
1683 /* 201 */ { 0, "door" },
1684 /* 202 */ { 0, "setreuid" },
1685 /* 203 */ { 0, "setregid" },
1686 /* 204 */ { 0, "install_utrap" },
1687 /* 205 */ { 0, 0 /* reserved */ },
1688 /* 206 */ { 0, 0 /* reserved */ },
1689 /* 207 */ { 0, 0 /* reserved */ },
1690 /* 208 */ { 0, 0 /* reserved */ },
1691 /* 209 */ { 0, 0 /* reserved */ },
1692 /* 210 */ { 0, "signotifywait" },
1693 /* 211 */ { 0, "lwp_sigredirect" },
1694 /* 212 */ { 0, "lwp_alarm" },
1697 static char *(solaris_error_names
[]) = {
1736 /* 38 */ "EL2NSYNC",
1745 /* 47 */ "ECANCELED",
1754 /* 56 */ "EDEADLOCK",
1756 /* 58 */ "Error code 58",
1757 /* 59 */ "Error code 59",
1770 /* 72 */ "Error code 72",
1771 /* 73 */ "Error code 73",
1772 /* 74 */ "EMULTIHOP",
1773 /* 75 */ "Error code 75",
1774 /* 76 */ "Error code 76",
1776 /* 78 */ "ENAMETOOLONG",
1777 /* 79 */ "EOVERFLOW",
1778 /* 80 */ "ENOTUNIQ",
1785 /* 87 */ "ELIBEXEC",
1789 /* 91 */ "ERESTART",
1790 /* 92 */ "ESTRPIPE",
1791 /* 93 */ "ENOTEMPTY",
1793 /* 95 */ "ENOTSOCK",
1794 /* 96 */ "EDESTADDRREQ",
1795 /* 97 */ "EMSGSIZE",
1796 /* 98 */ "EPROTOTYPE",
1797 /* 99 */ "ENOPROTOOPT",
1798 /* 100 */ "Error code 100",
1799 /* 101 */ "Error code 101",
1800 /* 102 */ "Error code 102",
1801 /* 103 */ "Error code 103",
1802 /* 104 */ "Error code 104",
1803 /* 105 */ "Error code 105",
1804 /* 106 */ "Error code 106",
1805 /* 107 */ "Error code 107",
1806 /* 108 */ "Error code 108",
1807 /* 109 */ "Error code 109",
1808 /* 110 */ "Error code 110",
1809 /* 111 */ "Error code 111",
1810 /* 112 */ "Error code 112",
1811 /* 113 */ "Error code 113",
1812 /* 114 */ "Error code 114",
1813 /* 115 */ "Error code 115",
1814 /* 116 */ "Error code 116",
1815 /* 117 */ "Error code 117",
1816 /* 118 */ "Error code 118",
1817 /* 119 */ "Error code 119",
1818 /* 120 */ "EPROTONOSUPPORT",
1819 /* 121 */ "ESOCKTNOSUPPORT",
1820 /* 122 */ "EOPNOTSUPP",
1821 /* 123 */ "EPFNOSUPPORT",
1822 /* 124 */ "EAFNOSUPPORT",
1823 /* 125 */ "EADDRINUSE",
1824 /* 126 */ "EADDRNOTAVAIL",
1825 /* 127 */ "ENETDOWN",
1826 /* 128 */ "ENETUNREACH",
1827 /* 129 */ "ENETRESET",
1828 /* 130 */ "ECONNABORTED",
1829 /* 131 */ "ECONNRESET",
1830 /* 132 */ "ENOBUFS",
1831 /* 133 */ "EISCONN",
1832 /* 134 */ "ENOTCONN",
1833 /* 135 */ "Error code 135", /* XENIX has 135 - 142 */
1834 /* 136 */ "Error code 136",
1835 /* 137 */ "Error code 137",
1836 /* 138 */ "Error code 138",
1837 /* 139 */ "Error code 139",
1838 /* 140 */ "Error code 140",
1839 /* 141 */ "Error code 141",
1840 /* 142 */ "Error code 142",
1841 /* 143 */ "ESHUTDOWN",
1842 /* 144 */ "ETOOMANYREFS",
1843 /* 145 */ "ETIMEDOUT",
1844 /* 146 */ "ECONNREFUSED",
1845 /* 147 */ "EHOSTDOWN",
1846 /* 148 */ "EHOSTUNREACH",
1847 /* 149 */ "EALREADY",
1848 /* 150 */ "EINPROGRESS",
1852 static char *(solaris_signal_names
[]) = {
1873 /* 20 */ "SIGWINCH",
1881 /* 28 */ "SIGVTALRM",
1885 /* 32 */ "SIGWAITING",
1887 /* 34 */ "SIGFREEZE",
1889 /* 36 */ "SIGCANCEL",
1892 static emul_syscall emul_solaris_syscalls
= {
1893 solaris_descriptors
,
1894 sizeof(solaris_descriptors
) / sizeof(solaris_descriptors
[0]),
1895 solaris_error_names
,
1896 sizeof(solaris_error_names
) / sizeof(solaris_error_names
[0]),
1897 solaris_signal_names
,
1898 sizeof(solaris_signal_names
) / sizeof(solaris_signal_names
[0]),
1902 /* Solaris's os_emul interface, most are just passed on to the generic
1905 static os_emul_data
*
1906 emul_solaris_create(device
*root
,
1910 /* check that this emulation is really for us */
1911 if (name
!= NULL
&& strcmp(name
, "solaris") != 0)
1917 return emul_unix_create(root
, image
, "solaris", &emul_solaris_syscalls
);
1921 emul_solaris_init(os_emul_data
*emul_data
,
1928 emul_solaris_system_call(cpu
*processor
,
1930 os_emul_data
*emul_data
)
1932 emul_do_system_call(emul_data
,
1933 emul_data
->syscalls
,
1934 cpu_registers(processor
)->gpr
[0],
1935 3, /*r3 contains arg0*/
1940 const os_emul emul_solaris
= {
1942 emul_solaris_create
,
1944 emul_solaris_system_call
,
1945 0, /*instruction_call*/
1952 Linux - Emulation of user programs for Linux/PPC
1959 /* Linux specific implementation */
1961 typedef unsigned32 linux_dev_t
;
1962 typedef unsigned32 linux_ino_t
;
1963 typedef unsigned32 linux_mode_t
;
1964 typedef unsigned16 linux_nlink_t
;
1965 typedef signed32 linux_off_t
;
1966 typedef signed32 linux_pid_t
;
1967 typedef unsigned32 linux_uid_t
;
1968 typedef unsigned32 linux_gid_t
;
1969 typedef unsigned32 linux_size_t
;
1970 typedef signed32 linux_ssize_t
;
1971 typedef signed32 linux_ptrdiff_t
;
1972 typedef signed32 linux_time_t
;
1973 typedef signed32 linux_clock_t
;
1974 typedef signed32 linux_daddr_t
;
1976 #ifdef HAVE_SYS_STAT_H
1977 /* For the PowerPC, don't both with the 'old' stat structure, since there
1978 should be no extant binaries with that structure. */
1983 linux_mode_t st_mode
;
1984 linux_nlink_t st_nlink
;
1987 linux_dev_t st_rdev
;
1988 linux_off_t st_size
;
1989 unsigned32 st_blksize
;
1990 unsigned32 st_blocks
;
1991 unsigned32 st_atimx
; /* don't use st_{a,c,m}time, that might a macro */
1992 unsigned32 __unused1
; /* defined by the host's stat.h */
1993 unsigned32 st_mtimx
;
1994 unsigned32 __unused2
;
1995 unsigned32 st_ctimx
;
1996 unsigned32 __unused3
;
1997 unsigned32 __unused4
;
1998 unsigned32 __unused5
;
2001 /* Convert from host stat structure to solaris stat structure */
2002 STATIC_INLINE_EMUL_UNIX
void
2003 convert_to_linux_stat(unsigned_word addr
,
2008 struct linux_stat target
;
2010 target
.st_dev
= H2T_4(host
->st_dev
);
2011 target
.st_ino
= H2T_4(host
->st_ino
);
2012 target
.st_mode
= H2T_4(host
->st_mode
);
2013 target
.st_nlink
= H2T_2(host
->st_nlink
);
2014 target
.st_uid
= H2T_4(host
->st_uid
);
2015 target
.st_gid
= H2T_4(host
->st_gid
);
2016 target
.st_size
= H2T_4(host
->st_size
);
2019 target
.st_rdev
= H2T_4(host
->st_rdev
);
2024 #ifdef HAVE_ST_BLKSIZE
2025 target
.st_blksize
= H2T_4(host
->st_blksize
);
2027 target
.st_blksize
= 0;
2030 #ifdef HAVE_ST_BLOCKS
2031 target
.st_blocks
= H2T_4(host
->st_blocks
);
2033 target
.st_blocks
= 0;
2036 target
.st_atimx
= H2T_4(host
->st_atime
);
2037 target
.st_ctimx
= H2T_4(host
->st_ctime
);
2038 target
.st_mtimx
= H2T_4(host
->st_mtime
);
2039 target
.__unused1
= 0;
2040 target
.__unused2
= 0;
2041 target
.__unused3
= 0;
2042 target
.__unused4
= 0;
2043 target
.__unused5
= 0;
2045 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2047 #endif /* HAVE_SYS_STAT_H */
2050 #define do_linux_stat 0
2053 do_linux_stat(os_emul_data
*emul
,
2059 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
2060 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2061 char path_buf
[PATH_MAX
];
2063 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
2066 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2067 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2069 status
= stat (path
, &buf
);
2071 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2073 emul_write_status(processor
, status
, errno
);
2078 #define do_linux_lstat 0
2081 do_linux_lstat(os_emul_data
*emul
,
2087 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
2088 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2089 char path_buf
[PATH_MAX
];
2091 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
2094 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2095 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2097 status
= lstat (path
, &buf
);
2099 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2101 emul_write_status(processor
, status
, errno
);
2106 #define do_linux_fstat 0
2109 do_linux_fstat(os_emul_data
*emul
,
2115 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
2116 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2120 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2121 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
2123 status
= fstat (fildes
, &buf
);
2125 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2127 emul_write_status(processor
, status
, errno
);
2131 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2132 #define LINUX_NCC 10
2133 #define LINUX_NCCS 19
2135 #define LINUX_VINTR 0
2136 #define LINUX_VQUIT 1
2137 #define LINUX_VERASE 2
2138 #define LINUX_VKILL 3
2139 #define LINUX_VEOF 4
2140 #define LINUX_VMIN 5
2141 #define LINUX_VEOL 6
2142 #define LINUX_VTIME 7
2143 #define LINUX_VEOL2 8
2144 #define LINUX_VSWTC 9
2145 #define LINUX_VWERASE 10
2146 #define LINUX_VREPRINT 11
2147 #define LINUX_VSUSP 12
2148 #define LINUX_VSTART 13
2149 #define LINUX_VSTOP 14
2150 #define LINUX_VLNEXT 15
2151 #define LINUX_VDISCARD 16
2153 #define LINUX_IOC_NRBITS 8
2154 #define LINUX_IOC_TYPEBITS 8
2155 #define LINUX_IOC_SIZEBITS 13
2156 #define LINUX_IOC_DIRBITS 3
2158 #define LINUX_IOC_NRMASK ((1 << LINUX_IOC_NRBITS)-1)
2159 #define LINUX_IOC_TYPEMASK ((1 << LINUX_IOC_TYPEBITS)-1)
2160 #define LINUX_IOC_SIZEMASK ((1 << LINUX_IOC_SIZEBITS)-1)
2161 #define LINUX_IOC_DIRMASK ((1 << LINUX_IOC_DIRBITS)-1)
2163 #define LINUX_IOC_NRSHIFT 0
2164 #define LINUX_IOC_TYPESHIFT (LINUX_IOC_NRSHIFT+LINUX_IOC_NRBITS)
2165 #define LINUX_IOC_SIZESHIFT (LINUX_IOC_TYPESHIFT+LINUX_IOC_TYPEBITS)
2166 #define LINUX_IOC_DIRSHIFT (LINUX_IOC_SIZESHIFT+LINUX_IOC_SIZEBITS)
2169 * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
2170 * And this turns out useful to catch old ioctl numbers in header
2173 #define LINUX_IOC_NONE 1U
2174 #define LINUX_IOC_READ 2U
2175 #define LINUX_IOC_WRITE 4U
2177 #define LINUX_IOC(dir,type,nr,size) \
2178 (((dir) << LINUX_IOC_DIRSHIFT) | \
2179 ((type) << LINUX_IOC_TYPESHIFT) | \
2180 ((nr) << LINUX_IOC_NRSHIFT) | \
2181 ((size) << LINUX_IOC_SIZESHIFT))
2183 /* used to create numbers */
2184 #define LINUX_IO(type,nr) LINUX_IOC(LINUX_IOC_NONE,(type),(nr),0)
2185 #define LINUX_IOR(type,nr,size) LINUX_IOC(LINUX_IOC_READ,(type),(nr),sizeof(size))
2186 #define LINUX_IOW(type,nr,size) LINUX_IOC(LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2187 #define LINUX_IOWR(type,nr,size) LINUX_IOC(LINUX_IOC_READ|LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2190 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2191 /* Convert to/from host termio structure */
2193 struct linux_termio
{
2194 unsigned16 c_iflag
; /* input modes */
2195 unsigned16 c_oflag
; /* output modes */
2196 unsigned16 c_cflag
; /* control modes */
2197 unsigned16 c_lflag
; /* line discipline modes */
2198 unsigned8 c_line
; /* line discipline */
2199 unsigned8 c_cc
[LINUX_NCC
]; /* control chars */
2202 STATIC_INLINE_EMUL_UNIX
void
2203 convert_to_linux_termio(unsigned_word addr
,
2204 struct termio
*host
,
2208 struct linux_termio target
;
2211 target
.c_iflag
= H2T_2 (host
->c_iflag
);
2212 target
.c_oflag
= H2T_2 (host
->c_oflag
);
2213 target
.c_cflag
= H2T_2 (host
->c_cflag
);
2214 target
.c_lflag
= H2T_2 (host
->c_lflag
);
2216 #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
2217 target
.c_line
= host
->c_line
;
2222 for (i
= 0; i
< LINUX_NCC
; i
++)
2226 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2230 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2234 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2238 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2242 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2246 target
.c_cc
[LINUX_VMIN
] = host
->c_cc
[VMIN
];
2250 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2254 target
.c_cc
[LINUX_VTIME
] = host
->c_cc
[VTIME
];
2258 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2262 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTC
];
2266 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2269 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2271 #endif /* HAVE_TERMIO_STRUCTURE */
2273 #ifdef HAVE_TERMIOS_STRUCTURE
2274 /* Convert to/from host termios structure */
2276 typedef unsigned32 linux_tcflag_t
;
2277 typedef unsigned8 linux_cc_t
;
2278 typedef unsigned32 linux_speed_t
;
2280 struct linux_termios
{
2281 linux_tcflag_t c_iflag
;
2282 linux_tcflag_t c_oflag
;
2283 linux_tcflag_t c_cflag
;
2284 linux_tcflag_t c_lflag
;
2285 linux_cc_t c_cc
[LINUX_NCCS
];
2291 STATIC_INLINE_EMUL_UNIX
void
2292 convert_to_linux_termios(unsigned_word addr
,
2293 struct termios
*host
,
2297 struct linux_termios target
;
2300 target
.c_iflag
= H2T_4 (host
->c_iflag
);
2301 target
.c_oflag
= H2T_4 (host
->c_oflag
);
2302 target
.c_cflag
= H2T_4 (host
->c_cflag
);
2303 target
.c_lflag
= H2T_4 (host
->c_lflag
);
2305 for (i
= 0; i
< LINUX_NCCS
; i
++)
2309 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2313 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2317 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2321 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2325 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2329 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2333 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2337 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2340 #ifdef HAVE_TERMIOS_CLINE
2341 target
.c_line
= host
->c_line
;
2346 #ifdef HAVE_CFGETISPEED
2347 target
.c_ispeed
= cfgetispeed (host
);
2349 target
.c_ispeed
= 0;
2352 #ifdef HAVE_CFGETOSPEED
2353 target
.c_ospeed
= cfgetospeed (host
);
2355 target
.c_ospeed
= 0;
2358 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2360 #endif /* HAVE_TERMIOS_STRUCTURE */
2363 #define do_linux_ioctl 0
2366 do_linux_ioctl(os_emul_data
*emul
,
2372 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
2373 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
2374 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
2376 const char *name
= "<unknown>";
2378 #ifdef HAVE_TERMIOS_STRUCTURE
2379 struct termios host_termio
;
2382 #ifdef HAVE_TERMIO_STRUCTURE
2383 struct termio host_termio
;
2389 case 0: /* make sure we have at least one case */
2395 #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2396 #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
2397 case LINUX_IOR('t', 23, struct linux_termio
): /* TCGETA */
2399 #ifdef HAVE_TCGETATTR
2400 status
= tcgetattr(fildes
, &host_termio
);
2401 #elif defined(TCGETS)
2402 status
= ioctl (fildes
, TCGETS
, &host_termio
);
2404 status
= ioctl (fildes
, TCGETA
, &host_termio
);
2407 convert_to_linux_termio (argp_addr
, &host_termio
, processor
, cia
);
2410 #endif /* HAVE_TERMIO_STRUCTURE */
2412 #ifdef HAVE_TERMIOS_STRUCTURE
2413 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
2414 case LINUX_IOR('t', 19, struct linux_termios
): /* TCGETS */
2416 #ifdef HAVE_TCGETATTR
2417 status
= tcgetattr(fildes
, &host_termio
);
2419 status
= ioctl (fildes
, TCGETS
, &host_termio
);
2422 convert_to_linux_termios (argp_addr
, &host_termio
, processor
, cia
);
2425 #endif /* HAVE_TERMIOS_STRUCTURE */
2428 emul_write_status(processor
, status
, errno
);
2430 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2431 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
2433 #endif /* HAVE_IOCTL */
2435 static emul_syscall_descriptor linux_descriptors
[] = {
2436 /* 0 */ { 0, "setup" },
2437 /* 1 */ { do_unix_exit
, "exit" },
2438 /* 2 */ { 0, "fork" },
2439 /* 3 */ { do_unix_read
, "read" },
2440 /* 4 */ { do_unix_write
, "write" },
2441 /* 5 */ { do_unix_open
, "open" },
2442 /* 6 */ { do_unix_close
, "close" },
2443 /* 7 */ { 0, "waitpid" },
2444 /* 8 */ { 0, "creat" },
2445 /* 9 */ { do_unix_link
, "link" },
2446 /* 10 */ { do_unix_unlink
, "unlink" },
2447 /* 11 */ { 0, "execve" },
2448 /* 12 */ { do_unix_chdir
, "chdir" },
2449 /* 13 */ { do_unix_time
, "time" },
2450 /* 14 */ { 0, "mknod" },
2451 /* 15 */ { 0, "chmod" },
2452 /* 16 */ { 0, "chown" },
2453 /* 17 */ { 0, "break" },
2454 /* 18 */ { 0, "stat" },
2455 /* 19 */ { do_unix_lseek
, "lseek" },
2456 /* 20 */ { do_unix_getpid
, "getpid" },
2457 /* 21 */ { 0, "mount" },
2458 /* 22 */ { 0, "umount" },
2459 /* 23 */ { 0, "setuid" },
2460 /* 24 */ { do_unix_getuid
, "getuid" },
2461 /* 25 */ { 0, "stime" },
2462 /* 26 */ { 0, "ptrace" },
2463 /* 27 */ { 0, "alarm" },
2464 /* 28 */ { 0, "fstat" },
2465 /* 29 */ { 0, "pause" },
2466 /* 30 */ { 0, "utime" },
2467 /* 31 */ { 0, "stty" },
2468 /* 32 */ { 0, "gtty" },
2469 /* 33 */ { do_unix_access
, "access" },
2470 /* 34 */ { 0, "nice" },
2471 /* 35 */ { 0, "ftime" },
2472 /* 36 */ { 0, "sync" },
2473 /* 37 */ { 0, "kill" },
2474 /* 38 */ { 0, "rename" },
2475 /* 39 */ { do_unix_mkdir
, "mkdir" },
2476 /* 40 */ { do_unix_rmdir
, "rmdir" },
2477 /* 41 */ { do_unix_dup
, "dup" },
2478 /* 42 */ { 0, "pipe" },
2479 /* 43 */ { 0, "times" },
2480 /* 44 */ { 0, "prof" },
2481 /* 45 */ { do_unix_break
, "brk" },
2482 /* 46 */ { 0, "setgid" },
2483 /* 47 */ { do_unix_getgid
, "getgid" },
2484 /* 48 */ { 0, "signal" },
2485 /* 49 */ { do_unix_geteuid
, "geteuid" },
2486 /* 50 */ { do_unix_getegid
, "getegid" },
2487 /* 51 */ { 0, "acct" },
2488 /* 52 */ { 0, "phys" },
2489 /* 53 */ { 0, "lock" },
2490 /* 54 */ { do_linux_ioctl
, "ioctl" },
2491 /* 55 */ { 0, "fcntl" },
2492 /* 56 */ { 0, "mpx" },
2493 /* 57 */ { 0, "setpgid" },
2494 /* 58 */ { 0, "ulimit" },
2495 /* 59 */ { 0, "olduname" },
2496 /* 60 */ { do_unix_umask
, "umask" },
2497 /* 61 */ { 0, "chroot" },
2498 /* 62 */ { 0, "ustat" },
2499 /* 63 */ { do_unix_dup2
, "dup2" },
2500 /* 64 */ { do_unix_getppid
, "getppid" },
2501 /* 65 */ { 0, "getpgrp" },
2502 /* 66 */ { 0, "setsid" },
2503 /* 67 */ { 0, "sigaction" },
2504 /* 68 */ { 0, "sgetmask" },
2505 /* 69 */ { 0, "ssetmask" },
2506 /* 70 */ { 0, "setreuid" },
2507 /* 71 */ { 0, "setregid" },
2508 /* 72 */ { 0, "sigsuspend" },
2509 /* 73 */ { 0, "sigpending" },
2510 /* 74 */ { 0, "sethostname" },
2511 /* 75 */ { 0, "setrlimit" },
2512 /* 76 */ { 0, "getrlimit" },
2513 /* 77 */ { do_unix_getrusage
, "getrusage" },
2514 /* 78 */ { do_unix_gettimeofday
, "gettimeofday" },
2515 /* 79 */ { 0, "settimeofday" },
2516 /* 80 */ { 0, "getgroups" },
2517 /* 81 */ { 0, "setgroups" },
2518 /* 82 */ { 0, "select" },
2519 /* 83 */ { do_unix_symlink
, "symlink" },
2520 /* 84 */ { 0, "lstat" },
2521 /* 85 */ { 0, "readlink" },
2522 /* 86 */ { 0, "uselib" },
2523 /* 87 */ { 0, "swapon" },
2524 /* 88 */ { 0, "reboot" },
2525 /* 89 */ { 0, "readdir" },
2526 /* 90 */ { 0, "mmap" },
2527 /* 91 */ { 0, "munmap" },
2528 /* 92 */ { 0, "truncate" },
2529 /* 93 */ { 0, "ftruncate" },
2530 /* 94 */ { 0, "fchmod" },
2531 /* 95 */ { 0, "fchown" },
2532 /* 96 */ { 0, "getpriority" },
2533 /* 97 */ { 0, "setpriority" },
2534 /* 98 */ { 0, "profil" },
2535 /* 99 */ { 0, "statfs" },
2536 /* 100 */ { 0, "fstatfs" },
2537 /* 101 */ { 0, "ioperm" },
2538 /* 102 */ { 0, "socketcall" },
2539 /* 103 */ { 0, "syslog" },
2540 /* 104 */ { 0, "setitimer" },
2541 /* 105 */ { 0, "getitimer" },
2542 /* 106 */ { do_linux_stat
, "newstat" },
2543 /* 107 */ { do_linux_lstat
, "newlstat" },
2544 /* 108 */ { do_linux_fstat
, "newfstat" },
2545 /* 109 */ { 0, "uname" },
2546 /* 110 */ { 0, "iopl" },
2547 /* 111 */ { 0, "vhangup" },
2548 /* 112 */ { 0, "idle" },
2549 /* 113 */ { 0, "vm86" },
2550 /* 114 */ { 0, "wait4" },
2551 /* 115 */ { 0, "swapoff" },
2552 /* 116 */ { 0, "sysinfo" },
2553 /* 117 */ { 0, "ipc" },
2554 /* 118 */ { 0, "fsync" },
2555 /* 119 */ { 0, "sigreturn" },
2556 /* 120 */ { 0, "clone" },
2557 /* 121 */ { 0, "setdomainname" },
2558 /* 122 */ { 0, "newuname" },
2559 /* 123 */ { 0, "modify_ldt" },
2560 /* 124 */ { 0, "adjtimex" },
2561 /* 125 */ { 0, "mprotect" },
2562 /* 126 */ { 0, "sigprocmask" },
2563 /* 127 */ { 0, "create_module" },
2564 /* 128 */ { 0, "init_module" },
2565 /* 129 */ { 0, "delete_module" },
2566 /* 130 */ { 0, "get_kernel_syms" },
2567 /* 131 */ { 0, "quotactl" },
2568 /* 132 */ { 0, "getpgid" },
2569 /* 133 */ { 0, "fchdir" },
2570 /* 134 */ { 0, "bdflush" },
2571 /* 135 */ { 0, "sysfs" },
2572 /* 136 */ { 0, "personality" },
2573 /* 137 */ { 0, "afs_syscall" },
2574 /* 138 */ { 0, "setfsuid" },
2575 /* 139 */ { 0, "setfsgid" },
2576 /* 140 */ { 0, "llseek" },
2577 /* 141 */ { 0, "getdents" },
2578 /* 142 */ { 0, "newselect" },
2579 /* 143 */ { 0, "flock" },
2580 /* 144 */ { 0, "msync" },
2581 /* 145 */ { 0, "readv" },
2582 /* 146 */ { 0, "writev" },
2583 /* 147 */ { 0, "getsid" },
2584 /* 148 */ { 0, "fdatasync" },
2585 /* 149 */ { 0, "sysctl" },
2586 /* 150 */ { 0, "mlock" },
2587 /* 151 */ { 0, "munlock" },
2588 /* 152 */ { 0, "mlockall" },
2589 /* 153 */ { 0, "munlockall" },
2590 /* 154 */ { 0, "sched_setparam" },
2591 /* 155 */ { 0, "sched_getparam" },
2592 /* 156 */ { 0, "sched_setscheduler" },
2593 /* 157 */ { 0, "sched_getscheduler" },
2594 /* 158 */ { 0, "sched_yield" },
2595 /* 159 */ { 0, "sched_get_priority_max" },
2596 /* 160 */ { 0, "sched_get_priority_min" },
2597 /* 161 */ { 0, "sched_rr_get_interval" },
2600 static char *(linux_error_names
[]) = {
2637 /* 36 */ "ENAMETOOLONG",
2640 /* 39 */ "ENOTEMPTY",
2646 /* 45 */ "EL2NSYNC",
2659 /* 58 */ "EDEADLOCK",
2673 /* 72 */ "EMULTIHOP",
2676 /* 75 */ "EOVERFLOW",
2677 /* 76 */ "ENOTUNIQ",
2684 /* 83 */ "ELIBEXEC",
2686 /* 85 */ "ERESTART",
2687 /* 86 */ "ESTRPIPE",
2689 /* 88 */ "ENOTSOCK",
2690 /* 89 */ "EDESTADDRREQ",
2691 /* 90 */ "EMSGSIZE",
2692 /* 91 */ "EPROTOTYPE",
2693 /* 92 */ "ENOPROTOOPT",
2694 /* 93 */ "EPROTONOSUPPORT",
2695 /* 94 */ "ESOCKTNOSUPPORT",
2696 /* 95 */ "EOPNOTSUPP",
2697 /* 96 */ "EPFNOSUPPORT",
2698 /* 97 */ "EAFNOSUPPORT",
2699 /* 98 */ "EADDRINUSE",
2700 /* 99 */ "EADDRNOTAVAIL",
2701 /* 100 */ "ENETDOWN",
2702 /* 101 */ "ENETUNREACH",
2703 /* 102 */ "ENETRESET",
2704 /* 103 */ "ECONNABORTED",
2705 /* 104 */ "ECONNRESET",
2706 /* 105 */ "ENOBUFS",
2707 /* 106 */ "EISCONN",
2708 /* 107 */ "ENOTCONN",
2709 /* 108 */ "ESHUTDOWN",
2710 /* 109 */ "ETOOMANYREFS",
2711 /* 110 */ "ETIMEDOUT",
2712 /* 111 */ "ECONNREFUSED",
2713 /* 112 */ "EHOSTDOWN",
2714 /* 113 */ "EHOSTUNREACH",
2715 /* 114 */ "EALREADY",
2716 /* 115 */ "EINPROGRESS",
2718 /* 117 */ "EUCLEAN",
2719 /* 118 */ "ENOTNAM",
2720 /* 119 */ "ENAVAIL",
2722 /* 121 */ "EREMOTEIO",
2726 static char *(linux_signal_names
[]) = {
2744 /* 16 */ "SIGSTKFLT",
2754 /* 26 */ "SIGVTALRM",
2756 /* 28 */ "SIGWINCH",
2759 /* 31 */ "SIGUNUSED",
2762 static emul_syscall emul_linux_syscalls
= {
2764 sizeof(linux_descriptors
) / sizeof(linux_descriptors
[0]),
2766 sizeof(linux_error_names
) / sizeof(linux_error_names
[0]),
2768 sizeof(linux_signal_names
) / sizeof(linux_signal_names
[0]),
2772 /* Linux's os_emul interface, most are just passed on to the generic
2775 static os_emul_data
*
2776 emul_linux_create(device
*root
,
2780 /* check that this emulation is really for us */
2781 if (name
!= NULL
&& strcmp(name
, "linux") != 0)
2787 return emul_unix_create(root
, image
, "linux", &emul_linux_syscalls
);
2791 emul_linux_init(os_emul_data
*emul_data
,
2798 emul_linux_system_call(cpu
*processor
,
2800 os_emul_data
*emul_data
)
2802 emul_do_system_call(emul_data
,
2803 emul_data
->syscalls
,
2804 cpu_registers(processor
)->gpr
[0],
2805 3, /*r3 contains arg0*/
2810 const os_emul emul_linux
= {
2814 emul_linux_system_call
,
2815 0, /*instruction_call*/
2819 #endif /* _EMUL_UNIX_C_ */