mirror of
https://github.com/CoderSherlock/CoderSherlock.github.io.git
synced 2026-06-13 08:08:10 -07:00
32 lines
1.8 KiB
Markdown
32 lines
1.8 KiB
Markdown
---
|
||
layout: post
|
||
title: "Xv6 introduction"
|
||
date: 2017-07-28 14:56:55 -0400
|
||
categories: xv6
|
||
---
|
||
|
||
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*.
|
||
|
||
~~~~c
|
||
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*.
|
||
|
||
~~~~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.
|