Building an OS

This is an advanced tutorial to experiment with a simple operating system under Cebollita.

If the simulator is run in "bare" mode, the "BIOS" will load the first disk block into a high memory address and then start the machine at that address.

To run an interesting system in this mode, you'll have to create an image file (a disk image) which contains the various components on it. The image should contain a bootloader at block zero. The bootloader will probably want to just stream in the first executable (starting at block one into low memory). This executable is often a simple OS, which will then take control and perhaps launch other processes. The current architecture looks like this:

Bootloader: apps/os/bootloader.s
Making the bootloader (in the apps/os directory)
java asm.Asm bootloader.s
java asm.Linker --bare bootloader.s
mv a.out boot
The --bare flag links the bootloader as a "raw" executable. That is, it has no executable header or data segment. It is just a sequence of instructions.

The OS:
Consists of the following files, in the apps/os directory
trap-handler.s   (an interrupt handler)
sys.c            (system calls, loader, etc).
The kernel is just a regular executable, with a small catch. The bootloader simply drops the OS image into memory starting at location zero. Because the first 6 words of the executable descriptor, the first actual instruction of the OS is at location 24. (The trap handler lives at this location.) For this reason, the OS has to be linked to live at a fixed location, namely 24. Make the kernel as follows:
java asm.Asm trap-handler.s
java comp.Scc sys.c
java asm.Asm sys.s
java asm.Linker --at 24 --entry __init trap-handler.o sys.o
mv a.out kernel
See the apps/os/Makefile for how to automate this process...

User programs:
Simple user programs with a main can be compiled, assembled, and linked in a normal manner. They should make use of syscalls as defined in iolibs/iolib-os.s. That is, they perform io via syscalls that are ultimately handled by the operating system.

Making an image:
  java sim.DiskMake boot kernel app1.exe app2.exe
This will create an image file called "image" and print an index that maps block number to the start of each of the above programs.

Running the thing:
  java sim.Mips --bare image   (for the command line simulator)
     -- or --

  java sim.UI --bare image  (for the GUI simulator)