kern

diff src/syscall.c @ 51:b1e8c8251884

lalalala
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 01 Aug 2011 06:45:29 +0300
parents
children fa65b4f45366
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/syscall.c	Mon Aug 01 06:45:29 2011 +0300
     1.3 @@ -0,0 +1,56 @@
     1.4 +#include <stdio.h>
     1.5 +#include "syscall.h"
     1.6 +#include "intr.h"
     1.7 +#include "proc.h"
     1.8 +#include "sched.h"
     1.9 +#include "timer.h"
    1.10 +
    1.11 +static int (*sys_func[NUM_SYSCALLS])();
    1.12 +
    1.13 +static void syscall(int inum, struct intr_frame *frm);
    1.14 +
    1.15 +static int sys_exit(int status);
    1.16 +static int sys_hello(void);
    1.17 +static int sys_sleep(int sec);
    1.18 +
    1.19 +void init_syscall(void)
    1.20 +{
    1.21 +	sys_func[SYS_EXIT] = sys_exit;
    1.22 +	sys_func[SYS_HELLO] = sys_hello;
    1.23 +	sys_func[SYS_SLEEP] = sys_sleep;
    1.24 +
    1.25 +	interrupt(SYSCALL_INT, syscall);
    1.26 +}
    1.27 +
    1.28 +static void syscall(int inum, struct intr_frame *frm)
    1.29 +{
    1.30 +	int idx = frm->regs.eax;
    1.31 +
    1.32 +	if(idx < 0 || idx >= NUM_SYSCALLS) {
    1.33 +		printf("invalid syscall: %d\n", idx);
    1.34 +		return;
    1.35 +	}
    1.36 +
    1.37 +	frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
    1.38 +	schedule();
    1.39 +}
    1.40 +
    1.41 +static int sys_exit(int status)
    1.42 +{
    1.43 +	return -1;	/* not implemented yet */
    1.44 +}
    1.45 +
    1.46 +static int sys_hello(void)
    1.47 +{
    1.48 +	/*printf("process %d says hello!\n", get_current_pid());*/
    1.49 +	return 0;
    1.50 +}
    1.51 +
    1.52 +static int sys_sleep(int sec)
    1.53 +{
    1.54 +	int pid = get_current_pid();
    1.55 +	/*printf("process %d will sleep for %d sec\n", pid, sec);*/
    1.56 +	start_timer(sec * 1000, (timer_func_t)unblock_proc, (void*)pid);
    1.57 +	block_proc(pid);
    1.58 +	return 0;
    1.59 +}