1 /* This file is part of the program psim.
3 Copyright (C) 1996, 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 #ifdef HAVE_SYS_TERMIOS_H
69 #include <sys/termios.h>
72 #ifdef HAVE_SYS_TERMIO_H
73 #include <sys/termio.h>
77 #ifndef HAVE_SYS_RESOURCE_H
83 #include <sys/resource.h>
88 #include <sys/ioctl.h>
92 #include <sys/mount.h>
97 # define NAMLEN(dirent) strlen((dirent)->d_name)
99 # define dirent direct
100 # define NAMLEN(dirent) (dirent)->d_namlen
102 # include <sys/ndir.h>
105 # include <sys/dir.h>
113 #undef MAXPATHLEN /* sys/param.h might define this also */
121 #if defined(BSD) && !defined(errno) && (BSD < 199306) /* here BSD as just a bug */
125 #ifndef STATIC_INLINE_EMUL_UNIX
126 #define STATIC_INLINE_EMUL_UNIX STATIC_INLINE
130 #define PATH_MAX 1024
137 /* UNIX's idea of what is needed to implement emulations */
139 struct _os_emul_data
{
141 emul_syscall
*syscalls
;
145 /* Emulation of simple UNIX system calls that are common on all systems. */
147 /* Structures that are common agmonst the UNIX varients */
148 struct unix_timeval
{
149 signed32 tv_sec
; /* seconds */
150 signed32 tv_usec
; /* microseconds */
153 struct unix_timezone
{
154 signed32 tz_minuteswest
; /* minutes west of Greenwich */
155 signed32 tz_dsttime
; /* type of dst correction */
158 #define UNIX_RUSAGE_SELF 0
159 #define UNIX_RUSAGE_CHILDREN (-1)
160 #define UNIX_RUSAGE_BOTH (-2) /* sys_wait4() uses this */
163 struct unix_timeval ru_utime
; /* user time used */
164 struct unix_timeval ru_stime
; /* system time used */
165 signed32 ru_maxrss
; /* maximum resident set size */
166 signed32 ru_ixrss
; /* integral shared memory size */
167 signed32 ru_idrss
; /* integral unshared data size */
168 signed32 ru_isrss
; /* integral unshared stack size */
169 signed32 ru_minflt
; /* any page faults not requiring I/O */
170 signed32 ru_majflt
; /* any page faults requiring I/O */
171 signed32 ru_nswap
; /* swaps */
172 signed32 ru_inblock
; /* block input operations */
173 signed32 ru_oublock
; /* block output operations */
174 signed32 ru_msgsnd
; /* messages sent */
175 signed32 ru_msgrcv
; /* messages received */
176 signed32 ru_nsignals
; /* signals received */
177 signed32 ru_nvcsw
; /* voluntary context switches */
178 signed32 ru_nivcsw
; /* involuntary " */
183 do_unix_exit(os_emul_data
*emul
,
189 int status
= (int)cpu_registers(processor
)->gpr
[arg0
];
190 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
191 printf_filtered ("%d)\n", status
);
193 cpu_halt(processor
, cia
, was_exited
, status
);
198 do_unix_read(os_emul_data
*emul
,
204 void *scratch_buffer
;
205 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
206 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
207 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
210 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
211 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
213 /* get a tempoary bufer */
214 scratch_buffer
= zalloc(nbytes
);
216 /* check if buffer exists by reading it */
217 emul_read_buffer(scratch_buffer
, buf
, nbytes
, processor
, cia
);
220 status
= read (d
, scratch_buffer
, nbytes
);
222 emul_write_status(processor
, status
, errno
);
224 emul_write_buffer(scratch_buffer
, buf
, status
, processor
, cia
);
226 zfree(scratch_buffer
);
231 do_unix_write(os_emul_data
*emul
,
237 void *scratch_buffer
= NULL
;
239 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
240 unsigned_word buf
= cpu_registers(processor
)->gpr
[arg0
+1];
241 int nbytes
= cpu_registers(processor
)->gpr
[arg0
+2];
244 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
245 printf_filtered ("%d, 0x%lx, %d", d
, (long)buf
, nbytes
);
247 /* get a tempoary bufer */
248 scratch_buffer
= zalloc(nbytes
); /* FIXME - nbytes == 0 */
251 nr_moved
= vm_data_map_read_buffer(cpu_data_map(processor
),
255 if (nr_moved
!= nbytes
) {
256 /* FIXME - should handle better */
257 error("system_call()write copy failed (nr_moved=%d != nbytes=%d)\n",
262 status
= write(d
, scratch_buffer
, nbytes
);
263 emul_write_status(processor
, status
, errno
);
264 zfree(scratch_buffer
);
271 do_unix_open(os_emul_data
*emul
,
277 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
278 char path_buf
[PATH_MAX
];
279 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
280 int flags
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
281 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
284 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
285 printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr
, path
, flags
, mode
);
287 status
= open(path
, flags
, mode
);
288 emul_write_status(processor
, status
, errno
);
293 do_unix_close(os_emul_data
*emul
,
299 int d
= (int)cpu_registers(processor
)->gpr
[arg0
];
302 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
303 printf_filtered ("%d", d
);
306 emul_write_status(processor
, status
, errno
);
311 do_unix_break(os_emul_data
*emul
,
317 /* just pass this onto the `vm' device */
318 psim
*system
= cpu_system(processor
);
319 unsigned_word new_break
= cpu_registers(processor
)->gpr
[arg0
];
322 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
323 printf_filtered ("0x%lx", (long)cpu_registers(processor
)->gpr
[arg0
]);
325 status
= device_ioctl(emul
->vm
,
329 new_break
); /*ioctl-data*/
331 emul_write_status(processor
, 0, status
);
335 #define do_unix_getpid 0
338 do_unix_getpid(os_emul_data
*emul
,
344 pid_t status
= getpid();
345 emul_write_status(processor
, (int)status
, errno
);
350 #define do_unix_getppid 0
353 do_unix_getppid(os_emul_data
*emul
,
359 pid_t status
= getppid();
360 emul_write_status(processor
, (int)status
, errno
);
364 #if !defined(HAVE_GETPID) || !defined(HAVE_GETPPID)
365 #define do_unix_getpid2 0
368 do_unix_getpid2(os_emul_data
*emul
,
374 int pid
= (int)getpid();
375 int ppid
= (int)getppid();
376 emul_write2_status(processor
, pid
, ppid
, errno
);
380 #if !defined(HAVE_GETUID) || !defined(HAVE_GETEUID)
381 #define do_unix_getuid2 0
384 do_unix_getuid2(os_emul_data
*emul
,
390 uid_t uid
= getuid();
391 uid_t euid
= geteuid();
392 emul_write2_status(processor
, (int)uid
, (int)euid
, errno
);
397 #define do_unix_getuid 0
400 do_unix_getuid(os_emul_data
*emul
,
406 uid_t status
= getuid();
407 emul_write_status(processor
, (int)status
, errno
);
412 #define do_unix_geteuid 0
415 do_unix_geteuid(os_emul_data
*emul
,
421 uid_t status
= geteuid();
422 emul_write_status(processor
, (int)status
, errno
);
428 #define do_unix_kill 0
431 do_unix_kill(os_emul_data
*emul
,
437 pid_t pid
= cpu_registers(processor
)->gpr
[arg0
];
438 int sig
= cpu_registers(processor
)->gpr
[arg0
+1];
440 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
441 printf_filtered ("%d, %d", (int)pid
, sig
);
443 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
446 cpu_halt(processor
, cia
, was_signalled
, sig
);
452 #define do_unix_dup 0
455 do_unix_dup(os_emul_data
*emul
,
461 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
462 int status
= dup(oldd
);
465 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
466 printf_filtered ("%d", oldd
);
468 emul_write_status(processor
, status
, err
);
473 #define do_unix_dup2 0
476 do_unix_dup2(os_emul_data
*emul
,
482 int oldd
= cpu_registers(processor
)->gpr
[arg0
];
483 int newd
= cpu_registers(processor
)->gpr
[arg0
+1];
484 int status
= dup2(oldd
, newd
);
487 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
488 printf_filtered ("%d, %d", oldd
, newd
);
490 emul_write_status(processor
, status
, err
);
495 #define do_unix_lseek 0
498 do_unix_lseek(os_emul_data
*emul
,
504 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
505 off_t offset
= (off_t
)cpu_registers(processor
)->gpr
[arg0
+1];
506 int whence
= (int)cpu_registers(processor
)->gpr
[arg0
+2];
509 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
510 printf_filtered ("%d %ld %d", fildes
, (long)offset
, whence
);
512 status
= lseek(fildes
, offset
, whence
);
513 emul_write_status(processor
, (int)status
, errno
);
518 #if !defined(HAVE_GETGID) || !defined(HAVE_GETEGID)
519 #define do_unix_getgid2 0
522 do_unix_getgid2(os_emul_data
*emul
,
528 gid_t gid
= getgid();
529 gid_t egid
= getegid();
530 emul_write2_status(processor
, (int)gid
, (int)egid
, errno
);
535 #define do_unix_getgid 0
538 do_unix_getgid(os_emul_data
*emul
,
544 gid_t status
= getgid();
545 emul_write_status(processor
, (int)status
, errno
);
550 #define do_unix_getegid 0
553 do_unix_getegid(os_emul_data
*emul
,
559 gid_t status
= getegid();
560 emul_write_status(processor
, (int)status
, errno
);
565 #define do_unix_umask 0
568 do_unix_umask(os_emul_data
*emul
,
574 mode_t mask
= (mode_t
)cpu_registers(processor
)->gpr
[arg0
];
575 int status
= umask(mask
);
577 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
578 printf_filtered ("0%o", mask
);
580 emul_write_status(processor
, status
, errno
);
585 #define do_unix_chdir 0
588 do_unix_chdir(os_emul_data
*emul
,
594 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
595 char path_buf
[PATH_MAX
];
596 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
599 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
600 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
602 status
= chdir(path
);
603 emul_write_status(processor
, status
, errno
);
608 #define do_unix_link 0
611 do_unix_link(os_emul_data
*emul
,
617 unsigned_word path1_addr
= cpu_registers(processor
)->gpr
[arg0
];
618 char path1_buf
[PATH_MAX
];
619 char *path1
= emul_read_string(path1_buf
, path1_addr
, PATH_MAX
, processor
, cia
);
620 unsigned_word path2_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
621 char path2_buf
[PATH_MAX
];
622 char *path2
= emul_read_string(path2_buf
, path2_addr
, PATH_MAX
, processor
, cia
);
625 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
626 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr
, path1
, (long)path2_addr
, path2
);
628 status
= link(path1
, path2
);
629 emul_write_status(processor
, status
, errno
);
634 #define do_unix_symlink 0
637 do_unix_symlink(os_emul_data
*emul
,
643 unsigned_word path1_addr
= cpu_registers(processor
)->gpr
[arg0
];
644 char path1_buf
[PATH_MAX
];
645 char *path1
= emul_read_string(path1_buf
, path1_addr
, PATH_MAX
, processor
, cia
);
646 unsigned_word path2_addr
= cpu_registers(processor
)->gpr
[arg0
+1];
647 char path2_buf
[PATH_MAX
];
648 char *path2
= emul_read_string(path2_buf
, path2_addr
, PATH_MAX
, processor
, cia
);
651 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
652 printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr
, path1
, (long)path2_addr
, path2
);
654 status
= symlink(path1
, path2
);
655 emul_write_status(processor
, status
, errno
);
660 #define do_unix_unlink 0
663 do_unix_unlink(os_emul_data
*emul
,
669 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
670 char path_buf
[PATH_MAX
];
671 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
674 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
675 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
677 status
= unlink(path
);
678 emul_write_status(processor
, status
, errno
);
683 #define do_unix_mkdir 0
686 do_unix_mkdir(os_emul_data
*emul
,
692 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
693 char path_buf
[PATH_MAX
];
694 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
695 int mode
= (int)cpu_registers(processor
)->gpr
[arg0
+1];
698 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
699 printf_filtered ("0x%lx [%s], 0%3o", (long)path_addr
, path
, mode
);
701 status
= mkdir(path
, mode
);
702 emul_write_status(processor
, status
, errno
);
707 #define do_unix_rmdir 0
710 do_unix_rmdir(os_emul_data
*emul
,
716 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
717 char path_buf
[PATH_MAX
];
718 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
721 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
722 printf_filtered ("0x%lx [%s]", (long)path_addr
, path
);
724 status
= rmdir(path
);
725 emul_write_status(processor
, status
, errno
);
730 #define do_unix_time 0
733 do_unix_time(os_emul_data
*emul
,
739 unsigned_word tp
= cpu_registers(processor
)->gpr
[arg0
];
740 time_t now
= time ((time_t *)0);
741 unsigned_word status
= H2T_4(now
);
743 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
744 printf_filtered ("0x%lx", (long)tp
);
746 emul_write_status(processor
, (int)status
, errno
);
749 emul_write_buffer(&status
, tp
, sizeof(status
), processor
, cia
);
753 #if !defined(HAVE_GETTIMEOFDAY) || !defined(HAVE_SYS_TIME_H)
754 #define do_unix_gettimeofday 0
757 do_unix_gettimeofday(os_emul_data
*emul
,
763 unsigned_word tv
= cpu_registers(processor
)->gpr
[arg0
];
764 unsigned_word tz
= cpu_registers(processor
)->gpr
[arg0
+1];
765 struct unix_timeval target_timeval
;
766 struct timeval host_timeval
;
767 struct unix_timezone target_timezone
;
768 struct timezone host_timezone
;
771 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
772 printf_filtered ("0x%lx, 0x%lx", (long)tv
, (long)tz
);
774 /* Just in case the system doesn't set the timezone structure */
775 host_timezone
.tz_minuteswest
= 0;
776 host_timezone
.tz_dsttime
= 0;
778 status
= gettimeofday(&host_timeval
, &host_timezone
);
781 target_timeval
.tv_sec
= H2T_4(host_timeval
.tv_sec
);
782 target_timeval
.tv_usec
= H2T_4(host_timeval
.tv_usec
);
783 emul_write_buffer((void *) &target_timeval
, tv
, sizeof(target_timeval
), processor
, cia
);
787 target_timezone
.tz_minuteswest
= H2T_4(host_timezone
.tz_minuteswest
);
788 target_timezone
.tz_dsttime
= H2T_4(host_timezone
.tz_dsttime
);
789 emul_write_buffer((void *) &target_timezone
, tv
, sizeof(target_timezone
), processor
, cia
);
793 emul_write_status(processor
, (int)status
, errno
);
798 #ifndef HAVE_GETRUSAGE
799 #define do_unix_getrusage 0
802 do_unix_getrusage(os_emul_data
*emul
,
808 signed_word who
= (signed_word
)cpu_registers(processor
)->gpr
[arg0
];
809 unsigned_word usage
= cpu_registers(processor
)->gpr
[arg0
+1];
810 struct rusage host_rusage
, host_rusage2
;
811 struct unix_rusage target_rusage
;
814 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
815 printf_filtered ("%ld, 0x%lx", (long)who
, (long)usage
);
823 case UNIX_RUSAGE_SELF
:
824 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
827 case UNIX_RUSAGE_CHILDREN
:
828 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage
);
831 case UNIX_RUSAGE_BOTH
:
832 status
= getrusage(RUSAGE_SELF
, &host_rusage
);
834 status
= getrusage(RUSAGE_CHILDREN
, &host_rusage2
);
836 host_rusage
.ru_utime
.tv_sec
+= host_rusage2
.ru_utime
.tv_sec
;
837 host_rusage
.ru_utime
.tv_usec
+= host_rusage2
.ru_utime
.tv_usec
;
838 host_rusage
.ru_stime
.tv_sec
+= host_rusage2
.ru_stime
.tv_sec
;
839 host_rusage
.ru_stime
.tv_usec
+= host_rusage2
.ru_stime
.tv_usec
;
840 host_rusage
.ru_maxrss
+= host_rusage2
.ru_maxrss
;
841 host_rusage
.ru_ixrss
+= host_rusage2
.ru_ixrss
;
842 host_rusage
.ru_idrss
+= host_rusage2
.ru_idrss
;
843 host_rusage
.ru_isrss
+= host_rusage2
.ru_isrss
;
844 host_rusage
.ru_minflt
+= host_rusage2
.ru_minflt
;
845 host_rusage
.ru_majflt
+= host_rusage2
.ru_majflt
;
846 host_rusage
.ru_nswap
+= host_rusage2
.ru_nswap
;
847 host_rusage
.ru_inblock
+= host_rusage2
.ru_inblock
;
848 host_rusage
.ru_oublock
+= host_rusage2
.ru_oublock
;
849 host_rusage
.ru_msgsnd
+= host_rusage2
.ru_msgsnd
;
850 host_rusage
.ru_msgrcv
+= host_rusage2
.ru_msgrcv
;
851 host_rusage
.ru_nsignals
+= host_rusage2
.ru_nsignals
;
852 host_rusage
.ru_nvcsw
+= host_rusage2
.ru_nvcsw
;
853 host_rusage
.ru_nivcsw
+= host_rusage2
.ru_nivcsw
;
859 target_rusage
.ru_utime
.tv_sec
= H2T_4(host_rusage2
.ru_utime
.tv_sec
);
860 target_rusage
.ru_utime
.tv_usec
= H2T_4(host_rusage2
.ru_utime
.tv_usec
);
861 target_rusage
.ru_stime
.tv_sec
= H2T_4(host_rusage2
.ru_stime
.tv_sec
);
862 target_rusage
.ru_stime
.tv_usec
= H2T_4(host_rusage2
.ru_stime
.tv_usec
);
863 target_rusage
.ru_maxrss
= H2T_4(host_rusage2
.ru_maxrss
);
864 target_rusage
.ru_ixrss
= H2T_4(host_rusage2
.ru_ixrss
);
865 target_rusage
.ru_idrss
= H2T_4(host_rusage2
.ru_idrss
);
866 target_rusage
.ru_isrss
= H2T_4(host_rusage2
.ru_isrss
);
867 target_rusage
.ru_minflt
= H2T_4(host_rusage2
.ru_minflt
);
868 target_rusage
.ru_majflt
= H2T_4(host_rusage2
.ru_majflt
);
869 target_rusage
.ru_nswap
= H2T_4(host_rusage2
.ru_nswap
);
870 target_rusage
.ru_inblock
= H2T_4(host_rusage2
.ru_inblock
);
871 target_rusage
.ru_oublock
= H2T_4(host_rusage2
.ru_oublock
);
872 target_rusage
.ru_msgsnd
= H2T_4(host_rusage2
.ru_msgsnd
);
873 target_rusage
.ru_msgrcv
= H2T_4(host_rusage2
.ru_msgrcv
);
874 target_rusage
.ru_nsignals
= H2T_4(host_rusage2
.ru_nsignals
);
875 target_rusage
.ru_nvcsw
= H2T_4(host_rusage2
.ru_nvcsw
);
876 target_rusage
.ru_nivcsw
= H2T_4(host_rusage2
.ru_nivcsw
);
877 emul_write_buffer((void *) &target_rusage
, usage
, sizeof(target_rusage
), processor
, cia
);
880 emul_write_status(processor
, status
, errno
);
885 /* Common code for initializing the system call stuff */
887 static os_emul_data
*
888 emul_unix_create(device
*root
,
891 emul_syscall
*syscall
)
893 unsigned_word top_of_stack
;
899 /* merge any emulation specific entries into the device tree */
901 /* establish a few defaults */
902 if (image
->xvec
->flavour
== bfd_target_elf_flavour
) {
904 top_of_stack
= 0xe0000000;
905 stack_size
= 0x00100000;
909 top_of_stack
= 0x20000000;
910 stack_size
= 0x00100000;
914 emul_add_tree_options(root
, image
, name
,
915 (WITH_ENVIRONMENT
== USER_ENVIRONMENT
916 ? "user" : "virtual"),
917 0 /*oea-interrupt-prefix*/);
919 /* virtual memory - handles growth of stack/heap */
920 vm
= device_tree_add_parsed(root
, "/openprom/vm@0x%lx",
921 (unsigned long)(top_of_stack
- stack_size
));
922 device_tree_add_parsed(vm
, "./stack-base 0x%lx",
923 (unsigned long)(top_of_stack
- stack_size
));
924 device_tree_add_parsed(vm
, "./nr-bytes 0x%x", stack_size
);
926 device_tree_add_parsed(root
, "/openprom/vm/map-binary/file-name %s",
927 bfd_get_filename(image
));
929 /* finish the init */
930 device_tree_add_parsed(root
, "/openprom/init/register/pc 0x%lx",
931 (unsigned long)bfd_get_start_address(image
));
932 device_tree_add_parsed(root
, "/openprom/init/register/sp 0x%lx",
933 (unsigned long)top_of_stack
);
934 device_tree_add_parsed(root
, "/openprom/init/register/msr 0x%x", msr_little_endian_mode
);
935 device_tree_add_parsed(root
, "/openprom/init/stack/stack-type %s",
936 (elf_binary
? "elf" : "xcoff"));
938 /* finally our emulation data */
939 data
= ZALLOC(os_emul_data
);
941 data
->syscalls
= syscall
;
946 /* Solaris specific implementation */
948 typedef signed32 solaris_uid_t
;
949 typedef signed32 solaris_gid_t
;
950 typedef signed32 solaris_off_t
;
951 typedef signed32 solaris_pid_t
;
952 typedef signed32 solaris_time_t
;
953 typedef unsigned32 solaris_dev_t
;
954 typedef unsigned32 solaris_ino_t
;
955 typedef unsigned32 solaris_mode_t
;
956 typedef unsigned32 solaris_nlink_t
;
958 #ifdef HAVE_SYS_STAT_H
959 #define SOLARIS_ST_FSTYPSZ 16 /* array size for file system type name */
961 struct solaris_stat
{
962 solaris_dev_t st_dev
;
963 signed32 st_pad1
[3]; /* reserved for network id */
964 solaris_ino_t st_ino
;
965 solaris_mode_t st_mode
;
966 solaris_nlink_t st_nlink
;
967 solaris_uid_t st_uid
;
968 solaris_gid_t st_gid
;
969 solaris_dev_t st_rdev
;
971 solaris_off_t st_size
;
972 signed32 st_pad3
; /* future off_t expansion */
973 struct unix_timeval st_atim
;
974 struct unix_timeval st_mtim
;
975 struct unix_timeval st_ctim
;
978 char st_fstype
[SOLARIS_ST_FSTYPSZ
];
979 signed32 st_pad4
[8]; /* expansion area */
982 /* Convert from host stat structure to solaris stat structure */
983 STATIC_INLINE_EMUL_UNIX
void
984 convert_to_solaris_stat(unsigned_word addr
,
989 struct solaris_stat target
;
992 target
.st_dev
= H2T_4(host
->st_dev
);
993 target
.st_ino
= H2T_4(host
->st_ino
);
994 target
.st_mode
= H2T_4(host
->st_mode
);
995 target
.st_nlink
= H2T_4(host
->st_nlink
);
996 target
.st_uid
= H2T_4(host
->st_uid
);
997 target
.st_gid
= H2T_4(host
->st_gid
);
998 target
.st_size
= H2T_4(host
->st_size
);
1001 target
.st_rdev
= H2T_4(host
->st_rdev
);
1006 #ifdef HAVE_ST_BLKSIZE
1007 target
.st_blksize
= H2T_4(host
->st_blksize
);
1009 target
.st_blksize
= 0;
1012 #ifdef HAVE_ST_BLOCKS
1013 target
.st_blocks
= H2T_4(host
->st_blocks
);
1015 target
.st_blocks
= 0;
1018 target
.st_atim
.tv_sec
= H2T_4(host
->st_atime
);
1019 target
.st_atim
.tv_usec
= 0;
1021 target
.st_ctim
.tv_sec
= H2T_4(host
->st_ctime
);
1022 target
.st_ctim
.tv_usec
= 0;
1024 target
.st_mtim
.tv_sec
= H2T_4(host
->st_mtime
);
1025 target
.st_mtim
.tv_usec
= 0;
1027 for (i
= 0; i
< sizeof (target
.st_pad1
) / sizeof (target
.st_pad1
[0]); i
++)
1028 target
.st_pad1
[i
] = 0;
1030 for (i
= 0; i
< sizeof (target
.st_pad2
) / sizeof (target
.st_pad2
[0]); i
++)
1031 target
.st_pad2
[i
] = 0;
1035 for (i
= 0; i
< sizeof (target
.st_pad4
) / sizeof (target
.st_pad4
[0]); i
++)
1036 target
.st_pad4
[i
] = 0;
1038 /* For now, just punt and always say it is a ufs file */
1039 strcpy (target
.st_fstype
, "ufs");
1041 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1043 #endif /* HAVE_SYS_STAT_H */
1046 #define do_solaris_stat 0
1049 do_solaris_stat(os_emul_data
*emul
,
1055 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1056 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1057 char path_buf
[PATH_MAX
];
1059 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1062 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1063 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1065 status
= stat (path
, &buf
);
1067 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1069 emul_write_status(processor
, status
, errno
);
1074 #define do_solaris_lstat 0
1077 do_solaris_lstat(os_emul_data
*emul
,
1083 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1084 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1085 char path_buf
[PATH_MAX
];
1087 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1090 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1091 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1093 status
= lstat (path
, &buf
);
1095 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1097 emul_write_status(processor
, status
, errno
);
1102 #define do_solaris_fstat 0
1105 do_solaris_fstat(os_emul_data
*emul
,
1111 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
1112 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1116 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1117 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
1119 status
= fstat (fildes
, &buf
);
1121 convert_to_solaris_stat (stat_pkt
, &buf
, processor
, cia
);
1123 emul_write_status(processor
, status
, errno
);
1127 #if defined(HAVE_SYS_TERMIO_H) || defined(HAVE_SYS_TERMIOS_H)
1128 #define SOLARIS_TIOC ('T'<<8)
1129 #define SOLARIS_NCC 8
1130 #define SOLARIS_NCCS 19
1132 #define SOLARIS_VINTR 0
1133 #define SOLARIS_VQUIT 1
1134 #define SOLARIS_VERASE 2
1135 #define SOLARIS_VKILL 3
1136 #define SOLARIS_VEOF 4
1137 #define SOLARIS_VEOL 5
1138 #define SOLARIS_VEOL2 6
1139 #define SOLARIS_VSWTCH 7
1140 #define SOLARIS_VSTART 8
1141 #define SOLARIS_VSTOP 9
1142 #define SOLARIS_VSUSP 10
1143 #define SOLARIS_VDSUSP 11
1144 #define SOLARIS_VREPRINT 12
1145 #define SOLARIS_VDISCARD 13
1146 #define SOLARIS_VWERASE 14
1147 #define SOLARIS_VLNEXT 15
1150 #ifdef HAVE_SYS_TERMIO_H
1151 /* Convert to/from host termio structure */
1153 struct solaris_termio
{
1154 unsigned16 c_iflag
; /* input modes */
1155 unsigned16 c_oflag
; /* output modes */
1156 unsigned16 c_cflag
; /* control modes */
1157 unsigned16 c_lflag
; /* line discipline modes */
1158 unsigned8 c_line
; /* line discipline */
1159 unsigned8 c_cc
[SOLARIS_NCC
]; /* control chars */
1162 STATIC_INLINE_EMUL_UNIX
void
1163 convert_to_solaris_termio(unsigned_word addr
,
1164 struct termio
*host
,
1168 struct solaris_termio target
;
1171 target
.c_iflag
= H2T_2 (host
->c_iflag
);
1172 target
.c_oflag
= H2T_2 (host
->c_oflag
);
1173 target
.c_cflag
= H2T_2 (host
->c_cflag
);
1174 target
.c_lflag
= H2T_2 (host
->c_lflag
);
1175 target
.c_line
= host
->c_line
;
1177 for (i
= 0; i
< SOLARIS_NCC
; i
++)
1181 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1185 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1189 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1193 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1197 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1201 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1205 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1209 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1213 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1217 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1219 #endif /* HAVE_SYS_TERMIO_H */
1221 #ifdef HAVE_SYS_TERMIOS_H
1222 /* Convert to/from host termios structure */
1224 typedef unsigned32 solaris_tcflag_t
;
1225 typedef unsigned8 solaris_cc_t
;
1226 typedef unsigned32 solaris_speed_t
;
1228 struct solaris_termios
{
1229 solaris_tcflag_t c_iflag
;
1230 solaris_tcflag_t c_oflag
;
1231 solaris_tcflag_t c_cflag
;
1232 solaris_tcflag_t c_lflag
;
1233 solaris_cc_t c_cc
[SOLARIS_NCCS
];
1236 STATIC_INLINE_EMUL_UNIX
void
1237 convert_to_solaris_termios(unsigned_word addr
,
1238 struct termios
*host
,
1242 struct solaris_termios target
;
1245 target
.c_iflag
= H2T_4 (host
->c_iflag
);
1246 target
.c_oflag
= H2T_4 (host
->c_oflag
);
1247 target
.c_cflag
= H2T_4 (host
->c_cflag
);
1248 target
.c_lflag
= H2T_4 (host
->c_lflag
);
1250 for (i
= 0; i
< SOLARIS_NCCS
; i
++)
1254 target
.c_cc
[SOLARIS_VINTR
] = host
->c_cc
[VINTR
];
1258 target
.c_cc
[SOLARIS_VQUIT
] = host
->c_cc
[VQUIT
];
1262 target
.c_cc
[SOLARIS_VERASE
] = host
->c_cc
[VERASE
];
1266 target
.c_cc
[SOLARIS_VKILL
] = host
->c_cc
[VKILL
];
1270 target
.c_cc
[SOLARIS_VEOF
] = host
->c_cc
[VEOF
];
1274 target
.c_cc
[SOLARIS_VEOL
] = host
->c_cc
[VEOL
];
1278 target
.c_cc
[SOLARIS_VEOL2
] = host
->c_cc
[VEOL2
];
1282 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTCH
];
1286 target
.c_cc
[SOLARIS_VSWTCH
] = host
->c_cc
[VSWTC
];
1291 target
.c_cc
[SOLARIS_VSTART
] = host
->c_cc
[VSTART
];
1295 target
.c_cc
[SOLARIS_VSTOP
] = host
->c_cc
[VSTOP
];
1299 target
.c_cc
[SOLARIS_VSUSP
] = host
->c_cc
[VSUSP
];
1303 target
.c_cc
[SOLARIS_VDSUSP
] = host
->c_cc
[VDSUSP
];
1307 target
.c_cc
[SOLARIS_VREPRINT
] = host
->c_cc
[VREPRINT
];
1311 target
.c_cc
[SOLARIS_VDISCARD
] = host
->c_cc
[VDISCARD
];
1315 target
.c_cc
[SOLARIS_VWERASE
] = host
->c_cc
[VWERASE
];
1319 target
.c_cc
[SOLARIS_VLNEXT
] = host
->c_cc
[VLNEXT
];
1322 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1324 #endif /* HAVE_SYS_TERMIOS_H */
1327 #define do_solaris_ioctl 0
1330 do_solaris_ioctl(os_emul_data
*emul
,
1336 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
1337 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
1338 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
1340 const char *name
= "<unknown>";
1342 #ifdef HAVE_SYS_TERMIO_H
1343 struct termio host_termio
;
1346 #ifdef HAVE_SYS_TERMIOS_H
1347 struct termios host_termios
;
1352 case 0: /* make sure we have at least one case */
1358 #ifdef HAVE_SYS_TERMIO_H
1360 case SOLARIS_TIOC
| 1: /* TCGETA */
1362 status
= ioctl (fildes
, TCGETA
, &host_termio
);
1364 convert_to_solaris_termio (argp_addr
, &host_termio
, processor
, cia
);
1367 #endif /* HAVE_SYS_TERMIO_H */
1369 #ifdef HAVE_SYS_TERMIOS_H
1370 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
1371 case SOLARIS_TIOC
| 13: /* TCGETS */
1373 #ifdef HAVE_TCGETATTR
1374 status
= tcgetattr(fildes
, &host_termios
);
1376 status
= ioctl (fildes
, TCGETS
, &host_termios
);
1379 convert_to_solaris_termios (argp_addr
, &host_termios
, processor
, cia
);
1382 #endif /* HAVE_SYS_TERMIOS_H */
1385 emul_write_status(processor
, status
, errno
);
1387 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1388 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
1390 #endif /* HAVE_IOCTL */
1392 static emul_syscall_descriptor solaris_descriptors
[] = {
1393 /* 0 */ { 0, "syscall" },
1394 /* 1 */ { do_unix_exit
, "exit" },
1395 /* 2 */ { 0, "fork" },
1396 /* 3 */ { do_unix_read
, "read" },
1397 /* 4 */ { do_unix_write
, "write" },
1398 /* 5 */ { do_unix_open
, "open" },
1399 /* 6 */ { do_unix_close
, "close" },
1400 /* 7 */ { 0, "wait" },
1401 /* 8 */ { 0, "creat" },
1402 /* 9 */ { do_unix_link
, "link" },
1403 /* 10 */ { do_unix_unlink
, "unlink" },
1404 /* 11 */ { 0, "exec" },
1405 /* 12 */ { do_unix_chdir
, "chdir" },
1406 /* 13 */ { do_unix_time
, "time" },
1407 /* 14 */ { 0, "mknod" },
1408 /* 15 */ { 0, "chmod" },
1409 /* 16 */ { 0, "chown" },
1410 /* 17 */ { do_unix_break
, "brk" },
1411 /* 18 */ { do_solaris_stat
, "stat" },
1412 /* 19 */ { do_unix_lseek
, "lseek" },
1413 /* 20 */ { do_unix_getpid2
, "getpid" },
1414 /* 21 */ { 0, "mount" },
1415 /* 22 */ { 0, "umount" },
1416 /* 23 */ { 0, "setuid" },
1417 /* 24 */ { do_unix_getuid2
, "getuid" },
1418 /* 25 */ { 0, "stime" },
1419 /* 26 */ { 0, "ptrace" },
1420 /* 27 */ { 0, "alarm" },
1421 /* 28 */ { do_solaris_fstat
, "fstat" },
1422 /* 29 */ { 0, "pause" },
1423 /* 30 */ { 0, "utime" },
1424 /* 31 */ { 0, "stty" },
1425 /* 32 */ { 0, "gtty" },
1426 /* 33 */ { 0, "access" },
1427 /* 34 */ { 0, "nice" },
1428 /* 35 */ { 0, "statfs" },
1429 /* 36 */ { 0, "sync" },
1430 /* 37 */ { 0, "kill" },
1431 /* 38 */ { 0, "fstatfs" },
1432 /* 39 */ { 0, "pgrpsys" },
1433 /* 40 */ { 0, "xenix" },
1434 /* 41 */ { do_unix_dup
, "dup" },
1435 /* 42 */ { 0, "pipe" },
1436 /* 43 */ { 0, "times" },
1437 /* 44 */ { 0, "profil" },
1438 /* 45 */ { 0, "plock" },
1439 /* 46 */ { 0, "setgid" },
1440 /* 47 */ { do_unix_getgid2
, "getgid" },
1441 /* 48 */ { 0, "signal" },
1442 /* 49 */ { 0, "msgsys" },
1443 /* 50 */ { 0, "syssun" },
1444 /* 51 */ { 0, "acct" },
1445 /* 52 */ { 0, "shmsys" },
1446 /* 53 */ { 0, "semsys" },
1447 /* 54 */ { do_solaris_ioctl
, "ioctl" },
1448 /* 55 */ { 0, "uadmin" },
1449 /* 56 */ { 0, 0 /* reserved for exch */ },
1450 /* 57 */ { 0, "utssys" },
1451 /* 58 */ { 0, "fdsync" },
1452 /* 59 */ { 0, "execve" },
1453 /* 60 */ { do_unix_umask
, "umask" },
1454 /* 61 */ { 0, "chroot" },
1455 /* 62 */ { 0, "fcntl" },
1456 /* 63 */ { 0, "ulimit" },
1457 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1458 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1459 /* 65 */ { 0, 0 /* reserved for UNIX PC */ },
1460 /* 66 */ { 0, 0 /* reserved for UNIX PC */ },
1461 /* 67 */ { 0, 0 /* reserved for UNIX PC */ },
1462 /* 68 */ { 0, 0 /* reserved for UNIX PC */ },
1463 /* 69 */ { 0, 0 /* reserved for UNIX PC */ },
1464 /* 70 */ { 0, 0 /* was advfs */ },
1465 /* 71 */ { 0, 0 /* was unadvfs */ },
1466 /* 72 */ { 0, 0 /* was rmount */ },
1467 /* 73 */ { 0, 0 /* was rumount */ },
1468 /* 74 */ { 0, 0 /* was rfstart */ },
1469 /* 75 */ { 0, 0 /* was sigret */ },
1470 /* 76 */ { 0, 0 /* was rdebug */ },
1471 /* 77 */ { 0, 0 /* was rfstop */ },
1472 /* 78 */ { 0, 0 /* was rfsys */ },
1473 /* 79 */ { do_unix_rmdir
, "rmdir" },
1474 /* 80 */ { do_unix_mkdir
, "mkdir" },
1475 /* 81 */ { 0, "getdents" },
1476 /* 82 */ { 0, 0 /* was libattach */ },
1477 /* 83 */ { 0, 0 /* was libdetach */ },
1478 /* 84 */ { 0, "sysfs" },
1479 /* 85 */ { 0, "getmsg" },
1480 /* 86 */ { 0, "putmsg" },
1481 /* 87 */ { 0, "poll" },
1482 /* 88 */ { do_solaris_lstat
, "lstat" },
1483 /* 89 */ { do_unix_symlink
, "symlink" },
1484 /* 90 */ { 0, "readlink" },
1485 /* 91 */ { 0, "setgroups" },
1486 /* 92 */ { 0, "getgroups" },
1487 /* 93 */ { 0, "fchmod" },
1488 /* 94 */ { 0, "fchown" },
1489 /* 95 */ { 0, "sigprocmask" },
1490 /* 96 */ { 0, "sigsuspend" },
1491 /* 97 */ { 0, "sigaltstack" },
1492 /* 98 */ { 0, "sigaction" },
1493 /* 99 */ { 0, "sigpending" },
1494 /* 100 */ { 0, "context" },
1495 /* 101 */ { 0, "evsys" },
1496 /* 102 */ { 0, "evtrapret" },
1497 /* 103 */ { 0, "statvfs" },
1498 /* 104 */ { 0, "fstatvfs" },
1499 /* 105 */ { 0, 0 /* reserved */ },
1500 /* 106 */ { 0, "nfssys" },
1501 /* 107 */ { 0, "waitsys" },
1502 /* 108 */ { 0, "sigsendsys" },
1503 /* 109 */ { 0, "hrtsys" },
1504 /* 110 */ { 0, "acancel" },
1505 /* 111 */ { 0, "async" },
1506 /* 112 */ { 0, "priocntlsys" },
1507 /* 113 */ { 0, "pathconf" },
1508 /* 114 */ { 0, "mincore" },
1509 /* 115 */ { 0, "mmap" },
1510 /* 116 */ { 0, "mprotect" },
1511 /* 117 */ { 0, "munmap" },
1512 /* 118 */ { 0, "fpathconf" },
1513 /* 119 */ { 0, "vfork" },
1514 /* 120 */ { 0, "fchdir" },
1515 /* 121 */ { 0, "readv" },
1516 /* 122 */ { 0, "writev" },
1517 /* 123 */ { 0, "xstat" },
1518 /* 124 */ { 0, "lxstat" },
1519 /* 125 */ { 0, "fxstat" },
1520 /* 126 */ { 0, "xmknod" },
1521 /* 127 */ { 0, "clocal" },
1522 /* 128 */ { 0, "setrlimit" },
1523 /* 129 */ { 0, "getrlimit" },
1524 /* 130 */ { 0, "lchown" },
1525 /* 131 */ { 0, "memcntl" },
1526 /* 132 */ { 0, "getpmsg" },
1527 /* 133 */ { 0, "putpmsg" },
1528 /* 134 */ { 0, "rename" },
1529 /* 135 */ { 0, "uname" },
1530 /* 136 */ { 0, "setegid" },
1531 /* 137 */ { 0, "sysconfig" },
1532 /* 138 */ { 0, "adjtime" },
1533 /* 139 */ { 0, "systeminfo" },
1534 /* 140 */ { 0, 0 /* reserved */ },
1535 /* 141 */ { 0, "seteuid" },
1536 /* 142 */ { 0, "vtrace" },
1537 /* 143 */ { 0, "fork1" },
1538 /* 144 */ { 0, "sigtimedwait" },
1539 /* 145 */ { 0, "lwp_info" },
1540 /* 146 */ { 0, "yield" },
1541 /* 147 */ { 0, "lwp_sema_wait" },
1542 /* 148 */ { 0, "lwp_sema_post" },
1543 /* 149 */ { 0, 0 /* reserved */ },
1544 /* 150 */ { 0, 0 /* reserved */ },
1545 /* 151 */ { 0, 0 /* reserved */ },
1546 /* 152 */ { 0, "modctl" },
1547 /* 153 */ { 0, "fchroot" },
1548 /* 154 */ { 0, "utimes" },
1549 /* 155 */ { 0, "vhangup" },
1550 /* 156 */ { do_unix_gettimeofday
, "gettimeofday" },
1551 /* 157 */ { 0, "getitimer" },
1552 /* 158 */ { 0, "setitimer" },
1553 /* 159 */ { 0, "lwp_create" },
1554 /* 160 */ { 0, "lwp_exit" },
1555 /* 161 */ { 0, "lwp_suspend" },
1556 /* 162 */ { 0, "lwp_continue" },
1557 /* 163 */ { 0, "lwp_kill" },
1558 /* 164 */ { 0, "lwp_self" },
1559 /* 165 */ { 0, "lwp_setprivate" },
1560 /* 166 */ { 0, "lwp_getprivate" },
1561 /* 167 */ { 0, "lwp_wait" },
1562 /* 168 */ { 0, "lwp_mutex_unlock" },
1563 /* 169 */ { 0, "lwp_mutex_lock" },
1564 /* 170 */ { 0, "lwp_cond_wait" },
1565 /* 171 */ { 0, "lwp_cond_signal" },
1566 /* 172 */ { 0, "lwp_cond_broadcast" },
1567 /* 173 */ { 0, "pread" },
1568 /* 174 */ { 0, "pwrite" },
1569 /* 175 */ { 0, "llseek" },
1570 /* 176 */ { 0, "inst_sync" },
1571 /* 177 */ { 0, 0 /* reserved */ },
1572 /* 178 */ { 0, "kaio" },
1573 /* 179 */ { 0, 0 /* reserved */ },
1574 /* 180 */ { 0, 0 /* reserved */ },
1575 /* 181 */ { 0, 0 /* reserved */ },
1576 /* 182 */ { 0, 0 /* reserved */ },
1577 /* 183 */ { 0, 0 /* reserved */ },
1578 /* 184 */ { 0, "tsolsys" },
1579 /* 185 */ { 0, "acl" },
1580 /* 186 */ { 0, "auditsys" },
1581 /* 187 */ { 0, "processor_bind" },
1582 /* 188 */ { 0, "processor_info" },
1583 /* 189 */ { 0, "p_online" },
1584 /* 190 */ { 0, "sigqueue" },
1585 /* 191 */ { 0, "clock_gettime" },
1586 /* 192 */ { 0, "clock_settime" },
1587 /* 193 */ { 0, "clock_getres" },
1588 /* 194 */ { 0, "timer_create" },
1589 /* 195 */ { 0, "timer_delete" },
1590 /* 196 */ { 0, "timer_settime" },
1591 /* 197 */ { 0, "timer_gettime" },
1592 /* 198 */ { 0, "timer_getoverrun" },
1593 /* 199 */ { 0, "nanosleep" },
1594 /* 200 */ { 0, "facl" },
1595 /* 201 */ { 0, "door" },
1596 /* 202 */ { 0, "setreuid" },
1597 /* 203 */ { 0, "setregid" },
1598 /* 204 */ { 0, "install_utrap" },
1599 /* 205 */ { 0, 0 /* reserved */ },
1600 /* 206 */ { 0, 0 /* reserved */ },
1601 /* 207 */ { 0, 0 /* reserved */ },
1602 /* 208 */ { 0, 0 /* reserved */ },
1603 /* 209 */ { 0, 0 /* reserved */ },
1604 /* 210 */ { 0, "signotifywait" },
1605 /* 211 */ { 0, "lwp_sigredirect" },
1606 /* 212 */ { 0, "lwp_alarm" },
1609 static char *(solaris_error_names
[]) = {
1648 /* 38 */ "EL2NSYNC",
1657 /* 47 */ "ECANCELED",
1666 /* 56 */ "EDEADLOCK",
1668 /* 58 */ "Error code 58",
1669 /* 59 */ "Error code 59",
1682 /* 72 */ "Error code 72",
1683 /* 73 */ "Error code 73",
1684 /* 74 */ "EMULTIHOP",
1685 /* 75 */ "Error code 75",
1686 /* 76 */ "Error code 76",
1688 /* 78 */ "ENAMETOOLONG",
1689 /* 79 */ "EOVERFLOW",
1690 /* 80 */ "ENOTUNIQ",
1697 /* 87 */ "ELIBEXEC",
1701 /* 91 */ "ERESTART",
1702 /* 92 */ "ESTRPIPE",
1703 /* 93 */ "ENOTEMPTY",
1705 /* 95 */ "ENOTSOCK",
1706 /* 96 */ "EDESTADDRREQ",
1707 /* 97 */ "EMSGSIZE",
1708 /* 98 */ "EPROTOTYPE",
1709 /* 99 */ "ENOPROTOOPT",
1710 /* 100 */ "Error code 100",
1711 /* 101 */ "Error code 101",
1712 /* 102 */ "Error code 102",
1713 /* 103 */ "Error code 103",
1714 /* 104 */ "Error code 104",
1715 /* 105 */ "Error code 105",
1716 /* 106 */ "Error code 106",
1717 /* 107 */ "Error code 107",
1718 /* 108 */ "Error code 108",
1719 /* 109 */ "Error code 109",
1720 /* 110 */ "Error code 110",
1721 /* 111 */ "Error code 111",
1722 /* 112 */ "Error code 112",
1723 /* 113 */ "Error code 113",
1724 /* 114 */ "Error code 114",
1725 /* 115 */ "Error code 115",
1726 /* 116 */ "Error code 116",
1727 /* 117 */ "Error code 117",
1728 /* 118 */ "Error code 118",
1729 /* 119 */ "Error code 119",
1730 /* 120 */ "EPROTONOSUPPORT",
1731 /* 121 */ "ESOCKTNOSUPPORT",
1732 /* 122 */ "EOPNOTSUPP",
1733 /* 123 */ "EPFNOSUPPORT",
1734 /* 124 */ "EAFNOSUPPORT",
1735 /* 125 */ "EADDRINUSE",
1736 /* 126 */ "EADDRNOTAVAIL",
1737 /* 127 */ "ENETDOWN",
1738 /* 128 */ "ENETUNREACH",
1739 /* 129 */ "ENETRESET",
1740 /* 130 */ "ECONNABORTED",
1741 /* 131 */ "ECONNRESET",
1742 /* 132 */ "ENOBUFS",
1743 /* 133 */ "EISCONN",
1744 /* 134 */ "ENOTCONN",
1745 /* 135 */ "Error code 135", /* XENIX has 135 - 142 */
1746 /* 136 */ "Error code 136",
1747 /* 137 */ "Error code 137",
1748 /* 138 */ "Error code 138",
1749 /* 139 */ "Error code 139",
1750 /* 140 */ "Error code 140",
1751 /* 141 */ "Error code 141",
1752 /* 142 */ "Error code 142",
1753 /* 143 */ "ESHUTDOWN",
1754 /* 144 */ "ETOOMANYREFS",
1755 /* 145 */ "ETIMEDOUT",
1756 /* 146 */ "ECONNREFUSED",
1757 /* 147 */ "EHOSTDOWN",
1758 /* 148 */ "EHOSTUNREACH",
1759 /* 149 */ "EALREADY",
1760 /* 150 */ "EINPROGRESS",
1764 static char *(solaris_signal_names
[]) = {
1785 /* 20 */ "SIGWINCH",
1793 /* 28 */ "SIGVTALRM",
1797 /* 32 */ "SIGWAITING",
1799 /* 34 */ "SIGFREEZE",
1801 /* 36 */ "SIGCANCEL",
1804 static emul_syscall emul_solaris_syscalls
= {
1805 solaris_descriptors
,
1806 sizeof(solaris_descriptors
) / sizeof(solaris_descriptors
[0]),
1807 solaris_error_names
,
1808 sizeof(solaris_error_names
) / sizeof(solaris_error_names
[0]),
1809 solaris_signal_names
,
1810 sizeof(solaris_signal_names
) / sizeof(solaris_signal_names
[0]),
1814 /* Solaris's os_emul interface, most are just passed on to the generic
1817 static os_emul_data
*
1818 emul_solaris_create(device
*root
,
1822 /* check that this emulation is really for us */
1823 if (name
!= NULL
&& strcmp(name
, "solaris") != 0)
1829 return emul_unix_create(root
, image
, "solaris", &emul_solaris_syscalls
);
1833 emul_solaris_init(os_emul_data
*emul_data
,
1840 emul_solaris_system_call(cpu
*processor
,
1842 os_emul_data
*emul_data
)
1844 emul_do_system_call(emul_data
,
1845 emul_data
->syscalls
,
1846 cpu_registers(processor
)->gpr
[0],
1847 3, /*r3 contains arg0*/
1852 const os_emul emul_solaris
= {
1854 emul_solaris_create
,
1856 emul_solaris_system_call
,
1857 0, /*instruction_call*/
1862 /* Linux specific implementation */
1864 typedef unsigned32 linux_dev_t
;
1865 typedef unsigned32 linux_ino_t
;
1866 typedef unsigned32 linux_mode_t
;
1867 typedef unsigned16 linux_nlink_t
;
1868 typedef signed32 linux_off_t
;
1869 typedef signed32 linux_pid_t
;
1870 typedef unsigned32 linux_uid_t
;
1871 typedef unsigned32 linux_gid_t
;
1872 typedef unsigned32 linux_size_t
;
1873 typedef signed32 linux_ssize_t
;
1874 typedef signed32 linux_ptrdiff_t
;
1875 typedef signed32 linux_time_t
;
1876 typedef signed32 linux_clock_t
;
1877 typedef signed32 linux_daddr_t
;
1879 #ifdef HAVE_SYS_STAT_H
1880 /* For the PowerPC, don't both with the 'old' stat structure, since there
1881 should be no extant binaries with that structure. */
1886 linux_mode_t st_mode
;
1887 linux_nlink_t st_nlink
;
1890 linux_dev_t st_rdev
;
1891 linux_off_t st_size
;
1892 unsigned32 st_blksize
;
1893 unsigned32 st_blocks
;
1894 unsigned32 st_atimx
; /* don't use st_{a,c,m}time, that might a macro */
1895 unsigned32 __unused1
; /* defined by the host's stat.h */
1896 unsigned32 st_mtimx
;
1897 unsigned32 __unused2
;
1898 unsigned32 st_ctimx
;
1899 unsigned32 __unused3
;
1900 unsigned32 __unused4
;
1901 unsigned32 __unused5
;
1904 /* Convert from host stat structure to solaris stat structure */
1905 STATIC_INLINE_EMUL_UNIX
void
1906 convert_to_linux_stat(unsigned_word addr
,
1911 struct linux_stat target
;
1913 target
.st_dev
= H2T_4(host
->st_dev
);
1914 target
.st_ino
= H2T_4(host
->st_ino
);
1915 target
.st_mode
= H2T_4(host
->st_mode
);
1916 target
.st_nlink
= H2T_2(host
->st_nlink
);
1917 target
.st_uid
= H2T_4(host
->st_uid
);
1918 target
.st_gid
= H2T_4(host
->st_gid
);
1919 target
.st_size
= H2T_4(host
->st_size
);
1922 target
.st_rdev
= H2T_4(host
->st_rdev
);
1927 #ifdef HAVE_ST_BLKSIZE
1928 target
.st_blksize
= H2T_4(host
->st_blksize
);
1930 target
.st_blksize
= 0;
1933 #ifdef HAVE_ST_BLOCKS
1934 target
.st_blocks
= H2T_4(host
->st_blocks
);
1936 target
.st_blocks
= 0;
1939 target
.st_atimx
= H2T_4(host
->st_atime
);
1940 target
.st_ctimx
= H2T_4(host
->st_ctime
);
1941 target
.st_mtimx
= H2T_4(host
->st_mtime
);
1942 target
.__unused1
= 0;
1943 target
.__unused2
= 0;
1944 target
.__unused3
= 0;
1945 target
.__unused4
= 0;
1946 target
.__unused5
= 0;
1948 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
1950 #endif /* HAVE_SYS_STAT_H */
1953 #define do_linux_stat 0
1956 do_linux_stat(os_emul_data
*emul
,
1962 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1963 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1964 char path_buf
[PATH_MAX
];
1966 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1969 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1970 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
1972 status
= stat (path
, &buf
);
1974 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
1976 emul_write_status(processor
, status
, errno
);
1981 #define do_linux_lstat 0
1984 do_linux_lstat(os_emul_data
*emul
,
1990 unsigned_word path_addr
= cpu_registers(processor
)->gpr
[arg0
];
1991 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
1992 char path_buf
[PATH_MAX
];
1994 char *path
= emul_read_string(path_buf
, path_addr
, PATH_MAX
, processor
, cia
);
1997 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
1998 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr
, path
, (long)stat_pkt
);
2000 status
= lstat (path
, &buf
);
2002 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2004 emul_write_status(processor
, status
, errno
);
2009 #define do_linux_fstat 0
2012 do_linux_fstat(os_emul_data
*emul
,
2018 int fildes
= (int)cpu_registers(processor
)->gpr
[arg0
];
2019 unsigned_word stat_pkt
= cpu_registers(processor
)->gpr
[arg0
+1];
2023 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2024 printf_filtered ("%d, 0x%lx", fildes
, (long)stat_pkt
);
2026 status
= fstat (fildes
, &buf
);
2028 convert_to_linux_stat (stat_pkt
, &buf
, processor
, cia
);
2030 emul_write_status(processor
, status
, errno
);
2034 #if defined(HAVE_SYS_TERMIO_H) || defined(HAVE_SYS_TERMIOS_H)
2035 #define LINUX_NCC 10
2036 #define LINUX_NCCS 19
2038 #define LINUX_VINTR 0
2039 #define LINUX_VQUIT 1
2040 #define LINUX_VERASE 2
2041 #define LINUX_VKILL 3
2042 #define LINUX_VEOF 4
2043 #define LINUX_VMIN 5
2044 #define LINUX_VEOL 6
2045 #define LINUX_VTIME 7
2046 #define LINUX_VEOL2 8
2047 #define LINUX_VSWTC 9
2048 #define LINUX_VWERASE 10
2049 #define LINUX_VREPRINT 11
2050 #define LINUX_VSUSP 12
2051 #define LINUX_VSTART 13
2052 #define LINUX_VSTOP 14
2053 #define LINUX_VLNEXT 15
2054 #define LINUX_VDISCARD 16
2056 #define LINUX_IOC_NRBITS 8
2057 #define LINUX_IOC_TYPEBITS 8
2058 #define LINUX_IOC_SIZEBITS 13
2059 #define LINUX_IOC_DIRBITS 3
2061 #define LINUX_IOC_NRMASK ((1 << LINUX_IOC_NRBITS)-1)
2062 #define LINUX_IOC_TYPEMASK ((1 << LINUX_IOC_TYPEBITS)-1)
2063 #define LINUX_IOC_SIZEMASK ((1 << LINUX_IOC_SIZEBITS)-1)
2064 #define LINUX_IOC_DIRMASK ((1 << LINUX_IOC_DIRBITS)-1)
2066 #define LINUX_IOC_NRSHIFT 0
2067 #define LINUX_IOC_TYPESHIFT (LINUX_IOC_NRSHIFT+LINUX_IOC_NRBITS)
2068 #define LINUX_IOC_SIZESHIFT (LINUX_IOC_TYPESHIFT+LINUX_IOC_TYPEBITS)
2069 #define LINUX_IOC_DIRSHIFT (LINUX_IOC_SIZESHIFT+LINUX_IOC_SIZEBITS)
2072 * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
2073 * And this turns out useful to catch old ioctl numbers in header
2076 #define LINUX_IOC_NONE 1U
2077 #define LINUX_IOC_READ 2U
2078 #define LINUX_IOC_WRITE 4U
2080 #define LINUX_IOC(dir,type,nr,size) \
2081 (((dir) << LINUX_IOC_DIRSHIFT) | \
2082 ((type) << LINUX_IOC_TYPESHIFT) | \
2083 ((nr) << LINUX_IOC_NRSHIFT) | \
2084 ((size) << LINUX_IOC_SIZESHIFT))
2086 /* used to create numbers */
2087 #define LINUX_IO(type,nr) LINUX_IOC(LINUX_IOC_NONE,(type),(nr),0)
2088 #define LINUX_IOR(type,nr,size) LINUX_IOC(LINUX_IOC_READ,(type),(nr),sizeof(size))
2089 #define LINUX_IOW(type,nr,size) LINUX_IOC(LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2090 #define LINUX_IOWR(type,nr,size) LINUX_IOC(LINUX_IOC_READ|LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2093 #ifdef HAVE_SYS_TERMIO_H
2094 /* Convert to/from host termio structure */
2096 struct linux_termio
{
2097 unsigned16 c_iflag
; /* input modes */
2098 unsigned16 c_oflag
; /* output modes */
2099 unsigned16 c_cflag
; /* control modes */
2100 unsigned16 c_lflag
; /* line discipline modes */
2101 unsigned8 c_line
; /* line discipline */
2102 unsigned8 c_cc
[LINUX_NCC
]; /* control chars */
2105 STATIC_INLINE_EMUL_UNIX
void
2106 convert_to_linux_termio(unsigned_word addr
,
2107 struct termio
*host
,
2111 struct linux_termio target
;
2114 target
.c_iflag
= H2T_2 (host
->c_iflag
);
2115 target
.c_oflag
= H2T_2 (host
->c_oflag
);
2116 target
.c_cflag
= H2T_2 (host
->c_cflag
);
2117 target
.c_lflag
= H2T_2 (host
->c_lflag
);
2118 target
.c_line
= host
->c_line
;
2120 for (i
= 0; i
< LINUX_NCC
; i
++)
2124 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2128 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2132 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2136 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2140 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2144 target
.c_cc
[LINUX_VMIN
] = host
->c_cc
[VMIN
];
2148 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2152 target
.c_cc
[LINUX_VTIME
] = host
->c_cc
[VTIME
];
2156 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2160 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTC
];
2164 target
.c_cc
[LINUX_VSWTC
] = host
->c_cc
[VSWTCH
];
2167 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2169 #endif /* HAVE_SYS_TERMIO_H */
2171 #ifdef HAVE_SYS_TERMIOS_H
2172 /* Convert to/from host termios structure */
2174 typedef unsigned32 linux_tcflag_t
;
2175 typedef unsigned8 linux_cc_t
;
2176 typedef unsigned32 linux_speed_t
;
2178 struct linux_termios
{
2179 linux_tcflag_t c_iflag
;
2180 linux_tcflag_t c_oflag
;
2181 linux_tcflag_t c_cflag
;
2182 linux_tcflag_t c_lflag
;
2183 linux_cc_t c_cc
[LINUX_NCCS
];
2189 STATIC_INLINE_EMUL_UNIX
void
2190 convert_to_linux_termios(unsigned_word addr
,
2191 struct termios
*host
,
2195 struct linux_termios target
;
2198 target
.c_iflag
= H2T_4 (host
->c_iflag
);
2199 target
.c_oflag
= H2T_4 (host
->c_oflag
);
2200 target
.c_cflag
= H2T_4 (host
->c_cflag
);
2201 target
.c_lflag
= H2T_4 (host
->c_lflag
);
2203 for (i
= 0; i
< LINUX_NCCS
; i
++)
2207 target
.c_cc
[LINUX_VINTR
] = host
->c_cc
[VINTR
];
2211 target
.c_cc
[LINUX_VQUIT
] = host
->c_cc
[VQUIT
];
2215 target
.c_cc
[LINUX_VERASE
] = host
->c_cc
[VERASE
];
2219 target
.c_cc
[LINUX_VKILL
] = host
->c_cc
[VKILL
];
2223 target
.c_cc
[LINUX_VEOF
] = host
->c_cc
[VEOF
];
2227 target
.c_cc
[LINUX_VEOL
] = host
->c_cc
[VEOL
];
2231 target
.c_cc
[LINUX_VEOL2
] = host
->c_cc
[VEOL2
];
2235 target
.c_cc
[LINUX_VSWTCH
] = host
->c_cc
[VSWTCH
];
2240 #ifdef HAVE_CFGETISPEED
2241 target
.c_ispeed
= cfgetispeed (host
);
2243 target
.c_ispeed
= 0;
2246 #ifdef HAVE_CFGETOSPEED
2247 target
.c_ospeed
= cfgetospeed (host
);
2249 target
.c_ospeed
= 0;
2252 emul_write_buffer(&target
, addr
, sizeof(target
), processor
, cia
);
2254 #endif /* HAVE_SYS_TERMIOS_H */
2257 #define do_linux_ioctl 0
2260 do_linux_ioctl(os_emul_data
*emul
,
2266 int fildes
= cpu_registers(processor
)->gpr
[arg0
];
2267 unsigned request
= cpu_registers(processor
)->gpr
[arg0
+1];
2268 unsigned_word argp_addr
= cpu_registers(processor
)->gpr
[arg0
+2];
2270 const char *name
= "<unknown>";
2272 #ifdef HAVE_SYS_TERMIO_H
2273 struct termio host_termio
;
2276 #ifdef HAVE_SYS_TERMIOS_H
2277 struct termios host_termios
;
2282 case 0: /* make sure we have at least one case */
2288 #ifdef HAVE_SYS_TERMIO_H
2290 case LINUX_IOR('t', 23, struct linux_termio
): /* TCGETA */
2292 status
= ioctl (fildes
, TCGETA
, &host_termio
);
2294 convert_to_linux_termio (argp_addr
, &host_termio
, processor
, cia
);
2297 #endif /* HAVE_SYS_TERMIO_H */
2299 #ifdef HAVE_SYS_TERMIOS_H
2300 #if defined(TCGETS) || defined(HAVE_TCGETATTR)
2301 case LINUX_IOR('t', 19, struct linux_termios
): /* TCGETS */
2303 #ifdef HAVE_TCGETATTR
2304 status
= tcgetattr(fildes
, &host_termios
);
2306 status
= ioctl (fildes
, TCGETS
, &host_termios
);
2309 convert_to_linux_termios (argp_addr
, &host_termios
, processor
, cia
);
2312 #endif /* HAVE_SYS_TERMIOS_H */
2315 emul_write_status(processor
, status
, errno
);
2317 if (WITH_TRACE
&& ppc_trace
[trace_os_emul
])
2318 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes
, request
, name
, (long)argp_addr
);
2320 #endif /* HAVE_IOCTL */
2322 static emul_syscall_descriptor linux_descriptors
[] = {
2323 /* 0 */ { 0, "setup" },
2324 /* 1 */ { do_unix_exit
, "exit" },
2325 /* 2 */ { 0, "fork" },
2326 /* 3 */ { do_unix_read
, "read" },
2327 /* 4 */ { do_unix_write
, "write" },
2328 /* 5 */ { do_unix_open
, "open" },
2329 /* 6 */ { do_unix_close
, "close" },
2330 /* 7 */ { 0, "waitpid" },
2331 /* 8 */ { 0, "creat" },
2332 /* 9 */ { do_unix_link
, "link" },
2333 /* 10 */ { do_unix_unlink
, "unlink" },
2334 /* 11 */ { 0, "execve" },
2335 /* 12 */ { do_unix_chdir
, "chdir" },
2336 /* 13 */ { do_unix_time
, "time" },
2337 /* 14 */ { 0, "mknod" },
2338 /* 15 */ { 0, "chmod" },
2339 /* 16 */ { 0, "chown" },
2340 /* 17 */ { 0, "break" },
2341 /* 18 */ { 0, "stat" },
2342 /* 19 */ { do_unix_lseek
, "lseek" },
2343 /* 20 */ { do_unix_getpid
, "getpid" },
2344 /* 21 */ { 0, "mount" },
2345 /* 22 */ { 0, "umount" },
2346 /* 23 */ { 0, "setuid" },
2347 /* 24 */ { do_unix_getuid
, "getuid" },
2348 /* 25 */ { 0, "stime" },
2349 /* 26 */ { 0, "ptrace" },
2350 /* 27 */ { 0, "alarm" },
2351 /* 28 */ { 0, "fstat" },
2352 /* 29 */ { 0, "pause" },
2353 /* 30 */ { 0, "utime" },
2354 /* 31 */ { 0, "stty" },
2355 /* 32 */ { 0, "gtty" },
2356 /* 33 */ { 0, "access" },
2357 /* 34 */ { 0, "nice" },
2358 /* 35 */ { 0, "ftime" },
2359 /* 36 */ { 0, "sync" },
2360 /* 37 */ { 0, "kill" },
2361 /* 38 */ { 0, "rename" },
2362 /* 39 */ { do_unix_mkdir
, "mkdir" },
2363 /* 40 */ { do_unix_rmdir
, "rmdir" },
2364 /* 41 */ { do_unix_dup
, "dup" },
2365 /* 42 */ { 0, "pipe" },
2366 /* 43 */ { 0, "times" },
2367 /* 44 */ { 0, "prof" },
2368 /* 45 */ { do_unix_break
, "brk" },
2369 /* 46 */ { 0, "setgid" },
2370 /* 47 */ { do_unix_getgid
, "getgid" },
2371 /* 48 */ { 0, "signal" },
2372 /* 49 */ { do_unix_geteuid
, "geteuid" },
2373 /* 50 */ { do_unix_getegid
, "getegid" },
2374 /* 51 */ { 0, "acct" },
2375 /* 52 */ { 0, "phys" },
2376 /* 53 */ { 0, "lock" },
2377 /* 54 */ { do_linux_ioctl
, "ioctl" },
2378 /* 55 */ { 0, "fcntl" },
2379 /* 56 */ { 0, "mpx" },
2380 /* 57 */ { 0, "setpgid" },
2381 /* 58 */ { 0, "ulimit" },
2382 /* 59 */ { 0, "olduname" },
2383 /* 60 */ { do_unix_umask
, "umask" },
2384 /* 61 */ { 0, "chroot" },
2385 /* 62 */ { 0, "ustat" },
2386 /* 63 */ { do_unix_dup2
, "dup2" },
2387 /* 64 */ { do_unix_getppid
, "getppid" },
2388 /* 65 */ { 0, "getpgrp" },
2389 /* 66 */ { 0, "setsid" },
2390 /* 67 */ { 0, "sigaction" },
2391 /* 68 */ { 0, "sgetmask" },
2392 /* 69 */ { 0, "ssetmask" },
2393 /* 70 */ { 0, "setreuid" },
2394 /* 71 */ { 0, "setregid" },
2395 /* 72 */ { 0, "sigsuspend" },
2396 /* 73 */ { 0, "sigpending" },
2397 /* 74 */ { 0, "sethostname" },
2398 /* 75 */ { 0, "setrlimit" },
2399 /* 76 */ { 0, "getrlimit" },
2400 /* 77 */ { do_unix_getrusage
, "getrusage" },
2401 /* 78 */ { do_unix_gettimeofday
, "gettimeofday" },
2402 /* 79 */ { 0, "settimeofday" },
2403 /* 80 */ { 0, "getgroups" },
2404 /* 81 */ { 0, "setgroups" },
2405 /* 82 */ { 0, "select" },
2406 /* 83 */ { do_unix_symlink
, "symlink" },
2407 /* 84 */ { 0, "lstat" },
2408 /* 85 */ { 0, "readlink" },
2409 /* 86 */ { 0, "uselib" },
2410 /* 87 */ { 0, "swapon" },
2411 /* 88 */ { 0, "reboot" },
2412 /* 89 */ { 0, "readdir" },
2413 /* 90 */ { 0, "mmap" },
2414 /* 91 */ { 0, "munmap" },
2415 /* 92 */ { 0, "truncate" },
2416 /* 93 */ { 0, "ftruncate" },
2417 /* 94 */ { 0, "fchmod" },
2418 /* 95 */ { 0, "fchown" },
2419 /* 96 */ { 0, "getpriority" },
2420 /* 97 */ { 0, "setpriority" },
2421 /* 98 */ { 0, "profil" },
2422 /* 99 */ { 0, "statfs" },
2423 /* 100 */ { 0, "fstatfs" },
2424 /* 101 */ { 0, "ioperm" },
2425 /* 102 */ { 0, "socketcall" },
2426 /* 103 */ { 0, "syslog" },
2427 /* 104 */ { 0, "setitimer" },
2428 /* 105 */ { 0, "getitimer" },
2429 /* 106 */ { do_linux_stat
, "newstat" },
2430 /* 107 */ { do_linux_lstat
, "newlstat" },
2431 /* 108 */ { do_linux_fstat
, "newfstat" },
2432 /* 109 */ { 0, "uname" },
2433 /* 110 */ { 0, "iopl" },
2434 /* 111 */ { 0, "vhangup" },
2435 /* 112 */ { 0, "idle" },
2436 /* 113 */ { 0, "vm86" },
2437 /* 114 */ { 0, "wait4" },
2438 /* 115 */ { 0, "swapoff" },
2439 /* 116 */ { 0, "sysinfo" },
2440 /* 117 */ { 0, "ipc" },
2441 /* 118 */ { 0, "fsync" },
2442 /* 119 */ { 0, "sigreturn" },
2443 /* 120 */ { 0, "clone" },
2444 /* 121 */ { 0, "setdomainname" },
2445 /* 122 */ { 0, "newuname" },
2446 /* 123 */ { 0, "modify_ldt" },
2447 /* 124 */ { 0, "adjtimex" },
2448 /* 125 */ { 0, "mprotect" },
2449 /* 126 */ { 0, "sigprocmask" },
2450 /* 127 */ { 0, "create_module" },
2451 /* 128 */ { 0, "init_module" },
2452 /* 129 */ { 0, "delete_module" },
2453 /* 130 */ { 0, "get_kernel_syms" },
2454 /* 131 */ { 0, "quotactl" },
2455 /* 132 */ { 0, "getpgid" },
2456 /* 133 */ { 0, "fchdir" },
2457 /* 134 */ { 0, "bdflush" },
2458 /* 135 */ { 0, "sysfs" },
2459 /* 136 */ { 0, "personality" },
2460 /* 137 */ { 0, "afs_syscall" },
2461 /* 138 */ { 0, "setfsuid" },
2462 /* 139 */ { 0, "setfsgid" },
2463 /* 140 */ { 0, "llseek" },
2464 /* 141 */ { 0, "getdents" },
2465 /* 142 */ { 0, "newselect" },
2466 /* 143 */ { 0, "flock" },
2467 /* 144 */ { 0, "msync" },
2468 /* 145 */ { 0, "readv" },
2469 /* 146 */ { 0, "writev" },
2470 /* 147 */ { 0, "getsid" },
2471 /* 148 */ { 0, "fdatasync" },
2472 /* 149 */ { 0, "sysctl" },
2473 /* 150 */ { 0, "mlock" },
2474 /* 151 */ { 0, "munlock" },
2475 /* 152 */ { 0, "mlockall" },
2476 /* 153 */ { 0, "munlockall" },
2477 /* 154 */ { 0, "sched_setparam" },
2478 /* 155 */ { 0, "sched_getparam" },
2479 /* 156 */ { 0, "sched_setscheduler" },
2480 /* 157 */ { 0, "sched_getscheduler" },
2481 /* 158 */ { 0, "sched_yield" },
2482 /* 159 */ { 0, "sched_get_priority_max" },
2483 /* 160 */ { 0, "sched_get_priority_min" },
2484 /* 161 */ { 0, "sched_rr_get_interval" },
2487 static char *(linux_error_names
[]) = {
2524 /* 36 */ "ENAMETOOLONG",
2527 /* 39 */ "ENOTEMPTY",
2533 /* 45 */ "EL2NSYNC",
2546 /* 58 */ "EDEADLOCK",
2560 /* 72 */ "EMULTIHOP",
2563 /* 75 */ "EOVERFLOW",
2564 /* 76 */ "ENOTUNIQ",
2571 /* 83 */ "ELIBEXEC",
2573 /* 85 */ "ERESTART",
2574 /* 86 */ "ESTRPIPE",
2576 /* 88 */ "ENOTSOCK",
2577 /* 89 */ "EDESTADDRREQ",
2578 /* 90 */ "EMSGSIZE",
2579 /* 91 */ "EPROTOTYPE",
2580 /* 92 */ "ENOPROTOOPT",
2581 /* 93 */ "EPROTONOSUPPORT",
2582 /* 94 */ "ESOCKTNOSUPPORT",
2583 /* 95 */ "EOPNOTSUPP",
2584 /* 96 */ "EPFNOSUPPORT",
2585 /* 97 */ "EAFNOSUPPORT",
2586 /* 98 */ "EADDRINUSE",
2587 /* 99 */ "EADDRNOTAVAIL",
2588 /* 100 */ "ENETDOWN",
2589 /* 101 */ "ENETUNREACH",
2590 /* 102 */ "ENETRESET",
2591 /* 103 */ "ECONNABORTED",
2592 /* 104 */ "ECONNRESET",
2593 /* 105 */ "ENOBUFS",
2594 /* 106 */ "EISCONN",
2595 /* 107 */ "ENOTCONN",
2596 /* 108 */ "ESHUTDOWN",
2597 /* 109 */ "ETOOMANYREFS",
2598 /* 110 */ "ETIMEDOUT",
2599 /* 111 */ "ECONNREFUSED",
2600 /* 112 */ "EHOSTDOWN",
2601 /* 113 */ "EHOSTUNREACH",
2602 /* 114 */ "EALREADY",
2603 /* 115 */ "EINPROGRESS",
2605 /* 117 */ "EUCLEAN",
2606 /* 118 */ "ENOTNAM",
2607 /* 119 */ "ENAVAIL",
2609 /* 121 */ "EREMOTEIO",
2613 static char *(linux_signal_names
[]) = {
2631 /* 16 */ "SIGSTKFLT",
2641 /* 26 */ "SIGVTALRM",
2643 /* 28 */ "SIGWINCH",
2646 /* 31 */ "SIGUNUSED",
2649 static emul_syscall emul_linux_syscalls
= {
2651 sizeof(linux_descriptors
) / sizeof(linux_descriptors
[0]),
2653 sizeof(linux_error_names
) / sizeof(linux_error_names
[0]),
2655 sizeof(linux_signal_names
) / sizeof(linux_signal_names
[0]),
2659 /* Linux's os_emul interface, most are just passed on to the generic
2662 static os_emul_data
*
2663 emul_linux_create(device
*root
,
2667 /* check that this emulation is really for us */
2668 if (name
!= NULL
&& strcmp(name
, "linux") != 0)
2674 return emul_unix_create(root
, image
, "linux", &emul_linux_syscalls
);
2678 emul_linux_init(os_emul_data
*emul_data
,
2685 emul_linux_system_call(cpu
*processor
,
2687 os_emul_data
*emul_data
)
2689 emul_do_system_call(emul_data
,
2690 emul_data
->syscalls
,
2691 cpu_registers(processor
)->gpr
[0],
2692 3, /*r3 contains arg0*/
2697 const os_emul emul_linux
= {
2701 emul_linux_system_call
,
2702 0, /*instruction_call*/
2706 #endif /* _EMUL_UNIX_C_ */