Skip to contentSkip to conversation

linux-user: Rework get_elf_hwcap() and support MIPS Loongson 2F/3A

PATCH Superseded Philippe Mathieu-Daudé 1 participant 6 messages Dec 14, 2020

lore
Share & tools
lore
#0 lore raw

v5 cover linux-user: Rework get_elf_hwcap() and support MIPS Loongson 2F/3A

Series now fully reviewed.

Since v4:
- Fixed yet another typo...

Since v3:
- Add CP0C0_AR_LENGTH definition (Richard)
- Fixed 3E -> 3A, Longsoon -> Loongson typos (Huacai)

Since v2:
- Use extract32() in GET_FEATURE_REG_EQU (rth)

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/3A userland binaries.

Huacai Chen (1):
MAINTAINERS: [email protected] -> [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/3A

 target/mips/cpu.h    |  1 +
 linux-user/elfload.c | 43 ++++++++++++++++++++++++++++++++++++-------
 .mailmap             |  2 ++
 MAINTAINERS          |  8 ++++----
 4 files changed, 43 insertions(+), 11 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH v5 1/7 MAINTAINERS: [email protected] -> [email protected]

From: Huacai Chen <[email protected]>

Use @kernel.org address as the main communications end point. Update the corresponding M-entries and .mailmap (for git shortlog translation).

Message-Id: <[email protected]>

---
 .mailmap    | 2 ++
 MAINTAINERS | 8 ++++----
 2 files changed, 6 insertions(+), 4 deletions(-)
.mailmap +2 -0
index 663819fb017..a1bd659817d 100644
@@ -49,6 +49,8 @@ Anthony Liguori <[email protected]> Anthony Liguori <[email protected]>
 Filip Bozuta <[email protected]> <[email protected]>
 Frederic Konrad <[email protected]> <[email protected]>
 Greg Kurz <[email protected]> <[email protected]>
+Huacai Chen <[email protected]> <[email protected]>
+Huacai Chen <[email protected]> <[email protected]>
 James Hogan <[email protected]> <[email protected]>
 Leif Lindholm <[email protected]> <[email protected]>
 Radoslaw Biernacki <[email protected]> <[email protected]>
MAINTAINERS +4 -4
index d48a4e8a8b7..d396c5943b6 100644
@@ -388,7 +388,7 @@ S: Maintained
 F: target/arm/kvm.c
 
 MIPS KVM CPUs
-M: Huacai Chen <[email protected]>
+M: Huacai Chen <[email protected]>
 S: Odd Fixes
 F: target/mips/kvm.c
 
@@ -1149,7 +1149,7 @@ F: hw/mips/mipssim.c
 F: hw/net/mipsnet.c
 
 Fuloong 2E
-M: Huacai Chen <[email protected]>
+M: Huacai Chen <[email protected]>
 M: Philippe Mathieu-Daudé <[email protected]>
 R: Jiaxun Yang <[email protected]>
 S: Odd Fixes
@@ -1159,7 +1159,7 @@ F: hw/pci-host/bonito.c
 F: include/hw/isa/vt82c686.h
 
 Loongson-3 virtual platforms
-M: Huacai Chen <[email protected]>
+M: Huacai Chen <[email protected]>
 R: Jiaxun Yang <[email protected]>
 S: Maintained
 F: hw/intc/loongson_liointc.c
@@ -2861,7 +2861,7 @@ F: disas/i386.c
 MIPS TCG target
 M: Philippe Mathieu-Daudé <[email protected]>
 R: Aurelien Jarno <[email protected]>
-R: Huacai Chen <[email protected]>
+R: Huacai Chen <[email protected]>
 R: Jiaxun Yang <[email protected]>
 R: Aleksandar Rikalo <[email protected]>
 S: Odd Fixes
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH v5 1/7] MAINTAINERS: [email protected] -> [email protected]

Quoted 6 lines · Philippe Mathieu-Daudé

From: Huacai Chen <[email protected]>

Use @kernel.org address as the main communications end point. Update the corresponding M-entries and .mailmap (for git shortlog translation).

Quoted 8 lines

Message-Id: <[email protected]>

---
 .mailmap    | 2 ++
 MAINTAINERS | 8 ++++----
 2 files changed, 6 insertions(+), 4 deletions(-)

Wrong series... Already sent pull request for this one, sorry for the noise.

#3 lore raw

PATCH v5 2/7 linux-user/elfload: Move GET_FEATURE macro out of get_elf_hwcap() body

In reply to Philippe Mathieu-Daudé

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
index 0b02a926025..aae28fd929d 100644
@@ -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
#4 lore raw

PATCH v5 3/7 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 it
GET_FEATURE_INSN().

---
 linux-user/elfload.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
linux-user/elfload.c +4 -4
index aae28fd929d..0e1d7e7677c 100644
@@ -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
#5 lore raw

PATCH v5 4/7 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
index 0e1d7e7677c..b7c6d30723a 100644
@@ -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