[PATCH 3/4] default-configs: Support o32 ABI with 64-bit MIPS CPUs

Philippe Mathieu-Daudé posted 4 patches 5 years, 2 months ago
Maintainers: Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aurelien Jarno <aurelien@aurel32.net>
[PATCH 3/4] default-configs: Support o32 ABI with 64-bit MIPS CPUs
Posted by Philippe Mathieu-Daudé 5 years, 2 months ago
MIPS o32 ABI on 64-bit CPUs looks like a ILP32-on-64bit data
model, allowing 64-bit arithmetic and data movement instructions.

This is the default ABI used by the "Sony Linux Toolkit for
Playstation 2".

As we don't know big-endian uses, we only introduce the
little-endian variant.

Inspired-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
Cc: Fredrik Noring <noring@nocrew.org>
Cc: Maciej W. Rozycki <macro@linux-mips.org>
Cc: Jürgen Urban <JuergenUrban@gmx.de>

Cc from https://lists.debian.org/debian-mips/2015/05/msg00014.html:
Cc: Mathieu Malaterre <malat@debian.org>
Cc: James Cowgill <james410@cowgill.org.uk>
Cc: YunQiang Su <wzssyqa@gmail.com>
Cc: David Daney <ddaney.cavm@gmail.com>
---
 docs/user/main.rst                                 | 3 +++
 default-configs/targets/mips64o32el-linux-user.mak | 7 +++++++
 2 files changed, 10 insertions(+)
 create mode 100644 default-configs/targets/mips64o32el-linux-user.mak

diff --git a/docs/user/main.rst b/docs/user/main.rst
index 8dfe232a3af..2cef1320ff3 100644
--- a/docs/user/main.rst
+++ b/docs/user/main.rst
@@ -211,6 +211,9 @@ Other binaries
 
    * ``qemu-mipsel`` executes 32-bit little endian MIPS binaries (MIPS O32 ABI).
 
+   * ``qemu-mips64o32el`` executes 64-bit little endian MIPS binaries (MIPS O32
+     ABI).
+
    * ``qemu-mips64`` executes 64-bit big endian MIPS binaries (MIPS N64 ABI).
 
    * ``qemu-mips64el`` executes 64-bit little endian MIPS binaries (MIPS N64
diff --git a/default-configs/targets/mips64o32el-linux-user.mak b/default-configs/targets/mips64o32el-linux-user.mak
new file mode 100644
index 00000000000..ecd57ff949f
--- /dev/null
+++ b/default-configs/targets/mips64o32el-linux-user.mak
@@ -0,0 +1,7 @@
+TARGET_ARCH=mips64
+TARGET_BASE_ARCH=mips
+TARGET_ABI_MIPSO32=y
+TARGET_ABI32=y
+TARGET_SYSTBL_ABI=o32
+TARGET_SYSTBL=../mips/syscall_o32.tbl
+TARGET_ALIGNED_ONLY=y
-- 
2.26.2

Re: [PATCH 3/4] default-configs: Support o32 ABI with 64-bit MIPS CPUs
Posted by Maciej W. Rozycki 5 years, 2 months ago
On Thu, 19 Nov 2020, Philippe Mathieu-Daudé wrote:

> MIPS o32 ABI on 64-bit CPUs looks like a ILP32-on-64bit data
> model, allowing 64-bit arithmetic and data movement instructions.
> 
> This is the default ABI used by the "Sony Linux Toolkit for
> Playstation 2".

 Please don't, not at least with a generic configuration (i.e. make it 
unambiguous that this is R5900-specific).  This only works with R5900 
because it does not implement the MIPS ISA correctly (e.g. see what $ra is 
set to with JAL/JALR/etc. in the kernel mode), and it is not supported by 
the standard Linux ABI.  Use n32 instead, which has the same functionality 
and is standard (and is also a better ABI in terms of performance).

 You'd probably need to implement all the R5900 addressing quirks for your 
proposed hack to match hardware, or otherwise you'll end up with emulation 
that creates its own reality.

  Maciej

Re: [PATCH 3/4] default-configs: Support o32 ABI with 64-bit MIPS CPUs
Posted by Philippe Mathieu-Daudé 5 years, 2 months ago
Hi Maciej,

On 11/19/20 5:45 PM, Maciej W. Rozycki wrote:
> On Thu, 19 Nov 2020, Philippe Mathieu-Daudé wrote:
> 
>> MIPS o32 ABI on 64-bit CPUs looks like a ILP32-on-64bit data
>> model, allowing 64-bit arithmetic and data movement instructions.
>>
>> This is the default ABI used by the "Sony Linux Toolkit for
>> Playstation 2".
> 
>  Please don't, not at least with a generic configuration (i.e. make it 
> unambiguous that this is R5900-specific).  This only works with R5900 
> because it does not implement the MIPS ISA correctly (e.g. see what $ra is 
> set to with JAL/JALR/etc. in the kernel mode), and it is not supported by 
> the standard Linux ABI.  Use n32 instead, which has the same functionality 
> and is standard (and is also a better ABI in terms of performance).

I think there are 2 different interests with the R5900. Fredrik sent a
series to run recent userland/kernel on a PS2. For QEMU, it would be
easier if these uses the n32 ABI indeed.

This series allows me to run unmodified binaries from the PS2 (built
maybe 20 years ago, apparently for a kernel 2.2).

>  You'd probably need to implement all the R5900 addressing quirks for your 
> proposed hack to match hardware, or otherwise you'll end up with emulation 
> that creates its own reality.

QEMU doesn't model well non-MIPS32 ISA, so the R5900 needs work indeed.

Laurent, maybe instead of 'mips64o32el-linux-user' we can call this
target 'r5900o32-linux-user', 'ps2-linux-user' or even 'r5900-ps2-user'
as Maciej said "it is not supported by the standard Linux ABI."

Also I'll see to mark it deprecated so it isn't built by default.

Thanks Maciej for your interest,

Phil.

Re: [PATCH 3/4] default-configs: Support o32 ABI with 64-bit MIPS CPUs
Posted by Fredrik Noring 5 years, 1 month ago
On Thu, Nov 19, 2020 at 04:45:29PM +0000, Maciej W. Rozycki wrote:
> On Thu, 19 Nov 2020, Philippe Mathieu-Daudé wrote:
> 
> > MIPS o32 ABI on 64-bit CPUs looks like a ILP32-on-64bit data
> > model, allowing 64-bit arithmetic and data movement instructions.
> > 
> > This is the default ABI used by the "Sony Linux Toolkit for
> > Playstation 2".
> 
>  Please don't, not at least with a generic configuration (i.e. make it 
> unambiguous that this is R5900-specific).  This only works with R5900 
> because it does not implement the MIPS ISA correctly (e.g. see what $ra is 
> set to with JAL/JALR/etc. in the kernel mode), and it is not supported by 
> the standard Linux ABI.  Use n32 instead, which has the same functionality 
> and is standard (and is also a better ABI in terms of performance).
> 
>  You'd probably need to implement all the R5900 addressing quirks for your 
> proposed hack to match hardware, or otherwise you'll end up with emulation 
> that creates its own reality.

I agree. Modern Linux kernel and GCC are important too. It seems both o32
and n32, with quirks, are generally accepted, but R5900 MMIs and other
special features are less clear:

For example, given the fact that the 128-bit MMIs are unconditionally
executable on R5900 hardware, a user may be forgiven to believe that they
always work. But unless the Linux kernel restores 128-bit registers in its
operating mode switches, which could be o32, there will be silent data
corruption (and ensuing frustration).

(For this reason I favour full register restores in all operating modes.)

Fredrik