linux-user: Rework get_elf_hwcap() and support MIPS Loongson 2F/3E
v2 cover linux-user: Rework get_elf_hwcap() and support MIPS Loongson 2F/3E
Introduce the GET_FEATURE_REG_SET() and GET_FEATURE_REG_EQU() macros to check if an instruction set is supported by a CPU using CP0 read-only bits (instead of QEMU insn_flags which is not always coherent - we might remove it soon).
Use these macros to test for MSA ASE and Release 6.
Update the ELF HWCAP bits and set the Loongson instructions so we can run 2F/3E userland binaries.
Supersedes: <[email protected]>
Philippe Mathieu-Daudé (6):
linux-user/elfload: Move GET_FEATURE macro out of get_elf_hwcap() body linux-user/elfload: Rename MIPS GET_FEATURE() as GET_FEATURE_INSN() linux-user/elfload: Introduce MIPS GET_FEATURE_REG_SET() macro linux-user/elfload: Introduce MIPS GET_FEATURE_REG_EQU() macro linux-user/elfload: Update HWCAP bits from linux 5.7
linux-user: Add support for MIPS Loongson 2F/3E
linux-user/elfload.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-)
Signature · 1 line
2.26.2
PATCH v2 1/6 linux-user/elfload: Move GET_FEATURE macro out of get_elf_hwcap() body
As we are going to add more macros, keep the function body clear.
--- linux-user/elfload.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
linux-user/elfload.c +5 -5
@@ -989,22 +989,22 @@ enum {#define ELF_HWCAP get_elf_hwcap() +#define GET_FEATURE (_flag, _hwcap) \ + do { if (cpu->env.insn_flags & (_flag)) { hwcaps |= _hwcap; } } while (0) +static uint32_t get_elf_hwcap (void ) {MIPSCPU *cpu =MIPS_CPU (thread_cpu);uint32_t hwcaps =0 ; -#define GET_FEATURE (flag, hwcap) \ - do { if (cpu->env.insn_flags & (flag)) { hwcaps |= hwcap; } } while (0) -GET_FEATURE (ISA_MIPS32R6 |ISA_MIPS64R6 ,HWCAP_MIPS_R6 );GET_FEATURE (ASE_MSA ,HWCAP_MIPS_MSA ); -#undef GET_FEATURE -return hwcaps; } +#undef GET_FEATURE +#endif /* TARGET_MIPS */ #ifdef TARGET_MICROBLAZE
Signature · 1 line
2.26.2
Re: [PATCH v2 1/6] linux-user/elfload: Move GET_FEATURE macro out of get_elf_hwcap() body
Quoted 6 lines · Philippe Mathieu-Daudé
As we are going to add more macros, keep the function body clear.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- linux-user/elfload.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
r~
PATCH v2 2/6 linux-user/elfload: Rename MIPS GET_FEATURE() as GET_FEATURE_INSN()
In reply to Philippe Mathieu-DaudéWe want to add macros similar to GET_FEATURE().
As this one use the 'insn_flags' field, rename itGET_FEATURE_INSN().
--- linux-user/elfload.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
linux-user/elfload.c +4 -4
@@ -989,7 +989,7 @@ enum {#define ELF_HWCAP get_elf_hwcap() -#define GET_FEATURE (_flag, _hwcap) \ +#define GET_FEATURE_INSN (_flag, _hwcap) \ do { if (cpu->env.insn_flags & (_flag)) { hwcaps |= _hwcap; } } while (0)static uint32_t get_elf_hwcap (void )
@@ -997,13 +997,13 @@ static uint32_t get_elf_hwcap(void)MIPSCPU *cpu =MIPS_CPU (thread_cpu);uint32_t hwcaps =0 ; -GET_FEATURE (ISA_MIPS32R6 |ISA_MIPS64R6 ,HWCAP_MIPS_R6 ); -GET_FEATURE (ASE_MSA ,HWCAP_MIPS_MSA ); +GET_FEATURE_INSN (ISA_MIPS32R6 |ISA_MIPS64R6 ,HWCAP_MIPS_R6 ); +GET_FEATURE_INSN (ASE_MSA ,HWCAP_MIPS_MSA ); return hwcaps; } -#undef GET_FEATURE +#undef GET_FEATURE_INSN#endif /* TARGET_MIPS */
Signature · 1 line
2.26.2
Re: [PATCH v2 2/6] linux-user/elfload: Rename MIPS GET_FEATURE() as GET_FEATURE_INSN()
Quoted 8 lines · Philippe Mathieu-Daudé
We want to add macros similar to
GET_FEATURE().
As this one use the 'insn_flags' field, rename itGET_FEATURE_INSN().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- linux-user/elfload.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
r~
PATCH v2 3/6 linux-user/elfload: Introduce MIPS GET_FEATURE_REG_SET() macro
In reply to Philippe Mathieu-DaudéISA features are usually denoted in read-only bits from CPU registers. Add the GET_FEATURE_REG_SET() macro which checks if a CPU register has bits set.
Use the macro to check for MSA (which sets the MSAP bit of the Config3 register when the ASE implementation is present).
--- linux-user/elfload.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
linux-user/elfload.c +5 -1
@@ -992,17 +992,21 @@ enum {#define GET_FEATURE_INSN (_flag, _hwcap) \ do { if (cpu->env.insn_flags & (_flag)) { hwcaps |= _hwcap; } } while (0) +#define GET_FEATURE_REG_SET (_reg, _mask, _hwcap) \ + do { if (cpu->env._reg & (_mask)) { hwcaps |= _hwcap; } } while (0) +static uint32_t get_elf_hwcap (void ) {MIPSCPU *cpu =MIPS_CPU (thread_cpu);uint32_t hwcaps =0 ;GET_FEATURE_INSN (ISA_MIPS32R6 |ISA_MIPS64R6 ,HWCAP_MIPS_R6 ); -GET_FEATURE_INSN (ASE_MSA ,HWCAP_MIPS_MSA ); +GET_FEATURE_REG_SET (CP0_Config3,1 <<CP0C3_MSAP ,HWCAP_MIPS_MSA );return hwcaps; } +#undef GET_FEATURE_REG_SET#undef GET_FEATURE_INSN#endif /* TARGET_MIPS */
Signature · 1 line
2.26.2
Re: [PATCH v2 3/6] linux-user/elfload: Introduce MIPS GET_FEATURE_REG_SET() macro
Quoted 11 lines · Philippe Mathieu-Daudé
ISA features are usually denoted in read-only bits from CPU registers. Add the
GET_FEATURE_REG_SET()macro which checks if a CPU register has bits set.Use the macro to check for MSA (which sets the MSAP bit of the Config3 register when the ASE implementation is present).
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- linux-user/elfload.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
r~
PATCH v2 4/6 linux-user/elfload: Introduce MIPS GET_FEATURE_REG_EQU() macro
In reply to Philippe Mathieu-DaudéISA features are usually denoted in read-only bits from CPU registers. Add the GET_FEATURE_REG_EQU() macro which checks if a CPU register has bits set to a specific value.
Use the macro to check the 'Architecture Revision' level of the Config0 register, which is '2' when the Release 6 ISA is implemented.
--- linux-user/elfload.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
linux-user/elfload.c +9 -1
@@ -995,17 +995,25 @@ enum {#define GET_FEATURE_REG_SET (_reg, _mask, _hwcap) \ do { if (cpu->env._reg & (_mask)) { hwcaps |= _hwcap; } } while (0) +#define GET_FEATURE_REG_EQU (_reg, _mask, _val, _hwcap) \ + do { \ + if ((cpu->env._reg & (_mask)) == _val) { \ + hwcaps |= _hwcap; \ + } \ + } while (0) +static uint32_t get_elf_hwcap (void ) {MIPSCPU *cpu =MIPS_CPU (thread_cpu);uint32_t hwcaps =0 ; -GET_FEATURE_INSN (ISA_MIPS32R6 |ISA_MIPS64R6 ,HWCAP_MIPS_R6 ); +GET_FEATURE_REG_EQU (CP0_Config0,7 <<CP0C0_AR ,2 ,HWCAP_MIPS_R6 );GET_FEATURE_REG_SET (CP0_Config3,1 <<CP0C3_MSAP ,HWCAP_MIPS_MSA );return hwcaps; } +#undef GET_FEATURE_REG_EQU#undef GET_FEATURE_REG_SET#undef GET_FEATURE_INSN
Signature · 1 line
2.26.2
Re: [PATCH v2 4/6] linux-user/elfload: Introduce MIPS GET_FEATURE_REG_EQU() macro
Quoted 4 lines · Philippe Mathieu-Daudé
linux-user/elfload.c +4
-0+#define GET_FEATURE_REG_EQU (_reg, _mask, _val, _hwcap) \ + do { \ + if ((cpu->env._reg & (_mask)) == _val) { \ + hwcaps |= _hwcap; \
linux-user/elfload.c enum { · line 1010
Quoted 10 lines
linux-user/elfload.c +4
-1+ } \ + }while (0 ) + static uint32_t get_elf_hwcap(void) {MIPSCPU *cpu =MIPS_CPU (thread_cpu);uint32_t hwcaps =0 ; -GET_FEATURE_INSN (ISA_MIPS32R6 |ISA_MIPS64R6 ,HWCAP_MIPS_R6 ); +GET_FEATURE_REG_EQU (CP0_Config0,7 <<CP0C0_AR ,2 ,HWCAP_MIPS_R6 );
You'd need 2 << CP0C0_AR for the equality to match. Would it be better to have the shift as a separate argument?
r~
Re: [PATCH v2 4/6] linux-user/elfload: Introduce MIPS GET_FEATURE_REG_EQU() macro
Quoted 13 lines · Richard Henderson
Quoted 12 lines · Philippe Mathieu-Daudé
linux-user/elfload.c +7
-0+#define GET_FEATURE_REG_EQU (_reg, _mask, _val, _hwcap) \ + do { \ + if ((cpu->env._reg & (_mask)) == _val) { \ + hwcaps |= _hwcap; \ + } \ + } while (0) +static uint32_t get_elf_hwcap (void ) {MIPSCPU *cpu =MIPS_CPU (thread_cpu);uint32_t hwcaps =0 ;
Quoted 4 lines
linux-user/elfload.c enum { · line 1010
Quoted 2 lines
linux-user/elfload.c +1
-1-GET_FEATURE_INSN (ISA_MIPS32R6 |ISA_MIPS64R6 ,HWCAP_MIPS_R6 ); +GET_FEATURE_REG_EQU (CP0_Config0,7 <<CP0C0_AR ,2 ,HWCAP_MIPS_R6 );You'd need 2 <<
CP0C0_ARfor the equality to match.
Oops...
Quoted 1 line
Would it be better to have the shift as a separate argument?
Yes, thanks!
Phil.
PATCH v2 5/6 linux-user/elfload: Update HWCAP bits from linux 5.7
In reply to Philippe Mathieu-Daudé--- linux-user/elfload.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
linux-user/elfload.c +13 -0
@@ -985,6 +985,19 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMIPSState *eenum {HWCAP_MIPS_R6 = (1 <<0 ),HWCAP_MIPS_MSA = (1 <<1 ), +HWCAP_MIPS_CRC32 = (1 <<2 ), +HWCAP_MIPS_MIPS16 = (1 <<3 ), +HWCAP_MIPS_MDMX = (1 <<4 ), +HWCAP_MIPS_MIPS3D = (1 <<5 ), +HWCAP_MIPS_SMARTMIPS = (1 <<6 ), +HWCAP_MIPS_DSP = (1 <<7 ), +HWCAP_MIPS_DSP2 = (1 <<8 ), +HWCAP_MIPS_DSP3 = (1 <<9 ), +HWCAP_MIPS_MIPS16E2 = (1 <<10 ), +HWCAP_LOONGSON_MMI = (1 <<11 ), +HWCAP_LOONGSON_EXT = (1 <<12 ), +HWCAP_LOONGSON_EXT2 = (1 <<13 ), +HWCAP_LOONGSON_CPUCFG = (1 <<14 ), };#define ELF_HWCAP get_elf_hwcap()
Signature · 1 line
2.26.2
PATCH v2 6/6 linux-user: Add support for MIPS Loongson 2F/3E
In reply to Philippe Mathieu-DaudéUserland ELF binaries using Longsoon SIMD instructions have the HWCAP_LOONGSON_MMI bit set [1].
Binaries compiled for Longsoon 3E [2] have the HWCAP_LOONGSON_EXT bit set for the LQ / SQ instructions.
[1] commit 8e2d5831e4b ("target/mips: Legalize Loongson insn flags")
[2] commit af868995e1b ("target/mips: Add Loongson-3 CPU definition")
--- linux-user/elfload.c | 2 ++ 1 file changed, 2 insertions(+)
linux-user/elfload.c +2 -0
@@ -1022,6 +1022,8 @@ static uint32_t get_elf_hwcap(void)GET_FEATURE_REG_EQU (CP0_Config0,7 <<CP0C0_AR ,2 ,HWCAP_MIPS_R6 );GET_FEATURE_REG_SET (CP0_Config3,1 <<CP0C3_MSAP ,HWCAP_MIPS_MSA ); +GET_FEATURE_INSN (ASE_LMMI ,HWCAP_LOONGSON_MMI ); +GET_FEATURE_INSN (ASE_LEXT ,HWCAP_LOONGSON_EXT );return hwcaps; }
Signature · 1 line
2.26.2