I have never seen this assembly syntax.
#include "syscall.h"
#include "traps.h"
#define SYSCALL(name) \
.globl name; \
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
SYSCALL(exit)
SYSCALL(wait)
SYSCALL(pipe)
SYSCALL(read)
SYSCALL(write)
SYSCALL(close)
SYSCALL(kill)
SYSCALL(exec)
SYSCALL(open)
SYSCALL(mknod)
SYSCALL(unlink)
SYSCALL(fstat)
SYSCALL(link)
SYSCALL(mkdir)
SYSCALL(chdir)
SYSCALL(dup)
SYSCALL(getpid)
SYSCALL(sbrk)
SYSCALL(sleep)
SYSCALL(uptime)
For assembly language file with extension .S, gcc will use a C preprocessor.
In C, \ at the end of line means that "connect the next line to this line".
For that reason, the macro becomes
#define SYSCALL(name) .globl name; name: movl $SYS_ ## name, %eax; int $T_SYSCALL; ret
## operator will concatenate the tokens in its left and right.
Therefore, for example, SYSCALL(fork) will be expanded to
.globl fork; fork: movl $SYS_fork, %eax; int $T_SYSCALL; ret
This means
fork publicfork (this will work as a function)SYS_fork to register %eax
T_SYSCALL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With