n
CPSC 331 Operating Systems Spring 2026

Project 3
xv6 System Call

Due: Fri 3/13 at the start of class

This project has several goals:

Your primary task is to add a system call to xv6 as described in the project README. You'll also write a small user program. There is very little code to write; the crux of the assignment is gaining understanding of several aspects of xv6.

Collaboration and the Use of AI

Review the course policy on academic integrity.

Certain uses of AI are permitted on this assignment. AI use is not required.

The basic rule: you may use the code completion features of Copilot but may not use features (such as the coding agent) where code is generated from English language prompts. It is also essential that you understand and think critically about any code suggested by Copilot, both to help develop your C programming skills and because while the code suggestions are often uncannily on target, they are not always exactly what you want.

Using the code explanation features of Copilot Chat is permitted, though be careful that this doesn't spill over into code generation.

Other Policies

Review the policy on late work.

Revise and resubmit applies for this assignment. Review the details of how revise and resubmit works.

Handin

To hand in your project:

Check that the handin was successful and that the directory structure is correct: your handin folder /classes/cs331/handin/username should contain a folder initial-xv6 which in turn contains a src directory.


Preliminaries

Do the steps outlined in reddish boxes below before you start writing code.

Provided Code

VSCode Configuration

Very important! One of the things the autoformatter can do is reorganize the #include directives in your code. While useful in some circumstances, this will break the xv6 code. To turn off sorting includes:

Running xv6

From the initial-xv6/src directory, use make to perform various tasks:

  make            # compile
  make qemu       # compile anything needed, then run using qemu
  make clean      # remove all compiled elements to force a rebuild from scratch on the next make

make qemu will open a new window with the xv6 shell. Type ls in the qemu window to see the programs available to run (i.e. the available commands). Exit qemu by closing the qemu window — there is no exit command.

Note: if you click in the qemu window, it will grab the focus. (You'll see the message "Press Ctrl-Alt-G to release grab" displayed in the title bar if this happens.) On some keyboards this specifically means the right control and right alt keys — if you have two control and/or alt keys and the one you try doesn't work, try the other one.

Running Tests

From the initial-xv6/src directory, use make to perform various testing-related tasks:

  make test        # compile and run the tests
  make test-clean  # remove compiled elements related to running the tests

You can also run

    ./test-getreadcount.sh

from the top-level initial-xv6 directory as described in the project README.

The provided test cases cover everything; you do not need to create additional tests. Note that the tester setup is a bit delicate and test 1 (hello) may not succeed if getreadcount hasn't been implemented yet — test hello by running it in xv6 as described in that section below, and hold off on running the provided tests until you are ready to test getreadcount as well.

Reference

xv6 — System Calls

System calls in xv6 were discussed in class. (See the posted slides.) For additional reference:

The following provide more detailed explanations of trap and system call handling in xv6. This is of relevance to this project, but these readings go into greater depth than is needed to complete the project. Check them out if you want to know more, or if you have questions not resolved by the links above and the materials from class.

xv6 — Navigating the Source

To search the source code for a particular string, you can utilize the "Find in Folder" feature of VSCode or the command line tool grep.

For both grep and Find in Folder, you can use wildcards to specify a collection of files — * matches any number of characters (including 0) and ? matches a single character. For example, if run in the initial-xv6/src directory,
  grep "getpid" */*.?

will print lines containing "getpid" from all files with a single-character extension in a subdirectory of the current directory — this will search header (.h), C source (.c), and assembly language (.S) files, which are likely the ones you want to search.

xv6 — Additional Background

The following resources provide additional background about xv6 that is not needed for this project, but which may be of interest for the big picture of what is going on:


Specifications and Details

You have two tasks: add a system call to xv6 as described in the project README, and create a small user program.

To do this:

Hello World

Create a system utility hello which prints out greetings. It should take the recipient of the greeting as a command line parameter and print out hello <recipient>. For example, when invoked as

  hello world

it should print out

  hello world

Additional specifications:

To do this:

Notes on writing xv6 programs:

getreadcount

Implement the getreadcount system call as described in the README.

Hints/suggestions: