1 |
/* |
/* |
2 |
* Copyright (C) 2004-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2004-2007 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: useremul.c,v 1.62 2005/08/16 06:49:26 debug Exp $ |
* $Id: useremul.c,v 1.74 2007/02/10 14:04:51 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 |
* |
* |
40 |
* Dynamic ELFs? |
* Dynamic ELFs? |
41 |
* |
* |
42 |
* Try to prefix "/emul/mips/" or similar to all filenames, |
* Try to prefix "/emul/mips/" or similar to all filenames, |
43 |
* and only if that fails, try the given filename |
* and only if that fails, try the given filename. |
44 |
|
* Read this setting from an environment variable, and only |
45 |
|
* if there is none, fall back to hardcoded string. |
46 |
* |
* |
47 |
* Automagic errno translation? |
* Automagic errno translation! |
48 |
* |
* |
49 |
* Memory allocation? mmap etc. |
* Memory allocation? mmap, munmap, mprotect, etc. |
50 |
|
* mprotect = unmap in dyntrans... |
51 |
* |
* |
52 |
* File descriptor (0,1,2) assumptions? |
* File descriptor (0,1,2) assumptions? Find and fix these? |
53 |
* |
* |
54 |
* |
* |
55 |
* This module needs more cleanup. |
* This module needs more cleanup. |
56 |
* ------------------------------- |
* ------------------------------- |
57 |
* |
* |
58 |
* |
* |
59 |
* NOTE: This module (useremul.c) is just a quick hack to see if |
* NOTE: This module (useremul.c) is just a quick hack so far, to see if |
60 |
* userland emulation works at all. |
* userland emulation works at all. It only works for Hello World- |
61 |
|
* style programs compiled for FreeBSD/alpha or NetBSD/mips. |
62 |
*/ |
*/ |
63 |
|
|
64 |
#include <errno.h> |
#include <errno.h> |
236 |
} |
} |
237 |
break; |
break; |
238 |
|
|
239 |
|
case ARCH_ALPHA: |
240 |
|
debug("useremul__netbsd_setup(): ALPHA: TODO\n"); |
241 |
|
break; |
242 |
|
|
243 |
case ARCH_ARM: |
case ARCH_ARM: |
244 |
debug("useremul__netbsd_setup(): ARM: TODO\n"); |
debug("useremul__netbsd_setup(): ARM: TODO\n"); |
245 |
break; |
break; |
252 |
|
|
253 |
break; |
break; |
254 |
|
|
255 |
case ARCH_X86: |
case ARCH_SH: |
256 |
debug("useremul__netbsd_setup(): X86: TODO\n"); |
debug("useremul__netbsd_setup(): SH: TODO\n"); |
|
|
|
257 |
break; |
break; |
258 |
|
|
259 |
default: |
default: |
367 |
uint64_t baseaddr, uint64_t len) |
uint64_t baseaddr, uint64_t len) |
368 |
{ |
{ |
369 |
unsigned char *charbuf; |
unsigned char *charbuf; |
370 |
ssize_t i; |
size_t i; |
371 |
|
|
372 |
charbuf = malloc(len); |
charbuf = malloc(len); |
373 |
if (charbuf == NULL) { |
if (charbuf == NULL) { |
702 |
case 58:res = useremul_readlink(cpu, &err, arg0, arg1, arg2); |
case 58:res = useremul_readlink(cpu, &err, arg0, arg1, arg2); |
703 |
break; |
break; |
704 |
|
|
705 |
|
case 73:/* munmap. TODO */ |
706 |
|
res = 1; |
707 |
|
break; |
708 |
|
|
709 |
case 117:res = useremul_getrusage(cpu, &err, arg0, arg1); |
case 117:res = useremul_getrusage(cpu, &err, arg0, arg1); |
710 |
break; |
break; |
711 |
|
|
839 |
arg3 = cpu->cd.ppc.gpr[6]; |
arg3 = cpu->cd.ppc.gpr[6]; |
840 |
/* TODO: More arguments? Stack arguments? */ |
/* TODO: More arguments? Stack arguments? */ |
841 |
break; |
break; |
842 |
|
|
843 |
|
case ARCH_ARM: |
844 |
|
sysnr = code & 0xfffff; |
845 |
|
arg0 = cpu->cd.arm.r[0]; |
846 |
|
arg1 = cpu->cd.arm.r[1]; |
847 |
|
arg2 = cpu->cd.arm.r[2]; |
848 |
|
arg3 = cpu->cd.arm.r[3]; |
849 |
|
/* TODO: More arguments? Stack arguments? */ |
850 |
|
break; |
851 |
|
|
852 |
|
default:fatal("netbsd syscall for this arch: TODO\n"); |
853 |
|
exit(1); |
854 |
} |
} |
855 |
|
|
856 |
/* |
/* |
857 |
* NOTE: The following code should not be CPU arch dependant! |
* NOTE/TODO: The following code should not be CPU arch dependent! |
|
* (TODO) |
|
858 |
*/ |
*/ |
859 |
|
|
860 |
switch (sysnr) { |
switch (sysnr) { |
1209 |
|
|
1210 |
|
|
1211 |
switch (cpu->machine->arch) { |
switch (cpu->machine->arch) { |
1212 |
|
case ARCH_ARM: |
1213 |
|
/* NetBSD/arm return values: */ |
1214 |
|
cpu->cd.arm.r[0] = result_low; |
1215 |
|
cpu->cd.arm.cpsr &= ~ARM_FLAG_C; |
1216 |
|
if (error_flag) { |
1217 |
|
cpu->cd.arm.cpsr |= ARM_FLAG_C; |
1218 |
|
cpu->cd.arm.r[0] = error_code; |
1219 |
|
} |
1220 |
|
if (result_high_set) |
1221 |
|
cpu->cd.arm.r[1] = result_high; |
1222 |
|
cpu->cd.arm.flags = cpu->cd.arm.cpsr >> 28; |
1223 |
|
break; |
1224 |
case ARCH_MIPS: |
case ARCH_MIPS: |
1225 |
/* |
/* |
1226 |
* NetBSD/mips return values: |
* NetBSD/mips return values: |
1719 |
void useremul_list_emuls(void) |
void useremul_list_emuls(void) |
1720 |
{ |
{ |
1721 |
struct syscall_emul *sep; |
struct syscall_emul *sep; |
1722 |
int iadd = 8; |
int iadd = DEBUG_INDENTATION * 2; |
1723 |
|
|
1724 |
sep = first_syscall_emul; |
sep = first_syscall_emul; |
1725 |
|
|
1757 |
add_useremul("Ultrix", ARCH_MIPS, "R3000", |
add_useremul("Ultrix", ARCH_MIPS, "R3000", |
1758 |
useremul__ultrix, useremul__ultrix_setup); |
useremul__ultrix, useremul__ultrix_setup); |
1759 |
|
|
1760 |
|
add_useremul("NetBSD/sh", ARCH_SH, "SH4", |
1761 |
|
useremul__netbsd, useremul__netbsd_setup); |
1762 |
|
|
1763 |
add_useremul("NetBSD/powerpc", ARCH_PPC, "PPC750", |
add_useremul("NetBSD/powerpc", ARCH_PPC, "PPC750", |
1764 |
useremul__netbsd, useremul__netbsd_setup); |
useremul__netbsd, useremul__netbsd_setup); |
1765 |
|
|
1766 |
add_useremul("NetBSD/pmax", ARCH_MIPS, "R3000", |
add_useremul("NetBSD/pmax", ARCH_MIPS, "R3000", |
1767 |
useremul__netbsd, useremul__netbsd_setup); |
useremul__netbsd, useremul__netbsd_setup); |
1768 |
|
|
1769 |
add_useremul("NetBSD/arm", ARCH_ARM, "ARM", |
add_useremul("NetBSD/arm", ARCH_ARM, "SA1110", |
1770 |
useremul__netbsd, useremul__netbsd_setup); |
useremul__netbsd, useremul__netbsd_setup); |
1771 |
|
|
1772 |
add_useremul("NetBSD/amd64", ARCH_X86, "AMD64", |
add_useremul("NetBSD/alpha", ARCH_ALPHA, "Alpha", |
1773 |
useremul__netbsd, useremul__netbsd_setup); |
useremul__netbsd, useremul__netbsd_setup); |
1774 |
|
|
1775 |
add_useremul("Linux/PPC64", ARCH_PPC, "PPC970", |
add_useremul("Linux/PPC64", ARCH_PPC, "PPC970", |