* Re: [Qemu-devel] [PATCH] linux-user: adapt uname machine to emulated CPU
[not found] <20091229213921.GA14667@bee.dooz.org>
@ 2010-01-04 9:21 ` Riku Voipio
2010-01-14 15:07 ` Aurelien Jarno
1 sibling, 0 replies; 3+ messages in thread
From: Riku Voipio @ 2010-01-04 9:21 UTC (permalink / raw)
To: Loïc Minier; +Cc: qemu-devel
Hi,
Works great, thanks.
Acked-By: Riku Voipio <riku.voipio@iki.fi>
On Tue, Dec 29, 2009 at 10:39:21PM +0100, Loïc Minier wrote:
> Hey there
>
> 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.
>
> Thanks,
>
>
> ---
> 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 7c1f30c..6414472 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -90,7 +90,7 @@ ifdef CONFIG_LINUX_USER
> VPATH+=:$(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR)
> QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR)
> obj-y = 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
>
> obj-$(TARGET_HAS_BFLT) += flatload.o
> obj-$(TARGET_HAS_ELFLOAD32) += elfload32.o
> diff --git a/linux-user/cpu-uname.c b/linux-user/cpu-uname.c
> new file mode 100644
> index 0000000..ddc37be
> --- /dev/null
> +++ b/linux-user/cpu-uname.c
> @@ -0,0 +1,72 @@
> +/*
> + * cpu to uname machine name map
> + *
> + * Copyright (c) 2009 Loïc 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 <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <stdio.h>
> +
> +#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 string 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, use:
> + * 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 = ((CPUX86State *)cpu_env)->cpuid_version;
> + int family = ((cpuid_version >> 8) & 0x0f) + ((cpuid_version >> 20) & 0xff);
> + if (family == 4)
> + return "i486";
> + if (family == 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 1acf1f5..9e2e89a 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -82,6 +82,7 @@
> #include <linux/fb.h>
> #include <linux/vt.h>
> #include "linux_loop.h"
> +#include "cpu-uname.h"
>
> #include "qemu.h"
> #include "qemu-common.h"
> @@ -5739,7 +5740,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
> if (!is_error(ret)) {
> /* Overrite the native machine name with whatever is being
> 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);
> --
> 1.6.5
>
>
> --
> Loïc Minier
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user: adapt uname machine to emulated CPU
[not found] <20091229213921.GA14667@bee.dooz.org>
2010-01-04 9:21 ` [Qemu-devel] [PATCH] linux-user: adapt uname machine to emulated CPU Riku Voipio
@ 2010-01-14 15:07 ` Aurelien Jarno
2010-01-17 11:52 ` Loïc Minier
1 sibling, 1 reply; 3+ messages in thread
From: Aurelien Jarno @ 2010-01-14 15:07 UTC (permalink / raw)
To: Loïc Minier; +Cc: qemu-devel
On Tue, Dec 29, 2009 at 10:39:21PM +0100, Loïc Minier wrote:
> Hey there
>
> 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.
This patch look ok, but is missing a Signed-off-by:
Aurelien
> Thanks,
>
>
> ---
> 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 7c1f30c..6414472 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -90,7 +90,7 @@ ifdef CONFIG_LINUX_USER
> VPATH+=:$(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR)
> QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR)
> obj-y = 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
>
> obj-$(TARGET_HAS_BFLT) += flatload.o
> obj-$(TARGET_HAS_ELFLOAD32) += elfload32.o
> diff --git a/linux-user/cpu-uname.c b/linux-user/cpu-uname.c
> new file mode 100644
> index 0000000..ddc37be
> --- /dev/null
> +++ b/linux-user/cpu-uname.c
> @@ -0,0 +1,72 @@
> +/*
> + * cpu to uname machine name map
> + *
> + * Copyright (c) 2009 Loïc 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 <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <stdio.h>
> +
> +#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 string 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, use:
> + * 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 = ((CPUX86State *)cpu_env)->cpuid_version;
> + int family = ((cpuid_version >> 8) & 0x0f) + ((cpuid_version >> 20) & 0xff);
> + if (family == 4)
> + return "i486";
> + if (family == 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 1acf1f5..9e2e89a 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -82,6 +82,7 @@
> #include <linux/fb.h>
> #include <linux/vt.h>
> #include "linux_loop.h"
> +#include "cpu-uname.h"
>
> #include "qemu.h"
> #include "qemu-common.h"
> @@ -5739,7 +5740,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
> if (!is_error(ret)) {
> /* Overrite the native machine name with whatever is being
> 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);
> --
> 1.6.5
>
>
> --
> Loïc Minier
>
>
>
--
Aurelien Jarno GPG: 1024D/F1BCDB73
aurelien@aurel32.net http://www.aurel32.net
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user: adapt uname machine to emulated CPU
2010-01-14 15:07 ` Aurelien Jarno
@ 2010-01-17 11:52 ` Loïc Minier
0 siblings, 0 replies; 3+ messages in thread
From: Loïc Minier @ 2010-01-17 11:52 UTC (permalink / raw)
To: Aurelien Jarno; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 338 bytes --]
On Thu, Jan 14, 2010, Aurelien Jarno wrote:
> This patch look ok, but is missing a Signed-off-by:
Attaching a rebased patch with a Signed-off-by. [ I didn't retest, but
it applied without any merge issue and there was only two
(arch-specific) commits in linux-user since the previous version. ]
Thanks,
--
Loïc Minier
[-- Attachment #2: 0001-linux-user-adapt-uname-machine-to-emulated-CPU.patch --]
[-- Type: text/x-diff, Size: 5166 bytes --]
>From c4396cafac0041cfa2fed686f935e9df3636e05b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Minier?= <lool@dooz.org>
Date: Tue, 29 Dec 2009 22:06:13 +0100
Subject: [PATCH] linux-user: adapt uname machine to emulated CPU
---
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 e661478..9f5bd17 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -95,7 +95,7 @@ $(call set-vpath, $(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR
QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR)
obj-y = 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
obj-$(TARGET_HAS_BFLT) += flatload.o
obj-$(TARGET_HAS_ELFLOAD32) += elfload32.o
diff --git a/linux-user/cpu-uname.c b/linux-user/cpu-uname.c
new file mode 100644
index 0000000..ddc37be
--- /dev/null
+++ b/linux-user/cpu-uname.c
@@ -0,0 +1,72 @@
+/*
+ * cpu to uname machine name map
+ *
+ * Copyright (c) 2009 Loïc 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+
+#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 string 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, use:
+ * 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 = ((CPUX86State *)cpu_env)->cpuid_version;
+ int family = ((cpuid_version >> 8) & 0x0f) + ((cpuid_version >> 20) & 0xff);
+ if (family == 4)
+ return "i486";
+ if (family == 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 <linux/fb.h>
#include <linux/vt.h>
#include "linux_loop.h"
+#include "cpu-uname.h"
#include "qemu.h"
#include "qemu-common.h"
@@ -5739,7 +5740,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
if (!is_error(ret)) {
/* Overrite the native machine name with whatever is being
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);
--
1.6.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-01-17 11:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20091229213921.GA14667@bee.dooz.org>
2010-01-04 9:21 ` [Qemu-devel] [PATCH] linux-user: adapt uname machine to emulated CPU Riku Voipio
2010-01-14 15:07 ` Aurelien Jarno
2010-01-17 11:52 ` Loïc Minier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).