This lab makes you familiar with xv6 and its system calls.
Install QEMU and gcc for RISC-V following the directions on the tools page.
Clone the base xv6 repository and set up a branch for this lab by following the directions on the git page.
Build xv6:
If you type ls at the prompt, you should see output similar to the following:
These are the programs/files that mkfs
includes in the initial
file system. You just ran one of them: ls
.
To quit QEMU, type Ctrl-a x, which means:
You can run python3 grade_lab_util.py to test your solutions with the grading script. This same grading script is used by the Gradescope autograding process.
Implement the Unix program sleep
for xv6; your sleep
should pause for a user-specified number of ticks. A tick is a notion of time defined by the xv6 kernel, namely the time between two interrupts from the timer chip. Your solution should be in the file user/sleep.c
.
Some hints:
user/
((e.g., user/echo.c
, user/grep.c
, and user/rm.c
)) to see how you can obtain the command-line arguments passed to a program.atoi
(see user/ulib.c
).sleep
.kernel/sysproc.c
for the xv6 kernel code that implements the sleep
system call (look for sys_sleep
), user/user.h
for the C definition of sleep
callable from a user program, and user/usys.S
for the assembler code that jumps from user code into the kernel for sleep.exit()
in order to exit your program.UPROGS
in Makefile
; once you’ve done that, make qemu will compile your program and you’ll be able to run it from the xv6 shell.Run the program from the xv6 shell:
Your solution is correct if your program pauses when run as shown above. However, you should test it using the grading script to make sure it operates correctly. You can see the exact tests that are run by inspecting the grading script code.
In this part, you will implement a shell command for xv6 kernel called countsys
, which returns the number of syscalls made by far (regardless of whether the syscall number is valid). You will implement your syscall function in the file kernel/sysproc.c and make neccesary modifications to kernel/syscall.c and kernel/syscall.h in order to make it work. You will also implement the user space program for countsys
in the file user/countsys.c as you did for sleep
.
Some hints:
countsys
does not require any arguments and it should print an error message if invalid arguments is presented.sleep
program. Add countsys callable definition in user/user.h. To generate assembler code that jumps from user code into the kernel for countsys, add something in user/usys.pl.\n
at the end of your printf
call, as the number of characters correlates with the number of syscalls made.Run the program from the xv6 shell:
When you are ready to submit your work to Gradescope to be automatically graded, you can run make gradescope which generates a submission.zip
file that can be uploaded to Gradescope. This file should only contain the files that were changed as a result of completing the lab assignment.
If you are using the remote VCM infrastructure, you can use scp
or rsync
to download the zip file.