ShedOS: my hobbyist operating system

My blog has been quiet recently. Mainly because I have been busy learning OS development.  At the moment I'm calling the result of my efforts by the name "ShedOS" in honour of men who build things in sheds.  I count myself in that category - even if my hobby is more likely to be practiced in Costa Coffee (drinking a flat white) than an actual shed.  Maybe I need to build a better shed, or maybe sheds should serve better coffee.

As I've mentioned before on this blog, I've been following Bran's Kernel Development tutorial, so my OS is based on that.  But I have been busy customising it and adding new things. Currently, ShedOS has these features:
- 32 bit x86 operating system
- preemptive multitasking
- floppy disk driver
- limited support for FAT12 filesystems (read-only)
- text only video driver (16 colours)
- exports a few system calls, like 'print', 'plot' and 'exit'
- can load and run user programs from disk
- oops, still no keyboard driver

I have just started to implement some system calls, so that the kernel can expose an API to user programs, it seems to work.  If I seem surprised; it's because I am.  I have gotten to the point where the kernel boots, then loads a user program from a FAT12 disk.  The user program runs, making use of the kernel's API to print to the screen.  Then the program exits and returns full control to the kernel again.  During that whole process the system continues to multitask.  Not a bad start I suppose.

At some point I'll bring over some of my favourite features from the PDP-11 world, like the ability to drop machine-code instructions straight into memory.  Running some code by typing the instructions in manually must be like a "rite of passage", and it's something that you can't do from windows.  Surely if you can do that using an OS that you've built yourself then you're the man.

Right, I really must get round to posting my floppy driver source code, just in case anybody else out there finds it interesting...  Sadly, I don't think there will be many other people developing drivers for floppy disks these days, but I'll post my code anyway.

A Floppy Driver is born

So when I discussed checking out Bran's Kernel Development Tutorial apparently I wasn't kidding.  I have now compiled my own kernel in C (and it actually works).  As kernels go I suspect that it is unique, because I implemented a floppy disk driver before a keyboard driver :-)  But hey, this is my OS so I can do whatever I like...  Here it is in action:

My OS kernel with floppy driver

So far, all it does is boot up, then find the first floppy disk and do a hex dump of the disk contents to the screen.  But there is a *lot* of coding needed to make that work!  At kernel level you have responsibility for stuff like turning the disk motor on and off and moving the drive heads to the right track.  Plus the command set for accessing a floppy drive is pretty *nasty*.  Also, I have had to remind myself all about tracks, heads and sectors.

The information and examples shown on the OSDEV tutorials have been essential reading.  Without all their examples I would not have gotten this to work.  I have tried not to just copy & paste somebody else's code, I have tried to write this in my own style - but credit has to go to all those people involved in the OSDEV tutorials.

My code is only designed to work with 3.5" drives (although it has not been near a real disk yet) I have only used it in VirtualBox.  It does not seem to work in Bochs for some reason (I don't know why yet).

So anyway... this has been a challenge, and I'm very pleased that I've gotten something that actually works.  I guess the next step is to begin writing FAT12 support, so I can get some proper file access.