how do i add a system call / utility in xv6

sashank picture sashank · Nov 5, 2011 · Viewed 35.4k times · Source

Can any one tell me/ point me any references to how to add a system call / utility in XV6

exhaustive search on google was futile and hacking the hard way also was not productive so far .

the reference book also did not have any hello world example to start with any help greatly appreciated

Answer

Yang picture Yang · Nov 3, 2012

To add a system call that can be called in xv6's shell, you should so something with the five files

  • sysproc.c add the real implementation of your method here
  • syscall.h define the position of the system call vector that connect to your implementation
  • user.h define the function that can be called through the shell
  • syscall.c external define the function that connect the shell and the kernel, use the position defined in syscall.h to add the function to the system call vector
  • usys.S use the macro to define connect the call of user to the system call function

  • defs.h add a forward declaration for your new system call

  • sysfunc.h add the new system call handler into this file too like "int sys_newsystemcall(void)"