[Vm-dev] [unix] Unrecognized opcode in FFI on PowerPC SPE

Eliot Miranda eliot.miranda at gmail.com
Tue Nov 27 18:43:45 UTC 2012


Bert,


On Mon, Nov 26, 2012 at 5:16 AM, Bert Freudenberg <bert at freudenbergs.de>wrote:

>
>
> On 2012-11-25, at 17:03, "David T. Lewis" <lewis at mail.msen.com> wrote:
>
> >
> > To summarize my understanding of this issue (see below for background):
> >
> > - powerpcspe is variant of powerpc that lacks certain parts of the
> powerpc
> > instruction set, as explained here:
> http://wiki.debian.org/PowerPCSPEPort
> >
> > - The FFI plugin has architecture-specific assembler modules that set
> > up the entry points for FFI calls. The assembly module for powerpc is
> > platforms/unix/plugins/SqueakFFIPrims/ppc-sysv-asm.S
> >
> > - The ppc-sysv-asm.S module uses one or more instructions ('lfd',
> possibly
> > others) that are not available on  the powerpcspe processor, and the the
> > module cannot be compiled on powerpcspe.
> >
> > - The solution for the Debian build is to not build the FFI plugin when
> > compiling for powerpcspe. This is done by passing the
> --without-SqueakFFIPrims
> > option to the cmake configure when building on powerpcspe.
> >
> > - The configuration is done in a file called debian/rules, and the
> provided
> > squeak-vm.patch is a patch for that rules file. This file is not part of
> > the Squeak VM platforms sources and is presumably maintained externally
> > by the Debian folks.
> >
> > - The right way to fix the build problem in the platforms sources would
> be
> > to modify platforms/unix/plugins/SqueakFFIPrims/config.cmake to disable
> > the FFI plugin for powerpcspe at configure time. This is probably easy to
> > do, although I do not have a way to try it myself.
> >
> > - Extra credit: If someone wanted FFI to work on powerpcspe, the way to
> make
> > this happen would be to write a variation of ppc-sysv-asm.S for
> powerpcspe
> > and add it to config.cmake.
> >
> > Dave
>
> Instead of disabling FFI it might be possible to fall back to libffi, as
> is done for some other architectures (e.g. ARM).
>

IMO, much better would be to add PPC support to ThreadedFFIPlugin.  This is
a framework for cross-platform FFI, currently instantiated for x86, but it
has all the hooks one needs to write a PPC interface.  This uses minimal
assembler, essentially only the occasional asm statement, e.g. to set the
flag that indicates a call has active floating-point parameters, or to
adjust the stack pointer after an alloca.  Being written in terms of the C
library's alloca stack allocator to create the outgoing argument frame it
is a) more efficient since arguments are not copied from a marshalling
space to the outgoing stack frame as occurs in the old FFI, and b)
reentrant, since there is no static area used for marshalling.

I've written support for PPC for VisualWorks in the same way so I do know
this approach does work and would be happy to help anyone with a PPC
mahcine who was interested in biting the bullet.  The tricky issues are the
need to pass register arguments alongside the stacked arguments, and the
need to avoid overwriting the marshalling area of the alloca'ed argument
frame when calling functions involved in marshalling arguments.  The first
issue is solved by always calling the external function as if it had 8
register arguments, and passing 8 arguments, hence loading the argument
registers.  The second issue is solved by over allocating and cutting back
the stack with an asm statement just before the call.

You'll find that the framework was written with this in mind even if the
support for PPC and ARM (and SPARC and AXP and MIPS, all of which I wrote
for the VisualWorks VM) isn't complete yet.

cheers
Eliot

>
> - Bert -
>
>
>
> >
> > On Mon, Nov 19, 2012 at 06:38:10PM +0100, Bert Freudenberg wrote:
> >>
> >> Begin forwarded message:
> >>
> >>> Resent-From: Roland Stigge <stigge at antcom.de>
> >>> From: Roland Stigge <stigge at antcom.de>
> >>> Subject: Bug#693633: squeak-vm: FTBFS on powerpcspe (asm stfd/lfd)
> >>> Date: 18. November 2012 21:10:04 MEZ
> >>> Resent-To: debian-bugs-dist at lists.debian.org
> >>> To: Debian Bug Tracking System <submit at bugs.debian.org>
> >>> Resent-Cc: Debian Squeak Team <
> pkg-squeak-devel at lists.alioth.debian.org>
> >>> Reply-To: Roland Stigge <stigge at antcom.de>, 693633 at bugs.debian.org
> >>>
> >>> Package: squeak-vm
> >>> Version: 1:4.4.7.2357-1.1
> >>> Severity: wishlist
> >>> Tags: sid patch
> >>> User: debian-powerpcspe at breakpoint.cc
> >>> Usertags: powerpcspe
> >>>
> >>> Hi,
> >>>
> >>> squeak-vm FTBFS on powerpcspe [1] like this:
> >>>
> >>> [ 82%] Building ASM object
> SqueakFFIPrims/CMakeFiles/SqueakFFIPrims.dir/<C2><AB>PKGBUILDDIR<C2><BB>/unix/plugins/SqueakFFIPrims/ppc-sysv-asm.S.o
> >>> /PKGBUILDDIR/unix/plugins/SqueakFFIPrims/ppc-sysv-asm.S: Assembler
> messages:
> >>> /PKGBUILDDIR/unix/plugins/SqueakFFIPrims/ppc-sysv-asm.S:109: Error:
> Unrecognized opcode: `lfd'
> >>> [...]
> >>>
> >>> There are some asm statements that only work on powerpc but not on
> powerpcspe.
> >>>
> >>> Attaching a patch that fixes it by disabling the SqueakFFIPrims plugin
> on
> >>> powerpcspe.
> >>>
> >>> Thanks,
> >>>
> >>> Roland
> >>>
> >>>
> >>> [1] http://wiki.debian.org/PowerPCSPEPort
> >>>
> >>> -- System Information:
> >>> Debian Release: wheezy/sid
> >>> APT prefers unstable
> >>> APT policy: (500, 'unstable'), (1, 'experimental')
> >>> Architecture: amd64 (x86_64)
> >>>
> >>> Kernel: Linux 3.5.0 (SMP w/4 CPU cores)
> >>> Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
> (ignored: LC_ALL set to en_GB.UTF-8)
> >>> Shell: /bin/sh linked to /bin/dash
> >
> >
> >>>
> >>
> >
>
>


-- 
best,
Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20121127/84f34ade/attachment-0001.htm


More information about the Vm-dev mailing list