Debian 8 (jessie)㧠SH4 ç¨ã®ã¯ãã¹ç°å¢ãä½ã£ãã®ã§ï¼æé ãã¡ã¢ãã¾ãï¼ãã®è¨äºã¯ http://d.hatena.ne.jp/pyopyopyo/20141120 ããã¼ã¹ã«ï¼ææ°ã®æ å ±ãå çãããã®ã§ãï¼
æ¦è¦
- host㯠amd64
- target㯠sh4
ã§ã
大ã¾ããªæé ã¯
- æé 1) hostã« targetç¨ã®ããããã¡ã¤ã«ãã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«
- æé 2) hostã« targetç¨ã®binutilsãã¤ã³ã¹ãã¼ã«
- æé 3) hostã« targetç¨ã®gccãã¤ã³ã¹ãã¼ã«
ã¨ãªãã¾ã
target ãARMã§ããã°debianãæ£å¼ã«ãµãã¼ããã¦ããããä½æ¥ã¯ç°¡åã§ãï¼ããã sh4ã¯æ£å¼ã«ãµãã¼ãããã¦ããªãã®ã§ï¼ä»¥ä¸ã®æé ã§å°ã å¼·å¼ã«ä½æ¥ãã¾ãã
æé 1) targetç¨ã®ã©ã¤ãã©ãªé¡ã®ã¤ã³ã¹ãã¼ã«
sh4 ã¢ã¼ããã¯ãã£ã¯ debian ã§ã¯æ£å¼ã«ãµãã¼ãããã¦ããªãã®ã§ï¼å°ã é¢åãããæé ãå¿ è¦ã§ãï¼
ã¾ã sh4 ã追å ãã¾ã
$ sudo dpkg --add-architecture sh4
次㫠/etc/apt/sources.list ã«ä¸è¨ã®ï¼è¡ã追å ãã¾ã
deb [arch=sh4] http://ftp.debian-ports.org/debian unstable main deb [arch=sh4] http://ftp.debian-ports.org/debian unreleased main
[arch=hoge] ã¨æ¸ãã¦ããã¨ï¼ã¢ã¼ããã¯ãã£ãhogeã®å ´åã ãï¼è¨å®ãæå¹ã«ãªãã¾ã
ä¸åº¦æ å ±ãæ´æ°ãã¾ã
sudo apt-get update
ç¶ãã¦ï¼debian-ports.org ã®ç½²åãã¤ã³ã¹ãã¼ã«
sudo apt-get install debian-ports-archive-keyring sudo apt-get update
ããã§ftp.debian-ports.orgã§é å¸ããã¦ããsh4ã®ãã¤ããªãæµç¨ã§ããããã«ãªãã¾ãï¼ãã¨ãã°
apt-get download libc6:sh4
ãªã©ã¨ããã¨ï¼ sh4 ç¨ã®debããã±ã¼ã¸ããã¦ã³ãã¼ãã§ãã¾ãï¼
次㫠dpkg-cross ã¨ãããã¼ã«ãã¤ã³ã¹ãã¼ã«ãã¾ã
$ sudo apt-get install dpkg-cross
dpkg-cross 㯠debããã±ã¼ã¸ãã¯ãã¹ç°å¢ç¨ã®ããã±ã¼ã¸ã«å¤æãããã¼ã«ã§ã
ãã¨ãã° sh4 ç¨ã® libc6ã®ããã±ã¼ã¸ libc6_2.19-19_sh4.deb ã¯
$ apt-get download libc6:sh4 $ dpkg-cross -A -M -a sh4 -b libc6_2.19-19_sh4.deb
㧠libc6-sh4-cross_2.19-19_all.debãã«å¤æã§ãã¾ãï¼å¤æå¾ã¯
$ sudo dpkg -i libc6-sh4-cross_2.19-19_all.deb
ã§ï¼ã¤ã³ã¹ãã¼ã«ã§ãã¾ã
ãã®æé ã§ï¼GCCã®ãã«ãã«å¿ è¦ãªããã±ã¼ã¸
ãã¤ã³ã¹ãã¼ã«ãã¾ã
Debian 7以å㯠apt-cross, xapt ã§å¤æï¼ã¤ã³ã¹ãã¼ã«ä½æ¥ãèªååã§ããã®ã§ããï¼ debian 8 ã§apt-crossãªã©ã obsolete ã«ãªã£ãããï¼å°éã«æåã¤ã³ã¹ãã¼ã«ãã¾ãï¼
æé 2) targetç¨ã®ã©ã¤ãã©ãªé¡ã®ç¢ºèª
sh4-corssãæä¾ãããã¡ã¤ã«ã¯ /usr/sh4-linux-gnu ãã£ã¬ã¯ããªä»¥ä¸ã«é ç½®ããã¾ã
éè¦ãªãã¡ã¤ã«ã¯ï¼ä»¥ä¸ã®ãã£ã¬ã¯ããªã«é ç½®ãããããããã¡ã¤ã«ã¨ã©ã¤ãã©ãªã§ã
fileã³ãã³ãã使ã£ã¦ï¼ãã¤ããªã®ãããã確èªããã¨
$ file /usr/sh4-linux-gnu/lib/crt1.o /usr/sh4-linux-gnu/lib/crt1.o: ELF 32-bit LSB relocatable, Renesas SH, version 1 (SYSV), for GNU/Linux 2.6.32, not stripped
ã¨ããæã㧠ã¿ã¼ã²ããã® sh4 ç¨ã®ãã¤ããªã§ãããã¨ã確èªã§ãã¾ã
æé 3) targetç¨ã®binutilsãã¤ã³ã¹ãã¼ã«
$ sudo apt-get build-dep --no-install-recommends binutils $ apt-get source binutils $ cd binutils-* $ TARGET=sh4 fakeroot dpkg-buildpackage -b -us -uc $ cd ..
åºæ¥ä¸ãã£ãdebããã±ã¼ã¸ã®å 容ã確èªãã¦ã¿ã¾ã
$ dpkg --contents binutils-sh4-linux*.deb
ä¾ãã° ãªã³ã«(ld)㯠/usr/bin/sh4-linux-gnu-ldï¼asã¯/usr/bin/sh4-linux-gnu-asã¨è¨ãæãã§ã³ãã³ãã®é ã« sh4-linux-gnu- ãä»ä¸ããã¦ããã°æåã§ãï¼
åé¡ãªããã°ã¤ã³ã¹ãã¼ã«ãã¾ã
$ sudo dpkg -i binutils-sh4-linux*.deb
æé 4) targetç¨ã®GCCãã¤ã³ã¹ãã¼ã«
sh4 ç¨ã®GCC ãã¤ã³ã¹ãã¼ã«ãã¾ã
ããã§
- debianã§ã¯ sh4 ã¯ãã¾ãã¡ã³ãããã¦ããªã
- ä»åï¼ç§ãå¿ è¦ã¨ããã®ã¯ Cã³ã³ãã¤ã©ã ãã§ï¼ gcjãobjc++çã¯ä¸è¦
ã¨ããçç±ãã GCC㯠debããã±ã¼ã¸ãç¨ããï¼èªåã§ãã«ããããã¨ã«ãã¾ãã
ã¤ã³ã¹ãã¼ã«å
ã¯å¿µã®çº /opt ã¨ãã¾ãï¼ã¤ã¾ãGCCã®configure æã«ã¯ --prefix=/opt ãã¤ãï¼
ã¢ã³ã¤ã¹ãã¼ã«æ㯠/opt 以ä¸ãæ¶ãã°OKï¼ã¨ãããã¨ã«ãªãã¾ã
$ sudo mkdir -p /opt
MultiArch ã®ã«ã¼ã«ã§ã¯ ã¯ãã¹ã³ã³ãã¤ã«ç¨ã®ã©ã¤ãã©ãªãããã㯠/usr/sh4-linux-gnu 以ä¸ã«é ç½®ãã¾ãï¼ --prefix=/opt ãã¤ããGCC㯠/opt/sh4-linux-gnu ãè¦ããã¨ã«ãªãã®ã§ï¼ã·ã³ããªãã¯ãªã³ã¯ãè²¼ãã¾ã
$ sudo ln -s /usr/sh4-linux-gnu /opt
次㫠GCCã®ã½ã¼ã¹ã³ã¼ãããã¦ã³ãã¼ããã¾ãï¼GCC 5.2.0 ã使ãã¾ãã
$ wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-5.2.0/gcc-5.2.0.tar.bz2
$ tar xfj gcc-5.2.0tar.bz2
$ cd gcc-5.2.0
ä½æ¥ç¨ãã£ã¬ã¯ããªãä½æãã¾ã
$ mkdir gccbuild $ cd gccbuild
念ã®çºï¼ä¸å ·åãèµ·ãããããªç°å¢å¤æ°éããªã»ãããã¾ã
unset CC unset CXX unset FC unset CCACHE_DIR
ã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«
sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev
../gcc-5.2.0/configure --prefix=/opt --enable-languages=c --target=sh4-linux-gnu --disable-libssp --disable-libgomp --disable-nls --disable-libatomic --disable-libquadmath --with-cpu=sh4 --with-multilib-list=m4,m4-nofpu --disable-threads
ãªãã·ã§ã³ã¯ãããã
- --enable-languages=c Cã®ã³ã³ãã¤ã©ã ããã«ã
- --target=sh4-linux-gnu
- --with-cpu=sh4 ã¿ã¼ã²ããã sh4 ã«
- --with-multilib-list=m4,m4-nofpu FPUæã¨ç¡çã®SH4ã«å¯¾å¿ããããã
- --disable-??? ä¸è¦ãªãã®ã¯ç¡å¹ã«ãã
ã¨ããæãã§ã
ãã«ããã¦ï¼ã¤ã³ã¹ãã¼ã«ãã¾ã
$ make -j16
$ sudo make install
Cã®ã³ã³ãã¤ã©ã ããªã®ã§ï¼ãã«ãã¯ããã«çµããã¾ãï¼æå
ã®ãã·ã³ã§ã¯ 3åç¨åº¦ã§çµããã¾ãã
step5) åä½ç¢ºèª
ã¾ããã¼ã¸ã§ã³çã確èªãã¾ããã
$ export PATH=/opt/bin:$PATH $ sh4-linux-gnu-gcc -v
次ã«ç°¡åãªã³ã¼ããã³ã³ãã¤ã«ãã¦ã¿ã¾ã
$ cat hoge.c int main() { return 123; } $ sh4-linux-gnu-gcc hoge.c $ file ./a.out ./a.out: ELF 32-bit LSB executable, Renesas SH, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, not stripped
ã¿ã¼ã²ããã« a.out ãã³ãã¼ãã¦ï¼å®è¡ãã¦ã¿ã¾ãï¼
$ ./a.out $ echo $? 123
åé¡ãªããã°ï¼æ¬¡ã®æ®µé㧠printf ã試ãã¦ã¿ã¾ã
$ cat hoge.c #include <stdio.h> int main() { printf("Hello C\n"); return 0; } $ sh4-linux-gnu-gcc hoge.c
ã¤ãã§ã« strip ã³ãã³ãã試ãã¦ã¿ã¾ã
$ sh4-linux-gnu-strip a.out
sh4-linux-gnu- ãã¤ããã®ãå¿ããã«ï¼
以ä¸ã§ï¼ã¯ãã¹ç°å¢ã®ã»ããã¢ããã¯å®äºã§ã