kern

diff 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
line diff
     1.1 --- a/src/syscall.c	Thu Oct 13 05:22:35 2011 +0300
     1.2 +++ b/src/syscall.c	Sat Oct 15 07:45:56 2011 +0300
     1.3 @@ -10,16 +10,16 @@
     1.4  static void syscall(int inum);
     1.5  
     1.6  static int sys_hello(void);
     1.7 -static int sys_sleep(int sec);
     1.8 -static int sys_fork(void);
     1.9 -static int sys_getpid(void);
    1.10  
    1.11  void init_syscall(void)
    1.12  {
    1.13  	sys_func[SYS_HELLO] = sys_hello;
    1.14 -	sys_func[SYS_SLEEP] = sys_sleep;
    1.15 -	sys_func[SYS_FORK] = sys_fork;
    1.16 -	sys_func[SYS_GETPID] = sys_getpid;
    1.17 +	sys_func[SYS_SLEEP] = sys_sleep;		/* timer.c */
    1.18 +	sys_func[SYS_FORK] = sys_fork;			/* proc.c */
    1.19 +	sys_func[SYS_EXIT] = sys_exit;			/* proc.c */
    1.20 +	sys_func[SYS_WAITPID] = sys_waitpid;	/* proc.c */
    1.21 +	sys_func[SYS_GETPID] = sys_getpid;		/* proc.c */
    1.22 +	sys_func[SYS_GETPPID] = sys_getppid;	/* proc.c */
    1.23  
    1.24  	interrupt(SYSCALL_INT, syscall);
    1.25  }
    1.26 @@ -41,6 +41,12 @@
    1.27  	 * so that it'll be restored into eax before returning to userland.
    1.28  	 */
    1.29  	frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
    1.30 +
    1.31 +	/* we don't necessarily want to return to the same process
    1.32 +	 * might have blocked or exited or whatever, so call schedule
    1.33 +	 * to decide what's going to run next.
    1.34 +	 */
    1.35 +	schedule();
    1.36  }
    1.37  
    1.38  static int sys_hello(void)
    1.39 @@ -48,23 +54,3 @@
    1.40  	printf("process %d says hello!\n", get_current_pid());
    1.41  	return 0;
    1.42  }
    1.43 -
    1.44 -static int sys_sleep(int sec)
    1.45 -{
    1.46 -	printf("process %d will sleep for %d seconds\n", get_current_pid(), sec);
    1.47 -	sleep(sec * 1000); /* timer.c */
    1.48 -	return 0;
    1.49 -}
    1.50 -
    1.51 -static int sys_fork(void)
    1.52 -{
    1.53 -	printf("process %d is forking\n", get_current_pid());
    1.54 -	return fork(); /* proc.c */
    1.55 -}
    1.56 -
    1.57 -static int sys_getpid(void)
    1.58 -{
    1.59 -	int pid = get_current_pid();
    1.60 -	printf("process %d getpid\n", pid);
    1.61 -	return pid;
    1.62 -}