Subject: Mips16 toolchain?

From: Johannes Stezenbach <[email-masked]>
Date: Mon, 25 Mar 2002 14:58:34 +0100

Hi all,

I'm currently using a toolchain based on binutils 2.12.90.0.1
and gcc-2.95.4-debian for my Linux kernel work.

Since I'm developing for an embedded target, I wanted to
check out mips16 code generation for the userspace apps.
Unfortunately my gcc aborts with an internal error
on even the simplest test program:

$ cat t16.c
extern int write(int fd, const char *buf, unsigned int size);

int main(int argc, char *argv[])
{
	write(0, "xy", 2);
	return 0;
}
$ mips-linux-gcc -mips16 -Wall -S t16.c
t16.c: In function `main':
t16.c:8: Internal compiler error:
t16.c:8: Unable to generate reloads for:
(call_insn 18 16 21 (parallel[ 
            (set (reg:SI 2 v0)
                (call (mem:SI (symbol_ref:SI ("write")) 0)
                    (const_int 16 [0x10])))
            (clobber (reg:SI 31 ra))
        ] ) 469 {call_value_internal2} (nil)
    (nil)
    (expr_list (use (reg:SI 6 a2))
        (expr_list (use (reg:SI 5 a1))
            (expr_list (use (reg:SI 4 a0))
                (nil)))))

I saw that the algorithmics toolchain (which Dominic Sweetman
offered to the Linux/MIPS community here a month ago) claims
to have full support for the mips16 instruction set.

My questions:
Does anyone here have experiences with mips16 and/or with the
algorithmics toolchain?
Is there working support for mips16 in any other gcc-version?
How about gcc-3.x from CVS?
Any other comments or recommendations regarding mips16?

glibc support wrt mips16 is not an issue for us, since we
plan to use the dietlibc (http://www.fefe.de/dietlibc/).
MIPS support for the dietlibc is still bit rough, though.

Regards,
Johannes

---

From: "Kevin D. Kissell" <[email-masked]>
Date: Mon, 25 Mar 2002 15:59:13 +0100

> Does anyone here have experiences with mips16 and/or with the

Yes.  Both Algorithmics and Green Hills embedded
tool chains support it reasonably well.  GHS has no
Linux target, though.  Algorithmics has been working
on one, but I'm not sure what it's current status is.

> Is there working support for mips16 in any other gcc-version?

Cygnus (now part of Red Hat) did the very first MIPS16
support for gcc, most of which found its way into the
main development/maintence stream.  But apparently
not enough of it, based on your experience.

> How about gcc-3.x from CVS?

No data there.

> Any other comments or recommendations regarding mips16?

MIPS16 requires more than just gcc support.
One needs a binutils that can distinguish a MIPS16
binary module (or function if you want to be fancy and 
mix/match within modules)  from a MIPS32/64 module
and perform fixups so that the right selections are made
between JAL and JALX on function invocations.  
If you've got that, you should not need a seperate 
MIPS16 libc.

To correctly support MIPS16, the Linux kernel does
need to be tweaked in those cases where user-mode
instructions are decoded and interpreted, as in
arch/mips/kernel/branch.c and unaligned.c.
I believe that code has been prototyped somewhere,
but it's not yet in any commonly used repository to
the best of my knowledge.  If you avoid throwing
executing non-instructions, performing unaligned 
accesses, etc, you should be able to tiptoe around
that deficiency.

            Regards,

            Kevin K.

---

From: Dominic Sweetman <[email-masked]>
Date: Mon, 25 Mar 2002 18:13:18 +0000

> on even the simplest test program:

No surprise, really.

> to have full support for the mips16 instruction set.

It does.  If you want an 'embedded' toolchain (to generate software to
run standalone or in general without position-independent shared
libraries) then it's a mature product.

We are also developing a compiler from the same source tree, but
configured for Linux.  That was the compiler we'll be looking for
beta-testers for in the next couple of months.

If you want to be able to build MIPS16 applications and then run them
on Linux, this is more challenging.  You have to build everything
static: then it works mostly, and some people at MIPS have built and
run some programs.

It seems likely we'll be doing some development work over the
spring/summer to make this more robust and less painful.

> How about gcc-3.x from CVS?

We believe not.  We'd like to converge our compiler (currently 2.96+
based) back to gcc 3.x so we can get most of our MIPS changes into the
mainstream tree, but it's not going to be easy.

--
Dominic Sweetman
Algorithmics Ltd
The Fruit Farm, Ely Road, Chittering, CAMBS CB5 9PH, ENGLAND
phone +44 1223 706200/fax +44 1223 706250/direct +44 1223 706205
http://www.algor.co.uk

---

From: Carsten Langgaard <[email-masked]>
Date: Tue, 26 Mar 2002 09:10:57 +0100

> accesses, etc, you should be able to tiptoe around

I don't think you need to tiptoe to get it working :-;
It should be easy to avoid non-instructions, unaligned accesses and co.
We have a few MIPS16 applications running using Algorithmics compiler
and a static non-PIC libc.

--
_    _ ____  ___   Carsten Langgaard   Mailto:[email-masked]
|\  /|||___)(___   MIPS Denmark        Direct: +45 4486 5527
| \/ |||    ____)  Lautrupvang 4B      Switch: +45 4486 5555
  TECHNOLOGIES     2750 Ballerup       Fax...: +45 4486 5556
                   Denmark             http://www.mips.com

---

From: Johannes Stezenbach <[email-masked]>
Date: Tue, 26 Mar 2002 19:53:36 +0100

First of all, many thanks for your help!

> t16.c:8: Internal compiler error:

Non-PIC mips16 compilation seems to work with gcc-2.95.4-debian:

  $ mips-linux-gcc -fno-pic -mno-abicalls -mips16 -Wall -c t16.c

yields a t16.o, which looks good when disassembled with
mips-linux-objdump.

Now I need a non-PIC version of libgcc to link against,
since mips-linux-ld cannot link PIC with non-PIC code.
I had built a non-PIC libgcc for earlier dietlibc experiments,
but discarded it in favor of a less experimental development
environment...

I feel I have to learn more about the Linux kernel's role
when executing mips16 code (unaligned.c etc.), and experiment
more with my toolchain, until I know what I'm really doing ;-)
I will post here when I have any meaningful results.

Regards,
Johannes