--- trunk/src/useremul.c 2007/10/08 16:18:38 12 +++ upstream/0.4.4/src/useremul.c 2007/10/08 16:21:26 35 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2005 Anders Gavare. All rights reserved. + * Copyright (C) 2004-2007 Anders Gavare. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -25,36 +25,40 @@ * SUCH DAMAGE. * * - * $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 $ * * Userland (syscall) emulation. * * TODO: * - * NetBSD/pmax: - * environment passing - * more syscalls + * environment passing for most emulation modes + * + * implement more syscalls * * 32-bit vs 64-bit problems? MIPS n32, o32, n64? * * Dynamic ELFs? * * Try to prefix "/emul/mips/" or similar to all filenames, - * and only if that fails, try the given filename + * and only if that fails, try the given filename. + * Read this setting from an environment variable, and only + * if there is none, fall back to hardcoded string. * - * Automagic errno translation? + * Automagic errno translation! * - * Memory allocation? mmap etc. + * Memory allocation? mmap, munmap, mprotect, etc. + * mprotect = unmap in dyntrans... * - * File descriptor (0,1,2) assumptions? + * File descriptor (0,1,2) assumptions? Find and fix these? * * * This module needs more cleanup. * ------------------------------- * * - * NOTE: This module (useremul.c) is just a quick hack to see if - * userland emulation works at all. + * NOTE: This module (useremul.c) is just a quick hack so far, to see if + * userland emulation works at all. It only works for Hello World- + * style programs compiled for FreeBSD/alpha or NetBSD/mips. */ #include @@ -232,6 +236,10 @@ } break; + case ARCH_ALPHA: + debug("useremul__netbsd_setup(): ALPHA: TODO\n"); + break; + case ARCH_ARM: debug("useremul__netbsd_setup(): ARM: TODO\n"); break; @@ -244,9 +252,8 @@ break; - case ARCH_X86: - debug("useremul__netbsd_setup(): X86: TODO\n"); - + case ARCH_SH: + debug("useremul__netbsd_setup(): SH: TODO\n"); break; default: @@ -360,7 +367,7 @@ uint64_t baseaddr, uint64_t len) { unsigned char *charbuf; - ssize_t i; + size_t i; charbuf = malloc(len); if (charbuf == NULL) { @@ -695,6 +702,10 @@ case 58:res = useremul_readlink(cpu, &err, arg0, arg1, arg2); break; + case 73:/* munmap. TODO */ + res = 1; + break; + case 117:res = useremul_getrusage(cpu, &err, arg0, arg1); break; @@ -828,11 +839,22 @@ arg3 = cpu->cd.ppc.gpr[6]; /* TODO: More arguments? Stack arguments? */ break; + + case ARCH_ARM: + sysnr = code & 0xfffff; + arg0 = cpu->cd.arm.r[0]; + arg1 = cpu->cd.arm.r[1]; + arg2 = cpu->cd.arm.r[2]; + arg3 = cpu->cd.arm.r[3]; + /* TODO: More arguments? Stack arguments? */ + break; + + default:fatal("netbsd syscall for this arch: TODO\n"); + exit(1); } /* - * NOTE: The following code should not be CPU arch dependant! - * (TODO) + * NOTE/TODO: The following code should not be CPU arch dependent! */ switch (sysnr) { @@ -1187,6 +1209,18 @@ switch (cpu->machine->arch) { + case ARCH_ARM: + /* NetBSD/arm return values: */ + cpu->cd.arm.r[0] = result_low; + cpu->cd.arm.cpsr &= ~ARM_FLAG_C; + if (error_flag) { + cpu->cd.arm.cpsr |= ARM_FLAG_C; + cpu->cd.arm.r[0] = error_code; + } + if (result_high_set) + cpu->cd.arm.r[1] = result_high; + cpu->cd.arm.flags = cpu->cd.arm.cpsr >> 28; + break; case ARCH_MIPS: /* * NetBSD/mips return values: @@ -1685,7 +1719,7 @@ void useremul_list_emuls(void) { struct syscall_emul *sep; - int iadd = 8; + int iadd = DEBUG_INDENTATION * 2; sep = first_syscall_emul; @@ -1723,16 +1757,19 @@ add_useremul("Ultrix", ARCH_MIPS, "R3000", useremul__ultrix, useremul__ultrix_setup); + add_useremul("NetBSD/sh", ARCH_SH, "SH4", + useremul__netbsd, useremul__netbsd_setup); + add_useremul("NetBSD/powerpc", ARCH_PPC, "PPC750", useremul__netbsd, useremul__netbsd_setup); add_useremul("NetBSD/pmax", ARCH_MIPS, "R3000", useremul__netbsd, useremul__netbsd_setup); - add_useremul("NetBSD/arm", ARCH_ARM, "ARM", + add_useremul("NetBSD/arm", ARCH_ARM, "SA1110", useremul__netbsd, useremul__netbsd_setup); - add_useremul("NetBSD/amd64", ARCH_X86, "AMD64", + add_useremul("NetBSD/alpha", ARCH_ALPHA, "Alpha", useremul__netbsd, useremul__netbsd_setup); add_useremul("Linux/PPC64", ARCH_PPC, "PPC970",