OSTEP_Projects_xv6: Initial_xv6_systemcall

1231·2024년 3월 2일

Labs_xv6

목록 보기
1/7

usys.S
%eax -> used for return code
the function will override the eax
put the system call number in the eax
usys.S is not dealing with system call arguments
->it leaves those arguments on the stack, basically when you call function.
xv6 knows that the arguments is on the stack, thus they pull them off and use them as arguments.

int $T_SYSCALL: trap instruction, takes one argument called $T_SYSCALL(it will help us to find a correct trap handler)

ret value will be the eax

User Side user.h
user.h contains declaration of the system calls which will help C compiler to find out the wrong arguments...etc

main.c
where the stuffs getting set up
tvinit() routine structures up the memory.
SETGATE macro gives information about trap vectors to the layout of the hardware.
array vectors[T_SYSCALL]

idtinit() routine, interrupt descriptor table init routine tell the cpu where the memory storing the trap vectors information is.
->lidt() assembly macro, which takes argument idt(where the interrupt descriptor table lives)

you have to figure out where the vectors are.
vector.S
system call number 64 will go to
vector64:
push the needed informations such as which trap this is on the stack, later we will see this stack and knows that this is system call
and all jump to alltraps

trapasm.S
alltraps will jump here
1. it completes the building called trap frame.
-> when you trap in the kernel, the hardware saves little bit of the its current state, so that it can go back after all is done(program counters)
where does save that stuff? -> kernel stack(because we don't want to trust user stack)

  1. memory segment management stuff

  2. call into C level routine
    trap() function first checks if it is already killed and call generic syscall() function
    syscall() function, every system call goes through here
    proc->tf->eax is what we store in usys.S, we moved number into eax.
    is override with return value of the syscalls[num],
    it is put back into trap fram and when it pops out of the kernel, it's gonna be register of the user program.
    and follows many functions...

  3. trapret
    iret, interrupt return undoes all stuff and goes back to user mode

How does system call takes argument from memory?
arguments are on the stack, the saved user %esp points to a saved program counter, and the first argument.

Let's trace the its procedure.
sysfile.c (where the file-system related system calls reside);

argstr? argint?
syscall.c


How to include new system call?
add macro on usys.S,
add declaration & definition on syscall.h, user.h, syscall.c
sysfile.c

0개의 댓글