Menu:

Design and Sell Merchandise Online for Free

An Ada95 "hello world" style kernel

Conversations on #Ada keep coming back to operating systems and their kernels so I decided to dig out some code I wrote in 2000 and get it working again. I intended this code to be the basis of a microkernel written in Ada. The code presented here is a second attempt at using the latest version of GNAT (4.2.2) and binutils (2.18) as the first time I just couldn't get it working properly.

Unlike other OSes that have been written in Ada like MarteOS, RTEMS, AdaExpOS (a more full featured test kernel), I wanted to get it working using no Ada runtime, which is quite tricky. These other compilers seem to have a full runtime as they use the host's native port of the compiler and just add the -nostdlib flag when compiling. This isn't exactly the best way forward as you won't actually have this when targeting bare hardware.

Also, I didn't want to go the route of porting the Ada runtime to bare hardware - this is what other Ada OS developers do, which makes sense for specific targets, i.e. a robot in a manufacturing plant or a guided missile, but not for a general purpose OS.

It is possible to build GNAT so that there is no runtime installed. This is called the "Zero Foot Print" runtime which has to be configured from the system.ads package which needs to be modified. The configuration options that are in the private part of the system.ads package are documented in the targparm.ads package in the GNAT distribution.

Further to modifying the system package, we need to provide restrictions in the gnat.adc file. These restrictions are supplied using the Ada 2005 pragma Restrictions directive. There used to be pragma No_Run_Time but this is deprecated now, although I've heard it still works. So, even though the source provided is Ada95 it should be possible to compile it using an Ada95 compiler and using a different gnat.adc file.

The following commands will configure a basic compiler and other tools required.

Bash code
$ cd <to somewhere on disk>
$ mkdir -p build-binutils-2.18 build-gcc-4.2.2
$ tar -xjvpf binutils-2.18.bz2
$ tar -xjvpf gcc-core-4.2.2.bz2
$ tar -xjvpf gcc-ada-4.2.2.bz2
$ cd build-binutils-2.18
$ ../binutils-2.18/configure --prefix=$HOME/opt/cross-gcc \
    --target=i386-elf --host=x86_64-pc-linux \
    --build=x86_64-pc-linux --disable-nls \
    2>&1|tee config.log
$ make
$ make install
$ export PATH=$HOME/opt/cross-gcc/bin:$PATH
$ cd ../build-gcc-4.2.2
$ ../gcc-4.2.2/configure --prefix=$HOME/opt/cross-gcc \
    --target=i386-elf --host=x86_64-pc-linux \
    --build=x86_64-pc-linux --disable-nls \
    --enable-languages=c,ada --without-headers \
    2>&1|tee config.log
$ make all-gcc
$ make install-gcc

You may need to change your --host and --build options to reflect what your host machine is, you may not even need them. I've added them as Ubuntu doesn't define the platform properly.

Now you have the compiler and tools installed you can build my test kernel by downloading it from below and extracting it somewhere, just type the following:

Bash code
$ tar -xzvpf multiboot.tgz
$ cd multiboot
$ make qemu

As long as you have qemu installed somewhere, this will build a boot floppy and boot into GRUB. For some reason, it doesn't pick up the menu, so when booted type the following to get the menu:

GRUB commands
$ configfile /boot/grub/menu.lst

As it stands, I'm not sure that restricting the runtime to zero footprint is the right approach. I think that providing a very limited runtime is the best way forward. This way, the kernel developer has access to aggregates, 'Image attribute (useful for debugging) and other features. Obviously it makes no sense to allow tasking or even exceptions (as far as I can see).

Download multiboot.tgz

Luke
Comment
Wrong
Reply #1 on : Tue May 13, 2008, 11:20:35
After having spent a day looking into this, it seems that by working this way (at least at the beginning) is the best way forward.

So, to clarify, build a basic no runtime compiler and copy over parts of the runtime as and when required, i.e. when the compiler complains that it needs something.

Write a comment

  • Required fields are marked with *.

If you have trouble reading the code, click on the code itself to generate a new random code.
Security Code: *