Spare Time Labs 2.0



jDraft 2.0




Ten-Buck Furnace

H8S Bootloader

Camera Calibration


Myford VFD

Fun with HC08


printf II

Java Goes Native





New Furnace

New Furnace
Part II

Linux 101



Gas Fired Furnace

Down Memory Lane


Wheel Patterns






JNA Benchmark

Contact Info

gcc/H8S for dummies


I created this page as notes on how to install the wonderfull GNU tool chain for Hitachi H8S aka H8/300 in Windows.

I have some +25 years of programming experience under my belt. A conservative estimate would be that I've written well over 100.000 lines of deployed C,C++,Java and Pascal code, not to mention +10.000 lines of assembler for 68HC11,68000,Z80 and then some. I've been doing this on DOS,Unix,Windows not to mention half a dozen totally forgotten systems. I've programmed in FORTRAN, BASIC, Lisp, SmallTalk, I've dabled with COBOL,Python,Perl and then some. I've used about half a dozen C-compilers and twice as many editors. I've programmed embedded systems, desktop applications, drivers, database systems, compilers ..and so on and so on... and I still program daily.

And yet I have problems with Linux/GNU tools. The tools, the documentation and the people who create them assume such a familiarity with their way of doing things that the un-initiated is easily at loss. Also they expect everybody is doing-it-in-Linux, whereas the rest of us are realy stuck with Windows, no matter how hard we try to get rid of it. Of course, the right thing to do, would be to learn it all by heart and become one of the in-crowd.

Meanwhile, this page is for dummies like me.

BTW: Most of the substance of this page comes from , I've just provided my commentary and corrected some mistakes.

So, what we are trying to do here (like Ludwig XIV, I often talk about meself in 3rd person ;-) is to install a free cross compiler for H8S processos so that we write some code in Windows and dumpit to a H8S CPU for execution. GNU gcc is a free (in all senses of the word) C-compiler that somebody has been good enough patch to support the Hitatchi chip. GNU tools are designed to run in unix-like systems, nowdays usually in Linux. One thing to understand about all unixes is that there is no binary standard for executables and their interface to the OS. Thus you cannot use unix tools unless somebody has the source code and can compile the tools. Very often this somebody is you. Like in this case.

If you, like me, have to use Windows, you need a way to somehow emulate unix like enviroment. The MS-DOS box looks like it could be part of the solution and I believe that with Mingw tools it becomes one. For various reasons I'm more familiar with Cygwin, so I go along with that. Cygwin is a kind of Linux/Unix emulator that runs on top Windows and lets those familiar with Unix use their PC via the time honoured shell based command line interface. BTW I've written a Linux/Unix tutorial for dummies like me.

And to compile the gcc source code you need a compiler, which of course is distributed in source form. Bit of a chicken and egg problem, huh. Fortunatelly Cygwin comes with precompiled gcc compiler, which you can use to compile the compiler with different configuration so that it can be used as a cross compiler to compile code in Windows for execution in you target system.

Installing Cygwin

Installing Cygwin is pretty easy but even here the uninitiated can be stumped. First of all the whole package is huge, my installation takes up about 1.5 GB for almost 90.000 files in more thatn 4000 directories! Even with a megabit connection to the web it takes a considerable time. So you want to install only the development package that contains the compilers and other necessary tools.

Go to the Cygwin homepage or click here to install Cygwin . Use the setup wizard and accept default values until you get to the 'Select packages' screen. Maximize the window and on the 'Category' column locate the package 'Devel' (BTW Make sure that the text next to the button "View" says "Category", if not keep clicking that button until it does.). On the right side of that there is a text 'Default'. Keep clicking that text until it changes to 'Install'. Then go on and finish the install. On 100 kB/s connection and with my 2.4 GHz laptop this took less than half an hour, glad I did not need the whole of Cygwin (but then I already had the basic system installed)!

Some Cygwin Notes

Some notes on Cygwin might be usefull.

Cygwin usually installs in 'C:\cygwin'. Under that there are several directories that probably are familiar to unix users, such as 'bin','usr' and 'etc'. Most important is the directory 'home' under which the installer will create your home directory, based on your Windows user name. This is you home directory, ofthen refered to in command line as '~'. Thus in my case my home directory is (my user name is 'nyholku'):

If you need to refer to the Windows drives such as like 'C:' from within Cygwin you can do so by refering to the directory '/cygdrive/c'.

Locating the Necessary Files

Next you need to locate and download the following files from the web:

binutils-2.13.2.tar.bz2 gcc-core-3.1.1.tar.bz2 h8300-hms-gcc-3.1-1.patch newlib-1.11.0.tar.gz gdb-5.2.1.tar.bz2
Actually you may not need the 'gdb', better read this page first through.

Unfortunatelly I cannot tell you were to find these files, I used Google with the exact file names and was able to find them pretty quickly, but all from different sources -- funny thing. Be sure to get just these versions, otherwise you will probably run out of luck before you are finished. In which case you need to start allover again, and that ain't fun as this will take several hours before you are done. The voice of experience.

Note that downloading the archives is best done using ftp as sometimes (have not figured out when) a browser (don't want to name InternerExploder as the culprit) saves some files in bad format if accessing a gnu mirror using http. So what I did was I googled for 'filename funet' (funet is the local gnu mirror) which came up with a URL to directory containing that file and just edited the url from 'http://' to 'ftp://".

Put all these files into your home directory. You can of course put them anywhere you like but to make these instruction concrete I've described this the way I did it.

Fire up Cygwin and you will be taken to the glass-teletype Window with 'bash' shell with your home directory as your current directory.

Installing binutils

Binutils is a collection binary file handling tools that we will need. Enter the following command to extract all the source code. This will create a new directory 'binutils-2.13.2' in your home directory:
tar xfj binutils-2.13.2.tar.bz2
Now go to that directory and create a subdirectory for the object code that will be produced and go to that directory:
cd binutils-2.13.2
mkdir objdir
cd objdir
Next run a configuration script that will produce a makefile into the current directory:
../configure --prefix=/usr/local --target=h8300-hms
Now use the makefile to compile and install the binutils with the following commands:
make CFLAGS="-O2 -fomit-frame-pointer" all
make install
Note that this and all the 'make's may take hours. (In Linux you'd probably use 'gmake' and you would need root priviledges). The above 'make' will create a bunch of 'h8300-hms-*' executable files into the directory:
which is a customary place for user (not administrator) installed tools i.e. programs and which usually is in your command search path.

Installing gcc and newlib

I'm not quite sure if the following is necessary, but it was in the original instructions - I used it and suffered no ill effects.
export PATH=$PATH:/usr/local/bin
Enter the following commands to extract all the source code for the new lib and gcc. This will create two new directories 'newlib-1.11.0' and 'gcc-3.1.1' in your home directory:
cd ~
tar xfj gcc-core-3.1.1.tar.bz2
tar xfz newlib-1.11.0.tar.gz
Note that the options flags for the tar command are different for each file.

Now go to the gcc-3.1.1 directory and create a symbolic link that is used to refer to the 'newlib'.

cd gcc-3.1.1
ln -s ../newlib-1.11.0/newlib .
Now we need to apply the patches to the source code with the following commands:
patch -p1 < ../h8300-hms-gcc-3.1-1.patch
Now create a subdirectory for the object code that will be produced and go to that directory:
mkdir objdir
cd objdir
Next run a configuration script that will produce a makefile into the current directory:
../configure --prefix=/usr/local --target=h8300-hms --enable-languages=c --with-newlib
Now use the makefile to compile and install the binutils with the following commands:
make CFLAGS="-O2 -fomit-frame-pointer" all
make install #this has to be done by root
Again, this will take a long time, but will hopefully produce a working gcc cross compiler 'h8300-hms-gcc' in the '/usr/local/bin' directory.

You can test it by creating a simple C-program:

int main(int argc, char *argv[])
/* nothing much usefull can be done without any knowledge of the target enviroment and I/O */

If you save that to file main.c' then you can compile it with the following command:

h8300-hms-gcc main.c
Of course this does not produce anything usefull but proves that the compiler runs.

Installing gdb, the GNU debugger

Sorry, can't help you there, I've managed to live a meaningfull life without a debugger with just 'printf', a LED and an oscilloscope to help me by, so I've never used a debugger or ICE in an embedded project. See the above mentioned sourceforge site for some instructions if you want to try.

Oh, by the way

I wrote a script that does all of the above. Just drop it to your home directory along with archive files I mentioned above and run it as follows (this starts and (times as well) a new shell to run the script so you do not need to chmod the execution rights, layzy I know, but faster):
time sh ./makeh8sgcc

In my new Fujitsu Celsius laptop (2.4 GHz, 2 MB RAM) it took a litle over 27 minutes to run the script. Your mileage is probably different.

And, yes, all of the above have has been tested several times by copy pasting (to catch typos) the indidual commands from this page to a shell window and also the script run twice in a virgin cygwin and home directory. So it realy should work. I do dislike untested instructions.

Programming Embedded Systems

That's the subject of another page, I'm afraid.

Cheers, Kusti