kern

annotate src/syscall.c @ 72:3941e82b07f2

- implemented syscalls: exit, waitpid, getppid - moved sys_whatever functions out of syscall.c into more reasonable files - putting all the definitions that must be synced with userland to include/kdef.h
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 15 Oct 2011 07:45:56 +0300
parents 5b29b15c5412
children 7ff2b4971216
rev   line source
nuclear@51 1 #include <stdio.h>
nuclear@51 2 #include "syscall.h"
nuclear@51 3 #include "intr.h"
nuclear@51 4 #include "proc.h"
nuclear@51 5 #include "sched.h"
nuclear@51 6 #include "timer.h"
nuclear@51 7
nuclear@51 8 static int (*sys_func[NUM_SYSCALLS])();
nuclear@51 9
nuclear@52 10 static void syscall(int inum);
nuclear@51 11
nuclear@51 12 static int sys_hello(void);
nuclear@51 13
nuclear@51 14 void init_syscall(void)
nuclear@51 15 {
nuclear@51 16 sys_func[SYS_HELLO] = sys_hello;
nuclear@72 17 sys_func[SYS_SLEEP] = sys_sleep; /* timer.c */
nuclear@72 18 sys_func[SYS_FORK] = sys_fork; /* proc.c */
nuclear@72 19 sys_func[SYS_EXIT] = sys_exit; /* proc.c */
nuclear@72 20 sys_func[SYS_WAITPID] = sys_waitpid; /* proc.c */
nuclear@72 21 sys_func[SYS_GETPID] = sys_getpid; /* proc.c */
nuclear@72 22 sys_func[SYS_GETPPID] = sys_getppid; /* proc.c */
nuclear@51 23
nuclear@51 24 interrupt(SYSCALL_INT, syscall);
nuclear@51 25 }
nuclear@51 26
nuclear@52 27 static void syscall(int inum)
nuclear@51 28 {
nuclear@52 29 struct intr_frame *frm;
nuclear@52 30 int idx;
nuclear@52 31
nuclear@52 32 frm = get_intr_frame();
nuclear@52 33 idx = frm->regs.eax;
nuclear@51 34
nuclear@51 35 if(idx < 0 || idx >= NUM_SYSCALLS) {
nuclear@51 36 printf("invalid syscall: %d\n", idx);
nuclear@51 37 return;
nuclear@51 38 }
nuclear@51 39
nuclear@54 40 /* the return value goes into the interrupt frame copy of the user's eax
nuclear@54 41 * so that it'll be restored into eax before returning to userland.
nuclear@54 42 */
nuclear@51 43 frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
nuclear@72 44
nuclear@72 45 /* we don't necessarily want to return to the same process
nuclear@72 46 * might have blocked or exited or whatever, so call schedule
nuclear@72 47 * to decide what's going to run next.
nuclear@72 48 */
nuclear@72 49 schedule();
nuclear@51 50 }
nuclear@51 51
nuclear@51 52 static int sys_hello(void)
nuclear@51 53 {
nuclear@54 54 printf("process %d says hello!\n", get_current_pid());
nuclear@51 55 return 0;
nuclear@51 56 }