Commit | Line | Data |
---|---|---|
c143ef62 MM |
1 | /* This file is part of the program psim. |
2 | ||
7393a6f0 | 3 | Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au> |
c143ef62 MM |
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_NETBSD_C_ | |
23 | #define _EMUL_NETBSD_C_ | |
24 | ||
93fac324 MM |
25 | |
26 | /* Note: this module is called via a table. There is no benefit in | |
27 | making it inline */ | |
28 | ||
c494cadd | 29 | #include "emul_generic.h" |
93fac324 | 30 | #include "emul_netbsd.h" |
c494cadd MM |
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 | ||
c143ef62 MM |
40 | #include <sys/types.h> |
41 | #include <sys/stat.h> | |
42 | #include <stdio.h> | |
c143ef62 MM |
43 | #include <signal.h> |
44 | #include <fcntl.h> | |
c143ef62 MM |
45 | #include <sys/errno.h> |
46 | #include <sys/param.h> | |
47 | #include <sys/time.h> | |
eada1efc MM |
48 | |
49 | #ifdef HAVE_GETRUSAGE | |
50 | #ifndef HAVE_SYS_RESOURCE_H | |
51 | #undef HAVE_GETRUSAGE | |
52 | #endif | |
53 | #endif | |
54 | ||
55 | #ifdef HAVE_GETRUSAGE | |
c143ef62 | 56 | #include <sys/resource.h> |
93fac324 | 57 | int getrusage(); |
eada1efc | 58 | #endif |
93fac324 | 59 | |
c143ef62 MM |
60 | #include <sys/ioctl.h> |
61 | #include <sys/mount.h> | |
7393a6f0 MM |
62 | |
63 | #if HAVE_DIRENT_H | |
64 | # include <dirent.h> | |
65 | # define NAMLEN(dirent) strlen((dirent)->d_name) | |
66 | #else | |
67 | # define dirent direct | |
68 | # define NAMLEN(dirent) (dirent)->d_namlen | |
69 | # if HAVE_SYS_NDIR_H | |
70 | # include <sys/ndir.h> | |
71 | # endif | |
72 | # if HAVE_SYS_DIR_H | |
73 | # include <sys/dir.h> | |
74 | # endif | |
75 | # if HAVE_NDIR_H | |
76 | # include <ndir.h> | |
77 | # endif | |
78 | #endif | |
c143ef62 | 79 | |
c494cadd MM |
80 | #ifdef HAVE_UNISTD_H |
81 | #include <unistd.h> | |
82 | #endif | |
83 | ||
84 | #ifdef HAVE_STDLIB_H | |
85 | #include <stdlib.h> | |
86 | #endif | |
87 | ||
c143ef62 MM |
88 | #define WITH_NetBSD_HOST (NetBSD >= 199306) |
89 | #if WITH_NetBSD_HOST /* here NetBSD as that is what we're emulating */ | |
90 | #include <sys/syscall.h> /* FIXME - should not be including this one */ | |
91 | #include <sys/sysctl.h> | |
92 | extern int getdirentries(int fd, char *buf, int nbytes, long *basep); | |
93 | #endif | |
94 | ||
95 | #if (BSD < 199306) /* here BSD as just a bug */ | |
96 | extern int errno; | |
97 | #endif | |
98 | ||
c143ef62 MM |
99 | #ifndef STATIC_INLINE_EMUL_NETBSD |
100 | #define STATIC_INLINE_EMUL_NETBSD STATIC_INLINE | |
101 | #endif | |
102 | ||
103 | ||
104 | #if WITH_NetBSD_HOST | |
105 | #define SYS(X) ASSERT(call == (SYS_##X)) | |
106 | #else | |
107 | #define SYS(X) | |
108 | #endif | |
109 | ||
110 | #if WITH_NetBSD_HOST && (PATH_MAX != 1024) | |
111 | #error "PATH_MAX not 1024" | |
112 | #elif !defined(PATH_MAX) | |
113 | #define PATH_MAX 1024 | |
114 | #endif | |
115 | ||
116 | ||
93fac324 MM |
117 | /* NetBSD's idea of what is needed to implement emulations */ |
118 | ||
119 | struct _os_emul_data { | |
7393a6f0 | 120 | device *vm; |
93fac324 MM |
121 | emul_syscall *syscalls; |
122 | }; | |
123 | ||
124 | ||
125 | ||
c143ef62 MM |
126 | STATIC_INLINE_EMUL_NETBSD void |
127 | write_stat(unsigned_word addr, | |
128 | struct stat buf, | |
129 | cpu *processor, | |
130 | unsigned_word cia) | |
131 | { | |
132 | H2T(buf.st_dev); | |
133 | H2T(buf.st_ino); | |
134 | H2T(buf.st_mode); | |
135 | H2T(buf.st_nlink); | |
136 | H2T(buf.st_uid); | |
137 | H2T(buf.st_gid); | |
138 | H2T(buf.st_rdev); | |
139 | H2T(buf.st_size); | |
140 | H2T(buf.st_atime); | |
141 | /* H2T(buf.st_spare1); */ | |
142 | H2T(buf.st_mtime); | |
143 | /* H2T(buf.st_spare2); */ | |
144 | H2T(buf.st_ctime); | |
145 | /* H2T(buf.st_spare3); */ | |
146 | H2T(buf.st_blksize); | |
147 | H2T(buf.st_blocks); | |
148 | #if WITH_NetBSD_HOST | |
149 | H2T(buf.st_flags); | |
150 | H2T(buf.st_gen); | |
151 | #endif | |
152 | emul_write_buffer(&buf, addr, sizeof(buf), processor, cia); | |
153 | } | |
154 | ||
155 | ||
156 | #if NetBSD | |
157 | STATIC_INLINE_EMUL_NETBSD void | |
158 | write_statfs(unsigned_word addr, | |
159 | struct statfs buf, | |
160 | cpu *processor, | |
161 | unsigned_word cia) | |
162 | { | |
163 | H2T(buf.f_type); | |
164 | H2T(buf.f_flags); | |
165 | H2T(buf.f_bsize); | |
166 | H2T(buf.f_iosize); | |
167 | H2T(buf.f_blocks); | |
168 | H2T(buf.f_bfree); | |
169 | H2T(buf.f_bavail); | |
170 | H2T(buf.f_files); | |
171 | H2T(buf.f_ffree); | |
172 | H2T(buf.f_fsid.val[0]); | |
173 | H2T(buf.f_fsid.val[1]); | |
174 | H2T(buf.f_owner); | |
175 | /* f_spare[4]; */ | |
176 | /* f_fstypename[MFSNAMELEN]; */ | |
177 | /* f_mntonname[MNAMELEN]; */ | |
178 | /* f_mntfromname[MNAMELEN]; */ | |
179 | emul_write_buffer(&buf, addr, sizeof(buf), processor, cia); | |
180 | } | |
181 | #endif | |
182 | ||
183 | ||
184 | STATIC_INLINE_EMUL_NETBSD void | |
185 | write_timeval(unsigned_word addr, | |
186 | struct timeval t, | |
187 | cpu *processor, | |
188 | unsigned_word cia) | |
189 | { | |
190 | H2T(t.tv_sec); | |
191 | H2T(t.tv_usec); | |
192 | emul_write_buffer(&t, addr, sizeof(t), processor, cia); | |
193 | } | |
194 | ||
195 | ||
196 | STATIC_INLINE_EMUL_NETBSD void | |
197 | write_timezone(unsigned_word addr, | |
198 | struct timezone tz, | |
199 | cpu *processor, | |
200 | unsigned_word cia) | |
201 | { | |
202 | H2T(tz.tz_minuteswest); | |
203 | H2T(tz.tz_dsttime); | |
204 | emul_write_buffer(&tz, addr, sizeof(tz), processor, cia); | |
205 | } | |
206 | ||
207 | ||
208 | #if WITH_NetBSD_HOST | |
209 | STATIC_INLINE_EMUL_NETBSD void | |
210 | write_direntries(unsigned_word addr, | |
211 | char *buf, | |
212 | int nbytes, | |
213 | cpu *processor, | |
214 | unsigned_word cia) | |
215 | { | |
216 | while (nbytes > 0) { | |
217 | struct dirent *out; | |
218 | struct dirent *in = (struct dirent*)buf; | |
219 | ASSERT(in->d_reclen <= nbytes); | |
220 | out = (struct dirent*)zalloc(in->d_reclen); | |
93fac324 | 221 | memcpy(out/*dest*/, in/*src*/, in->d_reclen); |
c143ef62 MM |
222 | H2T(out->d_fileno); |
223 | H2T(out->d_reclen); | |
224 | H2T(out->d_type); | |
225 | H2T(out->d_namlen); | |
226 | emul_write_buffer(out, addr, in->d_reclen, processor, cia); | |
227 | nbytes -= in->d_reclen; | |
228 | addr += in->d_reclen; | |
229 | buf += in->d_reclen; | |
230 | zfree(out); | |
231 | } | |
232 | } | |
233 | #endif | |
234 | ||
235 | ||
eada1efc | 236 | #ifdef HAVE_GETRUSAGE |
c143ef62 MM |
237 | STATIC_INLINE_EMUL_NETBSD void |
238 | write_rusage(unsigned_word addr, | |
239 | struct rusage rusage, | |
240 | cpu *processor, | |
241 | unsigned_word cia) | |
242 | { | |
243 | H2T(rusage.ru_utime.tv_sec); /* user time used */ | |
244 | H2T(rusage.ru_utime.tv_usec); | |
245 | H2T(rusage.ru_stime.tv_sec); /* system time used */ | |
246 | H2T(rusage.ru_stime.tv_usec); | |
247 | H2T(rusage.ru_maxrss); /* integral max resident set size */ | |
248 | H2T(rusage.ru_ixrss); /* integral shared text memory size */ | |
249 | H2T(rusage.ru_idrss); /* integral unshared data size */ | |
250 | H2T(rusage.ru_isrss); /* integral unshared stack size */ | |
251 | H2T(rusage.ru_minflt); /* page reclaims */ | |
252 | H2T(rusage.ru_majflt); /* page faults */ | |
253 | H2T(rusage.ru_nswap); /* swaps */ | |
254 | H2T(rusage.ru_inblock); /* block input operations */ | |
255 | H2T(rusage.ru_oublock); /* block output operations */ | |
256 | H2T(rusage.ru_msgsnd); /* messages sent */ | |
257 | H2T(rusage.ru_msgrcv); /* messages received */ | |
258 | H2T(rusage.ru_nsignals); /* signals received */ | |
259 | H2T(rusage.ru_nvcsw); /* voluntary context switches */ | |
260 | H2T(rusage.ru_nivcsw); /* involuntary context switches */ | |
261 | emul_write_buffer(&rusage, addr, sizeof(rusage), processor, cia); | |
262 | } | |
eada1efc | 263 | #endif |
c143ef62 | 264 | |
93fac324 MM |
265 | static void |
266 | do_exit(os_emul_data *emul, | |
c143ef62 MM |
267 | unsigned call, |
268 | const int arg0, | |
269 | cpu *processor, | |
270 | unsigned_word cia) | |
271 | { | |
272 | int status = (int)cpu_registers(processor)->gpr[arg0]; | |
273 | SYS(exit); | |
274 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
275 | printf_filtered ("%d)\n", status); | |
276 | ||
277 | cpu_halt(processor, cia, was_exited, status); | |
278 | } | |
279 | ||
280 | ||
93fac324 MM |
281 | static void |
282 | do_read(os_emul_data *emul, | |
c143ef62 MM |
283 | unsigned call, |
284 | const int arg0, | |
285 | cpu *processor, | |
286 | unsigned_word cia) | |
287 | { | |
288 | void *scratch_buffer; | |
289 | int d = (int)cpu_registers(processor)->gpr[arg0]; | |
290 | unsigned_word buf = cpu_registers(processor)->gpr[arg0+1]; | |
291 | int nbytes = cpu_registers(processor)->gpr[arg0+2]; | |
292 | int status; | |
c143ef62 MM |
293 | SYS(read); |
294 | ||
295 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
296 | printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes); | |
297 | ||
298 | /* get a tempoary bufer */ | |
299 | scratch_buffer = zalloc(nbytes); | |
300 | ||
301 | /* check if buffer exists by reading it */ | |
302 | emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia); | |
303 | ||
304 | /* read */ | |
305 | #if 0 | |
306 | if (d == 0) { | |
307 | status = fread (scratch_buffer, 1, nbytes, stdin); | |
308 | if (status == 0 && ferror (stdin)) | |
309 | status = -1; | |
310 | } | |
311 | #endif | |
312 | status = read (d, scratch_buffer, nbytes); | |
313 | ||
314 | if (status == -1) { | |
315 | cpu_registers(processor)->gpr[0] = errno; | |
316 | } else { | |
317 | cpu_registers(processor)->gpr[3] = status; | |
318 | ||
319 | if (status > 0) | |
320 | emul_write_buffer(scratch_buffer, buf, status, processor, cia); | |
321 | } | |
322 | ||
323 | zfree(scratch_buffer); | |
324 | } | |
325 | ||
326 | ||
93fac324 MM |
327 | static void |
328 | do_write(os_emul_data *emul, | |
c143ef62 MM |
329 | unsigned call, |
330 | const int arg0, | |
331 | cpu *processor, | |
332 | unsigned_word cia) | |
333 | { | |
334 | void *scratch_buffer = NULL; | |
335 | int nr_moved; | |
336 | int d = (int)cpu_registers(processor)->gpr[arg0]; | |
337 | unsigned_word buf = cpu_registers(processor)->gpr[arg0+1]; | |
338 | int nbytes = cpu_registers(processor)->gpr[arg0+2]; | |
339 | int status; | |
340 | SYS(write); | |
341 | ||
342 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
343 | printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes); | |
344 | ||
345 | /* get a tempoary bufer */ | |
346 | scratch_buffer = zalloc(nbytes); /* FIXME - nbytes == 0 */ | |
347 | ||
348 | /* copy in */ | |
349 | nr_moved = vm_data_map_read_buffer(cpu_data_map(processor), | |
350 | scratch_buffer, | |
351 | buf, | |
352 | nbytes); | |
353 | if (nr_moved != nbytes) { | |
354 | /* FIXME - should handle better */ | |
355 | error("system_call()write copy failed (nr_moved=%d != nbytes=%d)\n", | |
356 | nr_moved, nbytes); | |
357 | } | |
358 | ||
359 | /* write */ | |
360 | status = write(d, scratch_buffer, nbytes); | |
361 | emul_write_status(processor, status, errno); | |
362 | zfree(scratch_buffer); | |
262faa54 MM |
363 | |
364 | flush_stdoutput(); | |
c143ef62 MM |
365 | } |
366 | ||
367 | ||
93fac324 MM |
368 | static void |
369 | do_open(os_emul_data *emul, | |
c143ef62 MM |
370 | unsigned call, |
371 | const int arg0, | |
372 | cpu *processor, | |
373 | unsigned_word cia) | |
374 | { | |
375 | unsigned_word path_addr = cpu_registers(processor)->gpr[arg0]; | |
376 | char path_buf[PATH_MAX]; | |
377 | char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia); | |
378 | int flags = (int)cpu_registers(processor)->gpr[arg0+1]; | |
379 | int mode = (int)cpu_registers(processor)->gpr[arg0+2]; | |
380 | ||
381 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
382 | printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr, path, flags, mode); | |
383 | ||
384 | SYS(open); | |
385 | emul_write_status(processor, open(path, flags, mode), errno); | |
386 | } | |
387 | ||
388 | ||
93fac324 MM |
389 | static void |
390 | do_close(os_emul_data *emul, | |
c143ef62 MM |
391 | unsigned call, |
392 | const int arg0, | |
393 | cpu *processor, | |
394 | unsigned_word cia) | |
395 | { | |
396 | int d = (int)cpu_registers(processor)->gpr[arg0]; | |
397 | ||
398 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
399 | printf_filtered ("%d", d); | |
400 | ||
401 | SYS(close); | |
402 | emul_write_status(processor, close(d), errno); | |
403 | } | |
404 | ||
405 | ||
93fac324 MM |
406 | static void |
407 | do_break(os_emul_data *emul, | |
c143ef62 MM |
408 | unsigned call, |
409 | const int arg0, | |
410 | cpu *processor, | |
411 | unsigned_word cia) | |
c143ef62 | 412 | { |
7393a6f0 | 413 | /* just pass this onto the `vm' device */ |
c143ef62 | 414 | psim *system = cpu_system(processor); |
c143ef62 MM |
415 | |
416 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
417 | printf_filtered ("0x%lx", (long)cpu_registers(processor)->gpr[arg0]); | |
418 | ||
419 | SYS(break); | |
7393a6f0 | 420 | device_ioctl(emul->vm, |
93fac324 MM |
421 | system, |
422 | processor, | |
423 | cia, | |
424 | 0, /*ioctl*/ | |
425 | NULL); /*ioctl-data*/ | |
c143ef62 MM |
426 | } |
427 | ||
428 | ||
93fac324 MM |
429 | static void |
430 | do_getpid(os_emul_data *emul, | |
c143ef62 MM |
431 | unsigned call, |
432 | const int arg0, | |
433 | cpu *processor, | |
434 | unsigned_word cia) | |
435 | { | |
436 | SYS(getpid); | |
437 | cpu_registers(processor)->gpr[3] = (int)getpid(); | |
438 | } | |
439 | ||
440 | ||
93fac324 MM |
441 | static void |
442 | do_getuid(os_emul_data *emul, | |
c143ef62 MM |
443 | unsigned call, |
444 | const int arg0, | |
445 | cpu *processor, | |
446 | unsigned_word cia) | |
447 | { | |
448 | SYS(getuid); | |
449 | cpu_registers(processor)->gpr[3] = (int)getuid(); | |
450 | } | |
451 | ||
452 | ||
93fac324 MM |
453 | static void |
454 | do_geteuid(os_emul_data *emul, | |
c143ef62 MM |
455 | unsigned call, |
456 | const int arg0, | |
457 | cpu *processor, | |
458 | unsigned_word cia) | |
459 | { | |
460 | SYS(geteuid); | |
461 | cpu_registers(processor)->gpr[3] = (int)geteuid(); | |
462 | } | |
463 | ||
464 | ||
93fac324 MM |
465 | static void |
466 | do_kill(os_emul_data *emul, | |
c143ef62 MM |
467 | unsigned call, |
468 | const int arg0, | |
469 | cpu *processor, | |
470 | unsigned_word cia) | |
471 | { | |
472 | pid_t pid = cpu_registers(processor)->gpr[arg0]; | |
473 | int sig = cpu_registers(processor)->gpr[arg0+1]; | |
474 | ||
475 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
476 | printf_filtered ("%d, %d", (int)pid, sig); | |
477 | ||
478 | SYS(kill); | |
93fac324 MM |
479 | printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n", |
480 | (long)cia); | |
c143ef62 MM |
481 | cpu_halt(processor, cia, was_signalled, sig); |
482 | } | |
483 | ||
484 | ||
93fac324 MM |
485 | static void |
486 | do_dup(os_emul_data *emul, | |
c143ef62 MM |
487 | unsigned call, |
488 | const int arg0, | |
489 | cpu *processor, | |
490 | unsigned_word cia) | |
491 | { | |
492 | int oldd = cpu_registers(processor)->gpr[arg0]; | |
493 | int status = dup(oldd); | |
494 | ||
495 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
496 | printf_filtered ("%d", oldd); | |
497 | ||
498 | SYS(dup); | |
499 | emul_write_status(processor, status, errno); | |
500 | } | |
501 | ||
502 | ||
93fac324 MM |
503 | static void |
504 | do_getegid(os_emul_data *emul, | |
c143ef62 MM |
505 | unsigned call, |
506 | const int arg0, | |
507 | cpu *processor, | |
508 | unsigned_word cia) | |
509 | { | |
510 | SYS(getegid); | |
511 | cpu_registers(processor)->gpr[3] = (int)getegid(); | |
512 | } | |
513 | ||
514 | ||
93fac324 MM |
515 | static void |
516 | do_getgid(os_emul_data *emul, | |
c143ef62 MM |
517 | unsigned call, |
518 | const int arg0, | |
519 | cpu *processor, | |
520 | unsigned_word cia) | |
521 | { | |
522 | SYS(getgid); | |
523 | cpu_registers(processor)->gpr[3] = (int)getgid(); | |
524 | } | |
525 | ||
526 | ||
93fac324 MM |
527 | static void |
528 | do_sigprocmask(os_emul_data *emul, | |
c143ef62 MM |
529 | unsigned call, |
530 | const int arg0, | |
531 | cpu *processor, | |
532 | unsigned_word cia) | |
533 | { | |
534 | natural_word how = cpu_registers(processor)->gpr[arg0]; | |
535 | unsigned_word set = cpu_registers(processor)->gpr[arg0+1]; | |
536 | unsigned_word oset = cpu_registers(processor)->gpr[arg0+2]; | |
537 | SYS(sigprocmask); | |
538 | ||
539 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
540 | printf_filtered ("%ld, 0x%ld, 0x%ld", (long)how, (long)set, (long)oset); | |
541 | ||
542 | cpu_registers(processor)->gpr[3] = 0; | |
543 | cpu_registers(processor)->gpr[4] = set; | |
544 | } | |
545 | ||
546 | ||
93fac324 MM |
547 | static void |
548 | do_ioctl(os_emul_data *emul, | |
c143ef62 MM |
549 | unsigned call, |
550 | const int arg0, | |
551 | cpu *processor, | |
552 | unsigned_word cia) | |
553 | { | |
554 | int d = cpu_registers(processor)->gpr[arg0]; | |
555 | unsigned request = cpu_registers(processor)->gpr[arg0+1]; | |
556 | unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2]; | |
557 | ||
558 | #if !WITH_NetBSD_HOST | |
559 | cpu_registers(processor)->gpr[arg0] = 0; /* just succeed */ | |
560 | #else | |
c143ef62 | 561 | unsigned dir = request & IOC_DIRMASK; |
c143ef62 MM |
562 | int status; |
563 | SYS(ioctl); | |
564 | /* what we haven't done */ | |
565 | if (dir & IOC_IN /* write into the io device */ | |
566 | || dir & IOC_OUT | |
567 | || !(dir & IOC_VOID)) | |
568 | error("do_ioctl() read or write of parameter not implemented\n"); | |
569 | status = ioctl(d, request, NULL); | |
570 | emul_write_status(processor, status, errno); | |
571 | #endif | |
572 | ||
573 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
574 | printf_filtered ("%d, 0x%x, 0x%lx", d, request, (long)argp_addr); | |
575 | } | |
576 | ||
577 | ||
93fac324 MM |
578 | static void |
579 | do_umask(os_emul_data *emul, | |
c143ef62 MM |
580 | unsigned call, |
581 | const int arg0, | |
582 | cpu *processor, | |
583 | unsigned_word cia) | |
584 | { | |
585 | int mask = cpu_registers(processor)->gpr[arg0]; | |
586 | ||
587 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
588 | printf_filtered ("0%o", mask); | |
589 | ||
590 | SYS(umask); | |
591 | cpu_registers(processor)->gpr[3] = umask(mask); | |
592 | } | |
593 | ||
594 | ||
93fac324 MM |
595 | static void |
596 | do_dup2(os_emul_data *emul, | |
c143ef62 MM |
597 | unsigned call, |
598 | const int arg0, | |
599 | cpu *processor, | |
600 | unsigned_word cia) | |
601 | { | |
602 | int oldd = cpu_registers(processor)->gpr[arg0]; | |
603 | int newd = cpu_registers(processor)->gpr[arg0+1]; | |
604 | int status = dup2(oldd, newd); | |
605 | ||
606 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
607 | printf_filtered ("%d, %d", oldd, newd); | |
608 | ||
609 | SYS(dup2); | |
610 | emul_write_status(processor, status, errno); | |
611 | } | |
612 | ||
613 | ||
93fac324 MM |
614 | static void |
615 | do_fcntl(os_emul_data *emul, | |
c143ef62 MM |
616 | unsigned call, |
617 | const int arg0, | |
618 | cpu *processor, | |
619 | unsigned_word cia) | |
620 | { | |
621 | int fd = cpu_registers(processor)->gpr[arg0]; | |
622 | int cmd = cpu_registers(processor)->gpr[arg0+1]; | |
623 | int arg = cpu_registers(processor)->gpr[arg0+2]; | |
624 | int status; | |
625 | ||
626 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
627 | printf_filtered ("%d, %d, %d", fd, cmd, arg); | |
628 | ||
629 | SYS(fcntl); | |
630 | status = fcntl(fd, cmd, arg); | |
631 | emul_write_status(processor, status, errno); | |
632 | } | |
633 | ||
634 | ||
93fac324 MM |
635 | static void |
636 | do_gettimeofday(os_emul_data *emul, | |
c143ef62 MM |
637 | unsigned call, |
638 | const int arg0, | |
639 | cpu *processor, | |
640 | unsigned_word cia) | |
641 | { | |
642 | unsigned_word t_addr = cpu_registers(processor)->gpr[arg0]; | |
643 | unsigned_word tz_addr = cpu_registers(processor)->gpr[arg0+1]; | |
644 | struct timeval t; | |
645 | struct timezone tz; | |
646 | int status = gettimeofday((t_addr != 0 ? &t : NULL), | |
647 | (tz_addr != 0 ? &tz : NULL)); | |
648 | ||
649 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
650 | printf_filtered ("0x%lx, 0x%lx", (long)t_addr, (long)tz_addr); | |
651 | ||
652 | SYS(gettimeofday); | |
653 | emul_write_status(processor, status, errno); | |
654 | if (status == 0) { | |
655 | if (t_addr != 0) | |
656 | write_timeval(t_addr, t, processor, cia); | |
657 | if (tz_addr != 0) | |
658 | write_timezone(tz_addr, tz, processor, cia); | |
659 | } | |
660 | } | |
661 | ||
662 | ||
eada1efc MM |
663 | #ifndef HAVE_GETRUSAGE |
664 | #define do_getrusage 0 | |
665 | #else | |
93fac324 MM |
666 | static void |
667 | do_getrusage(os_emul_data *emul, | |
c143ef62 MM |
668 | unsigned call, |
669 | const int arg0, | |
670 | cpu *processor, | |
671 | unsigned_word cia) | |
672 | { | |
673 | int who = cpu_registers(processor)->gpr[arg0]; | |
674 | unsigned_word rusage_addr = cpu_registers(processor)->gpr[arg0+1]; | |
675 | struct rusage rusage; | |
676 | int status = getrusage(who, (rusage_addr != 0 ? &rusage : NULL)); | |
677 | ||
678 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
679 | printf_filtered ("%d, 0x%lx", who, (long)rusage_addr); | |
680 | ||
681 | SYS(getrusage); | |
682 | emul_write_status(processor, status, errno); | |
683 | if (status == 0) { | |
684 | if (rusage_addr != 0) | |
685 | write_rusage(rusage_addr, rusage, processor, cia); | |
686 | } | |
687 | } | |
eada1efc | 688 | #endif |
c143ef62 MM |
689 | |
690 | ||
691 | #if !WITH_NetBSD_HOST | |
692 | #define do_fstatfs 0 | |
693 | #else | |
93fac324 MM |
694 | static void |
695 | do_fstatfs(os_emul_data *emul, | |
c143ef62 MM |
696 | unsigned call, |
697 | const int arg0, | |
698 | cpu *processor, | |
699 | unsigned_word cia) | |
700 | { | |
701 | int fd = cpu_registers(processor)->gpr[arg0]; | |
702 | unsigned_word buf_addr = cpu_registers(processor)->gpr[arg0+1]; | |
703 | struct statfs buf; | |
704 | int status; | |
705 | ||
706 | if (WITH_TRACE && ppc_trace[trace_os_emul]) | |
707 | printf_filtered ("%d, 0x%lx", fd, (long)buf_addr); | |
708 | ||
709 | SYS(fstatfs); | |
710 | status = fstatfs(fd, (buf_addr == 0 ? NULL : &buf)); | |
711 | emul_write_status(processor, status, errno); | |
712 | if (status == 0) { | |
713 | if (buf_addr != 0) | |
714 | write_statfs(buf_addr, buf, processor, cia); | |
715 | } | |
716 | } | |
717 | #endif | |
718 | ||
719 | ||
93fac324 MM |
720 | static void |
721 | do_stat(os_emul_data *emul, | |
c143ef62 MM |
722 | unsigned call, |
723 | const int arg0, | |
724 | cpu *processor, | |
725 | unsigned_word cia) | |
726 | { | |
727 | char path_buf[PATH_MAX]; | |
728 | unsigned_word path_addr = cpu_registers(processor)->gpr[arg0]; | |
729 | unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1]; | |
730 | char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia); | |
731 | struct stat buf; | |
732 | int status; | |
733 | SYS(stat); | |
734 | status = stat(path, &buf); | |
735 | emul_write_status(processor, status, errno); | |
736 | if (status == 0) | |
737 | write_stat(stat_buf_addr, buf, processor, cia); | |
738 | } | |
739 | ||
740 | ||
93fac324 MM |
741 | static void |
742 | do_fstat(os_emul_data *emul, | |
c143ef62 MM |
743 | unsigned call, |
744 | const int arg0, | |
745 | cpu *processor, | |
746 | unsigned_word cia) | |
747 | { | |
748 | int fd = cpu_registers(processor)->gpr[arg0]; | |
749 | unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1]; | |
750 | struct stat buf; | |
751 | SYS(fstat); | |
752 | emul_write_status(processor, fstat(fd, &buf), errno); | |
753 | write_stat(stat_buf_addr, buf, processor, cia); | |
754 | } | |
755 | ||
756 | ||
93fac324 MM |
757 | static void |
758 | do_lstat(os_emul_data *emul, | |
c143ef62 MM |
759 | unsigned call, |
760 | const int arg0, | |
761 | cpu *processor, | |
762 | unsigned_word cia) | |
763 | { | |
764 | char path_buf[PATH_MAX]; | |
765 | unsigned_word path_addr = cpu_registers(processor)->gpr[arg0]; | |
766 | char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia); | |
767 | unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1]; | |
768 | struct stat buf; | |
769 | SYS(lstat); | |
770 | emul_write_status(processor, stat(path, &buf), errno); | |
771 | write_stat(stat_buf_addr, buf, processor, cia); | |
772 | } | |
773 | ||
774 | ||
775 | #if !WITH_NetBSD_HOST | |
776 | #define do_getdirentries 0 | |
777 | #else | |
93fac324 MM |
778 | static void |
779 | do_getdirentries(os_emul_data *emul, | |
c143ef62 MM |
780 | unsigned call, |
781 | const int arg0, | |
782 | cpu *processor, | |
783 | unsigned_word cia) | |
784 | { | |
785 | int fd = cpu_registers(processor)->gpr[arg0]; | |
786 | unsigned_word buf_addr = cpu_registers(processor)->gpr[arg0+1]; | |
787 | char *buf; | |
788 | int nbytes = cpu_registers(processor)->gpr[arg0+2]; | |
789 | unsigned_word basep_addr = cpu_registers(processor)->gpr[arg0+3]; | |
790 | long basep; | |
791 | int status; | |
792 | SYS(getdirentries); | |
793 | if (buf_addr != 0 && nbytes >= 0) | |
794 | buf = zalloc(nbytes); | |
795 | else | |
796 | buf = NULL; | |
797 | status = getdirentries(fd, | |
798 | (buf_addr == 0 ? NULL : buf), | |
799 | nbytes, | |
800 | (basep_addr == 0 ? NULL : &basep)); | |
801 | emul_write_status(processor, status, errno); | |
802 | if (basep_addr != 0) | |
803 | emul_write_word(basep_addr, basep, processor, cia); | |
804 | if (status > 0) | |
805 | write_direntries(buf_addr, buf, status, processor, cia); | |
806 | if (buf != NULL) | |
807 | zfree(buf); | |
808 | } | |
809 | #endif | |
810 | ||
811 | ||
93fac324 MM |
812 | static void |
813 | do___syscall(os_emul_data *emul, | |
c143ef62 MM |
814 | unsigned call, |
815 | const int arg0, | |
816 | cpu *processor, | |
817 | unsigned_word cia) | |
818 | { | |
819 | SYS(__syscall); | |
93fac324 MM |
820 | emul_do_system_call(emul, |
821 | emul->syscalls, | |
822 | cpu_registers(processor)->gpr[arg0], | |
823 | arg0 + 1, | |
824 | processor, | |
825 | cia); | |
c143ef62 MM |
826 | } |
827 | ||
828 | ||
93fac324 MM |
829 | static void |
830 | do_lseek(os_emul_data *emul, | |
c143ef62 MM |
831 | unsigned call, |
832 | const int arg0, | |
833 | cpu *processor, | |
834 | unsigned_word cia) | |
835 | { | |
836 | int fildes = cpu_registers(processor)->gpr[arg0]; | |
837 | off_t offset = emul_read_gpr64(processor, arg0+2); | |
838 | int whence = cpu_registers(processor)->gpr[arg0+4]; | |
839 | off_t status; | |
840 | SYS(lseek); | |
841 | status = lseek(fildes, offset, whence); | |
842 | if (status == -1) | |
843 | emul_write_status(processor, -1, errno); | |
844 | else { | |
845 | emul_write_gpr64(processor, 3, status); | |
846 | } | |
847 | } | |
848 | ||
849 | ||
93fac324 MM |
850 | static void |
851 | do___sysctl(os_emul_data *emul, | |
c143ef62 MM |
852 | unsigned call, |
853 | const int arg0, | |
854 | cpu *processor, | |
855 | unsigned_word cia) | |
856 | { | |
857 | /* call the arguments by their real name */ | |
858 | unsigned_word name = cpu_registers(processor)->gpr[arg0]; | |
859 | natural_word namelen = cpu_registers(processor)->gpr[arg0+1]; | |
860 | unsigned_word oldp = cpu_registers(processor)->gpr[arg0+2]; | |
861 | unsigned_word oldlenp = cpu_registers(processor)->gpr[arg0+3]; | |
862 | natural_word oldlen; | |
863 | natural_word mib; | |
864 | natural_word int_val; | |
865 | SYS(__sysctl); | |
866 | ||
867 | /* pluck out the management information base id */ | |
868 | if (namelen < 1) | |
869 | error("system_call()SYS___sysctl bad name[0]\n"); | |
870 | mib = vm_data_map_read_word(cpu_data_map(processor), | |
871 | name, | |
872 | processor, | |
873 | cia); | |
874 | name += sizeof(mib); | |
875 | ||
876 | /* see what to do with it ... */ | |
93fac324 | 877 | switch ((int)mib) { |
c143ef62 MM |
878 | case 6/*CTL_HW*/: |
879 | #if WITH_NetBSD_HOST && (CTL_HW != 6) | |
880 | # error "CTL_HW" | |
881 | #endif | |
882 | if (namelen < 2) | |
883 | error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n"); | |
884 | mib = vm_data_map_read_word(cpu_data_map(processor), | |
885 | name, | |
886 | processor, | |
887 | cia); | |
888 | name += sizeof(mib); | |
93fac324 | 889 | switch ((int)mib) { |
c143ef62 MM |
890 | case 7/*HW_PAGESIZE*/: |
891 | #if WITH_NetBSD_HOST && (HW_PAGESIZE != 7) | |
892 | # error "HW_PAGESIZE" | |
893 | #endif | |
894 | oldlen = vm_data_map_read_word(cpu_data_map(processor), | |
895 | oldlenp, | |
896 | processor, | |
897 | cia); | |
898 | if (sizeof(natural_word) > oldlen) | |
899 | error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n"); | |
900 | int_val = 8192; | |
901 | oldlen = sizeof(int_val); | |
902 | emul_write_word(oldp, int_val, processor, cia); | |
903 | emul_write_word(oldlenp, oldlen, processor, cia); | |
904 | break; | |
905 | default: | |
906 | error("sysctl() CTL_HW.%d unknown\n", mib); | |
907 | break; | |
908 | } | |
909 | break; | |
910 | default: | |
93fac324 | 911 | error("sysctl() name[0]=%d unknown\n", (int)mib); |
c143ef62 MM |
912 | break; |
913 | } | |
914 | cpu_registers(processor)->gpr[3] = 0; | |
915 | } | |
916 | ||
917 | ||
918 | ||
93fac324 MM |
919 | static emul_syscall_descriptor netbsd_descriptors[] = { |
920 | /* 0 */ { 0, "syscall" }, | |
921 | /* 1 */ { do_exit, "exit" }, | |
922 | /* 2 */ { 0, "fork" }, | |
923 | /* 3 */ { do_read, "read" }, | |
924 | /* 4 */ { do_write, "write" }, | |
925 | /* 5 */ { do_open, "open" }, | |
926 | /* 6 */ { do_close, "close" }, | |
927 | /* 7 */ { 0, "wait4" }, | |
c143ef62 | 928 | { 0, }, /* 8 is old creat */ |
93fac324 MM |
929 | /* 9 */ { 0, "link" }, |
930 | /* 10 */ { 0, "unlink" }, | |
c143ef62 | 931 | { 0, }, /* 11 is obsolete execv */ |
93fac324 MM |
932 | /* 12 */ { 0, "chdir" }, |
933 | /* 13 */ { 0, "fchdir" }, | |
934 | /* 14 */ { 0, "mknod" }, | |
935 | /* 15 */ { 0, "chmod" }, | |
936 | /* 16 */ { 0, "chown" }, | |
937 | /* 17 */ { do_break, "break" }, | |
938 | /* 18 */ { 0, "getfsstat" }, | |
c143ef62 | 939 | { 0, }, /* 19 is old lseek */ |
93fac324 MM |
940 | /* 20 */ { do_getpid, "getpid" }, |
941 | /* 21 */ { 0, "mount" }, | |
942 | /* 22 */ { 0, "unmount" }, | |
943 | /* 23 */ { 0, "setuid" }, | |
944 | /* 24 */ { do_getuid, "getuid" }, | |
945 | /* 25 */ { do_geteuid, "geteuid" }, | |
946 | /* 26 */ { 0, "ptrace" }, | |
947 | /* 27 */ { 0, "recvmsg" }, | |
948 | /* 28 */ { 0, "sendmsg" }, | |
949 | /* 29 */ { 0, "recvfrom" }, | |
950 | /* 30 */ { 0, "accept" }, | |
951 | /* 31 */ { 0, "getpeername" }, | |
952 | /* 32 */ { 0, "getsockname" }, | |
953 | /* 33 */ { 0, "access" }, | |
954 | /* 34 */ { 0, "chflags" }, | |
955 | /* 35 */ { 0, "fchflags" }, | |
956 | /* 36 */ { 0, "sync" }, | |
957 | /* 37 */ { do_kill, "kill" }, | |
c143ef62 | 958 | { 0, }, /* 38 is old stat */ |
93fac324 | 959 | /* 39 */ { 0, "getppid" }, |
c143ef62 | 960 | { 0, }, /* 40 is old lstat */ |
93fac324 MM |
961 | /* 41 */ { do_dup, "dup" }, |
962 | /* 42 */ { 0, "pipe" }, | |
963 | /* 43 */ { do_getegid, "getegid" }, | |
964 | /* 44 */ { 0, "profil" }, | |
965 | /* 45 */ { 0, "ktrace" }, | |
966 | /* 46 */ { 0, "sigaction" }, | |
967 | /* 47 */ { do_getgid, "getgid" }, | |
968 | /* 48 */ { do_sigprocmask, "sigprocmask" }, | |
969 | /* 49 */ { 0, "getlogin" }, | |
970 | /* 50 */ { 0, "setlogin" }, | |
971 | /* 51 */ { 0, "acct" }, | |
972 | /* 52 */ { 0, "sigpending" }, | |
973 | /* 53 */ { 0, "sigaltstack" }, | |
974 | /* 54 */ { do_ioctl, "ioctl" }, | |
975 | /* 55 */ { 0, "reboot" }, | |
976 | /* 56 */ { 0, "revoke" }, | |
977 | /* 57 */ { 0, "symlink" }, | |
978 | /* 58 */ { 0, "readlink" }, | |
979 | /* 59 */ { 0, "execve" }, | |
980 | /* 60 */ { do_umask, "umask" }, | |
981 | /* 61 */ { 0, "chroot" }, | |
c143ef62 MM |
982 | { 0, }, /* 62 is old fstat */ |
983 | { 0, }, /* 63 is old getkerninfo */ | |
984 | { 0, }, /* 64 is old getpagesize */ | |
93fac324 MM |
985 | /* 65 */ { 0, "msync" }, |
986 | /* 66 */ { 0, "vfork" }, | |
c143ef62 MM |
987 | { 0, }, /* 67 is obsolete vread */ |
988 | { 0, }, /* 68 is obsolete vwrite */ | |
93fac324 MM |
989 | /* 69 */ { 0, "sbrk" }, |
990 | /* 70 */ { 0, "sstk" }, | |
c143ef62 | 991 | { 0, }, /* 71 is old mmap */ |
93fac324 MM |
992 | /* 72 */ { 0, "vadvise" }, |
993 | /* 73 */ { 0, "munmap" }, | |
994 | /* 74 */ { 0, "mprotect" }, | |
995 | /* 75 */ { 0, "madvise" }, | |
c143ef62 MM |
996 | { 0, }, /* 76 is obsolete vhangup */ |
997 | { 0, }, /* 77 is obsolete vlimit */ | |
93fac324 MM |
998 | /* 78 */ { 0, "mincore" }, |
999 | /* 79 */ { 0, "getgroups" }, | |
1000 | /* 80 */ { 0, "setgroups" }, | |
1001 | /* 81 */ { 0, "getpgrp" }, | |
1002 | /* 82 */ { 0, "setpgid" }, | |
1003 | /* 83 */ { 0, "setitimer" }, | |
c143ef62 | 1004 | { 0, }, /* 84 is old wait */ |
93fac324 MM |
1005 | /* 85 */ { 0, "swapon" }, |
1006 | /* 86 */ { 0, "getitimer" }, | |
c143ef62 MM |
1007 | { 0, }, /* 87 is old gethostname */ |
1008 | { 0, }, /* 88 is old sethostname */ | |
1009 | { 0, }, /* 89 is old getdtablesize */ | |
93fac324 | 1010 | { do_dup2, "dup2" }, |
c143ef62 | 1011 | { 0, }, /* 91 */ |
93fac324 MM |
1012 | /* 92 */ { do_fcntl, "fcntl" }, |
1013 | /* 93 */ { 0, "select" }, | |
c143ef62 | 1014 | { 0, }, /* 94 */ |
93fac324 MM |
1015 | /* 95 */ { 0, "fsync" }, |
1016 | /* 96 */ { 0, "setpriority" }, | |
1017 | /* 97 */ { 0, "socket" }, | |
1018 | /* 98 */ { 0, "connect" }, | |
c143ef62 | 1019 | { 0, }, /* 99 is old accept */ |
93fac324 | 1020 | /* 100 */ { 0, "getpriority" }, |
c143ef62 MM |
1021 | { 0, }, /* 101 is old send */ |
1022 | { 0, }, /* 102 is old recv */ | |
93fac324 MM |
1023 | /* 103 */ { 0, "sigreturn" }, |
1024 | /* 104 */ { 0, "bind" }, | |
1025 | /* 105 */ { 0, "setsockopt" }, | |
1026 | /* 106 */ { 0, "listen" }, | |
c143ef62 MM |
1027 | { 0, }, /* 107 is obsolete vtimes */ |
1028 | { 0, }, /* 108 is old sigvec */ | |
1029 | { 0, }, /* 109 is old sigblock */ | |
1030 | { 0, }, /* 110 is old sigsetmask */ | |
93fac324 | 1031 | /* 111 */ { 0, "sigsuspend" }, |
c143ef62 MM |
1032 | { 0, }, /* 112 is old sigstack */ |
1033 | { 0, }, /* 113 is old recvmsg */ | |
1034 | { 0, }, /* 114 is old sendmsg */ | |
93fac324 MM |
1035 | /* - is obsolete vtrace */ { 0, "vtrace 115" }, |
1036 | /* 116 */ { do_gettimeofday, "gettimeofday" }, | |
1037 | /* 117 */ { do_getrusage, "getrusage" }, | |
1038 | /* 118 */ { 0, "getsockopt" }, | |
1039 | /* 119 */ { 0, "resuba" }, | |
1040 | /* 120 */ { 0, "readv" }, | |
1041 | /* 121 */ { 0, "writev" }, | |
1042 | /* 122 */ { 0, "settimeofday" }, | |
1043 | /* 123 */ { 0, "fchown" }, | |
1044 | /* 124 */ { 0, "fchmod" }, | |
c143ef62 MM |
1045 | { 0, }, /* 125 is old recvfrom */ |
1046 | { 0, }, /* 126 is old setreuid */ | |
1047 | { 0, }, /* 127 is old setregid */ | |
93fac324 | 1048 | /* 128 */ { 0, "rename" }, |
c143ef62 MM |
1049 | { 0, }, /* 129 is old truncate */ |
1050 | { 0, }, /* 130 is old ftruncate */ | |
93fac324 MM |
1051 | /* 131 */ { 0, "flock" }, |
1052 | /* 132 */ { 0, "mkfifo" }, | |
1053 | /* 133 */ { 0, "sendto" }, | |
1054 | /* 134 */ { 0, "shutdown" }, | |
1055 | /* 135 */ { 0, "socketpair" }, | |
1056 | /* 136 */ { 0, "mkdir" }, | |
1057 | /* 137 */ { 0, "rmdir" }, | |
1058 | /* 138 */ { 0, "utimes" }, | |
c143ef62 | 1059 | { 0, }, /* 139 is obsolete 4.2 sigreturn */ |
93fac324 | 1060 | /* 140 */ { 0, "adjtime" }, |
c143ef62 MM |
1061 | { 0, }, /* 141 is old getpeername */ |
1062 | { 0, }, /* 142 is old gethostid */ | |
1063 | { 0, }, /* 143 is old sethostid */ | |
1064 | { 0, }, /* 144 is old getrlimit */ | |
1065 | { 0, }, /* 145 is old setrlimit */ | |
1066 | { 0, }, /* 146 is old killpg */ | |
93fac324 MM |
1067 | /* 147 */ { 0, "setsid" }, |
1068 | /* 148 */ { 0, "quotactl" }, | |
c143ef62 MM |
1069 | { 0, }, /* 149 is old quota */ |
1070 | { 0, }, /* 150 is old getsockname */ | |
1071 | { 0, }, /* 151 */ | |
1072 | { 0, }, /* 152 */ | |
1073 | { 0, }, /* 153 */ | |
1074 | { 0, }, /* 154 */ | |
93fac324 | 1075 | /* 155 */ { 0, "nfssvc" }, |
c143ef62 | 1076 | { 0, }, /* 156 is old getdirentries */ |
93fac324 MM |
1077 | /* 157 */ { 0, "statfs" }, |
1078 | /* 158 */ { do_fstatfs, "fstatfs" }, | |
c143ef62 MM |
1079 | { 0, }, /* 159 */ |
1080 | { 0, }, /* 160 */ | |
93fac324 | 1081 | /* 161 */ { 0, "getfh" }, |
c143ef62 MM |
1082 | { 0, }, /* 162 is old getdomainname */ |
1083 | { 0, }, /* 163 is old setdomainname */ | |
1084 | { 0, }, /* 164 is old uname */ | |
93fac324 | 1085 | /* 165 */ { 0, "sysarch" }, |
c143ef62 MM |
1086 | { 0, }, /* 166 */ |
1087 | { 0, }, /* 167 */ | |
1088 | { 0, }, /* 168 */ | |
93fac324 MM |
1089 | /* 169 */ { 0, "semsys" }, |
1090 | /* 170 */ { 0, "msgsys" }, | |
1091 | /* 171 */ { 0, "shmsys" }, | |
c143ef62 MM |
1092 | { 0, }, /* 172 */ |
1093 | { 0, }, /* 173 */ | |
1094 | { 0, }, /* 174 */ | |
1095 | { 0, }, /* 175 */ | |
1096 | { 0, }, /* 176 */ | |
1097 | { 0, }, /* 177 */ | |
1098 | { 0, }, /* 178 */ | |
1099 | { 0, }, /* 179 */ | |
1100 | { 0, }, /* 180 */ | |
93fac324 MM |
1101 | /* 181 */ { 0, "setgid" }, |
1102 | /* 182 */ { 0, "setegid" }, | |
1103 | /* 183 */ { 0, "seteuid" }, | |
1104 | /* 184 */ { 0, "lfs_bmapv" }, | |
1105 | /* 185 */ { 0, "lfs_markv" }, | |
1106 | /* 186 */ { 0, "lfs_segclean" }, | |
1107 | /* 187 */ { 0, "lfs_segwait" }, | |
1108 | /* 188 */ { do_stat, "stat" }, | |
1109 | /* 189 */ { do_fstat, "fstat" }, | |
1110 | /* 190 */ { do_lstat, "lstat" }, | |
1111 | /* 191 */ { 0, "pathconf" }, | |
1112 | /* 192 */ { 0, "fpathconf" }, | |
c143ef62 | 1113 | { 0, }, /* 193 */ |
93fac324 MM |
1114 | /* 194 */ { 0, "getrlimit" }, |
1115 | /* 195 */ { 0, "setrlimit" }, | |
1116 | /* 196 */ { do_getdirentries, "getdirentries" }, | |
1117 | /* 197 */ { 0, "mmap" }, | |
1118 | /* 198 */ { do___syscall, "__syscall" }, | |
1119 | /* 199 */ { do_lseek, "lseek" }, | |
1120 | /* 200 */ { 0, "truncate" }, | |
1121 | /* 201 */ { 0, "ftruncate" }, | |
1122 | /* 202 */ { do___sysctl, "__sysctl" }, | |
1123 | /* 203 */ { 0, "mlock" }, | |
1124 | /* 204 */ { 0, "munlock" }, | |
c143ef62 MM |
1125 | }; |
1126 | ||
1127 | static char *(netbsd_error_names[]) = { | |
1128 | /* 0 */ "ESUCCESS", | |
1129 | /* 1 */ "EPERM", | |
1130 | /* 2 */ "ENOENT", | |
1131 | /* 3 */ "ESRCH", | |
1132 | /* 4 */ "EINTR", | |
1133 | /* 5 */ "EIO", | |
1134 | /* 6 */ "ENXIO", | |
1135 | /* 7 */ "E2BIG", | |
1136 | /* 8 */ "ENOEXEC", | |
1137 | /* 9 */ "EBADF", | |
1138 | /* 10 */ "ECHILD", | |
1139 | /* 11 */ "EDEADLK", | |
1140 | /* 12 */ "ENOMEM", | |
1141 | /* 13 */ "EACCES", | |
1142 | /* 14 */ "EFAULT", | |
1143 | /* 15 */ "ENOTBLK", | |
1144 | /* 16 */ "EBUSY", | |
1145 | /* 17 */ "EEXIST", | |
1146 | /* 18 */ "EXDEV", | |
1147 | /* 19 */ "ENODEV", | |
1148 | /* 20 */ "ENOTDIR", | |
1149 | /* 21 */ "EISDIR", | |
1150 | /* 22 */ "EINVAL", | |
1151 | /* 23 */ "ENFILE", | |
1152 | /* 24 */ "EMFILE", | |
1153 | /* 25 */ "ENOTTY", | |
1154 | /* 26 */ "ETXTBSY", | |
1155 | /* 27 */ "EFBIG", | |
1156 | /* 28 */ "ENOSPC", | |
1157 | /* 29 */ "ESPIPE", | |
1158 | /* 30 */ "EROFS", | |
1159 | /* 31 */ "EMLINK", | |
1160 | /* 32 */ "EPIPE", | |
1161 | /* 33 */ "EDOM", | |
1162 | /* 34 */ "ERANGE", | |
1163 | /* 35 */ "EAGAIN", | |
1164 | /* 36 */ "EINPROGRESS", | |
1165 | /* 37 */ "EALREADY", | |
1166 | /* 38 */ "ENOTSOCK", | |
1167 | /* 39 */ "EDESTADDRREQ", | |
1168 | /* 40 */ "EMSGSIZE", | |
1169 | /* 41 */ "EPROTOTYPE", | |
1170 | /* 42 */ "ENOPROTOOPT", | |
1171 | /* 43 */ "EPROTONOSUPPORT", | |
1172 | /* 44 */ "ESOCKTNOSUPPORT", | |
1173 | /* 45 */ "EOPNOTSUPP", | |
1174 | /* 46 */ "EPFNOSUPPORT", | |
1175 | /* 47 */ "EAFNOSUPPORT", | |
1176 | /* 48 */ "EADDRINUSE", | |
1177 | /* 49 */ "EADDRNOTAVAIL", | |
1178 | /* 50 */ "ENETDOWN", | |
1179 | /* 51 */ "ENETUNREACH", | |
1180 | /* 52 */ "ENETRESET", | |
1181 | /* 53 */ "ECONNABORTED", | |
1182 | /* 54 */ "ECONNRESET", | |
1183 | /* 55 */ "ENOBUFS", | |
1184 | /* 56 */ "EISCONN", | |
1185 | /* 57 */ "ENOTCONN", | |
1186 | /* 58 */ "ESHUTDOWN", | |
1187 | /* 59 */ "ETOOMANYREFS", | |
1188 | /* 60 */ "ETIMEDOUT", | |
1189 | /* 61 */ "ECONNREFUSED", | |
1190 | /* 62 */ "ELOOP", | |
1191 | /* 63 */ "ENAMETOOLONG", | |
1192 | /* 64 */ "EHOSTDOWN", | |
1193 | /* 65 */ "EHOSTUNREACH", | |
1194 | /* 66 */ "ENOTEMPTY", | |
1195 | /* 67 */ "EPROCLIM", | |
1196 | /* 68 */ "EUSERS", | |
1197 | /* 69 */ "EDQUOT", | |
1198 | /* 70 */ "ESTALE", | |
1199 | /* 71 */ "EREMOTE", | |
1200 | /* 72 */ "EBADRPC", | |
1201 | /* 73 */ "ERPCMISMATCH", | |
1202 | /* 74 */ "EPROGUNAVAIL", | |
1203 | /* 75 */ "EPROGMISMATCH", | |
1204 | /* 76 */ "EPROCUNAVAIL", | |
1205 | /* 77 */ "ENOLCK", | |
1206 | /* 78 */ "ENOSYS", | |
1207 | /* 79 */ "EFTYPE", | |
1208 | /* 80 */ "EAUTH", | |
1209 | /* 81 */ "ENEEDAUTH", | |
1210 | /* 81 */ "ELAST", | |
1211 | }; | |
1212 | ||
1213 | static char *(netbsd_signal_names[]) = { | |
1214 | /* 0 */ 0, | |
1215 | /* 1 */ "SIGHUP", | |
1216 | /* 2 */ "SIGINT", | |
1217 | /* 3 */ "SIGQUIT", | |
1218 | /* 4 */ "SIGILL", | |
1219 | /* 5 */ "SIGTRAP", | |
1220 | /* 6 */ "SIGABRT", | |
1221 | /* 7 */ "SIGEMT", | |
1222 | /* 8 */ "SIGFPE", | |
1223 | /* 9 */ "SIGKILL", | |
1224 | /* 10 */ "SIGBUS", | |
1225 | /* 11 */ "SIGSEGV", | |
1226 | /* 12 */ "SIGSYS", | |
1227 | /* 13 */ "SIGPIPE", | |
1228 | /* 14 */ "SIGALRM", | |
1229 | /* 15 */ "SIGTERM", | |
1230 | /* 16 */ "SIGURG", | |
1231 | /* 17 */ "SIGSTOP", | |
1232 | /* 18 */ "SIGTSTP", | |
1233 | /* 19 */ "SIGCONT", | |
1234 | /* 20 */ "SIGCHLD", | |
1235 | /* 21 */ "SIGTTIN", | |
1236 | /* 22 */ "SIGTTOU", | |
1237 | /* 23 */ "SIGIO", | |
1238 | /* 24 */ "SIGXCPU", | |
1239 | /* 25 */ "SIGXFSZ", | |
1240 | /* 26 */ "SIGVTALRM", | |
1241 | /* 27 */ "SIGPROF", | |
1242 | /* 28 */ "SIGWINCH", | |
1243 | /* 29 */ "SIGINFO", | |
1244 | /* 30 */ "SIGUSR1", | |
1245 | /* 31 */ "SIGUSR2", | |
1246 | }; | |
1247 | ||
93fac324 | 1248 | static emul_syscall emul_netbsd_syscalls = { |
c143ef62 MM |
1249 | netbsd_descriptors, |
1250 | sizeof(netbsd_descriptors) / sizeof(netbsd_descriptors[0]), | |
1251 | netbsd_error_names, | |
1252 | sizeof(netbsd_error_names) / sizeof(netbsd_error_names[0]), | |
1253 | netbsd_signal_names, | |
1254 | sizeof(netbsd_signal_names) / sizeof(netbsd_signal_names[0]), | |
1255 | }; | |
1256 | ||
93fac324 MM |
1257 | |
1258 | /* NetBSD's os_emul interface, most are just passed on to the generic | |
1259 | syscall stuff */ | |
1260 | ||
1261 | static os_emul_data * | |
1262 | emul_netbsd_create(device *root, | |
1263 | bfd *image, | |
1264 | const char *name) | |
1265 | { | |
1266 | unsigned_word top_of_stack; | |
1267 | unsigned stack_size; | |
1268 | int elf_binary; | |
1269 | os_emul_data *bsd_data; | |
7393a6f0 | 1270 | device *vm; |
93fac324 MM |
1271 | |
1272 | /* check that this emulation is really for us */ | |
1273 | if (name != NULL && strcmp(name, "netbsd") != 0) | |
1274 | return NULL; | |
1275 | if (image == NULL) | |
1276 | return NULL; | |
1277 | ||
1278 | ||
1279 | /* merge any emulation specific entries into the device tree */ | |
1280 | ||
1281 | /* establish a few defaults */ | |
1282 | if (image->xvec->flavour == bfd_target_elf_flavour) { | |
1283 | elf_binary = 1; | |
1284 | top_of_stack = 0xe0000000; | |
1285 | stack_size = 0x00100000; | |
1286 | } | |
1287 | else { | |
1288 | elf_binary = 0; | |
1289 | top_of_stack = 0x20000000; | |
1290 | stack_size = 0x00100000; | |
1291 | } | |
1292 | ||
1293 | /* options */ | |
7393a6f0 MM |
1294 | emul_add_tree_options(root, image, "netbsd", |
1295 | (WITH_ENVIRONMENT == USER_ENVIRONMENT | |
eada1efc MM |
1296 | ? "user" : "virtual"), |
1297 | 0 /*oea-interrupt-prefix*/); | |
93fac324 MM |
1298 | |
1299 | /* virtual memory - handles growth of stack/heap */ | |
7393a6f0 MM |
1300 | vm = device_tree_add_parsed(root, "/openprom/vm@0x%lx", |
1301 | (unsigned long)(top_of_stack - stack_size)); | |
1302 | device_tree_add_parsed(vm, "./stack-base 0x%lx", | |
1303 | (unsigned long)(top_of_stack - stack_size)); | |
1304 | device_tree_add_parsed(vm, "./nr-bytes 0x%x", stack_size); | |
1305 | ||
1306 | device_tree_add_parsed(root, "/openprom/vm/map-binary/file-name %s", | |
1307 | bfd_get_filename(image)); | |
93fac324 MM |
1308 | |
1309 | /* finish the init */ | |
7393a6f0 MM |
1310 | device_tree_add_parsed(root, "/openprom/init/register/pc 0x%lx", |
1311 | (unsigned long)bfd_get_start_address(image)); | |
1312 | device_tree_add_parsed(root, "/openprom/init/register/sp 0x%lx", | |
1313 | (unsigned long)top_of_stack); | |
1314 | device_tree_add_parsed(root, "/openprom/init/register/msr 0x%x", | |
1315 | (device_find_boolean_property(root, "/options/little-endian?") | |
1316 | ? msr_little_endian_mode | |
1317 | : 0)); | |
1318 | device_tree_add_parsed(root, "/openprom/init/stack/stack-type %s", | |
1319 | (elf_binary ? "elf" : "xcoff")); | |
93fac324 MM |
1320 | |
1321 | /* finally our emulation data */ | |
1322 | bsd_data = ZALLOC(os_emul_data); | |
7393a6f0 | 1323 | bsd_data->vm = vm; |
93fac324 MM |
1324 | bsd_data->syscalls = &emul_netbsd_syscalls; |
1325 | return bsd_data; | |
1326 | } | |
1327 | ||
1328 | static void | |
1329 | emul_netbsd_init(os_emul_data *emul_data, | |
1330 | int nr_cpus) | |
1331 | { | |
1332 | /* nothing yet */ | |
1333 | } | |
1334 | ||
1335 | static void | |
1336 | emul_netbsd_system_call(cpu *processor, | |
1337 | unsigned_word cia, | |
1338 | os_emul_data *emul_data) | |
1339 | { | |
1340 | emul_do_system_call(emul_data, | |
1341 | emul_data->syscalls, | |
1342 | cpu_registers(processor)->gpr[0], | |
1343 | 3, /*r3 contains arg0*/ | |
1344 | processor, | |
1345 | cia); | |
1346 | } | |
1347 | ||
1348 | const os_emul emul_netbsd = { | |
1349 | "netbsd", | |
1350 | emul_netbsd_create, | |
1351 | emul_netbsd_init, | |
1352 | emul_netbsd_system_call, | |
1353 | 0, /*instruction_call*/ | |
1354 | 0 /*data*/ | |
1355 | }; | |
1356 | ||
1357 | #endif _EMUL_NETBSD_C_ |