Location of the definition of open() in xv6

Viewed 1754

I have an assignment that has me design my own system call. To do this, I would like to view the definition of the open system call. By this, I mean I would like to see how the actual open(const char*, const int) is defined, not sys_open (Since I know where the source code is and can read it).

In both xv6's documentation and files in xv6-public, I am unable to find any reference of the prototype of definition. The theory of my friend and I is that it's defined in some asm file, or some .o file. Would anyone happen to know where the actual source code is? I'd appreciate this greatly.

Tried a ctrl-f for open in the source documentation, and tried a grep over all files in xv6-public. Found nothing.

1 Answers

Well,

open is declared in user.h.

open is defined in usys.S:

Lets see:

SYSCALL(open)

Will be transformed in

  .globl open; 
  open: 
    movl $SYS_ ## open, %eax; 
    int $T_SYSCALL; 
    ret

What happened?

When function open is called

  • register %eax is set to SYS_open (which value is 15 (see syscall.h) and SYS_open is defined in sysfile.c
  • interuption T_SYSCALL (64 see traps.h) is raised.
  • after the system call returned, open returns too.
Related