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