kern

view src/syscall.c @ 52:fa65b4f45366

picking this up again, let's fix it
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 07 Aug 2011 06:42:00 +0300
parents b1e8c8251884
children 4eaecb14fe31
line source
1 #include <stdio.h>
2 #include "syscall.h"
3 #include "intr.h"
4 #include "proc.h"
5 #include "sched.h"
6 #include "timer.h"
8 static int (*sys_func[NUM_SYSCALLS])();
10 static void syscall(int inum);
12 static int sys_exit(int status);
13 static int sys_hello(void);
14 static int sys_sleep(int sec);
16 void init_syscall(void)
17 {
18 sys_func[SYS_EXIT] = sys_exit;
19 sys_func[SYS_HELLO] = sys_hello;
20 sys_func[SYS_SLEEP] = sys_sleep;
22 interrupt(SYSCALL_INT, syscall);
23 }
25 static void syscall(int inum)
26 {
27 struct intr_frame *frm;
28 int idx;
30 frm = get_intr_frame();
31 idx = frm->regs.eax;
33 if(idx < 0 || idx >= NUM_SYSCALLS) {
34 printf("invalid syscall: %d\n", idx);
35 return;
36 }
38 frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
39 schedule();
40 }
42 static int sys_exit(int status)
43 {
44 return -1; /* not implemented yet */
45 }
47 static int sys_hello(void)
48 {
49 /*printf("process %d says hello!\n", get_current_pid());*/
50 return 0;
51 }
53 static int sys_sleep(int sec)
54 {
55 int pid = get_current_pid();
56 /*printf("process %d will sleep for %d sec\n", pid, sec);*/
57 start_timer(sec * 1000, (timer_func_t)unblock_proc, (void*)pid);
58 block_proc(pid);
59 return 0;
60 }