Skip to content

Instantly share code, notes, and snippets.

@colematt
Last active October 3, 2023 20:23
Show Gist options
  • Save colematt/9664600d03e3fb8f231755057cf8c3da to your computer and use it in GitHub Desktop.
Save colematt/9664600d03e3fb8f231755057cf8c3da to your computer and use it in GitHub Desktop.
Adding Programs and System Calls to XV6

Adding Programs and System Calls to XV6

Adding Userspace programs

To add a userspace program that can be executed in xv6 shell, make the following additions/edits:

program.c

  1. Include the headers needed to gain access to system call wrapper prototypes: types.h, user.h.
  2. If you need access to struct stat, include its header: stat.h
  3. Write the entry point function.
    • Do not return 0; from the entry point function, instead call exit(); to end its execution.

Makefile

  1. Add the program’s name to UPROGS variable
    • It’s recommended, but not required that you keep it in alphabetical order.
  2. Use make to build the OS.
    • Once the OS has booted, running ls will display your userspace program.

Adding System Calls to XV6

To add a system call that can be called in an XV6 user-space application, make the following additions/edits:

sysproc.c

  1. Add sys_callname(), the real implementation (kernel-mode implementation) of your system call here.

syscall.h

  1. Define the position of the system call vector that connects to your implementation

user.h

  1. Add callname(), the function forward declaration for the user-mode wrapper function that can be called by programs.
    • The signatures do not name the variables, only list the types of the variables!

syscall.c

  1. Externally define callname(), the wrapper function that connects the shell in user-mode and the system call in kernel-mode

syscall.c

  1. Use the position defined in syscall.h to add the function to the system call vector

usys.S

  1. Use #define SYSCALL(name) macro to make the connection between the user-space call and the kernel-space system call function

defs.h

  1. Add a forward declaration for your new system call.
    • Don’t forget to add it to the right group of declarations: defs.h is sorted by enclosing files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment