Skip to contentSkip to conversation

target/mips: Re-introduce the R5900 CPU (system) + sort tcg tests

PATCH In review Philippe Mathieu-Daudé 4 participants 34 messages Oct 28 – Oct 29 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v2 cover target/mips: Re-introduce the R5900 CPU (system) + sort tcg tests

Add R5900 system tests, code is covered, CPU can come back, allowing to fix a bug on PCGT opcode.

Since [v1]:
- rebased
- added freestanding libc stubs
- o32/n32 tests

[v1]: https://lore.kernel.org/qemu-devel/[email protected]/

Philippe Mathieu-Daudé (9):
target/mips: Re-introduce the R5900 CPU in system mode target/mips/tx79: Fix PCGT* (Parallel Compare for Greater Than) tests/guest-debug: Allow placing the binary within system QEMU args tests/tcg/mips64el: Add bare-metal harness for R5900 system tests tests/tcg/mips64el: Move R5900 tests to system mode and build with
meson
target/mips: Factor mips_gdb_read_value() out target/mips: Describe gdbstub registers with XML features target/mips: Expose R5900 registers to gdb tests/tcg/mips64el: Add a TX79 instruction test in system mode

 MAINTAINERS                                   |   1 +
 configs/targets/mips-linux-user.mak           |   1 +
 configs/targets/mips-softmmu.mak              |   1 +
 configs/targets/mips64-linux-user.mak         |   1 +
 configs/targets/mips64-softmmu.mak            |   1 +
 configs/targets/mips64el-linux-user.mak       |   1 +
 configs/targets/mips64el-softmmu.mak          |   1 +
 configs/targets/mipsel-linux-user.mak         |   1 +
 configs/targets/mipsel-softmmu.mak            |   1 +
 configs/targets/mipsn32-linux-user.mak        |   1 +
 configs/targets/mipsn32el-linux-user.mak      |   1 +
 target/mips/internal.h                        |   2 +
 tests/tcg/mips64el/system/include/assert.h    |  15 +
 tests/tcg/mips64el/system/include/inttypes.h  |   7 +
 tests/tcg/mips64el/system/include/stdio.h     |  17 +
 tests/tcg/mips64el/system/include/string.h    |  16 +
 target/mips/cpu.c                             |   4 +
 target/mips/gdbstub.c                         | 152 +++++-
 target/mips/tcg/tx79_translate.c              |  10 +-
 tests/tcg/mips64el/system/harness.c           |  66 +++
 .../system}/test_r5900_div1.c                 |   0
 .../system}/test_r5900_divu1.c                |   0
 .../system}/test_r5900_madd.c                 |   0
 .../system}/test_r5900_maddu.c                |   0
 .../system}/test_r5900_mflohi1.c              |   0
 .../system}/test_r5900_mtlohi1.c              |   0
 .../system}/test_r5900_mult.c                 |   0
 .../system}/test_r5900_multu.c                |   0
 tests/tcg/mips64el/system/test_r5900_tx79.c   | 477 ++++++++++++++++++
 target/mips/cpu-defs.c.inc                    |  45 ++
 gdbstub/gdb-xml/mips32-cp0.xml                |   9 +
 gdbstub/gdb-xml/mips32-cpu.xml                |  42 ++
 gdbstub/gdb-xml/mips32-fpu.xml                |  41 ++
 gdbstub/gdb-xml/mips64-cp0.xml                |   9 +
 gdbstub/gdb-xml/mips64-cpu.xml                |  42 ++
 gdbstub/gdb-xml/mips64-fpu.xml                |  41 ++
 gdbstub/gdb-xml/mips64-r5900.xml              |  47 ++
 tests/guest-debug/run-test.py                 |   9 +-
 tests/tcg/mips/user/isa/r5900/Makefile        |  32 --
 tests/tcg/mips/user/isa/r5900/README          |   6 -
 tests/tcg/mips64el/meson.build                |   2 +
 tests/tcg/mips64el/system/boot.S              |  23 +
 tests/tcg/mips64el/system/kernel.ld           |  43 ++
 tests/tcg/mips64el/system/meson.build         |  62 +++
 tests/tcg/mips64el/system/test-r5900.py       |  30 ++
 45 files changed, 1211 insertions(+), 49 deletions(-)
 create mode 100644 tests/tcg/mips64el/system/include/assert.h
 create mode 100644 tests/tcg/mips64el/system/include/inttypes.h
 create mode 100644 tests/tcg/mips64el/system/include/stdio.h
 create mode 100644 tests/tcg/mips64el/system/include/string.h
 create mode 100644 tests/tcg/mips64el/system/harness.c
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_div1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_divu1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_madd.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_maddu.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mflohi1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mtlohi1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mult.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_multu.c (100%)
 create mode 100644 tests/tcg/mips64el/system/test_r5900_tx79.c
 create mode 100644 gdbstub/gdb-xml/mips32-cp0.xml
 create mode 100644 gdbstub/gdb-xml/mips32-cpu.xml
 create mode 100644 gdbstub/gdb-xml/mips32-fpu.xml
 create mode 100644 gdbstub/gdb-xml/mips64-cp0.xml
 create mode 100644 gdbstub/gdb-xml/mips64-cpu.xml
 create mode 100644 gdbstub/gdb-xml/mips64-fpu.xml
 create mode 100644 gdbstub/gdb-xml/mips64-r5900.xml
 delete mode 100644 tests/tcg/mips/user/isa/r5900/Makefile
 delete mode 100644 tests/tcg/mips/user/isa/r5900/README
 create mode 100644 tests/tcg/mips64el/system/boot.S
 create mode 100644 tests/tcg/mips64el/system/kernel.ld
 create mode 100644 tests/tcg/mips64el/system/meson.build
 create mode 100644 tests/tcg/mips64el/system/test-r5900.py
Signature · 1 line
2.55.0
#1 lore raw

PATCH v2 1/9 target/mips: Re-introduce the R5900 CPU in system mode

From: Philippe Mathieu-Daudé <[email protected]>

Partly revert commit 823f2897bdd7 ("target/mips: Disable R5900 support"), which disabled it over ABI and emulation accuracy concerns. Those ABI concerns only affect user mode, so keep the CPU unavailable there. In system mode we now have enough of the CPU (MMI instructions and bare-metal tests) to use it.

---
 target/mips/cpu-defs.c.inc | 45 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
target/mips/cpu-defs.c.inc +45 -0
index b2ddfa1e826a..5f6fa2900f14 100644
@@ -590,6 +590,51 @@ const mips_def_t mips_defs[] =
         .insn_flags = CPU_MIPS4 | INSN_VR54XX,
         .mmu_type = MMU_TYPE_R4000,
     },
+#ifndef CONFIG_USER_ONLY
+    {
+        /*
+         * The Toshiba TX System RISC TX79 Core Architecture manual
+         *
+         * https://wiki.qemu.org/File:C790.pdf
+         *
+         * describes the C790 processor that is a follow-up to the R5900.
+         * There are a few notable differences in that the R5900 FPU
+         *
+         * - is not IEEE 754-1985 compliant,
+         * - does not implement double format, and
+         * - its machine code is nonstandard.
+         */
+        .name = "R5900",
+        .CP0_PRid = 0x00002E00,
+        /* No L2 cache, icache size 32k, dcache size 32k, uncached coherency. */
+        .CP0_Config0 = (0x3 << 9) | (0x3 << 6) | (0x2 << CP0C0_K0),
+        .CP0_Status_rw_bitmask = 0xF4C79C1F,
+        /*
+         * The R5900 COP1 FPU implements single-precision floating-point
+         * operations but is not entirely IEEE 754-1985 compatible. In
+         * particular,
+         *
+         * - NaN (not a number) and +/- infinities are not supported;
+         * - exception mechanisms are not fully supported;
+         * - denormalized numbers are not supported;
+         * - rounding towards nearest and +/- infinities are not supported;
+         * - computed results usually differs in the least significant bit;
+         * - saturations can differ more than the least significant bit.
+         *
+         * Since only rounding towards zero is supported, the two least
+         * significant bits of FCR31 are hardwired to 01.
+         *
+         * FPU emulation is disabled here until it is implemented.
+         *
+         * Note: Config1 is only used internally, the R5900 has only Config0.
+         */
+        .CP0_Config1 = (47 << CP0C1_MMU),
+        .SEGBITS = 32,
+        .PABITS = 32,
+        .insn_flags = CPU_MIPS3 | INSN_R5900 | ASE_MMI,
+        .mmu_type = MMU_TYPE_R4000,
+    },
+#endif /* !CONFIG_USER_ONLY */
     {
         .name = "5Kc",
         .CP0_PRid = 0x00018100,
Signature · 1 line
2.55.0
Reviewed-by on v2 1/9
#2 lore raw

Re: [PATCH v2 1/9] target/mips: Re-introduce the R5900 CPU in system mode

Quoted 8 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Partly revert commit 823f2897bdd7 ("target/mips: Disable R5900 support"), which disabled it over ABI and emulation accuracy concerns. Those ABI concerns only affect user mode, so keep the CPU unavailable there. In system mode we now have enough of the CPU (MMI instructions and bare-metal tests) to use it.

Quoted 6 lines
---
 target/mips/cpu-defs.c.inc | 45 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
#3 lore raw

PATCH v2 2/9 target/mips/tx79: Fix PCGT* (Parallel Compare for Greater Than)

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

PCGT* set each lane of rd when rs is greater than rt. We compared rt >= rs, returning the opposite result.

Fixes 8bd42c00f284 ("target/mips/tx79: Introduce PCGT ...")
---
 target/mips/tcg/tx79_translate.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
target/mips/tcg/tx79_translate.c +5 -5
index e071c867631e..3b413846c8d0 100644
@@ -255,7 +255,7 @@ static bool trans_parallel_compare(DisasContext *ctx, arg_r *a,
     for (int i = 0; i < (64 / wlen); i++) {
         tcg_gen_sextract_i64(t0, ax, wlen * i, wlen);
         tcg_gen_sextract_i64(t1, bx, wlen * i, wlen);
-        tcg_gen_movcond_i64(cond, t2, t1, t0, c1, c0);
+        tcg_gen_movcond_i64(cond, t2, t0, t1, c1, c0);
         tcg_gen_deposit_i64(cpu_gpr[a->rd], cpu_gpr[a->rd], t2, wlen * i, wlen);
     }
     /* Upper half */
@@ -264,7 +264,7 @@ static bool trans_parallel_compare(DisasContext *ctx, arg_r *a,
     for (int i = 0; i < (64 / wlen); i++) {
         tcg_gen_sextract_i64(t0, ax, wlen * i, wlen);
         tcg_gen_sextract_i64(t1, bx, wlen * i, wlen);
-        tcg_gen_movcond_i64(cond, t2, t1, t0, c1, c0);
+        tcg_gen_movcond_i64(cond, t2, t0, t1, c1, c0);
         tcg_gen_deposit_i64(cpu_gpr_hi[a->rd], cpu_gpr_hi[a->rd], t2, wlen * i, wlen);
     }
     return true;
@@ -273,7 +273,7 @@ static bool trans_parallel_compare(DisasContext *ctx, arg_r *a,
 /* Parallel Compare for Greater Than Byte */
 static bool trans_PCGTB(DisasContext *ctx, arg_r *a)
 {
-    return trans_parallel_compare(ctx, a, TCG_COND_GE, 8);
+    return trans_parallel_compare(ctx, a, TCG_COND_GT, 8);
 }
 
 /* Parallel Compare for Equal Byte */
@@ -285,7 +285,7 @@ static bool trans_PCEQB(DisasContext *ctx, arg_r *a)
 /* Parallel Compare for Greater Than Halfword */
 static bool trans_PCGTH(DisasContext *ctx, arg_r *a)
 {
-    return trans_parallel_compare(ctx, a, TCG_COND_GE, 16);
+    return trans_parallel_compare(ctx, a, TCG_COND_GT, 16);
 }
 
 /* Parallel Compare for Equal Halfword */
@@ -297,7 +297,7 @@ static bool trans_PCEQH(DisasContext *ctx, arg_r *a)
 /* Parallel Compare for Greater Than Word */
 static bool trans_PCGTW(DisasContext *ctx, arg_r *a)
 {
-    return trans_parallel_compare(ctx, a, TCG_COND_GE, 32);
+    return trans_parallel_compare(ctx, a, TCG_COND_GT, 32);
 }
 
 /* Parallel Compare for Equal Word */
Signature · 1 line
2.55.0
Reviewed-by on v2 2/9
#4 lore raw

Re: [PATCH v2 2/9] target/mips/tx79: Fix PCGT* (Parallel Compare for Greater Than)

Quoted 5 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

PCGT* set each lane of rd when rs is greater than rt. We compared rt >= rs, returning the opposite result.

Quoted 7 lines
Fixes 8bd42c00f284 ("target/mips/tx79: Introduce PCGT ...")
---
 target/mips/tcg/tx79_translate.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
#5 lore raw

PATCH v2 3/9 tests/guest-debug: Allow placing the binary within system QEMU args

In reply to Philippe Mathieu-Daudé

In system mode the binary is appended to the QEMU arguments, which must end with an option taking it, such as -kernel. Machines without -kernel, like 'none', load it with the generic loader device, where the path is part of an option value.

Replace @BINARY@ in the arguments by the binary path if present, otherwise keep appending it.

---
 tests/guest-debug/run-test.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tests/guest-debug/run-test.py +7 -2
index 9fdf05b55d31..e6911300e8d0 100755
@@ -87,9 +87,14 @@ def format_cmd(cmd):
 
     if "system" in args.qemu:
         # for system mode we assume qargs has set-up for binary if
-        # indeed we have set one.
+        # indeed we have set one, either ending with an option taking
+        # it (e.g. -kernel) or using the @BINARY@ placeholder.
         if args.binary:
-            qemu_cmd.append(args.binary)
+            if any("@BINARY@" in arg for arg in qemu_cmd):
+                qemu_cmd = [arg.replace("@BINARY@", args.binary)
+                            for arg in qemu_cmd]
+            else:
+                qemu_cmd.append(args.binary)
         if not args.no_suspend:
             qemu_cmd.append("-S")
         qemu_cmd.extend(["-gdb", f"unix:path={socket_name},server=on"])
Signature · 1 line
2.55.0
Reviewed-by on v2 3/9
#6 lore raw

Re: [PATCH v2 3/9] tests/guest-debug: Allow placing the binary within system QEMU args

Quoted 24 lines · Philippe Mathieu-Daudé

In system mode the binary is appended to the QEMU arguments, which must end with an option taking it, such as -kernel. Machines without -kernel, like 'none', load it with the generic loader device, where the path is part of an option value.

Replace @BINARY@ in the arguments by the binary path if present, otherwise keep appending it.

---
 tests/guest-debug/run-test.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tests/guest-debug/run-test.py +2 -1
index 9fdf05b55d31..e6911300e8d0 100755
@@ -87,9 +87,14 @@ def format_cmd(cmd):
 
     if "system" in args.qemu:
         # for system mode we assume qargs has set-up for binary if
-        # indeed we have set one.
+        # indeed we have set one, either ending with an option taking
+        # it (e.g. -kernel) or using the @BINARY@ placeholder.

tests/guest-debug/run-test.py def format_cmd(cmd): · line 100

Quoted 10 lines
tests/guest-debug/run-test.py +5 -1
         if args.binary:
-            qemu_cmd.append(args.binary)
+            if any("@BINARY@" in arg for arg in qemu_cmd):
+                qemu_cmd = [arg.replace("@BINARY@", args.binary)
+                            for arg in qemu_cmd]
+            else:
+                qemu_cmd.append(args.binary)
         if not args.no_suspend:
             qemu_cmd.append("-S")
         qemu_cmd.extend(["-gdb", f"unix:path={socket_name},server=on"])

A bit implicit, but good for me.

Regards,
Pierrick

#7 lore raw

Re: [PATCH v2 3/9] tests/guest-debug: Allow placing the binary within system QEMU args

Quoted 29 lines · Pierrick Bouvier
Quoted 28 lines · Philippe Mathieu-Daudé

In system mode the binary is appended to the QEMU arguments, which must end with an option taking it, such as -kernel. Machines without -kernel, like 'none', load it with the generic loader device, where the path is part of an option value.

Replace @BINARY@ in the arguments by the binary path if present, otherwise keep appending it.

---
  tests/guest-debug/run-test.py | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
tests/guest-debug/run-test.py +4 -2
index 9fdf05b55d31..e6911300e8d0 100755
@@ -87,9 +87,14 @@ def format_cmd(cmd):
 
      if "system" in args.qemu:
          # for system mode we assume qargs has set-up for binary if
-        # indeed we have set one.
+        # indeed we have set one, either ending with an option taking
+        # it (e.g. -kernel) or using the @BINARY@ placeholder.
          if args.binary:
-            qemu_cmd.append(args.binary)
+            if any("@BINARY@" in arg for arg in qemu_cmd):
+                qemu_cmd = [arg.replace("@BINARY@", args.binary)
Quoted 8 lines

tests/guest-debug/run-test.py def format_cmd(cmd): · line 100

Quoted 6 lines
tests/guest-debug/run-test.py +3 -0
+                            for arg in qemu_cmd]
+            else:
+                qemu_cmd.append(args.binary)
          if not args.no_suspend:
              qemu_cmd.append("-S")
          qemu_cmd.extend(["-gdb", f"unix:path={socket_name},server=on"])

A bit implicit, but good for me.

Indeed; I updated the script help output:

-- >8 --

tests/guest-debug/run-test.py +6 -1
index e6911300e8d0..74844a64d42b 100755
@@ -23,7 +23,12 @@ def get_args():
     parser = argparse.ArgumentParser(description="A gdbstub test runner")
     parser.add_argument("--qemu", help="Qemu binary for test",
                         required=True)
-    parser.add_argument("--qargs", help="Qemu arguments for test")
+    parser.add_argument("--qargs",
+                        help="Qemu arguments for test. In system mode, "
+                             "@BINARY@ is replaced by the --binary path; "
+                             "without it the path is appended last "
+                             "(so qargs must end with an option taking "
+                             "it, e.g. -kernel)")
     parser.add_argument("--pargs", help="Program arguments for test")
     parser.add_argument("--kargs", help="Kernel args to --append")
     parser.add_argument("--binary", help="Binary to debug")

---

Quoted 2 lines

Thanks!

#8 lore raw

Re: [PATCH v2 3/9] tests/guest-debug: Allow placing the binary within system QEMU args

Quoted 52 lines · Philippe Mathieu-Daudé
Quoted 29 lines · Pierrick Bouvier
Quoted 28 lines · Philippe Mathieu-Daudé

In system mode the binary is appended to the QEMU arguments, which must end with an option taking it, such as -kernel. Machines without -kernel, like 'none', load it with the generic loader device, where the path is part of an option value.

Replace @BINARY@ in the arguments by the binary path if present, otherwise keep appending it.

---
   tests/guest-debug/run-test.py | 9 +++++++--
   1 file changed, 7 insertions(+), 2 deletions(-)
tests/guest-debug/run-test.py +4 -2
index 9fdf05b55d31..e6911300e8d0 100755
@@ -87,9 +87,14 @@ def format_cmd(cmd):
 
       if "system" in args.qemu:
           # for system mode we assume qargs has set-up for binary if
-        # indeed we have set one.
+        # indeed we have set one, either ending with an option taking
+        # it (e.g. -kernel) or using the @BINARY@ placeholder.
           if args.binary:
-            qemu_cmd.append(args.binary)
+            if any("@BINARY@" in arg for arg in qemu_cmd):
+                qemu_cmd = [arg.replace("@BINARY@", args.binary)
Quoted 8 lines

tests/guest-debug/run-test.py def format_cmd(cmd): · line 100

Quoted 6 lines
tests/guest-debug/run-test.py +3 -0
+                            for arg in qemu_cmd]
+            else:
+                qemu_cmd.append(args.binary)
           if not args.no_suspend:
               qemu_cmd.append("-S")
           qemu_cmd.extend(["-gdb", f"unix:path={socket_name},server=on"])

A bit implicit, but good for me.

Indeed; I updated the script help output:

-- >8 --

tests/guest-debug/run-test.py +0 -1
index e6911300e8d0..74844a64d42b 100755
@@ -23,7 +23,12 @@ def get_args():
       parser = argparse.ArgumentParser(description="A gdbstub test runner")
       parser.add_argument("--qemu", help="Qemu binary for test",
                           required=True)
-    parser.add_argument("--qargs", help="Qemu arguments for test")

tests/guest-debug/run-test.py def get_args():

Quoted 10 lines
tests/guest-debug/run-test.py +6 -1
+    parser.add_argument("--qargs",
+                        help="Qemu arguments for test. In system mode, "
+                             "@BINARY@ is replaced by the --binary path; "
+                             "without it the path is appended last "
+                             "(so qargs must end with an option taking "
+                             "it, e.g. -kernel)")
       parser.add_argument("--pargs", help="Program arguments for test")
       parser.add_argument("--kargs", help="Kernel args to --append")
       parser.add_argument("--binary", help="Binary to debug")
---

Looks great.

Quoted 3 lines
Quoted 2 lines

Thanks!

#9 lore raw

PATCH v2 4/9 tests/tcg/mips64el: Add bare-metal harness for R5900 system tests

In reply to Philippe Mathieu-Daudé

There is no libc for the R5900, so its tests can not run in user mode [*]. Provide what is needed to run them bare-metal on the 'none' machine: start-up code, linker script, minimal assert.h, inttypes.h, stdio.h and string.h, and a gdb script.

A first generic loader loads the ELF at its physical addresses, a second one sets the PC to the KSEG0 entry point, sign-extended as the CPU is 64-bit. Tests end in test_done(), where the gdb script checks the status and kills QEMU. Tests use 32-bit pointers, so gdb must send 64-bit addresses to the remote stub.

No test is registered yet.

[*] https://lore.kernel.org/qemu-devel/[email protected]/

---
 tests/tcg/mips64el/system/include/assert.h   | 15 +++++
 tests/tcg/mips64el/system/include/inttypes.h |  7 +++
 tests/tcg/mips64el/system/include/stdio.h    | 17 +++++
 tests/tcg/mips64el/system/include/string.h   | 16 +++++
 tests/tcg/mips64el/system/harness.c          | 66 ++++++++++++++++++++
 tests/tcg/mips64el/meson.build               |  2 +
 tests/tcg/mips64el/system/boot.S             | 23 +++++++
 tests/tcg/mips64el/system/kernel.ld          | 43 +++++++++++++
 tests/tcg/mips64el/system/meson.build        | 33 ++++++++++
 tests/tcg/mips64el/system/test-r5900.py      | 30 +++++++++
 10 files changed, 252 insertions(+)
 create mode 100644 tests/tcg/mips64el/system/include/assert.h
 create mode 100644 tests/tcg/mips64el/system/include/inttypes.h
 create mode 100644 tests/tcg/mips64el/system/include/stdio.h
 create mode 100644 tests/tcg/mips64el/system/include/string.h
 create mode 100644 tests/tcg/mips64el/system/harness.c
 create mode 100644 tests/tcg/mips64el/system/boot.S
 create mode 100644 tests/tcg/mips64el/system/kernel.ld
 create mode 100644 tests/tcg/mips64el/system/meson.build
 create mode 100644 tests/tcg/mips64el/system/test-r5900.py
tests/tcg/mips64el/system/include/assert.h new file +15 -0
new file mode 100644
index 000000000000..7b466a3b8ab5
@@ -0,0 +1,15 @@
+/*
+ * Freestanding assert() for bare-metal R5900 tests
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef R5900_SYSTEM_ASSERT_H
+#define R5900_SYSTEM_ASSERT_H
+
+void test_assert_fail(int line) __attribute__((noreturn));
+void test_done(int status) __attribute__((noreturn));
+
+#define assert(cond) ((cond) ? (void)0 : test_assert_fail(__LINE__))
+
+#endif
tests/tcg/mips64el/system/include/inttypes.h new file +7 -0
new file mode 100644
index 000000000000..3bfbd2ce65ea
@@ -0,0 +1,7 @@
+/*
+ * Freestanding <inttypes.h> for bare-metal R5900 tests
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdint.h>
tests/tcg/mips64el/system/include/stdio.h new file +17 -0
new file mode 100644
index 000000000000..6130f77b77d1
@@ -0,0 +1,17 @@
+/*
+ * Freestanding <stdio.h> for bare-metal R5900 tests
+ *
+ * There is no console: fprintf() only records its format string,
+ * which the gdb script reports when the test fails.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef R5900_SYSTEM_STDIO_H
+#define R5900_SYSTEM_STDIO_H
+
+void test_message(const char *msg);
+
+#define fprintf(stream, fmt, ...) test_message(fmt)
+
+#endif
tests/tcg/mips64el/system/include/string.h new file +16 -0
new file mode 100644
index 000000000000..819da7cb1ada
@@ -0,0 +1,16 @@
+/*
+ * Freestanding <string.h> for bare-metal R5900 tests
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef R5900_SYSTEM_STRING_H
+#define R5900_SYSTEM_STRING_H
+
+#include <stddef.h>
+
+void *memset(void *s, int c, size_t n);
+void *memcpy(void *dest, const void *src, size_t n);
+int memcmp(const void *s1, const void *s2, size_t n);
+
+#endif
tests/tcg/mips64el/system/harness.c new file +66 -0

66 lines not on this page · raw message

tests/tcg/mips64el/meson.build +2 -0
index 606f300804a4..a68ceab3b4b9 100644
@@ -1,3 +1,5 @@
+subdir('system')
+
 if 'qemu-mips64el' in emulators
   tcg_tests += {
     'mips64el-linux-user': {
tests/tcg/mips64el/system/boot.S new file +23 -0
new file mode 100644
index 000000000000..0448f983bbeb
@@ -0,0 +1,23 @@
+/*
+ * Minimal start-up code for bare-metal R5900 tests
+ *
+ * The CPU starts in kernel mode at _start (PC set by the generic
+ * loader device). Set up a stack, run main() and report its return
+ * value to test_done(), where the gdb script is waiting.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+    .set    noreorder
+    .section .text.boot, "ax"
+    .globl  _start
+    .ent    _start
+_start:
+    la      $sp, _stack_top
+    jal     main
+    nop
+    jal     test_done
+    move    $a0, $v0
+1:  b       1b
+    nop
+    .end    _start
tests/tcg/mips64el/system/kernel.ld new file +43 -0

43 lines not on this page · raw message

tests/tcg/mips64el/system/meson.build new file +33 -0
new file mode 100644
index 000000000000..265a2eca4ff1
@@ -0,0 +1,33 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+tests = []
+
+cflags = ['-nostdlib', '-ffreestanding',
+          '-march=r5900', '-msoft-float',
+          '-mno-abicalls', '-fno-pic', '-G0',
+          '-I', meson.current_source_dir() / 'include',
+          files('boot.S')[0], files('harness.c')[0],
+          '-Wl,-T', files('kernel.ld')[0],
+          '-Wl,--no-warn-rwx-segments', '-Wl,--build-id=none']
+
+qemu_args = ['-M', 'none', '-cpu', 'R5900', '-m', '16M',
+             '-display', 'none',
+             '-device', 'loader,file=@BINARY@',
+             '-device', 'loader,addr=0xffffffff80100000,cpu-num=0']
+
+# Pointers are 32-bit (o32, n32), sign-extend them for the 64-bit CPU
+gdb_test = ['--gdb-args=-ex "set remoteaddresssize 64"',
+            '--test', files('test-r5900.py')]
+
+if 'qemu-system-mips64el' in emulators
+  tcg_tests += {
+    'mips64el-softmmu': {
+      'cc': 'mips64el-linux-gnuabi64-gcc',
+      'cc_dockerfile': 'debian-all-test-cross',
+      'folder': 'mips64el/system',
+      'gdb_arch': 'mips64el',
+      'qemu': emulators['qemu-system-mips64el'],
+      'tests': tests,
+    }
+  }
+endif
tests/tcg/mips64el/system/test-r5900.py new file +30 -0
new file mode 100644
index 000000000000..2e7ed191b3b6
@@ -0,0 +1,30 @@
+"""Run a bare-metal R5900 test and check its result
+
+The guest runs until test_done(); a non-zero status means the test
+failed: test_failed_line holds the line of a failed assert(), and
+test_failed_message the last message the test tried to print.
+
+SPDX-License-Identifier: GPL-2.0-or-later
+"""
+
+import gdb
+from test_gdbstub import main, report
+
+
+def run_test():
+    gdb.execute("break test_done")
+    gdb.execute("continue")
+
+    status = int(gdb.parse_and_eval("status"))
+    details = ""
+    if status:
+        line = int(gdb.parse_and_eval("test_failed_line"))
+        message = gdb.parse_and_eval("test_failed_message")
+        if line:
+            details = f" (assert failed at line {line})"
+        elif int(message):
+            details = f" ({message.string().strip()})"
+    report(status == 0, "guest test" + details)
+
+
+main(run_test)
Signature · 1 line
2.55.0
Reviewed-by on v2 4/9
#10 lore raw

Re: [PATCH v2 4/9] tests/tcg/mips64el: Add bare-metal harness for R5900 system tests

Quoted 30 lines · Philippe Mathieu-Daudé

There is no libc for the R5900, so its tests can not run in user mode [*]. Provide what is needed to run them bare-metal on the 'none' machine: start-up code, linker script, minimal assert.h, inttypes.h, stdio.h and string.h, and a gdb script.

A first generic loader loads the ELF at its physical addresses, a second one sets the PC to the KSEG0 entry point, sign-extended as the CPU is 64-bit. Tests end in test_done(), where the gdb script checks the status and kills QEMU. Tests use 32-bit pointers, so gdb must send 64-bit addresses to the remote stub.

No test is registered yet.

[*] https://lore.kernel.org/qemu-devel/[email protected]/

---
 tests/tcg/mips64el/system/include/assert.h   | 15 +++++
 tests/tcg/mips64el/system/include/inttypes.h |  7 +++
 tests/tcg/mips64el/system/include/stdio.h    | 17 +++++
 tests/tcg/mips64el/system/include/string.h   | 16 +++++
 tests/tcg/mips64el/system/harness.c          | 66 ++++++++++++++++++++
 tests/tcg/mips64el/meson.build               |  2 +
 tests/tcg/mips64el/system/boot.S             | 23 +++++++
 tests/tcg/mips64el/system/kernel.ld          | 43 +++++++++++++
 tests/tcg/mips64el/system/meson.build        | 33 ++++++++++
 tests/tcg/mips64el/system/test-r5900.py      | 30 +++++++++
 10 files changed, 252 insertions(+)
 create mode 100644 tests/tcg/mips64el/system/include/assert.h
Quoted 9 lines
 create mode 100644 tests/tcg/mips64el/system/include/inttypes.h
 create mode 100644 tests/tcg/mips64el/system/include/stdio.h
 create mode 100644 tests/tcg/mips64el/system/include/string.h
 create mode 100644 tests/tcg/mips64el/system/harness.c
 create mode 100644 tests/tcg/mips64el/system/boot.S
 create mode 100644 tests/tcg/mips64el/system/kernel.ld
 create mode 100644 tests/tcg/mips64el/system/meson.build
 create mode 100644 tests/tcg/mips64el/system/test-r5900.py
#11 lore raw

Re: [PATCH v2 4/9] tests/tcg/mips64el: Add bare-metal harness for R5900 system tests

In reply to Philippe Mathieu-Daudé

Hi Philippe, Maciej,

[ Maciej, a post [*] from you in 2021 is referenced in the following. ]

Quoted 2 lines · Philippe Mathieu-Daudé

There is no libc for the R5900, so its tests can not run in user mode [*].

Both Glibc and Musl are available for the R5900.[1][2] In fact, we also compile Gentoo for it. I believe the -mfix-r5900 option is used for the official Gentoo MIPS downloads.[3]

As for QEMU, I maintain my own fork with R5900 user mode support since 2020, based on QEMU v5.2, as well as a corresponding Gentoo package,[4][5] because later versions of QEMU became unfixable and unusable for R5900 user mode emulation.

A proper QEMU R5900 user mode must emulate the FPU like the Linux kernel does, which is why QEMU 5.2 remains the latest usable version of QEMU for the R5900.

It’s worth mentioning that there are discussions on introducing additional FPU modes for the R5900 and Linux, which would allow use of FPU hardware, despite its noncompliance with IEEE 754.[6][7]

Quoted 3 lines

[*] https://lore.kernel.org/qemu-devel/[email protected]/

Fredrik

[1] https://github.com/frno7/gentoo-mipsr5900el
[2] https://github.com/frno7/gentoo-mipsr5900el/blob/d84d04b2fd9d47d5cce9c1c0884026cc37d008cf/scripts/install-crossdev#L16-L17
[3] https://www.gentoo.org/downloads/mips/
[4] https://github.com/frno7/qemu
[5] https://github.com/frno7/gentoo.overlay/tree/main/app-emulation/qemu-mipsr5900el
[6] https://github.com/frno7/linux/wiki/R5900-floating-point-unit-(FPU)
[7] https://github.com/frno7/linux/issues/3

#12 lore raw

Re: [PATCH v2 4/9] tests/tcg/mips64el: Add bare-metal harness for R5900 system tests

Quoted 8 lines · Fredrik Noring

Hi Philippe, Maciej,

[ Maciej, a post [*] from you in 2021 is referenced in the following. ]

Quoted 2 lines · Philippe Mathieu-Daudé

There is no libc for the R5900, so its tests can not run in user mode [*].

I think that Philippe meant "there is no *prebuilt* libc for the r5900".

Quoted 4 lines

Both Glibc and Musl are available for the R5900.[1][2] In fact, we also compile Gentoo for it. I believe the -mfix-r5900 option is used for the official Gentoo MIPS downloads.[3]

If precompiled glibc or musl with companion toolchain are available from a .tar, yes it could be used.

Quoted 26 lines

As for QEMU, I maintain my own fork with R5900 user mode support since 2020, based on QEMU v5.2, as well as a corresponding Gentoo package,[4][5] because later versions of QEMU became unfixable and unusable for R5900 user mode emulation.

A proper QEMU R5900 user mode must emulate the FPU like the Linux kernel does, which is why QEMU 5.2 remains the latest usable version of QEMU for the R5900.

It’s worth mentioning that there are discussions on introducing additional FPU modes for the R5900 and Linux, which would allow use of FPU hardware, despite its noncompliance with IEEE 754.[6][7]

Quoted 3 lines

[*] https://lore.kernel.org/qemu-devel/[email protected]/

Fredrik

[1] https://github.com/frno7/gentoo-mipsr5900el
[2] https://github.com/frno7/gentoo-mipsr5900el/blob/d84d04b2fd9d47d5cce9c1c0884026cc37d008cf/scripts/install-crossdev#L16-L17
[3] https://www.gentoo.org/downloads/mips/
[4] https://github.com/frno7/qemu
[5] https://github.com/frno7/gentoo.overlay/tree/main/app-emulation/qemu-mipsr5900el
[6] https://github.com/frno7/linux/wiki/R5900-floating-point-unit-(FPU)
[7] https://github.com/frno7/linux/issues/3

#13 lore raw

Re: [PATCH v2 4/9] tests/tcg/mips64el: Add bare-metal harness for R5900 system tests

Hey Fredrik!

Quoted 12 lines · Pierrick Bouvier
Quoted 8 lines · Fredrik Noring

Hi Philippe, Maciej,

[ Maciej, a post [*] from you in 2021 is referenced in the following. ]

Quoted 2 lines · Philippe Mathieu-Daudé

There is no libc for the R5900, so its tests can not run in user mode [*].

I think that Philippe meant "there is no *prebuilt* libc for the r5900".

Quoted 7 lines
Quoted 4 lines

Both Glibc and Musl are available for the R5900.[1][2] In fact, we also compile Gentoo for it. I believe the -mfix-r5900 option is used for the official Gentoo MIPS downloads.[3]

If precompiled glibc or musl with companion toolchain are available from a .tar, yes it could be used.

For now I deliberately kept user-mode emulation out, focusing on system emulation which is less invasive.

I got user-emulation working but this add another QEMU binary and last time Laurent as linux-user maintainer was not motivated to add a new binary / target for 2 users :/

I have these changes on top of what I posted so far this week, but building a r5900 cross-compiler on a x86 container running on an aarch64 host takes age...:

-- >8 --

meson_options.txt +4 -0
index c9247e9de1..a48f2fcb7c 100644
@@ -461,6 +461,10 @@ option('tcg_tests_cross_cc_mips32r5el', type: 'string',
        description: 'cc for mips32r5el tcg tests')
 option('tcg_tests_cross_cflags_mips32r5el', type: 'string',
        description: 'cflags for mips32r5el tcg tests')
+option('tcg_tests_cross_cc_mipsr5900el', type: 'string',
+       description: 'cc for mipsr5900el tcg tests')
+option('tcg_tests_cross_cflags_mipsr5900el', type: 'string',
+       description: 'cflags for mipsr5900el tcg tests')
 option('tcg_tests_cross_cc_or1k', type: 'string',
        description: 'cc for or1k tcg tests')
 option('tcg_tests_cross_cflags_or1k', type: 'string',
scripts/meson-buildoptions.sh +0 -0
index 064e1429a4..69f203fa74 100644
@@ -539,6 +539,7 @@ _meson_option_parse() {
     --tcg-tests-cross-cc-m68k=*) quote_sh 
"-Dtcg_tests_cross_cc_m68k=$2" ;;
     --tcg-tests-cross-cc-mips=*) quote_sh 
"-Dtcg_tests_cross_cc_mips=$2" ;;
     --tcg-tests-cross-cc-mips32r5el=*) quote_sh 
"-Dtcg_tests_cross_cc_mips32r5el=$2" ;;
+    --tcg-tests-cross-cc-mipsr5900el=*) quote_sh "-Dtcg_tests_cross_cc_mipsr5900el=$2" ;;
     --tcg-tests-cross-cc-mips64=*) quote_sh 
"-Dtcg_tests_cross_cc_mips64=$2" ;;
     --tcg-tests-cross-cc-mips64el=*) quote_sh 
"-Dtcg_tests_cross_cc_mips64el=$2" ;;
     --tcg-tests-cross-cc-mips64r6=*) quote_sh 
"-Dtcg_tests_cross_cc_mips64r6=$2" ;;
@@ -565,6 +566,7 @@ _meson_option_parse() {
     --tcg-tests-cross-cflags-m68k=*) quote_sh 
"-Dtcg_tests_cross_cflags_m68k=$2" ;;
     --tcg-tests-cross-cflags-mips=*) quote_sh 
"-Dtcg_tests_cross_cflags_mips=$2" ;;
     --tcg-tests-cross-cflags-mips32r5el=*) quote_sh 
"-Dtcg_tests_cross_cflags_mips32r5el=$2" ;;
+    --tcg-tests-cross-cflags-mipsr5900el=*) quote_sh "-Dtcg_tests_cross_cflags_mipsr5900el=$2" ;;
     --tcg-tests-cross-cflags-mips64=*) quote_sh 
"-Dtcg_tests_cross_cflags_mips64=$2" ;;
     --tcg-tests-cross-cflags-mips64el=*) quote_sh 
"-Dtcg_tests_cross_cflags_mips64el=$2" ;;
     --tcg-tests-cross-cflags-mips64r6=*) quote_sh 

"-Dtcg_tests_cross_cflags_mips64r6=$2" ;;

tests/docker/dockerfiles/gentoo-mipsr5900el-cross.docker new file +40 -0
new file mode 100644
index 0000000000..f46c5a54b6
@@ -0,0 +1,40 @@
+#
+# Docker mipsel (R5900) cross-compiler target
+#
+# The compiler is built with Gentoo crossdev because the regular Debian MIPS
+# toolchains do not provide the R5900-specific instruction set.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+FROM docker.io/gentoo/stage3:latest
+
+RUN emerge-webrsync --quiet
+
+RUN mkdir -p /usr/local/portage-crossdev/{profiles,metadata} && \
+    printf '%s\n' crossdev > /usr/local/portage-crossdev/profiles/repo_name && \
+    printf '%s\n' 'masters = gentoo' > /usr/local/portage-crossdev/metadata/layout.conf && \
+    chown -R portage:portage /usr/local/portage-crossdev && \
+    mkdir -p /etc/portage/repos.conf && \
+    printf '%s\n' \
+        '[crossdev]' \
+        'location = /usr/local/portage-crossdev' \
+        'priority = 10' \
+        'masters = gentoo' \
+        'auto-sync = no' \
+        > /etc/portage/repos.conf/crossdev.conf
+
+RUN emerge -qv \
+        dev-vcs/git \
+        '>=dev-libs/glib-2.0' \
+        sys-devel/crossdev \
+        sys-libs/zlib \
+        dev-lang/python
+
+RUN crossdev -s4 -t mipsr5900el-unknown-linux-gnu
+
+ENV QEMU_CONFIGURE_OPTS="--cross-prefix=mipsr5900el-unknown-linux-gnu-"
+
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
tests/docker/dockerfiles/ubuntu2404-arm64-ps2dev.docker new file +41 -0

41 lines not on this page · raw message

tests/tcg/mips/meson.build +2 -0
index 2164f143ea..5f640d13e8 100644
@@ -1,3 +1,5 @@
+subdir('system')
+
 tests = []
 
 tests += tcg_tests['multiarch-linux-user']['tests']
tests/tcg/mips/system/boot.S new file +32 -0
new file mode 100644
index 0000000000..ab5b799059
@@ -0,0 +1,32 @@
+/*
+ * Minimal R5900 bare-metal entry point.
+ *
+ * The MIPS UHI semihosting ABI uses $25 for the operation and $4 for its
+ * argument.  UHI_exit is selected by executing sdbbp with code 1 while
+ * semihosting is enabled in QEMU.
+ */
+
+       .set noreorder
+       .set noat
+
+       .section .text.boot, "ax", @progbits
+       .align 2
+       .globl _start
+       .ent _start
+_start:
+       /* Keep the stack away from the image loaded at address zero. */
+       lui     $sp, 0x0100
+
+       jal     test_main
+        nop
+
+       move    $a0, $v0
+       li      $t9, 1                  /* UHI_exit */
+       /* sdbbp 1 (SPECIAL2, code 1); the PS2Dev assembler lacks the mnemonic. */
+       .word   0x7000007f
+        nop
+
+1:
+       b       1b
+        nop
+       .end _start
tests/tcg/mips/system/meson.build new file +76 -0

76 lines not on this page · raw message

tests/tcg/mips/system/run-test.py new file +30 -0
new file mode 100644
index 0000000000..912b6bb01b
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+"""Run a MIPS bare-metal ELF and propagate its UHI exit status."""
+
+import argparse
+import subprocess
+
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--qemu', required=True)
+    parser.add_argument('--elf', required=True)
+    args = parser.parse_args()
+
+    command = [
+        args.qemu,
+        '-M', 'none',
+        '-m', '16M',
+        '-cpu', 'R5900',
+        '-display', 'none',
+        '-device', f'loader,file={args.elf},cpu-num=0',
+        '-semihosting-config', 'enable=on,target=native',
+    ]
+
+    # Inherit stdout/stderr so diagnostics remain visible when the test
+    # fails.  UHI_exit makes QEMU's process status the test result.
+    return subprocess.run(command, check=False).returncode
+
+
+if __name__ == '__main__':
+    raise SystemExit(main())
tests/tcg/mips64/meson.build +4 -0
index c80a3716f5..0d3c44b643 100644
@@ -6,6 +6,10 @@ tests += {
   '../mips64/octeon-insns.c': {
     'qemu_args': ['-cpu', 'Octeon68XX'],
   },
+  '../mips64/tx79-insns.c': {
+    'qemu_args': ['-cpu', 'R5900'],
+    'cflags': '-march=mips64r2',
+  },
 }
tests/tcg/mipsel/meson.build +35 -0
index 3ac4711748..e69aff6211 100644
@@ -215,3 +215,38 @@ if 'qemu-mipsel' in emulators
     }
   }
 endif
+
+tests = []
+
+tests_mips_r5900 = [
+  '../mips/user/isa/r5900/test_r5900_div1.c',
+  '../mips/user/isa/r5900/test_r5900_divu1.c',
+  '../mips/user/isa/r5900/test_r5900_madd.c',
+  '../mips/user/isa/r5900/test_r5900_maddu.c',
+  '../mips/user/isa/r5900/test_r5900_mflohi1.c',
+  '../mips/user/isa/r5900/test_r5900_mtlohi1.c',
+  '../mips/user/isa/r5900/test_r5900_mult.c',
+  '../mips/user/isa/r5900/test_r5900_multu.c',
+]
+
+foreach src: tests_mips_r5900
+  tests += {
+    src: {
+      'cflags': ['-mabi=32', '-march=r5900'],
+      'qemu_args': ['-cpu', 'R5900'],
+    }
+  }
+endforeach
+
+if 'qemu-mipsel' in emulators
+  tcg_tests += {
+    'mipsr5900el-linux-user': {
+      'cc': 'mipsr5900el-unknown-linux-gnu-gcc',
+      'cc_dockerfile': 'gentoo-mipsr5900el-cross',
+      'folder': 'mipsel',
+      'gdb_arch': 'mipsel',
+      'qemu': emulators['qemu-mipsel'],
+      'tests': tests,
+    }
+  }
+endif

---

Quoted 27 lines
Quoted 26 lines

As for QEMU, I maintain my own fork with R5900 user mode support since 2020, based on QEMU v5.2, as well as a corresponding Gentoo package,[4][5] because later versions of QEMU became unfixable and unusable for R5900 user mode emulation.

A proper QEMU R5900 user mode must emulate the FPU like the Linux kernel does, which is why QEMU 5.2 remains the latest usable version of QEMU for the R5900.

It’s worth mentioning that there are discussions on introducing additional FPU modes for the R5900 and Linux, which would allow use of FPU hardware, despite its noncompliance with IEEE 754.[6][7]

Quoted 3 lines

[*] https://lore.kernel.org/qemu-devel/[email protected]/

Fredrik

[1] https://github.com/frno7/gentoo-mipsr5900el
[2] https://github.com/frno7/gentoo-mipsr5900el/blob/d84d04b2fd9d47d5cce9c1c0884026cc37d008cf/scripts/install-crossdev#L16-L17
[3] https://www.gentoo.org/downloads/mips/
[4] https://github.com/frno7/qemu
[5] https://github.com/frno7/gentoo.overlay/tree/main/app-emulation/qemu-mipsr5900el
[6] https://github.com/frno7/linux/wiki/R5900-floating-point-unit-(FPU)
[7] https://github.com/frno7/linux/issues/3

#14 lore raw

PATCH v2 5/9 tests/tcg/mips64el: Move R5900 tests to system mode and build with meson

In reply to Philippe Mathieu-Daudé

The Makefile needs a toolchain we do not have and qemu-mipsel, which no longer provides the R5900 CPU. Move the tests next to the bare-metal harness, register them in meson.build, and remove the Makefile and the obsolete README.

---
 .../system}/test_r5900_div1.c                 |  0
 .../system}/test_r5900_divu1.c                |  0
 .../system}/test_r5900_madd.c                 |  0
 .../system}/test_r5900_maddu.c                |  0
 .../system}/test_r5900_mflohi1.c              |  0
 .../system}/test_r5900_mtlohi1.c              |  0
 .../system}/test_r5900_mult.c                 |  0
 .../system}/test_r5900_multu.c                |  0
 tests/tcg/mips/user/isa/r5900/Makefile        | 32 -------------------
 tests/tcg/mips/user/isa/r5900/README          |  6 ----
 tests/tcg/mips64el/system/meson.build         | 20 ++++++++++++
 11 files changed, 20 insertions(+), 38 deletions(-)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_div1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_divu1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_madd.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_maddu.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mflohi1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mtlohi1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mult.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_multu.c (100%)
 delete mode 100644 tests/tcg/mips/user/isa/r5900/Makefile
 delete mode 100644 tests/tcg/mips/user/isa/r5900/README
tests/tcg/mips64el/system/test_r5900_div1.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_div1.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_div1.c
rename to tests/tcg/mips64el/system/test_r5900_div1.c
tests/tcg/mips64el/system/test_r5900_divu1.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_divu1.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_divu1.c
rename to tests/tcg/mips64el/system/test_r5900_divu1.c
tests/tcg/mips64el/system/test_r5900_madd.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_madd.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_madd.c
rename to tests/tcg/mips64el/system/test_r5900_madd.c
tests/tcg/mips64el/system/test_r5900_maddu.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_maddu.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_maddu.c
rename to tests/tcg/mips64el/system/test_r5900_maddu.c
tests/tcg/mips64el/system/test_r5900_mflohi1.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_mflohi1.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_mflohi1.c
rename to tests/tcg/mips64el/system/test_r5900_mflohi1.c
tests/tcg/mips64el/system/test_r5900_mtlohi1.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_mtlohi1.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_mtlohi1.c
rename to tests/tcg/mips64el/system/test_r5900_mtlohi1.c
tests/tcg/mips64el/system/test_r5900_mult.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_mult.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_mult.c
rename to tests/tcg/mips64el/system/test_r5900_mult.c
tests/tcg/mips64el/system/test_r5900_multu.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_multu.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_multu.c
rename to tests/tcg/mips64el/system/test_r5900_multu.c
tests/tcg/mips/user/isa/r5900/Makefile deleted +0 -32
deleted file mode 100644
index bff360df6c97..000000000000
@@ -1,32 +0,0 @@
--include ../../../../config-host.mak
-
-CROSS=mipsr5900el-unknown-linux-gnu-
-
-SIM=qemu-mipsel
-SIM_FLAGS=-cpu R5900
-
-CC      = $(CROSS)gcc
-CFLAGS  = -Wall -mabi=32 -march=r5900 -static
-
-TESTCASES  = test_r5900_div1.tst
-TESTCASES += test_r5900_divu1.tst
-TESTCASES += test_r5900_madd.tst
-TESTCASES += test_r5900_maddu.tst
-TESTCASES += test_r5900_mflohi1.tst
-TESTCASES += test_r5900_mtlohi1.tst
-TESTCASES += test_r5900_mult.tst
-TESTCASES += test_r5900_multu.tst
-
-all: $(TESTCASES)
-
-%.tst: %.c
-	$(CC) $(CFLAGS) $< -o $@
-
-check: $(TESTCASES)
-	@for case in $(TESTCASES); do \
-        echo $(SIM) $(SIM_FLAGS) ./$$case;\
-        $(SIM) $(SIM_FLAGS) ./$$case; \
-	done
-
-clean:
-	$(RM) -rf $(TESTCASES)
tests/tcg/mips/user/isa/r5900/README deleted +0 -6
deleted file mode 100644
index 18ecfc3bd0a5..000000000000
@@ -1,6 +0,0 @@
-This test suite can't be run at the moment. We don't have a qemu target for this
-architecture, which has single-float arithmetic, and custom 128-bit registers.
-Also, a specific toolchain has to be compiled for it.
-
-We keep the tests here in case someone is interested one day to resurrect this
-architecture.
tests/tcg/mips64el/system/meson.build +20 -0
index 265a2eca4ff1..fd5a759c20fa 100644
@@ -19,6 +19,26 @@ qemu_args = ['-M', 'none', '-cpu', 'R5900', '-m', '16M',
 gdb_test = ['--gdb-args=-ex "set remoteaddresssize 64"',
             '--test', files('test-r5900.py')]
 
+# o32: 32-bit pointers, 32-bit GPRs are enough
+foreach t: [
+  'div1',
+  'divu1',
+  'madd',
+  'maddu',
+  'mflohi1',
+  'mtlohi1',
+  'mult',
+  'multu',
+]
+  tests += {
+    'test_r5900_' + t + '.c': {
+      'cflags': cflags + ['-mabi=32'],
+      'qemu_args': qemu_args,
+      'gdb_test': gdb_test,
+    }
+  }
+endforeach
+
 if 'qemu-system-mips64el' in emulators
   tcg_tests += {
     'mips64el-softmmu': {
Signature · 1 line
2.55.0
Reviewed-by on v2 5/9
#15 lore raw

Re: [PATCH v2 5/9] tests/tcg/mips64el: Move R5900 tests to system mode and build with meson

Quoted 128 lines · Philippe Mathieu-Daudé

The Makefile needs a toolchain we do not have and qemu-mipsel, which no longer provides the R5900 CPU. Move the tests next to the bare-metal harness, register them in meson.build, and remove the Makefile and the obsolete README.

---
 .../system}/test_r5900_div1.c                 |  0
 .../system}/test_r5900_divu1.c                |  0
 .../system}/test_r5900_madd.c                 |  0
 .../system}/test_r5900_maddu.c                |  0
 .../system}/test_r5900_mflohi1.c              |  0
 .../system}/test_r5900_mtlohi1.c              |  0
 .../system}/test_r5900_mult.c                 |  0
 .../system}/test_r5900_multu.c                |  0
 tests/tcg/mips/user/isa/r5900/Makefile        | 32 -------------------
 tests/tcg/mips/user/isa/r5900/README          |  6 ----
 tests/tcg/mips64el/system/meson.build         | 20 ++++++++++++
 11 files changed, 20 insertions(+), 38 deletions(-)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_div1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_divu1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_madd.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_maddu.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mflohi1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mtlohi1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mult.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_multu.c (100%)
 delete mode 100644 tests/tcg/mips/user/isa/r5900/Makefile
 delete mode 100644 tests/tcg/mips/user/isa/r5900/README
tests/tcg/mips64el/system/test_r5900_div1.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_div1.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_div1.c
rename to tests/tcg/mips64el/system/test_r5900_div1.c
tests/tcg/mips64el/system/test_r5900_divu1.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_divu1.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_divu1.c
rename to tests/tcg/mips64el/system/test_r5900_divu1.c
tests/tcg/mips64el/system/test_r5900_madd.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_madd.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_madd.c
rename to tests/tcg/mips64el/system/test_r5900_madd.c
tests/tcg/mips64el/system/test_r5900_maddu.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_maddu.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_maddu.c
rename to tests/tcg/mips64el/system/test_r5900_maddu.c
tests/tcg/mips64el/system/test_r5900_mflohi1.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_mflohi1.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_mflohi1.c
rename to tests/tcg/mips64el/system/test_r5900_mflohi1.c
tests/tcg/mips64el/system/test_r5900_mtlohi1.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_mtlohi1.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_mtlohi1.c
rename to tests/tcg/mips64el/system/test_r5900_mtlohi1.c
tests/tcg/mips64el/system/test_r5900_mult.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_mult.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_mult.c
rename to tests/tcg/mips64el/system/test_r5900_mult.c
tests/tcg/mips64el/system/test_r5900_multu.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_multu.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_multu.c
rename to tests/tcg/mips64el/system/test_r5900_multu.c
tests/tcg/mips/user/isa/r5900/Makefile deleted +0 -32
deleted file mode 100644
index bff360df6c97..000000000000
@@ -1,32 +0,0 @@
--include ../../../../config-host.mak
-
-CROSS=mipsr5900el-unknown-linux-gnu-
-
-SIM=qemu-mipsel
-SIM_FLAGS=-cpu R5900
-
-CC      = $(CROSS)gcc
-CFLAGS  = -Wall -mabi=32 -march=r5900 -static
-
-TESTCASES  = test_r5900_div1.tst
-TESTCASES += test_r5900_divu1.tst
-TESTCASES += test_r5900_madd.tst
-TESTCASES += test_r5900_maddu.tst
-TESTCASES += test_r5900_mflohi1.tst
-TESTCASES += test_r5900_mtlohi1.tst
-TESTCASES += test_r5900_mult.tst
-TESTCASES += test_r5900_multu.tst
-
-all: $(TESTCASES)
-
-%.tst: %.c
-	$(CC) $(CFLAGS) $< -o $@
-
-check: $(TESTCASES)
-	@for case in $(TESTCASES); do \
-        echo $(SIM) $(SIM_FLAGS) ./$$case;\
-        $(SIM) $(SIM_FLAGS) ./$$case; \
-	done
-
-clean:
-	$(RM) -rf $(TESTCASES)
tests/tcg/mips/user/isa/r5900/README deleted +0 -6
deleted file mode 100644
index 18ecfc3bd0a5..000000000000
@@ -1,6 +0,0 @@
-This test suite can't be run at the moment. We don't have a qemu target for this
-architecture, which has single-float arithmetic, and custom 128-bit registers.
-Also, a specific toolchain has to be compiled for it.
-
-We keep the tests here in case someone is interested one day to resurrect this
-architecture.
tests/tcg/mips64el/system/meson.build +8 -0
index 265a2eca4ff1..fd5a759c20fa 100644
@@ -19,6 +19,26 @@ qemu_args = ['-M', 'none', '-cpu', 'R5900', '-m', '16M',
 gdb_test = ['--gdb-args=-ex "set remoteaddresssize 64"',
             '--test', files('test-r5900.py')]
 
+# o32: 32-bit pointers, 32-bit GPRs are enough
+foreach t: [
+  'div1',
+  'divu1',
+  'madd',
+  'maddu',
+  'mflohi1',
+  'mtlohi1',

tests/tcg/mips64el/system/meson.build qemu_args = ['-M', 'none', '-cpu', 'R5900', '-m', '16M', · line 39

Quoted 10 lines
tests/tcg/mips64el/system/meson.build +10 -0
+  'mult',
+  'multu',
+]
+  tests += {
+    'test_r5900_' + t + '.c': {
+      'cflags': cflags + ['-mabi=32'],
+      'qemu_args': qemu_args,
+      'gdb_test': gdb_test,
+    }
+  }

Just a small nit, please keep full file name in the original array (s/div1/div1.c), All other meson.build for tcg/tests do this also.

Regards,
Pierrick

#16 lore raw

Re: [PATCH v2 5/9] tests/tcg/mips64el: Move R5900 tests to system mode and build with meson

Quoted 134 lines · Pierrick Bouvier
Quoted 133 lines · Philippe Mathieu-Daudé

The Makefile needs a toolchain we do not have and qemu-mipsel, which no longer provides the R5900 CPU. Move the tests next to the bare-metal harness, register them in meson.build, and remove the Makefile and the obsolete README.

---
 .../system}/test_r5900_div1.c                 |  0
 .../system}/test_r5900_divu1.c                |  0
 .../system}/test_r5900_madd.c                 |  0
 .../system}/test_r5900_maddu.c                |  0
 .../system}/test_r5900_mflohi1.c              |  0
 .../system}/test_r5900_mtlohi1.c              |  0
 .../system}/test_r5900_mult.c                 |  0
 .../system}/test_r5900_multu.c                |  0
 tests/tcg/mips/user/isa/r5900/Makefile        | 32 -------------------
 tests/tcg/mips/user/isa/r5900/README          |  6 ----
 tests/tcg/mips64el/system/meson.build         | 20 ++++++++++++
 11 files changed, 20 insertions(+), 38 deletions(-)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_div1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_divu1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_madd.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_maddu.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mflohi1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mtlohi1.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mult.c (100%)
 rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_multu.c (100%)
 delete mode 100644 tests/tcg/mips/user/isa/r5900/Makefile
 delete mode 100644 tests/tcg/mips/user/isa/r5900/README
tests/tcg/mips64el/system/test_r5900_div1.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_div1.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_div1.c
rename to tests/tcg/mips64el/system/test_r5900_div1.c
tests/tcg/mips64el/system/test_r5900_divu1.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_divu1.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_divu1.c
rename to tests/tcg/mips64el/system/test_r5900_divu1.c
tests/tcg/mips64el/system/test_r5900_madd.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_madd.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_madd.c
rename to tests/tcg/mips64el/system/test_r5900_madd.c
tests/tcg/mips64el/system/test_r5900_maddu.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_maddu.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_maddu.c
rename to tests/tcg/mips64el/system/test_r5900_maddu.c
tests/tcg/mips64el/system/test_r5900_mflohi1.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_mflohi1.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_mflohi1.c
rename to tests/tcg/mips64el/system/test_r5900_mflohi1.c
tests/tcg/mips64el/system/test_r5900_mtlohi1.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_mtlohi1.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_mtlohi1.c
rename to tests/tcg/mips64el/system/test_r5900_mtlohi1.c
tests/tcg/mips64el/system/test_r5900_mult.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_mult.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_mult.c
rename to tests/tcg/mips64el/system/test_r5900_mult.c
tests/tcg/mips64el/system/test_r5900_multu.c renamed from tests/tcg/mips/user/isa/r5900/test_r5900_multu.c +0 -0
similarity index 100%
rename from tests/tcg/mips/user/isa/r5900/test_r5900_multu.c
rename to tests/tcg/mips64el/system/test_r5900_multu.c
tests/tcg/mips/user/isa/r5900/Makefile deleted +0 -32
deleted file mode 100644
index bff360df6c97..000000000000
@@ -1,32 +0,0 @@
--include ../../../../config-host.mak
-
-CROSS=mipsr5900el-unknown-linux-gnu-
-
-SIM=qemu-mipsel
-SIM_FLAGS=-cpu R5900
-
-CC      = $(CROSS)gcc
-CFLAGS  = -Wall -mabi=32 -march=r5900 -static
-
-TESTCASES  = test_r5900_div1.tst
-TESTCASES += test_r5900_divu1.tst
-TESTCASES += test_r5900_madd.tst
-TESTCASES += test_r5900_maddu.tst
-TESTCASES += test_r5900_mflohi1.tst
-TESTCASES += test_r5900_mtlohi1.tst
-TESTCASES += test_r5900_mult.tst
-TESTCASES += test_r5900_multu.tst
-
-all: $(TESTCASES)
-
-%.tst: %.c
-	$(CC) $(CFLAGS) $< -o $@
-
-check: $(TESTCASES)
-	@for case in $(TESTCASES); do \
-        echo $(SIM) $(SIM_FLAGS) ./$$case;\
-        $(SIM) $(SIM_FLAGS) ./$$case; \
-	done
-
-clean:
-	$(RM) -rf $(TESTCASES)
tests/tcg/mips/user/isa/r5900/README deleted +0 -6
deleted file mode 100644
index 18ecfc3bd0a5..000000000000
@@ -1,6 +0,0 @@
-This test suite can't be run at the moment. We don't have a qemu target for this
-architecture, which has single-float arithmetic, and custom 128-bit registers.
-Also, a specific toolchain has to be compiled for it.
-
-We keep the tests here in case someone is interested one day to resurrect this
-architecture.
tests/tcg/mips64el/system/meson.build +13 -0
index 265a2eca4ff1..fd5a759c20fa 100644
@@ -19,6 +19,26 @@ qemu_args = ['-M', 'none', '-cpu', 'R5900', '-m', '16M',
 gdb_test = ['--gdb-args=-ex "set remoteaddresssize 64"',
             '--test', files('test-r5900.py')]
 
+# o32: 32-bit pointers, 32-bit GPRs are enough
+foreach t: [
+  'div1',
+  'divu1',
+  'madd',
+  'maddu',
+  'mflohi1',
+  'mtlohi1',
+  'mult',
+  'multu',
+]
+  tests += {
+    'test_r5900_' + t + '.c': {
Quoted 9 lines

tests/tcg/mips64el/system/meson.build qemu_args = ['-M', 'none', '-cpu', 'R5900', '-m', '16M', · line 39

Quoted 5 lines
tests/tcg/mips64el/system/meson.build +5 -0
+      'cflags': cflags + ['-mabi=32'],
+      'qemu_args': qemu_args,
+      'gdb_test': gdb_test,
+    }
+  }

Just a small nit, please keep full file name in the original array (s/div1/div1.c), All other meson.build for tcg/tests do this also.

(s/div1/test_5900_div1.c)

Quoted 4 lines

Regards,
Pierrick

#17 lore raw

Re: [PATCH v2 5/9] tests/tcg/mips64el: Move R5900 tests to system mode and build with meson

Quoted 56 lines · Pierrick Bouvier
Quoted 45 lines · Pierrick Bouvier
Quoted 44 lines · Philippe Mathieu-Daudé

The Makefile needs a toolchain we do not have and qemu-mipsel, which no longer provides the R5900 CPU. Move the tests next to the bare-metal harness, register them in meson.build, and remove the Makefile and the obsolete README.

---
  .../system}/test_r5900_div1.c                 |  0
  .../system}/test_r5900_divu1.c                |  0
  .../system}/test_r5900_madd.c                 |  0
  .../system}/test_r5900_maddu.c                |  0
  .../system}/test_r5900_mflohi1.c              |  0
  .../system}/test_r5900_mtlohi1.c              |  0
  .../system}/test_r5900_mult.c                 |  0
  .../system}/test_r5900_multu.c                |  0
  tests/tcg/mips/user/isa/r5900/Makefile        | 32 -------------------
  tests/tcg/mips/user/isa/r5900/README          |  6 ----
  tests/tcg/mips64el/system/meson.build         | 20 ++++++++++++
  11 files changed, 20 insertions(+), 38 deletions(-)

rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_div1.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_divu1.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_madd.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_maddu.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mflohi1.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mtlohi1.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mult.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_multu.c (100%) delete mode 100644 tests/tcg/mips/user/isa/r5900/Makefile
delete mode 100644 tests/tcg/mips/user/isa/r5900/README

(quoted diff) +13 -0
+# o32: 32-bit pointers, 32-bit GPRs are enough
+foreach t: [
+  'div1',
+  'divu1',
+  'madd',
+  'maddu',
+  'mflohi1',
+  'mtlohi1',
+  'mult',
+  'multu',
+]
+  tests += {
+    'test_r5900_' + t + '.c': {
Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+      'cflags': cflags + ['-mabi=32'],
+      'qemu_args': qemu_args,
+      'gdb_test': gdb_test,
+    }
+  }

Just a small nit, please keep full file name in the original array (s/div1/div1.c), All other meson.build for tcg/tests do this also.

Quoted 1 line

(s/div1/test_5900_div1.c)

Squashed:

-- >8 --

tests/tcg/mips64el/system/meson.build +9 -9
index fd5a759c20fa..c16a21f57aef 100644
@@ -21,17 +21,17 @@ gdb_test = ['--gdb-args=-ex "set remoteaddresssize 64"',
 
 # o32: 32-bit pointers, 32-bit GPRs are enough
 foreach t: [
-  'div1',
-  'divu1',
-  'madd',
-  'maddu',
-  'mflohi1',
-  'mtlohi1',
-  'mult',
-  'multu',
+  'test_r5900_div1.c',
+  'test_r5900_divu1.c',
+  'test_r5900_madd.c',
+  'test_r5900_maddu.c',
+  'test_r5900_mflohi1.c',
+  'test_r5900_mtlohi1.c',
+  'test_r5900_mult.c',
+  'test_r5900_multu.c',
 ]
   tests += {
-    'test_r5900_' + t + '.c': {
+    t: {
       'cflags': cflags + ['-mabi=32'],
       'qemu_args': qemu_args,
       'gdb_test': gdb_test,

---

Quoted 2 lines
Quoted 2 lines

Thanks!

#18 lore raw

PATCH v2 6/9 target/mips: Factor mips_gdb_read_value() out

In reply to Philippe Mathieu-Daudé

Factor mips_gdb_read_value() out of mips_cpu_gdb_read_register() for re-use in the next commit. No functional change intended.

---
 target/mips/gdbstub.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
target/mips/gdbstub.c +16 -4
index 78d3e9a5b9b4..54649bfffc8d 100644
@@ -31,13 +31,13 @@ static int mips_gdb_get_regl(const CPUMIPSState *env,
                                   : gdb_get_reg32(buf, val);
 }
 
-int mips_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
+static bool mips_gdb_read_value(CPUMIPSState *env, int n, uint64_t *pval)
 {
-    CPUMIPSState *env = cpu_env(cs);
     uint64_t val;
 
     if (n < 32) {
-        return mips_gdb_get_regl(env, mem_buf, env->active_tc.gpr[n]);
+        *pval = env->active_tc.gpr[n];
+        return true;
     }
     if (env->CP0_Config1 & (1 << CP0C1_FP) && n >= 38 && n < 72) {
         switch (n) {
@@ -83,13 +83,25 @@ int mips_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
             break;
         default:
             if (n > 89) {
-                return 0;
+                return false;
             }
             /* 16 embedded regs.  */
             val = 0;
             break;
         }
     }
+    *pval = val;
+    return true;
+}
+
+int mips_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
+{
+    CPUMIPSState *env = cpu_env(cs);
+    uint64_t val;
+
+    if (!mips_gdb_read_value(env, n, &val)) {
+        return 0;
+    }
     return mips_gdb_get_regl(env, mem_buf, val);
 }
 
Signature · 1 line
2.55.0
Reviewed-by on v2 6/9
#19 lore raw

Re: [PATCH v2 6/9] target/mips: Factor mips_gdb_read_value() out

Quoted 8 lines · Philippe Mathieu-Daudé

Factor mips_gdb_read_value() out of mips_cpu_gdb_read_register() for re-use in the next commit. No functional change intended.

---
 target/mips/gdbstub.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
#20 lore raw

PATCH v2 7/9 target/mips: Describe gdbstub registers with XML features

In reply to Philippe Mathieu-Daudé

MIPS has no XML target description, so extra features can not be registered. Expose the cpu, cp0 and fpu registers as the GDB standard features, mapped to the legacy register numbers.

Registers are sized by the target long size (mips32-*.xml or mips64-*.xml) instead of the CPU: a 32-bit CPU on a 64-bit target now reports 64-bit registers. FPU registers are single-precision on 32-bit targets.

---
 MAINTAINERS                              |  1 +
 configs/targets/mips-linux-user.mak      |  1 +
 configs/targets/mips-softmmu.mak         |  1 +
 configs/targets/mips64-linux-user.mak    |  1 +
 configs/targets/mips64-softmmu.mak       |  1 +
 configs/targets/mips64el-linux-user.mak  |  1 +
 configs/targets/mips64el-softmmu.mak     |  1 +
 configs/targets/mipsel-linux-user.mak    |  1 +
 configs/targets/mipsel-softmmu.mak       |  1 +
 configs/targets/mipsn32-linux-user.mak   |  1 +
 configs/targets/mipsn32el-linux-user.mak |  1 +
 target/mips/internal.h                   |  2 +
 target/mips/cpu.c                        |  4 ++
 target/mips/gdbstub.c                    | 86 ++++++++++++++++++++++++
 gdbstub/gdb-xml/mips32-cp0.xml           |  9 +++
 gdbstub/gdb-xml/mips32-cpu.xml           | 42 ++++++++++++
 gdbstub/gdb-xml/mips32-fpu.xml           | 41 +++++++++++
 gdbstub/gdb-xml/mips64-cp0.xml           |  9 +++
 gdbstub/gdb-xml/mips64-cpu.xml           | 42 ++++++++++++
 gdbstub/gdb-xml/mips64-fpu.xml           | 41 +++++++++++
 20 files changed, 287 insertions(+)
 create mode 100644 gdbstub/gdb-xml/mips32-cp0.xml
 create mode 100644 gdbstub/gdb-xml/mips32-cpu.xml
 create mode 100644 gdbstub/gdb-xml/mips32-fpu.xml
 create mode 100644 gdbstub/gdb-xml/mips64-cp0.xml
 create mode 100644 gdbstub/gdb-xml/mips64-cpu.xml
 create mode 100644 gdbstub/gdb-xml/mips64-fpu.xml
MAINTAINERS +1 -0
index b36582c9d0b1..4269299b8ca3 100644
@@ -139,6 +139,7 @@ S: Odd Fixes
 K: ^Subject:.*(?i)mips
 F: docs/system/target-mips.rst
 F: configs/targets/mips*
+F: gdbstub/gdb-xml/mips*.xml
 F: tests/functional/mips*/meson.build
 
 X86 general architecture support
configs/targets/mips-linux-user.mak +1 -0
index 69bdc459b69a..0ee6a2722822 100644
@@ -4,3 +4,4 @@ TARGET_SYSTBL_ABI=o32
 TARGET_SYSTBL=syscall_o32.tbl
 TARGET_BIG_ENDIAN=y
 TARGET_LONG_BITS=32
+TARGET_XML_FILES= mips32-cpu.xml mips32-cp0.xml mips32-fpu.xml
configs/targets/mips-softmmu.mak +1 -0
index 95397af9442e..156310f94069 100644
@@ -2,3 +2,4 @@ TARGET_ARCH=mips
 TARGET_BIG_ENDIAN=y
 TARGET_LONG_BITS=32
 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
+TARGET_XML_FILES= mips32-cpu.xml mips32-cp0.xml mips32-fpu.xml
configs/targets/mips64-linux-user.mak +1 -0
index 04e82b3ab11d..52c3ae8dff32 100644
@@ -5,3 +5,4 @@ TARGET_SYSTBL_ABI=n64
 TARGET_SYSTBL=syscall_n64.tbl
 TARGET_BIG_ENDIAN=y
 TARGET_LONG_BITS=64
+TARGET_XML_FILES= mips64-cpu.xml mips64-cp0.xml mips64-fpu.xml
configs/targets/mips64-softmmu.mak +1 -0
index f9cc41b9ed43..03db5ef74abc 100644
@@ -3,3 +3,4 @@ TARGET_BASE_ARCH=mips
 TARGET_BIG_ENDIAN=y
 TARGET_LONG_BITS=64
 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
+TARGET_XML_FILES= mips64-cpu.xml mips64-cp0.xml mips64-fpu.xml
configs/targets/mips64el-linux-user.mak +1 -0
index 27f416942654..0600e05a877b 100644
@@ -4,3 +4,4 @@ TARGET_BASE_ARCH=mips
 TARGET_SYSTBL_ABI=n64
 TARGET_SYSTBL=syscall_n64.tbl
 TARGET_LONG_BITS=64
+TARGET_XML_FILES= mips64-cpu.xml mips64-cp0.xml mips64-fpu.xml
configs/targets/mips64el-softmmu.mak +1 -0
index 4e7dedc5f30d..b3433d8cf7ab 100644
@@ -2,3 +2,4 @@ TARGET_ARCH=mips64
 TARGET_BASE_ARCH=mips
 TARGET_LONG_BITS=64
 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
+TARGET_XML_FILES= mips64-cpu.xml mips64-cp0.xml mips64-fpu.xml
configs/targets/mipsel-linux-user.mak +1 -0
index 8b7e86ab2880..7fd2e2e6f791 100644
@@ -3,3 +3,4 @@ TARGET_ABI_MIPSO32=y
 TARGET_SYSTBL_ABI=o32
 TARGET_SYSTBL=syscall_o32.tbl
 TARGET_LONG_BITS=32
+TARGET_XML_FILES= mips32-cpu.xml mips32-cp0.xml mips32-fpu.xml
configs/targets/mipsel-softmmu.mak +1 -0
index b0fba8a9d0ad..c36b65918026 100644
@@ -1,3 +1,4 @@
 TARGET_ARCH=mips
 TARGET_LONG_BITS=32
 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
+TARGET_XML_FILES= mips32-cpu.xml mips32-cp0.xml mips32-fpu.xml
configs/targets/mipsn32-linux-user.mak +1 -0
index 39ae214633f1..ec1af1d969ed 100644
@@ -6,3 +6,4 @@ TARGET_SYSTBL_ABI=n32
 TARGET_SYSTBL=syscall_n32.tbl
 TARGET_BIG_ENDIAN=y
 TARGET_LONG_BITS=64
+TARGET_XML_FILES= mips64-cpu.xml mips64-cp0.xml mips64-fpu.xml
configs/targets/mipsn32el-linux-user.mak +1 -0
index d9b61d699025..3c74de867e45 100644
@@ -5,3 +5,4 @@ TARGET_BASE_ARCH=mips
 TARGET_SYSTBL_ABI=n32
 TARGET_SYSTBL=syscall_n32.tbl
 TARGET_LONG_BITS=64
+TARGET_XML_FILES= mips64-cpu.xml mips64-cp0.xml mips64-fpu.xml
target/mips/internal.h +2 -0
index d4a4fdad9128..1ca41b1e5284 100644
@@ -93,6 +93,8 @@ extern const int mips_defs_number;
 
 int mips_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
 int mips_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
+void mips_cpu_gdb_class_init_xml(CPUClass *cc);
+void mips_cpu_register_gdb_regs(CPUState *cs);
 QTree *mips_octeon_llm_tree_new(void);
 uint64_t mips_octeon_llm_load(QTree *tree, uint64_t addr);
 void mips_octeon_llm_store(QTree **treep, uint64_t addr, uint64_t value);
target/mips/cpu.c +4 -0
index 8ad5e49ade41..443b6d62b86f 100644
@@ -604,6 +604,8 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp)
         return;
     }
 
+    mips_cpu_register_gdb_regs(cs);
+
     env->exception_base = (int32_t)0xBFC00000;
 
 #if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
@@ -777,6 +779,8 @@ static void mips_cpu_cpudef_class_init(ObjectClass *oc, const void *data)
 {
     MIPSCPUClass *mcc = MIPS_CPU_CLASS(oc);
     mcc->cpu_def = data;
+
+    mips_cpu_gdb_class_init_xml(CPU_CLASS(oc));
 }
 
 static void mips_register_cpudef_type(const struct mips_def_t *def)
target/mips/gdbstub.c +86 -0

95 lines not on this page · raw message

gdbstub/gdb-xml/mips32-cp0.xml new file +9 -0
new file mode 100644
index 000000000000..eb15f00eee31
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<!-- SPDX-License-Identifier: GPL-2.0-or-later -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.mips.cp0">
+  <reg name="status" bitsize="32"/>
+  <reg name="badvaddr" bitsize="32"/>
+  <reg name="cause" bitsize="32"/>
+</feature>
gdbstub/gdb-xml/mips32-cpu.xml new file +42 -0

42 lines not on this page · raw message

gdbstub/gdb-xml/mips32-fpu.xml new file +41 -0

41 lines not on this page · raw message

gdbstub/gdb-xml/mips64-cp0.xml new file +9 -0
new file mode 100644
index 000000000000..a48c894e8362
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<!-- SPDX-License-Identifier: GPL-2.0-or-later -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.mips.cp0">
+  <reg name="status" bitsize="64"/>
+  <reg name="badvaddr" bitsize="64"/>
+  <reg name="cause" bitsize="64"/>
+</feature>
gdbstub/gdb-xml/mips64-cpu.xml new file +42 -0

42 lines not on this page · raw message

gdbstub/gdb-xml/mips64-fpu.xml new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.55.0
Reviewed-by on v2 7/9
#21 lore raw

Re: [PATCH v2 7/9] target/mips: Describe gdbstub registers with XML features

Quoted 30 lines · Philippe Mathieu-Daudé

MIPS has no XML target description, so extra features can not be registered. Expose the cpu, cp0 and fpu registers as the GDB standard features, mapped to the legacy register numbers.

Registers are sized by the target long size (mips32-*.xml or mips64-*.xml) instead of the CPU: a 32-bit CPU on a 64-bit target now reports 64-bit registers. FPU registers are single-precision on 32-bit targets.

---
 MAINTAINERS                              |  1 +
 configs/targets/mips-linux-user.mak      |  1 +
 configs/targets/mips-softmmu.mak         |  1 +
 configs/targets/mips64-linux-user.mak    |  1 +
 configs/targets/mips64-softmmu.mak       |  1 +
 configs/targets/mips64el-linux-user.mak  |  1 +
 configs/targets/mips64el-softmmu.mak     |  1 +
 configs/targets/mipsel-linux-user.mak    |  1 +
 configs/targets/mipsel-softmmu.mak       |  1 +
 configs/targets/mipsn32-linux-user.mak   |  1 +
 configs/targets/mipsn32el-linux-user.mak |  1 +
 target/mips/internal.h                   |  2 +
 target/mips/cpu.c                        |  4 ++
 target/mips/gdbstub.c                    | 86 ++++++++++++++++++++++++
 gdbstub/gdb-xml/mips32-cp0.xml           |  9 +++
 gdbstub/gdb-xml/mips32-cpu.xml           | 42 ++++++++++++
 gdbstub/gdb-xml/mips32-fpu.xml           | 41 +++++++++++
 gdbstub/gdb-xml/mips64-cp0.xml           |  9 +++
 gdbstub/gdb-xml/mips64-cpu.xml           | 42 ++++++++++++
Quoted 9 lines
 gdbstub/gdb-xml/mips64-fpu.xml           | 41 +++++++++++
 20 files changed, 287 insertions(+)
 create mode 100644 gdbstub/gdb-xml/mips32-cp0.xml
 create mode 100644 gdbstub/gdb-xml/mips32-cpu.xml
 create mode 100644 gdbstub/gdb-xml/mips32-fpu.xml
 create mode 100644 gdbstub/gdb-xml/mips64-cp0.xml
 create mode 100644 gdbstub/gdb-xml/mips64-cpu.xml
 create mode 100644 gdbstub/gdb-xml/mips64-fpu.xml
#22 lore raw

PATCH v2 8/9 target/mips: Expose R5900 registers to gdb

In reply to Philippe Mathieu-Daudé

GDB has no knowledge of the R5900 LO1/HI1 registers and of the upper halves of its 128-bit GPRs. Add a org.qemu.gdb.mips.r5900 feature with lo1, hi1 and r0_hi..r31_hi, transferred as 64-bit.

Unfortunately we need to gate on TARGET_MIPS64 because the gpr_hi[] upper halves are only declared there.

---
 configs/targets/mips64-softmmu.mak   |  2 +-
 configs/targets/mips64el-softmmu.mak |  2 +-
 target/mips/gdbstub.c                | 46 +++++++++++++++++++++++++++
 gdbstub/gdb-xml/mips64-r5900.xml     | 47 ++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+), 2 deletions(-)
 create mode 100644 gdbstub/gdb-xml/mips64-r5900.xml
configs/targets/mips64-softmmu.mak +1 -1
index 03db5ef74abc..b96e91559c9a 100644
@@ -3,4 +3,4 @@ TARGET_BASE_ARCH=mips
 TARGET_BIG_ENDIAN=y
 TARGET_LONG_BITS=64
 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
-TARGET_XML_FILES= mips64-cpu.xml mips64-cp0.xml mips64-fpu.xml
+TARGET_XML_FILES= mips64-cpu.xml mips64-cp0.xml mips64-fpu.xml mips64-r5900.xml
configs/targets/mips64el-softmmu.mak +1 -1
index b3433d8cf7ab..089f2c0c7c43 100644
@@ -2,4 +2,4 @@ TARGET_ARCH=mips64
 TARGET_BASE_ARCH=mips
 TARGET_LONG_BITS=64
 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
-TARGET_XML_FILES= mips64-cpu.xml mips64-cp0.xml mips64-fpu.xml
+TARGET_XML_FILES= mips64-cpu.xml mips64-cp0.xml mips64-fpu.xml mips64-r5900.xml
target/mips/gdbstub.c +46 -0

56 lines not on this page · raw message

gdbstub/gdb-xml/mips64-r5900.xml new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.55.0
Reviewed-by on v2 8/9
#23 lore raw

Re: [PATCH v2 8/9] target/mips: Expose R5900 registers to gdb

Quoted 10 lines · Philippe Mathieu-Daudé

GDB has no knowledge of the R5900 LO1/HI1 registers and of the upper halves of its 128-bit GPRs. Add a org.qemu.gdb.mips.r5900 feature with lo1, hi1 and r0_hi..r31_hi, transferred as 64-bit.

Unfortunately we need to gate on TARGET_MIPS64 because the gpr_hi[] upper halves are only declared there.

Quoted 8 lines
---
 configs/targets/mips64-softmmu.mak   |  2 +-
 configs/targets/mips64el-softmmu.mak |  2 +-
 target/mips/gdbstub.c                | 46 +++++++++++++++++++++++++++
 gdbstub/gdb-xml/mips64-r5900.xml     | 47 ++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+), 2 deletions(-)
 create mode 100644 gdbstub/gdb-xml/mips64-r5900.xml
#24 lore raw

PATCH v2 9/9 tests/tcg/mips64el: Add a TX79 instruction test in system mode

In reply to Philippe Mathieu-Daudé

Exercise the instructions decoded by tx79.decode (parallel arithmetic/compare/logic/extend, PCPYH, PROT3W, HI1/LO1 moves, LQ/SQ). The instruction words are emitted directly, as the assembler does not know the TX79 mnemonics.

Build it with the n32 ABI, to move 64-bit values to HI1/LO1.

AI-used-for: tests

---
 tests/tcg/mips64el/system/test_r5900_tx79.c | 477 ++++++++++++++++++++
 tests/tcg/mips64el/system/meson.build       |   9 +
 2 files changed, 486 insertions(+)
 create mode 100644 tests/tcg/mips64el/system/test_r5900_tx79.c
tests/tcg/mips64el/system/test_r5900_tx79.c new file +477 -0
new file mode 100644
index 000000000000..64b9b53b9440
@@ -0,0 +1,477 @@
+/*
+ * Test the TX79 instructions decoded by target/mips/tcg/tx79.decode.
+ *
+ * The instruction words are emitted directly because the normal MIPS64
+ * assembler does not know the TX79 mnemonics.  LQ and SQ are used to move
+ * values into and out of the emulated 128-bit GPRs.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+typedef struct {
+    uint64_t lo;
+    uint64_t hi;
+} __attribute__((aligned(16))) tx79_qword;
+
+#define TX79_STR1(x) #x
+#define TX79_STR(x) TX79_STR1(x)
+
+#define TX79_R(rs, rt, rd, sub, func) \
+    ((0x1cU << 26) | ((rs) << 21) | ((rt) << 16) | ((rd) << 11) | \
+     ((sub) << 6) | (func))
+#define TX79_LDST(op, base, rt, offset) \
+    (((op) << 26) | ((base) << 21) | ((rt) << 16) | ((offset) & 0xffffU))
+
+#define TX79_BINOP_WORD(INSN, A, B)                                      \
+    ({                                                                   \
+        tx79_qword _result;                                              \
+        asm volatile(                                                     \
+            "move $7, %[a]\n"                                           \
+            ".word " TX79_STR(TX79_LDST(0x1e, 7, 8, 0)) "\n"           \
+            "move $7, %[b]\n"                                           \
+            ".word " TX79_STR(TX79_LDST(0x1e, 7, 9, 0)) "\n"           \
+            "move $7, %[a]\n"                                           \
+            ".word " TX79_STR(TX79_LDST(0x1e, 7, 10, 0)) "\n"          \
+            ".word " TX79_STR(INSN) "\n"                                \
+            "move $7, %[result]\n"                                      \
+            ".word " TX79_STR(TX79_LDST(0x1f, 7, 10, 0)) "\n"          \
+            :                                                             \
+            : [a] "r" (A), [b] "r" (B), [result] "r" (&_result)        \
+            : "$7", "$8", "$9", "$10", "memory");                    \
+        _result;                                                          \
+    })
+
+#define TX79_UNARY_WORD(INSN, A)                                         \
+    ({                                                                   \
+        tx79_qword _result;                                              \
+        asm volatile(                                                     \
+            "move $7, %[a]\n"                                           \
+            ".word " TX79_STR(TX79_LDST(0x1e, 7, 8, 0)) "\n"           \
+            ".word " TX79_STR(INSN) "\n"                                \
+            "move $7, %[result]\n"                                      \
+            ".word " TX79_STR(TX79_LDST(0x1f, 7, 10, 0)) "\n"          \
+            :                                                             \
+            : [a] "r" (A), [result] "r" (&_result)                      \
+            : "$7", "$8", "$10", "memory");                            \
+        _result;                                                          \
+    })
+
+#define TX79_LQ_OFFSET(OFFSET, BASE)                                     \
+    ({                                                                   \
+        tx79_qword _result;                                              \
+        asm volatile(                                                     \
+            "move $7, %[base]\n"                                        \
+            ".word " TX79_STR(TX79_LDST(0x1e, 7, 8, OFFSET)) "\n"      \
+            "move $7, %[result]\n"                                      \
+            ".word " TX79_STR(TX79_LDST(0x1f, 7, 8, 0)) "\n"           \
+            :                                                             \
+            : [base] "r" (BASE), [result] "r" (&_result)                \
+            : "$7", "$8", "memory");                                   \
+        _result;                                                          \
+    })
+
+#define TX79_SQ_OFFSET(OFFSET, VALUE, BASE)                               \
+    do {                                                                   \
+        asm volatile(                                                       \
+            "move $7, %[value]\n"                                        \
+            ".word " TX79_STR(TX79_LDST(0x1e, 7, 8, 0)) "\n"            \
+            "move $7, %[base]\n"                                         \
+            ".word " TX79_STR(TX79_LDST(0x1f, 7, 8, OFFSET)) "\n"        \
+            :                                                               \
+            : [value] "r" (VALUE), [base] "r" (BASE)                     \
+            : "$7", "$8", "memory");                                    \
+    } while (0)
+
+static int check_qword(const char *name, tx79_qword got, tx79_qword expected)
+{
+    if (got.lo == expected.lo && got.hi == expected.hi) {
+        return 0;
+    }
+
+    fprintf(stderr, "%s: got %016llx:%016llx expected %016llx:%016llx\n",
+            name, (unsigned long long)got.hi, (unsigned long long)got.lo,
+            (unsigned long long)expected.hi,
+            (unsigned long long)expected.lo);
+    return 1;
+}
+
+static uint64_t lane_mask(unsigned bits)
+{
+    return (1ULL << bits) - 1;
+}
+
+static int64_t sign_extend_lane(uint64_t value, unsigned bits)
+{
+    uint64_t sign = 1ULL << (bits - 1);
+
+    value &= lane_mask(bits);
+    return (int64_t)((value ^ sign) - sign);
+}
+
+static tx79_qword ref_sub(tx79_qword a, tx79_qword b, unsigned bits)
+{
+    tx79_qword result = { 0, 0 };
+    uint64_t mask = lane_mask(bits);
+
+    for (unsigned half = 0; half < 2; half++) {
+        uint64_t av = half ? a.hi : a.lo;
+        uint64_t bv = half ? b.hi : b.lo;
+        uint64_t *dst = half ? &result.hi : &result.lo;
+
+        for (unsigned lane = 0; lane < 64 / bits; lane++) {
+            uint64_t shift = lane * bits;
+            *dst |= (((av >> shift) - (bv >> shift)) & mask) << shift;
+        }
+    }
+
+    return result;
+}
+
+static tx79_qword ref_compare(tx79_qword a, tx79_qword b, unsigned bits,
+                              int equal)
+{
+    tx79_qword result = { 0, 0 };
+    uint64_t mask = lane_mask(bits);
+
+    for (unsigned half = 0; half < 2; half++) {
+        uint64_t av = half ? a.hi : a.lo;
+        uint64_t bv = half ? b.hi : b.lo;
+        uint64_t *dst = half ? &result.hi : &result.lo;
+
+        for (unsigned lane = 0; lane < 64 / bits; lane++) {
+            uint64_t shift = lane * bits;
+            int64_t as = sign_extend_lane(av >> shift, bits);
+            int64_t bs = sign_extend_lane(bv >> shift, bits);
+            int match = equal ? as == bs : as > bs;
+
+            if (match) {
+                *dst |= mask << shift;
+            }
+        }
+    }
+
+    return result;
+}
+
+static tx79_qword ref_pext(tx79_qword a, tx79_qword b, unsigned bits,
+                           int upper)
+{
+    tx79_qword result = { 0, 0 };
+    uint64_t av = upper ? a.hi : a.lo;
+    uint64_t bv = upper ? b.hi : b.lo;
+
+    for (unsigned lane = 0; lane < 64 / (2 * bits); lane++) {
+        uint64_t shift = lane * bits;
+        uint64_t dst_shift = lane * 2 * bits;
+        uint64_t mask = lane_mask(bits);
+
+        result.lo |= ((bv >> shift) & mask) << dst_shift;
+        result.lo |= ((av >> shift) & mask) << (dst_shift + bits);
+        result.hi |= ((bv >> (shift + 32)) & mask) << dst_shift;
+        result.hi |= ((av >> (shift + 32)) & mask) << (dst_shift + bits);
+    }
+
+    return result;
+}
+
+static tx79_qword ref_logic(tx79_qword a, tx79_qword b, char op)
+{
+    tx79_qword result;
+
+    switch (op) {
+    case '&':
+        result.lo = a.lo & b.lo;
+        result.hi = a.hi & b.hi;
+        break;
+    case '|':
+        result.lo = a.lo | b.lo;
+        result.hi = a.hi | b.hi;
+        break;
+    case '^':
+        result.lo = a.lo ^ b.lo;
+        result.hi = a.hi ^ b.hi;
+        break;
+    default:
+        result.lo = ~(a.lo | b.lo);
+        result.hi = ~(a.hi | b.hi);
+        break;
+    }
+
+    return result;
+}
+
+static tx79_qword ref_pcpyh(tx79_qword a)
+{
+    uint64_t lo = a.lo & 0xffff;
+    uint64_t hi = a.hi & 0xffff;
+    tx79_qword result = {
+        lo * 0x0001000100010001ULL,
+        hi * 0x0001000100010001ULL,
+    };
+
+    return result;
+}
+
+static tx79_qword ref_prot3w(tx79_qword a)
+{
+    tx79_qword result = {
+        (a.lo >> 32) | ((a.hi & 0xffffffff) << 32),
+        (a.lo & 0xffffffff) | (a.hi & 0xffffffff00000000ULL),
+    };
+
+    return result;
+}
+
+static void tx79_set_hilo1(uint64_t hi, uint64_t lo)
+{
+    asm volatile(
+        "move $8, %[lo]\n"
+        ".word " TX79_STR(TX79_R(8, 0, 0, 0, 0x13)) "\n"
+        "move $8, %[hi]\n"
+        ".word " TX79_STR(TX79_R(8, 0, 0, 0, 0x11)) "\n"
+        :
+        : [lo] "r" (lo), [hi] "r" (hi)
+        : "$8");
+}
+
+static tx79_qword tx79_get_hilo1(void)
+{
+    tx79_qword result;
+
+    asm volatile(
+        ".word " TX79_STR(TX79_R(0, 0, 8, 0, 0x12)) "\n"
+        "move %[lo], $8\n"
+        ".word " TX79_STR(TX79_R(0, 0, 8, 0, 0x10)) "\n"
+        "move %[hi], $8\n"
+        : [lo] "=r" (result.lo), [hi] "=r" (result.hi)
+        :
+        : "$8");
+
+    return result;
+}
+
+static int test_hilo1(void)
+{
+    const uint64_t hi = 0x8899aabbccddeeffULL;
+    const uint64_t lo = 0x0011223344556677ULL;
+    tx79_qword got;
+
+    tx79_set_hilo1(hi, lo);
+    got = tx79_get_hilo1();
+    if (got.lo != lo || got.hi != hi) {
+        fprintf(stderr, "HI1/LO1 move instructions failed\n");
+        return 1;
+    }
+
+    return 0;
+}
+
+static int test_parallel(void)
+{
+    const tx79_qword a = {
+        0x800000007fffffffULL,
+        0xff0080007fff8000ULL,
+    };
+    const tx79_qword b = {
+        0x00000000ffffffffULL,
+        0x01008000ffff0001ULL,
+    };
+    tx79_qword got;
+
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 9, 8), &a, &b);
+    if (check_qword("PSUBB", got, ref_sub(a, b, 8))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 5, 8), &a, &b);
+    if (check_qword("PSUBH", got, ref_sub(a, b, 16))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 1, 8), &a, &b);
+    if (check_qword("PSUBW", got, ref_sub(a, b, 32))) {
+        return 1;
+    }
+
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 2, 8), &a, &b);
+    if (check_qword("PCGTW", got, ref_compare(a, b, 32, 0))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 6, 8), &a, &b);
+    if (check_qword("PCGTH", got, ref_compare(a, b, 16, 0))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 10, 8), &a, &b);
+    if (check_qword("PCGTB", got, ref_compare(a, b, 8, 0))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 2, 40), &a, &b);
+    if (check_qword("PCEQW", got, ref_compare(a, b, 32, 1))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 6, 40), &a, &b);
+    if (check_qword("PCEQH", got, ref_compare(a, b, 16, 1))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 10, 40), &a, &b);
+    if (check_qword("PCEQB", got, ref_compare(a, b, 8, 1))) {
+        return 1;
+    }
+
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 18, 8), &a, &b);
+    if (check_qword("PEXTLW", got, ref_pext(a, b, 32, 0))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 22, 8), &a, &b);
+    if (check_qword("PEXTLH", got, ref_pext(a, b, 16, 0))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 26, 8), &a, &b);
+    if (check_qword("PEXTLB", got, ref_pext(a, b, 8, 0))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 18, 40), &a, &b);
+    if (check_qword("PEXTUW", got, ref_pext(a, b, 32, 1))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 19, 8), &a, &b);
+    if (check_qword("PPACW", got, (tx79_qword) {
+            (uint32_t)b.lo | ((uint64_t)(uint32_t)b.hi << 32),
+            (uint32_t)a.lo | ((uint64_t)(uint32_t)a.hi << 32),
+        })) {
+        return 1;
+    }
+
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 18, 9), &a, &b);
+    if (check_qword("PAND", got, ref_logic(a, b, '&'))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 19, 9), &a, &b);
+    if (check_qword("PXOR", got, ref_logic(a, b, '^'))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 18, 41), &a, &b);
+    if (check_qword("POR", got, ref_logic(a, b, '|'))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 19, 41), &a, &b);
+    if (check_qword("PNOR", got, ref_logic(a, b, 'n'))) {
+        return 1;
+    }
+
+    got = TX79_UNARY_WORD(TX79_R(0, 8, 10, 27, 41), &a);
+    if (check_qword("PCPYH", got, ref_pcpyh(a))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 14, 9), &a, &b);
+    if (check_qword("PCPYLD", got, (tx79_qword) { b.lo, a.lo })) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 14, 41), &a, &b);
+    if (check_qword("PCPYUD", got, (tx79_qword) { a.hi, b.hi })) {
+        return 1;
+    }
+    got = TX79_UNARY_WORD(TX79_R(0, 8, 10, 31, 9), &a);
+    if (check_qword("PROT3W", got, ref_prot3w(a))) {
+        return 1;
+    }
+
+    got = TX79_BINOP_WORD(TX79_R(0, 9, 10, 14, 9), &a, &b);
+    if (check_qword("PCPYLD rt-only", got, (tx79_qword) { b.lo, 0 })) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 0, 10, 14, 41), &a, &b);
+    if (check_qword("PCPYUD rs-only", got, (tx79_qword) { a.hi, 0 })) {
+        return 1;
+    }
+    got = TX79_UNARY_WORD(TX79_R(0, 0, 10, 27, 41), &a);
+    if (check_qword("PCPYH zero", got, (tx79_qword) { 0, 0 })) {
+        return 1;
+    }
+
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 0, 1, 8), &a, &b);
+    if (check_qword("rd zero", got, (tx79_qword) {
+            a.lo, a.hi,
+        })) {
+        return 1;
+    }
+
+    return 0;
+}
+
+static int test_quadword_memory(void)
+{
+    static uint8_t memory[65536 + 64] __attribute__((aligned(16)));
+    static const int offsets[] = { -32768, -1, 0, 1, 32767 };
+    const tx79_qword value = {
+        0x0123456789abcdefULL,
+        0xfedcba9876543210ULL,
+    };
+    uint8_t *base = memory + 32784;
+
+    for (unsigned i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
+        int offset = offsets[i];
+        uintptr_t address = (uintptr_t)base + (intptr_t)offset;
+        uint8_t *aligned = (uint8_t *)(address & ~(uintptr_t)0xf);
+        tx79_qword got;
+
+        memset(memory, 0, sizeof(memory));
+        memcpy(aligned, &value, sizeof(value));
+        switch (offset) {
+        case -32768:
+            got = TX79_LQ_OFFSET(-32768, base);
+            break;
+        case -1:
+            got = TX79_LQ_OFFSET(-1, base);
+            break;
+        case 0:
+            got = TX79_LQ_OFFSET(0, base);
+            break;
+        case 1:
+            got = TX79_LQ_OFFSET(1, base);
+            break;
+        default:
+            got = TX79_LQ_OFFSET(32767, base);
+            break;
+        }
+        if (check_qword("LQ offset", got, value)) {
+            return 1;
+        }
+
+        memset(memory, 0, sizeof(memory));
+        switch (offset) {
+        case -32768:
+            TX79_SQ_OFFSET(-32768, &value, base);
+            break;
+        case -1:
+            TX79_SQ_OFFSET(-1, &value, base);
+            break;
+        case 0:
+            TX79_SQ_OFFSET(0, &value, base);
+            break;
+        case 1:
+            TX79_SQ_OFFSET(1, &value, base);
+            break;
+        default:
+            TX79_SQ_OFFSET(32767, &value, base);
+            break;
+        }
+        if (memcmp(aligned, &value, sizeof(value)) != 0) {
+            fprintf(stderr, "SQ offset %d failed\n", offset);
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+int main(void)
+{
+    if (test_hilo1() || test_parallel() || test_quadword_memory()) {
+        return 1;
+    }
+
+    return 0;
+}
tests/tcg/mips64el/system/meson.build +9 -0
index fd5a759c20fa..66c3d61c3134 100644
@@ -39,6 +39,15 @@ foreach t: [
   }
 endforeach
 
+# n32: 32-bit pointers, 64-bit GPRs are needed to move 64-bit values to HI1/LO1
+tests += {
+  'test_r5900_tx79.c': {
+    'cflags': cflags + ['-mabi=n32'],
+    'qemu_args': qemu_args,
+    'gdb_test': gdb_test,
+  }
+}
+
 if 'qemu-system-mips64el' in emulators
   tcg_tests += {
     'mips64el-softmmu': {
Signature · 1 line
2.55.0
Reviewed-by on v2 9/9
#25 lore raw

Re: [PATCH v2 9/9] tests/tcg/mips64el: Add a TX79 instruction test in system mode

Quoted 508 lines · Philippe Mathieu-Daudé

Exercise the instructions decoded by tx79.decode (parallel arithmetic/compare/logic/extend, PCPYH, PROT3W, HI1/LO1 moves, LQ/SQ). The instruction words are emitted directly, as the assembler does not know the TX79 mnemonics.

Build it with the n32 ABI, to move 64-bit values to HI1/LO1.

AI-used-for: tests

---
 tests/tcg/mips64el/system/test_r5900_tx79.c | 477 ++++++++++++++++++++
 tests/tcg/mips64el/system/meson.build       |   9 +
 2 files changed, 486 insertions(+)
 create mode 100644 tests/tcg/mips64el/system/test_r5900_tx79.c
tests/tcg/mips64el/system/test_r5900_tx79.c new file +477 -0
new file mode 100644
index 000000000000..64b9b53b9440
@@ -0,0 +1,477 @@
+/*
+ * Test the TX79 instructions decoded by target/mips/tcg/tx79.decode.
+ *
+ * The instruction words are emitted directly because the normal MIPS64
+ * assembler does not know the TX79 mnemonics.  LQ and SQ are used to move
+ * values into and out of the emulated 128-bit GPRs.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+typedef struct {
+    uint64_t lo;
+    uint64_t hi;
+} __attribute__((aligned(16))) tx79_qword;
+
+#define TX79_STR1(x) #x
+#define TX79_STR(x) TX79_STR1(x)
+
+#define TX79_R(rs, rt, rd, sub, func) \
+    ((0x1cU << 26) | ((rs) << 21) | ((rt) << 16) | ((rd) << 11) | \
+     ((sub) << 6) | (func))
+#define TX79_LDST(op, base, rt, offset) \
+    (((op) << 26) | ((base) << 21) | ((rt) << 16) | ((offset) & 0xffffU))
+
+#define TX79_BINOP_WORD(INSN, A, B)                                      \
+    ({                                                                   \
+        tx79_qword _result;                                              \
+        asm volatile(                                                     \
+            "move $7, %[a]\n"                                           \
+            ".word " TX79_STR(TX79_LDST(0x1e, 7, 8, 0)) "\n"           \
+            "move $7, %[b]\n"                                           \
+            ".word " TX79_STR(TX79_LDST(0x1e, 7, 9, 0)) "\n"           \
+            "move $7, %[a]\n"                                           \
+            ".word " TX79_STR(TX79_LDST(0x1e, 7, 10, 0)) "\n"          \
+            ".word " TX79_STR(INSN) "\n"                                \
+            "move $7, %[result]\n"                                      \
+            ".word " TX79_STR(TX79_LDST(0x1f, 7, 10, 0)) "\n"          \
+            :                                                             \
+            : [a] "r" (A), [b] "r" (B), [result] "r" (&_result)        \
+            : "$7", "$8", "$9", "$10", "memory");                    \
+        _result;                                                          \
+    })
+
+#define TX79_UNARY_WORD(INSN, A)                                         \
+    ({                                                                   \
+        tx79_qword _result;                                              \
+        asm volatile(                                                     \
+            "move $7, %[a]\n"                                           \
+            ".word " TX79_STR(TX79_LDST(0x1e, 7, 8, 0)) "\n"           \
+            ".word " TX79_STR(INSN) "\n"                                \
+            "move $7, %[result]\n"                                      \
+            ".word " TX79_STR(TX79_LDST(0x1f, 7, 10, 0)) "\n"          \
+            :                                                             \
+            : [a] "r" (A), [result] "r" (&_result)                      \
+            : "$7", "$8", "$10", "memory");                            \
+        _result;                                                          \
+    })
+
+#define TX79_LQ_OFFSET(OFFSET, BASE)                                     \
+    ({                                                                   \
+        tx79_qword _result;                                              \
+        asm volatile(                                                     \
+            "move $7, %[base]\n"                                        \
+            ".word " TX79_STR(TX79_LDST(0x1e, 7, 8, OFFSET)) "\n"      \
+            "move $7, %[result]\n"                                      \
+            ".word " TX79_STR(TX79_LDST(0x1f, 7, 8, 0)) "\n"           \
+            :                                                             \
+            : [base] "r" (BASE), [result] "r" (&_result)                \
+            : "$7", "$8", "memory");                                   \
+        _result;                                                          \
+    })
+
+#define TX79_SQ_OFFSET(OFFSET, VALUE, BASE)                               \
+    do {                                                                   \
+        asm volatile(                                                       \
+            "move $7, %[value]\n"                                        \
+            ".word " TX79_STR(TX79_LDST(0x1e, 7, 8, 0)) "\n"            \
+            "move $7, %[base]\n"                                         \
+            ".word " TX79_STR(TX79_LDST(0x1f, 7, 8, OFFSET)) "\n"        \
+            :                                                               \
+            : [value] "r" (VALUE), [base] "r" (BASE)                     \
+            : "$7", "$8", "memory");                                    \
+    } while (0)
+
+static int check_qword(const char *name, tx79_qword got, tx79_qword expected)
+{
+    if (got.lo == expected.lo && got.hi == expected.hi) {
+        return 0;
+    }
+
+    fprintf(stderr, "%s: got %016llx:%016llx expected %016llx:%016llx\n",
+            name, (unsigned long long)got.hi, (unsigned long long)got.lo,
+            (unsigned long long)expected.hi,
+            (unsigned long long)expected.lo);
+    return 1;
+}
+
+static uint64_t lane_mask(unsigned bits)
+{
+    return (1ULL << bits) - 1;
+}
+
+static int64_t sign_extend_lane(uint64_t value, unsigned bits)
+{
+    uint64_t sign = 1ULL << (bits - 1);
+
+    value &= lane_mask(bits);
+    return (int64_t)((value ^ sign) - sign);
+}
+
+static tx79_qword ref_sub(tx79_qword a, tx79_qword b, unsigned bits)
+{
+    tx79_qword result = { 0, 0 };
+    uint64_t mask = lane_mask(bits);
+
+    for (unsigned half = 0; half < 2; half++) {
+        uint64_t av = half ? a.hi : a.lo;
+        uint64_t bv = half ? b.hi : b.lo;
+        uint64_t *dst = half ? &result.hi : &result.lo;
+
+        for (unsigned lane = 0; lane < 64 / bits; lane++) {
+            uint64_t shift = lane * bits;
+            *dst |= (((av >> shift) - (bv >> shift)) & mask) << shift;
+        }
+    }
+
+    return result;
+}
+
+static tx79_qword ref_compare(tx79_qword a, tx79_qword b, unsigned bits,
+                              int equal)
+{
+    tx79_qword result = { 0, 0 };
+    uint64_t mask = lane_mask(bits);
+
+    for (unsigned half = 0; half < 2; half++) {
+        uint64_t av = half ? a.hi : a.lo;
+        uint64_t bv = half ? b.hi : b.lo;
+        uint64_t *dst = half ? &result.hi : &result.lo;
+
+        for (unsigned lane = 0; lane < 64 / bits; lane++) {
+            uint64_t shift = lane * bits;
+            int64_t as = sign_extend_lane(av >> shift, bits);
+            int64_t bs = sign_extend_lane(bv >> shift, bits);
+            int match = equal ? as == bs : as > bs;
+
+            if (match) {
+                *dst |= mask << shift;
+            }
+        }
+    }
+
+    return result;
+}
+
+static tx79_qword ref_pext(tx79_qword a, tx79_qword b, unsigned bits,
+                           int upper)
+{
+    tx79_qword result = { 0, 0 };
+    uint64_t av = upper ? a.hi : a.lo;
+    uint64_t bv = upper ? b.hi : b.lo;
+
+    for (unsigned lane = 0; lane < 64 / (2 * bits); lane++) {
+        uint64_t shift = lane * bits;
+        uint64_t dst_shift = lane * 2 * bits;
+        uint64_t mask = lane_mask(bits);
+
+        result.lo |= ((bv >> shift) & mask) << dst_shift;
+        result.lo |= ((av >> shift) & mask) << (dst_shift + bits);
+        result.hi |= ((bv >> (shift + 32)) & mask) << dst_shift;
+        result.hi |= ((av >> (shift + 32)) & mask) << (dst_shift + bits);
+    }
+
+    return result;
+}
+
+static tx79_qword ref_logic(tx79_qword a, tx79_qword b, char op)
+{
+    tx79_qword result;
+
+    switch (op) {
+    case '&':
+        result.lo = a.lo & b.lo;
+        result.hi = a.hi & b.hi;
+        break;
+    case '|':
+        result.lo = a.lo | b.lo;
+        result.hi = a.hi | b.hi;
+        break;
+    case '^':
+        result.lo = a.lo ^ b.lo;
+        result.hi = a.hi ^ b.hi;
+        break;
+    default:
+        result.lo = ~(a.lo | b.lo);
+        result.hi = ~(a.hi | b.hi);
+        break;
+    }
+
+    return result;
+}
+
+static tx79_qword ref_pcpyh(tx79_qword a)
+{
+    uint64_t lo = a.lo & 0xffff;
+    uint64_t hi = a.hi & 0xffff;
+    tx79_qword result = {
+        lo * 0x0001000100010001ULL,
+        hi * 0x0001000100010001ULL,
+    };
+
+    return result;
+}
+
+static tx79_qword ref_prot3w(tx79_qword a)
+{
+    tx79_qword result = {
+        (a.lo >> 32) | ((a.hi & 0xffffffff) << 32),
+        (a.lo & 0xffffffff) | (a.hi & 0xffffffff00000000ULL),
+    };
+
+    return result;
+}
+
+static void tx79_set_hilo1(uint64_t hi, uint64_t lo)
+{
+    asm volatile(
+        "move $8, %[lo]\n"
+        ".word " TX79_STR(TX79_R(8, 0, 0, 0, 0x13)) "\n"
+        "move $8, %[hi]\n"
+        ".word " TX79_STR(TX79_R(8, 0, 0, 0, 0x11)) "\n"
+        :
+        : [lo] "r" (lo), [hi] "r" (hi)
+        : "$8");
+}
+
+static tx79_qword tx79_get_hilo1(void)
+{
+    tx79_qword result;
+
+    asm volatile(
+        ".word " TX79_STR(TX79_R(0, 0, 8, 0, 0x12)) "\n"
+        "move %[lo], $8\n"
+        ".word " TX79_STR(TX79_R(0, 0, 8, 0, 0x10)) "\n"
+        "move %[hi], $8\n"
+        : [lo] "=r" (result.lo), [hi] "=r" (result.hi)
+        :
+        : "$8");
+
+    return result;
+}
+
+static int test_hilo1(void)
+{
+    const uint64_t hi = 0x8899aabbccddeeffULL;
+    const uint64_t lo = 0x0011223344556677ULL;
+    tx79_qword got;
+
+    tx79_set_hilo1(hi, lo);
+    got = tx79_get_hilo1();
+    if (got.lo != lo || got.hi != hi) {
+        fprintf(stderr, "HI1/LO1 move instructions failed\n");
+        return 1;
+    }
+
+    return 0;
+}
+
+static int test_parallel(void)
+{
+    const tx79_qword a = {
+        0x800000007fffffffULL,
+        0xff0080007fff8000ULL,
+    };
+    const tx79_qword b = {
+        0x00000000ffffffffULL,
+        0x01008000ffff0001ULL,
+    };
+    tx79_qword got;
+
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 9, 8), &a, &b);
+    if (check_qword("PSUBB", got, ref_sub(a, b, 8))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 5, 8), &a, &b);
+    if (check_qword("PSUBH", got, ref_sub(a, b, 16))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 1, 8), &a, &b);
+    if (check_qword("PSUBW", got, ref_sub(a, b, 32))) {
+        return 1;
+    }
+
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 2, 8), &a, &b);
+    if (check_qword("PCGTW", got, ref_compare(a, b, 32, 0))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 6, 8), &a, &b);
+    if (check_qword("PCGTH", got, ref_compare(a, b, 16, 0))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 10, 8), &a, &b);
+    if (check_qword("PCGTB", got, ref_compare(a, b, 8, 0))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 2, 40), &a, &b);
+    if (check_qword("PCEQW", got, ref_compare(a, b, 32, 1))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 6, 40), &a, &b);
+    if (check_qword("PCEQH", got, ref_compare(a, b, 16, 1))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 10, 40), &a, &b);
+    if (check_qword("PCEQB", got, ref_compare(a, b, 8, 1))) {
+        return 1;
+    }
+
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 18, 8), &a, &b);
+    if (check_qword("PEXTLW", got, ref_pext(a, b, 32, 0))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 22, 8), &a, &b);
+    if (check_qword("PEXTLH", got, ref_pext(a, b, 16, 0))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 26, 8), &a, &b);
+    if (check_qword("PEXTLB", got, ref_pext(a, b, 8, 0))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 18, 40), &a, &b);
+    if (check_qword("PEXTUW", got, ref_pext(a, b, 32, 1))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 19, 8), &a, &b);
+    if (check_qword("PPACW", got, (tx79_qword) {
+            (uint32_t)b.lo | ((uint64_t)(uint32_t)b.hi << 32),
+            (uint32_t)a.lo | ((uint64_t)(uint32_t)a.hi << 32),
+        })) {
+        return 1;
+    }
+
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 18, 9), &a, &b);
+    if (check_qword("PAND", got, ref_logic(a, b, '&'))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 19, 9), &a, &b);
+    if (check_qword("PXOR", got, ref_logic(a, b, '^'))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 18, 41), &a, &b);
+    if (check_qword("POR", got, ref_logic(a, b, '|'))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 19, 41), &a, &b);
+    if (check_qword("PNOR", got, ref_logic(a, b, 'n'))) {
+        return 1;
+    }
+
+    got = TX79_UNARY_WORD(TX79_R(0, 8, 10, 27, 41), &a);
+    if (check_qword("PCPYH", got, ref_pcpyh(a))) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 14, 9), &a, &b);
+    if (check_qword("PCPYLD", got, (tx79_qword) { b.lo, a.lo })) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 10, 14, 41), &a, &b);
+    if (check_qword("PCPYUD", got, (tx79_qword) { a.hi, b.hi })) {
+        return 1;
+    }
+    got = TX79_UNARY_WORD(TX79_R(0, 8, 10, 31, 9), &a);
+    if (check_qword("PROT3W", got, ref_prot3w(a))) {
+        return 1;
+    }
+
+    got = TX79_BINOP_WORD(TX79_R(0, 9, 10, 14, 9), &a, &b);
+    if (check_qword("PCPYLD rt-only", got, (tx79_qword) { b.lo, 0 })) {
+        return 1;
+    }
+    got = TX79_BINOP_WORD(TX79_R(8, 0, 10, 14, 41), &a, &b);
+    if (check_qword("PCPYUD rs-only", got, (tx79_qword) { a.hi, 0 })) {
+        return 1;
+    }
+    got = TX79_UNARY_WORD(TX79_R(0, 0, 10, 27, 41), &a);
+    if (check_qword("PCPYH zero", got, (tx79_qword) { 0, 0 })) {
+        return 1;
+    }
+
+    got = TX79_BINOP_WORD(TX79_R(8, 9, 0, 1, 8), &a, &b);
+    if (check_qword("rd zero", got, (tx79_qword) {
+            a.lo, a.hi,
+        })) {
+        return 1;
+    }
+
+    return 0;
+}
+
+static int test_quadword_memory(void)
+{
+    static uint8_t memory[65536 + 64] __attribute__((aligned(16)));
+    static const int offsets[] = { -32768, -1, 0, 1, 32767 };
+    const tx79_qword value = {
+        0x0123456789abcdefULL,
+        0xfedcba9876543210ULL,
+    };
+    uint8_t *base = memory + 32784;
+
+    for (unsigned i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
+        int offset = offsets[i];
+        uintptr_t address = (uintptr_t)base + (intptr_t)offset;
+        uint8_t *aligned = (uint8_t *)(address & ~(uintptr_t)0xf);
+        tx79_qword got;
+
+        memset(memory, 0, sizeof(memory));
+        memcpy(aligned, &value, sizeof(value));
+        switch (offset) {
+        case -32768:
+            got = TX79_LQ_OFFSET(-32768, base);
+            break;
+        case -1:
+            got = TX79_LQ_OFFSET(-1, base);
+            break;
+        case 0:
+            got = TX79_LQ_OFFSET(0, base);
+            break;
+        case 1:
+            got = TX79_LQ_OFFSET(1, base);
+            break;
+        default:
+            got = TX79_LQ_OFFSET(32767, base);
+            break;
+        }
+        if (check_qword("LQ offset", got, value)) {
+            return 1;
+        }
+
+        memset(memory, 0, sizeof(memory));
+        switch (offset) {
+        case -32768:
+            TX79_SQ_OFFSET(-32768, &value, base);
+            break;
+        case -1:
+            TX79_SQ_OFFSET(-1, &value, base);
+            break;
+        case 0:
+            TX79_SQ_OFFSET(0, &value, base);
+            break;
+        case 1:
+            TX79_SQ_OFFSET(1, &value, base);
+            break;
+        default:
+            TX79_SQ_OFFSET(32767, &value, base);
+            break;
+        }
+        if (memcmp(aligned, &value, sizeof(value)) != 0) {
+            fprintf(stderr, "SQ offset %d failed\n", offset);
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+int main(void)
+{
+    if (test_hilo1() || test_parallel() || test_quadword_memory()) {
+        return 1;
+    }
+
+    return 0;
+}
tests/tcg/mips64el/system/meson.build +2 -0
index fd5a759c20fa..66c3d61c3134 100644
@@ -39,6 +39,15 @@ foreach t: [
   }
 endforeach
 
+# n32: 32-bit pointers, 64-bit GPRs are needed to move 64-bit values to HI1/LO1
+tests += {

tests/tcg/mips64el/system/meson.build foreach t: [ · line 53

Quoted 10 lines
tests/tcg/mips64el/system/meson.build +7 -0
+  'test_r5900_tx79.c': {
+    'cflags': cflags + ['-mabi=n32'],
+    'qemu_args': qemu_args,
+    'gdb_test': gdb_test,
+  }
+}
+
 if 'qemu-system-mips64el' in emulators
   tcg_tests += {
     'mips64el-softmmu': {

Without diving too much into every line, looks good to me overall.

Regards,
Pierrick

#26 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 87 lines · Philippe Mathieu-Daudé

Add R5900 system tests, code is covered, CPU can come back, allowing to fix a bug on PCGT opcode.

Since [v1]:
- rebased
- added freestanding libc stubs
- o32/n32 tests

[v1]: https://lore.kernel.org/qemu-devel/[email protected]/

Philippe Mathieu-Daudé (9):
target/mips: Re-introduce the R5900 CPU in system mode target/mips/tx79: Fix PCGT* (Parallel Compare for Greater Than) tests/guest-debug: Allow placing the binary within system QEMU args tests/tcg/mips64el: Add bare-metal harness for R5900 system tests tests/tcg/mips64el: Move R5900 tests to system mode and build with
meson
target/mips: Factor mips_gdb_read_value() out target/mips: Describe gdbstub registers with XML features target/mips: Expose R5900 registers to gdb tests/tcg/mips64el: Add a TX79 instruction test in system mode

  MAINTAINERS                                   |   1 +
  configs/targets/mips-linux-user.mak           |   1 +
  configs/targets/mips-softmmu.mak              |   1 +
  configs/targets/mips64-linux-user.mak         |   1 +
  configs/targets/mips64-softmmu.mak            |   1 +
  configs/targets/mips64el-linux-user.mak       |   1 +
  configs/targets/mips64el-softmmu.mak          |   1 +
  configs/targets/mipsel-linux-user.mak         |   1 +
  configs/targets/mipsel-softmmu.mak            |   1 +
  configs/targets/mipsn32-linux-user.mak        |   1 +
  configs/targets/mipsn32el-linux-user.mak      |   1 +
  target/mips/internal.h                        |   2 +
  tests/tcg/mips64el/system/include/assert.h    |  15 +
  tests/tcg/mips64el/system/include/inttypes.h  |   7 +
  tests/tcg/mips64el/system/include/stdio.h     |  17 +
  tests/tcg/mips64el/system/include/string.h    |  16 +
  target/mips/cpu.c                             |   4 +
  target/mips/gdbstub.c                         | 152 +++++-
  target/mips/tcg/tx79_translate.c              |  10 +-
  tests/tcg/mips64el/system/harness.c           |  66 +++
  .../system}/test_r5900_div1.c                 |   0
  .../system}/test_r5900_divu1.c                |   0
  .../system}/test_r5900_madd.c                 |   0
  .../system}/test_r5900_maddu.c                |   0
  .../system}/test_r5900_mflohi1.c              |   0
  .../system}/test_r5900_mtlohi1.c              |   0
  .../system}/test_r5900_mult.c                 |   0
  .../system}/test_r5900_multu.c                |   0
  tests/tcg/mips64el/system/test_r5900_tx79.c   | 477 ++++++++++++++++++
  target/mips/cpu-defs.c.inc                    |  45 ++
  gdbstub/gdb-xml/mips32-cp0.xml                |   9 +
  gdbstub/gdb-xml/mips32-cpu.xml                |  42 ++
  gdbstub/gdb-xml/mips32-fpu.xml                |  41 ++
  gdbstub/gdb-xml/mips64-cp0.xml                |   9 +
  gdbstub/gdb-xml/mips64-cpu.xml                |  42 ++
  gdbstub/gdb-xml/mips64-fpu.xml                |  41 ++
  gdbstub/gdb-xml/mips64-r5900.xml              |  47 ++
  tests/guest-debug/run-test.py                 |   9 +-
  tests/tcg/mips/user/isa/r5900/Makefile        |  32 --
  tests/tcg/mips/user/isa/r5900/README          |   6 -
  tests/tcg/mips64el/meson.build                |   2 +
  tests/tcg/mips64el/system/boot.S              |  23 +
  tests/tcg/mips64el/system/kernel.ld           |  43 ++
  tests/tcg/mips64el/system/meson.build         |  62 +++
  tests/tcg/mips64el/system/test-r5900.py       |  30 ++
  45 files changed, 1211 insertions(+), 49 deletions(-)

create mode 100644 tests/tcg/mips64el/system/include/assert.h
create mode 100644 tests/tcg/mips64el/system/include/inttypes.h
create mode 100644 tests/tcg/mips64el/system/include/stdio.h
create mode 100644 tests/tcg/mips64el/system/include/string.h
create mode 100644 tests/tcg/mips64el/system/harness.c
rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_div1.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_divu1.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_madd.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_maddu.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mflohi1.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mtlohi1.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_mult.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/test_r5900_multu.c (100%) create mode 100644 tests/tcg/mips64el/system/test_r5900_tx79.c
create mode 100644 gdbstub/gdb-xml/mips32-cp0.xml
create mode 100644 gdbstub/gdb-xml/mips32-cpu.xml
create mode 100644 gdbstub/gdb-xml/mips32-fpu.xml
create mode 100644 gdbstub/gdb-xml/mips64-cp0.xml
create mode 100644 gdbstub/gdb-xml/mips64-cpu.xml

Quoted 9 lines

create mode 100644 gdbstub/gdb-xml/mips64-fpu.xml create mode 100644 gdbstub/gdb-xml/mips64-r5900.xml delete mode 100644 tests/tcg/mips/user/isa/r5900/Makefile delete mode 100644 tests/tcg/mips/user/isa/r5900/README create mode 100644 tests/tcg/mips64el/system/boot.S create mode 100644 tests/tcg/mips64el/system/kernel.ld create mode 100644 tests/tcg/mips64el/system/meson.build create mode 100644 tests/tcg/mips64el/system/test-r5900.py

See some test failures, related to gdb:
https://github.com/p-b-o/qemu-ci/actions/runs/40776744817/job/123131480244

Regards,
Pierrick

#27 lore raw
Quoted 98 lines · Pierrick Bouvier
Quoted 87 lines · Philippe Mathieu-Daudé

Add R5900 system tests, code is covered, CPU can come back, allowing to fix a bug on PCGT opcode.

Since [v1]:
- rebased
- added freestanding libc stubs
- o32/n32 tests

[v1]: https://lore.kernel.org/qemu-devel/20210214175912.732946-1- [email protected]/

Philippe Mathieu-Daudé (9):
   target/mips: Re-introduce the R5900 CPU in system mode target/mips/tx79: Fix PCGT* (Parallel Compare for Greater Than) tests/guest-debug: Allow placing the binary within system QEMU args tests/tcg/mips64el: Add bare-metal harness for R5900 system tests tests/tcg/mips64el: Move R5900 tests to system mode and build with meson
   target/mips: Factor mips_gdb_read_value() out target/mips: Describe gdbstub registers with XML features target/mips: Expose R5900 registers to gdb tests/tcg/mips64el: Add a TX79 instruction test in system mode

  MAINTAINERS                                   |   1 + configs/targets/mips-linux-user.mak           |   1 + configs/targets/mips-softmmu.mak              |   1 + configs/targets/mips64-linux-user.mak         |   1 + configs/targets/mips64-softmmu.mak            |   1 + configs/targets/mips64el-linux-user.mak       |   1 + configs/targets/mips64el-softmmu.mak          |   1 + configs/targets/mipsel-linux-user.mak         |   1 + configs/targets/mipsel-softmmu.mak            |   1 + configs/targets/mipsn32-linux-user.mak        |   1 + configs/targets/mipsn32el-linux-user.mak      |   1 + target/mips/internal.h                        |   2 + tests/tcg/mips64el/system/include/assert.h    |  15 + tests/tcg/mips64el/system/include/inttypes.h  |   7 + tests/tcg/mips64el/system/include/stdio.h     |  17 + tests/tcg/mips64el/system/include/string.h    |  16 + target/mips/cpu.c                             |   4 + target/mips/gdbstub.c                         | 152 +++++- target/mips/tcg/tx79_translate.c              |  10 +- tests/tcg/mips64el/system/harness.c           |  66 +++ .../system}/test_r5900_div1.c                 |   0 .../system}/test_r5900_divu1.c                |   0 .../system}/test_r5900_madd.c                 |   0 .../system}/test_r5900_maddu.c                |   0 .../system}/test_r5900_mflohi1.c              |   0 .../system}/test_r5900_mtlohi1.c              |   0 .../system}/test_r5900_mult.c                 |   0 .../system}/test_r5900_multu.c                |   0 tests/tcg/mips64el/system/test_r5900_tx79.c   | 477 ++++++++++++++++++ target/mips/cpu-defs.c.inc                    |  45 ++

  gdbstub/gdb-xml/mips32-cp0.xml                |   9 +
  gdbstub/gdb-xml/mips32-cpu.xml                |  42 ++
  gdbstub/gdb-xml/mips32-fpu.xml                |  41 ++
  gdbstub/gdb-xml/mips64-cp0.xml                |   9 +
  gdbstub/gdb-xml/mips64-cpu.xml                |  42 ++
  gdbstub/gdb-xml/mips64-fpu.xml                |  41 ++

  gdbstub/gdb-xml/mips64-r5900.xml              |  47 ++ tests/guest-debug/run-test.py                 |   9 +- tests/tcg/mips/user/isa/r5900/Makefile        |  32 -- tests/tcg/mips/user/isa/r5900/README          |   6 - tests/tcg/mips64el/meson.build                |   2 + tests/tcg/mips64el/system/boot.S              |  23 + tests/tcg/mips64el/system/kernel.ld           |  43 ++ tests/tcg/mips64el/system/meson.build         |  62 +++ tests/tcg/mips64el/system/test-r5900.py       |  30 ++

  45 files changed, 1211 insertions(+), 49 deletions(-)

  create mode 100644 tests/tcg/mips64el/system/include/assert.h
  create mode 100644 tests/tcg/mips64el/system/include/inttypes.h
  create mode 100644 tests/tcg/mips64el/system/include/stdio.h
  create mode 100644 tests/tcg/mips64el/system/include/string.h
  create mode 100644 tests/tcg/mips64el/system/harness.c
  rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_div1.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_divu1.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_madd.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_maddu.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_mflohi1.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_mtlohi1.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_mult.c (100%) rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_multu.c (100%) create mode 100644 tests/tcg/mips64el/system/test_r5900_tx79.c
  create mode 100644 gdbstub/gdb-xml/mips32-cp0.xml
  create mode 100644 gdbstub/gdb-xml/mips32-cpu.xml
  create mode 100644 gdbstub/gdb-xml/mips32-fpu.xml
  create mode 100644 gdbstub/gdb-xml/mips64-cp0.xml
  create mode 100644 gdbstub/gdb-xml/mips64-cpu.xml

Quoted 9 lines

  create mode 100644 gdbstub/gdb-xml/mips64-fpu.xml create mode 100644 gdbstub/gdb-xml/mips64-r5900.xml delete mode 100644 tests/tcg/mips/user/isa/r5900/Makefile delete mode 100644 tests/tcg/mips/user/isa/r5900/README create mode 100644 tests/tcg/mips64el/system/boot.S create mode 100644 tests/tcg/mips64el/system/kernel.ld create mode 100644 tests/tcg/mips64el/system/meson.build create mode 100644 tests/tcg/mips64el/system/test-r5900.py

Quoted 2 lines

See some test failures, related to gdb:
https://github.com/p-b-o/qemu-ci/actions/runs/40776744817/job/123131480244

Ah hmm I had similar failures due to too old gdb, I might have missed to check the version in that container image. IIRC Gustavo had similar problem with ARM I'll see how he fixed that (I suppose check gdb version and skip the tests).

Thanks!

#28 lore raw
Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Pierrick Bouvier
Quoted 2 lines · Philippe Mathieu-Daudé

Add R5900 system tests, code is covered, CPU can come back, allowing to fix a bug on PCGT opcode.

Quoted 7 lines
Quoted 2 lines

See some test failures, related to gdb:
https://github.com/p-b-o/qemu-ci/actions/runs/40776744817/ job/123131480244

Ah hmm I had similar failures due to too old gdb, I might have missed to check the version in that container image. IIRC Gustavo had similar problem with ARM I'll see how he fixed that (I suppose check gdb version and skip the tests).

Found it, this is 'gdb_feat_version' :)

tests/tcg/meson.build=18=tcg_tests = {} tests/tcg/meson.build-19-# tcg_tests is a dictionary with following structure:
tests/tcg/meson.build-20-#
tests/tcg/meson.build-21-# {
tests/tcg/meson.build-22-# 'name_of_target': {

tests/tcg/meson.build-23-#     'cc': 'cross_compiler',
tests/tcg/meson.build-24-#     'cc_alt': ['list of alternative cross compilers', ...]
tests/tcg/meson.build-25-#     'cc_dockerfile': 'name_of_dockerfile',
tests/tcg/meson.build-26-#     'cc_feat_cflags': {
tests/tcg/meson.build-27-#       'name': ['feature cflags'],
tests/tcg/meson.build-28-#       ...
tests/tcg/meson.build-29-#     },
tests/tcg/meson.build-30-#     'folder': 'folder_for_test_src_files',
tests/tcg/meson.build-31-#     'gdb_arch': 'gdb architecture requirement',
tests/tcg/meson.build:32:#     'gdb_feat_version': {
tests/tcg/meson.build-33-#       'name': ['minimal gdb version supporting feature'],
tests/tcg/meson.build-34-#       ...
tests/tcg/meson.build-35-#     },
tests/tcg/meson.build-36-#     'qemu': emulators['qemu-...'],
tests/tcg/meson.build-37-#     'tests': [
tests/tcg/meson.build-38-#       {
tests/tcg/meson.build-39-#         'src_file': {
tests/tcg/meson.build-40-#           'exe_name': ['provide an alternative binary name'],
tests/tcg/meson.build-41-#           'test_name': ['provide an alternative test name'],
tests/tcg/meson.build-42-#           'cflags': ['additional cflags to compile test', ...],
tests/tcg/meson.build-43-#           'depends': [meson_dependency, ...],
tests/tcg/meson.build-44-#           'cc_feat': 'feature name, must be present in cc_feat_cflags',
tests/tcg/meson.build-45-#           'qemu_args': ['qemu command line flags', ...],
tests/tcg/meson.build-46-#           'expected_output': 'file_to_compare_output',
tests/tcg/meson.build-47-#           'gdb_test': ['gdb test args'],
tests/tcg/meson.build:48:#           'gdb_feat': ['feature name, must be present in gdb_feat_version'],
tests/tcg/meson.build-49-#           'env_var': ['VAR=value', ...],
tests/tcg/meson.build-50-#           'wrapper': [program_to_launch_test, 'args'...],
tests/tcg/meson.build-51-#           'plugin_test': {

tests/tcg/meson.build-52-# 'plugin': 'plugin_name',
tests/tcg/meson.build-53-# 'args': ['plugin_args', ...],
tests/tcg/meson.build-54-# },
tests/tcg/meson.build-55-# }
tests/tcg/meson.build-56-# },
tests/tcg/meson.build-57-# ...
tests/tcg/meson.build-58-# ]
tests/tcg/meson.build-59-# }
tests/tcg/meson.build-60-# }

tests/tcg/meson.build=200=foreach target, plan: tcg_tests

tests/tcg/meson.build:518: if not gdb_version.version_compare('>=' + gdb_feat_version[gdb_feat])
tests/tcg/meson.build-519- skip_test = 'gdb feature ' + gdb_feat + ' not supported'
tests/tcg/meson.build-520- endif

tests/tcg/aarch64/meson.build:18:gdb_feat_version = {

tests/tcg/aarch64/meson.build-19-  'sme-tiles': '14.1',
tests/tcg/aarch64/meson.build-20-  'mte': '15.1',
tests/tcg/aarch64/meson.build-21-  'mte-baremetal': '16.0',

tests/tcg/aarch64/meson.build-22-}

tests/tcg/aarch64/meson.build=196=if 'qemu-aarch64' in emulators tests/tcg/aarch64/meson.build-197- tcg_tests += {
tests/tcg/aarch64/meson.build-198- 'aarch64-linux-user': {

tests/tcg/aarch64/meson.build-199-      'cc': cc,
tests/tcg/aarch64/meson.build-200-      'cc_alt': cc_alt,
tests/tcg/aarch64/meson.build-201-      'cc_dockerfile': cc_dockerfile,
tests/tcg/aarch64/meson.build-202-      'cc_feat_cflags': cc_feat_cflags,
tests/tcg/aarch64/meson.build-203-      'folder': 'aarch64',
tests/tcg/aarch64/meson.build-204-      'gdb_arch': 'aarch64',
tests/tcg/aarch64/meson.build:205:      'gdb_feat_version': gdb_feat_version,
tests/tcg/aarch64/meson.build-206-      'qemu': emulators['qemu-aarch64'],
tests/tcg/aarch64/meson.build-207-      'tests': tests,

tests/tcg/aarch64/meson.build-208- }
tests/tcg/aarch64/meson.build-209- }

#29 lore raw
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Pierrick Bouvier
Quoted 2 lines · Philippe Mathieu-Daudé

Add R5900 system tests, code is covered, CPU can come back, allowing to fix a bug on PCGT opcode.

See some test failures, related to gdb:
https://github.com/p-b-o/qemu-ci/actions/runs/40776744817/
job/123131480244

Quoted 7 lines
Quoted 4 lines

Ah hmm I had similar failures due to too old gdb, I might have missed to check the version in that container image. IIRC Gustavo had similar problem with ARM I'll see how he fixed that (I suppose check gdb version and skip the tests).

Found it, this is 'gdb_feat_version' :)

That's the right way to deal with it indeed.

That said, the gdb used in this test (on GitHub) comes from debian stable, which is fairly recent (16.3).

Is a more recent version needed for complete mips support?
If yes, I can update to the latest gdb so we can get full coverage on GitHub. Meanwhile, you can find which minimum version is needed.

Regards,
Pierrick

#30 lore raw
Quoted 17 lines · Pierrick Bouvier
Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Pierrick Bouvier
Quoted 2 lines · Philippe Mathieu-Daudé

Add R5900 system tests, code is covered, CPU can come back, allowing to fix a bug on PCGT opcode.

See some test failures, related to gdb:
https://github.com/p-b-o/qemu-ci/actions/runs/40776744817/
job/123131480244

Ah hmm I had similar failures due to too old gdb, I might have missed to check the version in that container image. IIRC Gustavo had similar problem with ARM I'll see how he fixed that (I suppose check gdb version and skip the tests).

Quoted 8 lines
Quoted 2 lines

Found it, this is 'gdb_feat_version' :)

That's the right way to deal with it indeed.

That said, the gdb used in this test (on GitHub) comes from debian stable, which is fairly recent (16.3).

Is a more recent version needed for complete mips support?
If yes, I can update to the latest gdb so we can get full coverage on GitHub. Meanwhile, you can find which minimum version is needed.

Indeed, the problem is simpler, located in the tests/tcg/multiarch/gdbstub/registers.py.

Before there were no register descriptions for MIPS and the test was skipping (registers with no names). Now it runs for real. Apparently this is what commit 6ef164188d00 ("tests/tcg: finesse the registers check for "hidden" regs") aimed to resolve but was a bit too restrictive, this fixes it:

-- >8 --

tests/tcg/multiarch/gdbstub/registers.py +5 -2
index b3d13cb077f1..8d886413eb28 100644
@@ -180,10 +180,13 @@ def complete_and_diff(reg_map):
 
     for e in reg_map.values():
-        if "initial" in e and "hidden" not in e:
+        if "initial" in e:
             name = e["name"]
             old_val = e["initial"]
 
             try:
-                new_val = frame.read_register(name)
+                if "hidden" in e:
+                    new_val = frame.read_register(e["regnum"])
+                else:
+                    new_val = frame.read_register(name)
             except ValueError:
                 report(False, f"failed to read {name} at end of run")

---

#31 lore raw
Quoted 51 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Pierrick Bouvier
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Pierrick Bouvier
Quoted 2 lines · Philippe Mathieu-Daudé

Add R5900 system tests, code is covered, CPU can come back, allowing to fix a bug on PCGT opcode.

See some test failures, related to gdb:
https://github.com/p-b-o/qemu-ci/actions/runs/40776744817/
job/123131480244

Quoted 7 lines
Quoted 4 lines

Ah hmm I had similar failures due to too old gdb, I might have missed to check the version in that container image. IIRC Gustavo had similar problem with ARM I'll see how he fixed that (I suppose check gdb version and skip the tests).

Found it, this is 'gdb_feat_version' :)

Quoted 8 lines

That's the right way to deal with it indeed.

That said, the gdb used in this test (on GitHub) comes from debian stable, which is fairly recent (16.3).

Is a more recent version needed for complete mips support? If yes, I can update to the latest gdb so we can get full coverage on GitHub. Meanwhile, you can find which minimum version is needed.

Indeed, the problem is simpler, located in the
tests/tcg/multiarch/gdbstub/registers.py.

Before there were no register descriptions for MIPS and the test was skipping (registers with no names). Now it runs for real. Apparently this is what commit 6ef164188d00 ("tests/tcg: finesse the registers check for "hidden" regs") aimed to resolve but was a bit too restrictive, this fixes it:

-- >8 --

tests/tcg/multiarch/gdbstub/registers.py +1 -1
index b3d13cb077f1..8d886413eb28 100644
@@ -180,10 +180,13 @@ def complete_and_diff(reg_map):
 
       for e in reg_map.values():
-        if "initial" in e and "hidden" not in e:
+        if "initial" in e:
               name = e["name"]
               old_val = e["initial"]

tests/tcg/multiarch/gdbstub/registers.py def complete_and_diff(reg_map):

Quoted 10 lines
tests/tcg/multiarch/gdbstub/registers.py +4 -2
 
               try:
-                new_val = frame.read_register(name)
+                if "hidden" in e:
+                    new_val = frame.read_register(e["regnum"])
+                else:
+                    new_val = frame.read_register(name)
               except ValueError:
                   report(False, f"failed to read {name} at end of run")
---

Great. Let's add this patch in next version and ship this before the freeze!

Regards,
Pierrick

Reviewed-by
#32 lore raw
In reply to Philippe Mathieu-Daudé

Hi Phil,

Quoted 52 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Pierrick Bouvier
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Pierrick Bouvier
Quoted 2 lines · Philippe Mathieu-Daudé

Add R5900 system tests, code is covered, CPU can come back, allowing to fix a bug on PCGT opcode.

See some test failures, related to gdb:
https://github.com/p-b-o/qemu-ci/actions/runs/40776744817/
job/123131480244

Quoted 7 lines
Quoted 4 lines

Ah hmm I had similar failures due to too old gdb, I might have missed to check the version in that container image. IIRC Gustavo had similar problem with ARM I'll see how he fixed that (I suppose check gdb version and skip the tests).

Found it, this is 'gdb_feat_version' :)

Quoted 8 lines

That's the right way to deal with it indeed.

That said, the gdb used in this test (on GitHub) comes from debian stable, which is fairly recent (16.3).

Is a more recent version needed for complete mips support? If yes, I can update to the latest gdb so we can get full coverage on GitHub. Meanwhile, you can find which minimum version is needed.

Indeed, the problem is simpler, located in the
tests/tcg/multiarch/gdbstub/registers.py.

Before there were no register descriptions for MIPS and the test was skipping (registers with no names). Now it runs for real. Apparently this is what commit 6ef164188d00 ("tests/tcg: finesse the registers check for "hidden" regs") aimed to resolve but was a bit too restrictive, this fixes it:

-- >8 --

tests/tcg/multiarch/gdbstub/registers.py +1 -1
index b3d13cb077f1..8d886413eb28 100644
@@ -180,10 +180,13 @@ def complete_and_diff(reg_map):
 
     for e in reg_map.values():
-        if "initial" in e and "hidden" not in e:
+        if "initial" in e:
             name = e["name"]
             old_val = e["initial"]

tests/tcg/multiarch/gdbstub/registers.py def complete_and_diff(reg_map):

Quoted 10 lines
tests/tcg/multiarch/gdbstub/registers.py +4 -2
 
             try:
-                new_val = frame.read_register(name)
+                if "hidden" in e:
+                    new_val = frame.read_register(e["regnum"])
+                else:
+                    new_val = frame.read_register(name)
             except ValueError:
                 report(False, f"failed to read {name} at end of run")
---

ah, I was late for the party, you already found it :)

Cheers,
Gustavo

#33 lore raw
In reply to Philippe Mathieu-Daudé

Hi Phil,

Quoted 108 lines · Philippe Mathieu-Daudé
Quoted 107 lines · Pierrick Bouvier
Quoted 105 lines · Philippe Mathieu-Daudé

Add R5900 system tests, code is covered, CPU can come back, allowing to fix a bug on PCGT opcode.

Since [v1]:
- rebased
- added freestanding libc stubs
- o32/n32 tests

[v1]: https://lore.kernel.org/qemu-devel/20210214175912.732946-1-
[email protected]/

Philippe Mathieu-Daudé (9):
   target/mips: Re-introduce the R5900 CPU in system mode target/mips/tx79: Fix PCGT* (Parallel Compare for Greater Than) tests/guest-debug: Allow placing the binary within system QEMU args tests/tcg/mips64el: Add bare-metal harness for R5900 system tests tests/tcg/mips64el: Move R5900 tests to system mode and build with meson
   target/mips: Factor mips_gdb_read_value() out target/mips: Describe gdbstub registers with XML features target/mips: Expose R5900 registers to gdb tests/tcg/mips64el: Add a TX79 instruction test in system mode

  MAINTAINERS                                   |   1 + configs/targets/mips-linux-user.mak           |   1 + configs/targets/mips-softmmu.mak              |   1 + configs/targets/mips64-linux-user.mak         |   1 + configs/targets/mips64-softmmu.mak            |   1 + configs/targets/mips64el-linux-user.mak       |   1 + configs/targets/mips64el-softmmu.mak          |   1 + configs/targets/mipsel-linux-user.mak         |   1 + configs/targets/mipsel-softmmu.mak            |   1 + configs/targets/mipsn32-linux-user.mak        |   1 + configs/targets/mipsn32el-linux-user.mak      |   1 + target/mips/internal.h                        |   2 + tests/tcg/mips64el/system/include/assert.h    |  15 + tests/tcg/mips64el/system/include/inttypes.h  |   7 + tests/tcg/mips64el/system/include/stdio.h     |  17 + tests/tcg/mips64el/system/include/string.h    |  16 + target/mips/cpu.c                             |   4 + target/mips/gdbstub.c                         | 152 +++++- target/mips/tcg/tx79_translate.c              |  10 +- tests/tcg/mips64el/system/harness.c           |  66 +++ .../system}/test_r5900_div1.c                 |   0 .../system}/test_r5900_divu1.c                |   0 .../system}/test_r5900_madd.c                 |   0 .../system}/test_r5900_maddu.c                |   0 .../system}/test_r5900_mflohi1.c              |   0 .../system}/test_r5900_mtlohi1.c              |   0 .../system}/test_r5900_mult.c                 |   0 .../system}/test_r5900_multu.c                |   0 tests/tcg/mips64el/system/test_r5900_tx79.c   | 477 ++++++++++++++++++ target/mips/cpu-defs.c.inc                    |  45 ++

  gdbstub/gdb-xml/mips32-cp0.xml                |   9 +
  gdbstub/gdb-xml/mips32-cpu.xml                |  42 ++
  gdbstub/gdb-xml/mips32-fpu.xml                |  41 ++
  gdbstub/gdb-xml/mips64-cp0.xml                |   9 +
  gdbstub/gdb-xml/mips64-cpu.xml                |  42 ++
  gdbstub/gdb-xml/mips64-fpu.xml                |  41 ++

  gdbstub/gdb-xml/mips64-r5900.xml              |  47 ++ tests/guest-debug/run-test.py                 |   9 +- tests/tcg/mips/user/isa/r5900/Makefile        |  32 -- tests/tcg/mips/user/isa/r5900/README          |   6 - tests/tcg/mips64el/meson.build                |   2 + tests/tcg/mips64el/system/boot.S              |  23 + tests/tcg/mips64el/system/kernel.ld           |  43 ++ tests/tcg/mips64el/system/meson.build         |  62 +++ tests/tcg/mips64el/system/test-r5900.py       |  30 ++

  45 files changed, 1211 insertions(+), 49 deletions(-)

  create mode 100644 tests/tcg/mips64el/system/include/assert.h create mode 100644 tests/tcg/mips64el/system/include/inttypes.h create mode 100644 tests/tcg/mips64el/system/include/stdio.h create mode 100644 tests/tcg/mips64el/system/include/string.h create mode 100644 tests/tcg/mips64el/system/harness.c rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_div1.c (100%)
  rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_divu1.c (100%)
  rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_madd.c (100%)
  rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_maddu.c (100%)
  rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_mflohi1.c (100%)
  rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_mtlohi1.c (100%)
  rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_mult.c (100%)
  rename tests/tcg/{mips/user/isa/r5900 => mips64el/system}/ test_r5900_multu.c (100%)
  create mode 100644 tests/tcg/mips64el/system/test_r5900_tx79.c create mode 100644 gdbstub/gdb-xml/mips32-cp0.xml create mode 100644 gdbstub/gdb-xml/mips32-cpu.xml create mode 100644 gdbstub/gdb-xml/mips32-fpu.xml create mode 100644 gdbstub/gdb-xml/mips64-cp0.xml create mode 100644 gdbstub/gdb-xml/mips64-cpu.xml create mode 100644 gdbstub/gdb-xml/mips64-fpu.xml create mode 100644 gdbstub/gdb-xml/mips64-r5900.xml delete mode 100644 tests/tcg/mips/user/isa/r5900/Makefile delete mode 100644 tests/tcg/mips/user/isa/r5900/README create mode 100644 tests/tcg/mips64el/system/boot.S create mode 100644 tests/tcg/mips64el/system/kernel.ld create mode 100644 tests/tcg/mips64el/system/meson.build create mode 100644 tests/tcg/mips64el/system/test-r5900.py

Quoted 7 lines
Quoted 2 lines

See some test failures, related to gdb:
https://github.com/p-b-o/qemu-ci/actions/runs/40776744817/job/123131480244

Ah hmm I had similar failures due to too old gdb, I might have missed to check the version in that container image. IIRC Gustavo had similar problem with ARM I'll see how he fixed that (I suppose check gdb version and skip the tests).

Hmm, I took a quick look at the failure, and it doesn't ring a bell.

It's also the first time I've looked at the tests/tcg/multiarch/gdbstub/registers.py test, so let me take a closer look at the test. If I find something, I'll report back here.

otoh, I'm happy my email filters are better now and I can easily catch when somebody cc's me :)

Cheers,
Gustavo