Cebollita

Building a Bootable Image File

Last modified: April 14, 2005
Sloop SMOK
  CSE Home  About Us    Search    Contact Info 

Building a Bootable Image File

Key Facts

The remainder of this document is an advanced tutorial to experiment with a simple operating system under Cebollita.

Details

If the simulator is run in "bootable" mode, the "BIOS" will load the first disk block into low memory 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 image files we have built look like this:

Bootloader (.../Cebollita/apps/os/bootloader.s)
To make the bootloader
java asm.Asm bootloader.s
java asm.Linker --output bootloader --bare bootloader.op
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.

OS (in .../Cebollita/apps/os/)
Consists of the following files:
trap-handler.s   (low-level interrupt handler and dispatcher)
os.c             (system calls, loader, etc).
stopProcessor.s  (contains a Halt assembler instruction)
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 asm.Asm stopProcessor.s
java comp.parser os.c
java asm.Asm os.s
java asm.Linker --output kernel --at 24 --entry __init trap-handler.o stopProcessor.o os.o
See the apps/os/Makefile for details (and use it to automate this process).

The shell (in .../cebollita/apps/os/)
There are two shells, shell.c and benchmarkShell.c. They are normal applications, and can be built using the usual compile, assemble, and link procedure.

User programs (a number exist below .../cebollita/apps/)
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.

To make an image:

  java sim.DiskMake --output image bootloader kernel shell.exe app1.exe app2.exe ...
This will create an image file called image. As it does so, it will print an index that maps block number to the start of each of the above programs. It will also create a file called "image.map" containing that mapping.

Finally, some trickiness is required to run the image, because your console window has to have character input buffering and echoing turned off for the OS you just built to work correctly (just like a real OS...). The best thing to do is use the shell script .../cebollita/apps/cebrun.sh to launch the bootable image:

    ./cebrun.sh image
(That command assumes you are in directory .../cebollita/apps.) Once the UI comes up, hit hte boot button to load the bootloader, and then the run button to begin its execution.


Department of Computer Science & Engineering
University of Washington
Box 352350
Seattle, WA  98195-2350
(206) 543-1695 voice, (206) 543-2969 FAX
[comments to zahorjan@cs.washington.edu]