In 2004 Gavin Barraclough created multitasking operating system for i386 with GUI, filesystem and mouse support (the OS has no name, so I will call it Gavin). It is written in C, it has only one source file and this file has size 3.5 kilobytes! Then Gavin sent OS to IOCCC (the International Obfuscated C Code Contest) and won. Of course, code is very obfuscated, for example:
F
U (Y (t + 28) + 1536) |=
62 & -n;
M
U (d + D) =
X (D, Y (t + 12) + 26628, 412162) ? X (D, Y (t + 12) + 27653,
410112) ? 31 : 0 : U (d + D);
for (; j < 12800; j += 8)
P (d + 27653 + Y (t + 12) + ' ' * (j & ~511) + j % 512,
U (Y (t + 28) + j / 8 + 64 * Y (t + 20)), 0);
}
In 2011 I deobfuscated and commented this code. For example, this is same code:
case msg_render:
/* This code draws content of window (black frame, white area and text) */
{
char *dest = (char *)arg;
if (shell){
(*content)[(LINES - 1) * COLUMNS] = '>';
}
/* Frame */
draw_rectangle(dest + my_task->begin, TITLE_HEIGHT + 8, 4, LINES * SYMBOL_HEIGHT + 3, COLUMNS * SYMBOL_WIDTH + 2, BLACK);
/* Area */
draw_rectangle(dest + my_task->begin, CONTENT_TOP, CONTENT_LEFT, LINES * SYMBOL_HEIGHT + 1, COLUMNS * SYMBOL_WIDTH, WHITE);
/* Text */
for (int i = 0; i != LINES; ++i){
for (int j = 0; j != COLUMNS; ++j){
draw_symbol(dest + my_task->begin + (CONTENT_TOP + i * SYMBOL_HEIGHT) * SCREEN_WIDTH + CONTENT_LEFT + j * SYMBOL_WIDTH, (*content)[(*line + i) * COLUMNS + j], BLACK);
}
}
}
break;
This package consists of all information about Gavin you want to know, namely:
- Some files which can help you to run original Gavin. They are in the directory
orig
- Deobfuscated Gavin. It is in directory
deobfuscated
Download it from the IOCCC site (there are also other winners of the IOCCC in this archive).
Then follow instructions in files gavin.hint
and gavin_install.txt
(or use Russian translation orig/gavin_ru.hint
and orig/gavin_install_ru.txt
from this package), but note following:
-
If you want to build only Gavin, type
make gavin
-
The most simple way to run Gavin is Qemu. At first try to use Qemu, then - other methods
-
To boot from Qemu type
qemu -m 256 -kernel /path/to/kernel -initrd /path/to/fs.tar /dev/null
(of course, you need to build Gavin first) -
You will get strange colors in Qemu
-
LILO is obsolete. You don't need files
lilo.conf
andboot.b
. Use any modern Linux loader. I would recommend GRUB 2 (but don't use too modern bootloader: GRUB 1.98 works, but GRUB 1.99 doesn't work). If you have GRUB 2, press "c" while booting and type:linux16 /path/to/kernel initrd16 /path/to/fs.tar boot
-
Floppy disks are obsolete. You can boot Gavin from any disk
-
You need very old gcc 3.x (you need 32-bit gcc, but you can run it on 32-bit or 64-bit OS)
-
If you cannot compile Gavin use precompiled
orig/kernel
andorig/fs.tar
from this package for real hardware andorig/qemu-kernel
andorig/qemu-fs.tar
for Qemu -
This package contains source of
prim
utility inorig/prim.c
(thanks to IOCCC judges)
-
First, build the kernel and filesystem (just
make
). (You can skip this step because the package contains precompileddeobfuscated/kernel
anddeobfuscated/fs.tar
for real hardware anddeobfuscated/qemu-kernel
anddeobfuscated/qemu-fs.tar
for Qemu.) In short, you need to build this on an x86 GNU/Linux machine. If you wish to try to compile on an OS other than GNU/Linux you may need modify the Makefile to compilesh
,vi
andprim
using a cross-compiler that produces ELF binaries - i.e. a cross-compiler targeting x86 GNU/Linux. Also, you need very old version of gcc - 3.x (you need 32-bit gcc, but you can run it on 32-bit or 64-bit OS). -
Next, find a suitable machine to run the OS on. It should be perfectly safe, and since it does not directly attempt to access any hard disk drives (only a ramdisk loaded by the bootloader) it should do no damage to your existing setup, BUT I ACCEPT NO LIABILITY FOR ANY DAMAGE DONE BY THIS PROGRAM. Run it at your own risk. The OS has been tested on half a dozen machines or so, and worked on all but one. The failure came in the form of the machine rebooting itself midway through loading the OS, with no nasty side-effects.
-
Hardware requirements - i386 or better processor, but the GUI is surprisingly power-hungry, so I would recommend a fast processor (has been tested on Pentium 3/Pentium 4/Athlon machines). Minimum RAM is something like 32MB. PS2 mouse & keyboard required - no USB I'm afraid. Uses Vesa VBE 3.0, so should work on any modern graphics card (has been tested on Nvidia, Matrox, and SiS cards).
-
Now you need to use virtual machine (this is simplest way) or a bootloader to load the OS.
-
Virtual machine. I recommend you Qemu. Just type command
qemu -m 256 -kernel /path/to/kernel -initrd /path/to/fs.tar /dev/null
. But in this case you must compile Gavin by commandmake QEMU=1
. -
Bootloader (GRUB 2). Don't use too modern bootloader: GRUB 1.98 works, but GRUB 1.99 doesn't work. At the boot menu simply hit "c" to get a console, then type
linux16 (hd0,1)/<PATH>/kernel
(substituting appropriate harddrive/partition numbers & path), theninitrd16 (hd0,1)/<PATH>/fs.tar
, and finallyboot
. -
Assuming the OS has booted, what can you do now? Well, start by trying
sh
, to open another shell. Then, tryvi mkkernel.c
, to open up the kernel source in a text file viewer (up/down or PgUp/PgDown to scroll). Also tryprim
. Note that all provided applications have windows of the same size, and that open in the top left corner of the screen, so you may need drag the windows around a bit to tell them apart. -
To shut down - just hit the power button. :-)
See deobfuscated/README-EN
.
- http://pdos.csail.mit.edu/6.828/2011/xv6.html - XV6, simple UNIX-like OS. Its source has size 277 kilobytes! It is Gavin x 78!
- http://wiki.osdev.org - wiki about OS development
https://github.com/safinaskar/gavin
All sources are in public domain. Docs use following copyright:
Copyright (C) 2004, Landon Curt Noll, Simon Cooper, Peter Seebach and Leonid A. Broukhis. All Rights Reserved. Permission for personal, educational or non-profit use is granted provided this copyright and notice are included in its entirety and remains unaltered. All other uses must receive prior permission from the contest judges.