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