To add a userspace program that can be executed in xv6 shell, make the following additions/edits:
- Include the headers needed to gain access to system call wrapper prototypes: types.h, user.h.
- If you need access to
struct stat
, include its header: stat.h - Write the entry point function.
- Do not
return 0;
from the entry point function, instead callexit();
to end its execution.
- Do not
- Add the program’s name to
UPROGS
variable- It’s recommended, but not required that you keep it in alphabetical order.
- Use make to build the OS.
- Once the OS has booted, running
ls
will display your userspace program.
- Once the OS has booted, running
To add a system call that can be called in an XV6 user-space application, make the following additions/edits:
- Add
sys_callname()
, the real implementation (kernel-mode implementation) of your system call here.
- Define the position of the system call vector that connects to your implementation
- 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!
- Externally define
callname()
, the wrapper function that connects the shell in user-mode and the system call in kernel-mode
- Use the position defined in syscall.h to add the function to the system call vector
- Use
#define SYSCALL(name)
macro to make the connection between the user-space call and the kernel-space system call function
- 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.