[RFC PATCH 41/42] tests/acceptance: Test R5900 CPU with BusyBox from Sony PS2

Philippe Mathieu-Daudé posted 42 patches 4 years, 9 months ago
There is a newer version of this series
[RFC PATCH 41/42] tests/acceptance: Test R5900 CPU with BusyBox from Sony PS2
Posted by Philippe Mathieu-Daudé 4 years, 9 months ago
Test BusyBox on the R5900 CPU with 2 different binaries:

- o32 32-bit (statically linked)
- o32 64-bit (dynamically linked, uses multimedia instructions)

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 MAINTAINERS                        |  1 +
 tests/acceptance/mips_r5900_ps2.py | 69 ++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)
 create mode 100644 tests/acceptance/mips_r5900_ps2.py

diff --git a/MAINTAINERS b/MAINTAINERS
index de5fe1c65f5..1a23f471b0e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -242,6 +242,7 @@ F: include/hw/mips/
 F: include/hw/misc/mips_*
 F: include/hw/timer/mips_gictimer.h
 F: tests/tcg/mips/
+F: tests/acceptance/mips_r5900_ps2.py
 K: ^Subject:.*(?i)mips
 
 MIPS TCG CPUs (nanoMIPS ISA)
diff --git a/tests/acceptance/mips_r5900_ps2.py b/tests/acceptance/mips_r5900_ps2.py
new file mode 100644
index 00000000000..ff73f994e59
--- /dev/null
+++ b/tests/acceptance/mips_r5900_ps2.py
@@ -0,0 +1,69 @@
+# Test the MIPS R5900 CPU
+#
+# Copyright (C) 2021 Philippe Mathieu-Daudé <f4bug@amsat.org>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import os
+import lzma
+import shutil
+
+from avocado import skipUnless
+
+from avocado.utils import archive
+from avocado_qemu import QemuUserTest
+
+class R5900(QemuUserTest):
+
+    @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
+    def test_gentoo_busybox_32bit(self):
+        """
+        :avocado: tags=arch:r5900o32el
+        :avocado: tags=linux_user
+        :avocado: tags=quick
+        """
+        busybox_url = ('https://raw.githubusercontent.com/philmd'
+                       '/qemu-testing-blob/bf6a300cf0bc56e4a2c5b'
+                       '/mips/ps2/busybox-gentoo-v1.32.0.xz')
+        busybox_hash = 'd2a0abc2c7c3adb6b2fdd63356be78bc5e99f324'
+        busybox_path_xz = self.fetch_asset(busybox_url, asset_hash=busybox_hash)
+
+        busybox_path = os.path.join(self.workdir, "busybox")
+        with lzma.open(busybox_path_xz, 'rb') as f_in:
+            with open(busybox_path, 'wb') as f_out:
+                shutil.copyfileobj(f_in, f_out)
+        os.chmod(busybox_path, 0o755)
+
+        res = self.run(busybox_path)
+        ver = 'BusyBox v1.32.0 (2021-02-09 15:13:23 -00) multi-call binary'
+        self.assertIn(ver, res.stdout_text)
+
+        res = self.run(busybox_path, ['uname', '-a'])
+        unm = 'mips64 mips64 mips64 GNU/Linux'
+        self.assertIn(unm, res.stdout_text)
+
+    @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
+    def test_ps2_busybox_64bit(self):
+        """
+        :avocado: tags=arch:r5900o32el
+        :avocado: tags=linux_user
+        :avocado: tags=quick
+        """
+        rootfs_url = ('https://raw.githubusercontent.com/philmd'
+                       '/qemu-testing-blob/bf6a300cf0bc56e4a2c5b/mips'
+                       '/ps2/ps2linux_live_v5_pal_netsurf_usb_busybox.tar.gz')
+        rootfs_hash = '9aa8fdd974cd3332c7167bceb6dd7137853d3a10'
+        rootfs_path_tgz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash)
+
+        archive.extract(rootfs_path_tgz, self.workdir)
+        busybox_path = self.workdir + "/bin/busybox"
+
+        self.add_ldpath(self.workdir)
+
+        res = self.run(busybox_path)
+        ver = 'BusyBox v0.60.5 (2010.06.06-16:16+0000) multi-call binary'
+        self.assertIn(ver, res.stderr_text)
+
+        res = self.run(busybox_path, ['uname', '-a'])
+        unm = 'mips64 unknown'
+        self.assertIn(unm, res.stdout_text)
-- 
2.26.2

Re: [RFC PATCH 41/42] tests/acceptance: Test R5900 CPU with BusyBox from Sony PS2
Posted by Fredrik Noring 4 years, 9 months ago
On Sun, Feb 14, 2021 at 06:59:11PM +0100, Philippe Mathieu-Daudé wrote:
> Test BusyBox on the R5900 CPU with 2 different binaries:
> 
> - o32 32-bit (statically linked)
> - o32 64-bit (dynamically linked, uses multimedia instructions)

R5900/libc update:

Gnu libc for o32 was merged some time ago so any recent Gentoo etc. will
do fine without patches.

For n32, there's a provisional patch that needs reworking to get merged
(to have libc emulate DMULT etc. rather than the kernel/QEMU).[1]

Musl has a pending patch I posted[2] about a month ago. Musl is o32 only,
for all MIPS, but other than that it's got two significant advantages
over Gnu libc:

1. excellent support for static linking;

2. program sizes are often much smaller, more than 5x smaller observed.

An important detail is that since the R5900 FPU isn't compliant with
the IEEE 754 standard[3] it's normally wholly emulated by either libc or
the kernel, to comply with the MIPS psABI. The R5900 hardware FPU can
perhaps be enabled with a future R5900 ELF ABI annotation extension.[4]

Finally, the situation with the 128-bit R5900 general purpose registers
(GPRs) is not fully resolved with the Linux kernel. The best case
scenario, I believe, would be to have them available at all times.[5]

Fredrik

References:

[1] https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg00974.html
[2] https://www.openwall.com/lists/musl/2020/12/24/2
[3] https://github.com/frno7/linux/wiki/R5900-floating-point-unit-(FPU)
[4] https://github.com/frno7/linux/issues/3
[5] https://github.com/frno7/linux/issues/5

Re: [RFC PATCH 41/42] tests/acceptance: Test R5900 CPU with BusyBox from Sony PS2
Posted by Maciej W. Rozycki 4 years, 9 months ago
On Mon, 15 Feb 2021, Fredrik Noring wrote:

> For n32, there's a provisional patch that needs reworking to get merged
> (to have libc emulate DMULT etc. rather than the kernel/QEMU).[1]

 FWIW I think standard `-march=mips3' n32 Linux binaries need to work with 
the R5900, and therefore the kernel will have to emulate the missing part 
of the ABI (since years ago we chose to have it in the kernel rather than 
in a SIGILL handler).  The patch proposed only allows building GNU libc 
with `-march=r5900' which I find an optional feature (I don't know offhand
what advantages over `-march=mips3' would be there).

  Maciej