kern

view src/syscall.c @ 61:5b29b15c5412

removed the unimplemented exit syscall
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 17 Aug 2011 05:38:40 +0300
parents 437360696883
children 3941e82b07f2
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_hello(void);
13 static int sys_sleep(int sec);
14 static int sys_fork(void);
15 static int sys_getpid(void);
17 void init_syscall(void)
18 {
19 sys_func[SYS_HELLO] = sys_hello;
20 sys_func[SYS_SLEEP] = sys_sleep;
21 sys_func[SYS_FORK] = sys_fork;
22 sys_func[SYS_GETPID] = sys_getpid;
24 interrupt(SYSCALL_INT, syscall);
25 }
27 static void syscall(int inum)
28 {
29 struct intr_frame *frm;
30 int idx;
32 frm = get_intr_frame();
33 idx = frm->regs.eax;
35 if(idx < 0 || idx >= NUM_SYSCALLS) {
36 printf("invalid syscall: %d\n", idx);
37 return;
38 }
40 /* the return value goes into the interrupt frame copy of the user's eax
41 * so that it'll be restored into eax before returning to userland.
42 */
43 frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
44 }
46 static int sys_hello(void)
47 {
48 printf("process %d says hello!\n", get_current_pid());
49 return 0;
50 }
52 static int sys_sleep(int sec)
53 {
54 printf("process %d will sleep for %d seconds\n", get_current_pid(), sec);
55 sleep(sec * 1000); /* timer.c */
56 return 0;
57 }
59 static int sys_fork(void)
60 {
61 printf("process %d is forking\n", get_current_pid());
62 return fork(); /* proc.c */
63 }
65 static int sys_getpid(void)
66 {
67 int pid = get_current_pid();
68 printf("process %d getpid\n", pid);
69 return pid;
70 }