-----BEGIN PGP SIGNATURE-----

iQIcBAABAgAGBQJakvhNAAoJEPMMOL0/L748zyUP/j2z597HjgMYC1+tKLp46kQa
 sWPMomEgaRAssfwPYOsk8m07J2fHkkCSKichkNP72zcluNAR63dFM9ekgagl8NK7
 YBNosXo907EwNo/YuH7XYSzjzvuFFcJAs9RYPkjRPOWi4K37kGICMEJ/rkvU1hMu
 sDyyWBPHJ1I3Gi+ulYx83CL/vxGkIpAohFTKvUKJMw0O3nPiOmXNcfEN8+hZlLFo
 7qOYe5I0NbPqom7ePekvR0qmf8MzCPitxCE+r366++mtspBNt73w3BzCyf0HN0Px
 RvWA1WRMo4g07ejpR7sb8H8D5GyhNmdfp3Z+WnYlwkQ7S0o3nmenG8NlYBQtnryH
 o7pprGtQ0W/dt7NuRiTl7VhRws2ifly3a8iVQ+qFZE166btaQLAPbTSVLn4Z9BHK
 6ThF+0rvZlY78CpO2g0ZqOZCbex9eb71M8JQ3pdrFiMvIQkgLT/zUTs/USvTSQVI
 8jpTSMA+8I4Ku1vQu7pZGwoFohJkfNfWNcmeqEwlZ8kuWfJTJCvqh5zRNZEVPO9A
 RFdbYBOPeVCACxTnV2yMqC6YJqkserpyzf8D0slzi0ne4TpexEDHTssQzXipk2vJ
 unGfY+QTKYsL7t6sFnBBHY9pq7hj69vw40/Ui7CJVQWdx2SwXJZds957YViHyrd4
 ucbzdCPhsG+G63Rsa4tw
 =a866
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-2.12-pull-request' into staging

# gpg: Signature made Sun 25 Feb 2018 17:54:21 GMT
# gpg:                using RSA key F30C38BD3F2FBE3C
# gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>"
# gpg:                 aka "Laurent Vivier <laurent@vivier.eu>"
# gpg:                 aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>"
# Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F  5173 F30C 38BD 3F2F BE3C

* remotes/vivier2/tags/linux-user-for-2.12-pull-request:
  linux-user: MIPS set cpu to r6 CPU if binary is R6
  linux-user, m68k: select CPU according to ELF header values
  linux-user: introduce functions to detect CPU type
  linux-user: Move CPU type name selection to a function

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2018-02-27 10:14:31 +00:00
commit 438cd7082c
24 changed files with 382 additions and 48 deletions

View File

@ -33,6 +33,9 @@ typedef int64_t Elf64_Sxword;
/* Flags in the e_flags field of the header */
/* MIPS architecture level. */
#define EF_MIPS_ARCH 0xf0000000
/* Legal values for MIPS architecture level. */
#define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code. */
#define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code. */
#define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */
@ -40,6 +43,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. */
@ -537,6 +544,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
*/

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -2396,6 +2396,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;

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,20 @@
/*
* 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)
{
if (eflags == 0 || (eflags & EF_M68K_M68000)) {
/* 680x0 */
return "m68040";
}
/* Coldfire */
return "any";
}
#endif

View File

@ -35,6 +35,7 @@
#include "elf.h"
#include "exec/log.h"
#include "trace/control.h"
#include "target_elf.h"
char *exec_path;
@ -4343,46 +4344,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) {
#if defined(TARGET_I386)
#ifdef TARGET_X86_64
cpu_model = "qemu64";
#else
cpu_model = "qemu32";
#endif
#elif defined(TARGET_ARM)
cpu_model = "any";
#elif defined(TARGET_UNICORE32)
cpu_model = "any";
#elif defined(TARGET_M68K)
cpu_model = "any";
#elif defined(TARGET_SPARC)
#ifdef TARGET_SPARC64
cpu_model = "TI UltraSparc II";
#else
cpu_model = "Fujitsu MB86904";
#endif
#elif defined(TARGET_MIPS)
#if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
cpu_model = "5KEf";
#else
cpu_model = "24Kf";
#endif
#elif defined TARGET_OPENRISC
cpu_model = "or1200";
#elif defined(TARGET_PPC)
# ifdef TARGET_PPC64
cpu_model = "POWER8";
# else
cpu_model = "750";
# endif
#elif defined TARGET_SH4
cpu_model = "sh7785";
#elif defined TARGET_S390X
cpu_model = "qemu";
#else
cpu_model = "any";
#endif
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
@ -4475,15 +4447,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) {

View File

@ -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

View File

@ -0,0 +1,17 @@
/*
* 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)
{
if ((eflags & EF_MIPS_ARCH) == EF_MIPS_ARCH_32R6) {
return "mips32r6-generic";
}
return "24Kf";
}
#endif

View File

@ -0,0 +1,17 @@
/*
* 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)
{
if ((eflags & EF_MIPS_ARCH) == EF_MIPS_ARCH_64R6) {
return "I6400";
}
return "5KEf";
}
#endif

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -186,6 +186,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);

View File

@ -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

View File

@ -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

View File

@ -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 SPARC_TARGET_ELF_H
#define SPARC_TARGET_ELF_H
static inline const char *cpu_get_model(uint32_t eflags)
{
#ifdef TARGET_SPARC64
return "TI UltraSparc II";
#else
return "Fujitsu MB86904";
#endif
}
#endif

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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