kern

view src/syscall.c @ 56:0be4615594df

finally, runqueues, blocking, waking up, idle loop etc, all seem to work fine on a single user process... Next up: try forking another one :)
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 15 Aug 2011 06:17:58 +0300
parents 4eaecb14fe31
children 437360696883
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);
16 void init_syscall(void)
17 {
18 sys_func[SYS_EXIT] = sys_exit;
19 sys_func[SYS_HELLO] = sys_hello;
20 sys_func[SYS_SLEEP] = sys_sleep;
22 interrupt(SYSCALL_INT, syscall);
23 }
25 static void syscall(int inum)
26 {
27 struct intr_frame *frm;
28 int idx;
30 frm = get_intr_frame();
31 idx = frm->regs.eax;
33 if(idx < 0 || idx >= NUM_SYSCALLS) {
34 printf("invalid syscall: %d\n", idx);
35 return;
36 }
38 /* the return value goes into the interrupt frame copy of the user's eax
39 * so that it'll be restored into eax before returning to userland.
40 */
41 frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
42 }
44 static int sys_exit(int status)
45 {
46 printf("SYSCALL: exit\n");
47 return -1; /* not implemented yet */
48 }
50 static int sys_hello(void)
51 {
52 printf("process %d says hello!\n", get_current_pid());
53 return 0;
54 }
56 static int sys_sleep(int sec)
57 {
58 printf("process %d will sleep for %d seconds\n", get_current_pid(), sec);
60 sleep(sec * 1000);
62 return 0;
63 }