CS444 Lab Week 4

Front Matter

  • Odin has been unavailable occasionally over the past couple weeks. We’re hoping these issues are resolved now — but let us know if you ever find this service unavailable.

  • Shell extended. Due Wednesday, 2017-02-08

This week

  • Introduction to xv6

  • Trap handling and syscalls

  • Adding a syscall to xv6

  • Debugging xv6

xv6

  • Pedagogical operating system

  • Small

  • Simple

  • Based off of early UNIX

Traps

  • Traps are a generalization of interrupts and exceptions

  • Interrupts and exceptions are a way to signal the operating system

  • Event-driven

  • Triggered by devices and software when they want attention

  • Full details in chapter 3 of the xv6 book

Making a system call

  • User code pushes some arguments onto the stack (handled by the compiler)

  • Puts the system call number into the eax register

  • Then runs the following instruction: int $T_SYSCALL

  • This generates a "software interrupt", and traps into the kernel

Handling the system call

  • The kernel checks the system call number and jumps to the appropiate function

  • System call handlers are named sys_{syscall name}, eg, sys_open, and have a system call number of SYS_{syscall name}, eg, SYS_open

  • These use argint, argptr, and argstr to retrieve the system call arguments from the user stack

Example system call: kill

  • To the code!

Example system call: open

  • To the code!

Adding a system call

  • Need to add a system call number SYS_{name} in syscall.h

  • Need to add a declaration of sys_{name} in syscall.c and add an entry to the syscall table

  • Need to add the user-visible prototype to user.h so programs can use it

  • Need to actually implement sys_{name} 😊

Building xv6

  • On odin, there is an xv6 directory in your home directory

  • This is your own personal fork of xv6. You will be extending it in future labs

  • Run make to build it

Running xv6

  • Run make qemu-nox to run it in a VM (just make qemu won’t work)

  • Type Ctrl-a and then c to cause qemu to break into the monitor console

  • You can use q or quit in the monitor console to kill the VM

Debugging xv6

  • You will probably make bugs in the kernel

  • You can debug it with gdb

  • Run make qemu-nox-gdb

  • Then, in another shell (either using a program like screen or tmux, or in another ssh connection to odin), run gdb while in the xv6 directory

Debugging demo

  • To the shell!