-
Create a new file <new_system_call_name> in
user/
directory.The new file should contain the following:
#include "kernel/param.h" #include "kernel/types.h" #include "kernel/stat.h" #include "user/user.h" int main(int argc, char *argv[]) { // code exit(exit_status); }
For example, see the
user/trace.c
fileNote:
The file name should be as same as the command name that you want to use to execute the system call. -
Add the new system call command name to
user/Makefile
as follows:UPROGS = \ ... $U/_<new_command_name>\ ...
eg:
$U/_trace \
This will allow the
make qemu
to enable the system call.Note:
The <new_command_name> part should be the same as the file name created in step 1. -
Add an entry to
user/usys.pl
.entry("<new_system_call_name>");
eg:
entry("trace");
This will route the system call into the kernel.
Note:
The <new_system_call_name> part does not have to be the same as the file name created in step 1. But all the names stated in the following steps should be the same as this one. -
Add the prototype of the new system call in
user/user.h
.eg:
int trace(int);
-
Define a system call number in
kernel/syscall.h
as follows:#define SYS_<new_system_call_name> <new_system_call_number>
eg:
#define SYS_trace 22
-
Define the system call function in
kernel/proc.c
<return type> <new_system_call_name>(<args>) { // code }
eg: see the
trace()
function inkernel/proc.c
-
Add the prototype of the new system call in
kernel/defs.h
. Preferably under theproc.c
comment.eg:
int trace(int);
-
Open
kernel/sysproc.c
and add the handler function that will execute the system call which has just been defined in step 6.<return type> sys_<new_system_call_name>(void) { // code }
eg: see the
sys_trace()
function inkernel/sysproc.c
-
In
kernel/syscall.c
,-
extern the new system call handler function.
extern int sys_<new_system_call_name>(void);
eg:
extern int sys_trace(void);
-
Add the new system call name to the
syscalls
array.[SYS_<new_system_call_name>] sys_<new_system_call_name>,
eg:
[SYS_trace] sys_trace,
-
-
Make required changes in other functions and files as required.
fardinanam / xv6-riscv Goto Github PK
View Code? Open in Web Editor NEWThis project forked from mit-pdos/xv6-riscv
Xv6 for RISC-V
License: Other