kern
view 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 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, struct intr_frame *frm);
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, struct intr_frame *frm)
26 {
27 int idx = frm->regs.eax;
29 if(idx < 0 || idx >= NUM_SYSCALLS) {
30 printf("invalid syscall: %d\n", idx);
31 return;
32 }
34 frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
35 schedule();
36 }
38 static int sys_exit(int status)
39 {
40 return -1; /* not implemented yet */
41 }
43 static int sys_hello(void)
44 {
45 /*printf("process %d says hello!\n", get_current_pid());*/
46 return 0;
47 }
49 static int sys_sleep(int sec)
50 {
51 int pid = get_current_pid();
52 /*printf("process %d will sleep for %d sec\n", pid, sec);*/
53 start_timer(sec * 1000, (timer_func_t)unblock_proc, (void*)pid);
54 block_proc(pid);
55 return 0;
56 }