From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NZnpu-0007wR-2J for qemu-devel@nongnu.org; Tue, 26 Jan 2010 11:00:14 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NZnpq-0007sV-8F for qemu-devel@nongnu.org; Tue, 26 Jan 2010 11:00:10 -0500 Received: from [199.232.76.173] (port=45570 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZnpp-0007s7-Ve for qemu-devel@nongnu.org; Tue, 26 Jan 2010 11:00:10 -0500 Received: from afflict.kos.to ([92.243.29.197]:36703) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NZnpo-0000VT-5d for qemu-devel@nongnu.org; Tue, 26 Jan 2010 11:00:09 -0500 From: Riku Voipio Date: Tue, 26 Jan 2010 16:00:00 +0000 Message-Id: <1264521604-2020-2-git-send-email-riku.voipio@iki.fi> In-Reply-To: <1264521604-2020-1-git-send-email-riku.voipio@iki.fi> References: <1264521604-2020-1-git-send-email-riku.voipio@iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 1/5] linux-user: adapt uname machine to emulated CPU List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Lo=C3=AFc=20Minier?= From: Lo=C3=AFc Minier This patch for linux-user adapts the output of the emulated uname() syscall to match the configured CPU. Tested with x86, x86-64 and arm emulation. Signed-off-by: Lo=C3=AFc Minier Signed-off-by: Riku Voipio --- Makefile.target | 2 +- linux-user/cpu-uname.c | 72 ++++++++++++++++++++++++++++++++++++++++++= ++++++ linux-user/cpu-uname.h | 1 + linux-user/syscall.c | 3 +- 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 linux-user/cpu-uname.c create mode 100644 linux-user/cpu-uname.h diff --git a/Makefile.target b/Makefile.target index 5c0ef1f..9dfc4c2 100644 --- a/Makefile.target +++ b/Makefile.target @@ -95,7 +95,7 @@ $(call set-vpath, $(SRC_PATH)/linux-user:$(SRC_PATH)/li= nux-user/$(TARGET_ABI_DIR =20 QEMU_CFLAGS+=3D-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGE= T_ABI_DIR) obj-y =3D main.o syscall.o strace.o mmap.o signal.o thunk.o \ - elfload.o linuxload.o uaccess.o gdbstub.o + elfload.o linuxload.o uaccess.o gdbstub.o cpu-uname.o =20 obj-$(TARGET_HAS_BFLT) +=3D flatload.o obj-$(TARGET_HAS_ELFLOAD32) +=3D elfload32.o diff --git a/linux-user/cpu-uname.c b/linux-user/cpu-uname.c new file mode 100644 index 0000000..23afede --- /dev/null +++ b/linux-user/cpu-uname.c @@ -0,0 +1,72 @@ +/* + * cpu to uname machine name map + * + * Copyright (c) 2009 Lo=EFc Minier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include + +#include "qemu.h" +//#include "qemu-common.h" +#include "cpu-uname.h" + +/* return highest utsname machine name for emulated instruction set + * + * NB: the default emulated CPU ("any") might not match any existing CPU= , e.g. + * on ARM it has all features turned on, so there is no perfect arch str= ing to + * return here */ +const char *cpu_to_uname_machine(void *cpu_env) +{ +#ifdef TARGET_ARM + /* utsname machine name on linux arm is CPU arch name + endianness, = e.g. + * armv7l; to get a list of CPU arch names from the linux source, us= e: + * grep arch_name: -A1 linux/arch/arm/mm/proc-*.S + * see arch/arm/kernel/setup.c: setup_processor() + * + * to test by CPU id, compare cpu_env->cp15.c0_cpuid to ARM_CPUID_* + * defines and to test by CPU feature, use arm_feature(cpu_env, + * ARM_FEATURE_*) */ + + /* in theory, endianness is configurable on some ARM CPUs, but this = isn't + * used in user mode emulation */ +#ifdef TARGET_WORDS_BIGENDIAN +#define utsname_suffix "b" +#else +#define utsname_suffix "l" +#endif + if (arm_feature(cpu_env, ARM_FEATURE_V7)) + return "armv7" utsname_suffix; + if (arm_feature(cpu_env, ARM_FEATURE_V6)) + return "armv6" utsname_suffix; + /* earliest emulated CPU is ARMv5TE; qemu can emulate the 1026, but = not its + * Jazelle support */ + return "armv5te" utsname_suffix; +#elif defined(TARGET_X86_64) + return "x86-64"; +#elif defined(TARGET_I386) + /* see arch/x86/kernel/cpu/bugs.c: check_bugs(), 386, 486, 586, 686 = */ + uint32_t cpuid_version =3D ((CPUX86State *)cpu_env)->cpuid_version; + int family =3D ((cpuid_version >> 8) & 0x0f) + ((cpuid_version >> 20= ) & 0xff); + if (family =3D=3D 4) + return "i486"; + if (family =3D=3D 5) + return "i586"; + return "i686"; +#else + /* default is #define-d in each arch/ subdir */ + return UNAME_MACHINE; +#endif +} diff --git a/linux-user/cpu-uname.h b/linux-user/cpu-uname.h new file mode 100644 index 0000000..32492de --- /dev/null +++ b/linux-user/cpu-uname.h @@ -0,0 +1 @@ +const char *cpu_to_uname_machine(void *cpu_env); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f2dd39e..9fb493f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -82,6 +82,7 @@ #include #include #include "linux_loop.h" +#include "cpu-uname.h" =20 #include "qemu.h" #include "qemu-common.h" @@ -5739,7 +5740,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, if (!is_error(ret)) { /* Overrite the native machine name with whatever is bei= ng emulated. */ - strcpy (buf->machine, UNAME_MACHINE); + strcpy (buf->machine, cpu_to_uname_machine(cpu_env)); /* Allow the user to override the reported release. */ if (qemu_uname_release && *qemu_uname_release) strcpy (buf->release, qemu_uname_release); --=20 1.6.5