kern

annotate 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
rev   line source
nuclear@51 1 #include <stdio.h>
nuclear@51 2 #include "syscall.h"
nuclear@51 3 #include "intr.h"
nuclear@51 4 #include "proc.h"
nuclear@51 5 #include "sched.h"
nuclear@51 6 #include "timer.h"
nuclear@51 7
nuclear@51 8 static int (*sys_func[NUM_SYSCALLS])();
nuclear@51 9
nuclear@52 10 static void syscall(int inum);
nuclear@51 11
nuclear@51 12 static int sys_exit(int status);
nuclear@51 13 static int sys_hello(void);
nuclear@51 14 static int sys_sleep(int sec);
nuclear@57 15 static int sys_fork(void);
nuclear@57 16 static int sys_getpid(void);
nuclear@51 17
nuclear@51 18 void init_syscall(void)
nuclear@51 19 {
nuclear@51 20 sys_func[SYS_EXIT] = sys_exit;
nuclear@51 21 sys_func[SYS_HELLO] = sys_hello;
nuclear@51 22 sys_func[SYS_SLEEP] = sys_sleep;
nuclear@57 23 sys_func[SYS_FORK] = sys_fork;
nuclear@57 24 sys_func[SYS_GETPID] = sys_getpid;
nuclear@51 25
nuclear@51 26 interrupt(SYSCALL_INT, syscall);
nuclear@51 27 }
nuclear@51 28
nuclear@52 29 static void syscall(int inum)
nuclear@51 30 {
nuclear@52 31 struct intr_frame *frm;
nuclear@52 32 int idx;
nuclear@52 33
nuclear@52 34 frm = get_intr_frame();
nuclear@52 35 idx = frm->regs.eax;
nuclear@51 36
nuclear@51 37 if(idx < 0 || idx >= NUM_SYSCALLS) {
nuclear@51 38 printf("invalid syscall: %d\n", idx);
nuclear@51 39 return;
nuclear@51 40 }
nuclear@51 41
nuclear@54 42 /* the return value goes into the interrupt frame copy of the user's eax
nuclear@54 43 * so that it'll be restored into eax before returning to userland.
nuclear@54 44 */
nuclear@51 45 frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
nuclear@51 46 }
nuclear@51 47
nuclear@51 48 static int sys_exit(int status)
nuclear@51 49 {
nuclear@54 50 printf("SYSCALL: exit\n");
nuclear@51 51 return -1; /* not implemented yet */
nuclear@51 52 }
nuclear@51 53
nuclear@51 54 static int sys_hello(void)
nuclear@51 55 {
nuclear@54 56 printf("process %d says hello!\n", get_current_pid());
nuclear@51 57 return 0;
nuclear@51 58 }
nuclear@51 59
nuclear@51 60 static int sys_sleep(int sec)
nuclear@51 61 {
nuclear@56 62 printf("process %d will sleep for %d seconds\n", get_current_pid(), sec);
nuclear@57 63 sleep(sec * 1000); /* timer.c */
nuclear@56 64 return 0;
nuclear@51 65 }
nuclear@57 66
nuclear@57 67 static int sys_fork(void)
nuclear@57 68 {
nuclear@57 69 printf("process %d is forking\n", get_current_pid());
nuclear@57 70 return fork(); /* proc.c */
nuclear@57 71 }
nuclear@57 72
nuclear@57 73 static int sys_getpid(void)
nuclear@57 74 {
nuclear@57 75 int pid = get_current_pid();
nuclear@57 76 printf("process %d getpid\n", pid);
nuclear@57 77 return pid;
nuclear@57 78 }