Run BSTC on Cubietruck, Raspberry PI, ...

yetiyeti Posts: 301
edited May 17 in Propeller 1 Vote Up0Vote Down
First guinea pig: A Cubietruck (aka: Cubie(board)3) running Cubieez/Wheezy.
(yeti@cubietruck0:9)/opt/bst/bin$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
NAME="Debian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"
ID=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.debian.org/";
SUPPORT_URL="http://www.debian.org/support/";
BUG_REPORT_URL="http://bugs.debian.org/";
(yeti@cubietruck0:9)/opt/bst/bin$ uname -a
Linux cubietruck0 3.4.79 #1 SMP PREEMPT Sat Nov 22 09:37:52 CST 2014 armv7l GNU/Linux
(yeti@cubietruck0:9)/opt/bst/bin$ qemu-i386 bstc -v
Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
Compiled for i386 Linux at 08:17:46 on 2009/07/20
So far I didn't find how to register "qemu-i386" as interpreter to execute Linux-i386-elf files (then recognised by magic, executed by binfmt_misc functions in kernel) without the need to type the prefix "qemu-i386". So for now I need to run "qemu-i386 bstc" explicitely:
(yeti@cubietruck0:3)/tmp$ cat huhu.spin
con
  _clkmode = xtal1|pll16x
  _clkfreq = 80_000_000
 
obj
  ser : "FullDuplexSerial"
 
pub main
  ser.start(31, 30, 0, 115200)
  ser.str(string("Huhu, OpenSpin!",13,10))
  waitcnt(_clkfreq + cnt)
  ser.stop
(yeti@cubietruck0:3)/tmp$ qemu-i386 /opt/bst/bin/bstc -b -Oa -L /opt/parallax.spin.src/spin huhu.spin 
Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
Compiled for i386 Linux at 08:17:46 on 2009/07/20
Loading Object huhu
Loading Object FullDuplexSerial
Program size is 568 longs
Compiled 182 Lines of Code in 1.073 Seconds
(yeti@cubietruck0:3)/tmp$ /opt/spinsim/bin/spinsim -b huhu.binary
Huhu, OpenSpin!

(yeti@cubietruck0:3)/tmp$ ls -l huhu.*
-rw-r--r-- 1 yeti yeti 572 Mai 14 18:18 huhu.binary
-rw-r--r-- 1 yeti yeti 207 Mai 14 18:15 huhu.spin
Well... hoping that OpenSpin will replace BSTC, this does not feel like a great success... it just feels like an additional layer colour covering some rust... but it may save the day... for someone... somewhen... so I think this hack(?) should be mentioned...

***some-minutes-of-elevator-music***

This is what I mean with registering with binfmt_misc to automagically select the right interpreter (here the one for Linux-elf-amd64 binaries):
(yeti@cubietruck0:3)~$ file ./Sync/openspin-linux-amd64  
./Sync/openspin-linux-amd64: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=0x765690cb1416e3d30c4f24bc459b9b9f82aaf30e, stripped
(yeti@cubietruck0:3)~$ $ ./Sync/openspin-linux-amd64 2>/dev/null
Propeller Spin/PASM Compiler 'OpenSpin' (c)2012-2016 Parallax Inc. DBA Parallax Semiconductor.
Version 1.00.80 Compiled on May  8 2017 04:19:27
Currently I don't see why it works for x86_64 but not x86 (32bit)...

***some-minutes-of-elevator-music***

Hmmmm...
It even works for an OpenSpin binary for x86...
(yeti@cubietruck0:3)~/Sync$ file openspin 
openspin: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=0xeadae60d8421e98dd858823e8c6e7729b7ddaaa2, stripped
(yeti@cubietruck0:3)~/Sync$ ./openspin 2>/dev/null
Propeller Spin/PASM Compiler 'OpenSpin' (c)2012-2016 Parallax Inc. DBA Parallax Semiconductor.
Version 1.00.80 Compiled on Jun  6 2016 12:42:51
Ok... the many years older BSTC binary must have a different "magic header" than the newer x86 binary... I need to read more about this topic to narrow it down more... and I'm getting optimistic that this will give us BSTC on RasPI and siblings without the need to prefix the calls with qemu-i386...

***some-minutes-of-elevator-music***

Ok...
(yeti@cubietruck0:3)/tmp$ cat xyzzy
#!/bin/sh
echo ':bstc-i386:M::\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff:/usr/bin/qemu-i386:' > /proc/sys/fs/binfmt_misc/register
(yeti@cubietruck0:3)/tmp$ sudo ./xyzzy
"xyzzy" has installed a "Lex-BSTC" in binfmt's rules:
(yeti@cubietruck0:3)/tmp$ cat /proc/sys/fs/binfmt_misc/bstc-i386
enabled
interpreter /usr/bin/qemu-i386
flags:
offset 0
magic 7f454c46010101030000000000000000020003
mask ffffffffffffffffffffffffffffffffffffff
...which handles files that start exactly like BSTC. I didn't want to screw up the other i386 rule, so an extra rule for BSTC seemed safer...
(-: There are lots of dead heroes and living cowards! :-)
(yeti@cubietruck0:3)/tmp$ /opt/bst/bin/bstc -v
Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
Compiled for i386 Linux at 08:17:46 on 2009/07/20
...and now BSTC can be run as transparently as any other binary and nobody will notice that it is an ancient i386 binary running on an ARMish system...

Edit@20170517

TODO:

Find how to set binfmt rules at boot on non-systemd-ish Linuxens.
https://www.freedesktop.org/software/systemd/man/binfmt.d.html looks like /etc/binfmt.d is a systemd invention.
Probably this will apply to pre-systemd Debian and systemd-free forks like Devuan.

The mask is not needed if it is only made of 0xff.
Windows.
No Source – No Go!
Please help: http://rosettacode.org/wiki/Category:Spin
Why Asimov's Laws of Robotics Don't Work - Computerphile
DNA is a four letter word.

Comments

Sign In or Register to comment.