linux-user: Move hwcap functions to s390x/elfload.c

For get_elf_hwcap, change the return type to abi_ulong
and pass in the cpu.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2025-07-27 21:39:23 -10:00
parent 92c9983c06
commit 1d4774b60e
5 changed files with 62 additions and 64 deletions

View file

@ -1039,65 +1039,7 @@ static inline void init_thread(struct target_pt_regs *regs,
#define ELF_DATA ELFDATA2MSB
#define ELF_ARCH EM_S390
#include "elf.h"
#define ELF_HWCAP get_elf_hwcap()
#define GET_FEATURE(_feat, _hwcap) \
do { if (s390_has_feat(_feat)) { hwcap |= _hwcap; } } while (0)
uint32_t get_elf_hwcap(void)
{
/*
* Let's assume we always have esan3 and zarch.
* 31-bit processes can use 64-bit registers (high gprs).
*/
uint32_t hwcap = HWCAP_S390_ESAN3 | HWCAP_S390_ZARCH | HWCAP_S390_HIGH_GPRS;
GET_FEATURE(S390_FEAT_STFLE, HWCAP_S390_STFLE);
GET_FEATURE(S390_FEAT_MSA, HWCAP_S390_MSA);
GET_FEATURE(S390_FEAT_LONG_DISPLACEMENT, HWCAP_S390_LDISP);
GET_FEATURE(S390_FEAT_EXTENDED_IMMEDIATE, HWCAP_S390_EIMM);
if (s390_has_feat(S390_FEAT_EXTENDED_TRANSLATION_3) &&
s390_has_feat(S390_FEAT_ETF3_ENH)) {
hwcap |= HWCAP_S390_ETF3EH;
}
GET_FEATURE(S390_FEAT_VECTOR, HWCAP_S390_VXRS);
GET_FEATURE(S390_FEAT_VECTOR_ENH, HWCAP_S390_VXRS_EXT);
GET_FEATURE(S390_FEAT_VECTOR_ENH2, HWCAP_S390_VXRS_EXT2);
return hwcap;
}
const char *elf_hwcap_str(uint32_t bit)
{
static const char *hwcap_str[] = {
[HWCAP_S390_NR_ESAN3] = "esan3",
[HWCAP_S390_NR_ZARCH] = "zarch",
[HWCAP_S390_NR_STFLE] = "stfle",
[HWCAP_S390_NR_MSA] = "msa",
[HWCAP_S390_NR_LDISP] = "ldisp",
[HWCAP_S390_NR_EIMM] = "eimm",
[HWCAP_S390_NR_DFP] = "dfp",
[HWCAP_S390_NR_HPAGE] = "edat",
[HWCAP_S390_NR_ETF3EH] = "etf3eh",
[HWCAP_S390_NR_HIGH_GPRS] = "highgprs",
[HWCAP_S390_NR_TE] = "te",
[HWCAP_S390_NR_VXRS] = "vx",
[HWCAP_S390_NR_VXRS_BCD] = "vxd",
[HWCAP_S390_NR_VXRS_EXT] = "vxe",
[HWCAP_S390_NR_GS] = "gs",
[HWCAP_S390_NR_VXRS_EXT2] = "vxe2",
[HWCAP_S390_NR_VXRS_PDE] = "vxp",
[HWCAP_S390_NR_SORT] = "sort",
[HWCAP_S390_NR_DFLT] = "dflt",
[HWCAP_S390_NR_NNPA] = "nnpa",
[HWCAP_S390_NR_PCI_MIO] = "pcimio",
[HWCAP_S390_NR_SIE] = "sie",
};
return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
}
#define ELF_HWCAP get_elf_hwcap(thread_cpu)
static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
{

View file

@ -104,13 +104,10 @@ const char *get_elf_cpu_model(uint32_t eflags);
#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_ARM) \
|| defined(TARGET_SPARC) || defined(TARGET_PPC) \
|| defined(TARGET_LOONGARCH64) || defined(TARGET_MIPS) \
|| defined(TARGET_SH4)
|| defined(TARGET_SH4) || defined(TARGET_S390X)
abi_ulong get_elf_hwcap(CPUState *cs);
abi_ulong get_elf_hwcap2(CPUState *cs);
#endif
#if defined(TARGET_S390X)
uint32_t get_elf_hwcap(void);
#endif
const char *elf_hwcap_str(uint32_t bit);
const char *elf_hwcap2_str(uint32_t bit);

View file

@ -3,9 +3,66 @@
#include "qemu/osdep.h"
#include "qemu.h"
#include "loader.h"
#include "elf.h"
const char *get_elf_cpu_model(uint32_t eflags)
{
return "qemu";
}
#define GET_FEATURE(_feat, _hwcap) \
do { if (s390_has_feat(_feat)) { hwcap |= _hwcap; } } while (0)
abi_ulong get_elf_hwcap(CPUState *cs)
{
/*
* Let's assume we always have esan3 and zarch.
* 31-bit processes can use 64-bit registers (high gprs).
*/
uint32_t hwcap = HWCAP_S390_ESAN3 | HWCAP_S390_ZARCH | HWCAP_S390_HIGH_GPRS;
GET_FEATURE(S390_FEAT_STFLE, HWCAP_S390_STFLE);
GET_FEATURE(S390_FEAT_MSA, HWCAP_S390_MSA);
GET_FEATURE(S390_FEAT_LONG_DISPLACEMENT, HWCAP_S390_LDISP);
GET_FEATURE(S390_FEAT_EXTENDED_IMMEDIATE, HWCAP_S390_EIMM);
if (s390_has_feat(S390_FEAT_EXTENDED_TRANSLATION_3) &&
s390_has_feat(S390_FEAT_ETF3_ENH)) {
hwcap |= HWCAP_S390_ETF3EH;
}
GET_FEATURE(S390_FEAT_VECTOR, HWCAP_S390_VXRS);
GET_FEATURE(S390_FEAT_VECTOR_ENH, HWCAP_S390_VXRS_EXT);
GET_FEATURE(S390_FEAT_VECTOR_ENH2, HWCAP_S390_VXRS_EXT2);
return hwcap;
}
const char *elf_hwcap_str(uint32_t bit)
{
static const char *hwcap_str[] = {
[HWCAP_S390_NR_ESAN3] = "esan3",
[HWCAP_S390_NR_ZARCH] = "zarch",
[HWCAP_S390_NR_STFLE] = "stfle",
[HWCAP_S390_NR_MSA] = "msa",
[HWCAP_S390_NR_LDISP] = "ldisp",
[HWCAP_S390_NR_EIMM] = "eimm",
[HWCAP_S390_NR_DFP] = "dfp",
[HWCAP_S390_NR_HPAGE] = "edat",
[HWCAP_S390_NR_ETF3EH] = "etf3eh",
[HWCAP_S390_NR_HIGH_GPRS] = "highgprs",
[HWCAP_S390_NR_TE] = "te",
[HWCAP_S390_NR_VXRS] = "vx",
[HWCAP_S390_NR_VXRS_BCD] = "vxd",
[HWCAP_S390_NR_VXRS_EXT] = "vxe",
[HWCAP_S390_NR_GS] = "gs",
[HWCAP_S390_NR_VXRS_EXT2] = "vxe2",
[HWCAP_S390_NR_VXRS_PDE] = "vxp",
[HWCAP_S390_NR_SORT] = "sort",
[HWCAP_S390_NR_DFLT] = "dflt",
[HWCAP_S390_NR_NNPA] = "nnpa",
[HWCAP_S390_NR_PCI_MIO] = "pcimio",
[HWCAP_S390_NR_SIE] = "sie",
};
return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
}

View file

@ -8,4 +8,6 @@
#ifndef S390X_TARGET_ELF_H
#define S390X_TARGET_ELF_H
#define HAVE_ELF_HWCAP 1
#endif

View file

@ -48,7 +48,7 @@ static void show_cpu_summary(CPUArchState *cpu_env, int fd)
{
S390CPUModel *model = env_archcpu(cpu_env)->model;
int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
uint32_t elf_hwcap = get_elf_hwcap();
uint32_t elf_hwcap = get_elf_hwcap(env_cpu(cpu_env));
const char *hwcap_str;
int i;