moonshot

blog

i built a compiler to build a kernel

i have always wanted to build an operating system with a real graphical interface. and now moonshot is being built in whatever hours a day leaves over, and it will be finished when it is finished, if ever.

the first moonshot

this is not the first moonshot. the first one carried the same name and ran on RISC-V, under QEMU, written in plain C and assembly. i did not get very far with it, i got stuck working on coff on the side, my assembly code ended up in a state i could not untangle, and somewhere in that mess the motivation went out of it.not a single line of that code was re-used in this project. what the failure taught me is that i did not want to patch a wobbly foundation, i wanted to build something robust from the beginning, and in the right order this time.

self-made

the right order meant starting further down than a kernel. before moonshot drew anything on screen, i built c0, a small systems language, and coff, its compiler. then coff was rewritten in c0 until it compiled its own source.every build of the self-hosted compiler is checked byte-for-byte against the bootstrap compiler. moonshot is built through that self-hosted compiler alone.

first light

the kernel's Multiboot header asks GRUB for a 1024×768 graphics mode, punkt maps the framebuffer the bootloader hands back, and the font renderer paints moonshot's own characters into it, pixel by pixel. and then it was simply there, MOONSHOT, drawn by my kernel, in my font, compiled by my compiler. typing on the keyboard put letters on the screen. :-)

the word MOONSHOT above the letters OS, drawn in moonshot's own font on a black framebuffer: the first thing the kernel ever put on the screen.
screenshot from first boot.

the road ahead

the aim is a real graphical system, the next step in that direction is something that can hold more than one thing on the screen at once, the beginning of a windowing layer. underneath it, the kernel already runs more than one task at a time through chrone, and the shell, skalman, can start and stop them.