Suppose you wanted to write a really trivial operating system for the
OLPC XO, one that just prints Hello, world! without using Linux.
HelloOS 1.0 we write in Forth. That's the simplest and most
sensible idea given that the XO already runs everybody's favourite
firmware. Create a file called olpc.fth on a USB stick looking
something like this:
." Hello, world!" cr
and you're done. Just poke the USB stick into an XO and it's installed.
HelloOS 2.0 is the same thing but written in C, for no good
reason at all. This is very easy too because openfirmware ships with a
subset libc implementation that gives us printf for free:
main() { printf("Hello, world!\n"); }
we just have to use the right incantations when we compile:
gcc -g -m32 -fno-builtin -fno-stack-limit -fno-stack-protector -c ../../hello/hello.c
ld -melf_i386 -Bstatic -N -Ttext 0x100000 -o hello.elf start.o hello.o libobp.a -lc
cp hello.elf hello.syms
strip hello.elf
and then we have hello.elf. We can stick that on a USB stick and run
boot u:\hello.elf and our operating system will print its
message.
HelloOS 3.0 is the same but ever-so-slightly more macho.
Instead of using premade libc functions we'll call into Forth directly
when we want a primitive -- and that's trivially easy too:
main() { OFInterpret0(".\" Hello, world!\" cr"); }
and since we're writing so many operating systems we can do up a snazzy Makefile too:
OFW = /home/luke/hacking/openfirmware
OFW_CLIENT = ${OFW}/clients/lib/x86
SYSTEMS = os1.elf
all: ${SYSTEMS}
%.o: %.c
${CC} ${CFLAGS} -c $<
%.elf: %.o
ld -melf_i386 -Bstatic -N -Ttext 0x100000 \
-o $@ ${OFW_CLIENT}/start.o $< ${OFW_CLIENT}/libobp.a -lc
strip $@
and then we start to see how one could write primitives (system calls)
in Forth for use by a "user program". That would be quite OSey.
Hurray So there we have it three operating systems in one afternoon. Life sure is grand :-) |