linux-user: select CPU type according ELF header values
v3 cover linux-user: select CPU type according ELF header values
This idea has been suggested to me before by Philippe Mathieu-Daudé, and recently YunQiang Su has proposed a patch to manage the MIPS r6 case.
Based on this, this series tries to clean-up the original patch, and introduces the use for m68k architecture and port the patch from YunQiang Su.
v3: fix code indent problem reported by patchew
remove useless "!= 0"
check for EF_M68K_M68000
add EF_M68K_* flags in elf.h
set 680x0 default CPU to m68040
change "#if ... #endif" structure for ppcv2: move cpu_model selection to linux-user/*/target_elf.h
provide eflags to cpu_get_model() instead of fd (and modify other patches accordingly)
Laurent Vivier (2):
linux-user: Move CPU type name selection to a function linux-user,m68k: select CPU according to ELF header values
YunQiang Su (2):
linux-user: introduce functions to detect CPU type
linux-user: MIPS set cpu to r6 CPU if binary is R6
include/elf.h | 32 +++++++++++++++++++++ linux-user/aarch64/target_elf.h | 14 +++++++++ linux-user/alpha/target_elf.h | 14 +++++++++ linux-user/arm/target_elf.h | 14 +++++++++ linux-user/cris/target_elf.h | 14 +++++++++ linux-user/elfload.c | 35 ++++++++++++++++++++++ linux-user/hppa/target_elf.h | 14 +++++++++ linux-user/i386/target_elf.h | 14 +++++++++ linux-user/m68k/target_elf.h | 20 +++++++++++++ linux-user/main.c | 59 +++++++------------------------------- linux-user/microblaze/target_elf.h | 14 +++++++++ linux-user/mips/target_elf.h | 17 +++++++++++ linux-user/mips64/target_elf.h | 17 +++++++++++ linux-user/nios2/target_elf.h | 14 +++++++++ linux-user/openrisc/target_elf.h | 14 +++++++++ linux-user/ppc/target_elf.h | 18 ++++++++++++ linux-user/qemu.h | 1 + linux-user/s390x/target_elf.h | 14 +++++++++ linux-user/sh4/target_elf.h | 14 +++++++++ linux-user/sparc/target_elf.h | 14 +++++++++ linux-user/sparc64/target_elf.h | 14 +++++++++ linux-user/tilegx/target_elf.h | 14 +++++++++ linux-user/unicore32/target_elf.h | 14 +++++++++ linux-user/x86_64/target_elf.h | 14 +++++++++ 24 files changed, 375 insertions(+), 48 deletions(-) create mode 100644 linux-user/aarch64/target_elf.h create mode 100644 linux-user/alpha/target_elf.h create mode 100644 linux-user/arm/target_elf.h create mode 100644 linux-user/cris/target_elf.h create mode 100644 linux-user/hppa/target_elf.h create mode 100644 linux-user/i386/target_elf.h create mode 100644 linux-user/m68k/target_elf.h create mode 100644 linux-user/microblaze/target_elf.h create mode 100644 linux-user/mips/target_elf.h create mode 100644 linux-user/mips64/target_elf.h create mode 100644 linux-user/nios2/target_elf.h create mode 100644 linux-user/openrisc/target_elf.h create mode 100644 linux-user/ppc/target_elf.h create mode 100644 linux-user/s390x/target_elf.h create mode 100644 linux-user/sh4/target_elf.h create mode 100644 linux-user/sparc/target_elf.h create mode 100644 linux-user/sparc64/target_elf.h create mode 100644 linux-user/tilegx/target_elf.h create mode 100644 linux-user/unicore32/target_elf.h create mode 100644 linux-user/x86_64/target_elf.h
Signature · 1 line
2.14.3
PATCH v3 1/4 linux-user: Move CPU type name selection to a function
Instead of a sequence of "#if ... #endif" move the selection to a function in linux-user/*/target_elf.h
We can't add them in linux-user/*/target_cpu.h
because we will need to include "elf.h" to
use ELF flags with eflags, and including
"elf.h" in "target_cpu.h" introduces some
conflicts in elfload.c
---
Notes:
v3: change "#if ... #endif" structure for ppc
v2: new patch in the series
linux-user/aarch64/target_elf.h | 14 +++++++++++++ linux-user/alpha/target_elf.h | 14 +++++++++++++ linux-user/arm/target_elf.h | 14 +++++++++++++ linux-user/cris/target_elf.h | 14 +++++++++++++ linux-user/hppa/target_elf.h | 14 +++++++++++++ linux-user/i386/target_elf.h | 14 +++++++++++++ linux-user/m68k/target_elf.h | 14 +++++++++++++ linux-user/main.c | 41 ++------------------------------------ linux-user/microblaze/target_elf.h | 14 +++++++++++++ linux-user/mips/target_elf.h | 14 +++++++++++++ linux-user/mips64/target_elf.h | 14 +++++++++++++ linux-user/nios2/target_elf.h | 14 +++++++++++++ linux-user/openrisc/target_elf.h | 14 +++++++++++++ linux-user/ppc/target_elf.h | 18 +++++++++++++++++ linux-user/s390x/target_elf.h | 14 +++++++++++++ linux-user/sh4/target_elf.h | 14 +++++++++++++ linux-user/sparc/target_elf.h | 14 +++++++++++++ linux-user/sparc64/target_elf.h | 14 +++++++++++++ linux-user/tilegx/target_elf.h | 14 +++++++++++++ linux-user/unicore32/target_elf.h | 14 +++++++++++++ linux-user/x86_64/target_elf.h | 14 +++++++++++++ 21 files changed, 286 insertions(+), 39 deletions(-) create mode 100644 linux-user/aarch64/target_elf.h create mode 100644 linux-user/alpha/target_elf.h create mode 100644 linux-user/arm/target_elf.h create mode 100644 linux-user/cris/target_elf.h create mode 100644 linux-user/hppa/target_elf.h create mode 100644 linux-user/i386/target_elf.h create mode 100644 linux-user/m68k/target_elf.h create mode 100644 linux-user/microblaze/target_elf.h create mode 100644 linux-user/mips/target_elf.h create mode 100644 linux-user/mips64/target_elf.h create mode 100644 linux-user/nios2/target_elf.h create mode 100644 linux-user/openrisc/target_elf.h create mode 100644 linux-user/ppc/target_elf.h create mode 100644 linux-user/s390x/target_elf.h create mode 100644 linux-user/sh4/target_elf.h create mode 100644 linux-user/sparc/target_elf.h create mode 100644 linux-user/sparc64/target_elf.h create mode 100644 linux-user/tilegx/target_elf.h create mode 100644 linux-user/unicore32/target_elf.h create mode 100644 linux-user/x86_64/target_elf.h
linux-user/aarch64/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef AARCH64_TARGET_ELF_H +#define AARCH64_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "any" ; +} +#endif
linux-user/alpha/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef ALPHA_TARGET_ELF_H +#define ALPHA_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "any" ; +} +#endif
linux-user/arm/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef ARM_TARGET_ELF_H +#define ARM_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "any" ; +} +#endif
linux-user/cris/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef CRIS_TARGET_ELF_H +#define CRIS_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "any" ; +} +#endif
linux-user/hppa/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef HPPA_TARGET_ELF_H +#define HPPA_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "any" ; +} +#endif
linux-user/i386/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef I386_TARGET_ELF_H +#define I386_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "qemu32" ; +} +#endif
linux-user/m68k/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef M68K_TARGET_ELF_H +#define M68K_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "any" ; +} +#endif
linux-user/main.c +2 -39
53 lines not on this page · raw message
linux-user/microblaze/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef MICROBLAZE_TARGET_ELF_H +#define MICROBLAZE_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "any" ; +} +#endif
linux-user/mips/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef MIPS_TARGET_ELF_H +#define MIPS_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "24Kf" ; +} +#endif
linux-user/mips64/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef MIPS64_TARGET_ELF_H +#define MIPS64_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "5KEf" ; +} +#endif
linux-user/nios2/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef NIOS2_TARGET_ELF_H +#define NIOS2_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "any" ; +} +#endif
linux-user/openrisc/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef OPENRISC_TARGET_ELF_H +#define OPENRISC_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "or1200" ; +} +#endif
linux-user/ppc/target_elf.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef PPC_TARGET_ELF_H +#define PPC_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +#ifdef TARGET_PPC64 +return "POWER8" ; +#else +return "750" ; +#endif +} +#endif
linux-user/s390x/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef S390X_TARGET_ELF_H +#define S390X_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "qemu" ; +} +#endif
linux-user/sh4/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef SH4_TARGET_ELF_H +#define SH4_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "sh7785" ; +} +#endif
linux-user/sparc/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef SPARC_TARGET_ELF_H +#define SPARC_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "Fujitsu MB86904" ; +} +#endif
linux-user/sparc64/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef SPARC64_TARGET_ELF_H +#define SPARC64_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "TI UltraSparc II" ; +} +#endif
linux-user/tilegx/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef TILEGX_TARGET_ELF_H +#define TILEGX_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "any" ; +} +#endif
linux-user/unicore32/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef UNICORE32_TARGET_ELF_H +#define UNICORE32_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "any" ; +} +#endif
linux-user/x86_64/target_elf.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or (at your option) any +* later version. See the COPYING file in the top-level directory. +*/ + +#ifndef X86_64_TARGET_ELF_H +#define X86_64_TARGET_ELF_H +static inline const char *cpu_get_model (uint32_t eflags) +{ +return "qemu64" ; +} +#endif
Signature · 1 line
2.14.3
PATCH v3 2/4 linux-user: introduce functions to detect CPU type
In reply to Laurent VivierFrom: YunQiang Su <[email protected]>
Add a function to return ELF e_flags and use it to select the CPU model.
---
Notes:
YunQiang Su, please add your Signed-off-by that was missing in your original patch.
v2: call cpu_get_model() with the result of get_elf_eflags()
linux-user/elfload.c | 35 +++++++++++++++++++++++++++++++++++ linux-user/main.c | 20 ++++++++++---------- linux-user/qemu.h | 1 + 3 files changed, 46 insertions(+), 10 deletions(-)
linux-user/elfload.c +35 -0
@@ -2376,6 +2376,41 @@ give_up:g_free (syms); } +uint32_t get_elf_eflags (int fd) +{ +struct elfhdr ehdr; +off_t offset; +int ret; + +/* Read ELF header */ + offset =lseek (fd,0 ,SEEK_SET ); +if (offset == (off_t) -1 ) { +return 0 ; + } + ret =read (fd, &ehdr,sizeof (ehdr)); +if (ret <sizeof (ehdr)) { +return 0 ; + } + offset =lseek (fd, offset,SEEK_SET ); +if (offset == (off_t) -1 ) { +return 0 ; + } + +/* Check ELF signature */ +if (!elf_check_ident (&ehdr)) { +return 0 ; + } + +/* check header */ +bswap_ehdr (&ehdr); +if (!elf_check_ehdr (&ehdr)) { +return 0 ; + } + +/* return architecture id */ +return ehdr.e_flags; +} +int load_elf_binary (struct linux_binprm *bprm,struct image_info *info) {struct image_info interp_info;
linux-user/main.c +10 -10
@@ -4319,8 +4319,17 @@ int main(int argc, char **argv, char **envp)init_qemu_uname_release (); + execfd =qemu_getauxval (AT_EXECFD ); +if (execfd ==0 ) { + execfd =open (filename,O_RDONLY ); +if (execfd <0 ) { +printf ("Error while loading %s: %s\n" , filename,strerror (errno)); +_exit (EXIT_FAILURE ); + } + } +if (cpu_model ==NULL ) { - cpu_model =cpu_get_model (0 ); + cpu_model =cpu_get_model (get_elf_eflags (execfd)); }tcg_exec_init (0 );/* NOTE: we need to init the CPU at this stage to get
@@ -4413,15 +4422,6 @@ int main(int argc, char **argv, char **envp) cpu->opaque = ts;task_settid (ts); - execfd =qemu_getauxval (AT_EXECFD ); -if (execfd ==0 ) { - execfd =open (filename,O_RDONLY ); -if (execfd <0 ) { -printf ("Error while loading %s: %s\n" , filename,strerror (errno)); -_exit (EXIT_FAILURE ); - } - } - ret =loader_exec (execfd, filename, target_argv, target_environ, regs, info, &bprm);if (ret !=0 ) {
linux-user/qemu.h +1 -0
@@ -188,6 +188,7 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, struct target_pt_regs * regs, struct image_info *infop, struct linux_binprm *); +uint32_t get_elf_eflags (int fd);int load_elf_binary (struct linux_binprm *bprm,struct image_info *info);int load_flt_binary (struct linux_binprm *bprm,struct image_info *info);
Signature · 1 line
2.14.3
PATCH v3 3/4 linux-user, m68k: select CPU according to ELF header values
In reply to Laurent VivierM680x0 doesn't support the same set of instructions as ColdFire, so we can't use "any" CPU type to execute m68020 instructions.
We select CPU type ("m68040" or "any" for ColdFire) according to the ELF header. If we can't, we use by default the value used until now: "any".
---
Notes:
v3: check for EF_M68K_M68000
add EF_M68K_* flags in elf.h
set 680x0 default CPU to m68040
v2: call cpu_get_model() with the result of get_elf_eflags()
include/elf.h | 28 ++++++++++++++++++++++++++++ linux-user/m68k/target_elf.h | 6 ++++++ 2 files changed, 34 insertions(+)
include/elf.h +28 -0
@@ -537,6 +537,34 @@ typedef struct {#define HWCAP_S390_HIGH_GPRS 512#define HWCAP_S390_TE 1024 +/* M68K specific definitions. */ +/* We use the top 24 bits to encode information about the +architecture variant. */ +#define EF_M68K_CPU32 0x00810000 +#define EF_M68K_M68000 0x01000000 +#define EF_M68K_CFV4E 0x00008000 +#define EF_M68K_FIDO 0x02000000 +#define EF_M68K_ARCH_MASK \ + (EF_M68K_M68000 | EF_M68K_CPU32 | EF_M68K_CFV4E | EF_M68K_FIDO) + +/* We use the bottom 8 bits to encode information about the +coldfire variant. If we use any of these bits, the top 24 bits are +either 0 or EF_M68K_CFV4E. */ +#define EF_M68K_CF_ISA_MASK 0x0F/* Which ISA */ +#define EF_M68K_CF_ISA_A_NODIV 0x01/* ISA A except for div */ +#define EF_M68K_CF_ISA_A 0x02 +#define EF_M68K_CF_ISA_A_PLUS 0x03 +#define EF_M68K_CF_ISA_B_NOUSP 0x04/* ISA_B except for USP */ +#define EF_M68K_CF_ISA_B 0x05 +#define EF_M68K_CF_ISA_C 0x06 +#define EF_M68K_CF_ISA_C_NODIV 0x07/* ISA C except for div */ +#define EF_M68K_CF_MAC_MASK 0x30 +#define EF_M68K_CF_MAC 0x10/* MAC */ +#define EF_M68K_CF_EMAC 0x20/* EMAC */ +#define EF_M68K_CF_EMAC_B 0x30/* EMAC_B */ +#define EF_M68K_CF_FLOAT 0x40/* Has float insns */ +#define EF_M68K_CF_MASK 0xFF +/* * 68k ELF relocation types */
linux-user/m68k/target_elf.h +6 -0
@@ -9,6 +9,12 @@#define M68K_TARGET_ELF_H static inline const char *cpu_get_model (uint32_t eflags) { +if (eflags ==0 || (eflags &EF_M68K_M68000 )) { +/* 680x0 */ +return "m68040" ; + } + +/* Coldfire */ return "any" ; }#endif
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH v3 3/4] linux-user, m68k: select CPU according to ELF header values
Quoted 9 lines · Laurent Vivier
M680x0 doesn't support the same set of instructions as ColdFire, so we can't use "any" CPU type to execute m68020 instructions.
We select CPU type ("m68040" or "any" for ColdFire) according to the ELF header. If we can't, we use by default the value used until now: "any".Signed-off-by Laurent Vivier <[email protected]>---
r~
PATCH v3 4/4 linux-user: MIPS set cpu to r6 CPU if binary is R6
In reply to Laurent VivierFrom: YunQiang Su <[email protected]>
So here we need to detect the version of binaries and set cpu_model for it.
---
Notes:
YunQiang Su, please add your Signed-off-by that was missing in your original patch.
v3: fix code indent problem reported by patchew
remove useless "!= 0"
v2: call cpu_get_model() with the result of get_elf_eflags()
include/elf.h | 4 ++++ linux-user/mips/target_elf.h | 3 +++ linux-user/mips64/target_elf.h | 3 +++ 3 files changed, 10 insertions(+)
include/elf.h +4 -0
@@ -40,6 +40,10 @@ typedef int64_t Elf64_Sxword;#define EF_MIPS_ARCH_5 0x40000000/* -mips5 code. */ #define EF_MIPS_ARCH_32 0x50000000/* MIPS32 code. */ #define EF_MIPS_ARCH_64 0x60000000/* MIPS64 code. */ +#define EF_MIPS_ARCH_32R2 0x70000000/* MIPS32r2 code. */ +#define EF_MIPS_ARCH_64R2 0x80000000/* MIPS64r2 code. */ +#define EF_MIPS_ARCH_32R6 0x90000000/* MIPS32r6 code. */ +#define EF_MIPS_ARCH_64R6 0xa0000000/* MIPS64r6 code. */ /* The ABI of a file. */ #define EF_MIPS_ABI_O32 0x00001000/* O32 ABI. */
linux-user/mips/target_elf.h +3 -0
@@ -9,6 +9,9 @@#define MIPS_TARGET_ELF_H static inline const char *cpu_get_model (uint32_t eflags) { +if (eflags &EF_MIPS_ARCH_32R6 ) { +return "mips32r6-generic" ; + }return "24Kf" ; }#endif
linux-user/mips64/target_elf.h +3 -0
@@ -9,6 +9,9 @@#define MIPS64_TARGET_ELF_H static inline const char *cpu_get_model (uint32_t eflags) { +if (eflags &EF_MIPS_ARCH_64R6 ) { +return "I6400" ; + }return "5KEf" ; }#endif
Signature · 1 line
2.14.3
Quoted 9 lines · On Tue, 16 Jan 2018 23:22:08 +0100 Laurent Vivier <[email protected]> wrote:
This idea has been suggested to me before by Philippe Mathieu-Daudé, and recently YunQiang Su has proposed a patch to manage the MIPS r6 case.
Based on this, this series tries to clean-up the original patch, and introduces the use for m68k architecture and port the patch from YunQiang Su.
v3: fix code indent problem reported by patchew
Quoted 8 lines
remove useless "!= 0" check for EF_M68K_M68000 add EF_M68K_* flags in elf.h set 680x0 default CPU to m68040 change "#if ... #endif" structure for ppcv2: move
cpu_modelselection tolinux-user/*/target_elf.h
provide eflags tocpu_get_model()instead of fd (and modify other patches accordingly)
Sorry for not noticing it earlier, but could you please fix series to use cpu type names instead of cpu_model?
I've just posted series that completes cpu_model refactoring
[PATCH 00/24] generalize parsing of cpu_model (part 4)
which removes remnants of the code using cpu_model to instantiate CPUs, including reworking how default cpu type for *-user is picked up.
After that cpu_model shouldn't be used anywhere in the code except of routines that process "-cpu" CLI and cpu types should be used directly.
So you might not need 1/4 after that or it would have to be reworked and probably other patches where where cpu_model is used.
Quoted 54 lines
Laurent Vivier (2):
linux-user: Move CPU type name selection to a function linux-user,m68k: select CPU according to ELF header valuesYunQiang Su (2):
linux-user: introduce functions to detect CPU type
linux-user: MIPS set cpu to r6 CPU if binary is R6include/elf.h | 32 +++++++++++++++++++++ linux-user/aarch64/target_elf.h | 14 +++++++++ linux-user/alpha/target_elf.h | 14 +++++++++ linux-user/arm/target_elf.h | 14 +++++++++ linux-user/cris/target_elf.h | 14 +++++++++ linux-user/elfload.c | 35 ++++++++++++++++++++++ linux-user/hppa/target_elf.h | 14 +++++++++ linux-user/i386/target_elf.h | 14 +++++++++ linux-user/m68k/target_elf.h | 20 +++++++++++++ linux-user/main.c | 59 +++++++------------------------------- linux-user/microblaze/target_elf.h | 14 +++++++++ linux-user/mips/target_elf.h | 17 +++++++++++ linux-user/mips64/target_elf.h | 17 +++++++++++ linux-user/nios2/target_elf.h | 14 +++++++++ linux-user/openrisc/target_elf.h | 14 +++++++++ linux-user/ppc/target_elf.h | 18 ++++++++++++ linux-user/qemu.h | 1 + linux-user/s390x/target_elf.h | 14 +++++++++ linux-user/sh4/target_elf.h | 14 +++++++++ linux-user/sparc/target_elf.h | 14 +++++++++ linux-user/sparc64/target_elf.h | 14 +++++++++ linux-user/tilegx/target_elf.h | 14 +++++++++ linux-user/unicore32/target_elf.h | 14 +++++++++ linux-user/x86_64/target_elf.h | 14 +++++++++ 24 files changed, 375 insertions(+), 48 deletions(-) create mode 100644 linux-user/aarch64/target_elf.h create mode 100644 linux-user/alpha/target_elf.h create mode 100644 linux-user/arm/target_elf.h create mode 100644 linux-user/cris/target_elf.h create mode 100644 linux-user/hppa/target_elf.h create mode 100644 linux-user/i386/target_elf.h create mode 100644 linux-user/m68k/target_elf.h create mode 100644 linux-user/microblaze/target_elf.h create mode 100644 linux-user/mips/target_elf.h create mode 100644 linux-user/mips64/target_elf.h create mode 100644 linux-user/nios2/target_elf.h create mode 100644 linux-user/openrisc/target_elf.h create mode 100644 linux-user/ppc/target_elf.h create mode 100644 linux-user/s390x/target_elf.h create mode 100644 linux-user/sh4/target_elf.h create mode 100644 linux-user/sparc/target_elf.h create mode 100644 linux-user/sparc64/target_elf.h create mode 100644 linux-user/tilegx/target_elf.h create mode 100644 linux-user/unicore32/target_elf.h create mode 100644 linux-user/x86_64/target_elf.h
Le 17/01/2018 à 16:49, Igor Mammedov a écrit :
Quoted 29 lines
Quoted 9 lines · On Tue, 16 Jan 2018 23:22:08 +0100 Laurent Vivier <[email protected]> wrote:
This idea has been suggested to me before by Philippe Mathieu-Daudé, and recently YunQiang Su has proposed a patch to manage the MIPS r6 case.
Based on this, this series tries to clean-up the original patch, and introduces the use for m68k architecture and port the patch from YunQiang Su.
v3: fix code indent problem reported by patchew
Quoted 8 lines
remove useless "!= 0" check for EF_M68K_M68000 add EF_M68K_* flags in elf.h set 680x0 default CPU to m68040 change "#if ... #endif" structure for ppcv2: move
cpu_modelselection tolinux-user/*/target_elf.h
provide eflags tocpu_get_model()instead of fd (and modify other patches accordingly)Sorry for not noticing it earlier, but could you please fix series to use cpu type names instead of
cpu_model?I've just posted series that completes
cpu_modelrefactoring
[PATCH 00/24] generalize parsing ofcpu_model(part 4)
which removes remnants of the code usingcpu_modelto instantiate CPUs, including reworking how default cpu type for *-user is picked up.
Quoted 7 lines
After that
cpu_modelshouldn't be used anywhere in the code except of routines that process "-cpu" CLI and cpu types should be used directly.So you might not need 1/4 after that or it would have to be reworked and probably other patches where where
cpu_modelis used.
If I understand correctly, in linux-user/main.c we have to use cpu_create() instead of cpu_init(), and provide the cpu_type instead of the cpu_model?
In linux-user/main.c, How can I detect we want to use the default one (we were relying on "cpu_model == NULL" until now) to be able to compute the default one from the ELF header?
Thanks,
Laurent
Quoted 34 lines · On Wed, 17 Jan 2018 17:15:38 +0100 Laurent Vivier <[email protected]> wrote:
Le 17/01/2018 à 16:49, Igor Mammedov a écrit :
Quoted 33 lines
Quoted 9 lines · On Tue, 16 Jan 2018 23:22:08 +0100 Laurent Vivier <[email protected]> wrote:
This idea has been suggested to me before by Philippe Mathieu-Daudé, and recently YunQiang Su has proposed a patch to manage the MIPS r6 case.
Based on this, this series tries to clean-up the original patch, and introduces the use for m68k architecture and port the patch from YunQiang Su.
v3: fix code indent problem reported by patchew
Quoted 8 lines
remove useless "!= 0" check for EF_M68K_M68000 add EF_M68K_* flags in elf.h set 680x0 default CPU to m68040 change "#if ... #endif" structure for ppcv2: move
cpu_modelselection tolinux-user/*/target_elf.h
provide eflags tocpu_get_model()instead of fd (and modify other patches accordingly)Sorry for not noticing it earlier, but could you please fix series to use cpu type names instead of
cpu_model?I've just posted series that completes
cpu_modelrefactoring
[PATCH 00/24] generalize parsing ofcpu_model(part 4)
which removes remnants of the code usingcpu_modelto instantiate CPUs, including reworking how default cpu type for *-user is picked up.After that
cpu_modelshouldn't be used anywhere in the code except of routines that process "-cpu" CLI and cpu types should be used directly.
Quoted 7 lines
Quoted 3 lines
So you might not need 1/4 after that or it would have to be reworked and probably other patches where where
cpu_modelis used.If I understand correctly, in
linux-user/main.cwe have to usecpu_create()instead ofcpu_init(), and provide thecpu_typeinstead of thecpu_model?
yes, that's what my series does.
Quoted 3 lines
In
linux-user/main.c, How can I detect we want to use the default one (we were relying on "cpu_model== NULL" until now) to be able to compute the default one from the ELF header?
maybe something along this lines would do the job:
linux-user/main.c +7 -0
@@ -43,6 +43,7 @@ static const char *filename;static const char *argv0;static int gdbstub_port;static envlist_t *envlist; +/* default type in case it's not possible to deduce from program */ static const char *cpu_type =TARGET_DEFAULT_CPU_TYPE ;unsigned long mmap_min_addr;unsigned long guest_base;
@@ -4250,6 +4251,12 @@ static int parse_args(int argc, char **argv) } filename = argv[optind]; + if (cpu_type is not set by user) { +/* override default type if we can get it from executable */ + override_cpu_type = cpu_get_type(filename) +if (override_cpu_type) + cpu_type = override_cpu_type + } exec_path = argv[optind];
Quoted 2 lines
Thanks,
Laurent
Le 18/01/2018 à 14:17, Igor Mammedov a écrit :
Quoted 65 lines
Quoted 34 lines · On Wed, 17 Jan 2018 17:15:38 +0100 Laurent Vivier <[email protected]> wrote:
Le 17/01/2018 à 16:49, Igor Mammedov a écrit :
Quoted 33 lines
Quoted 9 lines · On Tue, 16 Jan 2018 23:22:08 +0100 Laurent Vivier <[email protected]> wrote:
This idea has been suggested to me before by Philippe Mathieu-Daudé, and recently YunQiang Su has proposed a patch to manage the MIPS r6 case.
Based on this, this series tries to clean-up the original patch, and introduces the use for m68k architecture and port the patch from YunQiang Su.
v3: fix code indent problem reported by patchew
Quoted 8 lines
remove useless "!= 0" check for EF_M68K_M68000 add EF_M68K_* flags in elf.h set 680x0 default CPU to m68040 change "#if ... #endif" structure for ppcv2: move
cpu_modelselection tolinux-user/*/target_elf.h
provide eflags tocpu_get_model()instead of fd (and modify other patches accordingly)Sorry for not noticing it earlier, but could you please fix series to use cpu type names instead of
cpu_model?I've just posted series that completes
cpu_modelrefactoring
[PATCH 00/24] generalize parsing ofcpu_model(part 4)
which removes remnants of the code usingcpu_modelto instantiate CPUs, including reworking how default cpu type for *-user is picked up.After that
cpu_modelshouldn't be used anywhere in the code except of routines that process "-cpu" CLI and cpu types should be used directly.Quoted 7 lines
Quoted 3 lines
So you might not need 1/4 after that or it would have to be reworked and probably other patches where where
cpu_modelis used.If I understand correctly, in
linux-user/main.cwe have to usecpu_create()instead ofcpu_init(), and provide thecpu_typeinstead of thecpu_model?yes, that's what my series does.
Quoted 3 lines
In
linux-user/main.c, How can I detect we want to use the default one (we were relying on "cpu_model== NULL" until now) to be able to compute the default one from the ELF header?maybe something along this lines would do the job:
linux-user/main.c +1
-0@@ -43,6 +43,7 @@ static const char *filename;static const char *argv0;static int gdbstub_port;static envlist_t *envlist; +/* default type in case it's not possible to deduce from program */ static const char *cpu_type =TARGET_DEFAULT_CPU_TYPE ;unsigned long mmap_min_addr;unsigned long guest_base;@@ -4250,6 +4251,12 @@ static int parse_args(int argc, char **argv) }
linux-user/main.c static int parse_args(int argc, char **argv) · line 4261
Quoted 10 lines
linux-user/main.c +6
-0filename = argv[optind]; + if (cpu_type is not set by user) { +/* override default type if we can get it from executable */ + override_cpu_type = cpu_get_type(filename) +if (override_cpu_type) + cpu_type = override_cpu_type + } exec_path = argv[optind];
No, because the fd can be provided by the kernel (with binfmt and "open-binary" attribute, provided by getauxval(AT_EXECFD)), but I think we can manage this in linux-user/main.c:main() by setting cpu_type to NULL and calling cpu_get_type() to set it in this case.
Thanks,
Laurent
Le 17/01/2018 à 16:49, Igor Mammedov a écrit :
Quoted 20 lines
Quoted 9 lines · On Tue, 16 Jan 2018 23:22:08 +0100 Laurent Vivier <[email protected]> wrote:
This idea has been suggested to me before by Philippe Mathieu-Daudé, and recently YunQiang Su has proposed a patch to manage the MIPS r6 case.
Based on this, this series tries to clean-up the original patch, and introduces the use for m68k architecture and port the patch from YunQiang Su.
v3: fix code indent problem reported by patchew
Quoted 8 lines
remove useless "!= 0" check for EF_M68K_M68000 add EF_M68K_* flags in elf.h set 680x0 default CPU to m68040 change "#if ... #endif" structure for ppcv2: move
cpu_modelselection tolinux-user/*/target_elf.h
provide eflags tocpu_get_model()instead of fd (and modify other patches accordingly)
Quoted 2 lines
Sorry for not noticing it earlier, but could you please fix series to use cpu type names instead of
cpu_model?
As your series is not ready for inclusion, perhaps we can take my series first?
I'll happily help you to adapt your series on top of this one if you need.
Thanks,
Laurent
Quoted 21 lines · On Fri, 19 Jan 2018 14:56:53 +0100 Laurent Vivier <[email protected]> wrote:
Le 17/01/2018 à 16:49, Igor Mammedov a écrit :
Quoted 20 lines
Quoted 17 lines · On Tue, 16 Jan 2018 23:22:08 +0100 Laurent Vivier <[email protected]> wrote:
This idea has been suggested to me before by Philippe Mathieu-Daudé, and recently YunQiang Su has proposed a patch to manage the MIPS r6 case.
Based on this, this series tries to clean-up the original patch, and introduces the use for m68k architecture and port the patch from YunQiang Su.
v3: fix code indent problem reported by patchew
remove useless "!= 0" check for EF_M68K_M68000 add EF_M68K_* flags in elf.h set 680x0 default CPU to m68040 change "#if ... #endif" structure for ppcv2: move
cpu_modelselection tolinux-user/*/target_elf.h
provide eflags tocpu_get_model()instead of fd (and modify other patches accordingly)
Quoted 7 lines
Quoted 2 lines
Sorry for not noticing it earlier, but could you please fix series to use cpu type names instead of
cpu_model?As your series is not ready for inclusion, perhaps we can take my series first?
I'll happily help you to adapt your series on top of this one if you need.
It wasn't about whose series goes first (I don't really care as I can rebase),
suggestion was about using cpu types instead of cpu models which you are adding/moving into linux-user/*/target_elf.h
Otherwise we would need immediately to have a patch on top that replaces them in linux-user/*/target_elf.h with cpu types.
So I'd rather amend this series so that it would use cpu types from the start instead of doing refactoring on top which just doubles amount of touched lines.
Quoted 3 lines
Thanks,
Laurent