kern

annotate 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
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@51 10 static void syscall(int inum, struct intr_frame *frm);
nuclear@51 11
nuclear@51 12 static int sys_exit(int status);
nuclear@51 13 static int sys_hello(void);
nuclear@51 14 static int sys_sleep(int sec);
nuclear@51 15
nuclear@51 16 void init_syscall(void)
nuclear@51 17 {
nuclear@51 18 sys_func[SYS_EXIT] = sys_exit;
nuclear@51 19 sys_func[SYS_HELLO] = sys_hello;
nuclear@51 20 sys_func[SYS_SLEEP] = sys_sleep;
nuclear@51 21
nuclear@51 22 interrupt(SYSCALL_INT, syscall);
nuclear@51 23 }
nuclear@51 24
nuclear@51 25 static void syscall(int inum, struct intr_frame *frm)
nuclear@51 26 {
nuclear@51 27 int idx = frm->regs.eax;
nuclear@51 28
nuclear@51 29 if(idx < 0 || idx >= NUM_SYSCALLS) {
nuclear@51 30 printf("invalid syscall: %d\n", idx);
nuclear@51 31 return;
nuclear@51 32 }
nuclear@51 33
nuclear@51 34 frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
nuclear@51 35 schedule();
nuclear@51 36 }
nuclear@51 37
nuclear@51 38 static int sys_exit(int status)
nuclear@51 39 {
nuclear@51 40 return -1; /* not implemented yet */
nuclear@51 41 }
nuclear@51 42
nuclear@51 43 static int sys_hello(void)
nuclear@51 44 {
nuclear@51 45 /*printf("process %d says hello!\n", get_current_pid());*/
nuclear@51 46 return 0;
nuclear@51 47 }
nuclear@51 48
nuclear@51 49 static int sys_sleep(int sec)
nuclear@51 50 {
nuclear@51 51 int pid = get_current_pid();
nuclear@51 52 /*printf("process %d will sleep for %d sec\n", pid, sec);*/
nuclear@51 53 start_timer(sec * 1000, (timer_func_t)unblock_proc, (void*)pid);
nuclear@51 54 block_proc(pid);
nuclear@51 55 return 0;
nuclear@51 56 }