I hate xv6, a stupid, useless education-oriented system. In this article, I will generally talk about how to implement system call to this operating system.

## Xv6 Systemcall

To invoke a system call, we have to first define a user mode function to be the interface of the kernel instruction in file user.h.

    void function (void);

This interface-like function will then pass the function name, in this case function, to usys.S. When using user mode function in programs, usys.S will generate a reference to SYS_function and push system call number of this function into %eax. After that, system can know from syscall.c and determining whether this system call is available. We must define same name system function and add it into syscall.h and syscall.c.

    #define SYS_function ##		// ## is the system call number
    [SYS_function]  sys_function	// real system function name
    extern int sys_function(void);	// real system function declaration

After adding these sentences to syscall files, we can implement real function in specific place where you want to make the function works well.

Sometimes, we need to pass variables among system calls. In this case, variables’ values are not necessary and even can’t be pass directly into system_function. When invoke a system call function, all variables of this system call will be pushed into current process’ stack. In file syscall.c, multiple functions are provided to get these variables from the process. I won’t waste time on explaining how to use these functions especially when elegant and detailed comments were written in source codes. However, I will explain concepts and how process organized and works in xv6 in future articles.

Pengzhan Hao

GitHub Email

Newest Posts

- Generate Word Cloud Figures with Chinese-Tokenization and WordCloud python libraries
- Xv6 introduction
- Some of my previews experiment works: 2016
- Using charles proxy to monitor mobile SSL traffics
- Stop Talking is the worst title of one blog