I had to fiddle around a little bit, but finally got it working.

A few notes to anyone trying to get it working:
- Recent binutils have msp430 support built in.  You an just
  "./configure --target=msp430" and go.
- The msp430 CVS tree contains files that should be copied into
  (overwriting) the GCC tree before building.  After doing this,
  "./configure --target=msp430" will work.

  You want gcc-3.2.3, and the files from the "gcc-3.3"
  directory.  This is a bit confusing, but it's correct.

  I haven't tried to see if they'll work with the released 3.3.


I actually got a bit fancier, and used the Debian "toolchain-source"
utilities to build standard binutils-msp430 and gcc-msp430 packages
that give me a nicely working /usr/bin/msp430-gcc.

This is quite simple.  Parts prefixed with "sudo" need to be done
as rootl the rest can be done as an ordinary user.


0) sudo apt-get install toolchain-source
1) cd /usr/src
        Or whatever directory you prefer.
2) tpkg-make msp430
        Creates binutils-msp430-$VERSION and gcc-msp430-$VERSION
3) cd binutils-msp430-$VERSION
4) debuild
        If you don't have a gpg key, this will puke at the end about a
        missing gpg key (needed to sign the Debian packages), but that
        can be ignored.  The installable package has already been built.
5) sudo debi
        This will actually install .deb package, which was built
        before the key error.

Building the C compiler is a bit trickier:

6) cd ../gcc-msp430-$VERSION
7) debuild
8) AFTER debuild has unpacked the source, and WHILE it is
   patching it (a few minutes into the process), SUSPEND
   (^Z) the process.
9) ls src/gcc/config
        There should be a bunch of subdirectories here named after
        compiler targets.  If there aren't, you are too early;
        resume and go back to step 8.
9) Copy the mspgcc files over.
        I found that "mv" complains about existing directories, so I
        did it with tar:
        9a) pushd ~/mspgcc/gcc/gcc-3.3
        9b) tar cvf /tmp/mspgcc-patches .
        9c) popd
        9d) cd src
        9e) tar xvf /tmp/mspgcc-patches
        9f) cd ..
10) fg
        Resume the debuild process.  This should give the same error
        as in the binutils, above.  If you get a complaint about
        an unsupported target, you waited too long to pause and patch;
        go back to step 7 and start again.
11) sudo debi



Anyway, having done that, I tried a few code snippets and have a few glitches
to report.  I'm sorry that I'm only looking this gift horse in the mouth and
complaining, but hopefully these are repeatable.

=== 1) Optimization misses

unsigned
sum2(unsigned a, unsigned b)
{
        return a+b;
}

unsigned
sum4(unsigned a, unsigned b, unsigned c, unsigned d)
{
        return a+b+c+d;
}

unsigned
sum5(unsigned a, unsigned b, unsigned c, unsigned d, unsigned e)
{
        return a+b+c+d;
}

msp430-gcc -O -S produced the desired code for the first function:

> sum2:
>       add     r14, r15
>       ret

But produced pretty nasty code for the second:

> sum4:
>       push    r11
>       mov     r15, r11 
>       mov     r14, r15 
>       mov     r13, r14 
>       add     r11, r15
>       add     r14, r15
>       add     r12, r15
>       pop     r11
>       ret

I discovered that msp430-gcc -O2 did better:

> sum4:
>       add     r14, r15
>       add     r13, r15
>       add     r12, r15
>       ret

This is odd, because -O2 is usually the same thing as -O.
Is it -O1 here?


However, the code produced for the third function, even with
-O9 -fomit-frame-pointer, could use some work:

> sum5:
>       push    r11
>       mov     #llo(4), r11 
>       add     r1, r11
>       add     r14, r15
>       add     r13, r15
>       add     r12, r15
>       add     @r11, r15
>       pop     r11
>       ret

This is setting up r11 as a frame pointer, and accessing the fifth
argument from there.

Reply via email to