アセンブラを開発するために、GNU binutils を使用しました。
当プロジェクトでは、binutils (gas, ld) の mist32 向け実装の開発・移植を行います。
ダウンロードは github から。まだリリースできるものはありません。
新たなアーキテクチャ向けに GNU binutils を移植するための資料を書いています。
現状 –enable-maintainer-mode を使うので以下のツール群 (README-maintainer-mode 参照)
その他に以下のツールが必要
Makefile.in をいじってる関係で、すべて automake しなおす。
libtool のバージョンがうまく合わないので、libtoolize もしなおす。もっといい方法有りそう。
$ cp -r /path/to/cgen/src/cgen /path/to/binutils-mist32 $ libtoolize -f -c --recursive;aclocal;autoreconf -i $ cd binutils;libtoolize -f -c;aclocal;autoreconf -i $ cd ../bfd;libtoolize -f -c;aclocal;autoreconf -i $ cd ../gas;libtoolize -f -c;aclocal;autoreconf -i $ cd ../ld;libtoolize -f -c;aclocal;autoreconf -i $ cd ../opcodes;libtoolize -f -c;aclocal;autoreconf -i $ cd ../ $ ./configure --target=mist32-elf --prefix=/usr/local --program-suffix=-mist32 --enable-maintainer-mode
とりあえず make all する。
うまく行かない場合は、いちど make distclean したあとに configure, make しなおす。
$ make all make[4]: *** `opcodes.pot' に必要なターゲット `../mist32-asm.c' を make するルールがありません. 中止.
cgen で mist32 に関するコードを自動生成。
$ cd opcodes $ make stamp-mist32
あとは、make all を再開して、make install しておわり。
.globl _start .text _start: clr r1 ;clear loop: clr r0 wh16 r1, hi(testdata) ;hi(): hi 16bit of 32bit wl16 r1, lo(testdata) ;lo(): low 16bit of 32bit lih r2, hi(testdata2) wl16 r2, lo(testdata2) ld32 r3, r1 ;load testadata ld32 r4, r2 ;load testdata2 add r3, r4 lil r5, -86 ;0xffaa => 0xffffffaa add r5, 0x55 1: add r0, 1 ;increment cmp r0, 10 ;10 times? br 1b, #ge ;jump backward 1, if signed equal or above b loop, #al .data testdata: .long 0xaaffffaa testdata2: .long 0x55000055
$ as-mist32 test.asm $ objdump-mist32 -D a.out a.out: file format elf32-mist32 Disassembly of section .text: 00000000 <_start>: 0: 0d c0 00 20 clr r1 00000004 <loop>: 4: 0d c0 00 00 clr r0 8: 0d 60 00 20 wh16 r1,0x0 c: 0d 40 00 20 wl16 r1,0x0 10: 0e e0 00 40 lih r2,0x0 14: 0d 40 00 44 wl16 r2,0x4 18: 10 40 00 61 ld32 r3,r1 1c: 10 40 00 82 ld32 r4,r2 20: 00 00 00 64 add r3,r4 24: 0e df f4 aa lil r5,-86 28: 00 10 08 b5 add r5,85 2c: 00 10 00 01 add r0,1 30: 00 d0 00 0a cmp r0,10 34: 14 3c ff fe br 2c <loop+0x28>,#seo 38: 14 50 00 00 b 0 <_start>,#al Disassembly of section .data: 00000000 <testdata>: 0: aa ff ff aa *unknown* 00000004 <testdata2>: 4: 55 00 00 55 *unknown* $ readelf-mist32 -h a.out ELF Header: Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, big endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: REL (Relocatable file) Machine: Open Architecture mist32 Version: 0x1 Entry point address: 0x0 Start of program headers: 0 (bytes into file) Start of section headers: 172 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 0 (bytes) Number of program headers: 0 Size of section headers: 40 (bytes) Number of section headers: 8 Section header string table index: 5
$ ld-mist32 -Tdata=0x00010000 -o test.o a.out $ objdump-mist32 -D test.o test.o: file format elf32-mist32 Disassembly of section .data: 00010000 <testdata>: 10000: aa ff ff aa *unknown* 00010004 <testdata2>: 10004: 55 00 00 55 *unknown* Disassembly of section .text: 00004000 <_start>: 4000: 0d c0 00 20 clr r1 00004004 <loop>: 4004: 0d c0 00 00 clr r0 4008: 0d 60 00 21 wh16 r1,0x1 400c: 0d 40 00 20 wl16 r1,0x0 4010: 0e e0 00 41 lih r2,0x1 4014: 0d 40 00 44 wl16 r2,0x4 4018: 10 40 00 61 ld32 r3,r1 401c: 10 40 00 82 ld32 r4,r2 4020: 00 00 00 64 add r3,r4 4024: 0e df f4 aa lil r5,-86 4028: 00 10 08 b5 add r5,85 402c: 00 10 00 01 add r0,1 4030: 00 d0 00 0a cmp r0,10 4034: 14 3c ff fe br 402c <loop+0x28>,#seo 4038: 14 50 10 01 b 4004 <loop>,#al
まだバグバグ。
デバッグ用 HEX の吐き方
$ ld-mist32 -Tdata=0x0400 -Ttext=0x0000 -o test.o a.out $ objcopy-mist32 -O binary test.o test.bin $ od -t xC -w4 -v test.bin | cut -s -d ' ' -f 2- | sed -e 's/ //g'