25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: useremul.c,v 1.46 2005/04/14 21:01:54 debug Exp $ |
* $Id: useremul.c,v 1.66 2005/11/11 13:23:15 debug Exp $ |
29 |
* |
* |
30 |
* Userland (syscall) emulation. |
* Userland (syscall) emulation. |
31 |
* |
* |
32 |
* TODO: |
* TODO: |
33 |
* |
* |
34 |
* NetBSD/pmax: |
* environment passing for most emulation modes |
35 |
* environment passing |
* |
36 |
* more syscalls |
* implement more syscalls |
37 |
* |
* |
38 |
* 32-bit vs 64-bit problems? MIPS n32, o32, n64? |
* 32-bit vs 64-bit problems? MIPS n32, o32, n64? |
39 |
* |
* |
67 |
#include <sys/time.h> |
#include <sys/time.h> |
68 |
#include <sys/stat.h> |
#include <sys/stat.h> |
69 |
#include <sys/socket.h> |
#include <sys/socket.h> |
70 |
|
#include <sys/resource.h> |
71 |
#include <time.h> |
#include <time.h> |
72 |
|
|
73 |
#include "cpu.h" |
#include "cpu.h" |
133 |
{ |
{ |
134 |
debug("useremul__freebsd_setup(): TODO\n"); |
debug("useremul__freebsd_setup(): TODO\n"); |
135 |
|
|
136 |
if (cpu->machine->arch != ARCH_ALPHA) { |
switch (cpu->machine->arch) { |
137 |
|
case ARCH_ALPHA: |
138 |
|
/* According to FreeBSD's /usr/src/lib/csu/alpha/crt1.c: */ |
139 |
|
/* a0 = char **ap */ |
140 |
|
/* a1 = void (*cleanup)(void) from shared loader */ |
141 |
|
/* a2 = struct Struct_Obj_Entry *obj from shared loader */ |
142 |
|
/* a3 = struct ps_strings *ps_strings */ |
143 |
|
cpu->cd.alpha.r[ALPHA_A0] = 0; |
144 |
|
cpu->cd.alpha.r[ALPHA_A1] = 0; |
145 |
|
cpu->cd.alpha.r[ALPHA_A2] = 0; |
146 |
|
cpu->cd.alpha.r[ALPHA_A3] = 0; |
147 |
|
|
148 |
|
/* What is a good stack pointer? TODO */ |
149 |
|
cpu->cd.alpha.r[ALPHA_SP] = 0x120000000ULL + |
150 |
|
1048576 * cpu->machine->physical_ram_in_mb - 1024; |
151 |
|
break; |
152 |
|
default: |
153 |
fatal("non-Alpha not yet implemented for freebsd emul.\n"); |
fatal("non-Alpha not yet implemented for freebsd emul.\n"); |
154 |
exit(1); |
exit(1); |
155 |
} |
} |
|
|
|
|
/* What is a good stack pointer? TODO */ |
|
|
/* cpu->cd.alpha.gpr[...] = ... */ |
|
156 |
} |
} |
157 |
|
|
158 |
|
|
200 |
/* The userland stack: */ |
/* The userland stack: */ |
201 |
cpu->cd.mips.gpr[MIPS_GPR_SP] = stack_top - stack_margin; |
cpu->cd.mips.gpr[MIPS_GPR_SP] = stack_top - stack_margin; |
202 |
add_symbol_name(&cpu->machine->symbol_context, |
add_symbol_name(&cpu->machine->symbol_context, |
203 |
stack_top - stacksize, stacksize, "userstack", 0); |
stack_top - stacksize, stacksize, "userstack", 0, 0); |
204 |
|
|
205 |
/* Stack contents: (TODO: is this correct?) */ |
/* Stack contents: (TODO: is this correct?) */ |
206 |
store_32bit_word(cpu, stack_top - stack_margin, argc); |
store_32bit_word(cpu, stack_top - stack_margin, argc); |
232 |
} |
} |
233 |
break; |
break; |
234 |
|
|
235 |
|
case ARCH_ALPHA: |
236 |
|
debug("useremul__netbsd_setup(): ALPHA: TODO\n"); |
237 |
|
break; |
238 |
|
|
239 |
|
case ARCH_ARM: |
240 |
|
debug("useremul__netbsd_setup(): ARM: TODO\n"); |
241 |
|
break; |
242 |
|
|
243 |
case ARCH_PPC: |
case ARCH_PPC: |
244 |
debug("useremul__netbsd_setup(): PPC: TODO\n"); |
debug("useremul__netbsd_setup(): PPC: TODO\n"); |
245 |
|
|
282 |
/* The userland stack: */ |
/* The userland stack: */ |
283 |
cpu->cd.mips.gpr[MIPS_GPR_SP] = stack_top - stack_margin; |
cpu->cd.mips.gpr[MIPS_GPR_SP] = stack_top - stack_margin; |
284 |
add_symbol_name(&cpu->machine->symbol_context, |
add_symbol_name(&cpu->machine->symbol_context, |
285 |
stack_top - stacksize, stacksize, "userstack", 0); |
stack_top - stacksize, stacksize, "userstack", 0, 0); |
286 |
|
|
287 |
/* Stack contents: (TODO: is this correct?) */ |
/* Stack contents: (TODO: is this correct?) */ |
288 |
store_32bit_word(cpu, stack_top - stack_margin, argc); |
store_32bit_word(cpu, stack_top - stack_margin, argc); |
361 |
* TODO: combine this with get_userland_string() in some way |
* TODO: combine this with get_userland_string() in some way |
362 |
*/ |
*/ |
363 |
static unsigned char *get_userland_buf(struct cpu *cpu, |
static unsigned char *get_userland_buf(struct cpu *cpu, |
364 |
uint64_t baseaddr, int len) |
uint64_t baseaddr, uint64_t len) |
365 |
{ |
{ |
366 |
unsigned char *charbuf; |
unsigned char *charbuf; |
367 |
int i; |
ssize_t i; |
368 |
|
|
369 |
charbuf = malloc(len); |
charbuf = malloc(len); |
370 |
if (charbuf == NULL) { |
if (charbuf == NULL) { |
371 |
fprintf(stderr, "get_userland_buf(): out of memory (trying" |
fprintf(stderr, "get_userland_buf(): out of memory (trying" |
372 |
" to allocate %i bytes)\n", len); |
" to allocate %lli bytes)\n", (long long)len); |
373 |
exit(1); |
exit(1); |
374 |
} |
} |
375 |
|
|
402 |
} |
} |
403 |
|
|
404 |
|
|
405 |
|
/*****************************************************************************/ |
406 |
|
|
407 |
|
|
408 |
|
/* |
409 |
|
* useremul_exit(): |
410 |
|
*/ |
411 |
|
int useremul_exit(struct cpu *cpu, uint64_t arg0) |
412 |
|
{ |
413 |
|
debug("[ exit(%i) ]\n", (int)arg0); |
414 |
|
cpu->running = 0; |
415 |
|
cpu->machine->exit_without_entering_debugger = 1; |
416 |
|
return 0; |
417 |
|
} |
418 |
|
|
419 |
|
|
420 |
|
/* |
421 |
|
* useremul_write(): |
422 |
|
*/ |
423 |
|
int64_t useremul_write(struct cpu *cpu, int64_t *errnop, |
424 |
|
uint64_t arg0, uint64_t arg1, uint64_t arg2) |
425 |
|
{ |
426 |
|
int64_t res = 0; |
427 |
|
*errnop = 0; |
428 |
|
debug("[ write(%i,0x%llx,%lli) ]\n", |
429 |
|
(int)arg0, (long long)arg1, (long long)arg2); |
430 |
|
if (arg2 != 0) { |
431 |
|
unsigned char *cp = get_userland_buf(cpu, arg1, arg2); |
432 |
|
res = write(arg0, cp, arg2); |
433 |
|
if (res < 0) |
434 |
|
*errnop = errno; |
435 |
|
free(cp); |
436 |
|
} |
437 |
|
return res; |
438 |
|
} |
439 |
|
|
440 |
|
|
441 |
|
/* |
442 |
|
* useremul_break(): |
443 |
|
*/ |
444 |
|
int64_t useremul_break(struct cpu *cpu, uint64_t arg0) |
445 |
|
{ |
446 |
|
debug("[ break(0x%llx): TODO ]\n", (long long)arg0); |
447 |
|
|
448 |
|
/* TODO */ |
449 |
|
return 0; |
450 |
|
} |
451 |
|
|
452 |
|
|
453 |
|
/* |
454 |
|
* useremul_getpid(): |
455 |
|
*/ |
456 |
|
int64_t useremul_getpid(struct cpu *cpu) |
457 |
|
{ |
458 |
|
int64_t pid = getpid(); |
459 |
|
debug("[ getpid(): %lli ]\n", (long long)pid); |
460 |
|
return pid; |
461 |
|
} |
462 |
|
|
463 |
|
|
464 |
|
/* |
465 |
|
* useremul_getuid(): |
466 |
|
*/ |
467 |
|
int64_t useremul_getuid(struct cpu *cpu) |
468 |
|
{ |
469 |
|
int64_t uid = getuid(); |
470 |
|
debug("[ getuid(): %lli ]\n", (long long)uid); |
471 |
|
return uid; |
472 |
|
} |
473 |
|
|
474 |
|
|
475 |
|
/* |
476 |
|
* useremul_getegid(): |
477 |
|
*/ |
478 |
|
int64_t useremul_getegid(struct cpu *cpu) |
479 |
|
{ |
480 |
|
int64_t egid = getegid(); |
481 |
|
debug("[ getegid(): %lli ]\n", (long long)egid); |
482 |
|
return egid; |
483 |
|
} |
484 |
|
|
485 |
|
|
486 |
|
/* |
487 |
|
* useremul_getgid(): |
488 |
|
*/ |
489 |
|
int64_t useremul_getgid(struct cpu *cpu) |
490 |
|
{ |
491 |
|
int64_t gid = getgid(); |
492 |
|
debug("[ getgid(): %lli ]\n", (long long)gid); |
493 |
|
return gid; |
494 |
|
} |
495 |
|
|
496 |
|
|
497 |
|
/* |
498 |
|
* useremul_sync(): |
499 |
|
*/ |
500 |
|
int useremul_sync(struct cpu *cpu) |
501 |
|
{ |
502 |
|
debug("[ sync() ]\n"); |
503 |
|
sync(); |
504 |
|
return 0; |
505 |
|
} |
506 |
|
|
507 |
|
|
508 |
|
/* |
509 |
|
* useremul_readlink(): |
510 |
|
*/ |
511 |
|
int64_t useremul_readlink(struct cpu *cpu, int64_t *errnop, |
512 |
|
uint64_t arg0, uint64_t arg1, int64_t arg2) |
513 |
|
{ |
514 |
|
int64_t res = 0; |
515 |
|
unsigned char *charbuf = get_userland_string(cpu, arg0); |
516 |
|
unsigned char *buf2; |
517 |
|
|
518 |
|
debug("[ readlink(\"%s\",0x%llx,%lli) ]\n", |
519 |
|
charbuf, (long long)arg1, (long long)arg2); |
520 |
|
if (arg2 == 0 || arg2 > 150000) { |
521 |
|
fprintf(stderr, "[ useremul_readlink(): TODO ]\n"); |
522 |
|
exit(1); |
523 |
|
} |
524 |
|
|
525 |
|
buf2 = malloc(arg2); |
526 |
|
if (buf2 == NULL) { |
527 |
|
fprintf(stderr, "[ useremul_readlink(): out of memory ]\n"); |
528 |
|
exit(1); |
529 |
|
} |
530 |
|
res = readlink((char *)charbuf, (char *)buf2, arg2); |
531 |
|
buf2[arg2-1] = '\0'; |
532 |
|
if (res < 0) |
533 |
|
*errnop = errno; |
534 |
|
else |
535 |
|
store_string(cpu, arg1, (char *)buf2); |
536 |
|
free(buf2); |
537 |
|
free(charbuf); |
538 |
|
return res; |
539 |
|
} |
540 |
|
|
541 |
|
|
542 |
|
/* |
543 |
|
* useremul_getrusage(): |
544 |
|
*/ |
545 |
|
int64_t useremul_getrusage(struct cpu *cpu, int64_t *errnop, |
546 |
|
uint64_t arg0, uint64_t arg1) |
547 |
|
{ |
548 |
|
int64_t res; |
549 |
|
struct rusage rusage; |
550 |
|
debug("[ getrusage(%i,0x%llx) ]\n", (int)arg0, (long long)arg1); |
551 |
|
res = getrusage(arg0, &rusage); |
552 |
|
|
553 |
|
fatal("TODO: convert rusage into emulated memory!\n"); |
554 |
|
store_64bit_word(cpu, arg1 + 0, rusage.ru_utime.tv_sec); |
555 |
|
store_64bit_word(cpu, arg1 + 8, rusage.ru_utime.tv_usec); |
556 |
|
store_64bit_word(cpu, arg1 + 16, rusage.ru_stime.tv_sec); |
557 |
|
store_64bit_word(cpu, arg1 + 24, rusage.ru_stime.tv_usec); |
558 |
|
|
559 |
|
return res; |
560 |
|
} |
561 |
|
|
562 |
|
|
563 |
|
/* |
564 |
|
* useremul_fstat(): |
565 |
|
*/ |
566 |
|
int64_t useremul_fstat(struct cpu *cpu, int64_t *errnop, |
567 |
|
int64_t arg0, uint64_t arg1) |
568 |
|
{ |
569 |
|
int64_t res; |
570 |
|
struct stat sb; |
571 |
|
debug("[ fstat(%i,0x%llx) ]\n", (int)arg0, (long long)arg1); |
572 |
|
res = fstat(arg0, &sb); |
573 |
|
if (res < 0) |
574 |
|
*errnop = errno; |
575 |
|
else { |
576 |
|
fatal("TODO: convert sb into emulated memory!\n"); |
577 |
|
|
578 |
|
/* NOTE: FreeBSD/alpha only */ |
579 |
|
|
580 |
|
store_32bit_word(cpu, arg1 + 0, sb.st_dev); |
581 |
|
store_32bit_word(cpu, arg1 + 4, sb.st_ino); |
582 |
|
/* store_16bit_word(cpu, arg1 + 8, sb.st_mode); |
583 |
|
*/ store_16bit_word(cpu, arg1 + 10, sb.st_nlink); |
584 |
|
store_32bit_word(cpu, arg1 + 12, sb.st_uid); |
585 |
|
store_32bit_word(cpu, arg1 + 16, sb.st_gid); |
586 |
|
store_32bit_word(cpu, arg1 + 20, sb.st_rdev); |
587 |
|
#if 0 |
588 |
|
store_64bit_word(cpu, arg1 + 24, sb.st_atimespec.tv_sec); |
589 |
|
store_64bit_word(cpu, arg1 + 32, sb.st_atimespec.tv_nsec); |
590 |
|
store_64bit_word(cpu, arg1 + 40, sb.st_mtimespec.tv_sec); |
591 |
|
store_64bit_word(cpu, arg1 + 48, sb.st_mtimespec.tv_nsec); |
592 |
|
store_64bit_word(cpu, arg1 + 56, sb.st_ctimespec.tv_sec); |
593 |
|
store_64bit_word(cpu, arg1 + 64, sb.st_ctimespec.tv_nsec); |
594 |
|
|
595 |
|
store_64bit_word(cpu, arg1 + 72, sb.st_size); |
596 |
|
store_64bit_word(cpu, arg1 + 80, sb.st_blocks); |
597 |
|
store_64bit_word(cpu, arg1 + 88, sb.st_blksize); |
598 |
|
store_64bit_word(cpu, arg1 + 92, sb.st_flags); |
599 |
|
store_64bit_word(cpu, arg1 + 96, sb.st_gen); |
600 |
|
#endif |
601 |
|
} |
602 |
|
return res; |
603 |
|
} |
604 |
|
|
605 |
|
|
606 |
|
/* |
607 |
|
* useremul_mmap(): |
608 |
|
*/ |
609 |
|
int64_t useremul_mmap(struct cpu *cpu, int64_t *errnop, |
610 |
|
uint64_t arg0, int64_t arg1, int64_t arg2, |
611 |
|
int64_t arg3, int64_t arg4, uint64_t arg5) |
612 |
|
{ |
613 |
|
int64_t res = 0; |
614 |
|
|
615 |
|
/* arg0..5: addr, len, prot, flags, fd, offset */ |
616 |
|
debug("[ mmap(0x%llx,%lli,%i,%i,%i,%lli) ]\n", |
617 |
|
(long long)arg0, (long long)arg1, |
618 |
|
(int)arg2, (int)arg3, (int)arg4, (long long)arg5); |
619 |
|
|
620 |
|
if (arg4 != -1) { |
621 |
|
fatal("[ useremul_mmap(): fd != -1: TODO ]\n"); |
622 |
|
cpu->running = 0; |
623 |
|
return 0; |
624 |
|
} |
625 |
|
|
626 |
|
/* Anonymous allocation. */ |
627 |
|
if (arg0 != 0) { |
628 |
|
fatal("[ useremul_mmap(): addr != 0: TODO ]\n"); |
629 |
|
cpu->running = 0; |
630 |
|
return 0; |
631 |
|
} |
632 |
|
|
633 |
|
fatal("[ useremul_mmap(): TODO ]\n"); |
634 |
|
|
635 |
|
res = 0x18000000ULL; |
636 |
|
|
637 |
|
return res; |
638 |
|
} |
639 |
|
|
640 |
|
|
641 |
|
/*****************************************************************************/ |
642 |
|
|
643 |
|
|
644 |
/* |
/* |
645 |
* useremul__freebsd(): |
* useremul__freebsd(): |
646 |
* |
* |
647 |
* FreeBSD syscall emulation. |
* FreeBSD/Alpha syscall emulation. |
648 |
* |
* |
649 |
* TODO: How to make this work nicely with non-Alpha archs. |
* TODO: How to make this work nicely with non-Alpha archs. |
650 |
*/ |
*/ |
651 |
static void useremul__freebsd(struct cpu *cpu, uint32_t code) |
static void useremul__freebsd(struct cpu *cpu, uint32_t code) |
652 |
{ |
{ |
|
#if 0 |
|
|
unsigned char *cp; |
|
653 |
int nr; |
int nr; |
654 |
uint64_t arg0, arg1, arg2, arg3; |
int64_t res = 0, err = 0; |
655 |
|
uint64_t arg0, arg1, arg2, arg3, arg4, arg5; |
656 |
|
|
657 |
nr = cpu->cd.ppc.gpr[0]; |
nr = cpu->cd.alpha.r[ALPHA_V0]; |
658 |
arg0 = cpu->cd.ppc.gpr[3]; |
arg0 = cpu->cd.alpha.r[ALPHA_A0]; |
659 |
arg1 = cpu->cd.ppc.gpr[4]; |
arg1 = cpu->cd.alpha.r[ALPHA_A1]; |
660 |
arg2 = cpu->cd.ppc.gpr[5]; |
arg2 = cpu->cd.alpha.r[ALPHA_A2]; |
661 |
arg3 = cpu->cd.ppc.gpr[6]; |
arg3 = cpu->cd.alpha.r[ALPHA_A3]; |
662 |
|
arg4 = cpu->cd.alpha.r[ALPHA_A4]; |
663 |
|
arg5 = cpu->cd.alpha.r[ALPHA_A5]; |
664 |
|
|
665 |
|
if (nr == 198) { |
666 |
|
/* ___syscall */ |
667 |
|
nr = arg0; |
668 |
|
arg0 = arg1; |
669 |
|
arg1 = arg2; |
670 |
|
arg2 = arg3; |
671 |
|
arg3 = arg4; |
672 |
|
arg4 = arg5; |
673 |
|
/* TODO: stack arguments */ |
674 |
|
} |
675 |
|
|
676 |
switch (nr) { |
switch (nr) { |
677 |
|
|
678 |
case LINUX_PPC_SYS_exit: |
case 1: res = useremul_exit(cpu, arg0); |
|
debug("[ exit(%i) ]\n", (int)arg0); |
|
|
cpu->running = 0; |
|
679 |
break; |
break; |
680 |
|
|
681 |
case LINUX_PPC_SYS_write: |
case 4: res = useremul_write(cpu, &err, arg0, arg1, arg2); |
|
debug("[ write(%i,0x%llx,%lli) ]\n", |
|
|
(int)arg0, (long long)arg1, (long long)arg2); |
|
|
cp = get_userland_buf(cpu, arg1, arg2); |
|
|
write(arg0, cp, arg2); |
|
|
free(cp); |
|
682 |
break; |
break; |
683 |
|
|
684 |
default: |
case 17:res = useremul_break(cpu, arg0); |
685 |
fatal("useremul__linux(): syscall %i not yet implemented\n", |
break; |
686 |
nr); |
|
687 |
|
case 20:res = useremul_getpid(cpu); |
688 |
|
break; |
689 |
|
|
690 |
|
case 24:res = useremul_getuid(cpu); |
691 |
|
break; |
692 |
|
|
693 |
|
case 43:res = useremul_getegid(cpu); |
694 |
|
break; |
695 |
|
|
696 |
|
case 47:res = useremul_getgid(cpu); |
697 |
|
break; |
698 |
|
|
699 |
|
case 58:res = useremul_readlink(cpu, &err, arg0, arg1, arg2); |
700 |
|
break; |
701 |
|
|
702 |
|
case 117:res = useremul_getrusage(cpu, &err, arg0, arg1); |
703 |
|
break; |
704 |
|
|
705 |
|
case 189:res = useremul_fstat(cpu, &err, arg0, arg1); |
706 |
|
break; |
707 |
|
|
708 |
|
case 197:res = useremul_mmap(cpu, &err, arg0, arg1, arg2, arg3, |
709 |
|
arg4, arg5); |
710 |
|
break; |
711 |
|
|
712 |
|
default:fatal("useremul__freebsd(): syscall %i not yet " |
713 |
|
"implemented\n", nr); |
714 |
cpu->running = 0; |
cpu->running = 0; |
715 |
} |
} |
716 |
#endif |
|
717 |
|
if (err) { |
718 |
|
cpu->cd.alpha.r[ALPHA_A3] = 1; |
719 |
|
cpu->cd.alpha.r[ALPHA_V0] = err; |
720 |
|
} else { |
721 |
|
cpu->cd.alpha.r[ALPHA_A3] = 0; |
722 |
|
cpu->cd.alpha.r[ALPHA_V0] = res; |
723 |
|
} |
724 |
} |
} |
725 |
|
|
726 |
|
|
734 |
static void useremul__linux(struct cpu *cpu, uint32_t code) |
static void useremul__linux(struct cpu *cpu, uint32_t code) |
735 |
{ |
{ |
736 |
int nr; |
int nr; |
737 |
unsigned char *cp; |
int64_t res = 0, err = 0; |
738 |
uint64_t arg0, arg1, arg2, arg3; |
uint64_t arg0, arg1, arg2, arg3; |
739 |
|
|
740 |
if (code != 0) { |
if (code != 0) { |
751 |
switch (nr) { |
switch (nr) { |
752 |
|
|
753 |
case LINUX_PPC_SYS_exit: |
case LINUX_PPC_SYS_exit: |
754 |
debug("[ exit(%i) ]\n", (int)arg0); |
res = useremul_exit(cpu, arg0); |
|
cpu->running = 0; |
|
755 |
break; |
break; |
756 |
|
|
757 |
case LINUX_PPC_SYS_write: |
case LINUX_PPC_SYS_write: |
758 |
debug("[ write(%i,0x%llx,%lli) ]\n", |
res = useremul_write(cpu, &err, arg0, arg1, arg2); |
|
(int)arg0, (long long)arg1, (long long)arg2); |
|
|
cp = get_userland_buf(cpu, arg1, arg2); |
|
|
write(arg0, cp, arg2); |
|
|
free(cp); |
|
759 |
break; |
break; |
760 |
|
|
761 |
default: |
default: |
763 |
nr); |
nr); |
764 |
cpu->running = 0; |
cpu->running = 0; |
765 |
} |
} |
766 |
|
|
767 |
|
/* return res: TODO */ |
768 |
} |
} |
769 |
|
|
770 |
|
|
778 |
int error_flag = 0, result_high_set = 0; |
int error_flag = 0, result_high_set = 0; |
779 |
uint64_t arg0=0,arg1=0,arg2=0,arg3=0,stack0=0,stack1=0,stack2=0; |
uint64_t arg0=0,arg1=0,arg2=0,arg3=0,stack0=0,stack1=0,stack2=0; |
780 |
int sysnr = 0; |
int sysnr = 0; |
781 |
uint64_t error_code = 0; |
int64_t error_code = 0; |
782 |
uint64_t result_low = 0; |
uint64_t result_low = 0; |
783 |
uint64_t result_high = 0; |
uint64_t result_high = 0; |
784 |
struct timeval tv; |
struct timeval tv; |
832 |
arg3 = cpu->cd.ppc.gpr[6]; |
arg3 = cpu->cd.ppc.gpr[6]; |
833 |
/* TODO: More arguments? Stack arguments? */ |
/* TODO: More arguments? Stack arguments? */ |
834 |
break; |
break; |
835 |
|
|
836 |
|
case ARCH_ARM: |
837 |
|
sysnr = code & 0xfffff; |
838 |
|
arg0 = cpu->cd.arm.r[0]; |
839 |
|
arg1 = cpu->cd.arm.r[1]; |
840 |
|
arg2 = cpu->cd.arm.r[2]; |
841 |
|
arg3 = cpu->cd.arm.r[3]; |
842 |
|
/* TODO: More arguments? Stack arguments? */ |
843 |
|
break; |
844 |
|
|
845 |
|
default:fatal("netbsd syscall for this arch: TODO\n"); |
846 |
|
exit(1); |
847 |
} |
} |
848 |
|
|
849 |
/* |
/* |
850 |
* NOTE: The following code should not be CPU arch dependant! |
* NOTE/TODO: The following code should not be CPU arch dependent! |
|
* (TODO) |
|
851 |
*/ |
*/ |
852 |
|
|
853 |
switch (sysnr) { |
switch (sysnr) { |
940 |
break; |
break; |
941 |
|
|
942 |
case NETBSD_SYS_getuid: |
case NETBSD_SYS_getuid: |
943 |
debug("[ getuid() ]\n"); |
result_low = useremul_getuid(cpu); |
|
result_low = getuid(); |
|
944 |
break; |
break; |
945 |
|
|
946 |
case NETBSD_SYS_geteuid: |
case NETBSD_SYS_geteuid: |
998 |
break; |
break; |
999 |
|
|
1000 |
case NETBSD_SYS_break: |
case NETBSD_SYS_break: |
1001 |
debug("[ break(0x%llx): TODO ]\n", (long long)arg0); |
useremul_break(cpu, arg0); |
|
/* TODO */ |
|
1002 |
break; |
break; |
1003 |
|
|
1004 |
case NETBSD_SYS_readlink: |
case NETBSD_SYS_readlink: |
1005 |
charbuf = get_userland_string(cpu, arg0); |
result_low = useremul_readlink(cpu, &error_code, |
1006 |
debug("[ readlink(\"%s\",0x%lli,%lli) ]\n", |
arg0, arg1, arg2); |
|
charbuf, (long long)arg1, (long long)arg2); |
|
|
if (arg2 != 0 && arg2 < 50000) { |
|
|
unsigned char *buf2 = malloc(arg2); |
|
|
buf2[arg2-1] = '\0'; |
|
|
result_low = readlink((char *)charbuf, |
|
|
(char *)buf2, arg2 - 1); |
|
|
if ((int64_t)result_low < 0) { |
|
|
error_flag = 1; |
|
|
error_code = errno; |
|
|
} else |
|
|
store_string(cpu, arg1, (char *)buf2); |
|
|
free(buf2); |
|
|
} |
|
|
free(charbuf); |
|
1007 |
break; |
break; |
1008 |
|
|
1009 |
case NETBSD_SYS_sync: |
case NETBSD_SYS_sync: |
1010 |
debug("[ sync() ]\n"); |
useremul_sync(cpu); |
|
sync(); |
|
1011 |
break; |
break; |
1012 |
|
|
1013 |
case NETBSD_SYS_gettimeofday: |
case NETBSD_SYS_gettimeofday: |
1202 |
|
|
1203 |
|
|
1204 |
switch (cpu->machine->arch) { |
switch (cpu->machine->arch) { |
1205 |
|
case ARCH_ARM: |
1206 |
|
/* NetBSD/arm return values: */ |
1207 |
|
cpu->cd.arm.r[0] = result_low; |
1208 |
|
cpu->cd.arm.cpsr &= ~ARM_FLAG_C; |
1209 |
|
if (error_flag) { |
1210 |
|
cpu->cd.arm.cpsr |= ARM_FLAG_C; |
1211 |
|
cpu->cd.arm.r[0] = error_code; |
1212 |
|
} |
1213 |
|
if (result_high_set) |
1214 |
|
cpu->cd.arm.r[1] = result_high; |
1215 |
|
cpu->cd.arm.flags = cpu->cd.arm.cpsr >> 28; |
1216 |
|
break; |
1217 |
case ARCH_MIPS: |
case ARCH_MIPS: |
1218 |
/* |
/* |
1219 |
* NetBSD/mips return values: |
* NetBSD/mips return values: |
1255 |
int error_flag = 0, result_high_set = 0; |
int error_flag = 0, result_high_set = 0; |
1256 |
uint64_t arg0,arg1,arg2,arg3,stack0=0,stack1=0,stack2; |
uint64_t arg0,arg1,arg2,arg3,stack0=0,stack1=0,stack2; |
1257 |
int sysnr = 0; |
int sysnr = 0; |
1258 |
uint64_t error_code = 0; |
int64_t error_code = 0; |
1259 |
uint64_t result_low = 0; |
uint64_t result_low = 0; |
1260 |
uint64_t result_high = 0; |
uint64_t result_high = 0; |
1261 |
struct timeval tv; |
struct timeval tv; |
1376 |
break; |
break; |
1377 |
|
|
1378 |
case ULTRIX_SYS_break: |
case ULTRIX_SYS_break: |
1379 |
debug("[ break(0x%llx): TODO ]\n", (long long)arg0); |
useremul_break(cpu, arg0); |
|
/* TODO */ |
|
1380 |
break; |
break; |
1381 |
|
|
1382 |
case ULTRIX_SYS_sync: |
case ULTRIX_SYS_sync: |
1383 |
debug("[ sync() ]\n"); |
useremul_sync(cpu); |
|
sync(); |
|
1384 |
break; |
break; |
1385 |
|
|
1386 |
case ULTRIX_SYS_getuid: |
case ULTRIX_SYS_getuid: |
1387 |
debug("[ getuid() ]\n"); |
result_low = useremul_getuid(cpu); |
|
result_low = getuid(); |
|
1388 |
break; |
break; |
1389 |
|
|
1390 |
case ULTRIX_SYS_getgid: |
case ULTRIX_SYS_getgid: |
1490 |
break; |
break; |
1491 |
|
|
1492 |
case ULTRIX_SYS_fstat: |
case ULTRIX_SYS_fstat: |
1493 |
debug("[ fstat(%i, 0x%llx): TODO ]\n", |
result_low = useremul_fstat(cpu, &error_code, arg0, arg1); |
|
(int)arg0, (long long)arg1); |
|
|
|
|
|
if (arg1 != 0) { |
|
|
struct stat st; |
|
|
result_low = fstat(arg0, &st); |
|
|
if ((int64_t)result_low < 0) { |
|
|
error_flag = 1; |
|
|
error_code = errno; |
|
|
} else { |
|
|
/* Fill in the Ultrix stat struct at arg1: */ |
|
|
|
|
|
/* TODO */ |
|
|
} |
|
|
} else { |
|
|
error_flag = 1; |
|
|
error_code = 1111; /* TODO: ultrix ENOMEM? */ |
|
|
} |
|
1494 |
break; |
break; |
1495 |
|
|
1496 |
case ULTRIX_SYS_getpagesize: |
case ULTRIX_SYS_getpagesize: |
1756 |
add_useremul("NetBSD/pmax", ARCH_MIPS, "R3000", |
add_useremul("NetBSD/pmax", ARCH_MIPS, "R3000", |
1757 |
useremul__netbsd, useremul__netbsd_setup); |
useremul__netbsd, useremul__netbsd_setup); |
1758 |
|
|
1759 |
|
add_useremul("NetBSD/arm", ARCH_ARM, "SA1110", |
1760 |
|
useremul__netbsd, useremul__netbsd_setup); |
1761 |
|
|
1762 |
add_useremul("NetBSD/amd64", ARCH_X86, "AMD64", |
add_useremul("NetBSD/amd64", ARCH_X86, "AMD64", |
1763 |
useremul__netbsd, useremul__netbsd_setup); |
useremul__netbsd, useremul__netbsd_setup); |
1764 |
|
|
1765 |
|
add_useremul("NetBSD/alpha", ARCH_ALPHA, "Alpha", |
1766 |
|
useremul__netbsd, useremul__netbsd_setup); |
1767 |
|
|
1768 |
add_useremul("Linux/PPC64", ARCH_PPC, "PPC970", |
add_useremul("Linux/PPC64", ARCH_PPC, "PPC970", |
1769 |
useremul__linux, useremul__linux_setup); |
useremul__linux, useremul__linux_setup); |
1770 |
|
|
1771 |
add_useremul("FreeBSD/Alpha", ARCH_ALPHA, "EV4", |
add_useremul("FreeBSD/Alpha", ARCH_ALPHA, "Alpha", |
1772 |
useremul__freebsd, useremul__freebsd_setup); |
useremul__freebsd, useremul__freebsd_setup); |
1773 |
} |
} |
1774 |
|
|