Musings of a Fondue

Xv6 Mods

Xv6 is a simple operating system (based on Version 6 Unix). It was created as a teaching aid and as such has a relatively small code base. It also comes with a book which explains how its key components work.

The small size and generous documentation (commentary book, lectures) makes it an excellent candidate for my homebrew computer. My goal is to understand the OS completely, so that I can adapt it for use on the computer.

- Applications -

Xv6 is intentionally lightweight. As such it comes with only a few user-space utilities (all command-line based):

  • cat
  • echo
  • grep (minimal)
  • kill (minimal)
  • ln
  • ls (minimal)
  • mkdir
  • rm
  • sh (minimal)
  • wc

This is great for teaching, but poor for usability. To make the OS more useful, I plan to grow the number of user-space utilities.

- Code style -

As I work through the code, I’m taking steps to improve its readability such as:

  • renaming variables (opting for descriptive versus short)
  • adding generous comments and diagrams
  • breaking up one liners into logical sub-steps
  • separating kernel-space code from user-space code

Here’s an example commit, where adding comments helps to explain an otherwise cryptic piece of C syntactic sugar.

- Modifications -

I have made a number of changes to the OS thus far (see commit history).

It is worthwhile to note that security is not a consideration for my homebrew use case. Performance, reliability, and simplicity are my key considerations. As such, some of my modifications might make the security-conscious shudder.

Notable additions include:

  • VGA Mode 0x13 graphics
    • Visible in the demo below when running keditor and graphics_test
    • Implemented by:
      • mapping the VGA buffer to user-space. This allows user-space programs to write directly to the buffer without going through the kernel. See GFX.c, GFXText.c, vm.c
      • using ioctl to switch between text mode (0x03) and graphical mode (0x13). See display.c
  • Mouse support
  • A simple text editor called “keditor”
  • Some simple command-line utilities:
    • hexdump - shows a file’s contents in hexadecimal/ASCII. See hexdump.c
    • clock - shows the current time. See clock.c
  • A modified ls that gives more descriptive output including last-modified time. See ls.c
  • More useful debug/error messages from the kernel

Below is a video of the modified Xv6 running. (Things are a bit slow because QEMU is running within WSL (an emulation of Linux).)

Below is a video of the original/un-modified Xv6 running for comparison. (The files and programs shown by ls are all that is available.)

- TODO -

There are many things that remain to be done before the OS can be useful for my needs. Some of them include:

  • Replacing x86 assembly instructions with those of my CPU
  • Replacing x86 specific components such as:
    • the current boot process
    • the interrupt system (IDT, LAPIC)
    • the paging system (GDT)

Other nice to have features include:

  • Changing the graphics from VGA Mode 0x13 to something more flexible.
    • it has a fixed resolution of 320x200. An ideal alternative would allow arbitrary resolution.
    • it is limited to using a 256-color palette. An ideal alternative would allow the use of rgb to specify a pixel’s color.
  • Creating a simple windowing system
  • Integrating relevant updates from the RISC-V Xv6 project
    • MIT switched its focus from the x86 version of Xv6 to a RISC-V version. As such, any subsequent updates to Xv6 (such as bug fixes, logic changes) are now only present in the RISC-V repository.

- Resources -

I’ve come across many helpful resources during this process. All are mentioned within the source code. Here are a few of them:

Comments