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