I'm trying to write a simple system call on XV6 (documentation available here and Github here) in order to understand how they're implemented. I've used these steps
- In
syscall.c
, declaredextern int sys_hello(void)
and added[SYS_hello] sys_hello
intostatic int (*syscalls[])(void)
array - In
syscall.h
, definedSYS_hello
as call number 22 - In
user.h
, declared the function prototype asint hello (void);
- In
usys.S
, addedSYSCALL(hello)
to the macro In
sysproc.c
, added the functionsys_hello(void)
at the bottomint sys_hello(void) { cprintf ("Hello World System Call\n"); return 0; }
Created
hello.c
which simply calls thehello()
system call- Added
hello.c
to theMakefile
and ran the code
It worked as expected.
Now, my question is that it seems that the array in syscall.c matches the indexes of the commands with the system call numbers in syscall.h file However, if I move the hello position to the second spot in the syscall.c and let the system command number in syscall.h stay 22 the system command works as before. Where as, I expected that it'd break. Can you help me understand how the array syscall.c maps (if that's even the correct word) to the syscall.h system call number?
I'm fairly new to XV6 and C so please don't get mad at me if this question seems silly, I'm only trying to learn.
Here is the Github link to my fork of the XV6 repository if that helps: github.com/AdityaSingh/XV6