Re: rust for mipsel / mips32

Havard Eidnes <[email protected]>
Newsgroups gmane.os.netbsd.ports.mips.devel
Message-ID <[email protected]>
>>>      * cpu = "mips3", an earlier mistake.  Produces "of course" 64-bit
>>>        instructions, so gives "illegal instruction" on e.g. cobalt and
>>>        32-bit-only CPUs.  Despite this also being marked "highly experimental"
>>>        in llvm, this build completed.
>>
>> -march=mips3 -mabi=32?
>
> Hmm, possibly.  I'll look into whether / how that can be
> expressed in the rust target specification.

I've made an attempt with this rust target specification:

------------------------------
use crate::abi::Endian;
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
    let mut base = super::netbsd_base::opts();
    base.max_atomic_width = Some(32);
    base.cpu = "mips3".into();

    Target {
        llvm_target: "mipsel-unknown-netbsd".into(),
        pointer_width: 32,
        data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(),
        arch: "mips".into(),
        options: TargetOptions {
            features: "+soft-float,+m32".into(),
            mcount: "__mcount".into(),
            endian: Endian::Little,
            ..base
        },
    }
}
------------------------------

stored in compiler/rustc_target/src/specs/mipsel_unknown_netbsd.rs

However, note that I have not been able to find a comprehensive
overview of exactly what "features" I can turn on and what's
supported for which target, and no other rust mips targets try to
do anything like the above, so this is a bit of a "fumbling in
the dark" for me at the moment.

However, both on a Cobalt raq2 with an RM5200 CPU (but running an
9.2 O32 user-land) and a MIPSSIM emulator with a 24Kc CPU (with an
9.3 O32 user-land), in both cases I end up with an illegal
instruction trap when doing "cargo --help".

The executable of "cargo" is marked with

  Flags:    0x20001107, noreorder, pic, cpic, 32bitmode, o32, mips3

On both machines gdb refuses to cooperate and

a) cannot successfully read the core file I get from trying to do
   "cargo --help" (results in an internal consistency check
   causing gdb to want to dump a core of itself)
b) produces a different trap (trace/breakpoint) in an apparently
   un-mapped portion of memory according to "info target" when
   run under gdb

I don't know if this is because gdb in 9.2 and 9.3 is broken or if
there is something else going on, or whether a newer user-land would
improve matters.

So I don't quite know which instruction is at fault.  An earlier
attempt with just "mips3" without "+m32" succeeded the build, but
produced, perhaps expectedly, 64-bit instructions, and those are
"disabled" if you run the MIPSSIM NetBSD kernel.

I've uploaded the rust-bin package built with the above target
spec to

  ftp://ftp.netbsd.org/pub/NetBSD/misc/he/rust-bin-1.66.0-mips3-m32-fails.tgz

if anyone else wants to take a closer look at the executables and
can help identify the instruction causing the "illegal instruction"
fault.

Regards,

- Håvard
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.