import gdb-1999-10-18 snapshot
[deliverable/binutils-gdb.git] / sim / ppc / emul_unix.c
CommitLineData
c906108c
SS
1/* This file is part of the program psim.
2
3 Copyright (C) 1996-1998, Andrew Cagney <cagney@highland.com.au>
4
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.
9
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.
14
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.
18
19 */
20
21
22#ifndef _EMUL_UNIX_C_
23#define _EMUL_UNIX_C_
24
25
26/* Note: this module is called via a table. There is no benefit in
27 making it inline */
28
29#include "emul_generic.h"
30#include "emul_unix.h"
31
32#ifdef HAVE_STRING_H
33#include <string.h>
34#else
35#ifdef HAVE_STRINGS_H
36#include <strings.h>
37#endif
38#endif
39
40#ifdef HAVE_SYS_TYPES_H
41#include <sys/types.h>
42#endif
43
44#ifdef HAVE_SYS_TYPES_H
45#include <sys/stat.h>
46#else
47#undef HAVE_STAT
48#undef HAVE_LSTAT
49#undef HAVE_FSTAT
50#endif
51
52#include <stdio.h>
53#include <signal.h>
54#include <errno.h>
55
56#ifdef HAVE_FCNTL_H
57#include <fcntl.h>
58#endif
59
60#ifdef HAVE_SYS_PARAM_H
61#include <sys/param.h>
62#endif
63
64#ifdef HAVE_SYS_TIME_H
65#include <sys/time.h>
66#endif
67
68#ifndef HAVE_TERMIOS_STRUCTURE
69#undef HAVE_SYS_TERMIOS_H
70#undef HAVE_TCGETATTR
71#else
72#ifndef HAVE_SYS_TERMIOS_H
73#undef HAVE_TERMIOS_STRUCTURE
74#endif
75#endif
76
77#ifdef HAVE_TERMIOS_STRUCTURE
78#include <sys/termios.h>
79
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
82 time. */
83#undef HAVE_TERMIO_STRUCTURE
84#undef TCGETA
85#undef termio
86#define termio termios
87#endif
88
89#ifndef HAVE_TERMIO_STRUCTURE
90#undef HAVE_SYS_TERMIO_H
91#else
92#ifndef HAVE_SYS_TERMIO_H
93#undef HAVE_TERMIO_STRUCTURE
94#endif
95#endif
96
97#ifdef HAVE_TERMIO_STRUCTURE
98#include <sys/termio.h>
99#endif
100
101#ifdef HAVE_GETRUSAGE
102#ifndef HAVE_SYS_RESOURCE_H
103#undef HAVE_GETRUSAGE
104#endif
105#endif
106
107#ifdef HAVE_GETRUSAGE
108#include <sys/resource.h>
109int getrusage();
110#endif
111
112#if HAVE_DIRENT_H
113# include <dirent.h>
114# define NAMLEN(dirent) strlen((dirent)->d_name)
115#else
116# define dirent direct
117# define NAMLEN(dirent) (dirent)->d_namlen
118# if HAVE_SYS_NDIR_H
119# include <sys/ndir.h>
120# endif
121# if HAVE_SYS_DIR_H
122# include <sys/dir.h>
123# endif
124# if HAVE_NDIR_H
125# include <ndir.h>
126# endif
127#endif
128
129#ifdef HAVE_UNISTD_H
130#undef MAXPATHLEN /* sys/param.h might define this also */
131#include <unistd.h>
132#endif
133
134#ifdef HAVE_STDLIB_H
135#include <stdlib.h>
136#endif
137
138#if defined(BSD) && !defined(errno) && (BSD < 199306) /* here BSD as just a bug */
139extern int errno;
140#endif
141
142#ifndef STATIC_INLINE_EMUL_UNIX
143#define STATIC_INLINE_EMUL_UNIX STATIC_INLINE
144#endif
145
146#ifndef PATH_MAX
147#define PATH_MAX 1024
148#endif
149
150#ifndef EINVAL
151#define EINVAL -1
152#endif
153
154/* UNIX's idea of what is needed to implement emulations */
155
156struct _os_emul_data {
157 device *vm;
158 emul_syscall *syscalls;
159};
160
161\f
162/* Emulation of simple UNIX system calls that are common on all systems. */
163
164/* Structures that are common agmonst the UNIX varients */
165struct unix_timeval {
166 signed32 tv_sec; /* seconds */
167 signed32 tv_usec; /* microseconds */
168};
169
170struct unix_timezone {
171 signed32 tz_minuteswest; /* minutes west of Greenwich */
172 signed32 tz_dsttime; /* type of dst correction */
173};
174
175#define UNIX_RUSAGE_SELF 0
176#define UNIX_RUSAGE_CHILDREN (-1)
177#define UNIX_RUSAGE_BOTH (-2) /* sys_wait4() uses this */
178
179struct unix_rusage {
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 " */
196};
197
198
199static void
200do_unix_exit(os_emul_data *emul,
201 unsigned call,
202 const int arg0,
203 cpu *processor,
204 unsigned_word cia)
205{
206 int status = (int)cpu_registers(processor)->gpr[arg0];
207 if (WITH_TRACE && ppc_trace[trace_os_emul])
208 printf_filtered ("%d)\n", status);
209
210 cpu_halt(processor, cia, was_exited, status);
211}
212
213
214static void
215do_unix_read(os_emul_data *emul,
216 unsigned call,
217 const int arg0,
218 cpu *processor,
219 unsigned_word cia)
220{
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];
225 int status;
226
227 if (WITH_TRACE && ppc_trace[trace_os_emul])
228 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
229
230 /* get a tempoary bufer */
231 scratch_buffer = zalloc(nbytes);
232
233 /* check if buffer exists by reading it */
234 emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia);
235
236 /* read */
237 status = read (d, scratch_buffer, nbytes);
238
239 emul_write_status(processor, status, errno);
240 if (status > 0)
241 emul_write_buffer(scratch_buffer, buf, status, processor, cia);
242
243 zfree(scratch_buffer);
244}
245
246
247static void
248do_unix_write(os_emul_data *emul,
249 unsigned call,
250 const int arg0,
251 cpu *processor,
252 unsigned_word cia)
253{
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];
258 int status;
259
260 if (WITH_TRACE && ppc_trace[trace_os_emul])
261 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
262
263 /* get a tempoary bufer */
264 scratch_buffer = zalloc(nbytes); /* FIXME - nbytes == 0 */
265
266 /* copy in */
267 emul_read_buffer(scratch_buffer, buf, nbytes,
268 processor, cia);
269
270 /* write */
271 status = write(d, scratch_buffer, nbytes);
272 emul_write_status(processor, status, errno);
273 zfree(scratch_buffer);
274
275 flush_stdoutput();
276}
277
278
279static void
280do_unix_open(os_emul_data *emul,
281 unsigned call,
282 const int arg0,
283 cpu *processor,
284 unsigned_word cia)
285{
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];
291 int status;
292
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);
295
296 status = open(path, flags, mode);
297 emul_write_status(processor, status, errno);
298}
299
300
301static void
302do_unix_close(os_emul_data *emul,
303 unsigned call,
304 const int arg0,
305 cpu *processor,
306 unsigned_word cia)
307{
308 int d = (int)cpu_registers(processor)->gpr[arg0];
309 int status;
310
311 if (WITH_TRACE && ppc_trace[trace_os_emul])
312 printf_filtered ("%d", d);
313
314 status = close(d);
315 emul_write_status(processor, status, errno);
316}
317
318
319static void
320do_unix_break(os_emul_data *emul,
321 unsigned call,
322 const int arg0,
323 cpu *processor,
324 unsigned_word cia)
325{
326 /* just pass this onto the `vm' device */
327 unsigned_word new_break = cpu_registers(processor)->gpr[arg0];
328 int status;
329
330 if (WITH_TRACE && ppc_trace[trace_os_emul])
331 printf_filtered ("0x%lx", (long)cpu_registers(processor)->gpr[arg0]);
332
333 status = device_ioctl(emul->vm,
334 processor,
335 cia,
336 device_ioctl_break,
337 new_break); /*ioctl-data*/
338
339 emul_write_status(processor, 0, status);
340}
341
342#ifndef HAVE_ACCESS
343#define do_unix_access 0
344#else
345static void
346do_unix_access(os_emul_data *emul,
347 unsigned call,
348 const int arg0,
349 cpu *processor,
350 unsigned_word cia)
351{
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];
356 int status;
357
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);
360
361 status = access(path, mode);
362 emul_write_status(processor, status, errno);
363}
364#endif
365
366#ifndef HAVE_GETPID
367#define do_unix_getpid 0
368#else
369static void
370do_unix_getpid(os_emul_data *emul,
371 unsigned call,
372 const int arg0,
373 cpu *processor,
374 unsigned_word cia)
375{
376 pid_t status = getpid();
377 emul_write_status(processor, (int)status, errno);
378}
379#endif
380
381#ifndef HAVE_GETPPID
382#define do_unix_getppid 0
383#else
384static void
385do_unix_getppid(os_emul_data *emul,
386 unsigned call,
387 const int arg0,
388 cpu *processor,
389 unsigned_word cia)
390{
391 pid_t status = getppid();
392 emul_write_status(processor, (int)status, errno);
393}
394#endif
395
396#if !defined(HAVE_GETPID) || !defined(HAVE_GETPPID)
397#define do_unix_getpid2 0
398#else
399static void
400do_unix_getpid2(os_emul_data *emul,
401 unsigned call,
402 const int arg0,
403 cpu *processor,
404 unsigned_word cia)
405{
406 int pid = (int)getpid();
407 int ppid = (int)getppid();
408 emul_write2_status(processor, pid, ppid, errno);
409}
410#endif
411
412#if !defined(HAVE_GETUID) || !defined(HAVE_GETEUID)
413#define do_unix_getuid2 0
414#else
415static void
416do_unix_getuid2(os_emul_data *emul,
417 unsigned call,
418 const int arg0,
419 cpu *processor,
420 unsigned_word cia)
421{
422 uid_t uid = getuid();
423 uid_t euid = geteuid();
424 emul_write2_status(processor, (int)uid, (int)euid, errno);
425}
426#endif
427
428#ifndef HAVE_GETUID
429#define do_unix_getuid 0
430#else
431static void
432do_unix_getuid(os_emul_data *emul,
433 unsigned call,
434 const int arg0,
435 cpu *processor,
436 unsigned_word cia)
437{
438 uid_t status = getuid();
439 emul_write_status(processor, (int)status, errno);
440}
441#endif
442
443#ifndef HAVE_GETEUID
444#define do_unix_geteuid 0
445#else
446static void
447do_unix_geteuid(os_emul_data *emul,
448 unsigned call,
449 const int arg0,
450 cpu *processor,
451 unsigned_word cia)
452{
453 uid_t status = geteuid();
454 emul_write_status(processor, (int)status, errno);
455}
456#endif
457
458#if 0
459#ifndef HAVE_KILL
460#define do_unix_kill 0
461#else
462static void
463do_unix_kill(os_emul_data *emul,
464 unsigned call,
465 const int arg0,
466 cpu *processor,
467 unsigned_word cia)
468{
469 pid_t pid = cpu_registers(processor)->gpr[arg0];
470 int sig = cpu_registers(processor)->gpr[arg0+1];
471
472 if (WITH_TRACE && ppc_trace[trace_os_emul])
473 printf_filtered ("%d, %d", (int)pid, sig);
474
475 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
476 (long)cia);
477
478 cpu_halt(processor, cia, was_signalled, sig);
479}
480#endif
481#endif
482
483#ifndef HAVE_DUP
484#define do_unix_dup 0
485#else
486static void
487do_unix_dup(os_emul_data *emul,
488 unsigned call,
489 const int arg0,
490 cpu *processor,
491 unsigned_word cia)
492{
493 int oldd = cpu_registers(processor)->gpr[arg0];
494 int status = dup(oldd);
495 int err = errno;
496
497 if (WITH_TRACE && ppc_trace[trace_os_emul])
498 printf_filtered ("%d", oldd);
499
500 emul_write_status(processor, status, err);
501}
502#endif
503
504#ifndef HAVE_DUP2
505#define do_unix_dup2 0
506#else
507static void
508do_unix_dup2(os_emul_data *emul,
509 unsigned call,
510 const int arg0,
511 cpu *processor,
512 unsigned_word cia)
513{
514 int oldd = cpu_registers(processor)->gpr[arg0];
515 int newd = cpu_registers(processor)->gpr[arg0+1];
516 int status = dup2(oldd, newd);
517 int err = errno;
518
519 if (WITH_TRACE && ppc_trace[trace_os_emul])
520 printf_filtered ("%d, %d", oldd, newd);
521
522 emul_write_status(processor, status, err);
523}
524#endif
525
526#ifndef HAVE_LSEEK
527#define do_unix_lseek 0
528#else
529static void
530do_unix_lseek(os_emul_data *emul,
531 unsigned call,
532 const int arg0,
533 cpu *processor,
534 unsigned_word cia)
535{
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];
539 off_t status;
540
541 if (WITH_TRACE && ppc_trace[trace_os_emul])
542 printf_filtered ("%d %ld %d", fildes, (long)offset, whence);
543
544 status = lseek(fildes, offset, whence);
545 emul_write_status(processor, (int)status, errno);
546}
547#endif
548
549
550#if !defined(HAVE_GETGID) || !defined(HAVE_GETEGID)
551#define do_unix_getgid2 0
552#else
553static void
554do_unix_getgid2(os_emul_data *emul,
555 unsigned call,
556 const int arg0,
557 cpu *processor,
558 unsigned_word cia)
559{
560 gid_t gid = getgid();
561 gid_t egid = getegid();
562 emul_write2_status(processor, (int)gid, (int)egid, errno);
563}
564#endif
565
566#ifndef HAVE_GETGID
567#define do_unix_getgid 0
568#else
569static void
570do_unix_getgid(os_emul_data *emul,
571 unsigned call,
572 const int arg0,
573 cpu *processor,
574 unsigned_word cia)
575{
576 gid_t status = getgid();
577 emul_write_status(processor, (int)status, errno);
578}
579#endif
580
581#ifndef HAVE_GETEGID
582#define do_unix_getegid 0
583#else
584static void
585do_unix_getegid(os_emul_data *emul,
586 unsigned call,
587 const int arg0,
588 cpu *processor,
589 unsigned_word cia)
590{
591 gid_t status = getegid();
592 emul_write_status(processor, (int)status, errno);
593}
594#endif
595
596#ifndef HAVE_UMASK
597#define do_unix_umask 0
598#else
599static void
600do_unix_umask(os_emul_data *emul,
601 unsigned call,
602 const int arg0,
603 cpu *processor,
604 unsigned_word cia)
605{
606 mode_t mask = (mode_t)cpu_registers(processor)->gpr[arg0];
607 int status = umask(mask);
608
609 if (WITH_TRACE && ppc_trace[trace_os_emul])
610 printf_filtered ("0%o", (unsigned int)mask);
611
612 emul_write_status(processor, status, errno);
613}
614#endif
615
616#ifndef HAVE_CHDIR
617#define do_unix_chdir 0
618#else
619static void
620do_unix_chdir(os_emul_data *emul,
621 unsigned call,
622 const int arg0,
623 cpu *processor,
624 unsigned_word cia)
625{
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);
629 int status;
630
631 if (WITH_TRACE && ppc_trace[trace_os_emul])
632 printf_filtered ("0x%lx [%s]", (long)path_addr, path);
633
634 status = chdir(path);
635 emul_write_status(processor, status, errno);
636}
637#endif
638
639#ifndef HAVE_LINK
640#define do_unix_link 0
641#else
642static void
643do_unix_link(os_emul_data *emul,
644 unsigned call,
645 const int arg0,
646 cpu *processor,
647 unsigned_word cia)
648{
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);
655 int status;
656
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);
659
660 status = link(path1, path2);
661 emul_write_status(processor, status, errno);
662}
663#endif
664
665#ifndef HAVE_SYMLINK
666#define do_unix_symlink 0
667#else
668static void
669do_unix_symlink(os_emul_data *emul,
670 unsigned call,
671 const int arg0,
672 cpu *processor,
673 unsigned_word cia)
674{
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);
681 int status;
682
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);
685
686 status = symlink(path1, path2);
687 emul_write_status(processor, status, errno);
688}
689#endif
690
691#ifndef HAVE_UNLINK
692#define do_unix_unlink 0
693#else
694static void
695do_unix_unlink(os_emul_data *emul,
696 unsigned call,
697 const int arg0,
698 cpu *processor,
699 unsigned_word cia)
700{
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);
704 int status;
705
706 if (WITH_TRACE && ppc_trace[trace_os_emul])
707 printf_filtered ("0x%lx [%s]", (long)path_addr, path);
708
709 status = unlink(path);
710 emul_write_status(processor, status, errno);
711}
712#endif
713
714#ifndef HAVE_MKDIR
715#define do_unix_mkdir 0
716#else
717static void
718do_unix_mkdir(os_emul_data *emul,
719 unsigned call,
720 const int arg0,
721 cpu *processor,
722 unsigned_word cia)
723{
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];
728 int status;
729
730 if (WITH_TRACE && ppc_trace[trace_os_emul])
731 printf_filtered ("0x%lx [%s], 0%3o", (long)path_addr, path, mode);
732
733 status = mkdir(path, mode);
734 emul_write_status(processor, status, errno);
735}
736#endif
737
738#ifndef HAVE_RMDIR
739#define do_unix_rmdir 0
740#else
741static void
742do_unix_rmdir(os_emul_data *emul,
743 unsigned call,
744 const int arg0,
745 cpu *processor,
746 unsigned_word cia)
747{
748 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
749 char path_buf[PATH_MAX];
750 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
751 int status;
752
753 if (WITH_TRACE && ppc_trace[trace_os_emul])
754 printf_filtered ("0x%lx [%s]", (long)path_addr, path);
755
756 status = rmdir(path);
757 emul_write_status(processor, status, errno);
758}
759#endif
760
761#ifndef HAVE_TIME
762#define do_unix_time 0
763#else
764static void
765do_unix_time(os_emul_data *emul,
766 unsigned call,
767 const int arg0,
768 cpu *processor,
769 unsigned_word cia)
770{
771 unsigned_word tp = cpu_registers(processor)->gpr[arg0];
772 time_t now = time ((time_t *)0);
773 unsigned_word status = H2T_4(now);
774
775 if (WITH_TRACE && ppc_trace[trace_os_emul])
776 printf_filtered ("0x%lx", (long)tp);
777
778 emul_write_status(processor, (int)status, errno);
779
780 if (tp)
781 emul_write_buffer(&status, tp, sizeof(status), processor, cia);
782}
783#endif
784
785#if !defined(HAVE_GETTIMEOFDAY) || !defined(HAVE_SYS_TIME_H)
786#define do_unix_gettimeofday 0
787#else
788static void
789do_unix_gettimeofday(os_emul_data *emul,
790 unsigned call,
791 const int arg0,
792 cpu *processor,
793 unsigned_word cia)
794{
795 unsigned_word tv = cpu_registers(processor)->gpr[arg0];
796 unsigned_word tz = cpu_registers(processor)->gpr[arg0+1];
797 struct unix_timeval target_timeval;
798 struct timeval host_timeval;
799 struct unix_timezone target_timezone;
800 struct timezone host_timezone;
801 int status;
802
803 if (WITH_TRACE && ppc_trace[trace_os_emul])
804 printf_filtered ("0x%lx, 0x%lx", (long)tv, (long)tz);
805
806 /* Just in case the system doesn't set the timezone structure */
807 host_timezone.tz_minuteswest = 0;
808 host_timezone.tz_dsttime = 0;
809
810 status = gettimeofday(&host_timeval, &host_timezone);
811 if (status >= 0) {
812 if (tv) {
813 target_timeval.tv_sec = H2T_4(host_timeval.tv_sec);
814 target_timeval.tv_usec = H2T_4(host_timeval.tv_usec);
815 emul_write_buffer((void *) &target_timeval, tv, sizeof(target_timeval), processor, cia);
816 }
817
818 if (tz) {
819 target_timezone.tz_minuteswest = H2T_4(host_timezone.tz_minuteswest);
820 target_timezone.tz_dsttime = H2T_4(host_timezone.tz_dsttime);
821 emul_write_buffer((void *) &target_timezone, tv, sizeof(target_timezone), processor, cia);
822 }
823 }
824
825 emul_write_status(processor, (int)status, errno);
826}
827#endif
828
829
830#ifndef HAVE_GETRUSAGE
831#define do_unix_getrusage 0
832#else
833static void
834do_unix_getrusage(os_emul_data *emul,
835 unsigned call,
836 const int arg0,
837 cpu *processor,
838 unsigned_word cia)
839{
840 signed_word who = (signed_word)cpu_registers(processor)->gpr[arg0];
841 unsigned_word usage = cpu_registers(processor)->gpr[arg0+1];
842 struct rusage host_rusage, host_rusage2;
843 struct unix_rusage target_rusage;
844 int status;
845
846 if (WITH_TRACE && ppc_trace[trace_os_emul])
847 printf_filtered ("%ld, 0x%lx", (long)who, (long)usage);
848
849 switch (who) {
850 default:
851 status = -1;
852 errno = EINVAL;
853 break;
854
855 case UNIX_RUSAGE_SELF:
856 status = getrusage(RUSAGE_SELF, &host_rusage);
857 break;
858
859 case UNIX_RUSAGE_CHILDREN:
860 status = getrusage(RUSAGE_CHILDREN, &host_rusage);
861 break;
862
863 case UNIX_RUSAGE_BOTH:
864 status = getrusage(RUSAGE_SELF, &host_rusage);
865 if (status >= 0) {
866 status = getrusage(RUSAGE_CHILDREN, &host_rusage2);
867 if (status >= 0) {
868 host_rusage.ru_utime.tv_sec += host_rusage2.ru_utime.tv_sec;
869 host_rusage.ru_utime.tv_usec += host_rusage2.ru_utime.tv_usec;
870 host_rusage.ru_stime.tv_sec += host_rusage2.ru_stime.tv_sec;
871 host_rusage.ru_stime.tv_usec += host_rusage2.ru_stime.tv_usec;
872 host_rusage.ru_maxrss += host_rusage2.ru_maxrss;
873 host_rusage.ru_ixrss += host_rusage2.ru_ixrss;
874 host_rusage.ru_idrss += host_rusage2.ru_idrss;
875 host_rusage.ru_isrss += host_rusage2.ru_isrss;
876 host_rusage.ru_minflt += host_rusage2.ru_minflt;
877 host_rusage.ru_majflt += host_rusage2.ru_majflt;
878 host_rusage.ru_nswap += host_rusage2.ru_nswap;
879 host_rusage.ru_inblock += host_rusage2.ru_inblock;
880 host_rusage.ru_oublock += host_rusage2.ru_oublock;
881 host_rusage.ru_msgsnd += host_rusage2.ru_msgsnd;
882 host_rusage.ru_msgrcv += host_rusage2.ru_msgrcv;
883 host_rusage.ru_nsignals += host_rusage2.ru_nsignals;
884 host_rusage.ru_nvcsw += host_rusage2.ru_nvcsw;
885 host_rusage.ru_nivcsw += host_rusage2.ru_nivcsw;
886 }
887 }
888 }
889
890 if (status >= 0) {
891 target_rusage.ru_utime.tv_sec = H2T_4(host_rusage2.ru_utime.tv_sec);
892 target_rusage.ru_utime.tv_usec = H2T_4(host_rusage2.ru_utime.tv_usec);
893 target_rusage.ru_stime.tv_sec = H2T_4(host_rusage2.ru_stime.tv_sec);
894 target_rusage.ru_stime.tv_usec = H2T_4(host_rusage2.ru_stime.tv_usec);
895 target_rusage.ru_maxrss = H2T_4(host_rusage2.ru_maxrss);
896 target_rusage.ru_ixrss = H2T_4(host_rusage2.ru_ixrss);
897 target_rusage.ru_idrss = H2T_4(host_rusage2.ru_idrss);
898 target_rusage.ru_isrss = H2T_4(host_rusage2.ru_isrss);
899 target_rusage.ru_minflt = H2T_4(host_rusage2.ru_minflt);
900 target_rusage.ru_majflt = H2T_4(host_rusage2.ru_majflt);
901 target_rusage.ru_nswap = H2T_4(host_rusage2.ru_nswap);
902 target_rusage.ru_inblock = H2T_4(host_rusage2.ru_inblock);
903 target_rusage.ru_oublock = H2T_4(host_rusage2.ru_oublock);
904 target_rusage.ru_msgsnd = H2T_4(host_rusage2.ru_msgsnd);
905 target_rusage.ru_msgrcv = H2T_4(host_rusage2.ru_msgrcv);
906 target_rusage.ru_nsignals = H2T_4(host_rusage2.ru_nsignals);
907 target_rusage.ru_nvcsw = H2T_4(host_rusage2.ru_nvcsw);
908 target_rusage.ru_nivcsw = H2T_4(host_rusage2.ru_nivcsw);
909 emul_write_buffer((void *) &target_rusage, usage, sizeof(target_rusage), processor, cia);
910 }
911
912 emul_write_status(processor, status, errno);
913}
914#endif
915
916
917static void
918do_unix_nop(os_emul_data *emul,
919 unsigned call,
920 const int arg0,
921 cpu *processor,
922 unsigned_word cia)
923{
924 if (WITH_TRACE && ppc_trace[trace_os_emul])
925 printf_filtered ("0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
926 (long)cpu_registers(processor)->gpr[arg0],
927 (long)cpu_registers(processor)->gpr[arg0+1],
928 (long)cpu_registers(processor)->gpr[arg0+2],
929 (long)cpu_registers(processor)->gpr[arg0+3],
930 (long)cpu_registers(processor)->gpr[arg0+4],
931 (long)cpu_registers(processor)->gpr[arg0+5]);
932
933 emul_write_status(processor, 0, errno);
934}
935
936\f
937/* Common code for initializing the system call stuff */
938
939static os_emul_data *
940emul_unix_create(device *root,
941 bfd *image,
942 const char *name,
943 emul_syscall *syscall)
944{
945 unsigned_word top_of_stack;
946 unsigned stack_size;
947 int elf_binary;
948 os_emul_data *data;
949 device *vm;
950
951 /* merge any emulation specific entries into the device tree */
952
953 /* establish a few defaults */
954 if (image->xvec->flavour == bfd_target_elf_flavour) {
955 elf_binary = 1;
956 top_of_stack = 0xe0000000;
957 stack_size = 0x00100000;
958 }
959 else {
960 elf_binary = 0;
961 top_of_stack = 0x20000000;
962 stack_size = 0x00100000;
963 }
964
965 /* options */
966 emul_add_tree_options(root, image, name,
967 (WITH_ENVIRONMENT == USER_ENVIRONMENT
968 ? "user" : "virtual"),
969 0 /*oea-interrupt-prefix*/);
970
971 /* virtual memory - handles growth of stack/heap */
972 vm = tree_parse(root, "/openprom/vm@0x%lx",
973 (unsigned long)(top_of_stack - stack_size));
974 tree_parse(vm, "./stack-base 0x%lx",
975 (unsigned long)(top_of_stack - stack_size));
976 tree_parse(vm, "./nr-bytes 0x%x", stack_size);
977
978 tree_parse(root, "/openprom/vm/map-binary/file-name %s",
979 bfd_get_filename(image));
980
981 /* finish the init */
982 tree_parse(root, "/openprom/init/register/pc 0x%lx",
983 (unsigned long)bfd_get_start_address(image));
984 tree_parse(root, "/openprom/init/register/sp 0x%lx",
985 (unsigned long)top_of_stack);
986 tree_parse(root, "/openprom/init/register/msr 0x%x",
987 ((tree_find_boolean_property(root, "/options/little-endian?")
988 ? msr_little_endian_mode
989 : 0)
990 | (tree_find_boolean_property(root, "/openprom/options/floating-point?")
991 ? (msr_floating_point_available
992 | msr_floating_point_exception_mode_0
993 | msr_floating_point_exception_mode_1)
994 : 0)));
995 tree_parse(root, "/openprom/init/stack/stack-type %s",
996 (elf_binary ? "ppc-elf" : "ppc-xcoff"));
997
998 /* finally our emulation data */
999 data = ZALLOC(os_emul_data);
1000 data->vm = vm;
1001 data->syscalls = syscall;
1002 return data;
1003}
1004
1005\f
1006/* EMULATION
1007
1008 Solaris - Emulation of user programs for Solaris/PPC
1009
1010 DESCRIPTION
1011
1012 */
1013
1014
1015/* Solaris specific implementation */
1016
1017typedef signed32 solaris_uid_t;
1018typedef signed32 solaris_gid_t;
1019typedef signed32 solaris_off_t;
1020typedef signed32 solaris_pid_t;
1021typedef signed32 solaris_time_t;
1022typedef unsigned32 solaris_dev_t;
1023typedef unsigned32 solaris_ino_t;
1024typedef unsigned32 solaris_mode_t;
1025typedef unsigned32 solaris_nlink_t;
1026
1027#ifdef HAVE_SYS_STAT_H
1028#define SOLARIS_ST_FSTYPSZ 16 /* array size for file system type name */
1029
1030struct solaris_stat {
1031 solaris_dev_t st_dev;
1032 signed32 st_pad1[3]; /* reserved for network id */
1033 solaris_ino_t st_ino;
1034 solaris_mode_t st_mode;
1035 solaris_nlink_t st_nlink;
1036 solaris_uid_t st_uid;
1037 solaris_gid_t st_gid;
1038 solaris_dev_t st_rdev;
1039 signed32 st_pad2[2];
1040 solaris_off_t st_size;
1041 signed32 st_pad3; /* future off_t expansion */
1042 struct unix_timeval st_atim;
1043 struct unix_timeval st_mtim;
1044 struct unix_timeval st_ctim;
1045 signed32 st_blksize;
1046 signed32 st_blocks;
1047 char st_fstype[SOLARIS_ST_FSTYPSZ];
1048 signed32 st_pad4[8]; /* expansion area */
1049};
1050
1051/* Convert from host stat structure to solaris stat structure */
1052STATIC_INLINE_EMUL_UNIX void
1053convert_to_solaris_stat(unsigned_word addr,
1054 struct stat *host,
1055 cpu *processor,
1056 unsigned_word cia)
1057{
1058 struct solaris_stat target;
1059 int i;
1060
1061 target.st_dev = H2T_4(host->st_dev);
1062 target.st_ino = H2T_4(host->st_ino);
1063 target.st_mode = H2T_4(host->st_mode);
1064 target.st_nlink = H2T_4(host->st_nlink);
1065 target.st_uid = H2T_4(host->st_uid);
1066 target.st_gid = H2T_4(host->st_gid);
1067 target.st_size = H2T_4(host->st_size);
1068
1069#ifdef HAVE_ST_RDEV
1070 target.st_rdev = H2T_4(host->st_rdev);
1071#else
1072 target.st_rdev = 0;
1073#endif
1074
1075#ifdef HAVE_ST_BLKSIZE
1076 target.st_blksize = H2T_4(host->st_blksize);
1077#else
1078 target.st_blksize = 0;
1079#endif
1080
1081#ifdef HAVE_ST_BLOCKS
1082 target.st_blocks = H2T_4(host->st_blocks);
1083#else
1084 target.st_blocks = 0;
1085#endif
1086
1087 target.st_atim.tv_sec = H2T_4(host->st_atime);
1088 target.st_atim.tv_usec = 0;
1089
1090 target.st_ctim.tv_sec = H2T_4(host->st_ctime);
1091 target.st_ctim.tv_usec = 0;
1092
1093 target.st_mtim.tv_sec = H2T_4(host->st_mtime);
1094 target.st_mtim.tv_usec = 0;
1095
1096 for (i = 0; i < sizeof (target.st_pad1) / sizeof (target.st_pad1[0]); i++)
1097 target.st_pad1[i] = 0;
1098
1099 for (i = 0; i < sizeof (target.st_pad2) / sizeof (target.st_pad2[0]); i++)
1100 target.st_pad2[i] = 0;
1101
1102 target.st_pad3 = 0;
1103
1104 for (i = 0; i < sizeof (target.st_pad4) / sizeof (target.st_pad4[0]); i++)
1105 target.st_pad4[i] = 0;
1106
1107 /* For now, just punt and always say it is a ufs file */
1108 strcpy (target.st_fstype, "ufs");
1109
1110 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
1111}
1112#endif /* HAVE_SYS_STAT_H */
1113
1114#ifndef HAVE_STAT
1115#define do_solaris_stat 0
1116#else
1117static void
1118do_solaris_stat(os_emul_data *emul,
1119 unsigned call,
1120 const int arg0,
1121 cpu *processor,
1122 unsigned_word cia)
1123{
1124 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
1125 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
1126 char path_buf[PATH_MAX];
1127 struct stat buf;
1128 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
1129 int status;
1130
1131 if (WITH_TRACE && ppc_trace[trace_os_emul])
1132 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
1133
1134 status = stat (path, &buf);
1135 if (status == 0)
1136 convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
1137
1138 emul_write_status(processor, status, errno);
1139}
1140#endif
1141
1142#ifndef HAVE_LSTAT
1143#define do_solaris_lstat 0
1144#else
1145static void
1146do_solaris_lstat(os_emul_data *emul,
1147 unsigned call,
1148 const int arg0,
1149 cpu *processor,
1150 unsigned_word cia)
1151{
1152 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
1153 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
1154 char path_buf[PATH_MAX];
1155 struct stat buf;
1156 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
1157 int status;
1158
1159 if (WITH_TRACE && ppc_trace[trace_os_emul])
1160 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
1161
1162 status = lstat (path, &buf);
1163 if (status == 0)
1164 convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
1165
1166 emul_write_status(processor, status, errno);
1167}
1168#endif
1169
1170#ifndef HAVE_FSTAT
1171#define do_solaris_fstat 0
1172#else
1173static void
1174do_solaris_fstat(os_emul_data *emul,
1175 unsigned call,
1176 const int arg0,
1177 cpu *processor,
1178 unsigned_word cia)
1179{
1180 int fildes = (int)cpu_registers(processor)->gpr[arg0];
1181 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
1182 struct stat buf;
1183 int status;
1184
1185 if (WITH_TRACE && ppc_trace[trace_os_emul])
1186 printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt);
1187
1188 status = fstat (fildes, &buf);
1189 if (status == 0)
1190 convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
1191
1192 emul_write_status(processor, status, errno);
1193}
1194#endif
1195
1196#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1197#define SOLARIS_TIOC ('T'<<8)
1198#define SOLARIS_NCC 8
1199#define SOLARIS_NCCS 19
1200
1201#define SOLARIS_VINTR 0
1202#define SOLARIS_VQUIT 1
1203#define SOLARIS_VERASE 2
1204#define SOLARIS_VKILL 3
1205#define SOLARIS_VEOF 4
1206#define SOLARIS_VEOL 5
1207#define SOLARIS_VEOL2 6
1208#define SOLARIS_VSWTCH 7
1209#define SOLARIS_VSTART 8
1210#define SOLARIS_VSTOP 9
1211#define SOLARIS_VSUSP 10
1212#define SOLARIS_VDSUSP 11
1213#define SOLARIS_VREPRINT 12
1214#define SOLARIS_VDISCARD 13
1215#define SOLARIS_VWERASE 14
1216#define SOLARIS_VLNEXT 15
1217#endif
1218
1219#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1220/* Convert to/from host termio structure */
1221
1222struct solaris_termio {
1223 unsigned16 c_iflag; /* input modes */
1224 unsigned16 c_oflag; /* output modes */
1225 unsigned16 c_cflag; /* control modes */
1226 unsigned16 c_lflag; /* line discipline modes */
1227 unsigned8 c_line; /* line discipline */
1228 unsigned8 c_cc[SOLARIS_NCC]; /* control chars */
1229};
1230
1231STATIC_INLINE_EMUL_UNIX void
1232convert_to_solaris_termio(unsigned_word addr,
1233 struct termio *host,
1234 cpu *processor,
1235 unsigned_word cia)
1236{
1237 struct solaris_termio target;
1238 int i;
1239
1240 target.c_iflag = H2T_2 (host->c_iflag);
1241 target.c_oflag = H2T_2 (host->c_oflag);
1242 target.c_cflag = H2T_2 (host->c_cflag);
1243 target.c_lflag = H2T_2 (host->c_lflag);
1244
1245#if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
1246 target.c_line = host->c_line;
1247#else
1248 target.c_line = 0;
1249#endif
1250
1251 for (i = 0; i < SOLARIS_NCC; i++)
1252 target.c_cc[i] = 0;
1253
1254#ifdef VINTR
1255 target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];
1256#endif
1257
1258#ifdef VQUIT
1259 target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];
1260#endif
1261
1262#ifdef VERASE
1263 target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];
1264#endif
1265
1266#ifdef VKILL
1267 target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];
1268#endif
1269
1270#ifdef VEOF
1271 target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];
1272#endif
1273
1274#ifdef VEOL
1275 target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];
1276#endif
1277
1278#ifdef VEOL2
1279 target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];
1280#endif
1281
1282#ifdef VSWTCH
1283 target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];
1284
1285#else
1286#ifdef VSWTC
1287 target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];
1288#endif
1289#endif
1290
1291 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
1292}
1293#endif /* HAVE_TERMIO_STRUCTURE || HAVE_TERMIOS_STRUCTURE */
1294
1295#ifdef HAVE_TERMIOS_STRUCTURE
1296/* Convert to/from host termios structure */
1297
1298typedef unsigned32 solaris_tcflag_t;
1299typedef unsigned8 solaris_cc_t;
1300typedef unsigned32 solaris_speed_t;
1301
1302struct solaris_termios {
1303 solaris_tcflag_t c_iflag;
1304 solaris_tcflag_t c_oflag;
1305 solaris_tcflag_t c_cflag;
1306 solaris_tcflag_t c_lflag;
1307 solaris_cc_t c_cc[SOLARIS_NCCS];
1308};
1309
1310STATIC_INLINE_EMUL_UNIX void
1311convert_to_solaris_termios(unsigned_word addr,
1312 struct termios *host,
1313 cpu *processor,
1314 unsigned_word cia)
1315{
1316 struct solaris_termios target;
1317 int i;
1318
1319 target.c_iflag = H2T_4 (host->c_iflag);
1320 target.c_oflag = H2T_4 (host->c_oflag);
1321 target.c_cflag = H2T_4 (host->c_cflag);
1322 target.c_lflag = H2T_4 (host->c_lflag);
1323
1324 for (i = 0; i < SOLARIS_NCCS; i++)
1325 target.c_cc[i] = 0;
1326
1327#ifdef VINTR
1328 target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];
1329#endif
1330
1331#ifdef VQUIT
1332 target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];
1333#endif
1334
1335#ifdef VERASE
1336 target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];
1337#endif
1338
1339#ifdef VKILL
1340 target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];
1341#endif
1342
1343#ifdef VEOF
1344 target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];
1345#endif
1346
1347#ifdef VEOL
1348 target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];
1349#endif
1350
1351#ifdef VEOL2
1352 target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];
1353#endif
1354
1355#ifdef VSWTCH
1356 target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];
1357
1358#else
1359#ifdef VSWTC
1360 target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];
1361#endif
1362#endif
1363
1364#ifdef VSTART
1365 target.c_cc[SOLARIS_VSTART] = host->c_cc[VSTART];
1366#endif
1367
1368#ifdef VSTOP
1369 target.c_cc[SOLARIS_VSTOP] = host->c_cc[VSTOP];
1370#endif
1371
1372#ifdef VSUSP
1373 target.c_cc[SOLARIS_VSUSP] = host->c_cc[VSUSP];
1374#endif
1375
1376#ifdef VDSUSP
1377 target.c_cc[SOLARIS_VDSUSP] = host->c_cc[VDSUSP];
1378#endif
1379
1380#ifdef VREPRINT
1381 target.c_cc[SOLARIS_VREPRINT] = host->c_cc[VREPRINT];
1382#endif
1383
1384#ifdef VDISCARD
1385 target.c_cc[SOLARIS_VDISCARD] = host->c_cc[VDISCARD];
1386#endif
1387
1388#ifdef VWERASE
1389 target.c_cc[SOLARIS_VWERASE] = host->c_cc[VWERASE];
1390#endif
1391
1392#ifdef VLNEXT
1393 target.c_cc[SOLARIS_VLNEXT] = host->c_cc[VLNEXT];
1394#endif
1395
1396 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
1397}
1398#endif /* HAVE_TERMIOS_STRUCTURE */
1399
1400#ifndef HAVE_IOCTL
1401#define do_solaris_ioctl 0
1402#else
1403static void
1404do_solaris_ioctl(os_emul_data *emul,
1405 unsigned call,
1406 const int arg0,
1407 cpu *processor,
1408 unsigned_word cia)
1409{
1410 int fildes = cpu_registers(processor)->gpr[arg0];
1411 unsigned request = cpu_registers(processor)->gpr[arg0+1];
1412 unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
1413 int status = 0;
1414 const char *name = "<unknown>";
1415
1416#ifdef HAVE_TERMIOS_STRUCTURE
1417 struct termios host_termio;
1418
1419#else
1420#ifdef HAVE_TERMIO_STRUCTURE
1421 struct termio host_termio;
1422#endif
1423#endif
1424
1425 switch (request)
1426 {
1427 case 0: /* make sure we have at least one case */
1428 default:
1429 status = -1;
1430 errno = EINVAL;
1431 break;
1432
1433#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
1434#if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
1435 case SOLARIS_TIOC | 1: /* TCGETA */
1436 name = "TCGETA";
1437#ifdef HAVE_TCGETATTR
1438 status = tcgetattr(fildes, &host_termio);
1439#elif defined(TCGETS)
1440 status = ioctl (fildes, TCGETS, &host_termio);
1441#else
1442 status = ioctl (fildes, TCGETA, &host_termio);
1443#endif
1444 if (status == 0)
1445 convert_to_solaris_termio (argp_addr, &host_termio, processor, cia);
1446 break;
1447#endif /* TCGETA */
1448#endif /* HAVE_TERMIO_STRUCTURE */
1449
1450#ifdef HAVE_TERMIOS_STRUCTURE
1451#if defined(TCGETS) || defined(HAVE_TCGETATTR)
1452 case SOLARIS_TIOC | 13: /* TCGETS */
1453 name = "TCGETS";
1454#ifdef HAVE_TCGETATTR
1455 status = tcgetattr(fildes, &host_termio);
1456#else
1457 status = ioctl (fildes, TCGETS, &host_termio);
1458#endif
1459 if (status == 0)
1460 convert_to_solaris_termios (argp_addr, &host_termio, processor, cia);
1461 break;
1462#endif /* TCGETS */
1463#endif /* HAVE_TERMIOS_STRUCTURE */
1464 }
1465
1466 emul_write_status(processor, status, errno);
1467
1468 if (WITH_TRACE && ppc_trace[trace_os_emul])
1469 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);
1470}
1471#endif /* HAVE_IOCTL */
1472
1473static emul_syscall_descriptor solaris_descriptors[] = {
1474 /* 0 */ { 0, "syscall" },
1475 /* 1 */ { do_unix_exit, "exit" },
1476 /* 2 */ { 0, "fork" },
1477 /* 3 */ { do_unix_read, "read" },
1478 /* 4 */ { do_unix_write, "write" },
1479 /* 5 */ { do_unix_open, "open" },
1480 /* 6 */ { do_unix_close, "close" },
1481 /* 7 */ { 0, "wait" },
1482 /* 8 */ { 0, "creat" },
1483 /* 9 */ { do_unix_link, "link" },
1484 /* 10 */ { do_unix_unlink, "unlink" },
1485 /* 11 */ { 0, "exec" },
1486 /* 12 */ { do_unix_chdir, "chdir" },
1487 /* 13 */ { do_unix_time, "time" },
1488 /* 14 */ { 0, "mknod" },
1489 /* 15 */ { 0, "chmod" },
1490 /* 16 */ { 0, "chown" },
1491 /* 17 */ { do_unix_break, "brk" },
1492 /* 18 */ { do_solaris_stat, "stat" },
1493 /* 19 */ { do_unix_lseek, "lseek" },
1494 /* 20 */ { do_unix_getpid2, "getpid" },
1495 /* 21 */ { 0, "mount" },
1496 /* 22 */ { 0, "umount" },
1497 /* 23 */ { 0, "setuid" },
1498 /* 24 */ { do_unix_getuid2, "getuid" },
1499 /* 25 */ { 0, "stime" },
1500 /* 26 */ { 0, "ptrace" },
1501 /* 27 */ { 0, "alarm" },
1502 /* 28 */ { do_solaris_fstat, "fstat" },
1503 /* 29 */ { 0, "pause" },
1504 /* 30 */ { 0, "utime" },
1505 /* 31 */ { 0, "stty" },
1506 /* 32 */ { 0, "gtty" },
1507 /* 33 */ { do_unix_access, "access" },
1508 /* 34 */ { 0, "nice" },
1509 /* 35 */ { 0, "statfs" },
1510 /* 36 */ { 0, "sync" },
1511 /* 37 */ { 0, "kill" },
1512 /* 38 */ { 0, "fstatfs" },
1513 /* 39 */ { 0, "pgrpsys" },
1514 /* 40 */ { 0, "xenix" },
1515 /* 41 */ { do_unix_dup, "dup" },
1516 /* 42 */ { 0, "pipe" },
1517 /* 43 */ { 0, "times" },
1518 /* 44 */ { 0, "profil" },
1519 /* 45 */ { 0, "plock" },
1520 /* 46 */ { 0, "setgid" },
1521 /* 47 */ { do_unix_getgid2, "getgid" },
1522 /* 48 */ { 0, "signal" },
1523 /* 49 */ { 0, "msgsys" },
1524 /* 50 */ { 0, "syssun" },
1525 /* 51 */ { 0, "acct" },
1526 /* 52 */ { 0, "shmsys" },
1527 /* 53 */ { 0, "semsys" },
1528 /* 54 */ { do_solaris_ioctl, "ioctl" },
1529 /* 55 */ { 0, "uadmin" },
1530 /* 56 */ { 0, 0 /* reserved for exch */ },
1531 /* 57 */ { 0, "utssys" },
1532 /* 58 */ { 0, "fdsync" },
1533 /* 59 */ { 0, "execve" },
1534 /* 60 */ { do_unix_umask, "umask" },
1535 /* 61 */ { 0, "chroot" },
1536 /* 62 */ { 0, "fcntl" },
1537 /* 63 */ { 0, "ulimit" },
1538 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1539 /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
1540 /* 65 */ { 0, 0 /* reserved for UNIX PC */ },
1541 /* 66 */ { 0, 0 /* reserved for UNIX PC */ },
1542 /* 67 */ { 0, 0 /* reserved for UNIX PC */ },
1543 /* 68 */ { 0, 0 /* reserved for UNIX PC */ },
1544 /* 69 */ { 0, 0 /* reserved for UNIX PC */ },
1545 /* 70 */ { 0, 0 /* was advfs */ },
1546 /* 71 */ { 0, 0 /* was unadvfs */ },
1547 /* 72 */ { 0, 0 /* was rmount */ },
1548 /* 73 */ { 0, 0 /* was rumount */ },
1549 /* 74 */ { 0, 0 /* was rfstart */ },
1550 /* 75 */ { 0, 0 /* was sigret */ },
1551 /* 76 */ { 0, 0 /* was rdebug */ },
1552 /* 77 */ { 0, 0 /* was rfstop */ },
1553 /* 78 */ { 0, 0 /* was rfsys */ },
1554 /* 79 */ { do_unix_rmdir, "rmdir" },
1555 /* 80 */ { do_unix_mkdir, "mkdir" },
1556 /* 81 */ { 0, "getdents" },
1557 /* 82 */ { 0, 0 /* was libattach */ },
1558 /* 83 */ { 0, 0 /* was libdetach */ },
1559 /* 84 */ { 0, "sysfs" },
1560 /* 85 */ { 0, "getmsg" },
1561 /* 86 */ { 0, "putmsg" },
1562 /* 87 */ { 0, "poll" },
1563 /* 88 */ { do_solaris_lstat, "lstat" },
1564 /* 89 */ { do_unix_symlink, "symlink" },
1565 /* 90 */ { 0, "readlink" },
1566 /* 91 */ { 0, "setgroups" },
1567 /* 92 */ { 0, "getgroups" },
1568 /* 93 */ { 0, "fchmod" },
1569 /* 94 */ { 0, "fchown" },
1570 /* 95 */ { 0, "sigprocmask" },
1571 /* 96 */ { 0, "sigsuspend" },
1572 /* 97 */ { do_unix_nop, "sigaltstack" },
1573 /* 98 */ { do_unix_nop, "sigaction" },
1574 /* 99 */ { 0, "sigpending" },
1575 /* 100 */ { 0, "context" },
1576 /* 101 */ { 0, "evsys" },
1577 /* 102 */ { 0, "evtrapret" },
1578 /* 103 */ { 0, "statvfs" },
1579 /* 104 */ { 0, "fstatvfs" },
1580 /* 105 */ { 0, 0 /* reserved */ },
1581 /* 106 */ { 0, "nfssys" },
1582 /* 107 */ { 0, "waitsys" },
1583 /* 108 */ { 0, "sigsendsys" },
1584 /* 109 */ { 0, "hrtsys" },
1585 /* 110 */ { 0, "acancel" },
1586 /* 111 */ { 0, "async" },
1587 /* 112 */ { 0, "priocntlsys" },
1588 /* 113 */ { 0, "pathconf" },
1589 /* 114 */ { 0, "mincore" },
1590 /* 115 */ { 0, "mmap" },
1591 /* 116 */ { 0, "mprotect" },
1592 /* 117 */ { 0, "munmap" },
1593 /* 118 */ { 0, "fpathconf" },
1594 /* 119 */ { 0, "vfork" },
1595 /* 120 */ { 0, "fchdir" },
1596 /* 121 */ { 0, "readv" },
1597 /* 122 */ { 0, "writev" },
1598 /* 123 */ { 0, "xstat" },
1599 /* 124 */ { 0, "lxstat" },
1600 /* 125 */ { 0, "fxstat" },
1601 /* 126 */ { 0, "xmknod" },
1602 /* 127 */ { 0, "clocal" },
1603 /* 128 */ { 0, "setrlimit" },
1604 /* 129 */ { 0, "getrlimit" },
1605 /* 130 */ { 0, "lchown" },
1606 /* 131 */ { 0, "memcntl" },
1607 /* 132 */ { 0, "getpmsg" },
1608 /* 133 */ { 0, "putpmsg" },
1609 /* 134 */ { 0, "rename" },
1610 /* 135 */ { 0, "uname" },
1611 /* 136 */ { 0, "setegid" },
1612 /* 137 */ { 0, "sysconfig" },
1613 /* 138 */ { 0, "adjtime" },
1614 /* 139 */ { 0, "systeminfo" },
1615 /* 140 */ { 0, 0 /* reserved */ },
1616 /* 141 */ { 0, "seteuid" },
1617 /* 142 */ { 0, "vtrace" },
1618 /* 143 */ { 0, "fork1" },
1619 /* 144 */ { 0, "sigtimedwait" },
1620 /* 145 */ { 0, "lwp_info" },
1621 /* 146 */ { 0, "yield" },
1622 /* 147 */ { 0, "lwp_sema_wait" },
1623 /* 148 */ { 0, "lwp_sema_post" },
1624 /* 149 */ { 0, 0 /* reserved */ },
1625 /* 150 */ { 0, 0 /* reserved */ },
1626 /* 151 */ { 0, 0 /* reserved */ },
1627 /* 152 */ { 0, "modctl" },
1628 /* 153 */ { 0, "fchroot" },
1629 /* 154 */ { 0, "utimes" },
1630 /* 155 */ { 0, "vhangup" },
1631 /* 156 */ { do_unix_gettimeofday, "gettimeofday" },
1632 /* 157 */ { 0, "getitimer" },
1633 /* 158 */ { 0, "setitimer" },
1634 /* 159 */ { 0, "lwp_create" },
1635 /* 160 */ { 0, "lwp_exit" },
1636 /* 161 */ { 0, "lwp_suspend" },
1637 /* 162 */ { 0, "lwp_continue" },
1638 /* 163 */ { 0, "lwp_kill" },
1639 /* 164 */ { 0, "lwp_self" },
1640 /* 165 */ { 0, "lwp_setprivate" },
1641 /* 166 */ { 0, "lwp_getprivate" },
1642 /* 167 */ { 0, "lwp_wait" },
1643 /* 168 */ { 0, "lwp_mutex_unlock" },
1644 /* 169 */ { 0, "lwp_mutex_lock" },
1645 /* 170 */ { 0, "lwp_cond_wait" },
1646 /* 171 */ { 0, "lwp_cond_signal" },
1647 /* 172 */ { 0, "lwp_cond_broadcast" },
1648 /* 173 */ { 0, "pread" },
1649 /* 174 */ { 0, "pwrite" },
1650 /* 175 */ { 0, "llseek" },
1651 /* 176 */ { 0, "inst_sync" },
1652 /* 177 */ { 0, 0 /* reserved */ },
1653 /* 178 */ { 0, "kaio" },
1654 /* 179 */ { 0, 0 /* reserved */ },
1655 /* 180 */ { 0, 0 /* reserved */ },
1656 /* 181 */ { 0, 0 /* reserved */ },
1657 /* 182 */ { 0, 0 /* reserved */ },
1658 /* 183 */ { 0, 0 /* reserved */ },
1659 /* 184 */ { 0, "tsolsys" },
1660 /* 185 */ { 0, "acl" },
1661 /* 186 */ { 0, "auditsys" },
1662 /* 187 */ { 0, "processor_bind" },
1663 /* 188 */ { 0, "processor_info" },
1664 /* 189 */ { 0, "p_online" },
1665 /* 190 */ { 0, "sigqueue" },
1666 /* 191 */ { 0, "clock_gettime" },
1667 /* 192 */ { 0, "clock_settime" },
1668 /* 193 */ { 0, "clock_getres" },
1669 /* 194 */ { 0, "timer_create" },
1670 /* 195 */ { 0, "timer_delete" },
1671 /* 196 */ { 0, "timer_settime" },
1672 /* 197 */ { 0, "timer_gettime" },
1673 /* 198 */ { 0, "timer_getoverrun" },
1674 /* 199 */ { 0, "nanosleep" },
1675 /* 200 */ { 0, "facl" },
1676 /* 201 */ { 0, "door" },
1677 /* 202 */ { 0, "setreuid" },
1678 /* 203 */ { 0, "setregid" },
1679 /* 204 */ { 0, "install_utrap" },
1680 /* 205 */ { 0, 0 /* reserved */ },
1681 /* 206 */ { 0, 0 /* reserved */ },
1682 /* 207 */ { 0, 0 /* reserved */ },
1683 /* 208 */ { 0, 0 /* reserved */ },
1684 /* 209 */ { 0, 0 /* reserved */ },
1685 /* 210 */ { 0, "signotifywait" },
1686 /* 211 */ { 0, "lwp_sigredirect" },
1687 /* 212 */ { 0, "lwp_alarm" },
1688};
1689
1690static char *(solaris_error_names[]) = {
1691 /* 0 */ "ESUCCESS",
1692 /* 1 */ "EPERM",
1693 /* 2 */ "ENOENT",
1694 /* 3 */ "ESRCH",
1695 /* 4 */ "EINTR",
1696 /* 5 */ "EIO",
1697 /* 6 */ "ENXIO",
1698 /* 7 */ "E2BIG",
1699 /* 8 */ "ENOEXEC",
1700 /* 9 */ "EBADF",
1701 /* 10 */ "ECHILD",
1702 /* 11 */ "EAGAIN",
1703 /* 12 */ "ENOMEM",
1704 /* 13 */ "EACCES",
1705 /* 14 */ "EFAULT",
1706 /* 15 */ "ENOTBLK",
1707 /* 16 */ "EBUSY",
1708 /* 17 */ "EEXIST",
1709 /* 18 */ "EXDEV",
1710 /* 19 */ "ENODEV",
1711 /* 20 */ "ENOTDIR",
1712 /* 21 */ "EISDIR",
1713 /* 22 */ "EINVAL",
1714 /* 23 */ "ENFILE",
1715 /* 24 */ "EMFILE",
1716 /* 25 */ "ENOTTY",
1717 /* 26 */ "ETXTBSY",
1718 /* 27 */ "EFBIG",
1719 /* 28 */ "ENOSPC",
1720 /* 29 */ "ESPIPE",
1721 /* 30 */ "EROFS",
1722 /* 31 */ "EMLINK",
1723 /* 32 */ "EPIPE",
1724 /* 33 */ "EDOM",
1725 /* 34 */ "ERANGE",
1726 /* 35 */ "ENOMSG",
1727 /* 36 */ "EIDRM",
1728 /* 37 */ "ECHRNG",
1729 /* 38 */ "EL2NSYNC",
1730 /* 39 */ "EL3HLT",
1731 /* 40 */ "EL3RST",
1732 /* 41 */ "ELNRNG",
1733 /* 42 */ "EUNATCH",
1734 /* 43 */ "ENOCSI",
1735 /* 44 */ "EL2HLT",
1736 /* 45 */ "EDEADLK",
1737 /* 46 */ "ENOLCK",
1738 /* 47 */ "ECANCELED",
1739 /* 48 */ "ENOTSUP",
1740 /* 49 */ "EDQUOT",
1741 /* 50 */ "EBADE",
1742 /* 51 */ "EBADR",
1743 /* 52 */ "EXFULL",
1744 /* 53 */ "ENOANO",
1745 /* 54 */ "EBADRQC",
1746 /* 55 */ "EBADSLT",
1747 /* 56 */ "EDEADLOCK",
1748 /* 57 */ "EBFONT",
1749 /* 58 */ "Error code 58",
1750 /* 59 */ "Error code 59",
1751 /* 60 */ "ENOSTR",
1752 /* 61 */ "ENODATA",
1753 /* 62 */ "ETIME",
1754 /* 63 */ "ENOSR",
1755 /* 64 */ "ENONET",
1756 /* 65 */ "ENOPKG",
1757 /* 66 */ "EREMOTE",
1758 /* 67 */ "ENOLINK",
1759 /* 68 */ "EADV",
1760 /* 69 */ "ESRMNT",
1761 /* 70 */ "ECOMM",
1762 /* 71 */ "EPROTO",
1763 /* 72 */ "Error code 72",
1764 /* 73 */ "Error code 73",
1765 /* 74 */ "EMULTIHOP",
1766 /* 75 */ "Error code 75",
1767 /* 76 */ "Error code 76",
1768 /* 77 */ "EBADMSG",
1769 /* 78 */ "ENAMETOOLONG",
1770 /* 79 */ "EOVERFLOW",
1771 /* 80 */ "ENOTUNIQ",
1772 /* 81 */ "EBADFD",
1773 /* 82 */ "EREMCHG",
1774 /* 83 */ "ELIBACC",
1775 /* 84 */ "ELIBBAD",
1776 /* 85 */ "ELIBSCN",
1777 /* 86 */ "ELIBMAX",
1778 /* 87 */ "ELIBEXEC",
1779 /* 88 */ "EILSEQ",
1780 /* 89 */ "ENOSYS",
1781 /* 90 */ "ELOOP",
1782 /* 91 */ "ERESTART",
1783 /* 92 */ "ESTRPIPE",
1784 /* 93 */ "ENOTEMPTY",
1785 /* 94 */ "EUSERS",
1786 /* 95 */ "ENOTSOCK",
1787 /* 96 */ "EDESTADDRREQ",
1788 /* 97 */ "EMSGSIZE",
1789 /* 98 */ "EPROTOTYPE",
1790 /* 99 */ "ENOPROTOOPT",
1791 /* 100 */ "Error code 100",
1792 /* 101 */ "Error code 101",
1793 /* 102 */ "Error code 102",
1794 /* 103 */ "Error code 103",
1795 /* 104 */ "Error code 104",
1796 /* 105 */ "Error code 105",
1797 /* 106 */ "Error code 106",
1798 /* 107 */ "Error code 107",
1799 /* 108 */ "Error code 108",
1800 /* 109 */ "Error code 109",
1801 /* 110 */ "Error code 110",
1802 /* 111 */ "Error code 111",
1803 /* 112 */ "Error code 112",
1804 /* 113 */ "Error code 113",
1805 /* 114 */ "Error code 114",
1806 /* 115 */ "Error code 115",
1807 /* 116 */ "Error code 116",
1808 /* 117 */ "Error code 117",
1809 /* 118 */ "Error code 118",
1810 /* 119 */ "Error code 119",
1811 /* 120 */ "EPROTONOSUPPORT",
1812 /* 121 */ "ESOCKTNOSUPPORT",
1813 /* 122 */ "EOPNOTSUPP",
1814 /* 123 */ "EPFNOSUPPORT",
1815 /* 124 */ "EAFNOSUPPORT",
1816 /* 125 */ "EADDRINUSE",
1817 /* 126 */ "EADDRNOTAVAIL",
1818 /* 127 */ "ENETDOWN",
1819 /* 128 */ "ENETUNREACH",
1820 /* 129 */ "ENETRESET",
1821 /* 130 */ "ECONNABORTED",
1822 /* 131 */ "ECONNRESET",
1823 /* 132 */ "ENOBUFS",
1824 /* 133 */ "EISCONN",
1825 /* 134 */ "ENOTCONN",
1826 /* 135 */ "Error code 135", /* XENIX has 135 - 142 */
1827 /* 136 */ "Error code 136",
1828 /* 137 */ "Error code 137",
1829 /* 138 */ "Error code 138",
1830 /* 139 */ "Error code 139",
1831 /* 140 */ "Error code 140",
1832 /* 141 */ "Error code 141",
1833 /* 142 */ "Error code 142",
1834 /* 143 */ "ESHUTDOWN",
1835 /* 144 */ "ETOOMANYREFS",
1836 /* 145 */ "ETIMEDOUT",
1837 /* 146 */ "ECONNREFUSED",
1838 /* 147 */ "EHOSTDOWN",
1839 /* 148 */ "EHOSTUNREACH",
1840 /* 149 */ "EALREADY",
1841 /* 150 */ "EINPROGRESS",
1842 /* 151 */ "ESTALE",
1843};
1844
1845static char *(solaris_signal_names[]) = {
1846 /* 0 */ 0,
1847 /* 1 */ "SIGHUP",
1848 /* 2 */ "SIGINT",
1849 /* 3 */ "SIGQUIT",
1850 /* 4 */ "SIGILL",
1851 /* 5 */ "SIGTRAP",
1852 /* 6 */ "SIGABRT",
1853 /* 7 */ "SIGEMT",
1854 /* 8 */ "SIGFPE",
1855 /* 9 */ "SIGKILL",
1856 /* 10 */ "SIGBUS",
1857 /* 11 */ "SIGSEGV",
1858 /* 12 */ "SIGSYS",
1859 /* 13 */ "SIGPIPE",
1860 /* 14 */ "SIGALRM",
1861 /* 15 */ "SIGTERM",
1862 /* 16 */ "SIGUSR1",
1863 /* 17 */ "SIGUSR2",
1864 /* 18 */ "SIGCHLD",
1865 /* 19 */ "SIGPWR",
1866 /* 20 */ "SIGWINCH",
1867 /* 21 */ "SIGURG",
1868 /* 22 */ "SIGPOLL",
1869 /* 23 */ "SIGSTOP",
1870 /* 24 */ "SIGTSTP",
1871 /* 25 */ "SIGCONT",
1872 /* 26 */ "SIGTTIN",
1873 /* 27 */ "SIGTTOU",
1874 /* 28 */ "SIGVTALRM",
1875 /* 29 */ "SIGPROF",
1876 /* 30 */ "SIGXCPU",
1877 /* 31 */ "SIGXFSZ",
1878 /* 32 */ "SIGWAITING",
1879 /* 33 */ "SIGLWP",
1880 /* 34 */ "SIGFREEZE",
1881 /* 35 */ "SIGTHAW",
1882 /* 36 */ "SIGCANCEL",
1883};
1884
1885static emul_syscall emul_solaris_syscalls = {
1886 solaris_descriptors,
1887 sizeof(solaris_descriptors) / sizeof(solaris_descriptors[0]),
1888 solaris_error_names,
1889 sizeof(solaris_error_names) / sizeof(solaris_error_names[0]),
1890 solaris_signal_names,
1891 sizeof(solaris_signal_names) / sizeof(solaris_signal_names[0]),
1892};
1893
1894
1895/* Solaris's os_emul interface, most are just passed on to the generic
1896 syscall stuff */
1897
1898static os_emul_data *
1899emul_solaris_create(device *root,
1900 bfd *image,
1901 const char *name)
1902{
1903 /* check that this emulation is really for us */
1904 if (name != NULL && strcmp(name, "solaris") != 0)
1905 return NULL;
1906
1907 if (image == NULL)
1908 return NULL;
1909
1910 return emul_unix_create(root, image, "solaris", &emul_solaris_syscalls);
1911}
1912
1913static void
1914emul_solaris_init(os_emul_data *emul_data,
1915 int nr_cpus)
1916{
1917 /* nothing yet */
1918}
1919
1920static void
1921emul_solaris_system_call(cpu *processor,
1922 unsigned_word cia,
1923 os_emul_data *emul_data)
1924{
1925 emul_do_system_call(emul_data,
1926 emul_data->syscalls,
1927 cpu_registers(processor)->gpr[0],
1928 3, /*r3 contains arg0*/
1929 processor,
1930 cia);
1931}
1932
1933const os_emul emul_solaris = {
1934 "solaris",
1935 emul_solaris_create,
1936 emul_solaris_init,
1937 emul_solaris_system_call,
1938 0, /*instruction_call*/
1939 0 /*data*/
1940};
1941
1942\f
1943/* EMULATION
1944
1945 Linux - Emulation of user programs for Linux/PPC
1946
1947 DESCRIPTION
1948
1949 */
1950
1951
1952/* Linux specific implementation */
1953
1954typedef unsigned32 linux_dev_t;
1955typedef unsigned32 linux_ino_t;
1956typedef unsigned32 linux_mode_t;
1957typedef unsigned16 linux_nlink_t;
1958typedef signed32 linux_off_t;
1959typedef signed32 linux_pid_t;
1960typedef unsigned32 linux_uid_t;
1961typedef unsigned32 linux_gid_t;
1962typedef unsigned32 linux_size_t;
1963typedef signed32 linux_ssize_t;
1964typedef signed32 linux_ptrdiff_t;
1965typedef signed32 linux_time_t;
1966typedef signed32 linux_clock_t;
1967typedef signed32 linux_daddr_t;
1968
1969#ifdef HAVE_SYS_STAT_H
1970/* For the PowerPC, don't both with the 'old' stat structure, since there
1971 should be no extant binaries with that structure. */
1972
1973struct linux_stat {
1974 linux_dev_t st_dev;
1975 linux_ino_t st_ino;
1976 linux_mode_t st_mode;
1977 linux_nlink_t st_nlink;
1978 linux_uid_t st_uid;
1979 linux_gid_t st_gid;
1980 linux_dev_t st_rdev;
1981 linux_off_t st_size;
1982 unsigned32 st_blksize;
1983 unsigned32 st_blocks;
1984 unsigned32 st_atimx; /* don't use st_{a,c,m}time, that might a macro */
1985 unsigned32 __unused1; /* defined by the host's stat.h */
1986 unsigned32 st_mtimx;
1987 unsigned32 __unused2;
1988 unsigned32 st_ctimx;
1989 unsigned32 __unused3;
1990 unsigned32 __unused4;
1991 unsigned32 __unused5;
1992};
1993
1994/* Convert from host stat structure to solaris stat structure */
1995STATIC_INLINE_EMUL_UNIX void
1996convert_to_linux_stat(unsigned_word addr,
1997 struct stat *host,
1998 cpu *processor,
1999 unsigned_word cia)
2000{
2001 struct linux_stat target;
2002
2003 target.st_dev = H2T_4(host->st_dev);
2004 target.st_ino = H2T_4(host->st_ino);
2005 target.st_mode = H2T_4(host->st_mode);
2006 target.st_nlink = H2T_2(host->st_nlink);
2007 target.st_uid = H2T_4(host->st_uid);
2008 target.st_gid = H2T_4(host->st_gid);
2009 target.st_size = H2T_4(host->st_size);
2010
2011#ifdef HAVE_ST_RDEV
2012 target.st_rdev = H2T_4(host->st_rdev);
2013#else
2014 target.st_rdev = 0;
2015#endif
2016
2017#ifdef HAVE_ST_BLKSIZE
2018 target.st_blksize = H2T_4(host->st_blksize);
2019#else
2020 target.st_blksize = 0;
2021#endif
2022
2023#ifdef HAVE_ST_BLOCKS
2024 target.st_blocks = H2T_4(host->st_blocks);
2025#else
2026 target.st_blocks = 0;
2027#endif
2028
2029 target.st_atimx = H2T_4(host->st_atime);
2030 target.st_ctimx = H2T_4(host->st_ctime);
2031 target.st_mtimx = H2T_4(host->st_mtime);
2032 target.__unused1 = 0;
2033 target.__unused2 = 0;
2034 target.__unused3 = 0;
2035 target.__unused4 = 0;
2036 target.__unused5 = 0;
2037
2038 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
2039}
2040#endif /* HAVE_SYS_STAT_H */
2041
2042#ifndef HAVE_STAT
2043#define do_linux_stat 0
2044#else
2045static void
2046do_linux_stat(os_emul_data *emul,
2047 unsigned call,
2048 const int arg0,
2049 cpu *processor,
2050 unsigned_word cia)
2051{
2052 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
2053 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
2054 char path_buf[PATH_MAX];
2055 struct stat buf;
2056 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
2057 int status;
2058
2059 if (WITH_TRACE && ppc_trace[trace_os_emul])
2060 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
2061
2062 status = stat (path, &buf);
2063 if (status == 0)
2064 convert_to_linux_stat (stat_pkt, &buf, processor, cia);
2065
2066 emul_write_status(processor, status, errno);
2067}
2068#endif
2069
2070#ifndef HAVE_LSTAT
2071#define do_linux_lstat 0
2072#else
2073static void
2074do_linux_lstat(os_emul_data *emul,
2075 unsigned call,
2076 const int arg0,
2077 cpu *processor,
2078 unsigned_word cia)
2079{
2080 unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
2081 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
2082 char path_buf[PATH_MAX];
2083 struct stat buf;
2084 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
2085 int status;
2086
2087 if (WITH_TRACE && ppc_trace[trace_os_emul])
2088 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
2089
2090 status = lstat (path, &buf);
2091 if (status == 0)
2092 convert_to_linux_stat (stat_pkt, &buf, processor, cia);
2093
2094 emul_write_status(processor, status, errno);
2095}
2096#endif
2097
2098#ifndef HAVE_FSTAT
2099#define do_linux_fstat 0
2100#else
2101static void
2102do_linux_fstat(os_emul_data *emul,
2103 unsigned call,
2104 const int arg0,
2105 cpu *processor,
2106 unsigned_word cia)
2107{
2108 int fildes = (int)cpu_registers(processor)->gpr[arg0];
2109 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
2110 struct stat buf;
2111 int status;
2112
2113 if (WITH_TRACE && ppc_trace[trace_os_emul])
2114 printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt);
2115
2116 status = fstat (fildes, &buf);
2117 if (status == 0)
2118 convert_to_linux_stat (stat_pkt, &buf, processor, cia);
2119
2120 emul_write_status(processor, status, errno);
2121}
2122#endif
2123
2124#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2125#define LINUX_NCC 10
2126#define LINUX_NCCS 19
2127
2128#define LINUX_VINTR 0
2129#define LINUX_VQUIT 1
2130#define LINUX_VERASE 2
2131#define LINUX_VKILL 3
2132#define LINUX_VEOF 4
2133#define LINUX_VMIN 5
2134#define LINUX_VEOL 6
2135#define LINUX_VTIME 7
2136#define LINUX_VEOL2 8
2137#define LINUX_VSWTC 9
2138#define LINUX_VWERASE 10
2139#define LINUX_VREPRINT 11
2140#define LINUX_VSUSP 12
2141#define LINUX_VSTART 13
2142#define LINUX_VSTOP 14
2143#define LINUX_VLNEXT 15
2144#define LINUX_VDISCARD 16
2145
2146#define LINUX_IOC_NRBITS 8
2147#define LINUX_IOC_TYPEBITS 8
2148#define LINUX_IOC_SIZEBITS 13
2149#define LINUX_IOC_DIRBITS 3
2150
2151#define LINUX_IOC_NRMASK ((1 << LINUX_IOC_NRBITS)-1)
2152#define LINUX_IOC_TYPEMASK ((1 << LINUX_IOC_TYPEBITS)-1)
2153#define LINUX_IOC_SIZEMASK ((1 << LINUX_IOC_SIZEBITS)-1)
2154#define LINUX_IOC_DIRMASK ((1 << LINUX_IOC_DIRBITS)-1)
2155
2156#define LINUX_IOC_NRSHIFT 0
2157#define LINUX_IOC_TYPESHIFT (LINUX_IOC_NRSHIFT+LINUX_IOC_NRBITS)
2158#define LINUX_IOC_SIZESHIFT (LINUX_IOC_TYPESHIFT+LINUX_IOC_TYPEBITS)
2159#define LINUX_IOC_DIRSHIFT (LINUX_IOC_SIZESHIFT+LINUX_IOC_SIZEBITS)
2160
2161/*
2162 * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
2163 * And this turns out useful to catch old ioctl numbers in header
2164 * files for us.
2165 */
2166#define LINUX_IOC_NONE 1U
2167#define LINUX_IOC_READ 2U
2168#define LINUX_IOC_WRITE 4U
2169
2170#define LINUX_IOC(dir,type,nr,size) \
2171 (((dir) << LINUX_IOC_DIRSHIFT) | \
2172 ((type) << LINUX_IOC_TYPESHIFT) | \
2173 ((nr) << LINUX_IOC_NRSHIFT) | \
2174 ((size) << LINUX_IOC_SIZESHIFT))
2175
2176/* used to create numbers */
2177#define LINUX_IO(type,nr) LINUX_IOC(LINUX_IOC_NONE,(type),(nr),0)
2178#define LINUX_IOR(type,nr,size) LINUX_IOC(LINUX_IOC_READ,(type),(nr),sizeof(size))
2179#define LINUX_IOW(type,nr,size) LINUX_IOC(LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2180#define LINUX_IOWR(type,nr,size) LINUX_IOC(LINUX_IOC_READ|LINUX_IOC_WRITE,(type),(nr),sizeof(size))
2181#endif
2182
2183#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2184/* Convert to/from host termio structure */
2185
2186struct linux_termio {
2187 unsigned16 c_iflag; /* input modes */
2188 unsigned16 c_oflag; /* output modes */
2189 unsigned16 c_cflag; /* control modes */
2190 unsigned16 c_lflag; /* line discipline modes */
2191 unsigned8 c_line; /* line discipline */
2192 unsigned8 c_cc[LINUX_NCC]; /* control chars */
2193};
2194
2195STATIC_INLINE_EMUL_UNIX void
2196convert_to_linux_termio(unsigned_word addr,
2197 struct termio *host,
2198 cpu *processor,
2199 unsigned_word cia)
2200{
2201 struct linux_termio target;
2202 int i;
2203
2204 target.c_iflag = H2T_2 (host->c_iflag);
2205 target.c_oflag = H2T_2 (host->c_oflag);
2206 target.c_cflag = H2T_2 (host->c_cflag);
2207 target.c_lflag = H2T_2 (host->c_lflag);
2208
2209#if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
2210 target.c_line = host->c_line;
2211#else
2212 target.c_line = 0;
2213#endif
2214
2215 for (i = 0; i < LINUX_NCC; i++)
2216 target.c_cc[i] = 0;
2217
2218#ifdef VINTR
2219 target.c_cc[LINUX_VINTR] = host->c_cc[VINTR];
2220#endif
2221
2222#ifdef VQUIT
2223 target.c_cc[LINUX_VQUIT] = host->c_cc[VQUIT];
2224#endif
2225
2226#ifdef VERASE
2227 target.c_cc[LINUX_VERASE] = host->c_cc[VERASE];
2228#endif
2229
2230#ifdef VKILL
2231 target.c_cc[LINUX_VKILL] = host->c_cc[VKILL];
2232#endif
2233
2234#ifdef VEOF
2235 target.c_cc[LINUX_VEOF] = host->c_cc[VEOF];
2236#endif
2237
2238#ifdef VMIN
2239 target.c_cc[LINUX_VMIN] = host->c_cc[VMIN];
2240#endif
2241
2242#ifdef VEOL
2243 target.c_cc[LINUX_VEOL] = host->c_cc[VEOL];
2244#endif
2245
2246#ifdef VTIME
2247 target.c_cc[LINUX_VTIME] = host->c_cc[VTIME];
2248#endif
2249
2250#ifdef VEOL2
2251 target.c_cc[LINUX_VEOL2] = host->c_cc[VEOL2];
2252#endif
2253
2254#ifdef VSWTC
2255 target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTC];
2256#endif
2257
2258#ifdef VSWTCH
2259 target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTCH];
2260#endif
2261
2262 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
2263}
2264#endif /* HAVE_TERMIO_STRUCTURE */
2265
2266#ifdef HAVE_TERMIOS_STRUCTURE
2267/* Convert to/from host termios structure */
2268
2269typedef unsigned32 linux_tcflag_t;
2270typedef unsigned8 linux_cc_t;
2271typedef unsigned32 linux_speed_t;
2272
2273struct linux_termios {
2274 linux_tcflag_t c_iflag;
2275 linux_tcflag_t c_oflag;
2276 linux_tcflag_t c_cflag;
2277 linux_tcflag_t c_lflag;
2278 linux_cc_t c_cc[LINUX_NCCS];
2279 linux_cc_t c_line;
2280 signed32 c_ispeed;
2281 signed32 c_ospeed;
2282};
2283
2284STATIC_INLINE_EMUL_UNIX void
2285convert_to_linux_termios(unsigned_word addr,
2286 struct termios *host,
2287 cpu *processor,
2288 unsigned_word cia)
2289{
2290 struct linux_termios target;
2291 int i;
2292
2293 target.c_iflag = H2T_4 (host->c_iflag);
2294 target.c_oflag = H2T_4 (host->c_oflag);
2295 target.c_cflag = H2T_4 (host->c_cflag);
2296 target.c_lflag = H2T_4 (host->c_lflag);
2297
2298 for (i = 0; i < LINUX_NCCS; i++)
2299 target.c_cc[i] = 0;
2300
2301#ifdef VINTR
2302 target.c_cc[LINUX_VINTR] = host->c_cc[VINTR];
2303#endif
2304
2305#ifdef VQUIT
2306 target.c_cc[LINUX_VQUIT] = host->c_cc[VQUIT];
2307#endif
2308
2309#ifdef VERASE
2310 target.c_cc[LINUX_VERASE] = host->c_cc[VERASE];
2311#endif
2312
2313#ifdef VKILL
2314 target.c_cc[LINUX_VKILL] = host->c_cc[VKILL];
2315#endif
2316
2317#ifdef VEOF
2318 target.c_cc[LINUX_VEOF] = host->c_cc[VEOF];
2319#endif
2320
2321#ifdef VEOL
2322 target.c_cc[LINUX_VEOL] = host->c_cc[VEOL];
2323#endif
2324
2325#ifdef VEOL2
2326 target.c_cc[LINUX_VEOL2] = host->c_cc[VEOL2];
2327#endif
2328
2329#ifdef VSWTCH
2330 target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTCH];
2331#endif
2332
2333#ifdef HAVE_TERMIOS_CLINE
2334 target.c_line = host->c_line;
2335#else
2336 target.c_line = 0;
2337#endif
2338
2339#ifdef HAVE_CFGETISPEED
2340 target.c_ispeed = cfgetispeed (host);
2341#else
2342 target.c_ispeed = 0;
2343#endif
2344
2345#ifdef HAVE_CFGETOSPEED
2346 target.c_ospeed = cfgetospeed (host);
2347#else
2348 target.c_ospeed = 0;
2349#endif
2350
2351 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
2352}
2353#endif /* HAVE_TERMIOS_STRUCTURE */
2354
2355#ifndef HAVE_IOCTL
2356#define do_linux_ioctl 0
2357#else
2358static void
2359do_linux_ioctl(os_emul_data *emul,
2360 unsigned call,
2361 const int arg0,
2362 cpu *processor,
2363 unsigned_word cia)
2364{
2365 int fildes = cpu_registers(processor)->gpr[arg0];
2366 unsigned request = cpu_registers(processor)->gpr[arg0+1];
2367 unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
2368 int status = 0;
2369 const char *name = "<unknown>";
2370
2371#ifdef HAVE_TERMIOS_STRUCTURE
2372 struct termios host_termio;
2373
2374#else
2375#ifdef HAVE_TERMIO_STRUCTURE
2376 struct termio host_termio;
2377#endif
2378#endif
2379
2380 switch (request)
2381 {
2382 case 0: /* make sure we have at least one case */
2383 default:
2384 status = -1;
2385 errno = EINVAL;
2386 break;
2387
2388#if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
2389#if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
2390 case LINUX_IOR('t', 23, struct linux_termio): /* TCGETA */
2391 name = "TCGETA";
2392#ifdef HAVE_TCGETATTR
2393 status = tcgetattr(fildes, &host_termio);
2394#elif defined(TCGETS)
2395 status = ioctl (fildes, TCGETS, &host_termio);
2396#else
2397 status = ioctl (fildes, TCGETA, &host_termio);
2398#endif
2399 if (status == 0)
2400 convert_to_linux_termio (argp_addr, &host_termio, processor, cia);
2401 break;
2402#endif /* TCGETA */
2403#endif /* HAVE_TERMIO_STRUCTURE */
2404
2405#ifdef HAVE_TERMIOS_STRUCTURE
2406#if defined(TCGETS) || defined(HAVE_TCGETATTR)
2407 case LINUX_IOR('t', 19, struct linux_termios): /* TCGETS */
2408 name = "TCGETS";
2409#ifdef HAVE_TCGETATTR
2410 status = tcgetattr(fildes, &host_termio);
2411#else
2412 status = ioctl (fildes, TCGETS, &host_termio);
2413#endif
2414 if (status == 0)
2415 convert_to_linux_termios (argp_addr, &host_termio, processor, cia);
2416 break;
2417#endif /* TCGETS */
2418#endif /* HAVE_TERMIOS_STRUCTURE */
2419 }
2420
2421 emul_write_status(processor, status, errno);
2422
2423 if (WITH_TRACE && ppc_trace[trace_os_emul])
2424 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);
2425}
2426#endif /* HAVE_IOCTL */
2427
2428static emul_syscall_descriptor linux_descriptors[] = {
2429 /* 0 */ { 0, "setup" },
2430 /* 1 */ { do_unix_exit, "exit" },
2431 /* 2 */ { 0, "fork" },
2432 /* 3 */ { do_unix_read, "read" },
2433 /* 4 */ { do_unix_write, "write" },
2434 /* 5 */ { do_unix_open, "open" },
2435 /* 6 */ { do_unix_close, "close" },
2436 /* 7 */ { 0, "waitpid" },
2437 /* 8 */ { 0, "creat" },
2438 /* 9 */ { do_unix_link, "link" },
2439 /* 10 */ { do_unix_unlink, "unlink" },
2440 /* 11 */ { 0, "execve" },
2441 /* 12 */ { do_unix_chdir, "chdir" },
2442 /* 13 */ { do_unix_time, "time" },
2443 /* 14 */ { 0, "mknod" },
2444 /* 15 */ { 0, "chmod" },
2445 /* 16 */ { 0, "chown" },
2446 /* 17 */ { 0, "break" },
2447 /* 18 */ { 0, "stat" },
2448 /* 19 */ { do_unix_lseek, "lseek" },
2449 /* 20 */ { do_unix_getpid, "getpid" },
2450 /* 21 */ { 0, "mount" },
2451 /* 22 */ { 0, "umount" },
2452 /* 23 */ { 0, "setuid" },
2453 /* 24 */ { do_unix_getuid, "getuid" },
2454 /* 25 */ { 0, "stime" },
2455 /* 26 */ { 0, "ptrace" },
2456 /* 27 */ { 0, "alarm" },
2457 /* 28 */ { 0, "fstat" },
2458 /* 29 */ { 0, "pause" },
2459 /* 30 */ { 0, "utime" },
2460 /* 31 */ { 0, "stty" },
2461 /* 32 */ { 0, "gtty" },
2462 /* 33 */ { do_unix_access, "access" },
2463 /* 34 */ { 0, "nice" },
2464 /* 35 */ { 0, "ftime" },
2465 /* 36 */ { 0, "sync" },
2466 /* 37 */ { 0, "kill" },
2467 /* 38 */ { 0, "rename" },
2468 /* 39 */ { do_unix_mkdir, "mkdir" },
2469 /* 40 */ { do_unix_rmdir, "rmdir" },
2470 /* 41 */ { do_unix_dup, "dup" },
2471 /* 42 */ { 0, "pipe" },
2472 /* 43 */ { 0, "times" },
2473 /* 44 */ { 0, "prof" },
2474 /* 45 */ { do_unix_break, "brk" },
2475 /* 46 */ { 0, "setgid" },
2476 /* 47 */ { do_unix_getgid, "getgid" },
2477 /* 48 */ { 0, "signal" },
2478 /* 49 */ { do_unix_geteuid, "geteuid" },
2479 /* 50 */ { do_unix_getegid, "getegid" },
2480 /* 51 */ { 0, "acct" },
2481 /* 52 */ { 0, "phys" },
2482 /* 53 */ { 0, "lock" },
2483 /* 54 */ { do_linux_ioctl, "ioctl" },
2484 /* 55 */ { 0, "fcntl" },
2485 /* 56 */ { 0, "mpx" },
2486 /* 57 */ { 0, "setpgid" },
2487 /* 58 */ { 0, "ulimit" },
2488 /* 59 */ { 0, "olduname" },
2489 /* 60 */ { do_unix_umask, "umask" },
2490 /* 61 */ { 0, "chroot" },
2491 /* 62 */ { 0, "ustat" },
2492 /* 63 */ { do_unix_dup2, "dup2" },
2493 /* 64 */ { do_unix_getppid, "getppid" },
2494 /* 65 */ { 0, "getpgrp" },
2495 /* 66 */ { 0, "setsid" },
2496 /* 67 */ { 0, "sigaction" },
2497 /* 68 */ { 0, "sgetmask" },
2498 /* 69 */ { 0, "ssetmask" },
2499 /* 70 */ { 0, "setreuid" },
2500 /* 71 */ { 0, "setregid" },
2501 /* 72 */ { 0, "sigsuspend" },
2502 /* 73 */ { 0, "sigpending" },
2503 /* 74 */ { 0, "sethostname" },
2504 /* 75 */ { 0, "setrlimit" },
2505 /* 76 */ { 0, "getrlimit" },
2506 /* 77 */ { do_unix_getrusage, "getrusage" },
2507 /* 78 */ { do_unix_gettimeofday, "gettimeofday" },
2508 /* 79 */ { 0, "settimeofday" },
2509 /* 80 */ { 0, "getgroups" },
2510 /* 81 */ { 0, "setgroups" },
2511 /* 82 */ { 0, "select" },
2512 /* 83 */ { do_unix_symlink, "symlink" },
2513 /* 84 */ { 0, "lstat" },
2514 /* 85 */ { 0, "readlink" },
2515 /* 86 */ { 0, "uselib" },
2516 /* 87 */ { 0, "swapon" },
2517 /* 88 */ { 0, "reboot" },
2518 /* 89 */ { 0, "readdir" },
2519 /* 90 */ { 0, "mmap" },
2520 /* 91 */ { 0, "munmap" },
2521 /* 92 */ { 0, "truncate" },
2522 /* 93 */ { 0, "ftruncate" },
2523 /* 94 */ { 0, "fchmod" },
2524 /* 95 */ { 0, "fchown" },
2525 /* 96 */ { 0, "getpriority" },
2526 /* 97 */ { 0, "setpriority" },
2527 /* 98 */ { 0, "profil" },
2528 /* 99 */ { 0, "statfs" },
2529 /* 100 */ { 0, "fstatfs" },
2530 /* 101 */ { 0, "ioperm" },
2531 /* 102 */ { 0, "socketcall" },
2532 /* 103 */ { 0, "syslog" },
2533 /* 104 */ { 0, "setitimer" },
2534 /* 105 */ { 0, "getitimer" },
2535 /* 106 */ { do_linux_stat, "newstat" },
2536 /* 107 */ { do_linux_lstat, "newlstat" },
2537 /* 108 */ { do_linux_fstat, "newfstat" },
2538 /* 109 */ { 0, "uname" },
2539 /* 110 */ { 0, "iopl" },
2540 /* 111 */ { 0, "vhangup" },
2541 /* 112 */ { 0, "idle" },
2542 /* 113 */ { 0, "vm86" },
2543 /* 114 */ { 0, "wait4" },
2544 /* 115 */ { 0, "swapoff" },
2545 /* 116 */ { 0, "sysinfo" },
2546 /* 117 */ { 0, "ipc" },
2547 /* 118 */ { 0, "fsync" },
2548 /* 119 */ { 0, "sigreturn" },
2549 /* 120 */ { 0, "clone" },
2550 /* 121 */ { 0, "setdomainname" },
2551 /* 122 */ { 0, "newuname" },
2552 /* 123 */ { 0, "modify_ldt" },
2553 /* 124 */ { 0, "adjtimex" },
2554 /* 125 */ { 0, "mprotect" },
2555 /* 126 */ { 0, "sigprocmask" },
2556 /* 127 */ { 0, "create_module" },
2557 /* 128 */ { 0, "init_module" },
2558 /* 129 */ { 0, "delete_module" },
2559 /* 130 */ { 0, "get_kernel_syms" },
2560 /* 131 */ { 0, "quotactl" },
2561 /* 132 */ { 0, "getpgid" },
2562 /* 133 */ { 0, "fchdir" },
2563 /* 134 */ { 0, "bdflush" },
2564 /* 135 */ { 0, "sysfs" },
2565 /* 136 */ { 0, "personality" },
2566 /* 137 */ { 0, "afs_syscall" },
2567 /* 138 */ { 0, "setfsuid" },
2568 /* 139 */ { 0, "setfsgid" },
2569 /* 140 */ { 0, "llseek" },
2570 /* 141 */ { 0, "getdents" },
2571 /* 142 */ { 0, "newselect" },
2572 /* 143 */ { 0, "flock" },
2573 /* 144 */ { 0, "msync" },
2574 /* 145 */ { 0, "readv" },
2575 /* 146 */ { 0, "writev" },
2576 /* 147 */ { 0, "getsid" },
2577 /* 148 */ { 0, "fdatasync" },
2578 /* 149 */ { 0, "sysctl" },
2579 /* 150 */ { 0, "mlock" },
2580 /* 151 */ { 0, "munlock" },
2581 /* 152 */ { 0, "mlockall" },
2582 /* 153 */ { 0, "munlockall" },
2583 /* 154 */ { 0, "sched_setparam" },
2584 /* 155 */ { 0, "sched_getparam" },
2585 /* 156 */ { 0, "sched_setscheduler" },
2586 /* 157 */ { 0, "sched_getscheduler" },
2587 /* 158 */ { 0, "sched_yield" },
2588 /* 159 */ { 0, "sched_get_priority_max" },
2589 /* 160 */ { 0, "sched_get_priority_min" },
2590 /* 161 */ { 0, "sched_rr_get_interval" },
2591};
2592
2593static char *(linux_error_names[]) = {
2594 /* 0 */ "ESUCCESS",
2595 /* 1 */ "EPERM",
2596 /* 2 */ "ENOENT",
2597 /* 3 */ "ESRCH",
2598 /* 4 */ "EINTR",
2599 /* 5 */ "EIO",
2600 /* 6 */ "ENXIO",
2601 /* 7 */ "E2BIG",
2602 /* 8 */ "ENOEXEC",
2603 /* 9 */ "EBADF",
2604 /* 10 */ "ECHILD",
2605 /* 11 */ "EAGAIN",
2606 /* 12 */ "ENOMEM",
2607 /* 13 */ "EACCES",
2608 /* 14 */ "EFAULT",
2609 /* 15 */ "ENOTBLK",
2610 /* 16 */ "EBUSY",
2611 /* 17 */ "EEXIST",
2612 /* 18 */ "EXDEV",
2613 /* 19 */ "ENODEV",
2614 /* 20 */ "ENOTDIR",
2615 /* 21 */ "EISDIR",
2616 /* 22 */ "EINVAL",
2617 /* 23 */ "ENFILE",
2618 /* 24 */ "EMFILE",
2619 /* 25 */ "ENOTTY",
2620 /* 26 */ "ETXTBSY",
2621 /* 27 */ "EFBIG",
2622 /* 28 */ "ENOSPC",
2623 /* 29 */ "ESPIPE",
2624 /* 30 */ "EROFS",
2625 /* 31 */ "EMLINK",
2626 /* 32 */ "EPIPE",
2627 /* 33 */ "EDOM",
2628 /* 34 */ "ERANGE",
2629 /* 35 */ "EDEADLK",
2630 /* 36 */ "ENAMETOOLONG",
2631 /* 37 */ "ENOLCK",
2632 /* 38 */ "ENOSYS",
2633 /* 39 */ "ENOTEMPTY",
2634 /* 40 */ "ELOOP",
2635 /* 41 */ 0,
2636 /* 42 */ "ENOMSG",
2637 /* 43 */ "EIDRM",
2638 /* 44 */ "ECHRNG",
2639 /* 45 */ "EL2NSYNC",
2640 /* 46 */ "EL3HLT",
2641 /* 47 */ "EL3RST",
2642 /* 48 */ "ELNRNG",
2643 /* 49 */ "EUNATCH",
2644 /* 50 */ "ENOCSI",
2645 /* 51 */ "EL2HLT",
2646 /* 52 */ "EBADE",
2647 /* 53 */ "EBADR",
2648 /* 54 */ "EXFULL",
2649 /* 55 */ "ENOANO",
2650 /* 56 */ "EBADRQC",
2651 /* 57 */ "EBADSLT",
2652 /* 58 */ "EDEADLOCK",
2653 /* 59 */ "EBFONT",
2654 /* 60 */ "ENOSTR",
2655 /* 61 */ "ENODATA",
2656 /* 62 */ "ETIME",
2657 /* 63 */ "ENOSR",
2658 /* 64 */ "ENONET",
2659 /* 65 */ "ENOPKG",
2660 /* 66 */ "EREMOTE",
2661 /* 67 */ "ENOLINK",
2662 /* 68 */ "EADV",
2663 /* 69 */ "ESRMNT",
2664 /* 70 */ "ECOMM",
2665 /* 71 */ "EPROTO",
2666 /* 72 */ "EMULTIHOP",
2667 /* 73 */ "EDOTDOT",
2668 /* 74 */ "EBADMSG",
2669 /* 75 */ "EOVERFLOW",
2670 /* 76 */ "ENOTUNIQ",
2671 /* 77 */ "EBADFD",
2672 /* 78 */ "EREMCHG",
2673 /* 79 */ "ELIBACC",
2674 /* 80 */ "ELIBBAD",
2675 /* 81 */ "ELIBSCN",
2676 /* 82 */ "ELIBMAX",
2677 /* 83 */ "ELIBEXEC",
2678 /* 84 */ "EILSEQ",
2679 /* 85 */ "ERESTART",
2680 /* 86 */ "ESTRPIPE",
2681 /* 87 */ "EUSERS",
2682 /* 88 */ "ENOTSOCK",
2683 /* 89 */ "EDESTADDRREQ",
2684 /* 90 */ "EMSGSIZE",
2685 /* 91 */ "EPROTOTYPE",
2686 /* 92 */ "ENOPROTOOPT",
2687 /* 93 */ "EPROTONOSUPPORT",
2688 /* 94 */ "ESOCKTNOSUPPORT",
2689 /* 95 */ "EOPNOTSUPP",
2690 /* 96 */ "EPFNOSUPPORT",
2691 /* 97 */ "EAFNOSUPPORT",
2692 /* 98 */ "EADDRINUSE",
2693 /* 99 */ "EADDRNOTAVAIL",
2694 /* 100 */ "ENETDOWN",
2695 /* 101 */ "ENETUNREACH",
2696 /* 102 */ "ENETRESET",
2697 /* 103 */ "ECONNABORTED",
2698 /* 104 */ "ECONNRESET",
2699 /* 105 */ "ENOBUFS",
2700 /* 106 */ "EISCONN",
2701 /* 107 */ "ENOTCONN",
2702 /* 108 */ "ESHUTDOWN",
2703 /* 109 */ "ETOOMANYREFS",
2704 /* 110 */ "ETIMEDOUT",
2705 /* 111 */ "ECONNREFUSED",
2706 /* 112 */ "EHOSTDOWN",
2707 /* 113 */ "EHOSTUNREACH",
2708 /* 114 */ "EALREADY",
2709 /* 115 */ "EINPROGRESS",
2710 /* 116 */ "ESTALE",
2711 /* 117 */ "EUCLEAN",
2712 /* 118 */ "ENOTNAM",
2713 /* 119 */ "ENAVAIL",
2714 /* 120 */ "EISNAM",
2715 /* 121 */ "EREMOTEIO",
2716 /* 122 */ "EDQUOT",
2717};
2718
2719static char *(linux_signal_names[]) = {
2720 /* 0 */ 0,
2721 /* 1 */ "SIGHUP",
2722 /* 2 */ "SIGINT",
2723 /* 3 */ "SIGQUIT",
2724 /* 4 */ "SIGILL",
2725 /* 5 */ "SIGTRAP",
2726 /* 6 */ "SIGABRT",
2727 /* 6 */ "SIGIOT",
2728 /* 7 */ "SIGBUS",
2729 /* 8 */ "SIGFPE",
2730 /* 9 */ "SIGKILL",
2731 /* 10 */ "SIGUSR1",
2732 /* 11 */ "SIGSEGV",
2733 /* 12 */ "SIGUSR2",
2734 /* 13 */ "SIGPIPE",
2735 /* 14 */ "SIGALRM",
2736 /* 15 */ "SIGTERM",
2737 /* 16 */ "SIGSTKFLT",
2738 /* 17 */ "SIGCHLD",
2739 /* 18 */ "SIGCONT",
2740 /* 19 */ "SIGSTOP",
2741 /* 20 */ "SIGTSTP",
2742 /* 21 */ "SIGTTIN",
2743 /* 22 */ "SIGTTOU",
2744 /* 23 */ "SIGURG",
2745 /* 24 */ "SIGXCPU",
2746 /* 25 */ "SIGXFSZ",
2747 /* 26 */ "SIGVTALRM",
2748 /* 27 */ "SIGPROF",
2749 /* 28 */ "SIGWINCH",
2750 /* 29 */ "SIGIO",
2751 /* 30 */ "SIGPWR",
2752 /* 31 */ "SIGUNUSED",
2753};
2754
2755static emul_syscall emul_linux_syscalls = {
2756 linux_descriptors,
2757 sizeof(linux_descriptors) / sizeof(linux_descriptors[0]),
2758 linux_error_names,
2759 sizeof(linux_error_names) / sizeof(linux_error_names[0]),
2760 linux_signal_names,
2761 sizeof(linux_signal_names) / sizeof(linux_signal_names[0]),
2762};
2763
2764
2765/* Linux's os_emul interface, most are just passed on to the generic
2766 syscall stuff */
2767
2768static os_emul_data *
2769emul_linux_create(device *root,
2770 bfd *image,
2771 const char *name)
2772{
2773 /* check that this emulation is really for us */
2774 if (name != NULL && strcmp(name, "linux") != 0)
2775 return NULL;
2776
2777 if (image == NULL)
2778 return NULL;
2779
2780 return emul_unix_create(root, image, "linux", &emul_linux_syscalls);
2781}
2782
2783static void
2784emul_linux_init(os_emul_data *emul_data,
2785 int nr_cpus)
2786{
2787 /* nothing yet */
2788}
2789
2790static void
2791emul_linux_system_call(cpu *processor,
2792 unsigned_word cia,
2793 os_emul_data *emul_data)
2794{
2795 emul_do_system_call(emul_data,
2796 emul_data->syscalls,
2797 cpu_registers(processor)->gpr[0],
2798 3, /*r3 contains arg0*/
2799 processor,
2800 cia);
2801}
2802
2803const os_emul emul_linux = {
2804 "linux",
2805 emul_linux_create,
2806 emul_linux_init,
2807 emul_linux_system_call,
2808 0, /*instruction_call*/
2809 0 /*data*/
2810};
2811
2812#endif /* _EMUL_UNIX_C_ */
This page took 0.132371 seconds and 4 git commands to generate.