Adding a C library to the 68000 SBC

      No Comments on Adding a C library to the 68000 SBC

There are more than a few different choices of C library for running on small systems. Some candidate C libraries for the MINI000 board include:

  • Newlib is an extremely popular choice for small systems. It is relatively complete. Not quite complete enough for a modern desktop Unix system, but almost. It specifically targets bare-bones (AKA freestanding) 68K systems, and allows the insertion of “glue” to implement talking to the actual hardware, or a kernel.
  • Dietlibc is also pretty popular, but it appears to only target the Linux kernel on multiple architectures (x86, arm, etc)
  • Baselibc is a new one I found in my travels. It does not target an OS, leaving the implementation of stdio to hooks. It is limited, amongst other things, to functions which do not interact with files, so it has a printf() but no fopen().

Initially I went with Newlib. It’s configure command is fairly trivial:

../newlib-3.1.0/configure --prefix=/usr/local/m68k-elf/ \
    --target=m68k-elf --enable-newlib-nano-malloc \
    --enable-lite-exit --enable-multilib --disable-newlib-fvwrite-in-streami \
    --enable-newlib-nano-formatted-io

Out of the box (ie. with no customisations) it basically works great. I built my old test programs which I had running on the MAXI09 board – the prime number checker and the dates of Easter calculator – everything worked very nicely.

Unfortunately there is one problem: the library is large, relatively speaking. Even trivial programs which make use of only a couple of calls are tens of KByte in size. A program that uses printf() ends up being about 50 KBbyte, just small enough to fit into the two 32 KByte EEPROMs.

The –enable-X options on the configure command line were an attempt to reduce the size of the resultant binaries, but they didn’t really help much.

If I ever implement an OS kernel with dynamic linking for my 68K boards, I will almost certainly come back to Newlib.

In the quest for a more compact library, I’ve searched around and have ran into a little project called Baselibc, and it builds nicely with the 68000 GCC cross compiler. It is extremely small – it’s usually used on small ARM boards – and essentially contains only functions which can be implemented without an OS: string functions, memory functions, and the venerable printf(). It is therefore extremely compact: linking in printf() and a few other functions yields programs which only take up about 5KB in the EEPROMs.

I have contributed back to the project some trivial changes to make it build cleanly for the 68k-elf target.

A nice illustration of what I’ve got working so far, and it’s trivial but still cool, is a Mandelbrot renderer:

This makes use of floating point maths, and printf(). I plan to look around for more examples of small-ish C programs which only make use of memory and string C library functions and have a go at porting them, just for fun.

But for the more immediate future I plan to return to working on my machine-code monitor. Once I have a basic monitor working I can then look at hooking up peripheral ICs to the board via some breadboard  and test them out, before I start to flesh out my VGA display generator, which I briefly touched on in an earlier post

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.