Snowdrop OS's system organization is simple. Its main components are the boot loader, the kernel, and a startup application.
Upon computer start-up, the BIOS (or UEFI or newer, running in legacy BIOS mode) loads Snowdrop's single-stage 512 bytes boot loader. The BIOS then jumps to the beginning of the memory where the 512 bytes were loaded. This transfers control to the boot loader.
The boot loader then reads the disk's FAT to locate the file SNOWDROP.KRN. It then loads it, and jumps into its beginning, giving control to the kernel proper.
The Snowdrop OS kernel begins by initializing and registering all system interrupt services which are to be used by user applications. These include a random number generator, FAT12 driver, serial port driver, PS/2 mouse driver, etc.
The kernel then reads the file SNOWDROP.CFG, which holds configuration data, including the name of the startup application.
At the end of its initialization, the kernel reads the startup app binary, creating a task based on it. The kernel's final step is to start the scheduler, effectively yielding control to the startup application.
This user application is automatically started by the Snowdrop kernel. Generally (and by default in the Snowdrop package) this will be a shell, allowing the user to issue commands and run applications. This, and all other applications rely on the kernel-provided services.
PS/2 mouse driver
Snowdrop OS includes a mouse driver, which allows applications to rely on standard PS/2 mice. As with everything around it, I have designed and written the driver from scratch, mainly from PS/2 specifications. I have used two real computers and two virtual machines as my testing environment.
The driver has two conceptual layers. The first layer handles the communication and capture of raw mouse data from the mouse hardware, via IRQ12. The second layer translates the raw data into an absolute location and applies acceleration for quicker mouse motions.
A user application which needs the mouse will first initialize the mouse manager via an interrupt (see System Calls page), passing in the dimensions of the bounding box within which the mouse cursor can move. Usually, these dimensions will be the width and height of the whole screen. This is called "managed" mode, and the driver will ensure that the mouse never leaves the user-defined bounding box.
For example, when using graphics mode 13h, whose resolution is 320x200, the mouse's horizontal location will be between 0 and 319, inclusive. See test applications MMANAGED and MOUSEGUI for usages of "managed" mode.
Optionally, a consumer application can gain access to raw mouse data, allowing it to track the location of the mouse itself. See the test applications MINTRRAW and MINTRPOLL to see how to obtain raw (delta X, delta Y, button status) mouse data.
Multi-tasking components (scheduler, memory manager, virtual displays)
With the addition of basic multi-tasking, a few kernel components had to be added to the Snowdrop OS kernel:
The memory manager
is responsible for the allocation and deallocation of memory. I kept it simple, only allowing operation on entire 64kb memory segments. Prior to its existence, programs would simply use the next segment from where they were loaded, by virtue of only one task running at a time.
The introduction of multi-tasking support invalidated the assumption of the ready availability of the memory past where a task was loaded.
The second component I added was a virtual display driver
. This was needed because I wanted tasks to have their own, isolated display. At a low level, I had to implement my own direct-to-memory string output routines, complete with cursor management and scrolling. These routines more or less replace int 16h, the BIOS screen services interrupt. At a high level, the driver supports switching between the virtual displays, keeping only one of them active (on-screen) at a time.
In terms of effort (design, test, troubleshoot) per line of code, the
scheduler is the most expensive part of the Snowdrop OS kernel.
The third component I implemented was a scheduler
. The scheduler is in charge of managing tasks by handling requests for task addition, exit, and yield. The scheduling mechanism uses a non-preemptive (cooperative), round robin approach. Starvation (that is, running out of tasks) will cause the kernel to lock the CPU.
Snowdrop's FAT12 file system driver supports read, write, and delete operations. It was written mostly from the FAT12 specification.
While the read and delete functionality was reasonably difficult to implement, writing a file was among the most algorithmically-difficult pieces I've implemented for Snowdrop OS. It involved working with all parts of a FAT12 file system: FAT linked list, root directory, 12bit cluster references, and the data area.
Testing FAT12 driver writes and deletes took some time because I wanted consistency between Snowdrop, and Microsoft OSes (MSDOS6.22, Windows XP). Any change to the disk (file creation or deletion) was required to keep the disk in a good state between operating systems.
All file system driver functionality has been tested on real hardware, on both floppy disks and USB keys.
Serial port driver
Snowdrop OS supports communication over serial port. I have created a simple serial port driver, which allows programs to hook an interrupt handler to receive bytes from the serial port. An additional kernel service interrupt allows blocking writes to the serial port.
An accompanying test app hooks into the "read byte from serial" interrupt to read, as well as send keystrokes via serial. This was then used to test communication between two instances of Snowdrop, as well as between Snowdrop and HyperTerminal running in Windows XP. The tests took place on both virtual and real hardware.
Parallel port driver
Similarly to the serial port driver, Snowdrop OS can output single bytes to the parallel port via a blocking write interrupt.
The included paratest app shows how to use this functionality.
Snowdrop OS has the ability to replicate itself on other disks, starting from unformatted disks. Since it still assumes a 1.44Mb floppy disk, formatting such a disk is as simple as raw-writing a pre-generated blank FAT12 image.
The next step in the workflow is writing Snowdrop's boot loader to the disk's boot sector. What follows is the transfer of core Snowdrop files, such as kernel, configuration, etc. At this point, the user can copy whatever apps he chooses, as well as edit the configuration file on the new disk.
At every step of this process, I've tested the disk in a few other operating systems, to ensure that they see the disk as "proper".
"Keep memory" task lifetime mode
A given task can choose to tell the scheduler that it wants its memory to be kept (and not freed) after the task has exited. This allows the task to register an interrupt handler (such as a service, driver, etc.), after which it exits.
The result is that other programs can now invoke the interrupt handler which lives in the "kept" memory area. This concept is similar to MS-DOS's Terminate and Stay Resident (TSR) concept.
This feature was relatively easy to implement, given the way the scheduler was designed.
Snowdrop OS contains graphics routines which can load and display bitmaps from 256-colour BMP files. Furthermore, sprites can be used to achieve movable objects (such as video game characters, etc.) on top of a background.
See the Game Development section for more information.