GNU binutils patches

= FR80 processor patch =

Command line options
Provides following command line options in GNU assembler (GAS) for FR30 architecture: -mfr30                  disable support for the fr80 instruction set -mfr80                  support the fr80 instruction set --enforce-aligned-data  check data placement to be aligned correctly Last option provides following checks:
 * byte variables/constants in code segment produce a warning
 * all half-word and word vairables/constants are ensured to be aligned to 2 or 4 bytes respectively

Examples of usage
fr30-elf-objdump.exe -b binary --adjust-vma=0x40000 -D /c/1/b640101b.bin -EB -mfr80 .macro WORD name,val .balign 4 \name: .word  \val .endm .macro HWORD name,val .balign 2 \name: .hword  \val .endm .set var_absolute, 0x8F9C332C .text _start: .global _start srch0  R1      bra label1 label1: srch1  R1     srchC   R1      srchC   R1      bra label2 .balign 4 .word 33 label2: ldi:32 string1, R1    ldi32 var_absolute,R0 BORH 1,@R0 ret .data string1: .asciz "hi" HWORD num1, 0x1234 string2: .ascii "a??" WORD num2,0x5678 string3: .byte 'A' string4: .ascii "CC" WORD Lnum3,0x6666 WORD ptr, string2 string5: .ascii "ujjkk" string6: .ascii "abcd" .end
 * disassemble firmware binary
 * sample assembler program test.s:
 * 1) -- macros for my variables (all access must be aligned !!!)
 * 2) macro to define Word variable
 * 1) macro to define Half-Word variable
 * 1) variable at absolute address
 * 1) -- main program
 * 1) entry point
 * 1) FR30 only
 * 2)    copst 3,0x22,CR1,R2
 * 3)    ldres @R1+,4
 * 4)    stres 6,@R1+
 * 1) FR80 only

fr30-elf-as.exe -mfr80 --enforce-aligned-data ./test.s -o test.o fr30-elf-objdump.exe -xdsp -mfr80 ./test.o fr30-elf-ld.exe -o test -Ttext 0x40000 test.o fr30-elf-objcopy.exe -O binary test test.bin
 * assemble for FR80 to object file (relocatable)
 * disassemble object file
 * link firmware to ELF executable (not relocatable)
 * convert ELF executable to binary file

Accessing data
FR80 processor has no instructions for direct data access. Only indirect addressing is possible: the data address must be first loaded into register. Alignment rules apply for data access (see below).

Alignment issues
Following rules apply for FR80: If code address got uneven:  At the time of execution of the instruction, bit0 of the program counter (PC) automatically becomes "0", and is always at an even address. --- Fujitsu: FR80 Family Programming Manual, 2.3.1 If data address got unaligned:  If the specified address is not a multiple of 4, the lower two bits of the address are not set to "00" forcibly. There is no guarantee of operation when the specified address is not a multiple of 4. --- Fujitsu: FR80 Family Programming Manual, 2.3.2
 * instruction code of must be placed always 2-bytes aligned.
 * data address for word (32-bit) instructions must be always 4-bytes aligned.
 * data address for half-word (16-bit) instructions must be always 4-bytes aligned.

GAS is designed to provide any possible usage and rely that user knows how to correct align. GNU C compiler (GCC) that uses GAS for assembling, produces always correct alignment.

FR80 processor do not generate "unaligned data" exception in error case. This makes finding these places in code really painfull job. So you are strongly adviced to make use of "--enforce-aligned-data" GAS option.

WARNING 1: GAS do not check data address in register to be aligned.

WARNING 2: GAS do not automatically align data.

'''WARNING 3: NikonEmulator has at the moment no runtime checks !!! So runing the code in Emulator doesn't mean that alignment is correct.'''

Reorder
GAS for FR30/FR80 do not reorder data or code. So appropriate directives are not implemented: .set reorder .set noreorder WARNING: Please do not mix this with directive: .set reorder, It has nothing in common with alignment.

Building binutils for FR80 processor
Read this only if you want to compile binutils for FR80 from source code. Once you have got EXEs, you do not need MinGW/MSYS and other packages anymore.

On Windows: install MSYS/MinGW
This is only needed for building binutils.
 * 1) Download and install MSYS 1.0.11 from http://downloads.sourceforge.net/project/mingw/ This will provide make, sh and all other tools necessary for build on Windows platform.
 * 2) Edit msys\1.0\etc\fstab to include following lines: c:/mingw	/mingw&#13;c:/src		/src
 * You can place here your pathes to MingGW compiler and source directory, but spaces are not allowed in path.
 * 1) download and install/unzip MinGW GCC compiler 3.4.5 for Windows and binutils for Windows: gcc-core-3.4.5-20060117-3.tar.gz&#13;mingw-runtime-3.14.tar.gz&#13;w32api-3.14-mingw32-dev.tar.gz&#13;binutils-2.20.1-2-mingw32-bin.tar.gz

Download patch
It is in our project repository under GNU Patches\fr80-binutils-2.22.pat.

Apply patch

 * 1) Download GNU binutils 2.22 and extract to your source directory (usually /src/binutils-2.22/...).
 * 2) Download patch and save it in parent directory of binutils.
 * 3) In your sh-shell change to directory where subdirectory binutils-2.22 exists: cd /src
 * 4) You can test if patch can be applied by command (without really changing files): patch -p2 --dry-run < fr80-binutils-2.22.pat
 * Normal output without errors, looks like:
 * patching file binutils-2.22/bfd/archures.c&#13;patching file ...&#13;...
 * 1) Apply patch: patch -p2 < fr80-binutils-2.22.pat
 * (Linux/UNIX users should use instead tr -d '\r' < fr80-binutils-2.22.pat | patch -p2)

Compile binutils

 * 1) set correct timezone by export TZ=MET-1DST
 * or add this command to your startup file ~/.profile for MSYS shell
 * 1) start MSYS: cd msys\1.0\bin&#13;..\msys.bat
 * 2) type in msys terminal mkdir -p /tmp/build/binutils&#13;cd /tmp/build/binutils
 * This will be your build directory.
 * 1) configure binutils /src/binutils-2.22/configure --target=fr30-elf --prefix=/c/mingw/fr30-elf --disable-nls
 * Creates Makefile in current directory for building target "fr30-elf" with install directory c:\mingw\fr30-elf and disabled internationalisation support.
 * 1) build and install binaries make&#13;make install
 * 2) strip executables, because they contain too much debug information and full symbol table: strip -S --strip-unneeded /c/mingw/fr30-elf/bin/*.exe

FAQ
Q: Which platform was used to create patch ?

A: I am really happy that we have MinGW - thank you guys! It is superb and makes life easier for cross-platform developers. Nowdays everybody can take part in development for virtually any target. All instructions were tested on MinGW/MSYS platform.

Q: Why auto-align option was not implemented ?

A: GAS directives .align/.palign/.balign are very complex and powerfull. The best way to implement auto-alignment feature is to call s_align intern for each command in assembler of FR30/FR80. This will emulate as directives above was found in input assembler stream. But this is not possible, because of internal design. In fact several assemblers already call it in very ugly way. It is too complicated, unflexible and buggy if each CPU assembler in binutils will have own version of .align/.palign/.balign implementation. On another side, GCC compiler do not need auto-alignment. It aligns data by itself.

Q: Why so many static variables are used in patch ?

A: This is the only way you have, because context information is not passed to callbacks implemented for each particular CPU assembler. It is not a best-school of software design, but all binutils source use a lot of static variables. In fact binutils library is designed for single-processor, single-task and single-job. For example, you can't disassemble two different binaries at the same time, even if you use one processor and only having one task in your application.

Q: Why there is no GAS testsuite for FR80 ?

A: Even if I make one with CGEN, most people will not be able to use it. You need DeJaGNU to execute testsuite that in turn needs Exact and Tcl/Tk. At the time this patch was created Exact and DeJaGNU were not compilable on MinGW platform. If you find the way, let me know.

Q: What about macro commands ?

A: I do not know if somebody except me uses FR80 assembler :) So I have no idea which are used on this platform, except existing ldi8, ldi20, ldi32 which are actually synonyms of ldi:8, ldi:20, ldi:32. Those were defined to make life easier for Emacs users.

Q: Any details about implementation ?

A: Assembler/disassembler for FR30 are implemented as formal CPU description written in Scheme (fr30.cpu with helper fr30.opc). It is translated by CGEN into C code. Most instructions of FR80 are same as FR30, but there are some new and unique, and some other which are obsoleted. These differences were implemented in Scheme files by adding new "mach" and introducing instruction attributes that allow separation of opcodes based on machine type. Also command line options for switching machine type, alignment check and new ELF header flags for FR80 were added.

Q: I have more questions ?

A: Just post them in our Forums.