kern

view src/syscall.c @ 57:437360696883

I think we're done for now. two processes seem to be scheduled and switched just fine, fork seems to work (NO CoW YET!)
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 16 Aug 2011 03:26:53 +0300
parents 0be4615594df
children 5b29b15c5412
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);
15 static int sys_fork(void);
16 static int sys_getpid(void);
18 void init_syscall(void)
19 {
20 sys_func[SYS_EXIT] = sys_exit;
21 sys_func[SYS_HELLO] = sys_hello;
22 sys_func[SYS_SLEEP] = sys_sleep;
23 sys_func[SYS_FORK] = sys_fork;
24 sys_func[SYS_GETPID] = sys_getpid;
26 interrupt(SYSCALL_INT, syscall);
27 }
29 static void syscall(int inum)
30 {
31 struct intr_frame *frm;
32 int idx;
34 frm = get_intr_frame();
35 idx = frm->regs.eax;
37 if(idx < 0 || idx >= NUM_SYSCALLS) {
38 printf("invalid syscall: %d\n", idx);
39 return;
40 }
42 /* the return value goes into the interrupt frame copy of the user's eax
43 * so that it'll be restored into eax before returning to userland.
44 */
45 frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
46 }
48 static int sys_exit(int status)
49 {
50 printf("SYSCALL: exit\n");
51 return -1; /* not implemented yet */
52 }
54 static int sys_hello(void)
55 {
56 printf("process %d says hello!\n", get_current_pid());
57 return 0;
58 }
60 static int sys_sleep(int sec)
61 {
62 printf("process %d will sleep for %d seconds\n", get_current_pid(), sec);
63 sleep(sec * 1000); /* timer.c */
64 return 0;
65 }
67 static int sys_fork(void)
68 {
69 printf("process %d is forking\n", get_current_pid());
70 return fork(); /* proc.c */
71 }
73 static int sys_getpid(void)
74 {
75 int pid = get_current_pid();
76 printf("process %d getpid\n", pid);
77 return pid;
78 }