* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[deliverable/binutils-gdb.git] / sim / ppc / emul_unix.c
CommitLineData
88f1eac4
MM
1/* This file is part of the program psim.
2
3 Copyright (C) 1996, 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#ifdef HAVE_SYS_TERMIOS_H
69#include <sys/termios.h>
70#endif
71
72#ifdef HAVE_SYS_TERMIO_H
73#include <sys/termio.h>
74#endif
75
76#ifdef HAVE_GETRUSAGE
77#ifndef HAVE_SYS_RESOURCE_H
78#undef HAVE_GETRUSAGE
79#endif
80#endif
81
82#ifdef HAVE_GETRUSAGE
83#include <sys/resource.h>
84int getrusage();
85#endif
86
87#if HAVE_SYS_IOCTL_H
88#include <sys/ioctl.h>
89#endif
90
91#if HAVE_SYS_MOUNT_H
92#include <sys/mount.h>
93#endif
94
95#if HAVE_DIRENT_H
96# include <dirent.h>
97# define NAMLEN(dirent) strlen((dirent)->d_name)
98#else
99# define dirent direct
100# define NAMLEN(dirent) (dirent)->d_namlen
101# if HAVE_SYS_NDIR_H
102# include <sys/ndir.h>
103# endif
104# if HAVE_SYS_DIR_H
105# include <sys/dir.h>
106# endif
107# if HAVE_NDIR_H
108# include <ndir.h>
109# endif
110#endif
111
112#ifdef HAVE_UNISTD_H
113#undef MAXPATHLEN /* sys/param.h might define this also */
114#include <unistd.h>
115#endif
116
117#ifdef HAVE_STDLIB_H
118#include <stdlib.h>
119#endif
120
121#if defined(BSD) && !defined(errno) && (BSD < 199306) /* here BSD as just a bug */
122extern int errno;
123#endif
124
125#ifndef STATIC_INLINE_EMUL_UNIX
126#define STATIC_INLINE_EMUL_UNIX STATIC_INLINE
127#endif
128
129#ifndef PATH_MAX
130#define PATH_MAX 1024
131#endif
132
133#ifndef EINVAL
134#define EINVAL -1
135#endif
136
137/* UNIX's idea of what is needed to implement emulations */
138
139struct _os_emul_data {
140 device *vm;
141 emul_syscall *syscalls;
142};
143
5b18a1a0 144\f
88f1eac4 145/* Emulation of simple UNIX system calls that are common on all systems. */
5b18a1a0
MM
146
147/* Structures that are common agmonst the UNIX varients */
148struct unix_timeval {
149 signed32 tv_sec; /* seconds */
150 signed32 tv_usec; /* microseconds */
151};
152
153struct unix_timezone {
154 signed32 tz_minuteswest; /* minutes west of Greenwich */
155 signed32 tz_dsttime; /* type of dst correction */
156};
157
158#define UNIX_RUSAGE_SELF 0
159#define UNIX_RUSAGE_CHILDREN (-1)
160#define UNIX_RUSAGE_BOTH (-2) /* sys_wait4() uses this */
161
162struct unix_rusage {
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 " */
179};
180
181
88f1eac4
MM
182static void
183do_unix_exit(os_emul_data *emul,
184 unsigned call,
185 const int arg0,
186 cpu *processor,
187 unsigned_word cia)
188{
189 int status = (int)cpu_registers(processor)->gpr[arg0];
190 if (WITH_TRACE && ppc_trace[trace_os_emul])
191 printf_filtered ("%d)\n", status);
192
193 cpu_halt(processor, cia, was_exited, status);
194}
195
196
197static void
198do_unix_read(os_emul_data *emul,
199 unsigned call,
200 const int arg0,
201 cpu *processor,
202 unsigned_word cia)
203{
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];
208 int status;
209
210 if (WITH_TRACE && ppc_trace[trace_os_emul])
211 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
212
213 /* get a tempoary bufer */
214 scratch_buffer = zalloc(nbytes);
215
216 /* check if buffer exists by reading it */
217 emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia);
218
219 /* read */
220 status = read (d, scratch_buffer, nbytes);
221
222 emul_write_status(processor, status, errno);
223 if (status > 0)
224 emul_write_buffer(scratch_buffer, buf, status, processor, cia);
225
226 zfree(scratch_buffer);
227}
228
229
230static void
231do_unix_write(os_emul_data *emul,
232 unsigned call,
233 const int arg0,
234 cpu *processor,
235 unsigned_word cia)
236{
237 void *scratch_buffer = NULL;
238 int nr_moved;
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];
242 int status;
243
244 if (WITH_TRACE && ppc_trace[trace_os_emul])
245 printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
246
247 /* get a tempoary bufer */
248 scratch_buffer = zalloc(nbytes); /* FIXME - nbytes == 0 */
249
250 /* copy in */
251 nr_moved = vm_data_map_read_buffer(cpu_data_map(processor),
252 scratch_buffer,
253 buf,
254 nbytes);
255 if (nr_moved != nbytes) {
256 /* FIXME - should handle better */
257 error("system_call()write copy failed (nr_moved=%d != nbytes=%d)\n",
258 nr_moved, nbytes);
259 }
260
261 /* write */
262 status = write(d, scratch_buffer, nbytes);
263 emul_write_status(processor, status, errno);
264 zfree(scratch_buffer);
265
266 flush_stdoutput();
267}
268
269
270static void
271do_unix_open(os_emul_data *emul,
272 unsigned call,
273 const int arg0,
274 cpu *processor,
275 unsigned_word cia)
276{
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];
282 int status;
283
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);
286
287 status = open(path, flags, mode);
288 emul_write_status(processor, status, errno);
289}
290
291
292static void
293do_unix_close(os_emul_data *emul,
294 unsigned call,
295 const int arg0,
296 cpu *processor,
297 unsigned_word cia)
298{
299 int d = (int)cpu_registers(processor)->gpr[arg0];
300 int status;
301
302 if (WITH_TRACE && ppc_trace[trace_os_emul])
303 printf_filtered ("%d", d);
304
305 status = close(d);
306 emul_write_status(processor, status, errno);
307}
308
309
310static void
311do_unix_break(os_emul_data *emul,
312 unsigned call,
313 const int arg0,
314 cpu *processor,
315 unsigned_word cia)
316{
317 /* just pass this onto the `vm' device */
318 psim *system = cpu_system(processor);
319 unsigned_word new_break = cpu_registers(processor)->gpr[arg0];
320 int status;
321
322 if (WITH_TRACE && ppc_trace[trace_os_emul])
323 printf_filtered ("0x%lx", (long)cpu_registers(processor)->gpr[arg0]);
324
325 status = device_ioctl(emul->vm,
326 system,
327 processor,
328 cia,
329 new_break); /*ioctl-data*/
330
331 emul_write_status(processor, 0, status);
332}
333
334#ifndef HAVE_GETPID
335#define do_unix_getpid 0
336#else
337static void
338do_unix_getpid(os_emul_data *emul,
339 unsigned call,
340 const int arg0,
341 cpu *processor,
342 unsigned_word cia)
343{
5b18a1a0
MM
344 pid_t status = getpid();
345 emul_write_status(processor, (int)status, errno);
88f1eac4
MM
346}
347#endif
348
349#ifndef HAVE_GETPPID
350#define do_unix_getppid 0
351#else
352static void
353do_unix_getppid(os_emul_data *emul,
354 unsigned call,
355 const int arg0,
356 cpu *processor,
357 unsigned_word cia)
358{
5b18a1a0
MM
359 pid_t status = getppid();
360 emul_write_status(processor, (int)status, errno);
88f1eac4
MM
361}
362#endif
363
364#if !defined(HAVE_GETPID) || !defined(HAVE_GETPPID)
365#define do_unix_getpid2 0
366#else
367static void
368do_unix_getpid2(os_emul_data *emul,
369 unsigned call,
370 const int arg0,
371 cpu *processor,
372 unsigned_word cia)
373{
374 int pid = (int)getpid();
375 int ppid = (int)getppid();
376 emul_write2_status(processor, pid, ppid, errno);
377}
378#endif
379
380#if !defined(HAVE_GETUID) || !defined(HAVE_GETEUID)
381#define do_unix_getuid2 0
382#else
383static void
384do_unix_getuid2(os_emul_data *emul,
385 unsigned call,
386 const int arg0,
387 cpu *processor,
388 unsigned_word cia)
389{
5b18a1a0
MM
390 uid_t uid = getuid();
391 uid_t euid = geteuid();
392 emul_write2_status(processor, (int)uid, (int)euid, errno);
88f1eac4
MM
393}
394#endif
395
396#ifndef HAVE_GETUID
397#define do_unix_getuid 0
398#else
399static void
400do_unix_getuid(os_emul_data *emul,
401 unsigned call,
402 const int arg0,
403 cpu *processor,
404 unsigned_word cia)
405{
5b18a1a0
MM
406 uid_t status = getuid();
407 emul_write_status(processor, (int)status, errno);
88f1eac4
MM
408}
409#endif
410
411#ifndef HAVE_GETEUID
412#define do_unix_geteuid 0
413#else
414static void
415do_unix_geteuid(os_emul_data *emul,
416 unsigned call,
417 const int arg0,
418 cpu *processor,
419 unsigned_word cia)
420{
5b18a1a0
MM
421 uid_t status = geteuid();
422 emul_write_status(processor, (int)status, errno);
88f1eac4
MM
423}
424#endif
425
426#if 0
427#ifndef HAVE_KILL
428#define do_unix_kill 0
429#else
430static void
431do_unix_kill(os_emul_data *emul,
432 unsigned call,
433 const int arg0,
434 cpu *processor,
435 unsigned_word cia)
436{
437 pid_t pid = cpu_registers(processor)->gpr[arg0];
438 int sig = cpu_registers(processor)->gpr[arg0+1];
439
440 if (WITH_TRACE && ppc_trace[trace_os_emul])
441 printf_filtered ("%d, %d", (int)pid, sig);
442
443 printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
444 (long)cia);
445
446 cpu_halt(processor, cia, was_signalled, sig);
447}
448#endif
449#endif
450
451#ifndef HAVE_DUP
452#define do_unix_dup 0
453#else
454static void
455do_unix_dup(os_emul_data *emul,
456 unsigned call,
457 const int arg0,
458 cpu *processor,
459 unsigned_word cia)
460{
461 int oldd = cpu_registers(processor)->gpr[arg0];
462 int status = dup(oldd);
463 int err = errno;
464
465 if (WITH_TRACE && ppc_trace[trace_os_emul])
466 printf_filtered ("%d", oldd);
467
468 emul_write_status(processor, status, err);
469}
470#endif
471
472#ifndef HAVE_DUP2
473#define do_unix_dup2 0
474#else
475static void
476do_unix_dup2(os_emul_data *emul,
477 unsigned call,
478 const int arg0,
479 cpu *processor,
480 unsigned_word cia)
481{
482 int oldd = cpu_registers(processor)->gpr[arg0];
483 int newd = cpu_registers(processor)->gpr[arg0+1];
484 int status = dup2(oldd, newd);
485 int err = errno;
486
487 if (WITH_TRACE && ppc_trace[trace_os_emul])
488 printf_filtered ("%d, %d", oldd, newd);
489
490 emul_write_status(processor, status, err);
491}
492#endif
493
494#ifndef HAVE_LSEEK
495#define do_unix_lseek 0
496#else
497static void
498do_unix_lseek(os_emul_data *emul,
499 unsigned call,
500 const int arg0,
501 cpu *processor,
502 unsigned_word cia)
503{
5b18a1a0
MM
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];
88f1eac4
MM
507 off_t status;
508
509 if (WITH_TRACE && ppc_trace[trace_os_emul])
510 printf_filtered ("%d %ld %d", fildes, (long)offset, whence);
511
512 status = lseek(fildes, offset, whence);
5b18a1a0 513 emul_write_status(processor, (int)status, errno);
88f1eac4
MM
514}
515#endif
516
517
518#if !defined(HAVE_GETGID) || !defined(HAVE_GETEGID)
519#define do_unix_getgid2 0
520#else
521static void
522do_unix_getgid2(os_emul_data *emul,
523 unsigned call,
524 const int arg0,
525 cpu *processor,
526 unsigned_word cia)
527{
5b18a1a0
MM
528 gid_t gid = getgid();
529 gid_t egid = getegid();
530 emul_write2_status(processor, (int)gid, (int)egid, errno);
88f1eac4
MM
531}
532#endif
533
534#ifndef HAVE_GETGID
535#define do_unix_getgid 0
536#else
537static void
538do_unix_getgid(os_emul_data *emul,
539 unsigned call,
540 const int arg0,
541 cpu *processor,
542 unsigned_word cia)
543{
5b18a1a0
MM
544 gid_t status = getgid();
545 emul_write_status(processor, (int)status, errno);
88f1eac4
MM
546}
547#endif
548
549#ifndef HAVE_GETEGID
550#define do_unix_getegid 0
551#else
552static void
553do_unix_getegid(os_emul_data *emul,
554 unsigned call,
555 const int arg0,
556 cpu *processor,
557 unsigned_word cia)
558{
5b18a1a0
MM
559 gid_t status = getegid();
560 emul_write_status(processor, (int)status, errno);
88f1eac4
MM
561}
562#endif
563
564#ifndef HAVE_UMASK
565#define do_unix_umask 0
566#else
567static void
568do_unix_umask(os_emul_data *emul,
569 unsigned call,
570 const int arg0,
571 cpu *processor,
572 unsigned_word cia)
573{
5b18a1a0 574 mode_t mask = (mode_t)cpu_registers(processor)->gpr[arg0];
88f1eac4
MM
575 int status = umask(mask);
576
577 if (WITH_TRACE && ppc_trace[trace_os_emul])
578 printf_filtered ("0%o", mask);
579
580 emul_write_status(processor, status, errno);
581}
582#endif
583
584#ifndef HAVE_CHDIR
585#define do_unix_chdir 0
586#else
587static void
588do_unix_chdir(os_emul_data *emul,
589 unsigned call,
590 const int arg0,
591 cpu *processor,
592 unsigned_word cia)
593{
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);
597 int status;
598
599 if (WITH_TRACE && ppc_trace[trace_os_emul])
600 printf_filtered ("0x%lx [%s]", (long)path_addr, path);
601
602 status = chdir(path);
603 emul_write_status(processor, status, errno);
604}
605#endif
606
607#ifndef HAVE_LINK
608#define do_unix_link 0
609#else
610static void
611do_unix_link(os_emul_data *emul,
612 unsigned call,
613 const int arg0,
614 cpu *processor,
615 unsigned_word cia)
616{
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);
623 int status;
624
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);
627
628 status = link(path1, path2);
629 emul_write_status(processor, status, errno);
630}
631#endif
632
633#ifndef HAVE_SYMLINK
634#define do_unix_symlink 0
635#else
636static void
637do_unix_symlink(os_emul_data *emul,
638 unsigned call,
639 const int arg0,
640 cpu *processor,
641 unsigned_word cia)
642{
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);
649 int status;
650
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);
653
654 status = symlink(path1, path2);
655 emul_write_status(processor, status, errno);
656}
657#endif
658
659#ifndef HAVE_UNLINK
660#define do_unix_unlink 0
661#else
662static void
663do_unix_unlink(os_emul_data *emul,
664 unsigned call,
665 const int arg0,
666 cpu *processor,
667 unsigned_word cia)
668{
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);
672 int status;
673
674 if (WITH_TRACE && ppc_trace[trace_os_emul])
675 printf_filtered ("0x%lx [%s]", (long)path_addr, path);
676
677 status = unlink(path);
678 emul_write_status(processor, status, errno);
679}
680#endif
681
682#ifndef HAVE_MKDIR
683#define do_unix_mkdir 0
684#else
685static void
686do_unix_mkdir(os_emul_data *emul,
687 unsigned call,
688 const int arg0,
689 cpu *processor,
690 unsigned_word cia)
691{
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];
696 int status;
697
698 if (WITH_TRACE && ppc_trace[trace_os_emul])
699 printf_filtered ("0x%lx [%s], 0%3o", (long)path_addr, path, mode);
700
701 status = mkdir(path, mode);
702 emul_write_status(processor, status, errno);
703}
704#endif
705
706#ifndef HAVE_RMDIR
707#define do_unix_rmdir 0
708#else
709static void
710do_unix_rmdir(os_emul_data *emul,
711 unsigned call,
712 const int arg0,
713 cpu *processor,
714 unsigned_word cia)
715{
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);
719 int status;
720
721 if (WITH_TRACE && ppc_trace[trace_os_emul])
722 printf_filtered ("0x%lx [%s]", (long)path_addr, path);
723
724 status = rmdir(path);
725 emul_write_status(processor, status, errno);
726}
727#endif
728
5b18a1a0
MM
729#ifndef HAVE_TIME
730#define do_unix_time 0
731#else
732static void
733do_unix_time(os_emul_data *emul,
734 unsigned call,
735 const int arg0,
736 cpu *processor,
737 unsigned_word cia)
738{
739 unsigned_word tp = cpu_registers(processor)->gpr[arg0];
740 time_t now = time ((time_t *)0);
741 unsigned_word status = H2T_4(now);
742
743 if (WITH_TRACE && ppc_trace[trace_os_emul])
744 printf_filtered ("0x%lx", (long)tp);
745
746 emul_write_status(processor, (int)status, errno);
747
748 if (tp)
749 emul_write_buffer(&status, tp, sizeof(status), processor, cia);
750}
751#endif
752
753#if !defined(HAVE_GETTIMEOFDAY) || !defined(HAVE_SYS_TIME_H)
754#define do_unix_gettimeofday 0
755#else
756static void
757do_unix_gettimeofday(os_emul_data *emul,
758 unsigned call,
759 const int arg0,
760 cpu *processor,
761 unsigned_word cia)
762{
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;
769 int status;
770
771 if (WITH_TRACE && ppc_trace[trace_os_emul])
772 printf_filtered ("0x%lx, 0x%lx", (long)tv, (long)tz);
773
774 /* Just in case the system doesn't set the timezone structure */
775 host_timezone.tz_minuteswest = 0;
776 host_timezone.tz_dsttime = 0;
777
778 status = gettimeofday(&host_timeval, &host_timezone);
779 if (status >= 0) {
780 if (tv) {
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);
784 }
785
786 if (tz) {
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);
790 }
791 }
792
793 emul_write_status(processor, (int)status, errno);
794}
795#endif
796
797
798#ifndef HAVE_GETRUSAGE
799#define do_unix_getrusage 0
800#else
801static void
802do_unix_getrusage(os_emul_data *emul,
803 unsigned call,
804 const int arg0,
805 cpu *processor,
806 unsigned_word cia)
807{
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;
812 int status;
813
814 if (WITH_TRACE && ppc_trace[trace_os_emul])
815 printf_filtered ("%ld, 0x%lx", (long)who, (long)usage);
816
817 switch (who) {
818 default:
819 status = -1;
820 errno = EINVAL;
821 break;
822
823 case UNIX_RUSAGE_SELF:
824 status = getrusage(RUSAGE_SELF, &host_rusage);
825 break;
826
827 case UNIX_RUSAGE_CHILDREN:
828 status = getrusage(RUSAGE_CHILDREN, &host_rusage);
829 break;
830
831 case UNIX_RUSAGE_BOTH:
832 status = getrusage(RUSAGE_SELF, &host_rusage);
833 if (status >= 0) {
834 status = getrusage(RUSAGE_CHILDREN, &host_rusage2);
835 if (status >= 0) {
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;
854 }
855 }
856 }
857
858 if (status >= 0) {
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);
878 }
879
880 emul_write_status(processor, status, errno);
881}
882#endif
883
88f1eac4
MM
884\f
885/* Common code for initializing the system call stuff */
886
887static os_emul_data *
888emul_unix_create(device *root,
889 bfd *image,
890 const char *name,
891 emul_syscall *syscall)
892{
893 unsigned_word top_of_stack;
894 unsigned stack_size;
895 int elf_binary;
896 os_emul_data *data;
897 device *vm;
898
899 /* merge any emulation specific entries into the device tree */
900
901 /* establish a few defaults */
902 if (image->xvec->flavour == bfd_target_elf_flavour) {
903 elf_binary = 1;
904 top_of_stack = 0xe0000000;
905 stack_size = 0x00100000;
906 }
907 else {
908 elf_binary = 0;
909 top_of_stack = 0x20000000;
910 stack_size = 0x00100000;
911 }
912
913 /* options */
914 emul_add_tree_options(root, image, name,
915 (WITH_ENVIRONMENT == USER_ENVIRONMENT
916 ? "user" : "virtual"),
917 0 /*oea-interrupt-prefix*/);
918
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);
925
926 device_tree_add_parsed(root, "/openprom/vm/map-binary/file-name %s",
927 bfd_get_filename(image));
928
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"));
937
938 /* finally our emulation data */
939 data = ZALLOC(os_emul_data);
940 data->vm = vm;
941 data->syscalls = syscall;
942 return data;
943}
944
945\f
946/* Solaris specific implementation */
947
948typedef signed32 solaris_uid_t;
949typedef signed32 solaris_gid_t;
950typedef signed32 solaris_off_t;
951typedef signed32 solaris_pid_t;
952typedef signed32 solaris_time_t;
953typedef unsigned32 solaris_dev_t;
954typedef unsigned32 solaris_ino_t;
955typedef unsigned32 solaris_mode_t;
956typedef unsigned32 solaris_nlink_t;
957
958#ifdef HAVE_SYS_STAT_H
959#define SOLARIS_ST_FSTYPSZ 16 /* array size for file system type name */
960
88f1eac4
MM
961struct 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;
970 signed32 st_pad2[2];
971 solaris_off_t st_size;
972 signed32 st_pad3; /* future off_t expansion */
5b18a1a0
MM
973 struct unix_timeval st_atim;
974 struct unix_timeval st_mtim;
975 struct unix_timeval st_ctim;
88f1eac4
MM
976 signed32 st_blksize;
977 signed32 st_blocks;
978 char st_fstype[SOLARIS_ST_FSTYPSZ];
979 signed32 st_pad4[8]; /* expansion area */
980};
981
982/* Convert from host stat structure to solaris stat structure */
983STATIC_INLINE_EMUL_UNIX void
984convert_to_solaris_stat(unsigned_word addr,
985 struct stat *host,
986 cpu *processor,
987 unsigned_word cia)
988{
989 struct solaris_stat target;
990 int i;
991
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);
999
1000#ifdef HAVE_ST_RDEV
1001 target.st_rdev = H2T_4(host->st_rdev);
1002#else
1003 target.st_rdev = 0;
1004#endif
1005
1006#ifdef HAVE_ST_BLKSIZE
1007 target.st_blksize = H2T_4(host->st_blksize);
1008#else
1009 target.st_blksize = 0;
1010#endif
1011
1012#ifdef HAVE_ST_BLOCKS
1013 target.st_blocks = H2T_4(host->st_blocks);
1014#else
1015 target.st_blocks = 0;
1016#endif
1017
1018 target.st_atim.tv_sec = H2T_4(host->st_atime);
1019 target.st_atim.tv_usec = 0;
1020
1021 target.st_ctim.tv_sec = H2T_4(host->st_ctime);
1022 target.st_ctim.tv_usec = 0;
1023
1024 target.st_mtim.tv_sec = H2T_4(host->st_mtime);
1025 target.st_mtim.tv_usec = 0;
1026
1027 for (i = 0; i < sizeof (target.st_pad1) / sizeof (target.st_pad1[0]); i++)
1028 target.st_pad1[i] = 0;
1029
1030 for (i = 0; i < sizeof (target.st_pad2) / sizeof (target.st_pad2[0]); i++)
1031 target.st_pad2[i] = 0;
1032
1033 target.st_pad3 = 0;
1034
1035 for (i = 0; i < sizeof (target.st_pad4) / sizeof (target.st_pad4[0]); i++)
1036 target.st_pad4[i] = 0;
1037
1038 /* For now, just punt and always say it is a ufs file */
1039 strcpy (target.st_fstype, "ufs");
1040
1041 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
1042}
1043#endif /* HAVE_SYS_STAT_H */
1044
1045#ifndef HAVE_STAT
1046#define do_solaris_stat 0
1047#else
1048static void
1049do_solaris_stat(os_emul_data *emul,
1050 unsigned call,
1051 const int arg0,
1052 cpu *processor,
1053 unsigned_word cia)
1054{
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];
1058 struct stat buf;
1059 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
1060 int status;
1061
1062 if (WITH_TRACE && ppc_trace[trace_os_emul])
1063 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
1064
1065 status = stat (path, &buf);
1066 if (status == 0)
1067 convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
1068
1069 emul_write_status(processor, status, errno);
1070}
1071#endif
1072
1073#ifndef HAVE_LSTAT
1074#define do_solaris_lstat 0
1075#else
1076static void
1077do_solaris_lstat(os_emul_data *emul,
1078 unsigned call,
1079 const int arg0,
1080 cpu *processor,
1081 unsigned_word cia)
1082{
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];
1086 struct stat buf;
1087 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
1088 int status;
1089
1090 if (WITH_TRACE && ppc_trace[trace_os_emul])
1091 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
1092
1093 status = lstat (path, &buf);
1094 if (status == 0)
1095 convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
1096
1097 emul_write_status(processor, status, errno);
1098}
1099#endif
1100
1101#ifndef HAVE_FSTAT
1102#define do_solaris_fstat 0
1103#else
1104static void
1105do_solaris_fstat(os_emul_data *emul,
1106 unsigned call,
1107 const int arg0,
1108 cpu *processor,
1109 unsigned_word cia)
1110{
1111 int fildes = (int)cpu_registers(processor)->gpr[arg0];
1112 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
1113 struct stat buf;
1114 int status;
1115
1116 if (WITH_TRACE && ppc_trace[trace_os_emul])
1117 printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt);
1118
1119 status = fstat (fildes, &buf);
1120 if (status == 0)
1121 convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
1122
1123 emul_write_status(processor, status, errno);
1124}
1125#endif
1126
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
1131
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
1148#endif
1149
1150#ifdef HAVE_SYS_TERMIO_H
1151/* Convert to/from host termio structure */
1152
1153struct 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 */
1160};
1161
1162STATIC_INLINE_EMUL_UNIX void
1163convert_to_solaris_termio(unsigned_word addr,
1164 struct termio *host,
1165 cpu *processor,
1166 unsigned_word cia)
1167{
1168 struct solaris_termio target;
1169 int i;
1170
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;
1176
1177 for (i = 0; i < SOLARIS_NCC; i++)
1178 target.c_cc[i] = 0;
1179
1180#ifdef VINTR
1181 target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];
1182#endif
1183
1184#ifdef VQUIT
1185 target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];
1186#endif
1187
1188#ifdef VERASE
1189 target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];
1190#endif
1191
1192#ifdef VKILL
1193 target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];
1194#endif
1195
1196#ifdef VEOF
1197 target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];
1198#endif
1199
1200#ifdef VEOL
1201 target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];
1202#endif
1203
1204#ifdef VEOL2
1205 target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];
1206#endif
1207
1208#ifdef VSWTCH
1209 target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];
1210
1211#else
1212#ifdef VSWTC
1213 target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];
1214#endif
1215#endif
1216
1217 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
1218}
1219#endif /* HAVE_SYS_TERMIO_H */
1220
1221#ifdef HAVE_SYS_TERMIOS_H
1222/* Convert to/from host termios structure */
1223
1224typedef unsigned32 solaris_tcflag_t;
1225typedef unsigned8 solaris_cc_t;
1226typedef unsigned32 solaris_speed_t;
1227
1228struct 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];
1234};
1235
1236STATIC_INLINE_EMUL_UNIX void
1237convert_to_solaris_termios(unsigned_word addr,
1238 struct termios *host,
1239 cpu *processor,
1240 unsigned_word cia)
1241{
1242 struct solaris_termios target;
1243 int i;
1244
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);
1249
1250 for (i = 0; i < SOLARIS_NCCS; i++)
1251 target.c_cc[i] = 0;
1252
1253#ifdef VINTR
1254 target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];
1255#endif
1256
1257#ifdef VQUIT
1258 target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];
1259#endif
1260
1261#ifdef VERASE
1262 target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];
1263#endif
1264
1265#ifdef VKILL
1266 target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];
1267#endif
1268
1269#ifdef VEOF
1270 target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];
1271#endif
1272
1273#ifdef VEOL
1274 target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];
1275#endif
1276
1277#ifdef VEOL2
1278 target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];
1279#endif
1280
1281#ifdef VSWTCH
1282 target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];
1283
1284#else
1285#ifdef VSWTC
1286 target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];
1287#endif
1288#endif
1289
1290#ifdef VSTART
1291 target.c_cc[SOLARIS_VSTART] = host->c_cc[VSTART];
1292#endif
1293
1294#ifdef VSTOP
1295 target.c_cc[SOLARIS_VSTOP] = host->c_cc[VSTOP];
1296#endif
1297
1298#ifdef VSUSP
1299 target.c_cc[SOLARIS_VSUSP] = host->c_cc[VSUSP];
1300#endif
1301
1302#ifdef VDSUSP
1303 target.c_cc[SOLARIS_VDSUSP] = host->c_cc[VDSUSP];
1304#endif
1305
1306#ifdef VREPRINT
1307 target.c_cc[SOLARIS_VREPRINT] = host->c_cc[VREPRINT];
1308#endif
1309
1310#ifdef VDISCARD
1311 target.c_cc[SOLARIS_VDISCARD] = host->c_cc[VDISCARD];
1312#endif
1313
1314#ifdef VWERASE
1315 target.c_cc[SOLARIS_VWERASE] = host->c_cc[VWERASE];
1316#endif
1317
1318#ifdef VLNEXT
1319 target.c_cc[SOLARIS_VLNEXT] = host->c_cc[VLNEXT];
1320#endif
1321
1322 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
1323}
1324#endif /* HAVE_SYS_TERMIOS_H */
1325
1326#ifndef HAVE_IOCTL
1327#define do_solaris_ioctl 0
1328#else
1329static void
1330do_solaris_ioctl(os_emul_data *emul,
1331 unsigned call,
1332 const int arg0,
1333 cpu *processor,
1334 unsigned_word cia)
1335{
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];
1339 int status = 0;
1340 const char *name = "<unknown>";
1341
1342#ifdef HAVE_SYS_TERMIO_H
1343 struct termio host_termio;
1344#endif
1345
1346#ifdef HAVE_SYS_TERMIOS_H
1347 struct termios host_termios;
1348#endif
1349
1350 switch (request)
1351 {
1352 case 0: /* make sure we have at least one case */
1353 default:
1354 status = -1;
1355 errno = EINVAL;
1356 break;
1357
1358#ifdef HAVE_SYS_TERMIO_H
1359#ifdef TCGETA
1360 case SOLARIS_TIOC | 1: /* TCGETA */
1361 name = "TCGETA";
1362 status = ioctl (fildes, TCGETA, &host_termio);
1363 if (status == 0)
1364 convert_to_solaris_termio (argp_addr, &host_termio, processor, cia);
1365 break;
1366#endif /* TCGETA */
1367#endif /* HAVE_SYS_TERMIO_H */
1368
1369#ifdef HAVE_SYS_TERMIOS_H
1370#if defined(TCGETS) || defined(HAVE_TCGETATTR)
1371 case SOLARIS_TIOC | 13: /* TCGETS */
1372 name = "TCGETS";
1373#ifdef HAVE_TCGETATTR
1374 status = tcgetattr(fildes, &host_termios);
1375#else
1376 status = ioctl (fildes, TCGETS, &host_termios);
1377#endif
1378 if (status == 0)
1379 convert_to_solaris_termios (argp_addr, &host_termios, processor, cia);
1380 break;
1381#endif /* TCGETS */
1382#endif /* HAVE_SYS_TERMIOS_H */
1383 }
1384
1385 emul_write_status(processor, status, errno);
1386
1387 if (WITH_TRACE && ppc_trace[trace_os_emul])
1388 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);
1389}
1390#endif /* HAVE_IOCTL */
1391
1392static 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" },
5b18a1a0 1406 /* 13 */ { do_unix_time, "time" },
88f1eac4
MM
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" },
5b18a1a0 1550 /* 156 */ { do_unix_gettimeofday, "gettimeofday" },
88f1eac4
MM
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" },
1607};
1608
1609static char *(solaris_error_names[]) = {
1610 /* 0 */ "ESUCCESS",
1611 /* 1 */ "EPERM",
1612 /* 2 */ "ENOENT",
1613 /* 3 */ "ESRCH",
1614 /* 4 */ "EINTR",
1615 /* 5 */ "EIO",
1616 /* 6 */ "ENXIO",
1617 /* 7 */ "E2BIG",
1618 /* 8 */ "ENOEXEC",
1619 /* 9 */ "EBADF",
1620 /* 10 */ "ECHILD",
1621 /* 11 */ "EAGAIN",
1622 /* 12 */ "ENOMEM",
1623 /* 13 */ "EACCES",
1624 /* 14 */ "EFAULT",
1625 /* 15 */ "ENOTBLK",
1626 /* 16 */ "EBUSY",
1627 /* 17 */ "EEXIST",
1628 /* 18 */ "EXDEV",
1629 /* 19 */ "ENODEV",
1630 /* 20 */ "ENOTDIR",
1631 /* 21 */ "EISDIR",
1632 /* 22 */ "EINVAL",
1633 /* 23 */ "ENFILE",
1634 /* 24 */ "EMFILE",
1635 /* 25 */ "ENOTTY",
1636 /* 26 */ "ETXTBSY",
1637 /* 27 */ "EFBIG",
1638 /* 28 */ "ENOSPC",
1639 /* 29 */ "ESPIPE",
1640 /* 30 */ "EROFS",
1641 /* 31 */ "EMLINK",
1642 /* 32 */ "EPIPE",
1643 /* 33 */ "EDOM",
1644 /* 34 */ "ERANGE",
1645 /* 35 */ "ENOMSG",
1646 /* 36 */ "EIDRM",
1647 /* 37 */ "ECHRNG",
1648 /* 38 */ "EL2NSYNC",
1649 /* 39 */ "EL3HLT",
1650 /* 40 */ "EL3RST",
1651 /* 41 */ "ELNRNG",
1652 /* 42 */ "EUNATCH",
1653 /* 43 */ "ENOCSI",
1654 /* 44 */ "EL2HLT",
1655 /* 45 */ "EDEADLK",
1656 /* 46 */ "ENOLCK",
1657 /* 47 */ "ECANCELED",
1658 /* 48 */ "ENOTSUP",
1659 /* 49 */ "EDQUOT",
1660 /* 50 */ "EBADE",
1661 /* 51 */ "EBADR",
1662 /* 52 */ "EXFULL",
1663 /* 53 */ "ENOANO",
1664 /* 54 */ "EBADRQC",
1665 /* 55 */ "EBADSLT",
1666 /* 56 */ "EDEADLOCK",
1667 /* 57 */ "EBFONT",
1668 /* 58 */ "Error code 58",
1669 /* 59 */ "Error code 59",
1670 /* 60 */ "ENOSTR",
1671 /* 61 */ "ENODATA",
1672 /* 62 */ "ETIME",
1673 /* 63 */ "ENOSR",
1674 /* 64 */ "ENONET",
1675 /* 65 */ "ENOPKG",
1676 /* 66 */ "EREMOTE",
1677 /* 67 */ "ENOLINK",
1678 /* 68 */ "EADV",
1679 /* 69 */ "ESRMNT",
1680 /* 70 */ "ECOMM",
1681 /* 71 */ "EPROTO",
1682 /* 72 */ "Error code 72",
1683 /* 73 */ "Error code 73",
1684 /* 74 */ "EMULTIHOP",
1685 /* 75 */ "Error code 75",
1686 /* 76 */ "Error code 76",
1687 /* 77 */ "EBADMSG",
1688 /* 78 */ "ENAMETOOLONG",
1689 /* 79 */ "EOVERFLOW",
1690 /* 80 */ "ENOTUNIQ",
1691 /* 81 */ "EBADFD",
1692 /* 82 */ "EREMCHG",
1693 /* 83 */ "ELIBACC",
1694 /* 84 */ "ELIBBAD",
1695 /* 85 */ "ELIBSCN",
1696 /* 86 */ "ELIBMAX",
1697 /* 87 */ "ELIBEXEC",
1698 /* 88 */ "EILSEQ",
1699 /* 89 */ "ENOSYS",
1700 /* 90 */ "ELOOP",
1701 /* 91 */ "ERESTART",
1702 /* 92 */ "ESTRPIPE",
1703 /* 93 */ "ENOTEMPTY",
1704 /* 94 */ "EUSERS",
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",
1761 /* 151 */ "ESTALE",
1762};
1763
1764static char *(solaris_signal_names[]) = {
1765 /* 0 */ 0,
1766 /* 1 */ "SIGHUP",
1767 /* 2 */ "SIGINT",
1768 /* 3 */ "SIGQUIT",
1769 /* 4 */ "SIGILL",
1770 /* 5 */ "SIGTRAP",
1771 /* 6 */ "SIGABRT",
1772 /* 7 */ "SIGEMT",
1773 /* 8 */ "SIGFPE",
1774 /* 9 */ "SIGKILL",
1775 /* 10 */ "SIGBUS",
1776 /* 11 */ "SIGSEGV",
1777 /* 12 */ "SIGSYS",
1778 /* 13 */ "SIGPIPE",
1779 /* 14 */ "SIGALRM",
1780 /* 15 */ "SIGTERM",
1781 /* 16 */ "SIGUSR1",
1782 /* 17 */ "SIGUSR2",
1783 /* 18 */ "SIGCHLD",
1784 /* 19 */ "SIGPWR",
1785 /* 20 */ "SIGWINCH",
1786 /* 21 */ "SIGURG",
1787 /* 22 */ "SIGPOLL",
1788 /* 23 */ "SIGSTOP",
1789 /* 24 */ "SIGTSTP",
1790 /* 25 */ "SIGCONT",
1791 /* 26 */ "SIGTTIN",
1792 /* 27 */ "SIGTTOU",
1793 /* 28 */ "SIGVTALRM",
1794 /* 29 */ "SIGPROF",
1795 /* 30 */ "SIGXCPU",
1796 /* 31 */ "SIGXFSZ",
1797 /* 32 */ "SIGWAITING",
1798 /* 33 */ "SIGLWP",
1799 /* 34 */ "SIGFREEZE",
1800 /* 35 */ "SIGTHAW",
1801 /* 36 */ "SIGCANCEL",
1802};
1803
1804static 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]),
1811};
1812
1813
1814/* Solaris's os_emul interface, most are just passed on to the generic
1815 syscall stuff */
1816
1817static os_emul_data *
1818emul_solaris_create(device *root,
1819 bfd *image,
1820 const char *name)
1821{
1822 /* check that this emulation is really for us */
1823 if (name != NULL && strcmp(name, "solaris") != 0)
1824 return NULL;
1825
1826 if (image == NULL)
1827 return NULL;
1828
1829 return emul_unix_create(root, image, "solaris", &emul_solaris_syscalls);
1830}
1831
1832static void
1833emul_solaris_init(os_emul_data *emul_data,
1834 int nr_cpus)
1835{
1836 /* nothing yet */
1837}
1838
1839static void
1840emul_solaris_system_call(cpu *processor,
1841 unsigned_word cia,
1842 os_emul_data *emul_data)
1843{
1844 emul_do_system_call(emul_data,
1845 emul_data->syscalls,
1846 cpu_registers(processor)->gpr[0],
1847 3, /*r3 contains arg0*/
1848 processor,
1849 cia);
1850}
1851
1852const os_emul emul_solaris = {
1853 "solaris",
1854 emul_solaris_create,
1855 emul_solaris_init,
1856 emul_solaris_system_call,
1857 0, /*instruction_call*/
1858 0 /*data*/
1859};
1860
1861\f
1862/* Linux specific implementation */
1863
1864typedef unsigned32 linux_dev_t;
1865typedef unsigned32 linux_ino_t;
1866typedef unsigned32 linux_mode_t;
1867typedef unsigned16 linux_nlink_t;
1868typedef signed32 linux_off_t;
1869typedef signed32 linux_pid_t;
1870typedef unsigned32 linux_uid_t;
1871typedef unsigned32 linux_gid_t;
1872typedef unsigned32 linux_size_t;
1873typedef signed32 linux_ssize_t;
1874typedef signed32 linux_ptrdiff_t;
1875typedef signed32 linux_time_t;
1876typedef signed32 linux_clock_t;
1877typedef signed32 linux_daddr_t;
1878
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. */
1882
1883struct linux_stat {
1884 linux_dev_t st_dev;
1885 linux_ino_t st_ino;
1886 linux_mode_t st_mode;
1887 linux_nlink_t st_nlink;
1888 linux_uid_t st_uid;
1889 linux_gid_t st_gid;
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;
1902};
1903
1904/* Convert from host stat structure to solaris stat structure */
1905STATIC_INLINE_EMUL_UNIX void
1906convert_to_linux_stat(unsigned_word addr,
1907 struct stat *host,
1908 cpu *processor,
1909 unsigned_word cia)
1910{
1911 struct linux_stat target;
1912
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);
1920
1921#ifdef HAVE_ST_RDEV
1922 target.st_rdev = H2T_4(host->st_rdev);
1923#else
1924 target.st_rdev = 0;
1925#endif
1926
1927#ifdef HAVE_ST_BLKSIZE
1928 target.st_blksize = H2T_4(host->st_blksize);
1929#else
1930 target.st_blksize = 0;
1931#endif
1932
1933#ifdef HAVE_ST_BLOCKS
1934 target.st_blocks = H2T_4(host->st_blocks);
1935#else
1936 target.st_blocks = 0;
1937#endif
1938
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;
1947
1948 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
1949}
1950#endif /* HAVE_SYS_STAT_H */
1951
1952#ifndef HAVE_STAT
1953#define do_linux_stat 0
1954#else
1955static void
1956do_linux_stat(os_emul_data *emul,
1957 unsigned call,
1958 const int arg0,
1959 cpu *processor,
1960 unsigned_word cia)
1961{
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];
1965 struct stat buf;
1966 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
1967 int status;
1968
1969 if (WITH_TRACE && ppc_trace[trace_os_emul])
1970 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
1971
1972 status = stat (path, &buf);
1973 if (status == 0)
1974 convert_to_linux_stat (stat_pkt, &buf, processor, cia);
1975
1976 emul_write_status(processor, status, errno);
1977}
1978#endif
1979
1980#ifndef HAVE_LSTAT
1981#define do_linux_lstat 0
1982#else
1983static void
1984do_linux_lstat(os_emul_data *emul,
1985 unsigned call,
1986 const int arg0,
1987 cpu *processor,
1988 unsigned_word cia)
1989{
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];
1993 struct stat buf;
1994 char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
1995 int status;
1996
1997 if (WITH_TRACE && ppc_trace[trace_os_emul])
1998 printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
1999
2000 status = lstat (path, &buf);
2001 if (status == 0)
2002 convert_to_linux_stat (stat_pkt, &buf, processor, cia);
2003
2004 emul_write_status(processor, status, errno);
2005}
2006#endif
2007
2008#ifndef HAVE_FSTAT
2009#define do_linux_fstat 0
2010#else
2011static void
2012do_linux_fstat(os_emul_data *emul,
2013 unsigned call,
2014 const int arg0,
2015 cpu *processor,
2016 unsigned_word cia)
2017{
2018 int fildes = (int)cpu_registers(processor)->gpr[arg0];
2019 unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
2020 struct stat buf;
2021 int status;
2022
2023 if (WITH_TRACE && ppc_trace[trace_os_emul])
2024 printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt);
2025
2026 status = fstat (fildes, &buf);
2027 if (status == 0)
2028 convert_to_linux_stat (stat_pkt, &buf, processor, cia);
2029
2030 emul_write_status(processor, status, errno);
2031}
2032#endif
2033
2034#if defined(HAVE_SYS_TERMIO_H) || defined(HAVE_SYS_TERMIOS_H)
2035#define LINUX_NCC 10
2036#define LINUX_NCCS 19
2037
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
2055
2056#define LINUX_IOC_NRBITS 8
2057#define LINUX_IOC_TYPEBITS 8
2058#define LINUX_IOC_SIZEBITS 13
2059#define LINUX_IOC_DIRBITS 3
2060
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)
2065
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)
2070
2071/*
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
2074 * files for us.
2075 */
2076#define LINUX_IOC_NONE 1U
2077#define LINUX_IOC_READ 2U
2078#define LINUX_IOC_WRITE 4U
2079
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))
2085
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))
2091#endif
2092
2093#ifdef HAVE_SYS_TERMIO_H
2094/* Convert to/from host termio structure */
2095
2096struct 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 */
2103};
2104
2105STATIC_INLINE_EMUL_UNIX void
2106convert_to_linux_termio(unsigned_word addr,
2107 struct termio *host,
2108 cpu *processor,
2109 unsigned_word cia)
2110{
2111 struct linux_termio target;
2112 int i;
2113
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;
2119
2120 for (i = 0; i < LINUX_NCC; i++)
2121 target.c_cc[i] = 0;
2122
2123#ifdef VINTR
2124 target.c_cc[LINUX_VINTR] = host->c_cc[VINTR];
2125#endif
2126
2127#ifdef VQUIT
2128 target.c_cc[LINUX_VQUIT] = host->c_cc[VQUIT];
2129#endif
2130
2131#ifdef VERASE
2132 target.c_cc[LINUX_VERASE] = host->c_cc[VERASE];
2133#endif
2134
2135#ifdef VKILL
2136 target.c_cc[LINUX_VKILL] = host->c_cc[VKILL];
2137#endif
2138
2139#ifdef VEOF
2140 target.c_cc[LINUX_VEOF] = host->c_cc[VEOF];
2141#endif
2142
2143#ifdef VMIN
2144 target.c_cc[LINUX_VMIN] = host->c_cc[VMIN];
2145#endif
2146
2147#ifdef VEOL
2148 target.c_cc[LINUX_VEOL] = host->c_cc[VEOL];
2149#endif
2150
2151#ifdef VTIME
2152 target.c_cc[LINUX_VTIME] = host->c_cc[VTIME];
2153#endif
2154
2155#ifdef VEOL2
2156 target.c_cc[LINUX_VEOL2] = host->c_cc[VEOL2];
2157#endif
2158
2159#ifdef VSWTC
2160 target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTC];
2161#endif
2162
2163#ifdef VSWTCH
2164 target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTCH];
2165#endif
2166
2167 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
2168}
2169#endif /* HAVE_SYS_TERMIO_H */
2170
2171#ifdef HAVE_SYS_TERMIOS_H
2172/* Convert to/from host termios structure */
2173
2174typedef unsigned32 linux_tcflag_t;
2175typedef unsigned8 linux_cc_t;
2176typedef unsigned32 linux_speed_t;
2177
2178struct 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];
2184 linux_cc_t c_line;
2185 signed32 c_ispeed;
2186 signed32 c_ospeed;
2187};
2188
2189STATIC_INLINE_EMUL_UNIX void
2190convert_to_linux_termios(unsigned_word addr,
2191 struct termios *host,
2192 cpu *processor,
2193 unsigned_word cia)
2194{
2195 struct linux_termios target;
2196 int i;
2197
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);
2202
2203 for (i = 0; i < LINUX_NCCS; i++)
2204 target.c_cc[i] = 0;
2205
2206#ifdef VINTR
2207 target.c_cc[LINUX_VINTR] = host->c_cc[VINTR];
2208#endif
2209
2210#ifdef VQUIT
2211 target.c_cc[LINUX_VQUIT] = host->c_cc[VQUIT];
2212#endif
2213
2214#ifdef VERASE
2215 target.c_cc[LINUX_VERASE] = host->c_cc[VERASE];
2216#endif
2217
2218#ifdef VKILL
2219 target.c_cc[LINUX_VKILL] = host->c_cc[VKILL];
2220#endif
2221
2222#ifdef VEOF
2223 target.c_cc[LINUX_VEOF] = host->c_cc[VEOF];
2224#endif
2225
2226#ifdef VEOL
2227 target.c_cc[LINUX_VEOL] = host->c_cc[VEOL];
2228#endif
2229
2230#ifdef VEOL2
2231 target.c_cc[LINUX_VEOL2] = host->c_cc[VEOL2];
2232#endif
2233
2234#ifdef VSWTCH
2235 target.c_cc[LINUX_VSWTCH] = host->c_cc[VSWTCH];
2236#endif
2237
2238 target.c_line = 0;
2239
2240#ifdef HAVE_CFGETISPEED
2241 target.c_ispeed = cfgetispeed (host);
2242#else
2243 target.c_ispeed = 0;
2244#endif
2245
2246#ifdef HAVE_CFGETOSPEED
2247 target.c_ospeed = cfgetospeed (host);
2248#else
2249 target.c_ospeed = 0;
2250#endif
2251
2252 emul_write_buffer(&target, addr, sizeof(target), processor, cia);
2253}
2254#endif /* HAVE_SYS_TERMIOS_H */
2255
2256#ifndef HAVE_IOCTL
2257#define do_linux_ioctl 0
2258#else
2259static void
2260do_linux_ioctl(os_emul_data *emul,
2261 unsigned call,
2262 const int arg0,
2263 cpu *processor,
2264 unsigned_word cia)
2265{
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];
2269 int status = 0;
2270 const char *name = "<unknown>";
2271
2272#ifdef HAVE_SYS_TERMIO_H
2273 struct termio host_termio;
2274#endif
2275
2276#ifdef HAVE_SYS_TERMIOS_H
2277 struct termios host_termios;
2278#endif
2279
2280 switch (request)
2281 {
2282 case 0: /* make sure we have at least one case */
2283 default:
2284 status = -1;
2285 errno = EINVAL;
2286 break;
2287
2288#ifdef HAVE_SYS_TERMIO_H
2289#ifdef TCGETA
2290 case LINUX_IOR('t', 23, struct linux_termio): /* TCGETA */
2291 name = "TCGETA";
2292 status = ioctl (fildes, TCGETA, &host_termio);
2293 if (status == 0)
2294 convert_to_linux_termio (argp_addr, &host_termio, processor, cia);
2295 break;
2296#endif /* TCGETA */
2297#endif /* HAVE_SYS_TERMIO_H */
2298
2299#ifdef HAVE_SYS_TERMIOS_H
2300#if defined(TCGETS) || defined(HAVE_TCGETATTR)
2301 case LINUX_IOR('t', 19, struct linux_termios): /* TCGETS */
2302 name = "TCGETS";
2303#ifdef HAVE_TCGETATTR
2304 status = tcgetattr(fildes, &host_termios);
2305#else
2306 status = ioctl (fildes, TCGETS, &host_termios);
2307#endif
2308 if (status == 0)
2309 convert_to_linux_termios (argp_addr, &host_termios, processor, cia);
2310 break;
2311#endif /* TCGETS */
2312#endif /* HAVE_SYS_TERMIOS_H */
2313 }
2314
2315 emul_write_status(processor, status, errno);
2316
2317 if (WITH_TRACE && ppc_trace[trace_os_emul])
2318 printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);
2319}
2320#endif /* HAVE_IOCTL */
2321
2322static 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" },
5b18a1a0 2336 /* 13 */ { do_unix_time, "time" },
88f1eac4
MM
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" },
5b18a1a0
MM
2400 /* 77 */ { do_unix_getrusage, "getrusage" },
2401 /* 78 */ { do_unix_gettimeofday, "gettimeofday" },
88f1eac4
MM
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" },
2485};
2486
2487static char *(linux_error_names[]) = {
2488 /* 0 */ "ESUCCESS",
2489 /* 1 */ "EPERM",
2490 /* 2 */ "ENOENT",
2491 /* 3 */ "ESRCH",
2492 /* 4 */ "EINTR",
2493 /* 5 */ "EIO",
2494 /* 6 */ "ENXIO",
2495 /* 7 */ "E2BIG",
2496 /* 8 */ "ENOEXEC",
2497 /* 9 */ "EBADF",
2498 /* 10 */ "ECHILD",
2499 /* 11 */ "EAGAIN",
2500 /* 12 */ "ENOMEM",
2501 /* 13 */ "EACCES",
2502 /* 14 */ "EFAULT",
2503 /* 15 */ "ENOTBLK",
2504 /* 16 */ "EBUSY",
2505 /* 17 */ "EEXIST",
2506 /* 18 */ "EXDEV",
2507 /* 19 */ "ENODEV",
2508 /* 20 */ "ENOTDIR",
2509 /* 21 */ "EISDIR",
2510 /* 22 */ "EINVAL",
2511 /* 23 */ "ENFILE",
2512 /* 24 */ "EMFILE",
2513 /* 25 */ "ENOTTY",
2514 /* 26 */ "ETXTBSY",
2515 /* 27 */ "EFBIG",
2516 /* 28 */ "ENOSPC",
2517 /* 29 */ "ESPIPE",
2518 /* 30 */ "EROFS",
2519 /* 31 */ "EMLINK",
2520 /* 32 */ "EPIPE",
2521 /* 33 */ "EDOM",
2522 /* 34 */ "ERANGE",
2523 /* 35 */ "EDEADLK",
2524 /* 36 */ "ENAMETOOLONG",
2525 /* 37 */ "ENOLCK",
2526 /* 38 */ "ENOSYS",
2527 /* 39 */ "ENOTEMPTY",
2528 /* 40 */ "ELOOP",
2529 /* 41 */ 0,
2530 /* 42 */ "ENOMSG",
2531 /* 43 */ "EIDRM",
2532 /* 44 */ "ECHRNG",
2533 /* 45 */ "EL2NSYNC",
2534 /* 46 */ "EL3HLT",
2535 /* 47 */ "EL3RST",
2536 /* 48 */ "ELNRNG",
2537 /* 49 */ "EUNATCH",
2538 /* 50 */ "ENOCSI",
2539 /* 51 */ "EL2HLT",
2540 /* 52 */ "EBADE",
2541 /* 53 */ "EBADR",
2542 /* 54 */ "EXFULL",
2543 /* 55 */ "ENOANO",
2544 /* 56 */ "EBADRQC",
2545 /* 57 */ "EBADSLT",
2546 /* 58 */ "EDEADLOCK",
2547 /* 59 */ "EBFONT",
2548 /* 60 */ "ENOSTR",
2549 /* 61 */ "ENODATA",
2550 /* 62 */ "ETIME",
2551 /* 63 */ "ENOSR",
2552 /* 64 */ "ENONET",
2553 /* 65 */ "ENOPKG",
2554 /* 66 */ "EREMOTE",
2555 /* 67 */ "ENOLINK",
2556 /* 68 */ "EADV",
2557 /* 69 */ "ESRMNT",
2558 /* 70 */ "ECOMM",
2559 /* 71 */ "EPROTO",
2560 /* 72 */ "EMULTIHOP",
2561 /* 73 */ "EDOTDOT",
2562 /* 74 */ "EBADMSG",
2563 /* 75 */ "EOVERFLOW",
2564 /* 76 */ "ENOTUNIQ",
2565 /* 77 */ "EBADFD",
2566 /* 78 */ "EREMCHG",
2567 /* 79 */ "ELIBACC",
2568 /* 80 */ "ELIBBAD",
2569 /* 81 */ "ELIBSCN",
2570 /* 82 */ "ELIBMAX",
2571 /* 83 */ "ELIBEXEC",
2572 /* 84 */ "EILSEQ",
2573 /* 85 */ "ERESTART",
2574 /* 86 */ "ESTRPIPE",
2575 /* 87 */ "EUSERS",
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",
2604 /* 116 */ "ESTALE",
2605 /* 117 */ "EUCLEAN",
2606 /* 118 */ "ENOTNAM",
2607 /* 119 */ "ENAVAIL",
2608 /* 120 */ "EISNAM",
2609 /* 121 */ "EREMOTEIO",
2610 /* 122 */ "EDQUOT",
2611};
2612
2613static char *(linux_signal_names[]) = {
2614 /* 0 */ 0,
2615 /* 1 */ "SIGHUP",
2616 /* 2 */ "SIGINT",
2617 /* 3 */ "SIGQUIT",
2618 /* 4 */ "SIGILL",
2619 /* 5 */ "SIGTRAP",
2620 /* 6 */ "SIGABRT",
2621 /* 6 */ "SIGIOT",
2622 /* 7 */ "SIGBUS",
2623 /* 8 */ "SIGFPE",
2624 /* 9 */ "SIGKILL",
2625 /* 10 */ "SIGUSR1",
2626 /* 11 */ "SIGSEGV",
2627 /* 12 */ "SIGUSR2",
2628 /* 13 */ "SIGPIPE",
2629 /* 14 */ "SIGALRM",
2630 /* 15 */ "SIGTERM",
2631 /* 16 */ "SIGSTKFLT",
2632 /* 17 */ "SIGCHLD",
2633 /* 18 */ "SIGCONT",
2634 /* 19 */ "SIGSTOP",
2635 /* 20 */ "SIGTSTP",
2636 /* 21 */ "SIGTTIN",
2637 /* 22 */ "SIGTTOU",
2638 /* 23 */ "SIGURG",
2639 /* 24 */ "SIGXCPU",
2640 /* 25 */ "SIGXFSZ",
2641 /* 26 */ "SIGVTALRM",
2642 /* 27 */ "SIGPROF",
2643 /* 28 */ "SIGWINCH",
2644 /* 29 */ "SIGIO",
2645 /* 30 */ "SIGPWR",
2646 /* 31 */ "SIGUNUSED",
2647};
2648
2649static emul_syscall emul_linux_syscalls = {
2650 linux_descriptors,
2651 sizeof(linux_descriptors) / sizeof(linux_descriptors[0]),
2652 linux_error_names,
2653 sizeof(linux_error_names) / sizeof(linux_error_names[0]),
2654 linux_signal_names,
2655 sizeof(linux_signal_names) / sizeof(linux_signal_names[0]),
2656};
2657
2658
2659/* Linux's os_emul interface, most are just passed on to the generic
2660 syscall stuff */
2661
2662static os_emul_data *
2663emul_linux_create(device *root,
2664 bfd *image,
2665 const char *name)
2666{
2667 /* check that this emulation is really for us */
2668 if (name != NULL && strcmp(name, "linux") != 0)
2669 return NULL;
2670
2671 if (image == NULL)
2672 return NULL;
2673
2674 return emul_unix_create(root, image, "linux", &emul_linux_syscalls);
2675}
2676
2677static void
2678emul_linux_init(os_emul_data *emul_data,
2679 int nr_cpus)
2680{
2681 /* nothing yet */
2682}
2683
2684static void
2685emul_linux_system_call(cpu *processor,
2686 unsigned_word cia,
2687 os_emul_data *emul_data)
2688{
2689 emul_do_system_call(emul_data,
2690 emul_data->syscalls,
2691 cpu_registers(processor)->gpr[0],
2692 3, /*r3 contains arg0*/
2693 processor,
2694 cia);
2695}
2696
2697const os_emul emul_linux = {
2698 "linux",
2699 emul_linux_create,
2700 emul_linux_init,
2701 emul_linux_system_call,
2702 0, /*instruction_call*/
2703 0 /*data*/
2704};
2705
2706#endif /* _EMUL_UNIX_C_ */
This page took 0.197514 seconds and 4 git commands to generate.