f4grx.net

Date: 20221109

68HC11 toolchain

Developing for the 68hc11 is a pleasure. Up to now, I have programmed my sys11 board in pure assembly. I could not find a satisfactory C compiler even if I know that gcc supported this cpu at some point.

However, after having a look at FUZIX, I noticed that Alan Cox did a port to the 68hc11 in 2021, and this project is obviously developed in C. Alan was nice enough to give me some clues on twitter (thank you!) so I'm glad to share a recipe with you to get a working gcc for hc11.

The main information is: The latest binutils still supports the hc11 (despite a bug in the simulator that cannot remap IO registers), but the latest gcc version to support the hc11 is 3.4.6.

The recipe

I have used this procedure on a 64-bit intel laptop with Linux Mint 21, and on a Raspberry Pi 4 with debian.

1. Get the latest binutils, at this moment it is binutils 2.39 (local)

2. Build binutils for 68hc11 (no need for root if you install in your own system root, eg $HOME/.local):

Note that you will need the texinfo package to complete the build, or make will not find 'makeinfo' during the build.

$ wget https://ftp.gnu.org/gnu/binutils/binutils-2.39.tar.gz
$ tar zxvf binutils-2.39.tar.gz
$ mv binutils-2.39 binutils-m68hc11-elf-2.39
$ cd binutils-m68hc11-elf-2.39
$ ./configure --prefix=$HOME/.local --target=m68hc11-elf
$ make
$ make install
$ ls ~/.local/bin
m68hc11-elf-addr2line  m68hc11-elf-c++filt  m68hc11-elf-ld      m68hc11-elf-objcopy  m68hc11-elf-readelf  m68hc11-elf-strip
m68hc11-elf-ar         m68hc11-elf-elfedit  m68hc11-elf-ld.bfd  m68hc11-elf-objdump  m68hc11-elf-size
m68hc11-elf-as         m68hc11-elf-gprof    m68hc11-elf-nm      m68hc11-elf-ranlib   m68hc11-elf-strings

3. Make sure this bin directory is in your path (m68hc11-elf-ar is required by gcc)

4. Get the latest gcc with support for 68hc11, it is gcc-core 3.4.6 (local)

5. Prepare the build environment:

$ wget https://ftp.gnu.org/gnu/gcc/gcc-3.4.6/gcc-core-3.4.6.tar.gz
$ tar zxvf gcc-core-3.4.6.tar.gz
$ mv gcc-3.4.6 gcc-m68hc11-elf-3.4.6
$ cd gcc-m68hc11-elf-3.4.6

6. If you want to build on a raspberry pi, the config.guess provided with gcc-3.4.6 is too old to detect the aarch64 architecture of the raspi. You can copy it from binutils:

$ cp ../binutils-m68hc11-elf-2.39/config.guess .

7. Patch gcc/collect2.c at line 1537 to add (S_IRUSR|S_IWUSR) as third parameter to open (required with the O_CREAT flag, see here for the error you get without patching)

8. Patch gcc/config/m68hc11/larith.asm at line 97 to read .space 2 instead of .dc.w 1 (to reserve uninitialized space for the virtual regs)

9. Build gcc for 68hc11, you will get a lot of warnings, this is ok:

$ ./configure --prefix=$HOME/.local --target=m68hc11-elf
$ make
$ make install
$ $ ls ~/.local/bin/
m68hc11-elf-addr2line  m68hc11-elf-c++filt  m68hc11-elf-gcc        m68hc11-elf-gcov   m68hc11-elf-ld.bfd   m68hc11-elf-objdump  m68hc11-elf-size
m68hc11-elf-ar         m68hc11-elf-cpp      m68hc11-elf-gcc-3.4.6  m68hc11-elf-gprof  m68hc11-elf-nm       m68hc11-elf-ranlib   m68hc11-elf-strings
m68hc11-elf-as         m68hc11-elf-elfedit  m68hc11-elf-gccbug     m68hc11-elf-ld     m68hc11-elf-objcopy  m68hc11-elf-readelf  m68hc11-elf-strip
$ ~/.local/bin/m68hc11-elf-gcc -v
Reading specs from /home/grx/.local/lib/gcc/m68hc11-elf/3.4.6/specs
Configured with: ./configure --prefix=/home/grx/.local --target=m68hc11-elf
Thread model: single
gcc version 3.4.6

That's it, you can explore the 68hc11 in C! We appreciate the fact that this old gcc has no complex dependency!