Cross-developmental environment for Hitachi H8 microprocessor family

Last updated 2001-08-14 6:32 pm


Introduction

To create an executable file for target CPUs, we need assembler, compiler, library, and linker. GNU provides powerful tool set, binutils (binary utilities) and gcc, which can generate object codes targetting diverse CPUs. GNU also presents a C library (glibc), but it is so huge and not suitable for embedding systems. So, I recommend yout to utilize newlib instead of glibc. In addition, there is a nice and sophisticated debugger, gdb, for helping software development (surprisingly, gdb simulates H8 processor!).

In the following section, I'll introduce a method to create cross-development tools for hitachi H8 microprocessor. Hitachi H8 family is one of the major CPUs being carried with PDAs and small computers (the famous PDA, Cybiko embarks H8S/2246). The core of H8 family is H8/300H series and there are usefult kits for evaluation. Recently, Hitachi announced low cost evaluation development kits (EDK), which comes with a development board and software (99 USD). Akizuki electronic merchant has been sold a famous kit, AKI-H8, in Japan (7800 JPY). These H8/300H based CPU boards are inexpensive (less than 100 USD) and would be the best teaching materials for students and newbie engineers.

Goal

Prepare a cross-development platform for H8/300H CPU using the latest versions of binutils, gcc, newlib, and gdb.

Getting source codes

binutils (GNU)

Anonymous CVS
     
# cvs -z 9 -d :pserver:anoncvs@anoncvs.cygnus.com:/cvs/src login ( enter "anoncvs" as the password ) # cvs -z 9 -d :pserver:anoncvs@anoncvs.cygnus.com:/cvs/src co binutils ( the latest source tree will be expanded in ../src ) # ls src COPYING README-maintainer-mode configure intl ltmain.sh mpw-config.in COPYING.LIB bfd configure.in ld makefile.vms mpw-configure COPYING.NEWLIB binutils etc libiberty missing mpw-install CVS config gas libtool.m4 mkdep opcodes ChangeLog config-ml.in gettext.m4 ltcf-c.sh mkinstalldirs setup.com MAINTAINERS config.guess gprof ltcf-cxx.sh move-if-change symlink-tree Makefile.in config.if include ltcf-gcj.sh mpw-README texinfo README config.sub install-sh ltconfig mpw-build.in ylwrap

gcc 3.x (GNU)

Anonymous CVS
     
# cvs -z 9 -d :pserver:anoncvs@gcc.gnu.org:/cvs/gcc login ( enter "anoncvs" as the password ) # cvs -z 9 -d :pserver:anoncvs@gcc.gnu.org:/cvs/gcc co gcc ( the latest source tree will be expanded in ../gcc ) # ls gcc COPYING README configure install-sh libobjc ltconfig symlink-tree COPYING.LIB boehm-gc configure.in libchill libstdc++ ltmain.sh texinfo CVS config contrib libf2c libstdc++-v3 maintainer-scripts xiberty ChangeLog config-ml.in etc libffi libtool.m4 missing ylwrap INSTALL config.guess fastjar libiberty ltcf-c.sh mkdep zlib MAINTAINERS config.if gcc libio ltcf-cxx.sh mkinstalldirs Makefile.in config.sub include libjava ltcf-gcj.sh move-if-change

newlib C library (cygnus/RedHat)

Anonymous CVS
     
# cvs -z 9 -d :pserver:anoncvs@anoncvs.cygnus.com:/cvs/src login ( enter "anoncvs" as the password ) # cvs -z 9 -d :pserver:anoncvs@anoncvs.cygnus.com:/cvs/src co newlib ( the latest source tree will be expanded in ../src/newlib ) # ls src/newlib COPYING README configure ltcf-c.sh mkdep mpw-install COPYING.LIB README-maintainer-mode configure.in ltcf-cxx.sh mkinstalldirs newlib COPYING.NEWLIB config etc ltcf-gcj.sh move-if-change setup.com CVS config-ml.in gettext.m4 ltconfig mpw-README symlink-tree ChangeLog config.guess install-sh ltmain.sh mpw-build.in texinfo MAINTAINERS config.if libgloss makefile.vms mpw-config.in ylwrap Makefile.in config.sub libtool.m4 missing mpw-configure

gdb (GNU)

Cross-making

I expanded the source trees in /usr/src as follows.

And I created links to them for easy-typing.

     
18:36:31 root@mebius /usr/src # ls -l binutils gcc newlib gdb lrwxrwxrwx 1 root root 16 Aug 7 18:36 binutils -> cvs-binutils/src lrwxrwxrwx 1 root root 11 Aug 7 18:36 gcc -> cvs-gcc/gcc lrwxrwxrwx 1 root root 10 Aug 7 18:36 gdb -> gdb-5.0/src lrwxrwxrwx 1 root root 14 Aug 7 18:36 newlib -> cvs-newlib/src

First of all, we have to build up binutils since gcc calls archiver, linker, and assembler.

All of GNU compliant tools are initially configured by "configure script" and it aytomatically creates a Makefile optimised for the host environment. There are two essential configure options, --target and --prefix.

--target specifies CPUs for output codes and --prefix tells make where the binaries, man files, headers, and libraries will be installed. The abbrebiation of Hitachi H8/300H processor is "h8300-hms" (hms means Hitachi Microprocessor Systems; GNU family currently supports many platforms). I assigned /usr/local/h8 to --prefix and executable files will be installed in /usr/local/h8/bin/.

NOTICE: You should perform builds in a directory out of the source tree. In this case, you can create multiple binaries (H8/300H, x86, MIPS, ARM, and so on) using single source directory.

NOTICE: CFLAGS is defined as "-g -O2" in original Makefile, and the "-g" option force the executable files to be enlarged so much. You can ignore this option by inserting CFLAGS="-O2" in make command line.

Now, it's time to make. After several minutes (4 mins in case of Celeron 300MHz), make completes successfully. Lastly, do not forget to update PATH environment variable, because gcc calls cross-compiled binutils tools in next step (if you forget it, gcc complains "h8300-hms-ar is not found").

     
$ mkdir /usr/local/h8 $ cd /usr/src/h8 $ mkdir build-binutils $ cd build-binutils $ /usr/src/binutils/configure --target=h8300-hms --prefix=/usr/local/h8 $ make CFLAGS="-O2" all $ su # make install $ export PATH=$PATH:/usr/local/h8/bin

There should be newly created 17 tools in /usr/local/h8/bin/ directory. All of executable file names are prefixed with target name.

     
19:26:33 root@mebius /usr/src/h8/build-binutils # ls -l /usr/local/h8 total 5 drwxrwxr-x 8 root root 200 Aug 7 19:26 . drwxr-xr-x 19 root staff 464 Aug 7 19:26 .. drwxrwxr-x 2 root root 656 Aug 7 19:26 bin drwxrwxr-x 4 root root 96 Aug 7 19:26 h8300-hms drwxrwxr-x 2 root root 136 Aug 7 19:26 include drwxrwxr-x 2 root root 200 Aug 7 19:26 lib drwxrwxr-x 3 root root 72 Aug 7 19:26 man drwxrwxr-x 2 root root 48 Aug 7 19:26 share 19:27:21 root@mebius /usr/src/h8/build-binutils # ls -l /usr/local/h8/bin total 3654 drwxrwxr-x 2 root root 656 Aug 7 19:26 . drwxrwxr-x 8 root root 200 Aug 7 19:26 .. -rwxr-xr-x 1 root root 204642 Aug 7 19:26 h8300-hms-addr2line -rwxr-xr-x 2 root root 177830 Aug 7 19:26 h8300-hms-ar -rwxr-xr-x 2 root root 361754 Aug 7 19:26 h8300-hms-as -rwxr-xr-x 1 root root 61992 Aug 7 19:26 h8300-hms-c++filt -rwxr-xr-x 1 root root 159355 Aug 7 19:26 h8300-hms-coffdump -rwxr-xr-x 1 root root 50852 Aug 7 19:26 h8300-hms-gasp -rwxr-xr-x 2 root root 347184 Aug 7 19:26 h8300-hms-ld -rwxr-xr-x 2 root root 215351 Aug 7 19:26 h8300-hms-nm -rwxr-xr-x 1 root root 348455 Aug 7 19:26 h8300-hms-objcopy -rwxr-xr-x 1 root root 411607 Aug 7 19:26 h8300-hms-objdump -rwxr-xr-x 2 root root 177829 Aug 7 19:26 h8300-hms-ranlib -rwxr-xr-x 1 root root 162244 Aug 7 19:26 h8300-hms-readelf -rwxr-xr-x 1 root root 154559 Aug 7 19:26 h8300-hms-size -rwxr-xr-x 1 root root 176041 Aug 7 19:26 h8300-hms-srconv -rwxr-xr-x 1 root root 153259 Aug 7 19:26 h8300-hms-strings -rwxr-xr-x 2 root root 348454 Aug 7 19:26 h8300-hms-strip -rwxr-xr-x 1 root root 193882 Aug 7 19:26 h8300-hms-sysdump

Next target is gcc-3.x. There are three additional configure options you should consult.

Default Makefile produces codes for C++, JAVA, Fortran77, and Chill in addtion to ANSI C. Since almost of us do not need these optional languages, let's ignore them by using --enable-languages option (C is essential and we can not exclude it).

glibc is too huge and complex for small systems, so we have to choice another compact C library. newlib is one of the most hard-tested library, and gcc can be adopted for it by --with-newlib option. In this case, you have to specify --with-headers option. gcc itself creates libgcc.a and libiberty.a libraries, and standard include files are required for their compilation. Standard headers files for newlib are collected in its source tree (newlib/libc/include/).

NOTICE: --with-headers option is very important one for cross-making. Do not forget it!

As described above, we should ignore "-g" option (CFLAGS="-O2") and limit supporting languages to C and C++ (LANGUAGES="c c++"). Be careful, please specify LANGUAGES option in both of "make" and "make install". Celeron 300MHz took about 14 mins for completion.


$ cd /usr/src/h8
$ mkdir build-gcc
$ cd build-gcc
$ /usr/src/gcc/configure --target=h8300-hms --prefix=/usr/local/h8 --enable-languages="c++"
  --with-newlib --with-headers=/usr/src/newlib/newlib/libc/include
$ make CFLAGS="-O2" LANGUAGES="c c++"
$ su
# make LANGUAGES="c c++" install

Now, you will find 4 addtional files including gccbug, h8300-hms-c++, h8300-hms-cpp, and h8300-hms-g++.


20:24:48 root@mebius /usr/src/h8/build-gcc # ls -l /usr/local/h8/bin
total 3990
drwxrwxr-x    2 root     root          808 Aug  7 20:24 .
drwxrwxr-x    9 root     root          224 Aug  7 20:24 ..
-rwxr-xr-x    1 root     root        15390 Aug  7 20:24 gccbug
-rwxr-xr-x    1 root     root       204642 Aug  7 19:26 h8300-hms-addr2line
-rwxr-xr-x    2 root     root       177830 Aug  7 19:26 h8300-hms-ar
-rwxr-xr-x    2 root     root       361754 Aug  7 19:26 h8300-hms-as
-rwxr-xr-x    2 root     root        79718 Aug  7 20:24 h8300-hms-c++
-rwxr-xr-x    1 root     root        62100 Aug  7 20:24 h8300-hms-c++filt
-rwxr-xr-x    1 root     root       159355 Aug  7 19:26 h8300-hms-coffdump
-rwxr-xr-x    1 root     root        80037 Aug  7 20:24 h8300-hms-cpp
-rwxr-xr-x    2 root     root        79718 Aug  7 20:24 h8300-hms-g++
-rwxr-xr-x    1 root     root        50852 Aug  7 19:26 h8300-hms-gasp
-rwxr-xr-x    1 root     root        78342 Aug  7 20:24 h8300-hms-gcc
-rwxr-xr-x    2 root     root       347184 Aug  7 19:26 h8300-hms-ld
-rwxr-xr-x    2 root     root       215351 Aug  7 19:26 h8300-hms-nm
-rwxr-xr-x    1 root     root       348455 Aug  7 19:26 h8300-hms-objcopy
-rwxr-xr-x    1 root     root       411607 Aug  7 19:26 h8300-hms-objdump
-rwxr-xr-x    2 root     root       177829 Aug  7 19:26 h8300-hms-ranlib
-rwxr-xr-x    1 root     root       162244 Aug  7 19:26 h8300-hms-readelf
-rwxr-xr-x    1 root     root       154559 Aug  7 19:26 h8300-hms-size
-rwxr-xr-x    1 root     root       176041 Aug  7 19:26 h8300-hms-srconv
-rwxr-xr-x    1 root     root       153259 Aug  7 19:26 h8300-hms-strings
-rwxr-xr-x    2 root     root       348454 Aug  7 19:26 h8300-hms-strip

--target-help tells you target-specific gcc options. -mh option generates codes for H8/300H processor.


21:10:19 root@mebius /usr/src/h8/build-gcc # h8300-hms-gcc --target-help

Target specific options:
  -malign-300               Use H8/300 alignment rules
  -mno-h                    Do not generate H8/300H code
  -mh                       Generate H8/300H code
  -mrelax                   Enable linker relaxing
  -mslowbyte                Consider access to byte sized memory slow
  -mno-quickcall            Do not use registers for argument passing
  -mquickcall               Use registers for argument passing
  -mint32                   Make integers 32 bits wide
  -mno-s2600                Do not generate H8/S2600 code
  -ms2600                   Generate H8/S2600 code
  -mno-s                    Do not generate H8/S code
  -ms                       Generate H8/S code

There are undocumented target specific options as well.

Target specific options:
  -malign-300               Use H8/300 alignment rules
  -mno-h                    Do not generate H8/300H code
  -mh                       Generate H8/300H code
  -mrelax                   Enable linker relaxing
  -mslowbyte                Consider access to byte sized memory slow
  -mno-quickcall            Do not use registers for argument passing
  -mquickcall               Use registers for argument passing
  -mint32                   Make integers 32 bits wide
  -mno-s2600                Do not generate H8/S2600 code
  -ms2600                   Generate H8/S2600 code
  -mno-s                    Do not generate H8/S code
  -ms                       Generate H8/S code

There are undocumented target specific options as well.
  no emulation specific options.

Ok, now we are ready to cross-compile newlib package. The procedure is just same as binutils. Celeron 300MHz took about 8 mins for the job.


$ cd /usr/src/h8
$ mkdir build-newlib
$ cd build-newlib
$ /usr/src/newlib/configure --target=h8300-hms --prefix=/usr/local/h8
$ make CFLAGS="-O2" all
$ su
# make install

Five kinds of libraries (different data length) are installed in /usr/local/h8/h8300-hms/lib/. C Run Time start up file crt0.o and linker scripts are also provided.


21:29:45 root@mebius /usr/src/h8/build-newlib # ls -R /usr/local/h8/h8300-hms/lib/
/usr/local/h8/h8300-hms/lib/:
total 1251
drwxrwxr-x    5 root     root          224 Aug  7 21:28 .
drwxrwxr-x    6 root     root          152 Aug  7 21:28 ..
-rw-r--r--    1 root     root          712 Aug  7 21:28 crt0.o
drwxrwxr-x    3 root     root          168 Aug  7 21:28 h8300h
drwxrwxr-x    3 root     root          168 Aug  7 21:28 h8300s
drwxrwxr-x    2 root     root          480 Aug  7 19:26 ldscripts
-rw-r--r--    2 root     root       442730 Aug  7 21:28 libc.a
-rw-r--r--    2 root     root       442730 Aug  7 21:28 libg.a
-rw-r--r--    1 root     root       377620 Aug  7 21:28 libm.a

/usr/local/h8/h8300-hms/lib/h8300h:
total 1058
drwxrwxr-x    3 root     root          168 Aug  7 21:28 .
drwxrwxr-x    5 root     root          224 Aug  7 21:28 ..
-rw-r--r--    1 root     root          728 Aug  7 21:28 crt0.o
drwxrwxr-x    2 root     root          144 Aug  7 21:28 int32
-rw-r--r--    2 root     root       401190 Aug  7 21:28 libc.a
-rw-r--r--    2 root     root       401190 Aug  7 21:28 libg.a
-rw-r--r--    1 root     root       270704 Aug  7 21:28 libm.a

/usr/local/h8/h8300-hms/lib/h8300h/int32:
total 1073
drwxrwxr-x    2 root     root          144 Aug  7 21:28 .
drwxrwxr-x    3 root     root          168 Aug  7 21:28 ..
-rw-r--r--    1 root     root          728 Aug  7 21:28 crt0.o
-rw-r--r--    2 root     root       406152 Aug  7 21:28 libc.a
-rw-r--r--    2 root     root       406152 Aug  7 21:28 libg.a
-rw-r--r--    1 root     root       271788 Aug  7 21:28 libm.a

/usr/local/h8/h8300-hms/lib/h8300s:
total 1054
drwxrwxr-x    3 root     root          168 Aug  7 21:28 .
drwxrwxr-x    5 root     root          224 Aug  7 21:28 ..
-rw-r--r--    1 root     root          728 Aug  7 21:28 crt0.o
drwxrwxr-x    2 root     root          144 Aug  7 21:28 int32
-rw-r--r--    2 root     root       399414 Aug  7 21:28 libc.a
-rw-r--r--    2 root     root       399414 Aug  7 21:28 libg.a
-rw-r--r--    1 root     root       270014 Aug  7 21:28 libm.a

/usr/local/h8/h8300-hms/lib/h8300s/int32:
total 1065
drwxrwxr-x    2 root     root          144 Aug  7 21:28 .
drwxrwxr-x    3 root     root          168 Aug  7 21:28 ..
-rw-r--r--    1 root     root          728 Aug  7 21:28 crt0.o
-rw-r--r--    2 root     root       404326 Aug  7 21:28 libc.a
-rw-r--r--    2 root     root       404326 Aug  7 21:28 libg.a
-rw-r--r--    1 root     root       271096 Aug  7 21:28 libm.a

/usr/local/h8/h8300-hms/lib/ldscripts:
total 61
drwxrwxr-x    2 root     root          480 Aug  7 19:26 .
drwxrwxr-x    5 root     root          224 Aug  7 21:28 ..
-rw-r--r--    1 root     root         1159 Aug  7 19:26 h8300.x
-rw-r--r--    1 root     root         1159 Aug  7 19:26 h8300.xbn
-rw-r--r--    1 root     root         1159 Aug  7 19:26 h8300.xn
-rw-r--r--    1 root     root          901 Aug  7 19:26 h8300.xr
-rw-r--r--    1 root     root         1027 Aug  7 19:26 h8300.xu
-rw-r--r--    1 root     root         1445 Aug  7 19:26 h8300h.x
-rw-r--r--    1 root     root         1445 Aug  7 19:26 h8300h.xbn
-rw-r--r--    1 root     root         1445 Aug  7 19:26 h8300h.xn
-rw-r--r--    1 root     root         1180 Aug  7 19:26 h8300h.xr
-rw-r--r--    1 root     root         1306 Aug  7 19:26 h8300h.xu
-rw-r--r--    1 root     root         1445 Aug  7 19:26 h8300s.x
-rw-r--r--    1 root     root         1445 Aug  7 19:26 h8300s.xbn
-rw-r--r--    1 root     root         1445 Aug  7 19:26 h8300s.xn
-rw-r--r--    1 root     root         1180 Aug  7 19:26 h8300s.xr
-rw-r--r--    1 root     root         1306 Aug  7 19:26 h8300s.xu

Let's enjoy with the cross-tools. h8300-hms-gcc and h8300-hms-as really output native H8/300 code. Congratulations!


21:38:03 root@mebius /usr/src/h8 # cat test.c
int main()
{
 int a,b;

 a = 2;
 b = 123;
 a *= b;
 return(a);
}

21:38:40 root@mebius /usr/src/h8 # h8300-hms-gcc test.c
21:38:47 root@mebius /usr/src/h8 # h8300-hms-gcc -S test.c
21:39:11 root@mebius /usr/src/h8 # ls -l
total 25
drwxrwxr-x    5 root     root          248 Aug  7 21:39 .
drwxr-xr-x   69 root     root         2984 Aug  7 18:42 ..
-rwxrwxr-x    1 root     root         2752 Aug  7 21:36 a.out
drwxrwxr-x   12 root     root          392 Aug  7 19:20 build-binutils
drwxrwxr-x    7 root     root          304 Aug  7 19:35 build-gcc
drwxrwxr-x    5 root     root          216 Aug  7 21:17 build-newlib
-rw-------    1 root     root           65 Aug  7 21:36 test.c
-rw-rw-r--    1 root     root          461 Aug  7 21:39 test.s
21:39:12 root@mebius /usr/src/h8 # cat test.s
;       GCC For the Hitachi H8/300
;       By Hitachi America Ltd and Cygnus Support


        .file   "test.c"
        .section .text
        .align 1
        .global _main
_main:
        push    r6
        mov.w   r7,r6
        subs    #2,sp
        subs    #2,sp
        mov.w   #2,r2
        mov.w   r2,@(-2,r6)
        mov.w   #123,r2
        mov.w   r2,@(-4,r6)
        mov.w   @(-4,r6),r1
        mov.w   @(-2,r6),r0
        jsr     @___mulhi3
        mov.w   r0,r2
        mov.w   r2,@(-2,r6)
        mov.w   @(-2,r6),r2
        mov.w   r2,r0
        adds    #2,sp
        adds    #2,sp
        pop     r6
        rts
        .end
        .ident
"GCC: (GNU) 3.1 20010806 (experimental)"

Lastly, we construct gdb package. h8300-hms-gdb and h8300-hms-run will be newly installed in /usr/local/h8/bin/. Celeron 300MHz took about 5 mins.


$ cd /usr/src/h8
$ mkdir build-gdb
$ cd build-gdb
$ /usr/src/gdb/configure --target=h8300-hms --prefix=/usr/local/h8
$ make CFLAGS="-O2" all
$ su
# make install

Now, all the players gathered in our system.