add a new system call for x86

 

#define T_SYSCALL       64      // system call

#define SYS_fork    1
#define SYS_sleep   2

#define SYSCALL(name) \
  .globl name; \
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret


# in kernel,
code to process int $T_SYSCALL (x86's trap machanism),
get system call num from %eax,
get arguments from stack since when arguments are pushed to stack
when system call get called(assume no registered is used for arguments
which is true for x86, but x86_64 use register for arguments).

# usage
int main()
{
   sleep(2);
}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章