GNU gcc patches

= FR80 processor patch =

Command line options
Provides following command line options in GNU C compiler (GCC) for FR30 architecture: -mfr30                  disable support for the fr80 instruction set -mfr80                  support the fr80 instruction set

Preprocessor macros
There are two new preprocessor macros, defined if code is generated to FR80: __FR80__ __fr80__

Notes on usage

 * at the moment .data and .bss sections are linked at the end of .text code sections. So using global or static variables/arrays you must take care yourself if correspondent memory locations is writable and supply correct address for linker if necessary (use fr30-elf-objdump.exe to display executable sections)
 * compiling C code only, it is recommended to link with crt0naked.o instead of crt0.o, because it doesn't include initialisation of static objects and excepion sections.
 * calling linker, supply your crtXXXX.o at first place, or the start address of executable will be not 0.
 * if you let gcc link (for example by command gcc test.c -o test) then default C++ startup stubs are linked in and sections .data/.bss (with read-write access) are created, even if your code is C only. In this case start address of executable will be not 0.
 * C++ code can be compiled and linked correctly using default crt0.o. But absense of new, delete and throw make it pretty useless right now.
 * for C++ code linked, you need a custom linker script to get start address 0. Otherwise, section .init is placed at the begining of executable

Examples of usage
fr30-elf-gcc.exe -mfr80 -c test1.c -o test1.o set LIB_DIR=C:\mingw\fr30-elf\lib\gcc\fr30-elf\3.4.5\fr80 fr30-elf-ld.exe -o test1 -Ttext 0x40000 -L%LIB_DIR% %LIB_DIR%\crt0naked.o test1.o test2.o -lgcc fr30-elf-gcc.exe -E -dM - <NUL
 * compile C to object file for FR80 processor
 * Link objects to executable (mention crt0 object to be first so it gets start address +0x40000)
 * Print predefined compiler macros (for Windows)

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

Download patch
It is in our project repository under GNU Patches\r80-gcc-3.4.5mingw.pat.

Apply patch

 * 1) Download and extract following MinGW packages into your source directory (usually in /src/gcc-3.4.5-20060117-2/...): gcc-core-3.4.5-20060117-2-src.tar.gz&#13;gcc-g++-3.4.5-20060117-2-src.tar.gz
 * Last archive adds subdirectories /src/gcc-3.4.5-20060117-2/cp/* and /src/gcc-3.4.5-20060117-2/libstdc++-v3/*.
 * 1) Download patch file and save it in /src.
 * 2) In your sh-shell execute following commands cd /src&#13;patch -p2 < fr80-gcc-3.4.5mingw.pat
 * (Linux/UNIX users should use instead tr -d '\r' < fr80-gcc-3.4.5mingw.pat | patch -p2)

Compile gcc 3 for FR30
export PATH=${PATH}:/c/mingw/fr30-elf/bin /src/gcc-3.4.5-20060117-2/configure --target=fr30-elf --prefix=c:/mingw/fr30-elf --enable-languages=c,c++ --with-gcc --with-gnu-ld --with-gnu-as --with-stabs --disable-nls --without-headers make all-gcc make install-gcc find c:/mingw/fr30-elf -name *.exe -exec strip -S --strip-unneeded {} \; strip -S --strip-unneeded /c/mingw/fr30-elf/bin/fr30-elf-gcc-3.4.5
 * 1) Set correct timezone by export TZ=MET-1DST
 * or add this command to your startup file ~/.profile for MSYS shell or another sh-shell environment
 * 1) Select gcc install directory. It is used by GCC internally and can't be change after build. I selected c:\mingw\fr30-elf.
 * 2) Build FR80 binutils and copy complete install directory to your gcc install directory (or use same gcc install path). You will get following directory tree: C:\MINGW\FR30-ELF&#13;+---bin&#13;+---share&#13;|  +---info&#13;|   \---man&#13;|       \---man1&#13;\---fr30-elf&#13;    +---bin&#13;    \---lib&#13;        \---ldscripts
 * 3) start MSYS: cd msys\1.0\bin&#13;..\msys.bat
 * 4) Create build directory type in sh-shell terminal mkdir -p /tmp/build/gcc&#13;cd /tmp/build/gcc
 * This will be your build directory.
 * 1) Execute following commands (note path extension command, because build process uses FR80 binutils):

FAQ
Q: Why patch is for old GCC 3 ?

A: First of all, because author is familiar with GCC v3. Other reasons are: GCC v3 is easier to build and is much smaller.

Q: I get an error message that -lsim library is not found ?

A: For no known reason, gcc links some targets by default to libsim.a (simulator). I didn't remove usage of simulator, because this can break gcc automated testsuite execution. You can supress this by giving compiler command line option -mno-lsim. This option is not need if you call LD directly.

Q: I get an error message that -lc library is not found ?

A: If you do not have standard C library, you can supress linkage by setting compiler command line option -nodefaultlibs. This option is not need if you call LD directly.

Q: How about C++ ?

A: g++ compiler will be generated correctly. But missing implementations of new/delete functions it is barely usable. Default linking with provided crt0.o will even call static objects constructors.

Q: What about C++ exceptions ?

A: .eh_frame section will be correctly generated. The problem is only missing implementation of throw that is usually OS specific.

Q: Any details about implementation ?

A: GCC FR30 RTL templates were tested to use only instructions common to FR30 and FR80 processors. New machine command line option -mfr80 will be passed automatically to all tools like GAS. It is essential for generation correct .o files and to ensure only FR80 assembler instructions will be accepted from both GCC templates and inline assembler macros. Then makefile for processor dependent gcclib was extended to build two MULTILIB components: main libraries/objects for FR30 under .../lib/ and FR80 variant libraries/objects in .../lib/fr80/.

Q: I have more questions ?

A: Just post them in our Forums.