kern
view src/syscall.c @ 80:4db99a52863e
fixed the "endianess" of the text messages in the ATA identify info block. this
is the first time I've seen wrong byteorder in ascii text, the ATA committee
should be commended.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 06 Dec 2011 13:35:39 +0200 |
parents | 5b29b15c5412 |
children | 7ff2b4971216 |
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);
14 void init_syscall(void)
15 {
16 sys_func[SYS_HELLO] = sys_hello;
17 sys_func[SYS_SLEEP] = sys_sleep; /* timer.c */
18 sys_func[SYS_FORK] = sys_fork; /* proc.c */
19 sys_func[SYS_EXIT] = sys_exit; /* proc.c */
20 sys_func[SYS_WAITPID] = sys_waitpid; /* proc.c */
21 sys_func[SYS_GETPID] = sys_getpid; /* proc.c */
22 sys_func[SYS_GETPPID] = sys_getppid; /* proc.c */
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);
45 /* we don't necessarily want to return to the same process
46 * might have blocked or exited or whatever, so call schedule
47 * to decide what's going to run next.
48 */
49 schedule();
50 }
52 static int sys_hello(void)
53 {
54 printf("process %d says hello!\n", get_current_pid());
55 return 0;
56 }