kern
view src/syscall.c @ 95:ec62cbe00b55
whatever
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 11 Dec 2011 21:15:35 +0200 |
parents | 3941e82b07f2 |
children |
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"
7 #include "fs.h"
9 static int (*sys_func[NUM_SYSCALLS])();
11 static void syscall(int inum);
13 static int sys_hello(void);
15 void init_syscall(void)
16 {
17 sys_func[SYS_HELLO] = sys_hello;
18 sys_func[SYS_SLEEP] = sys_sleep; /* timer.c */
19 sys_func[SYS_FORK] = sys_fork; /* proc.c */
20 sys_func[SYS_EXIT] = sys_exit; /* proc.c */
21 sys_func[SYS_WAITPID] = sys_waitpid; /* proc.c */
22 sys_func[SYS_GETPID] = sys_getpid; /* proc.c */
23 sys_func[SYS_GETPPID] = sys_getppid; /* proc.c */
25 sys_func[SYS_MOUNT] = sys_mount; /* fs.c */
26 sys_func[SYS_UMOUNT] = sys_umount; /* fs.c */
27 sys_func[SYS_OPEN] = sys_open; /* fs.c */
28 sys_func[SYS_CLOSE] = sys_close; /* fs.c */
29 sys_func[SYS_READ] = sys_read; /* fs.c */
30 sys_func[SYS_WRITE] = sys_write; /* fs.c */
31 sys_func[SYS_LSEEK] = sys_lseek; /* fs.c */
33 interrupt(SYSCALL_INT, syscall);
34 }
36 static void syscall(int inum)
37 {
38 struct intr_frame *frm;
39 int idx;
41 frm = get_intr_frame();
42 idx = frm->regs.eax;
44 if(idx < 0 || idx >= NUM_SYSCALLS) {
45 printf("invalid syscall: %d\n", idx);
46 return;
47 }
49 /* the return value goes into the interrupt frame copy of the user's eax
50 * so that it'll be restored into eax before returning to userland.
51 */
52 frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
54 /* we don't necessarily want to return to the same process
55 * might have blocked or exited or whatever, so call schedule
56 * to decide what's going to run next.
57 */
58 schedule();
59 }
61 static int sys_hello(void)
62 {
63 printf("process %d says hello!\n", get_current_pid());
64 return 0;
65 }